a test for stringify "whitelist" which WebKit fails

Hallvord R. M. Steen hallvord at opera.com
Tue Sep 1 07:39:12 PDT 2009

On Fri, 28 Aug 2009 21:49:24 +0200, Oliver Hunt <oliver at apple.com> wrote:

> Okay, the final list of issues:

Great feedback on the tests - thanks a lot!

> correctness/010.js incorrectly expects the non-ascii characters to be
> escaped -- The abstract operation Quote only escapes ", \, and the
> characters less than space.  double-quote, backslash, backspace,
> formfeed, newline, carriage return, and tab get escaped as \", \\, \b,
> \f, \n, \r, and \t respectively.  The remaining control characters get
> the generic unicode escape.
> correctness/037.js incorrectly expects JSON.stringify(undefined) to
> produe an empty string -- it is spec'd as producing undefined.

Both fixed.

> correctness/045.js uses Number as the object to serialise, but Number
> is a function so does not get stringified - JSON.stringify(function()
> { return arguments; }(), ["length"]) should do.

Thanks - though funny that Safari is the only browser here that actually  
passes the test. So Safari has a bug here? :)

> integration/004.js makes Math.toJSON returns a stringified object
> instead of the new object itself,

If that's wrong, I've misunderstood how toJSON() is supposed to work  
(thought it was meant to return a *string* representation of the object).  
I see from the algorithm that the output of the toJSON() call goes through  
the quote operation if it is a string and the JA/JO serializations if it's  
array or object, but the spec does not really cover this issue in prose  
anywhere?! It's a bit late for such feedback but the functionality of a  
custom toJSON() method seems really underdefined.

> integrity/004.js and 005.js have incorrect regexps as they fail to
> account for 8.b.iii "if gap is not the empty string"


 From earlier E-mail:

> Do we intend that
> str = new String("foo");
> str.toString=function(){ alert("Wiffle"); }
> JSON.stringify(..., [str])
> will execute the custom toString?

Good question, now captured in this test:
asserting that it should indeed use the custom toString(). Only Firefox  
gets it right in this murky corner at the moment.

Hallvord R. M. Steen, Core Tester, Opera Software
http://www.opera.com http://my.opera.com/hallvors/

More information about the es-discuss mailing list