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

Node 8.3 and 8.4 do not throw TypeError: parseInt(Symbol('')); #450

Closed
Xotic750 opened this issue Sep 29, 2017 · 2 comments
Closed

Node 8.3 and 8.4 do not throw TypeError: parseInt(Symbol('')); #450

Xotic750 opened this issue Sep 29, 2017 · 2 comments

Comments

@Xotic750
Copy link
Contributor

Xotic750 commented Sep 29, 2017

If ES5-shim is loaded on Node 8.3 and 8.4, parseInt fails parseInt(ws + '08') === 8 and parseInt(ws + '0x16') === 22 by returning NaN, Node seems not to be trimming the ws correctly (or there is a whiteSpaceChracter change in the draft spec?), so the shim is loaded. The ES5-shim ToString does not check for Symbol (I believe, need to check the source: it is using String) and converts it to a string if a primitive, although Symbol object seems to throw, perhaps this is a change in the draft spec (I didn't see any) or just a Node bug?

require('es5-shim');
parseInt(Symbol('')); // Should throw TypeError but gives NaN
require('es5-shim');
parseInt(Object(Symbol(''))); // Throws TypeError

Draft:
String:
https://tc39.github.io/ecma262/#sec-string-constructor-string-value
parseInt:
https://tc39.github.io/ecma262/#sec-parseint-string-radix
ToString:
https://tc39.github.io/ecma262/#sec-tostring

ES2105:
String;
http://www.ecma-international.org/ecma-262/6.0/#sec-string-constructor-string-value
parseInt:
http://www.ecma-international.org/ecma-262/6.0/#sec-parseint-string-radix
ToString:
http://www.ecma-international.org/ecma-262/6.0/#sec-tostring

Maybe I've missed something, not sure, out of time just now.

@Xotic750
Copy link
Contributor Author

Xotic750 commented Sep 30, 2017

After a little more searching

Unicode v8.0.0 for whitespace
ECMAScript 6 required Unicode v5.1.0 Zs symbols to be recognized as whitespace in addition to any Zs symbols in whatever Unicode version the engine implemented.

Per tc39/ecma262#300 this is no longer the case in ES2016. 🎉

The only observable change is that U+180E is no longer considered whitespace.

So this could be the reason for parseInt being shimmed by ES5-shim, and possible several other methods, and leads also to Symbol primitive being coerced to a string rather than throwing TypeError.

https://tc39.github.io/ecma262/#prod-WhiteSpace

@Xotic750
Copy link
Contributor Author

Xotic750 commented Oct 1, 2017

#433

@ljharb ljharb closed this as completed in c3296bd Dec 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant