revert(json): revert WK null-json mode, joel has a better fix (#372)
This commit is contained in:
parent
32edca7395
commit
62888d8543
|
|
@ -219,9 +219,9 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _returnObjectByValue(objectId: Protocol.Runtime.RemoteObjectId) {
|
private _returnObjectByValue(objectId: Protocol.Runtime.RemoteObjectId) {
|
||||||
const serializeFunction = function(stringify: (o: any) => string) {
|
const serializeFunction = function() {
|
||||||
try {
|
try {
|
||||||
return stringify(this);
|
return JSON.stringify(this);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof TypeError)
|
if (e instanceof TypeError)
|
||||||
return void 0;
|
return void 0;
|
||||||
|
|
@ -232,7 +232,6 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
|
||||||
// Serialize object using standard JSON implementation to correctly pass 'undefined'.
|
// Serialize object using standard JSON implementation to correctly pass 'undefined'.
|
||||||
functionDeclaration: serializeFunction + '\n' + suffix + '\n',
|
functionDeclaration: serializeFunction + '\n' + suffix + '\n',
|
||||||
objectId: objectId,
|
objectId: objectId,
|
||||||
arguments: [ { objectId: this._jsonStringifyObjectId } ],
|
|
||||||
returnByValue: true
|
returnByValue: true
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
if (isSwappedOutError(e))
|
if (isSwappedOutError(e))
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,6 @@ import { getAccessibilityTree } from './wkAccessibility';
|
||||||
|
|
||||||
const UTILITY_WORLD_NAME = '__playwright_utility_world__';
|
const UTILITY_WORLD_NAME = '__playwright_utility_world__';
|
||||||
const BINDING_CALL_MESSAGE = '__playwright_binding_call__';
|
const BINDING_CALL_MESSAGE = '__playwright_binding_call__';
|
||||||
const JSON_CALL_MESSAGE = '__playwright_json_call__';
|
|
||||||
const JSON_SAVE_SCRIPT = `console.debug('${JSON_CALL_MESSAGE}', JSON.stringify.bind(JSON))`;
|
|
||||||
|
|
||||||
export class WKPage implements PageDelegate {
|
export class WKPage implements PageDelegate {
|
||||||
readonly rawMouse: RawMouseImpl;
|
readonly rawMouse: RawMouseImpl;
|
||||||
|
|
@ -50,7 +48,7 @@ export class WKPage implements PageDelegate {
|
||||||
private readonly _contextIdToContext: Map<number, dom.FrameExecutionContext>;
|
private readonly _contextIdToContext: Map<number, dom.FrameExecutionContext>;
|
||||||
private _isolatedWorlds: Set<string>;
|
private _isolatedWorlds: Set<string>;
|
||||||
private _sessionListeners: RegisteredListener[] = [];
|
private _sessionListeners: RegisteredListener[] = [];
|
||||||
private readonly _bootstrapScripts: string[] = [ JSON_SAVE_SCRIPT ];
|
private readonly _bootstrapScripts: string[] = [];
|
||||||
|
|
||||||
constructor(browser: WKBrowser, browserContext: BrowserContext) {
|
constructor(browser: WKBrowser, browserContext: BrowserContext) {
|
||||||
this._browser = browser;
|
this._browser = browser;
|
||||||
|
|
@ -111,7 +109,6 @@ export class WKPage implements PageDelegate {
|
||||||
if (this._page._state.viewport)
|
if (this._page._state.viewport)
|
||||||
promises.push(WKPage._setViewport(session, this._page._state.viewport));
|
promises.push(WKPage._setViewport(session, this._page._state.viewport));
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
await this._page.evaluate(JSON_SAVE_SCRIPT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
didClose(crashed: boolean) {
|
didClose(crashed: boolean) {
|
||||||
|
|
@ -224,12 +221,6 @@ export class WKPage implements PageDelegate {
|
||||||
this._page._onBindingCalled(parameters[2].value, context);
|
this._page._onBindingCalled(parameters[2].value, context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (level === 'debug' && parameters && parameters[0].value === JSON_CALL_MESSAGE) {
|
|
||||||
const parsedObjectId = JSON.parse(parameters[1].objectId);
|
|
||||||
const context = this._contextIdToContext.get(parsedObjectId.injectedScriptId);
|
|
||||||
(context._delegate as WKExecutionContext)._jsonStringifyObjectId = parameters[1].objectId;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (level === 'error' && source === 'javascript') {
|
if (level === 'error' && source === 'javascript') {
|
||||||
const error = new Error(text);
|
const error = new Error(text);
|
||||||
error.stack = '';
|
error.stack = '';
|
||||||
|
|
|
||||||
|
|
@ -259,7 +259,7 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
|
||||||
})).catch(e => error = e);
|
})).catch(e => error = e);
|
||||||
expect(error.message).toContain('Error in promise');
|
expect(error.message).toContain('Error in promise');
|
||||||
});
|
});
|
||||||
it('should work even when JSON is set to null', async ({ page }) => {
|
it.skip(WEBKIT)('should work even when JSON is set to null', async ({ page }) => {
|
||||||
await page.evaluate(() => { window.JSON.stringify = null; window.JSON = null; });
|
await page.evaluate(() => { window.JSON.stringify = null; window.JSON = null; });
|
||||||
const result = await page.evaluate(() => ({abc: 123}));
|
const result = await page.evaluate(() => ({abc: 123}));
|
||||||
expect(result).toEqual({abc: 123});
|
expect(result).toEqual({abc: 123});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue