Permalink
Browse files
Avoid crashes on ES module resolution when module not found (#1546)
- Loading branch information...
|
@@ -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; |
|
|
|
|
@@ -0,0 +1 @@ |
|
|
|
import "./bad-module.js"; |
|
|
@@ -0,0 +1 @@ |
|
|
|
NotFound: Cannot resolve module "./bad-module.js" from "[WILDCARD]/tests/error_009_missing_js_module.js" |
|
|
@@ -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
|
0 comments on commit
f9b167d