[w3c/IndexedDB] Spec contradicts WPT tests for detached `ArrayBuffer` passed to `getAllKeys()` (Issue #465)

nolanlawson created an issue (w3c/IndexedDB#465)

The spec currently defines ["is a potentially valid key range"](https://w3c.github.io/IndexedDB/#is-a-potentially-valid-key-range) as:

> 1. If value is a [key range](https://w3c.github.io/IndexedDB/#key-range), return true.
> 2. Let key be the result of [converting a value to a key](https://w3c.github.io/IndexedDB/#convert-a-value-to-a-key) with value.

In ["convert a value to a key"](https://w3c.github.io/IndexedDB/#convert-a-value-to-a-key) it states:

> If input is a [buffer source type](https://webidl.spec.whatwg.org/#dfn-buffer-source-type)
>     If input is [detached](https://webidl.spec.whatwg.org/#buffersource-detached) then return "invalid value".

So a detached `ArrayBuffer` is _not_ a "potentially valid key range."

Now consider steps 8 and 9 of ["create a request to retrieve multiple items"](https://w3c.github.io/IndexedDB/#create-a-request-to-retrieve-multiple-items). These effectively say that, if the input `queryOrOptions` is _not_ a potentially valid key range, then it should be interpreted as an `IDBGetAllOptions` object.

In the WPT tests, though, there's currently a test that contradicts the spec: `idbindex_getAllKeys.any.js` which [tests `getAll` with invalid keys](https://github.com/web-platform-tests/wpt/blob/a634fb24eedcd92b18fb04391e415c27d813e76e/IndexedDB/idbindex_getAllKeys.any.js#L87-L89). The invalid keys include [a detached `TypeArray` and a detached `ArrayBuffer`](https://github.com/web-platform-tests/wpt/blob/a634fb24eedcd92b18fb04391e415c27d813e76e/IndexedDB/resources/support-get-all.js#L564-L571).

Basically, the test's expectation is that the following code throws a `DataError`:

```js
transaction
  .objectStore('foo')
  .index('bar')
  .getAll(detachedArrayBuffer)
```

However, the spec implies that, since `detachedArrayBuffer` is instead interpreted as an `IDBGetAllOptions` object, then we should just access its `query`/`count`/`direction` members, which would give `undefined`, i.e. equivalent to:

```js
transaction
  .objectStore('foo')
  .index('bar')
  .getAll({})
```

...which should _not_ throw an error.

I think the reason for the mismatch may be [these lines of code in the Chromium source](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/indexeddb/idb_get_all_options_helper.cc;l=44-49;drc=0d06bdf5aab0e4abf0d334920b40dfbb6f66d64c). Unlike the spec, this just checks if the input object is an `ArrayBuffer`/`ArrayBufferView`, _not_ if it is detached.

This may just be a bug in Chromium/WPT, but I thought I'd raise it here first in case this is actually a spec issue, and the intended behavior is for detachedness to work differently in "is a potentially valid key range". I admit, as a web developer, that it feels kind of like a footgun if an `ArrayBuffer` could behave like an `IDBGetAllOptions` purely based on whether it's detached or not. So maybe the current WPT/Chromium behavior is desirable.

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

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

Received on Thursday, 7 August 2025 23:31:55 UTC