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.
The steps to check that a key could be injected into a value are as follows. The algorithm takes a value and a keyPath, and outputs 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 member of identifiers.
For each remaining identifier in 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.
The steps to inject a key into a value using a key path are as follows. The algorithm takes a value, a key and a keyPath.
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 member of identifiers and remove it from the list.
For each remaining identifier in 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 the steps to 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.