Skip to content

Commit b271e70

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
Allow Object.prototype to be serialized by structuredClone
https://bugs.webkit.org/show_bug.cgi?id=311143 rdar://173728983 Reviewed by Yusuke Suzuki. This patch aligns WebKit with Gecko / Firefox and Blink / Chromium. The structured clone serializer rejected Object.prototype because it checks for JSFinalObject exactly, but ObjectPrototype is a JSNonFinalObject subclass. Widen the check to also accept ObjectPrototype so it serializes as a plain object, naturally losing its immutable-prototype exotic-ness on deserialization. Per the StructuredSerializeInternal algorithm step 23: "Otherwise, if value is an exotic object and value is not the %Object.prototype% intrinsic object associated with any realm, then throw a DataCloneError DOMException." This explicitly carves out %Object.prototype% from the exotic object rejection, meaning it should be cloneable. Specification: https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal * LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.serviceworker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.sharedworker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.worker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/window-postmessage.window-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/webappapis/structured-clone/structured-clone.any-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/webappapis/structured-clone/structured-clone.any.worker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/workers/semantics/structured-clone/dedicated-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/workers/semantics/structured-clone/shared-expected.txt: * Source/WebCore/bindings/js/SerializedScriptValue.cpp: (WebCore::CloneSerializer::serialize): Canonical link: https://commits.webkit.org/310363@main
1 parent 65aa62f commit b271e70

File tree

10 files changed

+11
-10
lines changed

10 files changed

+11
-10
lines changed

LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ PASS Array ImageBitmap object, ImageBitmap 1x1 transparent black
127127
PASS Array ImageBitmap object, ImageBitmap 1x1 transparent non-black
128128
PASS Object ImageBitmap object, ImageBitmap 1x1 transparent black
129129
PASS Object ImageBitmap object, ImageBitmap 1x1 transparent non-black
130-
FAIL ObjectPrototype must lose its exotic-ness when cloned promise_test: Unhandled rejection with value: object "DataCloneError: The object can not be cloned."
130+
PASS ObjectPrototype must lose its exotic-ness when cloned
131131
PASS Serializing a non-serializable platform object fails
132132
PASS An object whose interface is deleted from the global must still deserialize
133133
PASS A subclass instance will deserialize as its closest serializable superclass

LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.serviceworker-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ PASS Object with non-enumerable property
112112
PASS Object with non-writable property
113113
PASS Object with non-configurable property
114114
PASS Object with a getter that throws
115-
FAIL ObjectPrototype must lose its exotic-ness when cloned promise_test: Unhandled rejection with value: object "DataCloneError: The object can not be cloned."
115+
PASS ObjectPrototype must lose its exotic-ness when cloned
116116
PASS Serializing a non-serializable platform object fails
117117
PASS An object whose interface is deleted from the global must still deserialize
118118
PASS A subclass instance will deserialize as its closest serializable superclass

LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.sharedworker-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ PASS Object with non-enumerable property
112112
PASS Object with non-writable property
113113
PASS Object with non-configurable property
114114
PASS Object with a getter that throws
115-
FAIL ObjectPrototype must lose its exotic-ness when cloned promise_test: Unhandled rejection with value: object "DataCloneError: The object can not be cloned."
115+
PASS ObjectPrototype must lose its exotic-ness when cloned
116116
PASS Serializing a non-serializable platform object fails
117117
PASS An object whose interface is deleted from the global must still deserialize
118118
PASS A subclass instance will deserialize as its closest serializable superclass

LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.worker-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ PASS Object with non-enumerable property
112112
PASS Object with non-writable property
113113
PASS Object with non-configurable property
114114
PASS Object with a getter that throws
115-
FAIL ObjectPrototype must lose its exotic-ness when cloned promise_test: Unhandled rejection with value: object "DataCloneError: The object can not be cloned."
115+
PASS ObjectPrototype must lose its exotic-ness when cloned
116116
PASS Serializing a non-serializable platform object fails
117117
PASS An object whose interface is deleted from the global must still deserialize
118118
PASS A subclass instance will deserialize as its closest serializable superclass

LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/window-postmessage.window-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ PASS Array ImageBitmap object, ImageBitmap 1x1 transparent black
127127
PASS Array ImageBitmap object, ImageBitmap 1x1 transparent non-black
128128
PASS Object ImageBitmap object, ImageBitmap 1x1 transparent black
129129
PASS Object ImageBitmap object, ImageBitmap 1x1 transparent non-black
130-
FAIL ObjectPrototype must lose its exotic-ness when cloned promise_test: Unhandled rejection with value: object "DataCloneError: The object can not be cloned."
130+
PASS ObjectPrototype must lose its exotic-ness when cloned
131131
PASS Serializing a non-serializable platform object fails
132132
PASS An object whose interface is deleted from the global must still deserialize
133133
PASS A subclass instance will deserialize as its closest serializable superclass

LayoutTests/imported/w3c/web-platform-tests/html/webappapis/structured-clone/structured-clone.any-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ PASS Array ImageBitmap object, ImageBitmap 1x1 transparent black
127127
PASS Array ImageBitmap object, ImageBitmap 1x1 transparent non-black
128128
PASS Object ImageBitmap object, ImageBitmap 1x1 transparent black
129129
PASS Object ImageBitmap object, ImageBitmap 1x1 transparent non-black
130-
FAIL ObjectPrototype must lose its exotic-ness when cloned promise_test: Unhandled rejection with value: object "DataCloneError: The object can not be cloned."
130+
PASS ObjectPrototype must lose its exotic-ness when cloned
131131
PASS Serializing a non-serializable platform object fails
132132
PASS An object whose interface is deleted from the global must still deserialize
133133
PASS A subclass instance will deserialize as its closest serializable superclass

LayoutTests/imported/w3c/web-platform-tests/html/webappapis/structured-clone/structured-clone.any.worker-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ PASS Object with non-enumerable property
112112
PASS Object with non-writable property
113113
PASS Object with non-configurable property
114114
PASS Object with a getter that throws
115-
FAIL ObjectPrototype must lose its exotic-ness when cloned promise_test: Unhandled rejection with value: object "DataCloneError: The object can not be cloned."
115+
PASS ObjectPrototype must lose its exotic-ness when cloned
116116
PASS Serializing a non-serializable platform object fails
117117
PASS An object whose interface is deleted from the global must still deserialize
118118
PASS A subclass instance will deserialize as its closest serializable superclass

LayoutTests/imported/w3c/web-platform-tests/workers/semantics/structured-clone/dedicated-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ PASS Array ImageBitmap object, ImageBitmap 1x1 transparent black
127127
PASS Array ImageBitmap object, ImageBitmap 1x1 transparent non-black
128128
PASS Object ImageBitmap object, ImageBitmap 1x1 transparent black
129129
PASS Object ImageBitmap object, ImageBitmap 1x1 transparent non-black
130-
FAIL ObjectPrototype must lose its exotic-ness when cloned promise_test: Unhandled rejection with value: object "DataCloneError: The object can not be cloned."
130+
PASS ObjectPrototype must lose its exotic-ness when cloned
131131
PASS Serializing a non-serializable platform object fails
132132
PASS An object whose interface is deleted from the global must still deserialize
133133
PASS A subclass instance will deserialize as its closest serializable superclass

LayoutTests/imported/w3c/web-platform-tests/workers/semantics/structured-clone/shared-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ PASS Array ImageBitmap object, ImageBitmap 1x1 transparent black
127127
PASS Array ImageBitmap object, ImageBitmap 1x1 transparent non-black
128128
PASS Object ImageBitmap object, ImageBitmap 1x1 transparent black
129129
PASS Object ImageBitmap object, ImageBitmap 1x1 transparent non-black
130-
FAIL ObjectPrototype must lose its exotic-ness when cloned promise_test: Unhandled rejection with value: object "DataCloneError: The object can not be cloned."
130+
PASS ObjectPrototype must lose its exotic-ness when cloned
131131
PASS Serializing a non-serializable platform object fails
132132
PASS An object whose interface is deleted from the global must still deserialize
133133
PASS A subclass instance will deserialize as its closest serializable superclass

Source/WebCore/bindings/js/SerializedScriptValue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
#include <JavaScriptCore/JSWebAssemblyModule.h>
100100
#include <JavaScriptCore/NumberObject.h>
101101
#include <JavaScriptCore/ObjectConstructor.h>
102+
#include <JavaScriptCore/ObjectPrototype.h>
102103
#include <JavaScriptCore/Options.h>
103104
#include <JavaScriptCore/PropertyNameArray.h>
104105
#include <JavaScriptCore/RegExp.h>
@@ -3006,7 +3007,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in)
30063007
// objects have been handled. If we reach this point and
30073008
// the input is not an Object object then we should throw
30083009
// a DataCloneError.
3009-
if (inObject->classInfo() != JSFinalObject::info())
3010+
if (inObject->classInfo() != JSFinalObject::info() && inObject->classInfo() != ObjectPrototype::info())
30103011
return SerializationReturnCode::DataCloneError;
30113012
inputObjectStack.append(inObject);
30123013
indexStack.append(0);

0 commit comments

Comments
 (0)