-
Notifications
You must be signed in to change notification settings - Fork 207
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
fix(xsnap): tolerate Symbols in console.log() arguments #3618
Conversation
The xsnap `print()` doesn't know how to print a Symbol, so until that's fixed, here's a workaround in our `tryPrint()` function. This is the backend of all console.log calls within the XS process. refs Moddable-OpenSource/moddable#679
36485f9
to
4b8e7e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test seems like it would pass without this fix, but that's not critical.
@@ -2,10 +2,14 @@ | |||
function tryPrint(...args) { | |||
try { | |||
// eslint-disable-next-line | |||
print(...args); | |||
print(...args.map(arg => typeof arg === 'symbol' ? arg.toString() : arg)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. The C code for print
already does fprintf(stdout, "%s", xsToString(xsArg(i)));
.
send('ok'); | ||
`); | ||
await vat.close(); | ||
t.deepEqual(['"ok"'], opts.messages); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just seems to test that it doesn't throw. It wasn't throwing before, was it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it throws without the .toString()
. It seems that xsToString(foo)
is different than foo.toString()
: the former fails on Symbols, while the latter succeeds. I notice the same issue with quasiliteral stringification on both Node.js and XS: you can't template-stringify a Symbol, but you can .toString
it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the try / catch in tryPrint
didn't catch the exception???
The xsnap
print()
doesn't know how to print a Symbol, so until that'sfixed, here's a workaround in our
tryPrint()
function. This is the backendof all console.log calls within the XS process.
refs Moddable-OpenSource/moddable#679