mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: implement (Async)Disposable on handles (#10802)
This commit is contained in:
parent
dca327f99f
commit
8c07631bd1
17
docs/api/puppeteer.elementhandle._symbol.asyncdispose_.md
Normal file
17
docs/api/puppeteer.elementhandle._symbol.asyncdispose_.md
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
sidebar_label: ElementHandle.[Symbol.asyncDispose]
|
||||
---
|
||||
|
||||
# ElementHandle.\[Symbol.asyncDispose\]() method
|
||||
|
||||
#### Signature:
|
||||
|
||||
```typescript
|
||||
class ElementHandle {
|
||||
[Symbol.asyncDispose](): Promise<void>;
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
|
||||
Promise<void>
|
17
docs/api/puppeteer.elementhandle._symbol.dispose_.md
Normal file
17
docs/api/puppeteer.elementhandle._symbol.dispose_.md
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
sidebar_label: ElementHandle.[Symbol.dispose]
|
||||
---
|
||||
|
||||
# ElementHandle.\[Symbol.dispose\]() method
|
||||
|
||||
#### Signature:
|
||||
|
||||
```typescript
|
||||
class ElementHandle {
|
||||
[Symbol.dispose](): void;
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
|
||||
void
|
@ -49,6 +49,8 @@ The constructor for this class is marked as internal. Third-party code should no
|
||||
|
||||
| Method | Modifiers | Description |
|
||||
| -------------------------------------------------------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [\[Symbol.asyncDispose\]()](./puppeteer.elementhandle._symbol.asyncdispose_.md) | | |
|
||||
| [\[Symbol.dispose\]()](./puppeteer.elementhandle._symbol.dispose_.md) | | |
|
||||
| [$(selector)](./puppeteer.elementhandle._.md) | | Queries the current element for an element matching the given selector. |
|
||||
| [$$(selector)](./puppeteer.elementhandle.__.md) | | Queries the current element for all elements matching the given selector. |
|
||||
| [$$eval(selector, pageFunction, args)](./puppeteer.elementhandle.__eval.md) | | <p>Runs the given function on an array of elements matching the given selector in the current element.</p><p>If the given function returns a promise, then this method will wait till the promise resolves.</p> |
|
||||
|
17
docs/api/puppeteer.jshandle._symbol.asyncdispose_.md
Normal file
17
docs/api/puppeteer.jshandle._symbol.asyncdispose_.md
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
sidebar_label: JSHandle.[Symbol.asyncDispose]
|
||||
---
|
||||
|
||||
# JSHandle.\[Symbol.asyncDispose\]() method
|
||||
|
||||
#### Signature:
|
||||
|
||||
```typescript
|
||||
class JSHandle {
|
||||
[Symbol.asyncDispose](): Promise<void>;
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
|
||||
Promise<void>
|
17
docs/api/puppeteer.jshandle._symbol.dispose_.md
Normal file
17
docs/api/puppeteer.jshandle._symbol.dispose_.md
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
sidebar_label: JSHandle.[Symbol.dispose]
|
||||
---
|
||||
|
||||
# JSHandle.\[Symbol.dispose\]() method
|
||||
|
||||
#### Signature:
|
||||
|
||||
```typescript
|
||||
class JSHandle {
|
||||
[Symbol.dispose](): void;
|
||||
}
|
||||
```
|
||||
|
||||
**Returns:**
|
||||
|
||||
void
|
@ -13,9 +13,11 @@ Handles can be used as arguments for any evaluation function such as [Page.$eval
|
||||
#### Signature:
|
||||
|
||||
```typescript
|
||||
export declare abstract class JSHandle<T = unknown>
|
||||
export declare abstract class JSHandle<T = unknown> implements Disposable, AsyncDisposable
|
||||
```
|
||||
|
||||
**Implements:** Disposable, AsyncDisposable
|
||||
|
||||
## Remarks
|
||||
|
||||
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `JSHandle` class.
|
||||
@ -36,6 +38,8 @@ const windowHandle = await page.evaluateHandle(() => window);
|
||||
|
||||
| Method | Modifiers | Description |
|
||||
| ---------------------------------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [\[Symbol.asyncDispose\]()](./puppeteer.jshandle._symbol.asyncdispose_.md) | | |
|
||||
| [\[Symbol.dispose\]()](./puppeteer.jshandle._symbol.dispose_.md) | | |
|
||||
| [asElement()](./puppeteer.jshandle.aselement.md) | | Either <code>null</code> or the handle itself if the handle is an instance of [ElementHandle](./puppeteer.elementhandle.md). |
|
||||
| [dispose()](./puppeteer.jshandle.dispose.md) | | Releases the object referenced by the handle for garbage collection. |
|
||||
| [evaluate(pageFunction, args)](./puppeteer.jshandle.evaluate.md) | | Evaluates the given function with the current handle as its first argument. |
|
||||
|
@ -250,8 +250,8 @@ export abstract class ElementHandle<
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
override async dispose(): Promise<void> {
|
||||
return await this.handle.dispose();
|
||||
override dispose(): Promise<void> {
|
||||
return this.handle.dispose();
|
||||
}
|
||||
|
||||
override asElement(): ElementHandle<ElementType> {
|
||||
@ -1323,6 +1323,14 @@ export abstract class ElementHandle<
|
||||
* ```
|
||||
*/
|
||||
abstract autofill(data: AutofillData): Promise<void>;
|
||||
|
||||
override [Symbol.dispose](): void {
|
||||
return void this.dispose().catch(debugError);
|
||||
}
|
||||
|
||||
override [Symbol.asyncDispose](): Promise<void> {
|
||||
return this.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,9 @@
|
||||
|
||||
import Protocol from 'devtools-protocol';
|
||||
|
||||
import {Symbol} from '../../third_party/disposablestack/disposablestack.js';
|
||||
import {EvaluateFuncWith, HandleFor, HandleOr} from '../common/types.js';
|
||||
import {debugError} from '../common/util.js';
|
||||
|
||||
import {ElementHandle} from './ElementHandle.js';
|
||||
|
||||
@ -41,7 +43,9 @@ import {ElementHandle} from './ElementHandle.js';
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export abstract class JSHandle<T = unknown> {
|
||||
export abstract class JSHandle<T = unknown>
|
||||
implements Disposable, AsyncDisposable
|
||||
{
|
||||
/**
|
||||
* Used for nominally typing {@link JSHandle}.
|
||||
*/
|
||||
@ -150,4 +154,12 @@ export abstract class JSHandle<T = unknown> {
|
||||
* backing this handle.
|
||||
*/
|
||||
abstract remoteObject(): Protocol.Runtime.RemoteObject;
|
||||
|
||||
[Symbol.dispose](): void {
|
||||
return void this.dispose().catch(debugError);
|
||||
}
|
||||
|
||||
[Symbol.asyncDispose](): Promise<void> {
|
||||
return this.dispose();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user