diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-04-16 06:58:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-16 12:58:17 +0200 |
commit | 5f250bb14835d0f1251b8e875a5fa431f12ef406 (patch) | |
tree | b2f626e9696ee1660d0858030d87198ad91392b1 /core/isolate.rs | |
parent | 42c421f49dcb7cd2e54ef590b0da6bf9004b696c (diff) |
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>
Diffstat (limited to 'core/isolate.rs')
-rw-r--r-- | core/isolate.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/core/isolate.rs b/core/isolate.rs index f876f2452..31a4c401c 100644 --- a/core/isolate.rs +++ b/core/isolate.rs @@ -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 => { @@ -1153,6 +1160,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| { let (mut isolate, _dispatch_count) = setup(Mode::Async); |