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

Differential Revision: https://phabricator.services.mozilla.com/D208506
This commit is contained in:
Thomas Wisniewski 2024-04-27 03:43:37 +00:00
parent 398b556e90
commit d7ebbe6a68
3 changed files with 17 additions and 9 deletions

View File

@ -144,6 +144,12 @@ MovingNotNull<RefPtr<IDBRequest>> GenerateRequest(
std::move(transaction));
}
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.
}
bool StructuredCloneWriteCallback(JSContext* aCx,
JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj,
@ -278,10 +284,14 @@ bool CopyingStructuredCloneWriteCallback(JSContext* aCx,
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<StructuredCloneReadInfoChild>,
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 */,

View File

@ -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

View File

@ -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", { autoIncrement: false });
let sab = new SharedArrayBuffer(256);