From 22b06f84c93e2e5198e0da2e8493030538d0bae6 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Tue, 2 Nov 2021 15:29:42 +0900 Subject: [PATCH 1/7] compat: switch dyn import error class --- cli/proc_state.rs | 14 +++++++++-- cli/tests/integration/compat_tests.rs | 5 ++++ .../testdata/compat/dyn_import_reject.js | 4 ++++ .../testdata/compat/dyn_import_reject.out | 2 ++ core/runtime.rs | 18 ++++++++++++--- runtime/js/07_compat.js | 23 +++++++++++++++++++ runtime/js/90_deno_ns.js | 1 + 7 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 cli/tests/testdata/compat/dyn_import_reject.js create mode 100644 cli/tests/testdata/compat/dyn_import_reject.out create mode 100644 runtime/js/07_compat.js diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 0c81ab2e88428c..0ddbdf5cb95c38 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -519,14 +519,24 @@ impl ProcState { } else { if maybe_referrer.is_some() && !is_dynamic { if let Some(span) = graph_data.resolved_map.get(&specifier) { + let error_class = if self.flags.compat { + "Deno.compat.errors.ERR_MODULE_NOT_FOUND" + } else { + "TypeError" + }; return Err(custom_error( - "NotFound", + error_class, format!("Cannot load module \"{}\".\n at {}", specifier, span), )); } } + let error_class = if self.flags.compat { + "Deno.compat.errors.ERR_MODULE_NOT_FOUND" + } else { + "TypeError" + }; return Err(custom_error( - "NotFound", + error_class, format!("Cannot load module \"{}\".", specifier), )); } diff --git a/cli/tests/integration/compat_tests.rs b/cli/tests/integration/compat_tests.rs index 81d2985b3b1f06..e15a19b8a31ae4 100644 --- a/cli/tests/integration/compat_tests.rs +++ b/cli/tests/integration/compat_tests.rs @@ -23,6 +23,11 @@ itest!(compat_with_import_map_and_https_imports { output: "compat/import_map_https_imports.out", }); +itest!(compat_dyn_import_rejects_with_node_compatible_error { + args: "run --quiet --compat --unstable -A compat/dyn_import_reject.js", + output: "compat/dyn_import_reject.out", +}); + #[test] fn globals_in_repl() { let (out, _err) = util::run_and_collect_output_with_args( diff --git a/cli/tests/testdata/compat/dyn_import_reject.js b/cli/tests/testdata/compat/dyn_import_reject.js new file mode 100644 index 00000000000000..f9a99f0dae90fc --- /dev/null +++ b/cli/tests/testdata/compat/dyn_import_reject.js @@ -0,0 +1,4 @@ +import("./foobar.js").catch((e) => { + console.log(e); + console.log(e.code); +}); diff --git a/cli/tests/testdata/compat/dyn_import_reject.out b/cli/tests/testdata/compat/dyn_import_reject.out new file mode 100644 index 00000000000000..4da17924524306 --- /dev/null +++ b/cli/tests/testdata/compat/dyn_import_reject.out @@ -0,0 +1,2 @@ +Error: Cannot load module "[WILDCARD]/testdata/compat/foobar.js". +ERR_MODULE_NOT_FOUND diff --git a/core/runtime.rs b/core/runtime.rs index 80221295da3860..c0210d2f8d2e91 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -1132,7 +1132,10 @@ impl JsRuntime { fn dynamic_import_reject(&mut self, id: ModuleLoadId, err: AnyError) { let module_map_rc = Self::module_map(self.v8_isolate()); - let scope = &mut self.handle_scope(); + let get_error_class_fn = self.op_state().borrow().get_error_class_fn; + let err_class = get_error_class_fn(&err); + let err_class = self.execute_script("", err_class).ok(); + let mut scope = &mut self.handle_scope(); let resolver_handle = module_map_rc .borrow_mut() @@ -1141,13 +1144,22 @@ impl JsRuntime { .expect("Invalid dynamic import id"); let resolver = resolver_handle.open(scope); - let exception = err + let exception: v8::Local = err .downcast_ref::() .map(|err| err.get_handle(scope)) .unwrap_or_else(|| { let message = err.to_string(); let message = v8::String::new(scope, &message).unwrap(); - v8::Exception::type_error(scope, message) + let err_class = + v8::Local::::new(&mut scope, err_class.unwrap()); + let maybe_err_class = + v8::Local::::try_from(err_class).ok(); + if let Some(err_class) = maybe_err_class { + let err = err_class.new_instance(scope, &[message.into()]).unwrap(); + err.into() + } else { + v8::Exception::type_error(scope, message) + } }); // IMPORTANT: No borrows to `ModuleMap` can be held at this point because diff --git a/runtime/js/07_compat.js b/runtime/js/07_compat.js new file mode 100644 index 00000000000000..fcaa2ea015a848 --- /dev/null +++ b/runtime/js/07_compat.js @@ -0,0 +1,23 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +"use strict"; + +((window) => { + const { + Error, + } = window.__bootstrap.primordials; + + class ERR_MODULE_NOT_FOUND extends Error { + constructor(msg) { + super(msg); + this.code = "ERR_MODULE_NOT_FOUND"; + } + } + + const errors = { + ERR_MODULE_NOT_FOUND, + }; + + window.__bootstrap.compat = { + errors, + }; +})(this); diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index f858a93eb30b01..b64ea74570d18c 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -139,5 +139,6 @@ flockSync: __bootstrap.fs.flockSync, funlock: __bootstrap.fs.funlock, funlockSync: __bootstrap.fs.funlockSync, + compat: __bootstrap.compat, }; })(this); From dd90ee7e6fbd2ae94b35ee2bf976fd2980529473 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 3 Nov 2021 21:27:28 +0900 Subject: [PATCH 2/7] fix --- cli/proc_state.rs | 15 +++------ .../testdata/compat/dyn_import_reject.out | 2 +- core/runtime.rs | 33 +++++++++++-------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 0ddbdf5cb95c38..535702f94323ab 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -517,24 +517,19 @@ impl ProcState { return Ok(module_source.clone()); } } else { + let error_class = if self.flags.compat { + "Deno.compat.errors.ERR_MODULE_NOT_FOUND" + } else { + "TypeError" + }; if maybe_referrer.is_some() && !is_dynamic { if let Some(span) = graph_data.resolved_map.get(&specifier) { - let error_class = if self.flags.compat { - "Deno.compat.errors.ERR_MODULE_NOT_FOUND" - } else { - "TypeError" - }; return Err(custom_error( error_class, format!("Cannot load module \"{}\".\n at {}", specifier, span), )); } } - let error_class = if self.flags.compat { - "Deno.compat.errors.ERR_MODULE_NOT_FOUND" - } else { - "TypeError" - }; return Err(custom_error( error_class, format!("Cannot load module \"{}\".", specifier), diff --git a/cli/tests/testdata/compat/dyn_import_reject.out b/cli/tests/testdata/compat/dyn_import_reject.out index 4da17924524306..510957829581ea 100644 --- a/cli/tests/testdata/compat/dyn_import_reject.out +++ b/cli/tests/testdata/compat/dyn_import_reject.out @@ -1,2 +1,2 @@ -Error: Cannot load module "[WILDCARD]/testdata/compat/foobar.js". +Error: Cannot load module "file:///[WILDCARD]/testdata/compat/foobar.js". ERR_MODULE_NOT_FOUND diff --git a/core/runtime.rs b/core/runtime.rs index c0210d2f8d2e91..ac25e94f815771 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -561,7 +561,14 @@ impl JsRuntime { source_code: &str, ) -> Result, AnyError> { let scope = &mut self.handle_scope(); + Self::execute_script_with_scope(scope, name, source_code) + } + fn execute_script_with_scope( + scope: &mut v8::HandleScope, + name: &str, + source_code: &str, + ) -> Result, AnyError> { let source = v8::String::new(scope, source_code).unwrap(); let name = v8::String::new(scope, name).unwrap(); let origin = bindings::script_origin(scope, name); @@ -1133,9 +1140,7 @@ impl JsRuntime { fn dynamic_import_reject(&mut self, id: ModuleLoadId, err: AnyError) { let module_map_rc = Self::module_map(self.v8_isolate()); let get_error_class_fn = self.op_state().borrow().get_error_class_fn; - let err_class = get_error_class_fn(&err); - let err_class = self.execute_script("", err_class).ok(); - let mut scope = &mut self.handle_scope(); + let scope = &mut self.handle_scope(); let resolver_handle = module_map_rc .borrow_mut() @@ -1144,22 +1149,24 @@ impl JsRuntime { .expect("Invalid dynamic import id"); let resolver = resolver_handle.open(scope); - let exception: v8::Local = err + let exception = err .downcast_ref::() .map(|err| err.get_handle(scope)) .unwrap_or_else(|| { let message = err.to_string(); let message = v8::String::new(scope, &message).unwrap(); - let err_class = - v8::Local::::new(&mut scope, err_class.unwrap()); - let maybe_err_class = - v8::Local::::try_from(err_class).ok(); - if let Some(err_class) = maybe_err_class { - let err = err_class.new_instance(scope, &[message.into()]).unwrap(); - err.into() - } else { - v8::Exception::type_error(scope, message) + if let Ok(err_class) = Self::execute_script_with_scope( + scope, + "", + get_error_class_fn(&err), + ) { + if let Ok(err_class) = v8::Local::::try_from( + v8::Local::::new(scope, err_class), + ) { + return err_class.new_instance(scope, &[message.into()]).unwrap().into(); + } } + v8::Exception::type_error(scope, message) }); // IMPORTANT: No borrows to `ModuleMap` can be held at this point because From a4aec92c7114d8f0296c2e6b6b6d5cc91d63e14b Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 3 Nov 2021 21:54:31 +0900 Subject: [PATCH 3/7] chore: fmt --- core/runtime.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/runtime.rs b/core/runtime.rs index ac25e94f815771..7fe6d6f2f7b612 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -1163,7 +1163,10 @@ impl JsRuntime { if let Ok(err_class) = v8::Local::::try_from( v8::Local::::new(scope, err_class), ) { - return err_class.new_instance(scope, &[message.into()]).unwrap().into(); + return err_class + .new_instance(scope, &[message.into()]) + .unwrap() + .into(); } } v8::Exception::type_error(scope, message) From 34efd0b56bc475fad990eb3b9f3e8d58bd1fe774 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Thu, 4 Nov 2021 14:52:52 +0900 Subject: [PATCH 4/7] refactor: create CustomErrorWithJsConstructor struct --- cli/proc_state.rs | 24 +++++++++++------------- core/error.rs | 42 +++++++++++++++++++++++++++++++++++++++++- core/runtime.rs | 38 +++++++++++++++++++++++--------------- 3 files changed, 75 insertions(+), 29 deletions(-) diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 535702f94323ab..7e6822c154e07d 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -20,6 +20,7 @@ use crate::version; use deno_core::error::anyhow; use deno_core::error::custom_error; +use deno_core::error::custom_error_with_js_constructor; use deno_core::error::get_custom_error_class; use deno_core::error::AnyError; use deno_core::error::Context; @@ -517,23 +518,20 @@ impl ProcState { return Ok(module_source.clone()); } } else { - let error_class = if self.flags.compat { - "Deno.compat.errors.ERR_MODULE_NOT_FOUND" - } else { - "TypeError" - }; + let mut message = format!("Cannot load module \"{}\".", specifier); if maybe_referrer.is_some() && !is_dynamic { if let Some(span) = graph_data.resolved_map.get(&specifier) { - return Err(custom_error( - error_class, - format!("Cannot load module \"{}\".\n at {}", specifier, span), - )); + message = + format!("Cannot load module \"{}\".\n at {}", specifier, span); } } - return Err(custom_error( - error_class, - format!("Cannot load module \"{}\".", specifier), - )); + if self.flags.compat { + return Err(custom_error_with_js_constructor( + "Deno.compat.errors.ERR_MODULE_NOT_FOUND", + message, + )); + } + return Err(custom_error("NotFound", message)); } } diff --git a/core/error.rs b/core/error.rs index 793a42603f099f..82a7160b709dea 100644 --- a/core/error.rs +++ b/core/error.rs @@ -82,10 +82,50 @@ impl Display for CustomError { impl Error for CustomError {} +pub fn custom_error_with_js_constructor( + js_constructor: &'static str, + message: impl Into>, +) -> AnyError { + CustomErrorWithJsConstructor { + js_constructor, + message: message.into(), + } + .into() +} + +#[derive(Debug)] +struct CustomErrorWithJsConstructor { + js_constructor: &'static str, + message: Cow<'static, str>, +} + +impl Display for CustomErrorWithJsConstructor { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_str(&self.message) + } +} + +impl Error for CustomErrorWithJsConstructor {} + /// If this error was crated with `custom_error()`, return the specified error /// class name. In all other cases this function returns `None`. pub fn get_custom_error_class(error: &AnyError) -> Option<&'static str> { - error.downcast_ref::().map(|e| e.class) + error + .downcast_ref::() + .map(|e| e.class) + .or_else(|| { + error + .downcast_ref::() + .map(|e| e.js_constructor) + }) +} + +/// If this error was crated with `custom_error()`, return the specified js constructor +/// class name. In all other cases this function returns `None`. +pub fn get_custom_js_constructor(error: &AnyError) -> Option<&'static str> { + error + .downcast_ref::() + .map(|e| e.js_constructor) } /// A `JsError` represents an exception coming from V8, with stack frames and diff --git a/core/runtime.rs b/core/runtime.rs index 7fe6d6f2f7b612..70d0e430aba73d 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -3,6 +3,7 @@ use crate::bindings; use crate::error::attach_handle_to_error; use crate::error::generic_error; +use crate::error::get_custom_js_constructor; use crate::error::AnyError; use crate::error::ErrWithV8Handle; use crate::error::JsError; @@ -1139,7 +1140,6 @@ impl JsRuntime { fn dynamic_import_reject(&mut self, id: ModuleLoadId, err: AnyError) { let module_map_rc = Self::module_map(self.v8_isolate()); - let get_error_class_fn = self.op_state().borrow().get_error_class_fn; let scope = &mut self.handle_scope(); let resolver_handle = module_map_rc @@ -1152,23 +1152,31 @@ impl JsRuntime { let exception = err .downcast_ref::() .map(|err| err.get_handle(scope)) - .unwrap_or_else(|| { - let message = err.to_string(); - let message = v8::String::new(scope, &message).unwrap(); - if let Ok(err_class) = Self::execute_script_with_scope( - scope, - "", - get_error_class_fn(&err), - ) { - if let Ok(err_class) = v8::Local::::try_from( - v8::Local::::new(scope, err_class), + .or_else(|| { + if let Some(js_constructor) = get_custom_js_constructor(&err) { + if let Ok(err_class) = Self::execute_script_with_scope( + scope, + "", + js_constructor, ) { - return err_class - .new_instance(scope, &[message.into()]) - .unwrap() - .into(); + if let Ok(err_class) = v8::Local::::try_from( + v8::Local::::new(scope, err_class), + ) { + let message = v8::String::new(scope, &err.to_string()).unwrap(); + return Some( + err_class + .new_instance(scope, &[message.into()]) + .unwrap() + .into(), + ); + } } } + None + }) + .unwrap_or_else(|| { + let message = err.to_string(); + let message = v8::String::new(scope, &message).unwrap(); v8::Exception::type_error(scope, message) }); From 7730714624211cf4db911ef8a13c15794ae90d72 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Thu, 4 Nov 2021 15:12:46 +0900 Subject: [PATCH 5/7] modify --- core/error.rs | 5 +++-- core/runtime.rs | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/error.rs b/core/error.rs index 82a7160b709dea..0672c1c8444dfa 100644 --- a/core/error.rs +++ b/core/error.rs @@ -120,8 +120,9 @@ pub fn get_custom_error_class(error: &AnyError) -> Option<&'static str> { }) } -/// If this error was crated with `custom_error()`, return the specified js constructor -/// class name. In all other cases this function returns `None`. +/// If this error was crated with `custom_error_with_js_constructor()`, return +/// the specified js constructor class name. In all other cases this function +/// returns `None`. pub fn get_custom_js_constructor(error: &AnyError) -> Option<&'static str> { error .downcast_ref::() diff --git a/core/runtime.rs b/core/runtime.rs index 70d0e430aba73d..7e758773392d23 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -1159,9 +1159,8 @@ impl JsRuntime { "", js_constructor, ) { - if let Ok(err_class) = v8::Local::::try_from( - v8::Local::::new(scope, err_class), - ) { + let value = v8::Local::::new(scope, err_class); + if let Ok(err_class) = v8::Local::::try_from(value) { let message = v8::String::new(scope, &err.to_string()).unwrap(); return Some( err_class From 8b09ada25acb9a633933b6e99e6381d46034ecdc Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sun, 7 Nov 2021 13:36:42 +0900 Subject: [PATCH 6/7] fix: set code to type error --- cli/proc_state.rs | 19 ++++---- .../testdata/compat/dyn_import_reject.out | 2 +- core/bindings.rs | 3 ++ core/error.rs | 43 +------------------ core/runtime.rs | 29 ------------- runtime/js/07_compat.js | 23 ---------- runtime/js/90_deno_ns.js | 1 - 7 files changed, 13 insertions(+), 107 deletions(-) delete mode 100644 runtime/js/07_compat.js diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 7e6822c154e07d..0c81ab2e88428c 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -20,7 +20,6 @@ use crate::version; use deno_core::error::anyhow; use deno_core::error::custom_error; -use deno_core::error::custom_error_with_js_constructor; use deno_core::error::get_custom_error_class; use deno_core::error::AnyError; use deno_core::error::Context; @@ -518,20 +517,18 @@ impl ProcState { return Ok(module_source.clone()); } } else { - let mut message = format!("Cannot load module \"{}\".", specifier); if maybe_referrer.is_some() && !is_dynamic { if let Some(span) = graph_data.resolved_map.get(&specifier) { - message = - format!("Cannot load module \"{}\".\n at {}", specifier, span); + return Err(custom_error( + "NotFound", + format!("Cannot load module \"{}\".\n at {}", specifier, span), + )); } } - if self.flags.compat { - return Err(custom_error_with_js_constructor( - "Deno.compat.errors.ERR_MODULE_NOT_FOUND", - message, - )); - } - return Err(custom_error("NotFound", message)); + return Err(custom_error( + "NotFound", + format!("Cannot load module \"{}\".", specifier), + )); } } diff --git a/cli/tests/testdata/compat/dyn_import_reject.out b/cli/tests/testdata/compat/dyn_import_reject.out index 510957829581ea..6d78135b27f9c8 100644 --- a/cli/tests/testdata/compat/dyn_import_reject.out +++ b/cli/tests/testdata/compat/dyn_import_reject.out @@ -1,2 +1,2 @@ -Error: Cannot load module "file:///[WILDCARD]/testdata/compat/foobar.js". +TypeError: Cannot load module "file:///[WILDCARD]/testdata/compat/foobar.js". ERR_MODULE_NOT_FOUND diff --git a/core/bindings.rs b/core/bindings.rs index d1b01c2d99641d..6f61dabfdbce9f 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -244,6 +244,9 @@ pub extern "C" fn host_import_module_dynamically_callback( let message = arg.get(scope, message_key.into()).unwrap(); let exception = v8::Exception::type_error(scope, message.try_into().unwrap()); + let code_key = v8::String::new(scope, "code").unwrap().into(); + let code_value = v8::String::new(scope, "ERR_MODULE_NOT_FOUND").unwrap().into(); + exception.to_object(scope).unwrap().set(scope, code_key, code_value); scope.throw_exception(exception); return; } diff --git a/core/error.rs b/core/error.rs index 0672c1c8444dfa..793a42603f099f 100644 --- a/core/error.rs +++ b/core/error.rs @@ -82,51 +82,10 @@ impl Display for CustomError { impl Error for CustomError {} -pub fn custom_error_with_js_constructor( - js_constructor: &'static str, - message: impl Into>, -) -> AnyError { - CustomErrorWithJsConstructor { - js_constructor, - message: message.into(), - } - .into() -} - -#[derive(Debug)] -struct CustomErrorWithJsConstructor { - js_constructor: &'static str, - message: Cow<'static, str>, -} - -impl Display for CustomErrorWithJsConstructor { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - f.write_str(&self.message) - } -} - -impl Error for CustomErrorWithJsConstructor {} - /// If this error was crated with `custom_error()`, return the specified error /// class name. In all other cases this function returns `None`. pub fn get_custom_error_class(error: &AnyError) -> Option<&'static str> { - error - .downcast_ref::() - .map(|e| e.class) - .or_else(|| { - error - .downcast_ref::() - .map(|e| e.js_constructor) - }) -} - -/// If this error was crated with `custom_error_with_js_constructor()`, return -/// the specified js constructor class name. In all other cases this function -/// returns `None`. -pub fn get_custom_js_constructor(error: &AnyError) -> Option<&'static str> { - error - .downcast_ref::() - .map(|e| e.js_constructor) + error.downcast_ref::().map(|e| e.class) } /// A `JsError` represents an exception coming from V8, with stack frames and diff --git a/core/runtime.rs b/core/runtime.rs index 7e758773392d23..80221295da3860 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -3,7 +3,6 @@ use crate::bindings; use crate::error::attach_handle_to_error; use crate::error::generic_error; -use crate::error::get_custom_js_constructor; use crate::error::AnyError; use crate::error::ErrWithV8Handle; use crate::error::JsError; @@ -562,14 +561,7 @@ impl JsRuntime { source_code: &str, ) -> Result, AnyError> { let scope = &mut self.handle_scope(); - Self::execute_script_with_scope(scope, name, source_code) - } - fn execute_script_with_scope( - scope: &mut v8::HandleScope, - name: &str, - source_code: &str, - ) -> Result, AnyError> { let source = v8::String::new(scope, source_code).unwrap(); let name = v8::String::new(scope, name).unwrap(); let origin = bindings::script_origin(scope, name); @@ -1152,27 +1144,6 @@ impl JsRuntime { let exception = err .downcast_ref::() .map(|err| err.get_handle(scope)) - .or_else(|| { - if let Some(js_constructor) = get_custom_js_constructor(&err) { - if let Ok(err_class) = Self::execute_script_with_scope( - scope, - "", - js_constructor, - ) { - let value = v8::Local::::new(scope, err_class); - if let Ok(err_class) = v8::Local::::try_from(value) { - let message = v8::String::new(scope, &err.to_string()).unwrap(); - return Some( - err_class - .new_instance(scope, &[message.into()]) - .unwrap() - .into(), - ); - } - } - } - None - }) .unwrap_or_else(|| { let message = err.to_string(); let message = v8::String::new(scope, &message).unwrap(); diff --git a/runtime/js/07_compat.js b/runtime/js/07_compat.js deleted file mode 100644 index fcaa2ea015a848..00000000000000 --- a/runtime/js/07_compat.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -"use strict"; - -((window) => { - const { - Error, - } = window.__bootstrap.primordials; - - class ERR_MODULE_NOT_FOUND extends Error { - constructor(msg) { - super(msg); - this.code = "ERR_MODULE_NOT_FOUND"; - } - } - - const errors = { - ERR_MODULE_NOT_FOUND, - }; - - window.__bootstrap.compat = { - errors, - }; -})(this); diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index b64ea74570d18c..f858a93eb30b01 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -139,6 +139,5 @@ flockSync: __bootstrap.fs.flockSync, funlock: __bootstrap.fs.funlock, funlockSync: __bootstrap.fs.funlockSync, - compat: __bootstrap.compat, }; })(this); From 0dfdd868f2de350a22c843dce31650350a8e63f4 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sun, 7 Nov 2021 13:42:50 +0900 Subject: [PATCH 7/7] chore: fmt --- core/bindings.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/bindings.rs b/core/bindings.rs index 6f61dabfdbce9f..10daee27ab93c3 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -244,9 +244,11 @@ pub extern "C" fn host_import_module_dynamically_callback( let message = arg.get(scope, message_key.into()).unwrap(); let exception = v8::Exception::type_error(scope, message.try_into().unwrap()); - let code_key = v8::String::new(scope, "code").unwrap().into(); - let code_value = v8::String::new(scope, "ERR_MODULE_NOT_FOUND").unwrap().into(); - exception.to_object(scope).unwrap().set(scope, code_key, code_value); + let code_key = v8::String::new(scope, "code").unwrap(); + let code_value = + v8::String::new(scope, "ERR_MODULE_NOT_FOUND").unwrap(); + let exception_obj = exception.to_object(scope).unwrap(); + exception_obj.set(scope, code_key.into(), code_value.into()); scope.throw_exception(exception); return; }