Skip to content

Commit 18a34f9

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 dd29b06 commit 18a34f9

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
@@ -11894,6 +11894,9 @@ void nsContentUtils::StructuredClone(JSContext* aCx, nsIGlobalObject* aGlobal,
1189411894
clonePolicy.allowSharedMemoryObjects();
1189511895
}
1189611896

11897+
// 2.7.10 Structured cloning API
11898+
// Step 1: Let serialized be
11899+
// ? StructuredSerializeWithTransfer(value, options["transfer"])
1189711900
StructuredCloneHolder holder(StructuredCloneHolder::CloningSupported,
1189811901
StructuredCloneHolder::TransferringSupported,
1189911902
JS::StructuredCloneScope::SameProcess);
@@ -11902,11 +11905,16 @@ void nsContentUtils::StructuredClone(JSContext* aCx, nsIGlobalObject* aGlobal,
1190211905
return;
1190311906
}
1190411907

11908+
// Step 2: Let deserializeRecord be
11909+
// ? StructuredDeserializeWithTransfer(serialized, this's relevant realm).
11910+
JSAutoRealm ar(aCx, aGlobal->GetGlobalJSObject());
1190511911
holder.Read(aCx, aRetval, clonePolicy, aError);
1190611912
if (NS_WARN_IF(aError.Failed())) {
1190711913
return;
1190811914
}
1190911915

11916+
// Step 3: Return deserializeRecord.[[Deserialized]].
11917+
// (discarding deserializeRecord.[[TransferredValues]])
1191011918
nsTArray<RefPtr<MessagePort>> ports = holder.TakeTransferredPorts();
1191111919
(void)ports;
1191211920
}

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)