diff --git a/Cargo.lock b/Cargo.lock index 1b56cd78f7..4105437632 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -958,9 +958,9 @@ dependencies = [ [[package]] name = "deno_ast" -version = "0.29.1" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8bb902bcaa072210ca7b2f28c391f77bb16f6ef64664331c5d928d99943303c" +checksum = "577ec3850834c2578eb44afa9250f9a807f8497664e6e2aaae19cea0aac2fe3b" dependencies = [ "anyhow", "base64 0.13.1", diff --git a/Cargo.toml b/Cargo.toml index 402b6e5073..08a112f234 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ license = "MIT" repository = "https://github.com/denoland/deno" [workspace.dependencies] -deno_ast = { version = "0.29.1", features = ["transpiling"] } +deno_ast = { version = "0.29.3", features = ["transpiling"] } deno_core = { version = "0.211.0" } diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index be9bc554ac..0a5e86b1f8 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -4701,3 +4701,8 @@ console.log(returnsHi());"#, ") .assert_exit_code(1); } + +itest!(explicit_resource_management { + args: "run --quiet --check run/explicit_resource_management/main.ts", + output: "run/explicit_resource_management/main.out", +}); diff --git a/cli/tests/testdata/run/explicit_resource_management/main.out b/cli/tests/testdata/run/explicit_resource_management/main.out new file mode 100644 index 0000000000..ff5ac4b59c --- /dev/null +++ b/cli/tests/testdata/run/explicit_resource_management/main.out @@ -0,0 +1,5 @@ +A +Disposed +B +Async disposed +C diff --git a/cli/tests/testdata/run/explicit_resource_management/main.ts b/cli/tests/testdata/run/explicit_resource_management/main.ts new file mode 100644 index 0000000000..0201a51f91 --- /dev/null +++ b/cli/tests/testdata/run/explicit_resource_management/main.ts @@ -0,0 +1,21 @@ +class Resource { + [Symbol.dispose]() { + console.log("Disposed"); + } +} +class AsyncResource { + async [Symbol.asyncDispose]() { + await new Promise((resolve) => setTimeout(resolve, 10)); + console.log("Async disposed"); + } +} + +{ + using resource = new Resource(); + console.log("A"); +} +{ + await using resource = new AsyncResource(); + console.log("B"); +} +console.log("C"); diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index fdd82862c7..af5c1d40c6 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -71,6 +71,11 @@ import { workerRuntimeGlobalProperties, } from "ext:runtime/98_global_scope.js"; +// deno-lint-ignore prefer-primordials +Symbol.dispose ??= Symbol("Symbol.dispose"); +// deno-lint-ignore prefer-primordials +Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose"); + let windowIsClosing = false; let globalThis_;