7.3. Convert a key to a value

To convert a key to a value with key, run the following steps. The steps return an ECMAScript value.

  1. Let type be key’s type.

  2. Let value be key’s value.

  3. Switch on type:

    number

    Return an ECMAScript Number value equal to value

    string

    Return an ECMAScript String value equal to value

    date

    1. Let date be the result of executing the ECMAScript Date constructor with the single argument value.

    2. Assert: date is not an abrupt completion.

    3. Return date.

  1. *binary*
  2. 1. Let len be values [length](https://infra.spec.whatwg.org/#byte-sequence-length).
  3. 2. Let buffer be the result of executing the ECMAScript ArrayBuffer constructor with len.
  4. 3. [Assert](https://infra.spec.whatwg.org/#assert): buffer is not an [abrupt completion](https://tc39.github.io/ecma262/#sec-completion-record-specification-type).
  5. 4. Set the entries in buffers \[\[ArrayBufferData\]\] internal slot to the entries in value.
  6. 5. Return buffer.
  7. *array*
  8. 1. Let array be the result of executing the ECMAScript Array constructor with no arguments.
  9. 2. [Assert](https://infra.spec.whatwg.org/#assert): array is not an [abrupt completion](https://tc39.github.io/ecma262/#sec-completion-record-specification-type).
  10. 3. Let len be values [size](https://infra.spec.whatwg.org/#list-size).
  11. 4. Let index be 0.
  12. 5. While index is less than len:
  13. 1. Let entry be the result of running [convert a key to a value](#convert-a-key-to-a-value) with value\[index\].
  14. 2. Let status be [CreateDataProperty](https://tc39.github.io/ecma262/#sec-createdataproperty)(array, index, entry).
  15. 3. [Assert](https://infra.spec.whatwg.org/#assert): status is true.
  16. 4. Increase index by 1.
  17. 6. Return array.