Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update crypto.subtle.digest() example in to fix async/await usage problems #1443

Closed
1 of 3 tasks
chrisdavidmills opened this issue Jan 18, 2021 · 0 comments · Fixed by #6619
Closed
1 of 3 tasks

Update crypto.subtle.digest() example in to fix async/await usage problems #1443

chrisdavidmills opened this issue Jan 18, 2021 · 0 comments · Fixed by #6619
Labels
Content:WebAPI Web API docs help wanted If you know something about this topic, we would love your help!

Comments

@chrisdavidmills
Copy link
Contributor

@bbrown-spsu commented on Wed Dec 09 2020

Request type

  • Please close this issue, I accidentally submitted it without adding any details
  • New documentation
  • Correction or update

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 on Sun Dec 20 2020

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 on Sun Dec 20 2020

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 on Mon Dec 21 2020

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.

@sideshowbarker sideshowbarker added the help wanted If you know something about this topic, we would love your help! label Jun 9, 2021
@sideshowbarker sideshowbarker changed the title https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest Update example in crypto.subtle.digest article to fix problems with async/await usage Jun 9, 2021
@sideshowbarker sideshowbarker changed the title Update example in crypto.subtle.digest article to fix problems with async/await usage Update example in crypto.subtle.digest doc to fix problems with async/await usage Jun 9, 2021
@sideshowbarker sideshowbarker changed the title Update example in crypto.subtle.digest doc to fix problems with async/await usage Update crypto.subtle.digest() example in to fix problems with async/await usage Jun 9, 2021
@sideshowbarker sideshowbarker changed the title Update crypto.subtle.digest() example in to fix problems with async/await usage Update crypto.subtle.digest() example in to fix async/await usage problems Jun 9, 2021
dontcallmedom added a commit to dontcallmedom/content that referenced this issue Jul 6, 2021
dontcallmedom added a commit to dontcallmedom/content that referenced this issue Jul 6, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Content:WebAPI Web API docs help wanted If you know something about this topic, we would love your help!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants