Closed Bug 1494726 Opened 1 year ago Closed 1 year ago
Malformed top-level await expression lead to confusing error
47 bytes, text/x-phabricator-request
|Details | Review|
**Steps to reproduce** 1. Open the console 2. Evaluate `await new Promise())` **Expected results** I get the same error as when I only type `Promise())`: `SyntaxError: unexpected token: ')'` **Actual results** The following error is displayed: `SyntaxError: await is only valid in async functions and async generators` --- The error is very confusing since we should now support top-level await.
Priority: -- → P2
Assignee: nobody → nchevobbe
Status: NEW → ASSIGNED
Priority: P2 → P1
When an expression starting with await is not mapped by the parserService, this means it is malformed. In order to get a meaningful error, we wrap it in an async iife before evaluatin it so the engine throws the appropriate error, and not "await is only valid in async functions and async generators". A test case is added to make sure this works as expected.
Attachment #9034992 - Attachment description: Bug 1494726 - Fix unhelpful error in top-level await malformed expression; r=jlast. → Bug 1494726 - Add a test for malformed top-level await expressions; r=jlast.
Pushed by email@example.com: https://hg.mozilla.org/integration/autoland/rev/46a48161f428 Add a test for malformed top-level await expressions; r=jlast.
You need to log in before you can comment on or make changes to this bug.