Skip to content

Commit afcb09f

Browse files
Return the result of Proc when it's called as JS closure
Somehow, the return value of the Proc was not returned to the JS side.
1 parent 4b53900 commit afcb09f

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

packages/gems/js/lib/js.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def await(promise)
7979
current = Fiber.current
8080
promise.call(
8181
:then,
82-
->(value) { current.transfer(value, :success) },
83-
->(value) { current.transfer(value, :failure) }
82+
->(value) { current.transfer(value, :success); nil },
83+
->(value) { current.transfer(value, :failure); nil }
8484
)
8585
if @loop == current
8686
raise (

packages/npm-packages/ruby-wasm-wasi/src/vm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export class RubyVM {
210210
procToJsFunction: (rawRbAbiValue) => {
211211
const rbValue = this.rbValueOfPointer(rawRbAbiValue);
212212
return (...args) => {
213-
rbValue.call("call", ...args.map((arg) => this.wrap(arg)));
213+
return rbValue.call("call", ...args.map((arg) => this.wrap(arg))).toJS();
214214
};
215215
},
216216
rbObjectToJsRbValue: (rawRbAbiValue) => {

packages/npm-packages/ruby-wasm-wasi/test/unit/test_proc.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@ def test_store_in_js
2626
function_to_call.call(:invoke)
2727
assert_equal 1, b
2828
end
29+
30+
def test_return_value
31+
obj = JS.eval(<<~JS)
32+
return { check: (callback) => { return callback(1) } }
33+
JS
34+
assert_equal 4, obj.call(:check, ->(a) { 3 + a.to_i }).to_i
35+
end
2936
end

0 commit comments

Comments
 (0)