Skip to content
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

Merged
merged 1 commit into from
Aug 7, 2021

Conversation

warner
Copy link
Member

@warner warner commented Aug 6, 2021

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

@warner warner added the xsnap the XS execution tool label Aug 6, 2021
@warner warner added this to the Testnet: Metering Phase milestone Aug 6, 2021
@warner warner requested a review from dckc August 6, 2021 23:47
@warner warner self-assigned this Aug 6, 2021
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
Copy link
Member

@dckc dckc left a 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));
Copy link
Member

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);
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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???

@warner warner merged commit 314ee93 into master Aug 7, 2021
@warner warner deleted the xsnap-print-symbols branch August 7, 2021 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
xsnap the XS execution tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants