chore: improve error message when Array.toJSON misbehaves (#32508)
Fixes: #32507
This commit is contained in:
parent
9fa06be49e
commit
f8562e4ca7
|
|
@ -846,6 +846,8 @@ export class PageBinding {
|
|||
const handle = await context.evaluateHandle(takeHandle, { name, seq }).catch(e => null);
|
||||
result = await binding.playwrightFunction({ frame: context.frame, page, context: page._browserContext }, handle);
|
||||
} else {
|
||||
if (!Array.isArray(serializedArgs))
|
||||
throw new Error(`serializedArgs is not an array. This can happen when Array.prototype.toJSON is defined incorrectly`);
|
||||
const args = serializedArgs!.map(a => parseEvaluationResultValue(a));
|
||||
result = await binding.playwrightFunction({ frame: context.frame, page, context: page._browserContext }, ...args);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -300,3 +300,12 @@ it('should work with busted Array.prototype.map/push', async ({ page, server })
|
|||
await page.exposeFunction('add', (a, b) => a + b);
|
||||
expect(await page.evaluate('add(5, 6)')).toBe(11);
|
||||
});
|
||||
|
||||
it('should fail with busted Array.prototype.toJSON', async ({ page }) => {
|
||||
await page.evaluateHandle(() => (Array.prototype as any).toJSON = () => '"[]"');
|
||||
|
||||
await page.exposeFunction('add', (a, b) => a + b);
|
||||
await expect(() => page.evaluate(`add(5, 6)`)).rejects.toThrowError('serializedArgs is not an array. This can happen when Array.prototype.toJSON is defined incorrectly');
|
||||
|
||||
expect.soft(await page.evaluate(() => ([] as any).toJSON())).toBe('"[]"');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue