From c9f56fc8589d5629ee9b550e57ad4706f280ff96 Mon Sep 17 00:00:00 2001 From: Thomas Wisniewski Date: Tue, 30 Apr 2024 16:15:12 +0000 Subject: [PATCH] Bug 1878148 - fix the WPT IndexedDB/serialize-sharedarraybuffer-throws.https.html to trigger a data clone error per spec, and send the correct DataCloneError it expects; r=jari,dom-storage-reviewers,janv Differential Revision: https://phabricator.services.mozilla.com/D208506 --- dom/indexedDB/IDBObjectStore.cpp | 22 ++++++++++++++----- ...ze-sharedarraybuffer-throws.https.html.ini | 2 -- .../serialization-via-idb.any.js.ini | 10 --------- ...ialize-sharedarraybuffer-throws.https.html | 2 +- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index 728f10b1055b..401c9defb2ce 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -276,12 +276,22 @@ bool CopyingStructuredCloneWriteCallback(JSContext* aCx, aObj); } +void StructuredCloneErrorCallback(JSContext* aCx, uint32_t aErrorId, + void* aClosure, const char* aErrorMessage) { + // This callback is only used to prevent the default cloning TypeErrors + // from being thrown, as we will throw DataCloneErrors instead per spec. +} + nsresult GetAddInfoCallback(JSContext* aCx, void* aClosure) { static const JSStructuredCloneCallbacks kStructuredCloneCallbacks = { - nullptr /* read */, StructuredCloneWriteCallback /* write */, - nullptr /* reportError */, nullptr /* readTransfer */, - nullptr /* writeTransfer */, nullptr /* freeTransfer */, - nullptr /* canTransfer */, nullptr /* sabCloned */ + nullptr /* read */, + StructuredCloneWriteCallback /* write */, + StructuredCloneErrorCallback /* reportError */, + nullptr /* readTransfer */, + nullptr /* writeTransfer */, + nullptr /* freeTransfer */, + nullptr /* canTransfer */, + nullptr /* sabCloned */ }; MOZ_ASSERT(aCx); @@ -555,7 +565,7 @@ bool IDBObjectStore::DeserializeValue( static const JSStructuredCloneCallbacks callbacks = { StructuredCloneReadCallback, nullptr, - nullptr, + StructuredCloneErrorCallback, nullptr, nullptr, nullptr, @@ -1751,7 +1761,7 @@ bool IDBObjectStore::ValueWrapper::Clone(JSContext* aCx) { static const JSStructuredCloneCallbacks callbacks = { CopyingStructuredCloneReadCallback /* read */, CopyingStructuredCloneWriteCallback /* write */, - nullptr /* reportError */, + StructuredCloneErrorCallback /* reportError */, nullptr /* readTransfer */, nullptr /* writeTransfer */, nullptr /* freeTransfer */, diff --git a/testing/web-platform/meta/IndexedDB/serialize-sharedarraybuffer-throws.https.html.ini b/testing/web-platform/meta/IndexedDB/serialize-sharedarraybuffer-throws.https.html.ini index bcfac5ac85dc..9a058c09d966 100644 --- a/testing/web-platform/meta/IndexedDB/serialize-sharedarraybuffer-throws.https.html.ini +++ b/testing/web-platform/meta/IndexedDB/serialize-sharedarraybuffer-throws.https.html.ini @@ -2,5 +2,3 @@ expected: if (os == "android") and not debug: [OK, TIMEOUT] if (os == "android") and debug: [OK, TIMEOUT] - [IndexedDB: Attempting to serialize a SharedArrayBuffer should throw] - expected: FAIL diff --git a/testing/web-platform/meta/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/serialization-via-idb.any.js.ini b/testing/web-platform/meta/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/serialization-via-idb.any.js.ini index 59a85ebb49b5..ad9b90f16656 100644 --- a/testing/web-platform/meta/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/serialization-via-idb.any.js.ini +++ b/testing/web-platform/meta/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/serialization-via-idb.any.js.ini @@ -4,17 +4,7 @@ [SharedArrayBuffer cloning via IndexedDB: basic case] expected: if (processor == "x86") and (os == "win") and not debug: [FAIL, TIMEOUT] - FAIL [SharedArrayBuffer cloning via the IndexedDB: is interleaved correctly] expected: if (processor == "x86") and (os == "win") and not debug: [FAIL, TIMEOUT] - FAIL - - -[serialization-via-idb.any.html] - [SharedArrayBuffer cloning via IndexedDB: basic case] - expected: FAIL - - [SharedArrayBuffer cloning via the IndexedDB: is interleaved correctly] - expected: FAIL diff --git a/testing/web-platform/tests/IndexedDB/serialize-sharedarraybuffer-throws.https.html b/testing/web-platform/tests/IndexedDB/serialize-sharedarraybuffer-throws.https.html index 613ddfe99d81..bff63fad8d13 100644 --- a/testing/web-platform/tests/IndexedDB/serialize-sharedarraybuffer-throws.https.html +++ b/testing/web-platform/tests/IndexedDB/serialize-sharedarraybuffer-throws.https.html @@ -13,7 +13,7 @@ let open_rq = createdb(t); open_rq.onupgradeneeded = function(e) { let db = e.target.result; - let objStore = db.createObjectStore("test", { keyPath:"pKey" }); + let objStore = db.createObjectStore("test"); let sab = new SharedArrayBuffer(256);