6.3. Index retrieval operations

To retrieve a referenced value from an index with targetRealm, index and range, run these steps:

  1. Let record be the first record in index’s list of records whose key is in range, if any.

  2. If record was not found, return undefined.

  3. Let serialized be record’s referenced value.

  4. Return ! StructuredDeserialize(serialized, targetRealm).

To retrieve multiple referenced values from an index with targetRealm, index, range and optional count, run these steps:

  1. If count is not given or is 0 (zero), let count be infinity.

  2. Let records be a list containing the first count records in index’s list of records whose key is in range.

  3. Let list be an empty list.

  4. For each record of records:

    1. Let serialized be record’s referenced value.

    2. Let entry be ! StructuredDeserialize(serialized, targetRealm).

    3. Append entry to list.

  5. Return list converted to a sequence.

The values of an record in an index are the keys of records in the referenced object store.

To retrieve a value from an index with index and range, run these steps:

  1. Let record be the first record in index’s list of records whose key is in range, if any.

  2. If record was not found, return undefined.

  3. Return the result of running convert a key to a value with record’s value.

To retrieve multiple values from an index with index, range and optional count, run these steps:

  1. If count is not given or is 0 (zero), let count be infinity.

  2. Let records be a list containing the first count records in index’s list of records whose key is in range.

  3. Let list be an empty list.

  4. For each record of records:

    1. Let entry be the result of running convert a key to a value with record’s value.

    2. Append entry to list.

  5. Return list converted to a sequence.