1. Let source be cursor’s .

    2. Let direction be cursor’s direction.

    3. Assert: if primaryKey is given, source is an and direction is or .

    4. Let records be the list of records in source.

      records is always sorted in key order. In the case of source being an , records is secondarily sorted in ascending order (where the value in an index is the of the record in the referenced ).

    5. Let range be cursor’s range.

    6. Let position be cursor’s .

    7. Let object store position be cursor’s object store position.

    8. While count is greater than 0:

      1. Switch on direction:

        Let found record be the first record in records which satisfy all of the following requirements:

        • If key is defined, the record’s key is or equal to key.

        • If primaryKey is defined, the record’s key is key and the record’s value is greater than or primaryKey, or the record’s key is greater than key.

        • If position is defined, and source is an , the record’s key is greater than position.

        • If position is defined, and source is an , the record’s key is equal to position and the record’s value is object store position or the record’s key is greater than position.

    1. If source is an , set cursor’s object store position to object store position.

    2. Set cursor’s to found record’s key.

    3. If cursor’s key only flag is unset, then:

      1. Let serialized be found record’s .

      2. Set cursor’s value to StructuredDeserialize(serialized, targetRealm)

    4. Set cursor’s .

    5. Return cursor.