Update dashboard, kb, memory +4 more (+28 ~18 -1)
This commit is contained in:
46
node_modules/puppeteer-core/src/util/AsyncIterableUtil.ts
generated
vendored
Normal file
46
node_modules/puppeteer-core/src/util/AsyncIterableUtil.ts
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2023 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
import type {AwaitableIterable} from '../common/types.js';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export class AsyncIterableUtil {
|
||||
static async *map<T, U>(
|
||||
iterable: AwaitableIterable<T>,
|
||||
map: (item: T) => Promise<U>,
|
||||
): AsyncIterable<U> {
|
||||
for await (const value of iterable) {
|
||||
yield await map(value);
|
||||
}
|
||||
}
|
||||
|
||||
static async *flatMap<T, U>(
|
||||
iterable: AwaitableIterable<T>,
|
||||
map: (item: T) => AwaitableIterable<U>,
|
||||
): AsyncIterable<U> {
|
||||
for await (const value of iterable) {
|
||||
yield* map(value);
|
||||
}
|
||||
}
|
||||
|
||||
static async collect<T>(iterable: AwaitableIterable<T>): Promise<T[]> {
|
||||
const result = [];
|
||||
for await (const value of iterable) {
|
||||
result.push(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static async first<T>(
|
||||
iterable: AwaitableIterable<T>,
|
||||
): Promise<T | undefined> {
|
||||
for await (const value of iterable) {
|
||||
return value;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
128
node_modules/puppeteer-core/src/util/Deferred.ts
generated
vendored
Normal file
128
node_modules/puppeteer-core/src/util/Deferred.ts
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2024 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
import {TimeoutError} from '../common/Errors.js';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface DeferredOptions {
|
||||
message: string;
|
||||
timeout: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a deferred object along with the resolve/reject functions.
|
||||
*
|
||||
* If the deferred has not been resolved/rejected within the `timeout` period,
|
||||
* the deferred gets resolves with a timeout error. `timeout` has to be greater than 0 or
|
||||
* it is ignored.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export class Deferred<T, V extends Error = Error> {
|
||||
static create<R, X extends Error = Error>(
|
||||
opts?: DeferredOptions,
|
||||
): Deferred<R, X> {
|
||||
return new Deferred<R, X>(opts);
|
||||
}
|
||||
|
||||
static async race<R>(
|
||||
awaitables: Array<Promise<R> | Deferred<R>>,
|
||||
): Promise<R> {
|
||||
const deferredWithTimeout = new Set<Deferred<R>>();
|
||||
try {
|
||||
const promises = awaitables.map(value => {
|
||||
if (value instanceof Deferred) {
|
||||
if (value.#timeoutId) {
|
||||
deferredWithTimeout.add(value);
|
||||
}
|
||||
|
||||
return value.valueOrThrow();
|
||||
}
|
||||
|
||||
return value;
|
||||
});
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return await Promise.race(promises);
|
||||
} finally {
|
||||
for (const deferred of deferredWithTimeout) {
|
||||
// We need to stop the timeout else
|
||||
// Node.JS will keep running the event loop till the
|
||||
// timer executes
|
||||
deferred.reject(new Error('Timeout cleared'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#isResolved = false;
|
||||
#isRejected = false;
|
||||
#value: T | V | TimeoutError | undefined;
|
||||
// SAFETY: This is ensured by #taskPromise.
|
||||
#resolve!: (value: void) => void;
|
||||
// TODO: Switch to Promise.withResolvers with Node 22
|
||||
#taskPromise = new Promise<void>(resolve => {
|
||||
this.#resolve = resolve;
|
||||
});
|
||||
#timeoutId: ReturnType<typeof setTimeout> | undefined;
|
||||
#timeoutError: TimeoutError | undefined;
|
||||
|
||||
constructor(opts?: DeferredOptions) {
|
||||
if (opts && opts.timeout > 0) {
|
||||
this.#timeoutError = new TimeoutError(opts.message);
|
||||
this.#timeoutId = setTimeout(() => {
|
||||
this.reject(this.#timeoutError!);
|
||||
}, opts.timeout);
|
||||
}
|
||||
}
|
||||
|
||||
#finish(value: T | V | TimeoutError) {
|
||||
clearTimeout(this.#timeoutId);
|
||||
this.#value = value;
|
||||
this.#resolve();
|
||||
}
|
||||
|
||||
resolve(value: T): void {
|
||||
if (this.#isRejected || this.#isResolved) {
|
||||
return;
|
||||
}
|
||||
this.#isResolved = true;
|
||||
this.#finish(value);
|
||||
}
|
||||
|
||||
reject(error: V | TimeoutError): void {
|
||||
if (this.#isRejected || this.#isResolved) {
|
||||
return;
|
||||
}
|
||||
this.#isRejected = true;
|
||||
this.#finish(error);
|
||||
}
|
||||
|
||||
resolved(): boolean {
|
||||
return this.#isResolved;
|
||||
}
|
||||
|
||||
finished(): boolean {
|
||||
return this.#isResolved || this.#isRejected;
|
||||
}
|
||||
|
||||
value(): T | V | TimeoutError | undefined {
|
||||
return this.#value;
|
||||
}
|
||||
|
||||
#promise: Promise<T> | undefined;
|
||||
valueOrThrow(): Promise<T> {
|
||||
if (!this.#promise) {
|
||||
this.#promise = (async () => {
|
||||
await this.#taskPromise;
|
||||
if (this.#isRejected) {
|
||||
throw this.#value;
|
||||
}
|
||||
return this.#value as T;
|
||||
})();
|
||||
}
|
||||
return this.#promise;
|
||||
}
|
||||
}
|
||||
66
node_modules/puppeteer-core/src/util/ErrorLike.ts
generated
vendored
Normal file
66
node_modules/puppeteer-core/src/util/ErrorLike.ts
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type {ProtocolError} from '../common/Errors.js';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface ErrorLike extends Error {
|
||||
name: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function isErrorLike(obj: unknown): obj is ErrorLike {
|
||||
return (
|
||||
typeof obj === 'object' && obj !== null && 'name' in obj && 'message' in obj
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function isErrnoException(obj: unknown): obj is NodeJS.ErrnoException {
|
||||
return (
|
||||
isErrorLike(obj) &&
|
||||
('errno' in obj || 'code' in obj || 'path' in obj || 'syscall' in obj)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function rewriteError(
|
||||
error: ProtocolError,
|
||||
message: string,
|
||||
originalMessage?: string,
|
||||
): Error {
|
||||
error.message = message;
|
||||
error.originalMessage = originalMessage ?? error.originalMessage;
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function createProtocolErrorMessage(object: {
|
||||
error: {message: string; data: any; code: number};
|
||||
}): string {
|
||||
let message = object.error.message;
|
||||
// TODO: remove the type checks when we stop connecting to BiDi with a CDP
|
||||
// client.
|
||||
if (
|
||||
object.error &&
|
||||
typeof object.error === 'object' &&
|
||||
'data' in object.error
|
||||
) {
|
||||
message += ` ${object.error.data}`;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
95
node_modules/puppeteer-core/src/util/Function.ts
generated
vendored
Normal file
95
node_modules/puppeteer-core/src/util/Function.ts
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2023 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
const createdFunctions = new Map<string, (...args: unknown[]) => unknown>();
|
||||
|
||||
/**
|
||||
* Creates a function from a string.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export const createFunction = (
|
||||
functionValue: string,
|
||||
): ((...args: unknown[]) => unknown) => {
|
||||
let fn = createdFunctions.get(functionValue);
|
||||
if (fn) {
|
||||
return fn;
|
||||
}
|
||||
fn = new Function(`return ${functionValue}`)() as (
|
||||
...args: unknown[]
|
||||
) => unknown;
|
||||
createdFunctions.set(functionValue, fn);
|
||||
return fn;
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function stringifyFunction(fn: (...args: never) => unknown): string {
|
||||
let value = fn.toString();
|
||||
if (
|
||||
value.match(/^(async )*function(\(|\s)/) ||
|
||||
value.match(/^(async )*function\s*\*\s*/)
|
||||
) {
|
||||
return value;
|
||||
}
|
||||
const isArrow =
|
||||
value.startsWith('(') ||
|
||||
value.match(/^async\s*\(/) ||
|
||||
value.match(
|
||||
/^(async)*\s*(?:[$_\p{ID_Start}])(?:[$\u200C\u200D\p{ID_Continue}])*\s*=>/u,
|
||||
);
|
||||
if (isArrow) {
|
||||
return value;
|
||||
}
|
||||
// This means we might have a function shorthand (e.g. `test(){}`). Let's
|
||||
// try prefixing.
|
||||
let prefix = 'function ';
|
||||
if (value.startsWith('async ')) {
|
||||
prefix = `async ${prefix}`;
|
||||
value = value.substring('async '.length);
|
||||
}
|
||||
return `${prefix}${value}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces `PLACEHOLDER`s with the given replacements.
|
||||
*
|
||||
* All replacements must be valid JS code.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* interpolateFunction(() => PLACEHOLDER('test'), {test: 'void 0'});
|
||||
* // Equivalent to () => void 0
|
||||
* ```
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export const interpolateFunction = <T extends (...args: never[]) => unknown>(
|
||||
fn: T,
|
||||
replacements: Record<string, string>,
|
||||
): T => {
|
||||
let value = stringifyFunction(fn);
|
||||
for (const [name, jsValue] of Object.entries(replacements)) {
|
||||
value = value.replace(
|
||||
new RegExp(`PLACEHOLDER\\(\\s*(?:'${name}'|"${name}")\\s*\\)`, 'g'),
|
||||
// Wrapping this ensures tersers that accidentally inline PLACEHOLDER calls
|
||||
// are still valid. Without, we may get calls like ()=>{...}() which is
|
||||
// not valid.
|
||||
`(${jsValue})`,
|
||||
);
|
||||
}
|
||||
return createFunction(value) as unknown as T;
|
||||
};
|
||||
|
||||
declare global {
|
||||
/**
|
||||
* Used for interpolation with {@link interpolateFunction}.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
function PLACEHOLDER<T>(name: string): T;
|
||||
}
|
||||
51
node_modules/puppeteer-core/src/util/Mutex.ts
generated
vendored
Normal file
51
node_modules/puppeteer-core/src/util/Mutex.ts
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2024 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
import {Deferred} from './Deferred.js';
|
||||
import {disposeSymbol} from './disposable.js';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export class Mutex {
|
||||
static Guard = class Guard {
|
||||
#mutex: Mutex;
|
||||
#onRelease?: () => void;
|
||||
constructor(mutex: Mutex, onRelease?: () => void) {
|
||||
this.#mutex = mutex;
|
||||
this.#onRelease = onRelease;
|
||||
}
|
||||
[disposeSymbol](): void {
|
||||
this.#onRelease?.();
|
||||
return this.#mutex.release();
|
||||
}
|
||||
};
|
||||
|
||||
#locked = false;
|
||||
#acquirers: Array<() => void> = [];
|
||||
|
||||
// This is FIFO.
|
||||
async acquire(
|
||||
onRelease?: () => void,
|
||||
): Promise<InstanceType<typeof Mutex.Guard>> {
|
||||
if (!this.#locked) {
|
||||
this.#locked = true;
|
||||
return new Mutex.Guard(this);
|
||||
}
|
||||
const deferred = Deferred.create<void>();
|
||||
this.#acquirers.push(deferred.resolve.bind(deferred));
|
||||
await deferred.valueOrThrow();
|
||||
return new Mutex.Guard(this, onRelease);
|
||||
}
|
||||
|
||||
release(): void {
|
||||
const resolve = this.#acquirers.shift();
|
||||
if (!resolve) {
|
||||
this.#locked = false;
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
21
node_modules/puppeteer-core/src/util/assert.ts
generated
vendored
Normal file
21
node_modules/puppeteer-core/src/util/assert.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Asserts that the given value is truthy.
|
||||
* @param value - some conditional statement
|
||||
* @param message - the error message to throw if the value is not truthy.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export const assert: (value: unknown, message?: string) => asserts value = (
|
||||
value,
|
||||
message,
|
||||
) => {
|
||||
if (!value) {
|
||||
throw new Error(message);
|
||||
}
|
||||
};
|
||||
210
node_modules/puppeteer-core/src/util/decorators.ts
generated
vendored
Normal file
210
node_modules/puppeteer-core/src/util/decorators.ts
generated
vendored
Normal file
@@ -0,0 +1,210 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2023 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type {EventType} from '../common/EventEmitter.js';
|
||||
import type {EventEmitter} from '../common/EventEmitter.js';
|
||||
import type {Disposed, Moveable} from '../common/types.js';
|
||||
|
||||
import {asyncDisposeSymbol, disposeSymbol} from './disposable.js';
|
||||
import {Mutex} from './Mutex.js';
|
||||
|
||||
const instances = new WeakSet<object>();
|
||||
|
||||
export function moveable<
|
||||
Class extends abstract new (...args: never[]) => Moveable,
|
||||
>(Class: Class, _: ClassDecoratorContext<Class>): Class {
|
||||
let hasDispose = false;
|
||||
if (Class.prototype[disposeSymbol]) {
|
||||
const dispose = Class.prototype[disposeSymbol];
|
||||
Class.prototype[disposeSymbol] = function (this: InstanceType<Class>) {
|
||||
if (instances.has(this)) {
|
||||
instances.delete(this);
|
||||
return;
|
||||
}
|
||||
return dispose.call(this);
|
||||
};
|
||||
hasDispose = true;
|
||||
}
|
||||
if (Class.prototype[asyncDisposeSymbol]) {
|
||||
const asyncDispose = Class.prototype[asyncDisposeSymbol];
|
||||
Class.prototype[asyncDisposeSymbol] = function (this: InstanceType<Class>) {
|
||||
if (instances.has(this)) {
|
||||
instances.delete(this);
|
||||
return;
|
||||
}
|
||||
return asyncDispose.call(this);
|
||||
};
|
||||
hasDispose = true;
|
||||
}
|
||||
if (hasDispose) {
|
||||
Class.prototype.move = function (
|
||||
this: InstanceType<Class>,
|
||||
): InstanceType<Class> {
|
||||
instances.add(this);
|
||||
return this;
|
||||
};
|
||||
}
|
||||
return Class;
|
||||
}
|
||||
|
||||
export function throwIfDisposed<This extends Disposed>(
|
||||
message: (value: This) => string = value => {
|
||||
return `Attempted to use disposed ${value.constructor.name}.`;
|
||||
},
|
||||
) {
|
||||
return (target: (this: This, ...args: any[]) => any, _: unknown) => {
|
||||
return function (this: This, ...args: any[]): any {
|
||||
if (this.disposed) {
|
||||
throw new Error(message(this));
|
||||
}
|
||||
return target.call(this, ...args);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function inertIfDisposed<This extends Disposed>(
|
||||
target: (this: This, ...args: any[]) => any,
|
||||
_: unknown,
|
||||
) {
|
||||
return function (this: This, ...args: any[]): any {
|
||||
if (this.disposed) {
|
||||
return;
|
||||
}
|
||||
return target.call(this, ...args);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The decorator only invokes the target if the target has not been invoked with
|
||||
* the same arguments before. The decorated method throws an error if it's
|
||||
* invoked with a different number of elements: if you decorate a method, it
|
||||
* should have the same number of arguments
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export function invokeAtMostOnceForArguments(
|
||||
target: (this: unknown, ...args: any[]) => any,
|
||||
_: unknown,
|
||||
): typeof target {
|
||||
const cache = new WeakMap();
|
||||
let cacheDepth = -1;
|
||||
return function (this: unknown, ...args: unknown[]) {
|
||||
if (cacheDepth === -1) {
|
||||
cacheDepth = args.length;
|
||||
}
|
||||
if (cacheDepth !== args.length) {
|
||||
throw new Error(
|
||||
'Memoized method was called with the wrong number of arguments',
|
||||
);
|
||||
}
|
||||
let freshArguments = false;
|
||||
let cacheIterator = cache;
|
||||
for (const arg of args) {
|
||||
if (cacheIterator.has(arg as object)) {
|
||||
cacheIterator = cacheIterator.get(arg as object)!;
|
||||
} else {
|
||||
freshArguments = true;
|
||||
cacheIterator.set(arg as object, new WeakMap());
|
||||
cacheIterator = cacheIterator.get(arg as object)!;
|
||||
}
|
||||
}
|
||||
if (!freshArguments) {
|
||||
return;
|
||||
}
|
||||
return target.call(this, ...args);
|
||||
};
|
||||
}
|
||||
|
||||
export function guarded<T extends object>(
|
||||
getKey = function (this: T): object {
|
||||
return this;
|
||||
},
|
||||
) {
|
||||
return (
|
||||
target: (this: T, ...args: any[]) => Promise<any>,
|
||||
_: ClassMethodDecoratorContext<T>,
|
||||
): typeof target => {
|
||||
const mutexes = new WeakMap<object, Mutex>();
|
||||
return async function (...args) {
|
||||
const key = getKey.call(this);
|
||||
let mutex = mutexes.get(key);
|
||||
if (!mutex) {
|
||||
mutex = new Mutex();
|
||||
mutexes.set(key, mutex);
|
||||
}
|
||||
await using _ = await mutex.acquire();
|
||||
return await target.call(this, ...args);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
const bubbleHandlers = new WeakMap<object, Map<any, any>>();
|
||||
const bubbleInitializer = function <
|
||||
T extends EventType[],
|
||||
This extends EventEmitter<any>,
|
||||
>(this: This, events?: T) {
|
||||
const handlers = bubbleHandlers.get(this) ?? new Map();
|
||||
if (handlers.has(events)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const handler =
|
||||
events !== undefined
|
||||
? (type: EventType, event: unknown) => {
|
||||
if (events.includes(type)) {
|
||||
this.emit(type, event);
|
||||
}
|
||||
}
|
||||
: (type: EventType, event: unknown) => {
|
||||
this.emit(type, event);
|
||||
};
|
||||
|
||||
handlers.set(events, handler);
|
||||
bubbleHandlers.set(this, handlers);
|
||||
};
|
||||
/**
|
||||
* Event emitter fields marked with `bubble` will have their events bubble up
|
||||
* the field owner.
|
||||
*/
|
||||
// The type is too complicated to type.
|
||||
export function bubble<T extends EventType[]>(events?: T) {
|
||||
return <This extends EventEmitter<any>, Value extends EventEmitter<any>>(
|
||||
{set, get}: ClassAccessorDecoratorTarget<This, Value>,
|
||||
context: ClassAccessorDecoratorContext<This, Value>,
|
||||
): ClassAccessorDecoratorResult<This, Value> => {
|
||||
context.addInitializer(function () {
|
||||
return bubbleInitializer.apply(this, [events]);
|
||||
});
|
||||
return {
|
||||
set(emitter) {
|
||||
const handler = bubbleHandlers.get(this)!.get(events)!;
|
||||
|
||||
// In case we are re-setting.
|
||||
const oldEmitter = get.call(this);
|
||||
if (oldEmitter !== undefined) {
|
||||
oldEmitter.off('*', handler);
|
||||
}
|
||||
|
||||
if (emitter === undefined) {
|
||||
return;
|
||||
}
|
||||
emitter.on('*', handler);
|
||||
set.call(this, emitter);
|
||||
},
|
||||
init(emitter) {
|
||||
if (emitter === undefined) {
|
||||
return emitter;
|
||||
}
|
||||
|
||||
bubbleInitializer.apply(this, [events]);
|
||||
|
||||
const handler = bubbleHandlers.get(this)!.get(events)!;
|
||||
emitter.on('*', handler as any);
|
||||
return emitter;
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
396
node_modules/puppeteer-core/src/util/disposable.ts
generated
vendored
Normal file
396
node_modules/puppeteer-core/src/util/disposable.ts
generated
vendored
Normal file
@@ -0,0 +1,396 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2023 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
declare global {
|
||||
interface SymbolConstructor {
|
||||
/**
|
||||
* A method that is used to release resources held by an object. Called by
|
||||
* the semantics of the `using` statement.
|
||||
*/
|
||||
readonly dispose: unique symbol;
|
||||
|
||||
/**
|
||||
* A method that is used to asynchronously release resources held by an
|
||||
* object. Called by the semantics of the `await using` statement.
|
||||
*/
|
||||
readonly asyncDispose: unique symbol;
|
||||
}
|
||||
|
||||
interface Disposable {
|
||||
[Symbol.dispose](): void;
|
||||
}
|
||||
|
||||
interface AsyncDisposable {
|
||||
[Symbol.asyncDispose](): PromiseLike<void>;
|
||||
}
|
||||
}
|
||||
|
||||
(Symbol as any).dispose ??= Symbol('dispose');
|
||||
(Symbol as any).asyncDispose ??= Symbol('asyncDispose');
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const disposeSymbol: typeof Symbol.dispose = Symbol.dispose;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const asyncDisposeSymbol: typeof Symbol.asyncDispose =
|
||||
Symbol.asyncDispose;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export class DisposableStackPolyfill {
|
||||
#disposed = false;
|
||||
#stack: Disposable[] = [];
|
||||
|
||||
/**
|
||||
* Returns a value indicating whether the stack has been disposed.
|
||||
*/
|
||||
get disposed(): boolean {
|
||||
return this.#disposed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for `[Symbol.dispose]()`.
|
||||
*/
|
||||
dispose(): void {
|
||||
this[disposeSymbol]();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a disposable resource to the top of stack, returning the resource.
|
||||
* Has no effect if provided `null` or `undefined`.
|
||||
*
|
||||
* @param value - A `Disposable` object, `null`, or `undefined`.
|
||||
* `null` and `undefined` will not be added, but will be returned.
|
||||
* @returns The provided `value`.
|
||||
*/
|
||||
use<T extends Disposable | null | undefined>(value: T): T {
|
||||
if (value && typeof value[disposeSymbol] === 'function') {
|
||||
this.#stack.push(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a non-disposable resource and a disposal callback to the top of the stack.
|
||||
*
|
||||
* @param value - A resource to be disposed.
|
||||
* @param onDispose - A callback invoked to dispose the provided value.
|
||||
* Will be invoked with `value` as the first parameter.
|
||||
* @returns The provided `value`.
|
||||
*/
|
||||
adopt<T>(value: T, onDispose: (value: T) => void): T {
|
||||
this.#stack.push({
|
||||
[disposeSymbol]() {
|
||||
onDispose(value);
|
||||
},
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a disposal callback to the top of the stack to be invoked when stack is disposed.
|
||||
* @param onDispose - A callback to invoke when this object is disposed.
|
||||
*/
|
||||
defer(onDispose: () => void): void {
|
||||
this.#stack.push({
|
||||
[disposeSymbol]() {
|
||||
onDispose();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Move all resources out of this stack and into a new `DisposableStack`, and
|
||||
* marks this stack as disposed.
|
||||
* @returns The new `DisposableStack`.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* class C {
|
||||
* #res1: Disposable;
|
||||
* #res2: Disposable;
|
||||
* #disposables: DisposableStack;
|
||||
* constructor() {
|
||||
* // stack will be disposed when exiting constructor for any reason
|
||||
* using stack = new DisposableStack();
|
||||
*
|
||||
* // get first resource
|
||||
* this.#res1 = stack.use(getResource1());
|
||||
*
|
||||
* // get second resource. If this fails, both `stack` and `#res1` will be disposed.
|
||||
* this.#res2 = stack.use(getResource2());
|
||||
*
|
||||
* // all operations succeeded, move resources out of `stack` so that
|
||||
* // they aren't disposed when constructor exits
|
||||
* this.#disposables = stack.move();
|
||||
* }
|
||||
*
|
||||
* [disposeSymbol]() {
|
||||
* this.#disposables.dispose();
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
move(): DisposableStackPolyfill {
|
||||
if (this.#disposed) {
|
||||
throw new ReferenceError('A disposed stack can not use anything new');
|
||||
}
|
||||
const stack = new DisposableStackPolyfill();
|
||||
stack.#stack = this.#stack;
|
||||
this.#stack = [];
|
||||
this.#disposed = true;
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes each resource in the stack in last-in-first-out (LIFO) manner.
|
||||
*/
|
||||
[disposeSymbol](): void {
|
||||
if (this.#disposed) {
|
||||
return;
|
||||
}
|
||||
this.#disposed = true;
|
||||
const errors: unknown[] = [];
|
||||
for (const resource of this.#stack.reverse()) {
|
||||
try {
|
||||
resource[disposeSymbol]();
|
||||
} catch (e) {
|
||||
errors.push(e);
|
||||
}
|
||||
}
|
||||
if (errors.length === 1) {
|
||||
throw errors[0];
|
||||
} else if (errors.length > 1) {
|
||||
let suppressed = null;
|
||||
for (const error of errors) {
|
||||
if (suppressed === null) {
|
||||
suppressed = error;
|
||||
} else {
|
||||
suppressed = new SuppressedErrorPolyfill(error, suppressed);
|
||||
}
|
||||
}
|
||||
throw suppressed;
|
||||
}
|
||||
}
|
||||
|
||||
readonly [Symbol.toStringTag] = 'DisposableStack';
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const DisposableStack: typeof DisposableStackPolyfill =
|
||||
(globalThis.DisposableStack as any) ?? DisposableStackPolyfill;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export class AsyncDisposableStackPolyfill {
|
||||
#disposed = false;
|
||||
#stack: AsyncDisposable[] = [];
|
||||
|
||||
/**
|
||||
* Returns a value indicating whether the stack has been disposed.
|
||||
*/
|
||||
get disposed(): boolean {
|
||||
return this.#disposed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for `[Symbol.asyncDispose]()`.
|
||||
*/
|
||||
async disposeAsync(): Promise<void> {
|
||||
await this[asyncDisposeSymbol]();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a AsyncDisposable resource to the top of stack, returning the resource.
|
||||
* Has no effect if provided `null` or `undefined`.
|
||||
*
|
||||
* @param value - A `AsyncDisposable` object, `null`, or `undefined`.
|
||||
* `null` and `undefined` will not be added, but will be returned.
|
||||
* @returns The provided `value`.
|
||||
*/
|
||||
use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T {
|
||||
if (value) {
|
||||
const asyncDispose = (value as AsyncDisposable)[asyncDisposeSymbol];
|
||||
const dispose = (value as Disposable)[disposeSymbol];
|
||||
|
||||
if (typeof asyncDispose === 'function') {
|
||||
this.#stack.push(value as AsyncDisposable);
|
||||
} else if (typeof dispose === 'function') {
|
||||
this.#stack.push({
|
||||
[asyncDisposeSymbol]: async () => {
|
||||
(value as Disposable)[disposeSymbol]();
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a non-disposable resource and a disposal callback to the top of the stack.
|
||||
*
|
||||
* @param value - A resource to be disposed.
|
||||
* @param onDispose - A callback invoked to dispose the provided value.
|
||||
* Will be invoked with `value` as the first parameter.
|
||||
* @returns The provided `value`.
|
||||
*/
|
||||
adopt<T>(value: T, onDispose: (value: T) => Promise<void>): T {
|
||||
this.#stack.push({
|
||||
[asyncDisposeSymbol]() {
|
||||
return onDispose(value);
|
||||
},
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a disposal callback to the top of the stack to be invoked when stack is disposed.
|
||||
* @param onDispose - A callback to invoke when this object is disposed.
|
||||
*/
|
||||
defer(onDispose: () => Promise<void>): void {
|
||||
this.#stack.push({
|
||||
[asyncDisposeSymbol]() {
|
||||
return onDispose();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Move all resources out of this stack and into a new `DisposableStack`, and
|
||||
* marks this stack as disposed.
|
||||
* @returns The new `AsyncDisposableStack`.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* class C {
|
||||
* #res1: Disposable;
|
||||
* #res2: Disposable;
|
||||
* #disposables: DisposableStack;
|
||||
* constructor() {
|
||||
* // stack will be disposed when exiting constructor for any reason
|
||||
* using stack = new DisposableStack();
|
||||
*
|
||||
* // get first resource
|
||||
* this.#res1 = stack.use(getResource1());
|
||||
*
|
||||
* // get second resource. If this fails, both `stack` and `#res1` will be disposed.
|
||||
* this.#res2 = stack.use(getResource2());
|
||||
*
|
||||
* // all operations succeeded, move resources out of `stack` so that
|
||||
* // they aren't disposed when constructor exits
|
||||
* this.#disposables = stack.move();
|
||||
* }
|
||||
*
|
||||
* [disposeSymbol]() {
|
||||
* this.#disposables.dispose();
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
move(): AsyncDisposableStackPolyfill {
|
||||
if (this.#disposed) {
|
||||
throw new ReferenceError('A disposed stack can not use anything new');
|
||||
}
|
||||
const stack = new AsyncDisposableStackPolyfill();
|
||||
stack.#stack = this.#stack;
|
||||
this.#stack = [];
|
||||
this.#disposed = true;
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes each resource in the stack in last-in-first-out (LIFO) manner.
|
||||
*/
|
||||
async [asyncDisposeSymbol](): Promise<void> {
|
||||
if (this.#disposed) {
|
||||
return;
|
||||
}
|
||||
this.#disposed = true;
|
||||
const errors: unknown[] = [];
|
||||
for (const resource of this.#stack.reverse()) {
|
||||
try {
|
||||
await resource[asyncDisposeSymbol]();
|
||||
} catch (e) {
|
||||
errors.push(e);
|
||||
}
|
||||
}
|
||||
if (errors.length === 1) {
|
||||
throw errors[0];
|
||||
} else if (errors.length > 1) {
|
||||
let suppressed = null;
|
||||
for (const error of errors) {
|
||||
if (suppressed === null) {
|
||||
suppressed = error;
|
||||
} else {
|
||||
suppressed = new SuppressedErrorPolyfill(error, suppressed);
|
||||
}
|
||||
}
|
||||
throw suppressed;
|
||||
}
|
||||
}
|
||||
|
||||
readonly [Symbol.toStringTag] = 'AsyncDisposableStack';
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const AsyncDisposableStack: typeof AsyncDisposableStackPolyfill =
|
||||
(globalThis.AsyncDisposableStack as any) ?? AsyncDisposableStackPolyfill;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Represents an error that occurs when multiple errors are thrown during
|
||||
* the disposal of resources. This class encapsulates the primary error and
|
||||
* any suppressed errors that occurred subsequently.
|
||||
*/
|
||||
class SuppressedErrorPolyfill extends Error {
|
||||
#error: unknown;
|
||||
#suppressed: unknown;
|
||||
|
||||
constructor(
|
||||
error: unknown,
|
||||
suppressed: unknown,
|
||||
message = 'An error was suppressed during disposal',
|
||||
) {
|
||||
super(message);
|
||||
this.name = 'SuppressedError';
|
||||
this.#error = error;
|
||||
this.#suppressed = suppressed;
|
||||
}
|
||||
|
||||
/**
|
||||
* The primary error that occurred during disposal.
|
||||
*/
|
||||
get error(): unknown {
|
||||
return this.#error;
|
||||
}
|
||||
|
||||
/**
|
||||
* The suppressed error i.e. the error that was suppressed
|
||||
* because it occurred later in the flow after the original error.
|
||||
*/
|
||||
get suppressed(): unknown {
|
||||
return this.#suppressed;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const SuppressedError: typeof SuppressedErrorPolyfill =
|
||||
(globalThis.SuppressedError as any) ?? SuppressedErrorPolyfill;
|
||||
71
node_modules/puppeteer-core/src/util/encoding.ts
generated
vendored
Normal file
71
node_modules/puppeteer-core/src/util/encoding.ts
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2024 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function stringToTypedArray(
|
||||
string: string,
|
||||
base64Encoded = false,
|
||||
): Uint8Array {
|
||||
if (base64Encoded) {
|
||||
// TODO: use
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64
|
||||
// once available.
|
||||
if (typeof Buffer === 'function') {
|
||||
return Buffer.from(string, 'base64');
|
||||
}
|
||||
return Uint8Array.from(atob(string), m => {
|
||||
return m.codePointAt(0)!;
|
||||
});
|
||||
}
|
||||
return new TextEncoder().encode(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function stringToBase64(str: string): string {
|
||||
return typedArrayToBase64(new TextEncoder().encode(str));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function typedArrayToBase64(typedArray: Uint8Array): string {
|
||||
// chunkSize should be less V8 limit on number of arguments!
|
||||
// https://github.com/v8/v8/blob/d3de848bea727518aee94dd2fd42ba0b62037a27/src/objects/code.h#L444
|
||||
const chunkSize = 65534;
|
||||
const chunks = [];
|
||||
|
||||
for (let i = 0; i < typedArray.length; i += chunkSize) {
|
||||
const chunk = typedArray.subarray(i, i + chunkSize);
|
||||
chunks.push(String.fromCodePoint.apply(null, chunk as unknown as number[]));
|
||||
}
|
||||
|
||||
const binaryString = chunks.join('');
|
||||
return btoa(binaryString);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function mergeUint8Arrays(items: Uint8Array[]): Uint8Array {
|
||||
let length = 0;
|
||||
for (const item of items) {
|
||||
length += item.length;
|
||||
}
|
||||
|
||||
// Create a new array with total length and merge all source arrays.
|
||||
const result = new Uint8Array(length);
|
||||
let offset = 0;
|
||||
for (const item of items) {
|
||||
result.set(item, offset);
|
||||
offset += item.length;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
23
node_modules/puppeteer-core/src/util/incremental-id-generator.ts
generated
vendored
Normal file
23
node_modules/puppeteer-core/src/util/incremental-id-generator.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2024 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function createIncrementalIdGenerator(): GetIdFn {
|
||||
let id = 0;
|
||||
return (): number => {
|
||||
if (id === Number.MAX_SAFE_INTEGER) {
|
||||
id = 0;
|
||||
}
|
||||
return ++id;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type GetIdFn = () => number;
|
||||
13
node_modules/puppeteer-core/src/util/util.ts
generated
vendored
Normal file
13
node_modules/puppeteer-core/src/util/util.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
export * from './assert.js';
|
||||
export * from './Deferred.js';
|
||||
export * from './Mutex.js';
|
||||
export * from './ErrorLike.js';
|
||||
export * from './AsyncIterableUtil.js';
|
||||
export * from './disposable.js';
|
||||
export * from './incremental-id-generator.js';
|
||||
10
node_modules/puppeteer-core/src/util/version.ts
generated
vendored
Normal file
10
node_modules/puppeteer-core/src/util/version.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// If moved update release-please config
|
||||
// x-release-please-start-version
|
||||
export const packageVersion = '24.37.1';
|
||||
// x-release-please-end
|
||||
Reference in New Issue
Block a user