chore(evaluate): remove private _evaluateInUtility methods (#6815)

This commit is contained in:
Joel Einbinder 2021-06-01 08:36:16 -07:00 committed by GitHub
parent 5fd15d8a5e
commit 2951f4b065
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 2 additions and 58 deletions

View file

@ -181,16 +181,6 @@ export class Frame extends ChannelOwner<channels.FrameChannel, channels.FrameIni
});
}
async _evaluateHandleInUtility<R, Arg>(pageFunction: structs.PageFunction<Arg, R>, arg: Arg): Promise<structs.SmartHandle<R>>;
async _evaluateHandleInUtility<R>(pageFunction: structs.PageFunction<void, R>, arg?: any): Promise<structs.SmartHandle<R>>;
async _evaluateHandleInUtility<R, Arg>(pageFunction: structs.PageFunction<Arg, R>, arg?: Arg): Promise<structs.SmartHandle<R>> {
assertMaxArguments(arguments.length, 2);
return this._wrapApiCall(this._apiName('_evaluateHandleInUtility'), async (channel: channels.FrameChannel) => {
const result = await channel.evaluateExpressionHandle({ expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg), world: 'utility' });
return JSHandle.from(result.handle) as any as structs.SmartHandle<R>;
});
}
async evaluate<R, Arg>(pageFunction: structs.PageFunction<Arg, R>, arg?: Arg): Promise<R> {
assertMaxArguments(arguments.length, 2);
return this._wrapApiCall(this._apiName('evaluate'), async (channel: channels.FrameChannel) => {
@ -199,16 +189,6 @@ export class Frame extends ChannelOwner<channels.FrameChannel, channels.FrameIni
});
}
async _evaluateInUtility<R, Arg>(pageFunction: structs.PageFunction<Arg, R>, arg: Arg): Promise<R>;
async _evaluateInUtility<R>(pageFunction: structs.PageFunction<void, R>, arg?: any): Promise<R>;
async _evaluateInUtility<R, Arg>(pageFunction: structs.PageFunction<Arg, R>, arg?: Arg): Promise<R> {
assertMaxArguments(arguments.length, 2);
return this._wrapApiCall(this._apiName('evaluate'), async (channel: channels.FrameChannel) => {
const result = await channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg), world: 'utility' });
return parseResult(result.value);
});
}
async $(selector: string): Promise<ElementHandle<SVGElement | HTMLElement> | null> {
return this._wrapApiCall(this._apiName('$'), async (channel: channels.FrameChannel) => {
const result = await channel.querySelector({ selector });

View file

@ -61,11 +61,11 @@ export class FrameDispatcher extends Dispatcher<Frame, channels.FrameInitializer
}
async evaluateExpression(params: channels.FrameEvaluateExpressionParams, metadata: CallMetadata): Promise<channels.FrameEvaluateExpressionResult> {
return { value: serializeResult(await this._frame.evaluateExpressionAndWaitForSignals(params.expression, params.isFunction, parseArgument(params.arg), params.world)) };
return { value: serializeResult(await this._frame.evaluateExpressionAndWaitForSignals(params.expression, params.isFunction, parseArgument(params.arg), 'main')) };
}
async evaluateExpressionHandle(params: channels.FrameEvaluateExpressionHandleParams, metadata: CallMetadata): Promise<channels.FrameEvaluateExpressionHandleResult> {
return { handle: ElementHandleDispatcher.fromJSHandle(this._scope, await this._frame.evaluateExpressionHandleAndWaitForSignals(params.expression, params.isFunction, parseArgument(params.arg), params.world)) };
return { handle: ElementHandleDispatcher.fromJSHandle(this._scope, await this._frame.evaluateExpressionHandleAndWaitForSignals(params.expression, params.isFunction, parseArgument(params.arg), 'main')) };
}
async waitForSelector(params: channels.FrameWaitForSelectorParams, metadata: CallMetadata): Promise<channels.FrameWaitForSelectorResult> {

View file

@ -1458,11 +1458,9 @@ export type FrameEvaluateExpressionParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
world?: 'main' | 'utility',
};
export type FrameEvaluateExpressionOptions = {
isFunction?: boolean,
world?: 'main' | 'utility',
};
export type FrameEvaluateExpressionResult = {
value: SerializedValue,
@ -1471,11 +1469,9 @@ export type FrameEvaluateExpressionHandleParams = {
expression: string,
isFunction?: boolean,
arg: SerializedArgument,
world?: 'main' | 'utility',
};
export type FrameEvaluateExpressionHandleOptions = {
isFunction?: boolean,
world?: 'main' | 'utility',
};
export type FrameEvaluateExpressionHandleResult = {
handle: JSHandleChannel,

View file

@ -1148,11 +1148,6 @@ Frame:
expression: string
isFunction: boolean?
arg: SerializedArgument
world:
type: enum?
literals:
- main
- utility
returns:
value: SerializedValue
@ -1161,11 +1156,6 @@ Frame:
expression: string
isFunction: boolean?
arg: SerializedArgument
world:
type: enum?
literals:
- main
- utility
returns:
handle: JSHandle

View file

@ -590,13 +590,11 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
expression: tString,
isFunction: tOptional(tBoolean),
arg: tType('SerializedArgument'),
world: tOptional(tEnum(['main', 'utility'])),
});
scheme.FrameEvaluateExpressionHandleParams = tObject({
expression: tString,
isFunction: tOptional(tBoolean),
arg: tType('SerializedArgument'),
world: tOptional(tEnum(['main', 'utility'])),
});
scheme.FrameFillParams = tObject({
selector: tString,

View file

@ -17,7 +17,6 @@
import { test as it, expect } from './pageTest';
import { attachFrame, detachFrame } from '../config/utils';
import type { Frame } from '../../src/client/frame';
it('should have different execution contexts', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
@ -184,22 +183,3 @@ it('evaluateHandle should work', async ({page, server}) => {
expect(windowHandle).toBeTruthy();
});
it('evaluateInUtility should work', async ({page}) => {
await page.setContent('<body>hello</body>');
const mainFrame = page.mainFrame() as any as Frame;
await mainFrame.evaluate(() => window['foo'] = 42);
expect(await mainFrame.evaluate(() => window['foo'])).toBe(42);
expect(await mainFrame._evaluateInUtility(() => window['foo'])).toBe(undefined);
expect(await mainFrame._evaluateInUtility(() => document.body.textContent)).toBe('hello');
});
it('evaluateHandleInUtility should work', async ({page}) => {
await page.setContent('<body>hello</body>');
const mainFrame = page.mainFrame() as any as Frame;
await mainFrame.evaluate(() => window['foo'] = 42);
expect(await mainFrame.evaluate(() => window['foo'])).toBe(42);
const handle1 = await mainFrame._evaluateHandleInUtility(() => window['foo']);
expect(await handle1.jsonValue()).toBe(undefined);
const handle2 = await mainFrame._evaluateHandleInUtility(() => document.body);
expect(await handle2.evaluate(body => body.textContent)).toBe('hello');
});