Comments on April ES5 final draft standard tc39-2009-025
Mark S. Miller
erights at google.com
Sun Apr 26 15:45:36 PDT 2009
2009/4/25 Mark S. Miller <erights at google.com>:
> JSON to be covered separately.
15.5.4.21 String.prototype.toJSON ( key )
15.6.4.4 Boolean.prototype.toJSON ( key )
15.7.4.8 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.
15.12.1.2 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
effect.
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
Boolean.prototype.
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.
--
Cheers,
--MarkM
More information about the es-discuss
mailing list