diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2021-11-08 16:02:40 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-08 16:02:40 +0900 |
commit | 8e010b6844b339ab138b4d9e40148c60d44d197a (patch) | |
tree | 8ad367d0b7bfc81b22dc2307a20efc2b57bb1363 | |
parent | 3828a7eb11de2beeb545e464550249337ca5618a (diff) |
feat(compat): add .code to dyn import error (#12633)
-rw-r--r-- | cli/tests/integration/compat_tests.rs | 5 | ||||
-rw-r--r-- | cli/tests/testdata/compat/dyn_import_reject.js | 4 | ||||
-rw-r--r-- | cli/tests/testdata/compat/dyn_import_reject.out | 2 | ||||
-rw-r--r-- | core/bindings.rs | 5 |
4 files changed, 16 insertions, 0 deletions
diff --git a/cli/tests/integration/compat_tests.rs b/cli/tests/integration/compat_tests.rs index 81d2985b3..e15a19b8a 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 000000000..f9a99f0da --- /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 000000000..6d78135b2 --- /dev/null +++ b/cli/tests/testdata/compat/dyn_import_reject.out @@ -0,0 +1,2 @@ +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 d1b01c2d9..10daee27a 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -244,6 +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(); + 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; } |