fix(firefox): enable a bunch of evaluation tests (#4006)
This commit is contained in:
parent
6350cf0892
commit
e8f044c3be
@ -21,9 +21,34 @@ class ExecutionContext {
|
|||||||
});
|
});
|
||||||
return createHandle(this, payload.result, payload.exceptionDetails);
|
return createHandle(this, payload.result, payload.exceptionDetails);
|
||||||
}
|
}
|
||||||
|
if (typeof pageFunction !== 'function')
|
||||||
|
throw new Error(`Expected to get |string| or |function| as the first argument, but got "${pageFunction}" instead.`);
|
||||||
|
|
||||||
|
let functionText = pageFunction.toString();
|
||||||
|
try {
|
||||||
|
new Function('(' + functionText + ')');
|
||||||
|
} catch (e1) {
|
||||||
|
// This means we might have a function shorthand. Try another
|
||||||
|
// time prefixing 'function '.
|
||||||
|
if (functionText.startsWith('async '))
|
||||||
|
functionText = 'async function ' + functionText.substring('async '.length);
|
||||||
|
else
|
||||||
|
functionText = 'function ' + functionText;
|
||||||
|
try {
|
||||||
|
new Function('(' + functionText + ')');
|
||||||
|
} catch (e2) {
|
||||||
|
// We tried hard to serialize, but there's a weird beast here.
|
||||||
|
throw new Error('Passed function is not well-serializable!');
|
||||||
|
}
|
||||||
|
}
|
||||||
args = args.map(arg => {
|
args = args.map(arg => {
|
||||||
if (arg instanceof JSHandle)
|
if (arg instanceof JSHandle) {
|
||||||
|
if (arg._context !== this)
|
||||||
|
throw new Error('JSHandles can be evaluated only in the context they were created!');
|
||||||
|
if (arg._disposed)
|
||||||
|
throw new Error('JSHandle is disposed!');
|
||||||
return arg._protocolValue;
|
return arg._protocolValue;
|
||||||
|
}
|
||||||
if (Object.is(arg, Infinity))
|
if (Object.is(arg, Infinity))
|
||||||
return {unserializableValue: 'Infinity'};
|
return {unserializableValue: 'Infinity'};
|
||||||
if (Object.is(arg, -Infinity))
|
if (Object.is(arg, -Infinity))
|
||||||
@ -35,7 +60,7 @@ class ExecutionContext {
|
|||||||
return {value: arg};
|
return {value: arg};
|
||||||
});
|
});
|
||||||
const payload = await this._session.send('Page.evaluate', {
|
const payload = await this._session.send('Page.evaluate', {
|
||||||
functionText: pageFunction.toString(),
|
functionText,
|
||||||
args,
|
args,
|
||||||
executionContextId: this._executionContextId
|
executionContextId: this._executionContextId
|
||||||
});
|
});
|
||||||
|
@ -13,6 +13,7 @@ class JSHandle {
|
|||||||
this._objectId = payload.objectId;
|
this._objectId = payload.objectId;
|
||||||
this._type = payload.type;
|
this._type = payload.type;
|
||||||
this._subtype = payload.subtype;
|
this._subtype = payload.subtype;
|
||||||
|
this._disposed = false;
|
||||||
this._protocolValue = {
|
this._protocolValue = {
|
||||||
unserializableValue: payload.unserializableValue,
|
unserializableValue: payload.unserializableValue,
|
||||||
value: payload.value,
|
value: payload.value,
|
||||||
@ -102,6 +103,7 @@ class JSHandle {
|
|||||||
async dispose() {
|
async dispose() {
|
||||||
if (!this._objectId)
|
if (!this._objectId)
|
||||||
return;
|
return;
|
||||||
|
this._disposed = true;
|
||||||
await this._session.send('Page.disposeObject', {
|
await this._session.send('Page.disposeObject', {
|
||||||
executionContextId: this._executionContextId,
|
executionContextId: this._executionContextId,
|
||||||
objectId: this._objectId,
|
objectId: this._objectId,
|
||||||
|
@ -82,7 +82,7 @@ class ExecutionContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof pageFunction !== 'function')
|
if (typeof pageFunction !== 'function')
|
||||||
throw new Error('The following is not a function: ' + pageFunction);
|
throw new Error(`Expected to get |string| or |function| as the first argument, but got "${pageFunction}" instead.`);
|
||||||
|
|
||||||
let functionText = pageFunction.toString();
|
let functionText = pageFunction.toString();
|
||||||
try {
|
try {
|
||||||
|
@ -68,7 +68,7 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
it_fails_ffox('should return undefined for objects with symbols', async({page, server}) => {
|
it_fails_ffox('should return undefined for objects with symbols', async({page, server}) => {
|
||||||
expect(await page.evaluate(() => [Symbol('foo4')])).toBe(undefined);
|
expect(await page.evaluate(() => [Symbol('foo4')])).toBe(undefined);
|
||||||
});
|
});
|
||||||
(asyncawait ? it_fails_ffox : xit)('should work with function shorthands', async({page, server}) => {
|
(asyncawait ? it : xit)('should work with function shorthands', async({page, server}) => {
|
||||||
// trick node6 transpiler to not touch our object.
|
// trick node6 transpiler to not touch our object.
|
||||||
// TODO(lushnikov): remove eval once Node6 is dropped.
|
// TODO(lushnikov): remove eval once Node6 is dropped.
|
||||||
const a = eval(`({
|
const a = eval(`({
|
||||||
@ -188,7 +188,7 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
const text = await page.evaluate(e => e.textContent, element);
|
const text = await page.evaluate(e => e.textContent, element);
|
||||||
expect(text).toBe('42');
|
expect(text).toBe('42');
|
||||||
});
|
});
|
||||||
it_fails_ffox('should throw if underlying element was disposed', async({page, server}) => {
|
it('should throw if underlying element was disposed', async({page, server}) => {
|
||||||
await page.setContent('<section>39</section>');
|
await page.setContent('<section>39</section>');
|
||||||
const element = await page.$('section');
|
const element = await page.$('section');
|
||||||
expect(element).toBeTruthy();
|
expect(element).toBeTruthy();
|
||||||
@ -197,7 +197,7 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
await page.evaluate(e => e.textContent, element).catch(e => error = e);
|
await page.evaluate(e => e.textContent, element).catch(e => error = e);
|
||||||
expect(error.message).toContain('JSHandle is disposed');
|
expect(error.message).toContain('JSHandle is disposed');
|
||||||
});
|
});
|
||||||
it_fails_ffox('should throw if elementHandles are from other frames', async({page, server}) => {
|
it('should throw if elementHandles are from other frames', async({page, server}) => {
|
||||||
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
||||||
const bodyHandle = await page.frames()[1].$('body');
|
const bodyHandle = await page.frames()[1].$('body');
|
||||||
let error = null;
|
let error = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user