Skip to content

fix(ecmascript): reject top-level await in strict scripts and eval - #1007

Open
EthanThatOneKid wants to merge 1 commit into
trynova:mainfrom
EthanThatOneKid:fix/ecmascript-strict-await-syntax-error
Open

EthanThatOneKid wants to merge 1 commit into
trynova:mainfrom
EthanThatOneKid:fix/ecmascript-strict-await-syntax-error

Conversation

@EthanThatOneKid

@EthanThatOneKid EthanThatOneKid commented Nov 21, 2026 •

Copy link
Copy Markdown

Fixes #1006.

Problem

A strict-mode script or eval containing an await expression or for await outside an async function panicked with Unexpected yield or await (vm.rs:49) instead of throwing a SyntaxError.

SourceCode::parse_source parses strict scripts and evals as a sloppy script first, to reject module-only syntax like top-level await, and then re-parses as a module to get strict mode. The sloppy parse was only treated as failed when the parser panicked, so non-fatal parser errors were dropped. The module re-parse then accepted the await, which compiled to an Await at the top level.

Change

Return the sloppy parse errors too (if panicked || !sloppy_errors.is_empty()). Adds a unit test, strict_script_with_top_level_await, covering strict Script and strict Eval with await 10; and for await. It fails without the fix and passes with it.

Also removes the two now-passing tests from tests/expectations.json and updates tests/metrics.json (crash 162 → 160, pass 40692 → 40694).

Results

Before (591bf7b) After
eval("await 10"), eval("for await (let x of []) {}"), script await 10; (strict) panic Unexpected yield or await SyntaxError (same as --no-strict)
staging/sm/async-functions/await-error.js Crash Pass
staging/sm/AsyncGenerators/for-await-of-error.js Crash Pass
test262 crash / pass 162 / 40692 160 / 40694
cargo test (nova_vm lib) 69 passed 70 passed
cargo fmt --check ok ok
cargo clippy --all-targets -- -D warnings ok ok

Notes

  • I ran the full test262 suite with -u on Windows. There it reports 35 unrelated differences from the Linux expectations (TCO tests crashing or timing out, a CRLF line-terminator test, recursion.js, Date timing) both before and after this change. I did not commit those, only the two intended changes, so the Linux CI Test262 job is the authoritative check on the expectations.
  • Not run locally: the +nightly-2026-10-01 clippy run, cargo dylint, and the typos check from CI.

Strict scripts and evals are syntax checked as a sloppy script first to
reject module-only syntax such as top-level await, and then re-parsed as
a module to get strict mode. The sloppy parse was only treated as failed
when the parser panicked, so non-fatal parser errors were dropped. The
module re-parse then accepted `await` expressions and `for await`, which
compiled to an Await at the top level and hit the "Unexpected yield or
await" panic in ExecutionResult::into_js_result.

Return the sloppy parse errors as well, so these now throw a SyntaxError
like they do in sloppy mode.

Fixes trynova#1006
@EthanThatOneKid
EthanThatOneKid force-pushed the fix/ecmascript-strict-await-syntax-error branch from b6a9f06 to 751044a Compare November 21, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strict-mode script/eval containing await panics with "Unexpected yield or await" instead of throwing SyntaxError

1 participant