Implementing an identical JSON.stringify
Darien Valentine
valentinium at gmail.com
Sun Aug 5 03:04:38 UTC 2018
> 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?
There’s no discrepancy — they shouldn’t all produce "0", because the
algorithm calls ToNumber on the value if it has the [[NumberData]] slot.
This in turn calls ToPrimitive because the value is an object. This
ultimately ends up calling the `@@toPrimitive` or `toValue` method _of_ the
object. In the case of the object with String.prototype for its prototype,
this will be `String.prototype.toValue`, which throws if its receiver
doesn’t have [[StringData]]. In the case of the object with
Object.prototype for its prototype, this will be `Object.prototype.toValue`.
On Sat, Aug 4, 2018 at 10:31 PM Darien Valentine <valentinium at gmail.com>
wrote:
> Oh, thanks Claude, I missed that. I guess it is all replicable then.
>
> On Sat, Aug 4, 2018 at 10:28 PM Claude Pache <claude.pache at gmail.com>
> wrote:
>
>>
>>
>> > Le 5 août 2018 à 04:14, Darien Valentine <valentinium at gmail.com> a
>> écrit :
>> >
>> >
>> > However it is ultimately not possible to replicate because there is no
>> possible brand test for [[BooleanData]].
>>
>> Per spec, checking whether `Boolean.prototype.valueOf.call(obj)` throws
>> will test whether an object has [[BooleanData]] internal slot.
>>
>> —Claude
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180804/c165d2ad/attachment.html>
More information about the es-discuss
mailing list