New issue
Advanced search Search tips

Issue 820012 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner:
Closed: Mar 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Android , Windows , Chrome , Mac
Pri: 3
Type: Bug



Sign in to add a comment

Complaining about await inside async function as part of Promise in Service Worker

Reported by kenneth....@gmail.com, Mar 8 2018

Issue description

I have the following code in a SW:

const decoderReady = new Promise(async resolve => {
  if (WebPDecoder) {
    return WebPDecoder;
  }
  importScripts('webp-decoder.js');

  const { WebPDecoder } = await importWebPDecoder(); // <- line 6
  resolve(WebPDecoder);
})

(and later inside async function):
const WebPDecoder = await decoderReady;

But it fails with the following error:

sw.js:6 Uncaught (in promise) Error: Uncaught SyntaxError: await is only valid in async function
    at Promise (sw.js:6)
    at new Promise (<anonymous>)
    at sw.js:2
 
Actually this seems to be the line before... importScripts() where there are async functions with await
Cc: adamk@chromium.org gsat...@chromium.org
Labels: OS-Android OS-Chrome OS-Mac OS-Windows
Hmm, that `await` on line 6 does occur directly within the `async` arrow function, so this smells like a bug indeed.

Have you been able to come up with a reduced test case for this behavior? 
This program works as expected:

    const p = new Promise(async (resolve) => {
      const x = await 42;
      resolve(x);
    });

So it seems the `importScripts` call might have an influence.

Comment 4 by adamk@chromium.org, Mar 8 2018

Labels: needs-feee

Comment 5 by adamk@chromium.org, Mar 8 2018

Labels: -needs-feee Needs-Feedback
Indeed this requires more detail before we can further triage; the problem as reported shouldn't happen.

A full reduction isn't necessary, but the contents of webp-decoder.js are.
Components: Blink>JavaScript
I cannot reproduce this now, so it might have been another bug and a confusing error message. I guess we can close

Comment 8 by adamk@chromium.org, Mar 15 2018

Labels: -Needs-Feedback
Owner: adamk@chromium.org
Status: WontFix (was: Unconfirmed)
Closing per #7

Sign in to add a comment