Skip to content

Commit

Permalink
Bug 1636761 - Make URLSearchParams not structured-cloneable, r=asuth,…
Browse files Browse the repository at this point in the history
…webidl

Differential Revision: https://phabricator.services.mozilla.com/D182825
  • Loading branch information
edgul committed Jan 30, 2024
1 parent f5c07f1 commit 5266c6f
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@
["DOMMatrixReadOnly", ["Window", "Worker"], () => new DOMMatrixReadOnly()],
["ImageBitmap", ["Window", "Worker"], makeImageBitmap],
["RTCCertificate", ["Window"], generateCertificate],
[
"URLSearchParams",
["Window", "Worker", "WorkerDebugger"],
() => new URLSearchParams(),
],
["VideoFrame", ["Window", "DedicatedWorker"], makeVideoFrame],
];

Expand Down
54 changes: 0 additions & 54 deletions dom/url/URLSearchParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,60 +171,6 @@ void URLSearchParams::Sort(ErrorResult& aRv) {
NotifyObserver();
}

bool URLSearchParams::WriteStructuredClone(
JSStructuredCloneWriter* aWriter) const {
const uint32_t& nParams = mParams->Length();
if (!JS_WriteUint32Pair(aWriter, nParams, 0)) {
return false;
}
for (uint32_t i = 0; i < nParams; ++i) {
if (!StructuredCloneHolder::WriteString(aWriter,
mParams->GetKeyAtIndex(i)) ||
!StructuredCloneHolder::WriteString(aWriter,
mParams->GetValueAtIndex(i))) {
return false;
}
}
return true;
}

bool URLSearchParams::ReadStructuredClone(JSStructuredCloneReader* aReader) {
MOZ_ASSERT(aReader);

DeleteAll();

uint32_t nParams, zero;
nsAutoString key, value;
if (!JS_ReadUint32Pair(aReader, &nParams, &zero) || zero != 0) {
return false;
}

for (uint32_t i = 0; i < nParams; ++i) {
if (!StructuredCloneHolder::ReadString(aReader, key) ||
!StructuredCloneHolder::ReadString(aReader, value)) {
return false;
}
Append(key, value);
}
return true;
}

bool URLSearchParams::WriteStructuredClone(
JSContext* aCx, JSStructuredCloneWriter* aWriter) const {
return WriteStructuredClone(aWriter);
}

// static
already_AddRefed<URLSearchParams> URLSearchParams::ReadStructuredClone(
JSContext* aCx, nsIGlobalObject* aGlobal,
JSStructuredCloneReader* aReader) {
RefPtr<URLSearchParams> params = new URLSearchParams(aGlobal);
if (!params->ReadStructuredClone(aReader)) {
return nullptr;
}
return params.forget();
}

// contentTypeWithCharset can be set to the contentType or
// contentType+charset based on what the spec says.
// See: https://fetch.spec.whatwg.org/#concept-bodyinit-extract
Expand Down
11 changes: 0 additions & 11 deletions dom/url/URLSearchParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,11 @@ class URLSearchParams final : public nsISupports, public nsWrapperCache {

void Stringify(nsString& aRetval) const { Serialize(aRetval); }

static already_AddRefed<URLSearchParams> ReadStructuredClone(
JSContext* aCx, nsIGlobalObject* aGlobal,
JSStructuredCloneReader* aReader);

bool WriteStructuredClone(JSContext* aCx,
JSStructuredCloneWriter* aWriter) const;

nsresult GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
nsACString& aContentTypeWithCharset,
nsACString& aCharset) const;

private:
bool ReadStructuredClone(JSStructuredCloneReader* aReader);

bool WriteStructuredClone(JSStructuredCloneWriter* aWriter) const;

void AppendInternal(const nsAString& aName, const nsAString& aValue);

void DeleteAll();
Expand Down
3 changes: 1 addition & 2 deletions dom/webidl/URLSearchParams.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
* http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
*/

[Exposed=(Window,Worker,WorkerDebugger),
Serializable]
[Exposed=(Window,Worker,WorkerDebugger)]
interface URLSearchParams {
[Throws]
constructor(optional (sequence<sequence<USVString>> or
Expand Down
8 changes: 0 additions & 8 deletions testing/web-platform/meta/url/historical.any.js.ini

This file was deleted.

0 comments on commit 5266c6f

Please sign in to comment.