1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -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:
Ryan Dahl 2020-04-16 06:58:17 -04:00 committed by GitHub
parent 42c421f49d
commit 5f250bb148
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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| {