Skip to content

Commit 8a41f10

Browse files
foward block in JS::Object#method_missing
1 parent bba21d7 commit 8a41f10

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

ext/js/lib/js.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "js.so"
22

33
class JS::Object
4-
def method_missing(name, *args)
5-
self.call(name, *args)
4+
def method_missing(name, *args, &block)
5+
self.call(name, *args, &block)
66
end
77
end

packages/npm-packages/ruby-wasm-wasi/test/js_from_rb.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ describe("Manipulation of JS from Ruby", () => {
8787
expect(vm.eval(result).toString()).toBe(props.result);
8888
});
8989

90+
test("JS::Object#method_missing with block", async () => {
91+
const vm = await initRubyVM();
92+
const proc = vm.eval(`
93+
require "js"
94+
proc do |obj|
95+
obj.take_block "x" do |y|
96+
$y = y
97+
end
98+
end
99+
`);
100+
proc.call("call", vm.wrap({
101+
take_block: (arg1: string, block: (_: any) => void) => {
102+
expect(arg1).toBe("x");
103+
block("y");
104+
}
105+
}))
106+
const y = vm.eval(`$y`);
107+
expect(y.toString()).toBe("y");
108+
});
109+
90110
test.each([
91111
{ expr: "JS.global[:Object]", result: Object },
92112
{ expr: "JS.global[:Object][:keys]", result: Object.keys },

0 commit comments

Comments
 (0)