mirror of
https://github.com/denoland/deno.git
synced 2024-12-27 01:29:14 -05:00
Properly propagate error when deno_core::Isolate gets syntax error (#4770)
Co-authored-by: Filipe Schenkel de Souza <filipe.schenkel@azion.com> Co-authored-by: Douglas Caetano dos Santos <douglas.santos@azion.com> Co-authored-by: João Avelino Bellomo Filho <joao.avelino@azion.com>
This commit is contained in:
parent
42c421f49d
commit
5f250bb148
1 changed files with 18 additions and 1 deletions
|
@ -446,7 +446,14 @@ impl Isolate {
|
|||
let tc = try_catch.enter();
|
||||
|
||||
let mut script =
|
||||
v8::Script::compile(scope, context, source, Some(&origin)).unwrap();
|
||||
match v8::Script::compile(scope, context, source, Some(&origin)) {
|
||||
Some(script) => script,
|
||||
None => {
|
||||
let exception = tc.exception().unwrap();
|
||||
return exception_to_err_result(scope, exception, js_error_create_fn);
|
||||
}
|
||||
};
|
||||
|
||||
match script.run(scope, context) {
|
||||
Some(_) => Ok(()),
|
||||
None => {
|
||||
|
@ -1152,6 +1159,16 @@ pub mod tests {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn syntax_error() {
|
||||
let mut isolate = Isolate::new(StartupData::None, false);
|
||||
let src = "hocuspocus(";
|
||||
let r = isolate.execute("i.js", src);
|
||||
let e = r.unwrap_err();
|
||||
let js_error = e.downcast::<JSError>().unwrap();
|
||||
assert_eq!(js_error.end_column, Some(11));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_encode_decode() {
|
||||
run_in_task(|mut cx| {
|
||||
|
|
Loading…
Reference in a new issue