Skip to content

Inspect JS value by String(v) instead of v.toString #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/npm-packages/ruby-wasm-wasi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ export class RubyVM {
return new RbValue(abiValue, this, this.privateObject());
},
jsValueToString: (value) => {
return value.toString();
// According to the [spec](https://tc39.es/ecma262/multipage/text-processing.html#sec-string-constructor-string-value)
// `String(value)` always returns a string.
return String(value);
},
exportJsValueToHost: (value) => {
// See `JsValueExporter` for the reason why we need to do this
Expand Down
3 changes: 3 additions & 0 deletions packages/npm-packages/ruby-wasm-wasi/test/js_from_rb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ describe("Manipulation of JS from Ruby", () => {
test.each([
{ expr: `JS.global`, expected: "[object Object]" },
{ expr: `1.to_js`, expected: "1" },
{ expr: `JS.eval("return null")`, expected: "null" },
{ expr: `JS.eval("return undefined")`, expected: "undefined" },
{ expr: `JS.eval("return Symbol('sym')")`, expected: "Symbol(sym)" },
{ expr: `JS.eval("return {}")`, expected: "[object Object]" },
{
expr: `JS.eval("class X {}; return new X()")`,
Expand Down