mirror of
https://github.com/denoland/deno
synced 2024-08-27 20:09:17 +00:00
Avoid crashes on ES module resolution when module not found (#1546)
This commit is contained in:
parent
315e4abd7e
commit
f9b167deb0
|
@ -558,7 +558,11 @@ v8::MaybeLocal<v8::Module> ResolveCallback(v8::Local<v8::Context> context,
|
|||
|
||||
if (d->resolve_module_.IsEmpty()) {
|
||||
// Resolution Error.
|
||||
isolate->ThrowException(v8_str("module resolution error"));
|
||||
std::stringstream err_ss;
|
||||
err_ss << "NotFound: Cannot resolve module \"" << specifier_c
|
||||
<< "\" from \"" << referrer_filename << "\"";
|
||||
auto resolve_error = v8_str(err_ss.str().c_str());
|
||||
isolate->ThrowException(resolve_error);
|
||||
return v8::MaybeLocal<v8::Module>();
|
||||
} else {
|
||||
auto module = d->resolve_module_.Get(isolate);
|
||||
|
@ -612,6 +616,8 @@ bool ExecuteMod(v8::Local<v8::Context> context, const char* js_filename,
|
|||
auto module = maybe_module.ToLocalChecked();
|
||||
auto maybe_ok = module->InstantiateModule(context, ResolveCallback);
|
||||
if (maybe_ok.IsNothing()) {
|
||||
DCHECK(try_catch.HasCaught());
|
||||
HandleException(context, try_catch.Exception());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -403,8 +403,15 @@ extern "C" fn resolve_cb(
|
|||
debug!("module_resolve callback {} {}", specifier, referrer);
|
||||
let isolate = unsafe { Isolate::from_raw_ptr(user_data) };
|
||||
|
||||
let out =
|
||||
code_fetch_and_maybe_compile(&isolate.state, specifier, referrer).unwrap();
|
||||
let maybe_out =
|
||||
code_fetch_and_maybe_compile(&isolate.state, specifier, referrer);
|
||||
|
||||
if maybe_out.is_err() {
|
||||
// Resolution failure
|
||||
return;
|
||||
}
|
||||
|
||||
let out = maybe_out.unwrap();
|
||||
|
||||
let filename = CString::new(out.filename.clone()).unwrap();
|
||||
let filename_ptr = filename.as_ptr() as *const i8;
|
||||
|
|
1
tests/error_009_missing_js_module.js
Normal file
1
tests/error_009_missing_js_module.js
Normal file
|
@ -0,0 +1 @@
|
|||
import "./bad-module.js";
|
1
tests/error_009_missing_js_module.js.out
Normal file
1
tests/error_009_missing_js_module.js.out
Normal file
|
@ -0,0 +1 @@
|
|||
NotFound: Cannot resolve module "./bad-module.js" from "[WILDCARD]/tests/error_009_missing_js_module.js"
|
4
tests/error_009_missing_js_module.test
Normal file
4
tests/error_009_missing_js_module.test
Normal file
|
@ -0,0 +1,4 @@
|
|||
args: tests/error_009_missing_js_module.js
|
||||
check_stderr: true
|
||||
exit_code: 1
|
||||
output: tests/error_009_missing_js_module.js.out
|
Loading…
Reference in a new issue