JSON.stringify custom toJSON method is called without a "key" parameter

RESOLVED FIXED

Status

()

Core
JavaScript Engine
RESOLVED FIXED
8 years ago
6 years ago

People

(Reporter: Fabian Jakobs, Assigned: Saint Wesonga)

Tracking

({testcase})

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 1 obsolete attachment)

(Reporter)

Description

8 years ago
If the top level object to stringify has a custom "toJSON" method, the key parameter is
set to "undefined" but according to the spec it is supposed to be the empty string "".

Example:

      var custom = {}
      custom.toJSON = function(key)
      {
				return "#" + key + "#";
      };
      alert( qx.bom.Json.stringify(custom));
      
 This code will alert "#undefined#" but it should be "##".
 
 
 Quote from the spec (15.12.3):
 
 9. Return the result of calling the abstract operation Str with the empty string and wrapper.

Comment 1

8 years ago
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.3a1pre) Gecko/20090818 Minefield/3.7a1pre

Confirming based on my understanding of the spec.
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Mac OS X → All
Summary: JSON.stringify custom toJSON method is called with wring "key" parameter → JSON.stringify custom toJSON method is called with wrong "key" parameter

Comment 2

8 years ago
Created attachment 395224 [details]
testcase

Updated

8 years ago
Keywords: testcase
(Assignee)

Comment 3

8 years ago
Created attachment 398892 [details] [diff] [review]
Patch v1
Assignee: general → wesongathedeveloper
Status: NEW → ASSIGNED
Attachment #398892 - Flags: review?(brendan)
(Assignee)

Comment 4

8 years ago
Created attachment 398897 [details] [diff] [review]
Patch v1
Attachment #398892 - Attachment is obsolete: true
Attachment #398897 - Flags: review?(brendan)
Attachment #398892 - Flags: review?(brendan)
Comment on attachment 398897 [details] [diff] [review]
Patch v1

Use cx->malloc (new in tracemonkey repo's jscntxt.h). Other than that I defer to sayrer. Thanks for the patch!

/be
Attachment #398897 - Flags: review?(brendan) → review?(sayrer)
(Assignee)

Updated

8 years ago
Attachment #398897 - Flags: review?(sayrer)
Yuck, how'd this get dropped on the floor?  :-\

The patch here is really old, dating back to before JSON was even part of the JS engine, so it doesn't really apply to current code.  But I happen to have fixed this in the patch in bug 636079, without knowing this bug had already been filed for the problem, so we're in not-horrible shape -- setting that dependency.
Depends on: 636079
Summary: JSON.stringify custom toJSON method is called with wrong "key" parameter → JSON.stringify custom toJSON method is called without a "key" parameter
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.