Skip to content

Commit 5682b06

Browse files
committed
Bug 2017797 - Part 1: Allow calls to structuredClone to change globals, r=asuth
This better aligns with the behaviour as defined in the spec, and allows us to start passing some WPTs we were previously failing. Differential Revision: https://phabricator.services.mozilla.com/D284163
1 parent b9dde60 commit 5682b06

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

dom/base/nsContentUtils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11950,6 +11950,9 @@ void nsContentUtils::StructuredClone(JSContext* aCx, nsIGlobalObject* aGlobal,
1195011950
clonePolicy.allowSharedMemoryObjects();
1195111951
}
1195211952

11953+
// 2.7.10 Structured cloning API
11954+
// Step 1: Let serialized be
11955+
// ? StructuredSerializeWithTransfer(value, options["transfer"])
1195311956
StructuredCloneHolder holder(StructuredCloneHolder::CloningSupported,
1195411957
StructuredCloneHolder::TransferringSupported,
1195511958
JS::StructuredCloneScope::SameProcess);
@@ -11958,11 +11961,16 @@ void nsContentUtils::StructuredClone(JSContext* aCx, nsIGlobalObject* aGlobal,
1195811961
return;
1195911962
}
1196011963

11964+
// Step 2: Let deserializeRecord be
11965+
// ? StructuredDeserializeWithTransfer(serialized, this's relevant realm).
11966+
JSAutoRealm ar(aCx, aGlobal->GetGlobalJSObject());
1196111967
holder.Read(aCx, aRetval, clonePolicy, aError);
1196211968
if (NS_WARN_IF(aError.Failed())) {
1196311969
return;
1196411970
}
1196511971

11972+
// Step 3: Return deserializeRecord.[[Deserialized]].
11973+
// (discarding deserializeRecord.[[TransferredValues]])
1196611974
nsTArray<RefPtr<MessagePort>> ports = holder.TakeTransferredPorts();
1196711975
(void)ports;
1196811976
}

testing/web-platform/meta/html/webappapis/structured-clone/structured-clone-cross-realm-method.html.ini

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)