`JS::Object#await` is unavailable inside Proc converted into JS closure
Personne n'a encore pris cette issue.
- Langage dominant
- Ruby
- Étoiles
- 875
- Forks
- 68
- Merge moyen
- 9 j 5 h
- PR mergées (30 j)
- 1
Description
Reproducer
<html>
<script src="https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.6.0/dist/browser.script.iife.js"></script>
<script type="text/ruby" data-eval="async">
require "js"
JS.global.setTimeout(-> {
JS.global[:Promise].resolve.await
}, 0)
</script>
</html>
browser.script.iife.js:2731 Uncaught Error: /bundle/gems/js-2.6.0/lib/js.rb:86:in `await': JS::Object#await can be called only from RubyVM#evalAsync or RbValue#callAsync JS API
If you are using browser.script.iife.js, please ensure that you specify `data-eval="async"` in your script tag
e.g. <script type="text/ruby" data-eval="async">puts :hello</script>
Or <script type="text/ruby" data-eval="async" src="path/to/script.rb"></script> (RuntimeError)
/bundle/gems/js-2.6.0/lib/js.rb:240:in `await'
eval_async:9:in `block in <main>'
at checkStatusTag (browser.script.iife.js:2731:21)
at browser.script.iife.js:2766:11
at wrapRbOperation (browser.script.iife.js:2738:18)
at callRbMethod (browser.script.iife.js:2764:14)
at RbValue.call (browser.script.iife.js:2547:30)
at browser.script.iife.js:2322:38
Workaround
Wrap the block with Fiber.new do ... end.transfer.
JS.global.setTimeout(-> {
Fiber.new do
JS.global[:Promise].resolve.await
end.transfer
}, 0)
Solutions
We have several options to solve the issue
- Always enter the body of Proc in Ruby with
callAsyncinstead ofcall- https://github.com/ruby/ruby.wasm/blob/dc9921a39c42cde001478622058531fc7ebf94e4/packages/npm-packages/ruby-wasm-wasi/src/vm.ts#L101C1-L106C9
- It's no use to manually choose whether
call/callAsyncandeval/evalAsync
- Add conversion method to create an async version of JS function from proc.
- e.g.
JS.global.setTimeout(JS.async do
JS.global[:Promise].resolve.await
end, 0)
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par le reproducteur et le contournement de JS::Object#await dans cette issue, puis examinez packages/npm-packages/ruby-wasm-wasi/src/vm.ts autour de l’implémentation liée de call/callAsync. Comparez la manière dont les callbacks Proc de setTimeout entrent dans Ruby et déterminez quelle direction proposée préserve le comportement asynchrone. Le travail est terminé lorsque le callback peut attendre le Promise sans nécessiter de transfert manuel de Fiber.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, ruby, wasm
- Domaine
- devtools, web-dev
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100