diff --git a/nova_vm/src/ecmascript/scripts_and_modules/source_code.rs b/nova_vm/src/ecmascript/scripts_and_modules/source_code.rs index 8448bf956..25fe372db 100644 --- a/nova_vm/src/ecmascript/scripts_and_modules/source_code.rs +++ b/nova_vm/src/ecmascript/scripts_and_modules/source_code.rs @@ -166,7 +166,7 @@ impl<'a> SourceCode<'a> { panicked, .. } = sloppy_result; - if panicked { + if panicked || !sloppy_errors.is_empty() { return Err(sloppy_errors); } let SemanticBuilderReturn { @@ -433,6 +433,40 @@ mod test { assert!(!errors.is_empty()); } + #[test] + fn strict_script_with_top_level_await() { + let (mut gc, mut scope) = unsafe { GcScope::create_root() }; + let mut gc = GcScope::new(&mut gc, &mut scope); + let mut agent = Agent::new(AgentOptions::default(), &DefaultHostHooks); + initialize_default_realm(&mut agent, gc.reborrow()); + + for source_type in [ + SourceCodeType::Script { strict: true }, + SourceCodeType::Eval { + direct: false, + strict: true, + }, + ] { + for source in ["await 10;", "for await (let x of []) {}"] { + let source_text = String::from_static_str(&mut agent, source, gc.nogc()); + // SAFETY: tests. + let errors = unsafe { + SourceCode::parse_source( + &mut agent, + source_text, + source_type, + #[cfg(feature = "typescript")] + false, + gc.nogc(), + ) + } + .unwrap_err(); + + assert!(!errors.is_empty()); + } + } + } + #[test] fn parse_and_realloc_source_codes_with_program() { let (mut gc, mut scope) = unsafe { GcScope::create_root() }; diff --git a/tests/expectations.json b/tests/expectations.json index d104ae2b5..2a274874e 100644 --- a/tests/expectations.json +++ b/tests/expectations.json @@ -7439,7 +7439,6 @@ "staging/sm/Array/unscopables.js": "FAIL", "staging/sm/Array/values.js": "FAIL", "staging/sm/ArrayBuffer/slice-species.js": "FAIL", - "staging/sm/AsyncGenerators/for-await-of-error.js": "CRASH", "staging/sm/BigInt/Number-conversion-rounding.js": "FAIL", "staging/sm/BigInt/large-bit-length.js": "TIMEOUT", "staging/sm/Date/dst-offset-caching-1-of-8.js": "TIMEOUT", @@ -7678,7 +7677,6 @@ "staging/sm/TypedArray/sort-non-function.js": "FAIL", "staging/sm/TypedArray/test-integrity-level-detached.js": "FAIL", "staging/sm/TypedArray/toString.js": "FAIL", - "staging/sm/async-functions/await-error.js": "CRASH", "staging/sm/async-functions/await-in-arrow-parameters.js": "FAIL", "staging/sm/async-functions/await-in-parameters-of-async-func.js": "FAIL", "staging/sm/async-functions/toString.js": "FAIL", diff --git a/tests/metrics.json b/tests/metrics.json index 64570d3a7..2a2b1f315 100644 --- a/tests/metrics.json +++ b/tests/metrics.json @@ -1,8 +1,8 @@ { "results": { - "crash": 162, + "crash": 160, "fail": 7572, - "pass": 40692, + "pass": 40694, "skip": 5127, "timeout": 22, "unresolved": 41