Re: [w3c/IndexedDB] Is it really true that StructuredDeserialize can't throw in this spec? (Issue #391)

annevk left a comment (w3c/IndexedDB#391)

This does happen in practice. `RTCCertificate` is `[Exposed=Window, Serializable]`, and IndexedDB is exposed in workers. So a certificate stored from a window and read back in a dedicated worker reaches a realm where its interface is not exposed. StructuredDeserialize then throws a "`DataCloneError`" `DOMException`. The same applies to `[SecureContext]` serializable interfaces, such as `CryptoKey`, read in a non-secure context of the same origin.

I tested this by storing `{ name: "record", certificate }` from a window and calling `get()` from a dedicated worker:

* Chrome: `get()` succeeds with `null` as its result, losing the entire record.
* Firefox: the `success` event fires, and reading `result` throws an "`InvalidStateError`" `DOMException`.
* Safari: the certificate is delivered to the worker. That's a bug in WebKit that we are fixing.

I propose we standardize Firefox's approach, but with "`DataCloneError`" as the exception: the request succeeds, because the record exists, but the value cannot be read in that realm. In terms of the specification:

* The retrieval operations return the serialized value instead of deserializing it.
* The `IDBRequest` `result` getter, the `IDBCursorWithValue` `value` getter, and the `IDBRecord` `value` getter deserialize on first access using `?` and cache the result. An exception from StructuredDeserialize is rethrown.
* The note claiming StructuredDeserialize cannot throw is removed.

That also avoids deserializing values that are never read.

(The other option would be to fail the request with a "`DataCloneError`" `DOMException` and an `error` event. That requires deserializing every retrieved value before dispatching `success`, including values script never looks at.)

I'll add tentative tests for this to web-platform-tests.

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

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

Received on Thursday, 8 October 2026 09:37:47 UTC