Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`JS::Object#await` is unavailable inside Proc converted into JS closure

Đang mở
#459 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, ruby, wasm
Lĩnh vực
devtools, web-dev

Hướng nghiên cứu

Bắt đầu với trình tái hiện và cách khắc phục JS::Object#await trong issue này, sau đó kiểm tra packages/npm-packages/ruby-wasm-wasi/src/vm.ts xung quanh phần triển khai call/callAsync được liên kết. So sánh cách các callback Proc từ setTimeout đi vào Ruby và xác định hướng được đề xuất nào duy trì hành vi bất đồng bộ. Được xem là hoàn tất khi callback có thể await Promise mà không cần chuyển Fiber thủ công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

  1. Always enter the body of Proc in Ruby with callAsync instead of call
  2. 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)
Ngôn ngữ chính
Ruby
Star
875
Fork
68
Merge trung bình
9 ngày 5 giờ
Pull request đã merge (30 ngày)
1

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ruby/ruby.wasm

Tất cả issue của ruby/ruby.wasm

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.