Skip to content

Commit

Permalink
chore: infer client from context in JSHandle (#8842)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Aug 25, 2022
1 parent 5fba0dc commit 744a6e0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/common/ElementHandle.ts
@@ -1,9 +1,8 @@
import {Protocol} from 'devtools-protocol';
import {assert} from '../util/assert.js';
import {CDPSession} from './Connection.js';
import {ExecutionContext} from './ExecutionContext.js';
import {FrameManager} from './FrameManager.js';
import {Frame} from './Frame.js';
import {FrameManager} from './FrameManager.js';
import {
MAIN_WORLD,
PUPPETEER_WORLD,
Expand Down Expand Up @@ -80,13 +79,12 @@ export class ElementHandle<
*/
constructor(
context: ExecutionContext,
client: CDPSession,
remoteObject: Protocol.Runtime.RemoteObject,
frame: Frame,
page: Page,
frameManager: FrameManager
) {
super(context, client, remoteObject);
super(context, remoteObject);
this.#frame = frame;
this.#page = page;
this.#frameManager = frameManager;
Expand Down
9 changes: 3 additions & 6 deletions src/common/JSHandle.ts
Expand Up @@ -78,7 +78,6 @@ export class JSHandle<T = unknown> {
*/
[__JSHandleSymbol]?: T;

#client: CDPSession;
#disposed = false;
#context: ExecutionContext;
#remoteObject: Protocol.Runtime.RemoteObject;
Expand All @@ -87,7 +86,7 @@ export class JSHandle<T = unknown> {
* @internal
*/
get client(): CDPSession {
return this.#client;
return this.#context._client;
}

/**
Expand All @@ -102,11 +101,9 @@ export class JSHandle<T = unknown> {
*/
constructor(
context: ExecutionContext,
client: CDPSession,
remoteObject: Protocol.Runtime.RemoteObject
) {
this.#context = context;
this.#client = client;
this.#remoteObject = remoteObject;
}

Expand Down Expand Up @@ -196,7 +193,7 @@ export class JSHandle<T = unknown> {
assert(this.#remoteObject.objectId);
// We use Runtime.getProperties rather than iterative building because the
// 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,
ownProperties: true,
});
Expand Down Expand Up @@ -247,7 +244,7 @@ export class JSHandle<T = unknown> {
return;
}
this.#disposed = true;
await releaseObject(this.#client, this.#remoteObject);
await releaseObject(this.client, this.#remoteObject);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/common/WebWorker.ts
Expand Up @@ -93,7 +93,7 @@ export class WebWorker extends EventEmitter {
return consoleAPICalled(
event.type,
event.args.map((object: Protocol.Runtime.RemoteObject) => {
return new JSHandle(context, this.#client, object);
return new JSHandle(context, object);
}),
event.stackTrace
);
Expand Down
3 changes: 1 addition & 2 deletions src/common/util.ts
Expand Up @@ -222,14 +222,13 @@ export function createJSHandle(
const frameManager = frame._frameManager;
return new ElementHandle(
context,
context._client,
remoteObject,
frame,
frameManager.page(),
frameManager
);
}
return new JSHandle(context, context._client, remoteObject);
return new JSHandle(context, remoteObject);
}

/**
Expand Down

0 comments on commit 744a6e0

Please sign in to comment.