Skip to content

Commit

Permalink
chore: rename DOMWorld to IsolatedWorld (#8761)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Aug 9, 2022
1 parent 932a053 commit 837b10b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 39 deletions.
20 changes: 13 additions & 7 deletions src/common/AriaQueryHandler.ts
Expand Up @@ -17,7 +17,11 @@
import {Protocol} from 'devtools-protocol';
import {assert} from './assert.js';
import {CDPSession} from './Connection.js';
import {DOMWorld, PageBinding, WaitForSelectorOptions} from './DOMWorld.js';
import {
IsolatedWorld,
PageBinding,
WaitForSelectorOptions,
} from './IsolatedWorld.js';
import {ElementHandle} from './ElementHandle.js';
import {JSHandle} from './JSHandle.js';
import {InternalQueryHandler} from './QueryHandler.js';
Expand Down Expand Up @@ -101,19 +105,19 @@ const queryOne = async (
};

const waitFor = async (
domWorld: DOMWorld,
isolatedWorld: IsolatedWorld,
selector: string,
options: WaitForSelectorOptions
): Promise<ElementHandle<Element> | null> => {
const binding: PageBinding = {
name: 'ariaQuerySelector',
pptrFunction: async (selector: string) => {
const root = options.root || (await domWorld._document());
const root = options.root || (await isolatedWorld._document());
const element = await queryOne(root, selector);
return element;
},
};
return (await domWorld._waitForSelectorInPage(
return (await isolatedWorld._waitForSelectorInPage(
(_: Element, selector: string) => {
return (
globalThis as unknown as {
Expand All @@ -135,11 +139,13 @@ const queryAll = async (
const {name, role} = parseAriaSelector(selector);
const res = await queryAXTree(exeCtx._client, element, name, role);
const world = exeCtx._world!;
return (await Promise.all(
return Promise.all(
res.map(axNode => {
return world.adoptBackendNode(axNode.backendDOMNodeId);
return world.adoptBackendNode(axNode.backendDOMNodeId) as Promise<
ElementHandle<Node>
>;
})
)) as Array<ElementHandle<Node>>;
);
};

const queryAllArray = async (
Expand Down
2 changes: 1 addition & 1 deletion src/common/ElementHandle.ts
@@ -1,7 +1,7 @@
import {Protocol} from 'devtools-protocol';
import {assert} from './assert.js';
import {CDPSession} from './Connection.js';
import {WaitForSelectorOptions} from './DOMWorld.js';
import {WaitForSelectorOptions} from './IsolatedWorld.js';
import {ExecutionContext} from './ExecutionContext.js';
import {Frame, FrameManager} from './FrameManager.js';
import {
Expand Down
6 changes: 3 additions & 3 deletions src/common/ExecutionContext.ts
Expand Up @@ -17,7 +17,7 @@
import {Protocol} from 'devtools-protocol';
import {assert} from './assert.js';
import {CDPSession} from './Connection.js';
import {DOMWorld} from './DOMWorld.js';
import {IsolatedWorld} from './IsolatedWorld.js';
import {ElementHandle} from './ElementHandle.js';
import {Frame} from './FrameManager.js';
import {JSHandle} from './JSHandle.js';
Expand Down Expand Up @@ -57,7 +57,7 @@ export class ExecutionContext {
/**
* @internal
*/
_world?: DOMWorld;
_world?: IsolatedWorld;
/**
* @internal
*/
Expand All @@ -73,7 +73,7 @@ export class ExecutionContext {
constructor(
client: CDPSession,
contextPayload: Protocol.Runtime.ExecutionContextDescription,
world?: DOMWorld
world?: IsolatedWorld
) {
this._client = client;
this._world = world;
Expand Down
12 changes: 6 additions & 6 deletions src/common/FrameManager.ts
Expand Up @@ -17,7 +17,7 @@
import {Protocol} from 'devtools-protocol';
import {assert} from './assert.js';
import {CDPSession} from './Connection.js';
import {DOMWorld, WaitForSelectorOptions} from './DOMWorld.js';
import {IsolatedWorld, WaitForSelectorOptions} from './IsolatedWorld.js';
import {ElementHandle} from './ElementHandle.js';
import {EventEmitter} from './EventEmitter.js';
import {EVALUATION_SCRIPT_URL, ExecutionContext} from './ExecutionContext.js';
Expand Down Expand Up @@ -530,7 +530,7 @@ export class FrameManager extends EventEmitter {
const frameId = auxData && auxData.frameId;
const frame =
typeof frameId === 'string' ? this.#frames.get(frameId) : undefined;
let world: DOMWorld | undefined;
let world: IsolatedWorld | undefined;
if (frame) {
// Only care about execution contexts created for the current session.
if (frame._client() !== session) {
Expand Down Expand Up @@ -763,11 +763,11 @@ export class Frame {
/**
* @internal
*/
_mainWorld!: DOMWorld;
_mainWorld!: IsolatedWorld;
/**
* @internal
*/
_secondaryWorld!: DOMWorld;
_secondaryWorld!: IsolatedWorld;
/**
* @internal
*/
Expand Down Expand Up @@ -803,13 +803,13 @@ export class Frame {
*/
_updateClient(client: CDPSession): void {
this.#client = client;
this._mainWorld = new DOMWorld(
this._mainWorld = new IsolatedWorld(
this.#client,
this._frameManager,
this,
this._frameManager._timeoutSettings
);
this._secondaryWorld = new DOMWorld(
this._secondaryWorld = new IsolatedWorld(
this.#client,
this._frameManager,
this,
Expand Down
35 changes: 19 additions & 16 deletions src/common/DOMWorld.ts → src/common/IsolatedWorld.ts
Expand Up @@ -72,7 +72,7 @@ export interface PageBinding {
/**
* @internal
*/
export class DOMWorld {
export class IsolatedWorld {
#frameManager: FrameManager;
#client: CDPSession;
#frame: Frame;
Expand Down Expand Up @@ -564,7 +564,7 @@ export class DOMWorld {
// Previous operation added the binding so we are done.
if (
this.#ctxBindings.has(
DOMWorld.#bindingIdentifier(name, context._contextId)
IsolatedWorld.#bindingIdentifier(name, context._contextId)
)
) {
return;
Expand Down Expand Up @@ -604,7 +604,7 @@ export class DOMWorld {
}
}
this.#ctxBindings.add(
DOMWorld.#bindingIdentifier(name, context._contextId)
IsolatedWorld.#bindingIdentifier(name, context._contextId)
);
};

Expand Down Expand Up @@ -632,7 +632,7 @@ export class DOMWorld {
if (
type !== 'internal' ||
!this.#ctxBindings.has(
DOMWorld.#bindingIdentifier(name, context._contextId)
IsolatedWorld.#bindingIdentifier(name, context._contextId)
)
) {
return;
Expand Down Expand Up @@ -695,7 +695,7 @@ export class DOMWorld {
return checkWaitForOptions(node, waitForVisible, waitForHidden);
}
const waitTaskOptions: WaitTaskOptions = {
domWorld: this,
isolatedWorld: this,
predicateBody: makePredicateString(predicate, queryOne),
predicateAcceptsContextElement: true,
title,
Expand Down Expand Up @@ -723,7 +723,7 @@ export class DOMWorld {
const {polling = 'raf', timeout = this.#timeoutSettings.timeout()} =
options;
const waitTaskOptions: WaitTaskOptions = {
domWorld: this,
isolatedWorld: this,
predicateBody: pageFunction,
predicateAcceptsContextElement: false,
title: 'function',
Expand Down Expand Up @@ -769,7 +769,7 @@ export class DOMWorld {
* @internal
*/
export interface WaitTaskOptions {
domWorld: DOMWorld;
isolatedWorld: IsolatedWorld;
predicateBody: Function | string;
predicateAcceptsContextElement: boolean;
title: string;
Expand All @@ -786,7 +786,7 @@ const noop = (): void => {};
* @internal
*/
export class WaitTask {
#domWorld: DOMWorld;
#isolatedWorld: IsolatedWorld;
#polling: 'raf' | 'mutation' | number;
#timeout: number;
#predicateBody: string;
Expand Down Expand Up @@ -824,7 +824,7 @@ export class WaitTask {
return `return (${predicateBody})(...args);`;
}

this.#domWorld = options.domWorld;
this.#isolatedWorld = options.isolatedWorld;
this.#polling = options.polling;
this.#timeout = options.timeout;
this.#root = options.root || null;
Expand All @@ -834,9 +834,9 @@ export class WaitTask {
this.#args = options.args;
this.#binding = options.binding;
this.#runCount = 0;
this.#domWorld._waitTasks.add(this);
this.#isolatedWorld._waitTasks.add(this);
if (this.#binding) {
this.#domWorld._boundFunctions.set(
this.#isolatedWorld._boundFunctions.set(
this.#binding.name,
this.#binding.pptrFunction
);
Expand Down Expand Up @@ -868,12 +868,15 @@ export class WaitTask {
const runCount = ++this.#runCount;
let success: JSHandle | null = null;
let error: Error | null = null;
const context = await this.#domWorld.executionContext();
const context = await this.#isolatedWorld.executionContext();
if (this.#terminated || runCount !== this.#runCount) {
return;
}
if (this.#binding) {
await this.#domWorld._addBindingToContext(context, this.#binding.name);
await this.#isolatedWorld._addBindingToContext(
context,
this.#binding.name
);
}
if (this.#terminated || runCount !== this.#runCount) {
return;
Expand Down Expand Up @@ -904,7 +907,7 @@ export class WaitTask {
// throw an error - ignore this predicate run altogether.
if (
!error &&
(await this.#domWorld
(await this.#isolatedWorld
.evaluate(s => {
return !s;
}, success)
Expand All @@ -922,7 +925,7 @@ export class WaitTask {
if (error.message.includes('TypeError: binding is not a function')) {
return this.rerun();
}
// When frame is detached the task should have been terminated by the DOMWorld.
// When frame is detached the task should have been terminated by the IsolatedWorld.
// This can fail if we were adding this task while the frame was detached,
// so we terminate here instead.
if (
Expand Down Expand Up @@ -960,7 +963,7 @@ export class WaitTask {

#cleanup(): void {
this.#timeoutTimer !== undefined && clearTimeout(this.#timeoutTimer);
this.#domWorld._waitTasks.delete(this);
this.#isolatedWorld._waitTasks.delete(this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/Page.ts
Expand Up @@ -23,7 +23,7 @@ import {CDPSession, CDPSessionEmittedEvents} from './Connection.js';
import {ConsoleMessage, ConsoleMessageType} from './ConsoleMessage.js';
import {Coverage} from './Coverage.js';
import {Dialog} from './Dialog.js';
import {WaitForSelectorOptions} from './DOMWorld.js';
import {WaitForSelectorOptions} from './IsolatedWorld.js';
import {ElementHandle} from './ElementHandle.js';
import {EmulationManager} from './EmulationManager.js';
import {EventEmitter, Handler} from './EventEmitter.js';
Expand Down
8 changes: 4 additions & 4 deletions src/common/QueryHandler.ts
Expand Up @@ -15,7 +15,7 @@
*/

import {ariaHandler} from './AriaQueryHandler.js';
import {DOMWorld, WaitForSelectorOptions} from './DOMWorld.js';
import {IsolatedWorld, WaitForSelectorOptions} from './IsolatedWorld.js';
import {ElementHandle} from './ElementHandle.js';
import {JSHandle} from './JSHandle.js';

Expand Down Expand Up @@ -72,7 +72,7 @@ export interface InternalQueryHandler {
* Akin to {@link Window.prototype.querySelectorAll}.
*/
waitFor?: (
domWorld: DOMWorld,
isolatedWorld: IsolatedWorld,
selector: string,
options: WaitForSelectorOptions
) => Promise<ElementHandle<Node> | null>;
Expand All @@ -95,11 +95,11 @@ function internalizeCustomQueryHandler(
return null;
};
internalHandler.waitFor = (
domWorld: DOMWorld,
isolatedWorld: IsolatedWorld,
selector: string,
options: WaitForSelectorOptions
) => {
return domWorld._waitForSelectorInPage(queryOne, selector, options);
return isolatedWorld._waitForSelectorInPage(queryOne, selector, options);
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Expand Up @@ -18,7 +18,6 @@ export * from './common/Connection.js';
export * from './common/ConnectionTransport.js';
export * from './common/ConsoleMessage.js';
export * from './common/Coverage.js';
export * from './common/DOMWorld.js';
export * from './common/Debug.js';
export * from './common/DeviceDescriptors.js';
export * from './common/Dialog.js';
Expand All @@ -33,6 +32,7 @@ export * from './common/FrameManager.js';
export * from './common/HTTPRequest.js';
export * from './common/HTTPResponse.js';
export * from './common/Input.js';
export * from './common/IsolatedWorld.js';
export * from './common/JSHandle.js';
export * from './common/LifecycleWatcher.js';
export * from './common/NetworkConditions.js';
Expand Down

0 comments on commit 837b10b

Please sign in to comment.