[w3c/IndexedDB] IDBRecord getters and key conversion to value caching (Issue #494)

ArnaudBienner created an issue (w3c/IndexedDB#494)

When retrieving objects using getAll, the following is specified in the spec as of today (for both [object stores](https://w3c.github.io/IndexedDB/#retrieve-multiple-items-from-an-object-store) and [indexes](https://w3c.github.io/IndexedDB/#retrieve-multiple-items-from-an-index)):
"Let key be the result of [converting a key to a value](https://w3c.github.io/IndexedDB/#convert-a-key-to-a-value) with record’s key."
But for getAllRecords, it is defined like this:
"Let key be the record’s key."

And the conversion from a key to a value [is defined in key and primaryKey's getters](https://w3c.github.io/IndexedDB/#dom-idbrecord-key):
"The key getter steps are to return the result of [converting a key to a value](https://w3c.github.io/IndexedDB/#convert-a-key-to-a-value) with [this](https://webidl.spec.whatwg.org/#this)’s [key](https://w3c.github.io/IndexedDB/#record-snapshot-key)."

It's probably defined  that way to allow the value to be converted lazily, only if the getter is called.

But it sounds like a new object shall be created everytime the getter is called, and this sounds rather inefficient, in the case key is not a primitive type (large arrays, strings or binaries).

Chrome doesn't implement it this way (always returns the same object), and, in Firefox, [we are also considering this approach for our getAllRecords implementation](https://phabricator.services.mozilla.com/D295592#10262750).

Safari (preview) returns a new object on every call.

@smaug---- suggested we could use the [SameObject] [attribute](https://webidl.spec.whatwg.org/#SameObject) in the webidl to clarify this behavior in the spec
i.e. having:
```
interface IDBRecord {
  [SameObject] readonly attribute any key;
  [SameObject] readonly attribute any primaryKey;
  [SameObject] readonly attribute any value;
};
```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/IndexedDB/issues/494
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/IndexedDB/issues/494@github.com>

Received on Saturday, 9 May 2026 17:13:54 UTC