Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use custom disposable stack #10943

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/puppeteer-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
"ws": "8.14.1"
},
"devDependencies": {
"disposablestack": "1.1.1",
"mitt": "3.0.1",
"parsel-js": "1.1.2",
"rxjs": "7.8.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/puppeteer-core/src/api/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import {type ChildProcess} from 'child_process';

import {type Protocol} from 'devtools-protocol';

import {Symbol} from '../../third_party/disposablestack/disposablestack.js';
import {EventEmitter, type EventType} from '../common/EventEmitter.js';
import {debugError, waitWithTimeout} from '../common/util.js';
import {Deferred} from '../util/Deferred.js';
import {asyncDisposeSymbol, disposeSymbol} from '../util/disposable.js';

import type {BrowserContext} from './BrowserContext.js';
import type {Page} from './Page.js';
Expand Down Expand Up @@ -488,12 +488,12 @@ export abstract class Browser extends EventEmitter<BrowserEvents> {
abstract get connected(): boolean;

/** @internal */
[Symbol.dispose](): void {
[disposeSymbol](): void {
return void this.close().catch(debugError);
}

/** @internal */
[Symbol.asyncDispose](): Promise<void> {
[asyncDisposeSymbol](): Promise<void> {
return this.close();
}
}
5 changes: 3 additions & 2 deletions packages/puppeteer-core/src/api/BrowserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import {EventEmitter, type EventType} from '../common/EventEmitter.js';
import {debugError} from '../common/util.js';
import {asyncDisposeSymbol, disposeSymbol} from '../util/disposable.js';

import type {Browser, Permission} from './Browser.js';
import {type Page} from './Page.js';
Expand Down Expand Up @@ -226,12 +227,12 @@ export abstract class BrowserContext extends EventEmitter<BrowserContextEvents>
}

/** @internal */
[Symbol.dispose](): void {
[disposeSymbol](): void {
return void this.close().catch(debugError);
}

/** @internal */
[Symbol.asyncDispose](): Promise<void> {
[asyncDisposeSymbol](): Promise<void> {
return this.close();
}
}
6 changes: 3 additions & 3 deletions packages/puppeteer-core/src/api/JSHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

import type Protocol from 'devtools-protocol';

import {Symbol} from '../../third_party/disposablestack/disposablestack.js';
import {
type EvaluateFuncWith,
type HandleFor,
type HandleOr,
} from '../common/types.js';
import {debugError, withSourcePuppeteerURLIfNone} from '../common/util.js';
import {moveable, throwIfDisposed} from '../util/decorators.js';
import {disposeSymbol, asyncDisposeSymbol} from '../util/disposable.js';

import {type ElementHandle} from './ElementHandle.js';
import {type Realm} from './Realm.js';
Expand Down Expand Up @@ -217,12 +217,12 @@ export abstract class JSHandle<T = unknown> {
abstract remoteObject(): Protocol.Runtime.RemoteObject;

/** @internal */
[Symbol.dispose](): void {
[disposeSymbol](): void {
return void this.dispose().catch(debugError);
}

/** @internal */
[Symbol.asyncDispose](): Promise<void> {
[asyncDisposeSymbol](): Promise<void> {
return this.dispose();
}
}
5 changes: 3 additions & 2 deletions packages/puppeteer-core/src/api/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
import type {Viewport} from '../common/Viewport.js';
import {assert} from '../util/assert.js';
import {type Deferred} from '../util/Deferred.js';
import {asyncDisposeSymbol, disposeSymbol} from '../util/disposable.js';

import type {Browser} from './Browser.js';
import type {BrowserContext} from './BrowserContext.js';
Expand Down Expand Up @@ -2853,12 +2854,12 @@ export abstract class Page extends EventEmitter<PageEvents> {
}

/** @internal */
[Symbol.dispose](): void {
[disposeSymbol](): void {
return void this.close().catch(debugError);
}

/** @internal */
[Symbol.asyncDispose](): Promise<void> {
[asyncDisposeSymbol](): Promise<void> {
return this.close();
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/puppeteer-core/src/api/Realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
type InnerLazyParams,
} from '../common/types.js';
import {TaskManager, WaitTask} from '../common/WaitTask.js';
import {disposeSymbol} from '../util/disposable.js';

import {type ElementHandle} from './ElementHandle.js';
import {type Environment} from './Environment.js';
Expand Down Expand Up @@ -102,7 +103,7 @@ export abstract class Realm implements Disposable {

#disposed = false;
/** @internal */
[Symbol.dispose](): void {
[disposeSymbol](): void {
this.#disposed = true;
this.taskManager.terminateAll(
new Error('waitForFunction failed: frame got detached.')
Expand Down
7 changes: 4 additions & 3 deletions packages/puppeteer-core/src/bidi/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
waitWithTimeout,
} from '../common/util.js';
import {Deferred} from '../util/Deferred.js';
import {disposeSymbol} from '../util/disposable.js';

import {
getWaitUntilSingle,
Expand Down Expand Up @@ -250,15 +251,15 @@ export class BidiFrame extends Frame {
return this.#disposed;
}

[Symbol.dispose](): void {
[disposeSymbol](): void {
if (this.#disposed) {
return;
}
this.#disposed = true;
this.#abortDeferred.reject(new Error('Frame detached'));
this.#context.dispose();
this.sandboxes[MAIN_SANDBOX][Symbol.dispose]();
this.sandboxes[PUPPETEER_SANDBOX][Symbol.dispose]();
this.sandboxes[MAIN_SANDBOX][disposeSymbol]();
this.sandboxes[PUPPETEER_SANDBOX][disposeSymbol]();
}

#exposedFunctions = new Map<string, ExposeableFunction<never[], unknown>>();
Expand Down
1 change: 1 addition & 0 deletions packages/puppeteer-core/src/bidi/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
EventSubscription,
type EventType,
} from '../common/EventEmitter.js';
import {DisposableStack} from '../util/disposable.js';

import {type BidiConnection} from './Connection.js';
import {type BidiFrame} from './Frame.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/puppeteer-core/src/bidi/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
import {type Viewport} from '../common/Viewport.js';
import {assert} from '../util/assert.js';
import {Deferred} from '../util/Deferred.js';
import {disposeSymbol} from '../util/disposable.js';

import {type BidiBrowser} from './Browser.js';
import {type BidiBrowserContext} from './BrowserContext.js';
Expand Down Expand Up @@ -314,7 +315,7 @@ export class BidiPage extends Page {
for (const child of frame.childFrames()) {
this.#removeFramesRecursively(child);
}
frame[Symbol.dispose]();
frame[disposeSymbol]();
this.#networkManager.clearMapAfterFrameDispose(frame);
this.#frameTree.removeFrame(frame);
this.emit(PageEvent.FrameDetached, frame);
Expand Down
3 changes: 2 additions & 1 deletion packages/puppeteer-core/src/bidi/Realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isString,
} from '../common/util.js';
import type PuppeteerUtil from '../injected/injected.js';
import {disposeSymbol} from '../util/disposable.js';
import {stringifyFunction} from '../util/Function.js';

import {type BidiConnection} from './Connection.js';
Expand Down Expand Up @@ -198,7 +199,7 @@ export class BidiRealm extends EventEmitter<Record<EventType, any>> {
: createBidiHandle(sandbox, result.result);
}

[Symbol.dispose](): void {
[disposeSymbol](): void {
this.connection.off(
Bidi.ChromiumBidi.Script.EventNames.RealmCreated,
this.handleRealmCreated
Expand Down
1 change: 1 addition & 0 deletions packages/puppeteer-core/src/cdp/Binding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {JSHandle} from '../api/JSHandle.js';
import {debugError} from '../common/util.js';
import {DisposableStack} from '../util/disposable.js';
import {isErrorLike} from '../util/ErrorLike.js';

import {type ExecutionContext} from './ExecutionContext.js';
Expand Down
1 change: 1 addition & 0 deletions packages/puppeteer-core/src/cdp/Coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {type CDPSession} from '../api/CDPSession.js';
import {EventSubscription} from '../common/EventEmitter.js';
import {debugError, PuppeteerURL} from '../common/util.js';
import {assert} from '../util/assert.js';
import {DisposableStack} from '../util/disposable.js';

/**
* The CoverageEntry class represents one entry of the coverage report.
Expand Down
7 changes: 4 additions & 3 deletions packages/puppeteer-core/src/cdp/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {type Page, type WaitTimeoutOptions} from '../api/Page.js';
import {setPageContent} from '../common/util.js';
import {assert} from '../util/assert.js';
import {Deferred} from '../util/Deferred.js';
import {disposeSymbol} from '../util/disposable.js';
import {isErrorLike} from '../util/ErrorLike.js';

import {
Expand Down Expand Up @@ -338,12 +339,12 @@ export class CdpFrame extends Frame {
return this.#detached;
}

[Symbol.dispose](): void {
[disposeSymbol](): void {
if (this.#detached) {
return;
}
this.#detached = true;
this.worlds[MAIN_WORLD][Symbol.dispose]();
this.worlds[PUPPETEER_WORLD][Symbol.dispose]();
this.worlds[MAIN_WORLD][disposeSymbol]();
this.worlds[PUPPETEER_WORLD][disposeSymbol]();
}
}
3 changes: 2 additions & 1 deletion packages/puppeteer-core/src/cdp/FrameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {type TimeoutSettings} from '../common/TimeoutSettings.js';
import {debugError, PuppeteerURL, UTILITY_WORLD_NAME} from '../common/util.js';
import {assert} from '../util/assert.js';
import {Deferred} from '../util/Deferred.js';
import {disposeSymbol} from '../util/disposable.js';
import {isErrorLike} from '../util/ErrorLike.js';

import {CdpCDPSession} from './CDPSession.js';
Expand Down Expand Up @@ -561,7 +562,7 @@ export class FrameManager extends EventEmitter<FrameManagerEvents> {
for (const child of frame.childFrames()) {
this.#removeFramesRecursively(child);
}
frame[Symbol.dispose]();
frame[disposeSymbol]();
this._frameTree.removeFrame(frame);
this.emit(FrameManagerEvent.FrameDetached, frame);
frame.emit(FrameEvent.FrameDetached, frame);
Expand Down
5 changes: 3 additions & 2 deletions packages/puppeteer-core/src/cdp/IsolatedWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
withSourcePuppeteerURLIfNone,
} from '../common/util.js';
import {Deferred} from '../util/Deferred.js';
import {disposeSymbol} from '../util/disposable.js';

import {type Binding} from './Binding.js';
import {type ExecutionContext, createCdpHandle} from './ExecutionContext.js';
Expand Down Expand Up @@ -278,8 +279,8 @@ export class IsolatedWorld extends Realm {
return newHandle;
}

[Symbol.dispose](): void {
super[Symbol.dispose]();
[disposeSymbol](): void {
super[disposeSymbol]();
this.client.off('Runtime.bindingCalled', this.#onBindingCalled);
}
}
1 change: 1 addition & 0 deletions packages/puppeteer-core/src/cdp/LifecycleWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {type TimeoutError} from '../common/Errors.js';
import {EventSubscription} from '../common/EventEmitter.js';
import {assert} from '../util/assert.js';
import {Deferred} from '../util/Deferred.js';
import {DisposableStack} from '../util/disposable.js';

import {type CdpFrame} from './Frame.js';
import {FrameManagerEvent} from './FrameManager.js';
Expand Down
5 changes: 3 additions & 2 deletions packages/puppeteer-core/src/cdp/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type {Protocol} from 'devtools-protocol';

import {type CDPSession, CDPSessionEvent} from '../api/CDPSession.js';
import {CDPSessionEvent, type CDPSession} from '../api/CDPSession.js';
import type {Frame} from '../api/Frame.js';
import {
EventEmitter,
Expand All @@ -25,12 +25,13 @@ import {
} from '../common/EventEmitter.js';
import {debugError, isString} from '../common/util.js';
import {assert} from '../util/assert.js';
import {DisposableStack} from '../util/disposable.js';

import {CdpHTTPRequest} from './HTTPRequest.js';
import {CdpHTTPResponse} from './HTTPResponse.js';
import {
type FetchRequestId,
NetworkEventManager,
type FetchRequestId,
} from './NetworkEventManager.js';

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/puppeteer-core/src/common/EventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

import {Symbol} from '../../third_party/disposablestack/disposablestack.js';
import mitt, {
type Emitter,
type EventHandlerMap,
type EventType,
} from '../../third_party/mitt/index.js';
import {disposeSymbol} from '../util/disposable.js';

export {
/**
Expand Down Expand Up @@ -230,7 +230,7 @@ export class EventSubscription<
this.#target.on(this.#type, this.#handler);
}

[Symbol.dispose](): void {
[disposeSymbol](): void {
this.#target.off(this.#type, this.#handler);
}
}
3 changes: 2 additions & 1 deletion packages/puppeteer-core/src/common/HandleIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import {type JSHandle} from '../api/JSHandle.js';
import {DisposableStack, disposeSymbol} from '../util/disposable.js';

import {type AwaitableIterable, type HandleFor} from './types.js';

Expand Down Expand Up @@ -47,7 +48,7 @@ async function* fastTransposeIteratorHandle<T>(
using stack = new DisposableStack();
stack.defer(() => {
for (using handle of handles) {
handle[Symbol.dispose]();
handle[disposeSymbol]();
}
});
yield* handles;
Expand Down
3 changes: 2 additions & 1 deletion packages/puppeteer-core/src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {type Page} from '../api/Page.js';
import {isNode} from '../environment.js';
import {assert} from '../util/assert.js';
import {Deferred} from '../util/Deferred.js';
import {disposeSymbol} from '../util/disposable.js';
import {isErrorLike} from '../util/ErrorLike.js';

import {debug} from './Debug.js';
Expand Down Expand Up @@ -614,7 +615,7 @@ export class Mutex {
constructor(mutex: Mutex) {
this.#mutex = mutex;
}
[Symbol.dispose](): void {
[disposeSymbol](): void {
return this.#mutex.release();
}
};
Expand Down
1 change: 1 addition & 0 deletions packages/puppeteer-core/src/node/PipeTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {type ConnectionTransport} from '../common/ConnectionTransport.js';
import {EventSubscription} from '../common/EventEmitter.js';
import {debugError} from '../common/util.js';
import {assert} from '../util/assert.js';
import {DisposableStack} from '../util/disposable.js';

/**
* @internal
Expand Down