diff --git a/infra.bs b/infra.bs
index 91f1360..ee17a52 100644
--- a/infra.bs
+++ b/infra.bs
@@ -14,7 +14,14 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262;
text: %JSONStringify%; url: #sec-json.stringify
text: List; url: sec-list-and-record-specification-type
text: The String Type; url: sec-ecmascript-language-types-string-type
- type: abstract-op; text: Call; url: sec-call
+ text: realm; url: realm
+ type: abstract-op;
+ text: Call; url: sec-call
+ text: Get; url: sec-get-o-p
+ text: IsArray; url: sec-isarray
+ text: ToLength; url: sec-tolength
+ text: ToString; url: sec-tostring
+ text: Type; url: sec-ecmascript-data-types-and-values
@@ -1074,18 +1081,16 @@ as 200/`OK
`.
The conventions used in the algorithms in this section are those of the JavaScript +specification. [[!ECMA-262]] +
To parse JSON from bytes given bytes, run these steps:
Let jsonText be the result of running UTF-8 decode on bytes. [[!ENCODING]] -
Return ? Call(%JSONParse%, undefined, « jsonText »). - [[!ECMA-262]] - -
The conventions used in this step are those of the JavaScript specification. - +
Return ? Call(%JSONParse%, undefined, « jsonText »).
To serialize JSON to bytes a given JavaScript value value, run these @@ -1093,16 +1098,82 @@ steps:
Let jsonString be the result of +
Let jsonString be ? Call(%JSONStringify%, undefined, « value »). - [[!ECMA-262]] -
The conventions used in this step are those of the JavaScript specification. - Also, since no additional arguments are passed to %JSONStringify%, the resulting string - will have no whitespace inserted. + +
Since no additional arguments are passed to %JSONStringify%, the resulting + string will have no whitespace inserted.
Return the result of running UTF-8 encode on jsonString. [[!ENCODING]]
The above two operations operate on JavaScript values directly; in particular, this means that +the involved objects or arrays are tied to a particular JavaScript realm. In +standards, it is often more convenient to parse JSON into realm-independent maps, +lists, strings, booleans, numbers, and nulls. + +
To parse JSON into maps and lists, given a string +jsonText: + +
Let |jsValue| be ? [$Call$](%JSONParse%, undefined, « |jsonText| »). + +
Return the result of [=converting a JSON-derived JavaScript value to an Infra value=], given + |jsValue|. +
To convert a JSON-derived JavaScript value to an Infra value, +given a JavaScript value jsValue: + +
If [$Type$](|jsValue|) is Null, String, or Number, then return |jsValue|. + +
If [$IsArray$](|jsValue|) is true, then: + +
Let |result| be an empty [=list=]. + +
Let |length| be ! [$ToLength$](! [$Get$](|jsValue|, "`length`")). + +
[=list/For each=] |index| of [=the range=] 0 to |length| − 1, inclusive: + +
Let |indexName| be ! [$ToString$](|index|). + +
Let |jsValueAtIndex| be ! [$Get$](|jsValue|, |indexName|). + +
Let |infraValueAtIndex| be the result of [=converting a JSON-derived JavaScript value to an Infra value=], + given |jsValueAtIndex|. + +
[=list/Append=] |infraValueAtIndex| to |result|. +
Return |result|. +
Let |result| be an empty [=ordered map=]. + +
[=list/For each=] |key| of ! |jsValue|.\[[OwnPropertyKeys]](): + +
Let |jsValueAtKey| be ! [$Get$](|jsValue|, |key|). + +
Let |infraValueAtKey| be the result of [=converting a JSON-derived JavaScript value to an Infra value=], + given |jsValueAtKey|. + +
[=map/Set=] |result|[|key|] to |infraValueAtKey|. +
Return |result|. +