mdn / sprints

Archived: MDN Web Docs issues are tracked in the content repository.
https://github.com/mdn/content
Creative Commons Zero v1.0 Universal
150 stars 142 forks source link

https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest #3950

Closed bbrown-spsu closed 3 years ago

bbrown-spsu commented 3 years ago

Request type

Details

The examples on this page will not run in Firefox 83.0 64 bit. That appears to be because "await" is not within an async function on the next-to-last line. The message I get is "Uncaught SyntaxError: await is only valid in async functions and async generators"

https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest

MendyBerger commented 3 years ago

As pointed out by @bbrown-spsu this is because of an await that is not in an async function.

What is the general rule when it come's to cases like this? Do we wrap it with an async iife (would probably bloat the code samples)? Do we assume that users will understand that they have to put it in an async function? Any other options?

Worth pointing out that this is not an example that is meant to be run from withing the page like interactive-examples, but rather its a code sample.

bbrown-spsu commented 3 years ago

A couple of thoughts...

  1. "Assume users will understand..." is fraught with possibilities for badness. People come to the examples because they do not understand.
  2. Bloated examples are better than obscure examples for the reason given above.

I think the very minimum change would be a comment before the call: // The code below must itself be within an async function. Better would be a real async function (not iife) called by a non-async function, in other words, something that could be clipped out and run. It would double the length of the example, but more than double the usefulness of the example.

chrisdavidmills commented 3 years ago

I would be happy for you to fix them up so they are runnable at a basic level. I agree with @bbrown-spsu here, and async/await is still fairly new.

chrisdavidmills commented 3 years ago

Issue moved to mdn/content #1443 via ZenHub