diff --git a/docs/index.html b/docs/index.html index 0da94d5..bce32c7 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2557,7 +2557,7 @@

1.1 JSON.isRawJSON ( O )

1.2 JSON.parse ( text [ , reviver ] )

The parse function parses a JSON text (a JSON-formatted String) and produces an ECMAScript language value. The JSON format represents literals, arrays, and objects with a syntax similar to the syntax for ECMAScript literals, Array Initializers, and Object Initializers. After parsing, JSON objects are realized as ECMAScript objects. JSON arrays are realized as ECMAScript Array instances. JSON strings, numbers, booleans, and null are realized as ECMAScript Strings, Numbers, Booleans, and null.

-

The optional reviver parameter is a function that takes twothree parameters, key and value and a context object. It can filter and transform the results. It is called with each of the key/value pairs produced by the parse and details of their corresponding Parse Node, and its return value is used instead of the original value. If it returns what it received, the structure is not modified. If it returns undefined then the property is deleted from the result.

+

The optional reviver parameter is a function that takes twothree parameters, key and value and a context object. It can filter and transform the results. It is called with each of the key/value pairs produced by the parse and (for primitive values) details of their corresponding Parse Node, and its return value is used instead of the original value. If it returns what it received, the structure is not modified. If it returns undefined then the property is deleted from the result.

  1. Let jsonString be ? ToString(text).
  2. Parse StringToCodePoints(jsonString) as a JSON text as specified in ECMA-404. Throw a SyntaxError exception if it is not a valid JSON text as defined in that specification.
  3. Let scriptString be the string-concatenation of "(", jsonString, and ");".
  4. Let script be ParseText(StringToCodePoints(scriptString), Script).
  5. NOTE: The early error rules defined in 13.2.5.1 have special handling for the above invocation of ParseText.
  6. Assert: script is a Parse Node.
  7. Let completion be the result of evaluating script.
  8. NOTE: The PropertyDefinitionEvaluation semantics defined in 13.2.5.5 have special handling for the above evaluation.
  9. Let unfiltered be completion.[[Value]].
  10. Assert: unfiltered is either a String, Number, Boolean, Null, or an Object that is defined by either an ArrayLiteral or an ObjectLiteral.
  11. If IsCallable(reviver) is true, then
    1. Let root be OrdinaryObjectCreate(%Object.prototype%).
    2. Let rootName be the empty String.
    3. Perform ! CreateDataPropertyOrThrow(root, rootName, unfiltered).
    4. Return ? InternalizeJSONProperty(root, rootName, reviver, script).
  12. Else,
    1. Return unfiltered.

The "length" property of the parse function is 2𝔽.

Note
@@ -2572,7 +2572,7 @@

1.2.1 InternalizeJSONProperty ( holderThis algorithm intentionally does not throw an exception if either [[Delete]] or CreateDataProperty return false.

It performs the following steps when called:

-
  1. Let typedValNode be ShallowestContained of valNode with argument « NullLiteral, BooleanLiteral, NumericLiteral, StringLiteral, ArrayLiteral, ObjectLiteral ».
  2. Assert: typedValNode is not empty.
  3. Let context be OrdinaryObjectCreate(%Object.prototype%).
  4. Let sourceText be the source text matched by typedValNode.
  5. Perform ! CreateDataPropertyOrThrow(context, "source", CodePointsToString(sourceText)).
  6. Let val be ? Get(holder, name).
  7. If Type(val) is Object, then
    1. Let isArray be ? IsArray(val).
    2. If isArray is true, then
      1. Assert: typedValNode is an ArrayLiteral Parse Node.
      2. Let elements be ArrayElementList of typedValNode.
      3. Let elementsLen be the number of elements in elements.
      4. Let I be 0.
      5. Let len be ? LengthOfArrayLike(val).
      6. Assert: len = elementsLen.
      7. Repeat, while I < len,
        1. Let prop be ! ToString(𝔽(I)).
        2. Let newElement be ? InternalizeJSONProperty(val, prop, reviver, elements[I]).
        3. If newElement is undefined, then
          1. Perform ? val.[[Delete]](prop).
        4. Else,
          1. Perform ? CreateDataProperty(val, prop, newElement).
        5. Set I to I + 1.
    3. Else,
      1. Assert: typedValNode is an ObjectLiteral Parse Node.
      2. Let properties be PropertyDefinitionList of typedValNode.
      3. Let keys be ? EnumerableOwnPropertyNames(val, key).
      4. For each String P of keys, do
        1. Let propertyDefinition be empty.
        2. For each Parse Node candidate of properties, do
          1. Let propName be PropName of candidate.
          2. If SameValue(propName, P) is true, set propertyDefinition to candidate.
        3. Assert: propertyDefinition is not empty.
        4. NOTE: In the case of JSON text specifying multiple name/value pairs with the same name for a single object (such as {"a":"lost","a":"kept"}), the value for the corresponding property of the resulting ECMAScript object is specified by the last pair with that name.
        5. Assert: propertyDefinition is +
          1. Let typedValNode be ShallowestContained of valNode with argument « NullLiteral, BooleanLiteral, NumericLiteral, StringLiteral, ArrayLiteral, ObjectLiteral ».
          2. Assert: typedValNode is not empty.
          3. Let context be OrdinaryObjectCreate(%Object.prototype%).
          4. If typedValNode is not an ArrayLiteral Parse Node and not an ObjectLiteral Parse Node, then
            1. Let sourceText be the source text matched by typedValNode.
            2. Perform ! CreateDataPropertyOrThrow(context, "source", CodePointsToString(sourceText)).
          5. Let val be ? Get(holder, name).
          6. If Type(val) is Object, then
            1. Let isArray be ? IsArray(val).
            2. If isArray is true, then
              1. Assert: typedValNode is an ArrayLiteral Parse Node.
              2. Let elements be ArrayElementList of typedValNode.
              3. Let elementsLen be the number of elements in elements.
              4. Let I be 0.
              5. Let len be ? LengthOfArrayLike(val).
              6. Assert: len = elementsLen.
              7. Repeat, while I < len,
                1. Let prop be ! ToString(𝔽(I)).
                2. Let newElement be ? InternalizeJSONProperty(val, prop, reviver, elements[I]).
                3. If newElement is undefined, then
                  1. Perform ? val.[[Delete]](prop).
                4. Else,
                  1. Perform ? CreateDataProperty(val, prop, newElement).
                5. Set I to I + 1.
            3. Else,
              1. Assert: typedValNode is an ObjectLiteral Parse Node.
              2. Let properties be PropertyDefinitionList of typedValNode.
              3. Let keys be ? EnumerableOwnPropertyNames(val, key).
              4. For each String P of keys, do
                1. Let propertyDefinition be empty.
                2. For each Parse Node candidate of properties, do
                  1. Let propName be PropName of candidate.
                  2. If SameValue(propName, P) is true, set propertyDefinition to candidate.
                3. Assert: propertyDefinition is not empty.
                4. NOTE: In the case of JSON text specifying multiple name/value pairs with the same name for a single object (such as {"a":"lost","a":"kept"}), the value for the corresponding property of the resulting ECMAScript object is specified by the last pair with that name.
                5. Assert: propertyDefinition is PropertyDefinition : PropertyName : diff --git a/spec.html b/spec.html index c5022b2..c344695 100644 --- a/spec.html +++ b/spec.html @@ -45,7 +45,7 @@

                  JSON.isRawJSON ( _O_ )

                  JSON.parse ( _text_ [ , _reviver_ ] )

                  The `parse` function parses a JSON text (a JSON-formatted String) and produces an ECMAScript language value. The JSON format represents literals, arrays, and objects with a syntax similar to the syntax for ECMAScript literals, Array Initializers, and Object Initializers. After parsing, JSON objects are realized as ECMAScript objects. JSON arrays are realized as ECMAScript Array instances. JSON strings, numbers, booleans, and null are realized as ECMAScript Strings, Numbers, Booleans, and *null*.

                  -

                  The optional _reviver_ parameter is a function that takes twothree parameters, _key_ and _value_ and a _context_ object. It can filter and transform the results. It is called with each of the _key_/_value_ pairs produced by the parse and details of their corresponding Parse Node, and its return value is used instead of the original value. If it returns what it received, the structure is not modified. If it returns *undefined* then the property is deleted from the result.

                  +

                  The optional _reviver_ parameter is a function that takes twothree parameters, _key_ and _value_ and a _context_ object. It can filter and transform the results. It is called with each of the _key_/_value_ pairs produced by the parse and (for primitive values) details of their corresponding Parse Node, and its return value is used instead of the original value. If it returns what it received, the structure is not modified. If it returns *undefined* then the property is deleted from the result.

                  1. Let _jsonString_ be ? ToString(_text_). 1. [id="step-json-parse-validate"] Parse StringToCodePoints(_jsonString_) as a JSON text as specified in ECMA-404. Throw a *SyntaxError* exception if it is not a valid JSON text as defined in that specification. @@ -90,8 +90,9 @@

                  1. Let _typedValNode_ be ShallowestContained of _valNode_ with argument « |NullLiteral|, |BooleanLiteral|, |NumericLiteral|, |StringLiteral|, |ArrayLiteral|, |ObjectLiteral| ». 1. Assert: _typedValNode_ is not ~empty~. 1. Let _context_ be OrdinaryObjectCreate(%Object.prototype%). - 1. Let _sourceText_ be the source text matched by _typedValNode_. - 1. Perform ! CreateDataPropertyOrThrow(_context_, *"source"*, CodePointsToString(_sourceText_)). + 1. If _typedValNode_ is not an |ArrayLiteral| Parse Node and not an |ObjectLiteral| Parse Node, then + 1. Let _sourceText_ be the source text matched by _typedValNode_. + 1. Perform ! CreateDataPropertyOrThrow(_context_, *"source"*, CodePointsToString(_sourceText_)). 1. Let _val_ be ? Get(_holder_, _name_). 1. If Type(_val_) is Object, then 1. Let _isArray_ be ? IsArray(_val_).