7.2. Inject a key into a value
The key paths used in this section are always strings and never sequences, since it is not possible to create a object store which has a key generator and also has a key path that is a sequence.
To check that a key could be injected into a value with value and a keyPath, run the following steps. The result of these steps is either true or false.
Let identifiers be the result of strictly splitting keyPath on U+002E FULL STOP characters (.).
Assert: identifiers is not empty.
Remove the last item of identifiers.
For each remaining identifier of identifiers, if any:
Return true if value is an Object or an Array, or false otherwise.
Assertions can be made in the above steps because this algorithm is only applied to values that are the output of StructuredDeserialize.
To inject a key into a value using a key path with value, a key and a keyPath, run these steps:
Let identifiers be the result of strictly splitting keyPath on U+002E FULL STOP characters (.).
Assert: identifiers is not empty.
Let last be the last item of identifiers and remove it from the list.
For each remaining identifier of identifiers:
Let hop be ! HasOwnProperty(value, identifier).
If hop is false, then:
Let o be a new Object created as if by the expression
({})
.Let status be CreateDataProperty(value, identifier, o).
Assert: status is true.
Let keyValue be the result of running convert a key to a value with key.
Let status be CreateDataProperty(value, last, keyValue).
Assert: status is true.
Assertions can be made in the above steps because this algorithm is only applied to values that are the output of StructuredDeserialize, and the steps to check that a key could be injected into a value have been run.