Node 8.3 and 8.4 do not throw TypeError: parseInt(Symbol(''));
Xotic750 opened this issue · 2 comments
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.
After a little more searching
Unicode v8.0.0 for whitespace
ECMAScript 6 required Unicode v5.1.0Zs
symbols to be recognized as whitespace in addition to anyZs
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
.