chore: infer client from context in JSHandle (#8842)

This commit is contained in:
jrandolf 2022-08-25 17:00:35 +02:00 committed by GitHub
parent 5fba0dc932
commit 744a6e028a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 13 deletions

View File

@ -1,9 +1,8 @@
import {Protocol} from 'devtools-protocol'; import {Protocol} from 'devtools-protocol';
import {assert} from '../util/assert.js'; import {assert} from '../util/assert.js';
import {CDPSession} from './Connection.js';
import {ExecutionContext} from './ExecutionContext.js'; import {ExecutionContext} from './ExecutionContext.js';
import {FrameManager} from './FrameManager.js';
import {Frame} from './Frame.js'; import {Frame} from './Frame.js';
import {FrameManager} from './FrameManager.js';
import { import {
MAIN_WORLD, MAIN_WORLD,
PUPPETEER_WORLD, PUPPETEER_WORLD,
@ -80,13 +79,12 @@ export class ElementHandle<
*/ */
constructor( constructor(
context: ExecutionContext, context: ExecutionContext,
client: CDPSession,
remoteObject: Protocol.Runtime.RemoteObject, remoteObject: Protocol.Runtime.RemoteObject,
frame: Frame, frame: Frame,
page: Page, page: Page,
frameManager: FrameManager frameManager: FrameManager
) { ) {
super(context, client, remoteObject); super(context, remoteObject);
this.#frame = frame; this.#frame = frame;
this.#page = page; this.#page = page;
this.#frameManager = frameManager; this.#frameManager = frameManager;

View File

@ -78,7 +78,6 @@ export class JSHandle<T = unknown> {
*/ */
[__JSHandleSymbol]?: T; [__JSHandleSymbol]?: T;
#client: CDPSession;
#disposed = false; #disposed = false;
#context: ExecutionContext; #context: ExecutionContext;
#remoteObject: Protocol.Runtime.RemoteObject; #remoteObject: Protocol.Runtime.RemoteObject;
@ -87,7 +86,7 @@ export class JSHandle<T = unknown> {
* @internal * @internal
*/ */
get client(): CDPSession { get client(): CDPSession {
return this.#client; return this.#context._client;
} }
/** /**
@ -102,11 +101,9 @@ export class JSHandle<T = unknown> {
*/ */
constructor( constructor(
context: ExecutionContext, context: ExecutionContext,
client: CDPSession,
remoteObject: Protocol.Runtime.RemoteObject remoteObject: Protocol.Runtime.RemoteObject
) { ) {
this.#context = context; this.#context = context;
this.#client = client;
this.#remoteObject = remoteObject; this.#remoteObject = remoteObject;
} }
@ -196,7 +193,7 @@ export class JSHandle<T = unknown> {
assert(this.#remoteObject.objectId); assert(this.#remoteObject.objectId);
// We use Runtime.getProperties rather than iterative building because the // We use Runtime.getProperties rather than iterative building because the
// iterative approach might create a distorted snapshot. // iterative approach might create a distorted snapshot.
const response = await this.#client.send('Runtime.getProperties', { const response = await this.client.send('Runtime.getProperties', {
objectId: this.#remoteObject.objectId, objectId: this.#remoteObject.objectId,
ownProperties: true, ownProperties: true,
}); });
@ -247,7 +244,7 @@ export class JSHandle<T = unknown> {
return; return;
} }
this.#disposed = true; this.#disposed = true;
await releaseObject(this.#client, this.#remoteObject); await releaseObject(this.client, this.#remoteObject);
} }
/** /**

View File

@ -93,7 +93,7 @@ export class WebWorker extends EventEmitter {
return consoleAPICalled( return consoleAPICalled(
event.type, event.type,
event.args.map((object: Protocol.Runtime.RemoteObject) => { event.args.map((object: Protocol.Runtime.RemoteObject) => {
return new JSHandle(context, this.#client, object); return new JSHandle(context, object);
}), }),
event.stackTrace event.stackTrace
); );

View File

@ -222,14 +222,13 @@ export function createJSHandle(
const frameManager = frame._frameManager; const frameManager = frame._frameManager;
return new ElementHandle( return new ElementHandle(
context, context,
context._client,
remoteObject, remoteObject,
frame, frame,
frameManager.page(), frameManager.page(),
frameManager frameManager
); );
} }
return new JSHandle(context, context._client, remoteObject); return new JSHandle(context, remoteObject);
} }
/** /**