Comments on April ES5 final draft standard tc39-2009-025

Mark S. Miller erights at
Sun Apr 26 15:45:36 PDT 2009

2009/4/25 Mark S. Miller <erights at>:
> JSON to be covered separately. String.prototype.toJSON (  key ) Boolean.prototype.toJSON ( key ) Number.prototype.toJSON ( key )

All three of these use the same boilerplate to a) typically unwrap a
wrapped primitive, and b) in all cases ensure a primitive is returned.
This seems largely redundant with ToPrimitive. How about for all of
these just saying

    1. Return the result of calling ToPrimitive on the this value.

Alternatively, all these are already almost redundant with logic
within the JSON.stringify algorithm. But slightly repairing that logic
(see below), we can simply remove these three methods; simplifying the
spec. The JSON Syntactic Grammar

> defines a valid JSON text in terms of tokens from defined by the

delete "from"

15.12.2 parse ( text [ , reviver ] )

> The JSON format is a restricted form of ECMAScript literal.

Not quite. \u2028 and \u2029 can appear in a JSONString unescaped. But
ES5 considers these to be newline characters, and so they can only
appear in ES5 literal strings if escaped. We need a note to that

In abstract Walk operation, step 2, what's the purpose of the
IsCallable test here? I think this test should be deleted.

> 2.a.iii.2 Let newElement be the result of calling the [[Put]] internal method ...

This binding of newElement is never used. Which is a good thing
because [[Put]] doesn't return anything anyway. Also, it is not
necessarily the case that this [[Put]] will succeed. Change to

    Call the [[ThrowingPut]] internal method ... and true.

> 2.b.i. ... Object.key ...

Should be Object.keys. Likewise in step 6.a of JO.

15.12.3 stringify ( value [ , replacer [ , space ] ] )

> The value parameter is a JavaScript value is usually an object or array, ...

Insert "that" between "value" and "is".

Step 7 of Str

The unwrapping here of Strings and Numbers is redundant with that in
their toJSON methods as mentioned above. However, Boolean is left out
here. I think it is better to have the unwrapping of primitive
wrappers here, with Boolean repaired, and to remove the redundant
toJSON methods on Number.prototype, String.prototype, and

JO and JA refer to the abstract operation "str". Should be "Str".

JA step 10.b.iii. uses "{" and "}". Should be "[" and "]".

Several of the issues I've raised in this and my earlier message were
first noticed by other Googlers and raised internally.


More information about the es-discuss mailing list