Skip to content

Commit e4468e0

Browse files
mamekateinoigakukun
authored andcommitted
Add JS::Undefined and JS::Null
just for convenience
1 parent dbca040 commit e4468e0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ext/js/lib/js.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# end
1414
#
1515
module JS
16+
Undefined = JS.eval("return undefined")
17+
Null = JS.eval("return null")
1618
end
1719

1820
class JS::Object

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,16 @@ describe("Manipulation of JS from Ruby", () => {
228228
object.call("itself");
229229
}
230230
});
231+
232+
test.each([
233+
{ expr: `JS::Undefined`, expected: "undefined" },
234+
{ expr: `JS::Null`, expected: "null" },
235+
])("constant %s", async ({ expr, expected }) => {
236+
const vm = await initRubyVM();
237+
const result = vm.eval(`
238+
require "js"
239+
${expr}.inspect
240+
`);
241+
expect(result.toJS()).toEqual(expected);
242+
});
231243
});

0 commit comments

Comments
 (0)