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
,
Mar 8 2018
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?
,
Mar 8 2018
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.
,
Mar 8 2018
,
Mar 8 2018
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.
,
Mar 8 2018
,
Mar 15 2018
I cannot reproduce this now, so it might have been another bug and a confusing error message. I guess we can close
,
Mar 15 2018
Closing per #7 |
||||||
►
Sign in to add a comment |
||||||
Comment 1 by kenneth....@gmail.com
, Mar 8 2018