diff --git a/Cargo.lock b/Cargo.lock index c676f78b1e..f33233ab72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1343,9 +1343,9 @@ dependencies = [ [[package]] name = "deno_core" -version = "0.299.0" +version = "0.300.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428488cc6b392a199a159054da754f56a1fdc63ee03f16be2c21cbd22e936e7b" +checksum = "eb79d0494b8c15f97761645f4afca5d52a414d4dc8f8aef8ca3b3ca82240ab55" dependencies = [ "anyhow", "bincode", @@ -1829,9 +1829,9 @@ dependencies = [ [[package]] name = "deno_ops" -version = "0.175.0" +version = "0.176.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2b71759647722be6ae051919b75cb66b3dccafe61b53c75ad5a6fad9d0ee4a" +checksum = "8ecb75c43c9441f413f0595f694746f90d8ffd292337287da309dbd93773928c" dependencies = [ "proc-macro-rules", "proc-macro2", @@ -6002,9 +6002,9 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.208.0" +version = "0.209.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583f3c71a6f7acc1711ad718a33f6e799bacdc711d297b15bb28533f32264c58" +checksum = "15d9095a8a725125fff1706f940af182e2a8ca01da8b0cd019aa47da93b28b94" dependencies = [ "num-bigint", "serde", @@ -7637,9 +7637,9 @@ dependencies = [ [[package]] name = "v8" -version = "0.99.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa3fc0608a78f0c7d4ec88025759cb78c90a29984b48540060355a626ae329c1" +checksum = "06bc034c7b5e85fac85d2c6f181878266dd344790702d03e946c25cba78646a9" dependencies = [ "bindgen", "bitflags 2.5.0", diff --git a/Cargo.toml b/Cargo.toml index 414822d32d..52cf330726 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ repository = "https://github.com/denoland/deno" [workspace.dependencies] deno_ast = { version = "=0.41.2", features = ["transpiling"] } -deno_core = { version = "0.299.0" } +deno_core = { version = "0.300.0" } deno_bench_util = { version = "0.158.0", path = "./bench_util" } deno_lockfile = "0.20.0" diff --git a/cli/module_loader.rs b/cli/module_loader.rs index 3ac222b013..afd707ad82 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -35,7 +35,6 @@ use crate::util::text_encoding::code_without_source_map; use crate::util::text_encoding::source_map_from_code; use crate::worker::ModuleLoaderAndSourceMapGetter; use crate::worker::ModuleLoaderFactory; - use deno_ast::MediaType; use deno_core::anyhow::anyhow; use deno_core::anyhow::bail; @@ -64,6 +63,7 @@ use deno_graph::Module; use deno_graph::ModuleGraph; use deno_graph::Resolution; use deno_runtime::code_cache; +use deno_runtime::deno_node::create_host_defined_options; use deno_runtime::deno_permissions::PermissionsContainer; use deno_semver::npm::NpmPackageReqReference; use node_resolver::NodeResolutionMode; @@ -725,6 +725,19 @@ impl ModuleLoader Ok(specifier) } + fn get_host_defined_options<'s>( + &self, + scope: &mut deno_core::v8::HandleScope<'s>, + name: &str, + ) -> Option> { + let name = deno_core::ModuleSpecifier::parse(name).ok()?; + if self.0.shared.node_resolver.in_npm_package(&name) { + Some(create_host_defined_options(scope)) + } else { + None + } + } + fn load( &self, specifier: &ModuleSpecifier, diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index 1538807f1e..afacacc1f2 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -25,6 +25,7 @@ use deno_core::ResolutionKind; use deno_npm::npm_rc::ResolvedNpmRc; use deno_package_json::PackageJsonDepValue; use deno_runtime::deno_fs; +use deno_runtime::deno_node::create_host_defined_options; use deno_runtime::deno_node::NodeResolver; use deno_runtime::deno_permissions::Permissions; use deno_runtime::deno_permissions::PermissionsContainer; @@ -267,6 +268,19 @@ impl ModuleLoader for EmbeddedModuleLoader { } } + fn get_host_defined_options<'s>( + &self, + scope: &mut deno_core::v8::HandleScope<'s>, + name: &str, + ) -> Option> { + let name = deno_core::ModuleSpecifier::parse(name).ok()?; + if self.shared.node_resolver.in_npm_package(&name) { + Some(create_host_defined_options(scope)) + } else { + None + } + } + fn load( &self, original_specifier: &ModuleSpecifier, diff --git a/ext/node/global.rs b/ext/node/global.rs index 618e684948..2434a64fd4 100644 --- a/ext/node/global.rs +++ b/ext/node/global.rs @@ -1,13 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use std::mem::MaybeUninit; - use deno_core::v8; use deno_core::v8::GetPropertyNamesArgs; use deno_core::v8::MapFnTo; -use crate::NodeResolverRc; - // NOTE(bartlomieju): somehow calling `.map_fn_to()` multiple times on a function // returns two different pointers. That shouldn't be the case as `.map_fn_to()` // creates a thin wrapper that is a pure function. @piscisaureus suggests it @@ -17,8 +13,8 @@ use crate::NodeResolverRc; thread_local! { pub static GETTER_MAP_FN: v8::NamedPropertyGetterCallback<'static> = getter.map_fn_to(); pub static SETTER_MAP_FN: v8::NamedPropertySetterCallback<'static> = setter.map_fn_to(); - pub static QUERY_MAP_FN: v8::NamedPropertyGetterCallback<'static> = query.map_fn_to(); - pub static DELETER_MAP_FN: v8::NamedPropertyGetterCallback<'static> = deleter.map_fn_to(); + pub static QUERY_MAP_FN: v8::NamedPropertyQueryCallback<'static> = query.map_fn_to(); + pub static DELETER_MAP_FN: v8::NamedPropertyDeleterCallback<'static> = deleter.map_fn_to(); pub static ENUMERATOR_MAP_FN: v8::NamedPropertyEnumeratorCallback<'static> = enumerator.map_fn_to(); pub static DEFINER_MAP_FN: v8::NamedPropertyDefinerCallback<'static> = definer.map_fn_to(); pub static DESCRIPTOR_MAP_FN: v8::NamedPropertyGetterCallback<'static> = descriptor.map_fn_to(); @@ -93,8 +89,6 @@ enum Mode { } struct GlobalsStorage { - reflect_get: v8::Global, - reflect_set: v8::Global, deno_globals: v8::Global, node_globals: v8::Global, } @@ -154,27 +148,6 @@ pub fn global_object_middleware<'s>( .unwrap(); assert_ne!(global, object_prototype); - // Get the Reflect object - let reflect_key = - v8::String::new_external_onebyte_static(scope, b"Reflect").unwrap(); - let reflect = global - .get(scope, reflect_key.into()) - .unwrap() - .to_object(scope) - .unwrap(); - - // Get the Reflect.get function. - let get_key = v8::String::new_external_onebyte_static(scope, b"get").unwrap(); - let reflect_get = reflect.get(scope, get_key.into()).unwrap(); - let reflect_get_fn: v8::Local = reflect_get.try_into().unwrap(); - let reflect_get = v8::Global::new(scope, reflect_get_fn); - - // Get the Reflect.set function. - let set_key = v8::String::new_external_onebyte_static(scope, b"set").unwrap(); - let reflect_set = reflect.get(scope, set_key.into()).unwrap(); - let reflect_set_fn: v8::Local = reflect_set.try_into().unwrap(); - let reflect_set = v8::Global::new(scope, reflect_set_fn); - // globalThis.__bootstrap.ext_node_denoGlobals and // globalThis.__bootstrap.ext_node_nodeGlobals are the objects that contain // the Deno and Node specific globals respectively. If they do not yet exist @@ -231,8 +204,6 @@ pub fn global_object_middleware<'s>( // Create the storage struct and store it in a context slot. let storage = GlobalsStorage { - reflect_get, - reflect_set, deno_globals, node_globals, }; @@ -264,19 +235,19 @@ fn is_managed_key( } fn current_mode(scope: &mut v8::HandleScope) -> Mode { - let Some(v8_string) = - v8::StackTrace::current_script_name_or_source_url(scope) + let Some(host_defined_options) = scope.get_current_host_defined_options() else { return Mode::Deno; }; - let op_state = deno_core::JsRuntime::op_state_from(scope); - let op_state = op_state.borrow(); - let Some(node_resolver) = op_state.try_borrow::() else { - return Mode::Deno; + // SAFETY: host defined options must always be a PrimitiveArray in current V8. + let host_defined_options = unsafe { + v8::Local::::cast_unchecked(host_defined_options) }; - let mut buffer = [MaybeUninit::uninit(); 2048]; - let str = v8_string.to_rust_cow_lossy(scope, &mut buffer); - if str.starts_with("node:") || node_resolver.in_npm_package_with_cache(str) { + if host_defined_options.length() < 1 { + return Mode::Deno; + } + let is_node = host_defined_options.get(scope, 0).is_true(); + if is_node { Mode::Node } else { Mode::Deno @@ -297,25 +268,17 @@ pub fn getter<'s>( let mode = current_mode(scope); let context = scope.get_current_context(); - let (reflect_get, inner) = { + let inner = { let storage = context.get_slot::(scope).unwrap(); - let reflect_get = storage.reflect_get.clone(); - let inner = storage.inner_for_mode(mode); - (reflect_get, inner) + storage.inner_for_mode(mode) }; - let reflect_get = v8::Local::new(scope, reflect_get); let inner = v8::Local::new(scope, inner); if !inner.has_own_property(scope, key).unwrap_or(false) { return v8::Intercepted::No; } - let undefined = v8::undefined(scope); - let Some(value) = reflect_get.call( - scope, - undefined.into(), - &[inner.into(), key.into(), this.into()], - ) else { + let Some(value) = inner.get_with_receiver(scope, key.into(), this) else { return v8::Intercepted::No; }; @@ -328,7 +291,7 @@ pub fn setter<'s>( key: v8::Local<'s, v8::Name>, value: v8::Local<'s, v8::Value>, args: v8::PropertyCallbackArguments<'s>, - mut rv: v8::ReturnValue, + mut rv: v8::ReturnValue<()>, ) -> v8::Intercepted { if !is_managed_key(scope, key) { return v8::Intercepted::No; @@ -338,26 +301,18 @@ pub fn setter<'s>( let mode = current_mode(scope); let context = scope.get_current_context(); - let (reflect_set, inner) = { + let inner = { let storage = context.get_slot::(scope).unwrap(); - let reflect_set = storage.reflect_set.clone(); - let inner = storage.inner_for_mode(mode); - (reflect_set, inner) + storage.inner_for_mode(mode) }; - let reflect_set = v8::Local::new(scope, reflect_set); let inner = v8::Local::new(scope, inner); - let undefined = v8::undefined(scope); - - let Some(success) = reflect_set.call( - scope, - undefined.into(), - &[inner.into(), key.into(), value, this.into()], - ) else { + let Some(success) = inner.set_with_receiver(scope, key.into(), value, this) + else { return v8::Intercepted::No; }; - rv.set(success); + rv.set_bool(success); v8::Intercepted::Yes } @@ -365,7 +320,7 @@ pub fn query<'s>( scope: &mut v8::HandleScope<'s>, key: v8::Local<'s, v8::Name>, _args: v8::PropertyCallbackArguments<'s>, - mut rv: v8::ReturnValue, + mut rv: v8::ReturnValue, ) -> v8::Intercepted { if !is_managed_key(scope, key) { return v8::Intercepted::No; @@ -396,7 +351,7 @@ pub fn deleter<'s>( scope: &mut v8::HandleScope<'s>, key: v8::Local<'s, v8::Name>, args: v8::PropertyCallbackArguments<'s>, - mut rv: v8::ReturnValue, + mut rv: v8::ReturnValue, ) -> v8::Intercepted { if !is_managed_key(scope, key) { return v8::Intercepted::No; @@ -429,7 +384,7 @@ pub fn deleter<'s>( pub fn enumerator<'s>( scope: &mut v8::HandleScope<'s>, _args: v8::PropertyCallbackArguments<'s>, - mut rv: v8::ReturnValue, + mut rv: v8::ReturnValue, ) { let mode = current_mode(scope); @@ -451,7 +406,7 @@ pub fn enumerator<'s>( return; }; - rv.set(array.into()); + rv.set(array); } pub fn definer<'s>( @@ -459,7 +414,7 @@ pub fn definer<'s>( key: v8::Local<'s, v8::Name>, descriptor: &v8::PropertyDescriptor, args: v8::PropertyCallbackArguments<'s>, - _rv: v8::ReturnValue, + _rv: v8::ReturnValue<()>, ) -> v8::Intercepted { if !is_managed_key(scope, key) { return v8::Intercepted::No; diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 987d525200..a4a757996e 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -655,8 +655,8 @@ deno_core::extension!(deno_node, }); vm::DELETER_MAP_FN.with(|deleter| { external_references.push(ExternalReference { - named_getter: *deleter, - },); + named_deleter: *deleter, + }); }); vm::ENUMERATOR_MAP_FN.with(|enumerator| { external_references.push(ExternalReference { @@ -686,7 +686,7 @@ deno_core::extension!(deno_node, }); vm::INDEXED_DELETER_MAP_FN.with(|deleter| { external_references.push(ExternalReference { - indexed_getter: *deleter, + indexed_deleter: *deleter, }); }); vm::INDEXED_DEFINER_MAP_FN.with(|definer| { @@ -712,13 +712,13 @@ deno_core::extension!(deno_node, }); global::QUERY_MAP_FN.with(|query| { external_references.push(ExternalReference { - named_getter: *query, + named_query: *query, }); }); global::DELETER_MAP_FN.with(|deleter| { external_references.push(ExternalReference { - named_getter: *deleter, - },); + named_deleter: *deleter, + }); }); global::ENUMERATOR_MAP_FN.with(|enumerator| { external_references.push(ExternalReference { @@ -842,3 +842,12 @@ impl<'a> deno_package_json::fs::DenoPkgJsonFs for DenoPkgJsonFsAdapter<'a> { .map_err(|err| err.into_io_error()) } } + +pub fn create_host_defined_options<'s>( + scope: &mut v8::HandleScope<'s>, +) -> v8::Local<'s, v8::Data> { + let host_defined_options = v8::PrimitiveArray::new(scope, 1); + let value = v8::Boolean::new(scope, true); + host_defined_options.set(scope, 0, value.into()); + host_defined_options.into() +} diff --git a/ext/node/ops/vm_internal.rs b/ext/node/ops/vm_internal.rs index a9c13a582f..ca3cac41f1 100644 --- a/ext/node/ops/vm_internal.rs +++ b/ext/node/ops/vm_internal.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use crate::create_host_defined_options; use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::v8; @@ -19,7 +20,22 @@ impl ContextifyScript { scope: &mut v8::HandleScope, source_str: v8::Local, ) -> Result { - let source = v8::script_compiler::Source::new(source_str, None); + let resource_name = v8::undefined(scope); + let host_defined_options = create_host_defined_options(scope); + let origin = v8::ScriptOrigin::new( + scope, + resource_name.into(), + 0, + 0, + false, + 0, + None, + false, + false, + false, + Some(host_defined_options), + ); + let source = v8::script_compiler::Source::new(source_str, Some(&origin)); let unbound_script = v8::script_compiler::compile_unbound_script( scope, @@ -260,7 +276,7 @@ pub fn init_global_template<'a>( thread_local! { pub static GETTER_MAP_FN: v8::NamedPropertyGetterCallback<'static> = property_getter.map_fn_to(); pub static SETTER_MAP_FN: v8::NamedPropertySetterCallback<'static> = property_setter.map_fn_to(); - pub static DELETER_MAP_FN: v8::NamedPropertyGetterCallback<'static> = property_deleter.map_fn_to(); + pub static DELETER_MAP_FN: v8::NamedPropertyDeleterCallback<'static> = property_deleter.map_fn_to(); pub static ENUMERATOR_MAP_FN: v8::NamedPropertyEnumeratorCallback<'static> = property_enumerator.map_fn_to(); pub static DEFINER_MAP_FN: v8::NamedPropertyDefinerCallback<'static> = property_definer.map_fn_to(); pub static DESCRIPTOR_MAP_FN: v8::NamedPropertyGetterCallback<'static> = property_descriptor.map_fn_to(); @@ -269,7 +285,7 @@ thread_local! { thread_local! { pub static INDEXED_GETTER_MAP_FN: v8::IndexedPropertyGetterCallback<'static> = indexed_property_getter.map_fn_to(); pub static INDEXED_SETTER_MAP_FN: v8::IndexedPropertySetterCallback<'static> = indexed_property_setter.map_fn_to(); - pub static INDEXED_DELETER_MAP_FN: v8::IndexedPropertyGetterCallback<'static> = indexed_property_deleter.map_fn_to(); + pub static INDEXED_DELETER_MAP_FN: v8::IndexedPropertyDeleterCallback<'static> = indexed_property_deleter.map_fn_to(); pub static INDEXED_DEFINER_MAP_FN: v8::IndexedPropertyDefinerCallback<'static> = indexed_property_definer.map_fn_to(); pub static INDEXED_DESCRIPTOR_MAP_FN: v8::IndexedPropertyGetterCallback<'static> = indexed_property_descriptor.map_fn_to(); } @@ -362,7 +378,7 @@ fn property_setter<'s>( key: v8::Local<'s, v8::Name>, value: v8::Local<'s, v8::Value>, args: v8::PropertyCallbackArguments<'s>, - mut rv: v8::ReturnValue, + mut rv: v8::ReturnValue<()>, ) -> v8::Intercepted { let Some(ctx) = ContextifyContext::get(scope, args.this()) else { return v8::Intercepted::No; @@ -441,7 +457,7 @@ fn property_setter<'s>( .has_own_property(scope, set_key.into()) .unwrap_or(false) { - rv.set(value); + rv.set_bool(true); return v8::Intercepted::Yes; } } @@ -455,7 +471,7 @@ fn property_deleter<'s>( scope: &mut v8::HandleScope<'s>, key: v8::Local<'s, v8::Name>, args: v8::PropertyCallbackArguments<'s>, - mut rv: v8::ReturnValue, + mut rv: v8::ReturnValue, ) -> v8::Intercepted { let Some(ctx) = ContextifyContext::get(scope, args.this()) else { return v8::Intercepted::No; @@ -475,7 +491,7 @@ fn property_deleter<'s>( fn property_enumerator<'s>( scope: &mut v8::HandleScope<'s>, args: v8::PropertyCallbackArguments<'s>, - mut rv: v8::ReturnValue, + mut rv: v8::ReturnValue, ) { let Some(ctx) = ContextifyContext::get(scope, args.this()) else { return; @@ -490,7 +506,7 @@ fn property_enumerator<'s>( return; }; - rv.set(properties.into()); + rv.set(properties); } fn property_definer<'s>( @@ -498,7 +514,7 @@ fn property_definer<'s>( key: v8::Local<'s, v8::Name>, desc: &v8::PropertyDescriptor, args: v8::PropertyCallbackArguments<'s>, - _: v8::ReturnValue, + _: v8::ReturnValue<()>, ) -> v8::Intercepted { let Some(ctx) = ContextifyContext::get(scope, args.this()) else { return v8::Intercepted::No; @@ -622,7 +638,7 @@ fn indexed_property_setter<'s>( index: u32, value: v8::Local<'s, v8::Value>, args: v8::PropertyCallbackArguments<'s>, - rv: v8::ReturnValue, + rv: v8::ReturnValue<()>, ) -> v8::Intercepted { let key = uint32_to_name(scope, index); property_setter(scope, key, value, args, rv) @@ -632,7 +648,7 @@ fn indexed_property_deleter<'s>( scope: &mut v8::HandleScope<'s>, index: u32, args: v8::PropertyCallbackArguments<'s>, - mut rv: v8::ReturnValue, + mut rv: v8::ReturnValue, ) -> v8::Intercepted { let Some(ctx) = ContextifyContext::get(scope, args.this()) else { return v8::Intercepted::No; @@ -656,7 +672,7 @@ fn indexed_property_definer<'s>( index: u32, descriptor: &v8::PropertyDescriptor, args: v8::PropertyCallbackArguments<'s>, - rv: v8::ReturnValue, + rv: v8::ReturnValue<()>, ) -> v8::Intercepted { let key = uint32_to_name(scope, index); property_definer(scope, key, descriptor, args, rv) diff --git a/ext/node/polyfills/01_require.js b/ext/node/polyfills/01_require.js index 94d6e90e08..f71e009ba9 100644 --- a/ext/node/polyfills/01_require.js +++ b/ext/node/polyfills/01_require.js @@ -976,9 +976,14 @@ function wrapSafe( filename, content, cjsModuleInstance, + format, ) { const wrapper = Module.wrap(content); - const [f, err] = core.evalContext(wrapper, `file://${filename}`); + const [f, err] = core.evalContext( + wrapper, + url.pathToFileURL(filename).toString(), + [format !== "module"], + ); if (err) { if (process.mainModule === cjsModuleInstance) { enrichCJSError(err.thrown); @@ -995,8 +1000,16 @@ function wrapSafe( return f; } -Module.prototype._compile = function (content, filename) { - const compiledWrapper = wrapSafe(filename, content, this); +Module.prototype._compile = function (content, filename, format) { + const compiledWrapper = wrapSafe(filename, content, this, format); + + if (format === "module") { + // TODO(https://github.com/denoland/deno/issues/24822): implement require esm + throw createRequireEsmError( + filename, + moduleParentCache.get(module)?.filename, + ); + } const dirname = pathDirname(filename); const require = makeRequireFunction(this); @@ -1053,17 +1066,24 @@ Module.prototype._compile = function (content, filename) { Module._extensions[".js"] = function (module, filename) { const content = op_require_read_file(filename); + let format; if (StringPrototypeEndsWith(filename, ".js")) { const pkg = op_require_read_closest_package_json(filename); - if (pkg && pkg.typ === "module") { + if (pkg?.typ === "module") { + // TODO(https://github.com/denoland/deno/issues/24822): implement require esm + format = "module"; throw createRequireEsmError( filename, moduleParentCache.get(module)?.filename, ); + } else if (pkg?.type === "commonjs") { + format = "commonjs"; } + } else if (StringPrototypeEndsWith(filename, ".cjs")) { + format = "commonjs"; } - module._compile(content, filename); + module._compile(content, filename, format); }; function createRequireEsmError(filename, parent) { diff --git a/ext/node_resolver/resolution.rs b/ext/node_resolver/resolution.rs index 772bc5d34c..ae791e312b 100644 --- a/ext/node_resolver/resolution.rs +++ b/ext/node_resolver/resolution.rs @@ -1,7 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use std::borrow::Cow; -use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; @@ -138,38 +137,17 @@ pub type NodeResolverRc = crate::sync::MaybeArc>; pub struct NodeResolver { env: TEnv, npm_resolver: NpmResolverRc, - in_npm_package_cache: crate::sync::MaybeArcMutex>, } impl NodeResolver { pub fn new(env: TEnv, npm_resolver: NpmResolverRc) -> Self { - Self { - env, - npm_resolver, - in_npm_package_cache: crate::sync::MaybeArcMutex::new(HashMap::new()), - } + Self { env, npm_resolver } } pub fn in_npm_package(&self, specifier: &Url) -> bool { self.npm_resolver.in_npm_package(specifier) } - pub fn in_npm_package_with_cache(&self, specifier: Cow) -> bool { - let mut cache = self.in_npm_package_cache.lock(); - - if let Some(result) = cache.get(specifier.as_ref()) { - return *result; - } - - let result = if let Ok(specifier) = Url::parse(&specifier) { - self.npm_resolver.in_npm_package(&specifier) - } else { - false - }; - cache.insert(specifier.into_owned(), result); - result - } - /// This function is an implementation of `defaultResolve` in /// `lib/internal/modules/esm/resolve.js` from Node. pub fn resolve( diff --git a/ext/node_resolver/sync.rs b/ext/node_resolver/sync.rs index f6689a56ab..3c4729aa2c 100644 --- a/ext/node_resolver/sync.rs +++ b/ext/node_resolver/sync.rs @@ -6,79 +6,16 @@ pub use inner::*; mod inner { #![allow(clippy::disallowed_types)] - use std::ops::Deref; - use std::ops::DerefMut; pub use std::sync::Arc as MaybeArc; - pub struct MaybeArcMutexGuard<'lock, T>(std::sync::MutexGuard<'lock, T>); - - impl<'lock, T> Deref for MaybeArcMutexGuard<'lock, T> { - type Target = std::sync::MutexGuard<'lock, T>; - fn deref(&self) -> &std::sync::MutexGuard<'lock, T> { - &self.0 - } - } - - impl<'lock, T> DerefMut for MaybeArcMutexGuard<'lock, T> { - fn deref_mut(&mut self) -> &mut std::sync::MutexGuard<'lock, T> { - &mut self.0 - } - } - - #[derive(Debug)] - pub struct MaybeArcMutex(std::sync::Arc>); - impl MaybeArcMutex { - pub fn new(val: T) -> Self { - Self(std::sync::Arc::new(std::sync::Mutex::new(val))) - } - } - - impl<'lock, T> MaybeArcMutex { - pub fn lock(&'lock self) -> MaybeArcMutexGuard<'lock, T> { - MaybeArcMutexGuard(self.0.lock().unwrap()) - } - } - pub use core::marker::Send as MaybeSend; pub use core::marker::Sync as MaybeSync; } #[cfg(not(feature = "sync"))] mod inner { - use std::ops::Deref; - use std::ops::DerefMut; - pub use std::rc::Rc as MaybeArc; - pub struct MaybeArcMutexGuard<'lock, T>(std::cell::RefMut<'lock, T>); - - impl<'lock, T> Deref for MaybeArcMutexGuard<'lock, T> { - type Target = std::cell::RefMut<'lock, T>; - fn deref(&self) -> &std::cell::RefMut<'lock, T> { - &self.0 - } - } - - impl<'lock, T> DerefMut for MaybeArcMutexGuard<'lock, T> { - fn deref_mut(&mut self) -> &mut std::cell::RefMut<'lock, T> { - &mut self.0 - } - } - - #[derive(Debug)] - pub struct MaybeArcMutex(std::rc::Rc>); - impl MaybeArcMutex { - pub fn new(val: T) -> Self { - Self(std::rc::Rc::new(std::cell::RefCell::new(val))) - } - } - - impl<'lock, T> MaybeArcMutex { - pub fn lock(&'lock self) -> MaybeArcMutexGuard<'lock, T> { - MaybeArcMutexGuard(self.0.borrow_mut()) - } - } - pub trait MaybeSync {} impl MaybeSync for T where T: ?Sized {} pub trait MaybeSend {} diff --git a/tests/node_compat/test/common/index.js b/tests/node_compat/test/common/index.js index bc1ea05e45..ebac56ac55 100644 --- a/tests/node_compat/test/common/index.js +++ b/tests/node_compat/test/common/index.js @@ -59,7 +59,6 @@ let knownGlobals = [ queueMicrotask, removeEventListener, reportError, - self, sessionStorage, setImmediate, ]; diff --git a/tests/testdata/run/worker_close_in_wasm_reactions.js.out b/tests/testdata/run/worker_close_in_wasm_reactions.js.out index 325180de4f..904613dae9 100644 --- a/tests/testdata/run/worker_close_in_wasm_reactions.js.out +++ b/tests/testdata/run/worker_close_in_wasm_reactions.js.out @@ -1,2 +1,2 @@ -Error: CompileError: WebAssembly.compile(): reached end while decoding length: @+10 +Error: CompileError: WebAssembly.compile(): reached end while decoding length @+10 at file:///[WILDCARD]/close_in_wasm_reactions.js:18:13 diff --git a/tests/unit/console_test.ts b/tests/unit/console_test.ts index 957ad3ef94..d9ac71dd89 100644 --- a/tests/unit/console_test.ts +++ b/tests/unit/console_test.ts @@ -518,8 +518,8 @@ Deno.test(function consoleTestStringifyFunctionWithProperties() { ], [isArray]: [Function: isArray] { [length]: 1, [name]: "isArray" }, [from]: [Function: from] { [length]: 1, [name]: "from" }, - [of]: [Function: of] { [length]: 0, [name]: "of" }, [fromAsync]: [Function: fromAsync] { [length]: 1, [name]: "fromAsync" }, + [of]: [Function: of] { [length]: 0, [name]: "of" }, [Symbol(Symbol.species)]: [Getter] }`, );