Skip to content

Commit f843e48

Browse files
mystorpchevrel@mozilla.com
authored andcommitted
Bug 2017797 - Part 1: Allow calls to structuredClone to change globals, a=pascalc
This better aligns with the behaviour as defined in the spec, and allows us to start passing some WPTs we were previously failing. Original Revision: https://phabricator.services.mozilla.com/D284163 Differential Revision: https://phabricator.services.mozilla.com/D285609
1 parent 9623064 commit f843e48

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
@@ -11928,6 +11928,9 @@ void nsContentUtils::StructuredClone(JSContext* aCx, nsIGlobalObject* aGlobal,
1192811928
clonePolicy.allowSharedMemoryObjects();
1192911929
}
1193011930

11931+
// 2.7.10 Structured cloning API
11932+
// Step 1: Let serialized be
11933+
// ? StructuredSerializeWithTransfer(value, options["transfer"])
1193111934
StructuredCloneHolder holder(StructuredCloneHolder::CloningSupported,
1193211935
StructuredCloneHolder::TransferringSupported,
1193311936
JS::StructuredCloneScope::SameProcess);
@@ -11936,11 +11939,16 @@ void nsContentUtils::StructuredClone(JSContext* aCx, nsIGlobalObject* aGlobal,
1193611939
return;
1193711940
}
1193811941

11942+
// Step 2: Let deserializeRecord be
11943+
// ? StructuredDeserializeWithTransfer(serialized, this's relevant realm).
11944+
JSAutoRealm ar(aCx, aGlobal->GetGlobalJSObject());
1193911945
holder.Read(aCx, aRetval, clonePolicy, aError);
1194011946
if (NS_WARN_IF(aError.Failed())) {
1194111947
return;
1194211948
}
1194311949

11950+
// Step 3: Return deserializeRecord.[[Deserialized]].
11951+
// (discarding deserializeRecord.[[TransferredValues]])
1194411952
nsTArray<RefPtr<MessagePort>> ports = holder.TakeTransferredPorts();
1194511953
(void)ports;
1194611954
}

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)