Implementing an identical JSON.stringify

Claude Pache claude.pache at gmail.com
Sun Aug 5 02:50:22 UTC 2018



> Le 5 août 2018 à 01:43, Michael Theriot <michael.lee.theriot at gmail.com> a écrit :
> 
> Try `Number.prototype.valueOf.call(obj)`: it will throw a TypeError if and only if `obj` has no [[NumberData]] internal slot. Ditto for String, Boolean and Symbol.
> 
> I already mention this and demonstrate why it is not sufficient in my example.
> 
> Reiterated plainly:
> ```js
> JSON.stringify(Reflect.construct(Number, [], Number)); // "0"
> JSON.stringify(Reflect.construct(Number, [], String)); // TypeError
> JSON.stringify(Reflect.construct(Number, [], Object)); // null
> ```

Per spec, the three expressions should produce `"0"`, as the three objects have a [[NumberData]] internal slot (step 4 of [1]). I guess there is some discrepancy between implementation and spec for those exotic edge cases?

[1]: https://tc39.github.io/ecma262/#sec-serializejsonproperty <https://tc39.github.io/ecma262/#sec-serializejsonproperty>

—Claude


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180805/e7fbae69/attachment.html>


More information about the es-discuss mailing list