New issue
Advanced search Search tips

Issue 613863 link

Starred by 2 users

Issue metadata

Status: Duplicate
Merged: issue 595738
Owner: ----
Closed: May 2016
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 2
Type: Bug



Sign in to add a comment

JSON.stringify() doesn't respect toJSON() if it is bound

Reported by denis.wa...@futurice.com, May 22 2016

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36

Steps to reproduce the problem:
Run the following code:

    const o = {a: 1};
    o.toJSON = function() { return {b: 2}; }.bind(this);
    console.log(JSON.stringify(o));

What is the expected behavior?
toJSON() should be called and the output should be '{"b":2}'.

What went wrong?
toJSON() is ignored and '{"a":1}' is returned, as if the toJSON property wouldn't exist.

Did this work before? N/A 

Chrome version: 50.0.2661.102  Channel: stable
OS Version: OS X 10.11.4
Flash Version: Shockwave Flash 21.0 r0

The same code works as intended on Firefox 45.0.1.
 
Confirmed that this works fine on Chrome 52. 

Comment 3 by japhet@chromium.org, May 23 2016

Mergedinto: 595738
Status: Duplicate (was: Unconfirmed)
Marking duplicate, per comments 1 and 2.

Sign in to add a comment