feat: disposable Deno resources (#20845)

This commit implements Symbol.dispose and Symbol.asyncDispose for
the relevant resources.

Closes #20839

---------

Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Luca Casonato 2023-11-01 20:26:12 +01:00 committed by GitHub
parent 1d19b1011b
commit d42f154312
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 342 additions and 35 deletions

View file

@ -70,11 +70,24 @@ import {
windowOrWorkerGlobalScope,
workerRuntimeGlobalProperties,
} from "ext:runtime/98_global_scope.js";
import { SymbolAsyncDispose, SymbolDispose } from "ext:deno_web/00_infra.js";
// deno-lint-ignore prefer-primordials
Symbol.dispose ??= Symbol("Symbol.dispose");
// deno-lint-ignore prefer-primordials
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
if (Symbol.dispose) throw "V8 supports Symbol.dispose now, no need to shim it!";
ObjectDefineProperties(Symbol, {
dispose: {
value: SymbolDispose,
enumerable: false,
writable: false,
configurable: false,
},
asyncDispose: {
value: SymbolAsyncDispose,
enumerable: false,
writable: false,
configurable: false,
},
});
let windowIsClosing = false;
let globalThis_;