Repository navigation
fix(ecmascript): reject top-level await in strict scripts and eval - #1007
Open
EthanThatOneKid wants to merge 1 commit into
Open
EthanThatOneKid wants to merge 1 commit into
EthanThatOneKid wants to merge 1 commit into
Conversation
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
force-pushed
the
fix/ecmascript-strict-await-syntax-error
branch
from
November 21, 2026 04:52
b6a9f06 to
751044a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1006.
Problem
A strict-mode script or
evalcontaining anawaitexpression orfor awaitoutside an async function panicked withUnexpected yield or await(vm.rs:49) instead of throwing aSyntaxError.SourceCode::parse_sourceparses strict scripts and evals as a sloppy script first, to reject module-only syntax like top-levelawait, and then re-parses as a module to get strict mode. The sloppy parse was only treated as failed when the parserpanicked, so non-fatal parser errors were dropped. The module re-parse then accepted theawait, which compiled to anAwaitat 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 strictScriptand strictEvalwithawait 10;andfor await. It fails without the fix and passes with it.Also removes the two now-passing tests from
tests/expectations.jsonand updatestests/metrics.json(crash 162 → 160, pass 40692 → 40694).Results
eval("await 10"),eval("for await (let x of []) {}"), scriptawait 10;(strict)Unexpected yield or awaitSyntaxError(same as--no-strict)staging/sm/async-functions/await-error.jsstaging/sm/AsyncGenerators/for-await-of-error.jscargo test(nova_vm lib)cargo fmt --checkcargo clippy --all-targets -- -D warningsNotes
-uon 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.+nightly-2026-10-01clippy run,cargo dylint, and the typos check from CI.