From a555cb4d1d3c04a4bdc0e04d20d23b157cef3b92 Mon Sep 17 00:00:00 2001 From: snek Date: Mon, 1 Jul 2024 15:48:52 -0700 Subject: [PATCH] feat: upgrade deno_core (#24364) - Symbol.asyncDispose no longer needs to be polyfilled - assorted updates for cppgc api changes --- Cargo.lock | 85 +++++++++++++++++++++++++++++++---- Cargo.toml | 2 +- ext/node/ops/blocklist.rs | 2 +- ext/node/ops/crypto/digest.rs | 4 +- ext/node/ops/crypto/x509.rs | 2 +- ext/node/ops/vm.rs | 2 +- ext/node/ops/vm_internal.rs | 34 ++++++++------ ext/node/ops/zlib/mod.rs | 4 +- ext/tls/tls_key.rs | 4 +- runtime/js/99_main.js | 16 +------ 10 files changed, 108 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 77d0b35f6091bb..5aea422a35a888 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -438,6 +438,29 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags 2.5.0", + "cexpr", + "clang-sys", + "itertools", + "lazy_static", + "lazycell", + "log", + "prettyplease 0.2.17", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.58", + "which 4.4.2", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -596,6 +619,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom 7.1.3", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -628,6 +660,17 @@ dependencies = [ "inout", ] +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading 0.8.3", +] + [[package]] name = "clap" version = "4.4.17" @@ -1292,9 +1335,9 @@ dependencies = [ [[package]] name = "deno_core" -version = "0.291.0" +version = "0.292.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec3d6bd1d8fc2858208a55aa492d43d92de7d42b9f434f0a7ed251befaf27a3c" +checksum = "248b86ab980532603f44c14e1c079881133fc54be4c5c716d5333c67952293d2" dependencies = [ "anyhow", "bincode", @@ -1755,9 +1798,9 @@ dependencies = [ [[package]] name = "deno_ops" -version = "0.167.0" +version = "0.168.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b573e543149e9a37cdf9cf37b88d778215a8eff7da8211b94f84d3d155cfe3f5" +checksum = "81638e46cda0051461c034e6aeef73d7184264fffface2372586a6ce410a0e89" dependencies = [ "proc-macro-rules", "proc-macro2", @@ -3761,6 +3804,12 @@ dependencies = [ "spin 0.5.2", ] +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "lexical-core" version = "0.8.5" @@ -4892,6 +4941,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "prettyplease" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7" +dependencies = [ + "proc-macro2", + "syn 2.0.58", +] + [[package]] name = "primeorder" version = "0.13.6" @@ -4986,7 +5045,7 @@ dependencies = [ "log", "multimap", "petgraph", - "prettyplease", + "prettyplease 0.1.25", "prost", "prost-types", "regex", @@ -5771,9 +5830,9 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.200.0" +version = "0.201.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579057484ec81c031826ca53bc5b4ab5d1273fcd5cc4c8057c0f0cd1e57dfa65" +checksum = "4f7436cf7c06303e6570fea42ec827e47111a77edbf6b40fcfc05424da4d01c0" dependencies = [ "num-bigint", "serde", @@ -5846,6 +5905,12 @@ dependencies = [ "dirs", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook" version = "0.3.17" @@ -7365,16 +7430,18 @@ dependencies = [ [[package]] name = "v8" -version = "0.93.1" +version = "0.95.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82943fec029559cb43f9d7fc36e2bb85121534702d6f893554e737d1b147d140" +checksum = "c4395d3c43b81368d91335ffc78d71cb6e3288d311ab6a55094634cb2afdc5c5" dependencies = [ + "bindgen", "bitflags 2.5.0", "fslock", "gzip-header", "home", "miniz_oxide", "once_cell", + "paste", "which 6.0.1", ] diff --git a/Cargo.toml b/Cargo.toml index 85a052d089f7f8..293d6b440c9863 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ repository = "https://github.com/denoland/deno" [workspace.dependencies] deno_ast = { version = "=0.39.2", features = ["transpiling"] } -deno_core = { version = "0.291.0" } +deno_core = { version = "0.292.0" } deno_bench_util = { version = "0.152.0", path = "./bench_util" } deno_lockfile = "0.20.0" diff --git a/ext/node/ops/blocklist.rs b/ext/node/ops/blocklist.rs index b853a572337f7f..182f15df320860 100644 --- a/ext/node/ops/blocklist.rs +++ b/ext/node/ops/blocklist.rs @@ -22,7 +22,7 @@ pub struct BlockListResource { blocklist: RefCell, } -impl deno_core::GcResource for BlockListResource {} +impl deno_core::GarbageCollected for BlockListResource {} #[derive(Serialize)] struct SocketAddressSerialization(String, String); diff --git a/ext/node/ops/crypto/digest.rs b/ext/node/ops/crypto/digest.rs index 588ea7425d43c3..e3a91e338f4fb6 100644 --- a/ext/node/ops/crypto/digest.rs +++ b/ext/node/ops/crypto/digest.rs @@ -1,7 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use deno_core::error::generic_error; use deno_core::error::AnyError; -use deno_core::GcResource; +use deno_core::GarbageCollected; use digest::Digest; use digest::DynDigest; use digest::ExtendableOutput; @@ -13,7 +13,7 @@ pub struct Hasher { pub hash: Rc>>, } -impl GcResource for Hasher {} +impl GarbageCollected for Hasher {} impl Hasher { pub fn new( diff --git a/ext/node/ops/crypto/x509.rs b/ext/node/ops/crypto/x509.rs index 517a3a943ae0c7..c9a23aca09a12b 100644 --- a/ext/node/ops/crypto/x509.rs +++ b/ext/node/ops/crypto/x509.rs @@ -19,7 +19,7 @@ pub(crate) struct Certificate { cert: X509Certificate<'static>, } -impl deno_core::GcResource for Certificate {} +impl deno_core::GarbageCollected for Certificate {} impl Certificate { fn fingerprint(&self) -> Option { diff --git a/ext/node/ops/vm.rs b/ext/node/ops/vm.rs index 2614c4f7366b38..df631a51f9e223 100644 --- a/ext/node/ops/vm.rs +++ b/ext/node/ops/vm.rs @@ -29,7 +29,7 @@ pub struct Script { inner: i::ContextifyScript, } -impl deno_core::GcResource for Script {} +impl deno_core::GarbageCollected for Script {} impl Script { fn new( diff --git a/ext/node/ops/vm_internal.rs b/ext/node/ops/vm_internal.rs index 0ac714c9facd3e..afcdc1b9c1a41a 100644 --- a/ext/node/ops/vm_internal.rs +++ b/ext/node/ops/vm_internal.rs @@ -58,13 +58,17 @@ impl ContextifyScript { } } -#[derive(Debug, Clone)] pub struct ContextifyContext { - context: v8::Global, - sandbox: v8::Global, + context: v8::TracedReference, + sandbox: v8::TracedReference, } -impl deno_core::GcResource for ContextifyContext {} +impl deno_core::GarbageCollected for ContextifyContext { + fn trace(&self, visitor: &v8::cppgc::Visitor) { + visitor.trace(&self.context); + visitor.trace(&self.sandbox); + } +} impl ContextifyContext { pub fn attach( @@ -102,12 +106,12 @@ impl ContextifyContext { ); } - let context = v8::Global::new(scope, v8_context); - let sandbox = v8::Global::new(scope, sandbox_obj); + let context = v8::TracedReference::new(scope, v8_context); + let sandbox = v8::TracedReference::new(scope, sandbox_obj); let wrapper = deno_core::cppgc::make_cppgc_object(scope, Self { context, sandbox }); - let ptr = deno_core::cppgc::try_unwrap_cppgc_object::(wrapper.into()) - .unwrap(); + let ptr = + deno_core::cppgc::try_unwrap_cppgc_object::(scope, wrapper.into()); // SAFETY: We are storing a pointer to the ContextifyContext // in the embedder data of the v8::Context. The contextified wrapper @@ -115,7 +119,7 @@ impl ContextifyContext { unsafe { v8_context.set_aligned_pointer_in_embedder_data( 3, - ptr as *const ContextifyContext as _, + ptr.borrow().unwrap() as *const ContextifyContext as _, ); } @@ -137,8 +141,12 @@ impl ContextifyContext { sandbox_obj .get_private(scope, private_symbol) .and_then(|wrapper| { - deno_core::cppgc::try_unwrap_cppgc_object::(wrapper) - .map(|s| s as _) + deno_core::cppgc::try_unwrap_cppgc_object::(scope, wrapper) + .borrow() + // SAFETY: the lifetime of the scope does not actually bind to + // the lifetime of this reference at all, but the object we read + // it from does, so it will be alive at least that long. + .map(|r| unsafe { &*(r as *const _) }) }) } @@ -153,7 +161,7 @@ impl ContextifyContext { &self, scope: &mut v8::HandleScope<'a>, ) -> v8::Local<'a, v8::Context> { - v8::Local::new(scope, &self.context) + self.context.get(scope).unwrap() } fn global_proxy<'s>( @@ -168,7 +176,7 @@ impl ContextifyContext { &self, scope: &mut v8::HandleScope<'a>, ) -> v8::Local<'a, v8::Object> { - v8::Local::new(scope, &self.sandbox) + self.sandbox.get(scope).unwrap() } fn get<'a, 'c>( diff --git a/ext/node/ops/zlib/mod.rs b/ext/node/ops/zlib/mod.rs index 9e030176abf9fd..b1d6d21d22d60c 100644 --- a/ext/node/ops/zlib/mod.rs +++ b/ext/node/ops/zlib/mod.rs @@ -144,7 +144,7 @@ impl ZlibInner { self.err = self.strm.inflate(self.flush); // TODO(@littledivy): Use if let chain when it is stable. // https://github.com/rust-lang/rust/issues/53667 - // + // // Data was encoded with dictionary if let (Z_NEED_DICT, Some(dictionary)) = (self.err, &self.dictionary) { self.err = self.strm.inflate_set_dictionary(dictionary); @@ -233,7 +233,7 @@ struct Zlib { inner: RefCell>, } -impl deno_core::GcResource for Zlib {} +impl deno_core::GarbageCollected for Zlib {} impl deno_core::Resource for Zlib { fn name(&self) -> Cow { diff --git a/ext/tls/tls_key.rs b/ext/tls/tls_key.rs index 66fea3a6955299..47a8e0e5707d4e 100644 --- a/ext/tls/tls_key.rs +++ b/ext/tls/tls_key.rs @@ -50,7 +50,7 @@ pub enum TlsKeys { pub struct TlsKeysHolder(RefCell); -impl deno_core::GcResource for TlsKeysHolder {} +impl deno_core::GarbageCollected for TlsKeysHolder {} impl TlsKeysHolder { pub fn take(&self) -> TlsKeys { @@ -224,7 +224,7 @@ pub struct TlsKeyLookup { RefCell>>>, } -impl deno_core::GcResource for TlsKeyLookup {} +impl deno_core::GarbageCollected for TlsKeyLookup {} impl TlsKeyLookup { /// Multiple `poll` calls are safe, but this method is not starvation-safe. Generally diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 4f949b214636f2..0a750f891d7b75 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -92,15 +92,7 @@ import { import { workerRuntimeGlobalProperties, } from "ext:runtime/98_global_scope_worker.js"; -import { - SymbolAsyncDispose, - SymbolDispose, - SymbolMetadata, -} from "ext:deno_web/00_infra.js"; -// deno-lint-ignore prefer-primordials -if (Symbol.asyncDispose) { - throw "V8 supports Symbol.asyncDispose now, no need to shim it!"; -} +import { SymbolDispose, SymbolMetadata } from "ext:deno_web/00_infra.js"; // deno-lint-ignore prefer-primordials if (Symbol.metadata) { throw "V8 supports Symbol.metadata now, no need to shim it!"; @@ -112,12 +104,6 @@ ObjectDefineProperties(Symbol, { writable: false, configurable: false, }, - asyncDispose: { - value: SymbolAsyncDispose, - enumerable: false, - writable: false, - configurable: false, - }, metadata: { value: SymbolMetadata, enumerable: false,