Skip to content

Commit

Permalink
Bug 1875781 - Add explicit non-default URLSearchParams deserializatio…
Browse files Browse the repository at this point in the history
…n; r=dom-storage-reviewers,asuth

This is a preparation for bug 1636761 which needs to make URLSearchParams not
structured-cloneable. The deserialization uses the existing method
URLSearchParams::ReadStructuredClone for now, but it will be replaced with own
deserialization in bug 1636761 because URLSearchParams::ReadStructuredClone
will be removed.

Differential Revision: https://phabricator.services.mozilla.com/D199344
  • Loading branch information
janvarga committed Jan 30, 2024
1 parent 210a406 commit 75234fd
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion dom/indexedDB/IndexedDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "mozilla/dom/FileBlobImpl.h"
#include "mozilla/dom/StructuredCloneTags.h"
#include "mozilla/dom/URLSearchParams.h"
#include "mozilla/dom/WorkerScope.h"
#include "MainThreadUtils.h"
#include "jsapi.h"
Expand Down Expand Up @@ -358,10 +359,37 @@ JSObject* CommonStructuredCloneReadCallback(
SCTAG_DOM_FILE_WITHOUT_LASTMODIFIEDDATE == 0xffff8002 &&
SCTAG_DOM_MUTABLEFILE == 0xffff8004 &&
SCTAG_DOM_FILE == 0xffff8005 &&
SCTAG_DOM_WASM_MODULE == 0xffff8006,
SCTAG_DOM_WASM_MODULE == 0xffff8006 &&
SCTAG_DOM_URLSEARCHPARAMS == 0xffff8014,
"You changed our structured clone tag values and just ate "
"everyone's IndexedDB data. I hope you are happy.");

if (aTag == SCTAG_DOM_URLSEARCHPARAMS) {
// Protect the result from a moving GC in ~RefPtr.
JS::Rooted<JSObject*> result(aCx);

{
// Scope for the RefPtr below.

nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx);
if (!global) {
return nullptr;
}

RefPtr<URLSearchParams> params =
URLSearchParams::ReadStructuredClone(aCx, global, aReader);
if (!params) {
return nullptr;
}

if (!WrapAsJSObject(aCx, params, &result)) {
return nullptr;
}
}

return result;
}

using StructuredCloneFile =
typename StructuredCloneReadInfo::StructuredCloneFile;

Expand Down

0 comments on commit 75234fd

Please sign in to comment.