Does JSON.stringify(new String("foo")) return '"foo"' unconditionally, or does it depend on String.prototype.toString?

RESOLVED FIXED

Status

()

Core
JavaScript Engine
RESOLVED FIXED
8 years ago
7 years ago

People

(Reporter: Waldo, Assigned: Waldo)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: fixed-in-tracemonkey, URL)

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

8 years ago
Spec sez it depends on String.prototype.toString.  Chrome and WebKit both perform per spec; Firefox and Opera return the string object's primitive value.  My IE9 developer preview seems horked for some reason, so I can't tell what IE does here (does it even implement JSON?  really not sure).

Either behavior is somewhat reasonable, I kind of prefer our behavior but it's not to spec, so either this has to change or there has to be an erratum.
(Assignee)

Comment 1

8 years ago
Started an es5-discuss thread on this:

https://mail.mozilla.org/pipermail/es5-discuss/2010-April/003529.html
(Assignee)

Comment 2

8 years ago
Created attachment 500724 [details] [diff] [review]
Patch and test
Assignee: general → jwalden+bmo
Status: NEW → ASSIGNED
Attachment #500724 - Flags: review?(jorendorff)
Comment on attachment 500724 [details] [diff] [review]
Patch and test

This corner of ES5 is gross. Oh well.

r=me.
Attachment #500724 - Flags: review?(jorendorff) → review+
(Assignee)

Comment 4

8 years ago
http://hg.mozilla.org/tracemonkey/rev/567f16dd81f3
Whiteboard: fixed-in-tracemonkey
Target Milestone: --- → mozilla2.0b10
(Assignee)

Comment 5

8 years ago
Backed out, I forgot (as always) about the xpcshell tests (dom/src/json/test/unit/test_encode.js, dom/src/json/test/unit/test_wrapper.js) that need to be changed whenever JSON is changed.  A followup's usually easy.  But those tests compare against json2.js, which is not compatible with ES5 (no, really), so that's a strike against a fast fix.  Worse yet, json2.js appears to pollute [BNS].prototype with toJSON methods not in ES5, and those additions mean the ES5 algorithm short-circuits before the changes here could take effect, so basically it's impossible to fix fast.

http://hg.mozilla.org/tracemonkey/rev/039f81de26e5

Punting after 4.0, at which time I *will* kill those non-js/src/tests JSON tests -- they've been a problem for JSON-hacking SpiderMonkey developers for too long.
Whiteboard: fixed-in-tracemonkey
Target Milestone: mozilla2.0b10 → ---
(Assignee)

Updated

8 years ago
Attachment #500724 - Flags: review?(jwalden+bmo)

Updated

8 years ago
Blocks: 633256
(Assignee)

Updated

8 years ago
Duplicate of this bug: 635009
(Assignee)

Comment 7

8 years ago
Created attachment 514495 [details] [diff] [review]
Patch, updated and with the dom/src/json/test/unit tests fixed

I did the very minimum amount of work needed to make the DOM tests pass.  I'll file another bug to move/remove/etc. them.  Now waiting for the tree to be ready to take this.
Attachment #500724 - Attachment is obsolete: true
Attachment #514495 - Flags: review+
Attachment #500724 - Flags: review?(jwalden+bmo)
(Assignee)

Comment 8

8 years ago
http://hg.mozilla.org/tracemonkey/rev/c7e3c056478b
Whiteboard: fixed-in-tracemonkey
http://hg.mozilla.org/mozilla-central/rev/c7e3c056478b
Status: ASSIGNED → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → FIXED

Updated

7 years ago
Duplicate of this bug: 633256
You need to log in before you can comment on or make changes to this bug.