From 109b4f827ee982caf7a5503ce8576cd2254bce10 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Fri, 3 Jan 2020 13:46:51 -0800 Subject: [PATCH] fix(webkit): returnByValue returns undefined for objects with symbols --- src/webkit/wkExecutionContext.ts | 10 ++++++++-- test/evaluation.spec.js | 10 +++++++++- test/page.spec.js | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/webkit/wkExecutionContext.ts b/src/webkit/wkExecutionContext.ts index 1e843cb842..250b956e33 100644 --- a/src/webkit/wkExecutionContext.ts +++ b/src/webkit/wkExecutionContext.ts @@ -219,9 +219,15 @@ export class WKExecutionContext implements js.ExecutionContextDelegate { } private _returnObjectByValue(objectId: Protocol.Runtime.RemoteObjectId) { - const serializeFunction = function(stringify: (o: any) => string) { + const serializeFunction = function(stringify: (o: any, replacer: (key: any, value: any) => any) => string) { try { - return stringify(this); + let hasSymbol = false; + const result = stringify(this, (key, value) => { + if (typeof value === 'symbol') + hasSymbol = true; + return value; + }); + return hasSymbol ? undefined : result; } catch (e) { if (e instanceof TypeError) return void 0; diff --git a/test/evaluation.spec.js b/test/evaluation.spec.js index 7fd2730575..9ab172e6b0 100644 --- a/test/evaluation.spec.js +++ b/test/evaluation.spec.js @@ -61,8 +61,16 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROME, WEBKIT}) { await page.goto(server.PREFIX + '/global-var.html'); expect(await page.evaluate('globalVar')).toBe(123); }); - it.skip(FFOX || WEBKIT)('should return undefined for objects with symbols', async({page, server}) => { + it.skip(FFOX)('should return undefined for objects with symbols', async({page, server}) => { expect(await page.evaluate(() => [Symbol('foo4')])).toBe(undefined); + expect(await page.evaluate(() => { + const a = { }; + a[Symbol('foo4')] = 42; + return a; + })).toEqual({}); + expect(await page.evaluate(() => { + return { foo: [{ a: Symbol('foo4') }] }; + })).toBe(undefined); }); it('should work with function shorthands', async({page, server}) => { const a = { diff --git a/test/page.spec.js b/test/page.spec.js index d40534fd46..e2ae6714a6 100644 --- a/test/page.spec.js +++ b/test/page.spec.js @@ -172,7 +172,7 @@ module.exports.describe = function({testRunner, expect, headless, playwright, FF expect(await page.evaluate(() => !!window.opener)).toBe(false); expect(await popup.evaluate(() => !!window.opener)).toBe(false); }); - it.skip(WEBKIT || FFOX)('should not treat navigations as new popups', async({page, server}) => { + it('should not treat navigations as new popups', async({page, server}) => { await page.goto(server.EMPTY_PAGE); await page.setContent('yo'); const [popup] = await Promise.all([