Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for structured cloning of ErrorInstance objects #14296

Merged

Conversation

cdumez
Copy link
Contributor

@cdumez cdumez commented May 24, 2023

7bd6b87

Add support for structured cloning of ErrorInstance objects
https://bugs.webkit.org/show_bug.cgi?id=257268

Reviewed by Yusuke Suzuki and Ryosuke Niwa.

Add support for structured cloning of ErrorInstance objects, per:
- https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal

This aligns our behavior with Blink and Gecko.

* LayoutTests/fast/dom/Window/window-postmessage-clone-expected.txt:
* LayoutTests/fast/dom/Window/window-postmessage-clone.html:
* LayoutTests/fast/events/message-port-multi-expected.txt:
* LayoutTests/fast/events/resources/message-port-multi.js:
* LayoutTests/fast/storage/serialized-script-value.html:
* LayoutTests/imported/w3c/web-platform-tests/IndexedDB/structured-clone.any.worker_81-100-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/IndexedDB/structured-clone.any_81-100-expected.txt:
* 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/structured-cloning-error-stack-optional.sub.window-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/structuredclone_0-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/workers/semantics/structured-clone/dedicated-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/structured-clone/shared-expected.txt:
* LayoutTests/storage/indexeddb/resources/structured-clone.js:
* LayoutTests/storage/indexeddb/structured-clone-expected.txt:
* LayoutTests/userscripts/window-onerror-for-isolated-world-1-expected.txt:
* LayoutTests/userscripts/window-onerror-for-isolated-world-2-expected.txt:
* Source/JavaScriptCore/runtime/ErrorInstance.cpp:
(JSC::ErrorInstance::finishCreation):
* Source/JavaScriptCore/runtime/ErrorInstance.h:
(JSC::ErrorInstance::createWithoutStackTrace):
* Source/WebCore/bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneSerializer::dumpIfTerminal):
(WebCore::CloneDeserializer::readTerminal):

Canonical link: https://commits.webkit.org/264552@main

cbf266e

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2   πŸ§ͺ api-mac βœ… πŸ›  gtk
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ›  πŸ§ͺ jsc βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ jsc-arm64 βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ›  jsc-armv7
βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-wk2-stress βœ… πŸ§ͺ jsc-armv7-tests
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch βœ… πŸ›  jsc-mips
βœ… πŸ›  watch-sim βœ… πŸ§ͺ jsc-mips-tests

@cdumez cdumez self-assigned this May 24, 2023
@cdumez cdumez added the DOM For bugs specific to XML/HTML DOM elements (including parsing). label May 24, 2023
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 24, 2023
@cdumez cdumez removed the merging-blocked Applied to prevent a change from being merged label May 24, 2023
@cdumez cdumez force-pushed the 257268_ErrorInstance_structured_clone branch from 8727198 to 9c7f8f5 Compare May 24, 2023 20:03
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 24, 2023
@cdumez cdumez removed the merging-blocked Applied to prevent a change from being merged label May 24, 2023
@cdumez cdumez force-pushed the 257268_ErrorInstance_structured_clone branch from 9c7f8f5 to b626b87 Compare May 24, 2023 23:20
@cdumez cdumez force-pushed the 257268_ErrorInstance_structured_clone branch from b626b87 to 73823ed Compare May 25, 2023 00:54
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 25, 2023
@cdumez cdumez removed the merging-blocked Applied to prevent a change from being merged label May 25, 2023
@cdumez cdumez force-pushed the 257268_ErrorInstance_structured_clone branch from 73823ed to a22af47 Compare May 25, 2023 03:03
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 25, 2023
@cdumez cdumez removed the merging-blocked Applied to prevent a change from being merged label May 25, 2023
@cdumez cdumez force-pushed the 257268_ErrorInstance_structured_clone branch from a22af47 to 44107e9 Compare May 25, 2023 15:17
@cdumez cdumez marked this pull request as ready for review May 25, 2023 19:01
@cdumez cdumez requested review from rniwa and a team as code owners May 25, 2023 19:01
PASS TypeError objects can be cloned
PASS URIError objects can be cloned
PASS URIError objects from other realms are treated as URIError
FAIL Cloning a modified Error assert_equals: Checking prototype expected object "TypeError" but got object "URIError"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing the issues that Yusuke mentioned fixes this subtest. Will reupload a newer version shortly.

@cdumez cdumez force-pushed the 257268_ErrorInstance_structured_clone branch 2 times, most recently from 65e5923 to 6722405 Compare May 25, 2023 21:37
@cdumez cdumez requested a review from Constellation May 25, 2023 21:40
Comment on lines 1439 to 1451
auto errorTypeString = errorInstance->get(m_lexicalGlobalObject, vm.propertyNames->name).toWTFString(m_lexicalGlobalObject);
RETURN_IF_EXCEPTION(scope, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's error check twice. get can throw error, and can return JSEmpty. And toWTFString onto JSEmpty will crash. So,

auto errorTypeValue = errorInstance->get(m_lexicalGlobalObject, vm.propertyNames->name);
RETURN_IF_EXCEPTION(scope, false);
auto errorTypeString = errorTypeValue.toWTFString(m_lexicalGlobalObject);
RETURN_IF_EXCEPTION(scope, false);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.


String message;
PropertyDescriptor messageDescriptor;
if (errorInstance->getOwnPropertyDescriptor(m_lexicalGlobalObject, vm.propertyNames->message, messageDescriptor) && messageDescriptor.isDataDescriptor())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do error check after getOwnPropertyDescriptor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks correct to me?

If getOwnPropertyDescriptor() threw an exception, it would return false and I already have an exception check after the if case.


unsigned line = 0;
PropertyDescriptor lineDescriptor;
if (errorInstance->getOwnPropertyDescriptor(m_lexicalGlobalObject, vm.propertyNames->line, lineDescriptor) && lineDescriptor.isDataDescriptor())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.


unsigned column = 0;
PropertyDescriptor columnDescriptor;
if (errorInstance->getOwnPropertyDescriptor(m_lexicalGlobalObject, vm.propertyNames->column, columnDescriptor) && columnDescriptor.isDataDescriptor())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.


String sourceURL;
PropertyDescriptor sourceURLDescriptor;
if (errorInstance->getOwnPropertyDescriptor(m_lexicalGlobalObject, vm.propertyNames->sourceURL, sourceURLDescriptor) && sourceURLDescriptor.isDataDescriptor())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

unsigned line = 0;
PropertyDescriptor lineDescriptor;
if (errorInstance->getOwnPropertyDescriptor(m_lexicalGlobalObject, vm.propertyNames->line, lineDescriptor) && lineDescriptor.isDataDescriptor())
line = lineDescriptor.value().toNumber(m_lexicalGlobalObject);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. toNumber requires error check. (Object can be returned, and it can have valueOf method).

unsigned column = 0;
PropertyDescriptor columnDescriptor;
if (errorInstance->getOwnPropertyDescriptor(m_lexicalGlobalObject, vm.propertyNames->column, columnDescriptor) && columnDescriptor.isDataDescriptor())
column = columnDescriptor.value().toNumber(m_lexicalGlobalObject);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

String stack;
PropertyDescriptor stackDescriptor;
if (errorInstance->getOwnPropertyDescriptor(m_lexicalGlobalObject, vm.propertyNames->stack, stackDescriptor) && stackDescriptor.isDataDescriptor())
stack = stackDescriptor.value().toWTFString(m_lexicalGlobalObject);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Comment on lines 264 to 276
if (equalLettersIgnoringASCIICase(name, "evalerror"_s))
return ErrorType::EvalError;
if (equalLettersIgnoringASCIICase(name, "rangeerror"_s))
return ErrorType::RangeError;
if (equalLettersIgnoringASCIICase(name, "referenceerror"_s))
return ErrorType::ReferenceError;
if (equalLettersIgnoringASCIICase(name, "syntaxerror"_s))
return ErrorType::SyntaxError;
if (equalLettersIgnoringASCIICase(name, "typeerror"_s))
return ErrorType::TypeError;
if (equalLettersIgnoringASCIICase(name, "urierror"_s))
return ErrorType::URIError;
return ErrorType::Error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should define these enums separately in this SerializedScriptValue. ErrorType enum is not a defined interface in JSC. So this can be changed freely, and it can break serialization since it is relying on this errorType number serialized in persistent storage.

Comment on lines 281 to 297
switch (value) {
case enumToUnderlyingType(ErrorType::Error):
return ErrorType::Error;
case enumToUnderlyingType(ErrorType::EvalError):
return ErrorType::EvalError;
case enumToUnderlyingType(ErrorType::RangeError):
return ErrorType::RangeError;
case enumToUnderlyingType(ErrorType::ReferenceError):
return ErrorType::ReferenceError;
case enumToUnderlyingType(ErrorType::SyntaxError):
return ErrorType::SyntaxError;
case enumToUnderlyingType(ErrorType::TypeError):
return ErrorType::TypeError;
case enumToUnderlyingType(ErrorType::URIError):
return ErrorType::URIError;
default:
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we should get JSC's ErrorType from defined enum here.

@cdumez cdumez force-pushed the 257268_ErrorInstance_structured_clone branch from 6722405 to cbf266e Compare May 25, 2023 22:19
@cdumez cdumez requested a review from Constellation May 25, 2023 22:20
Copy link
Member

@Constellation Constellation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me

@cdumez cdumez added the merge-queue Applied to send a pull request to merge-queue label May 26, 2023
https://bugs.webkit.org/show_bug.cgi?id=257268

Reviewed by Yusuke Suzuki and Ryosuke Niwa.

Add support for structured cloning of ErrorInstance objects, per:
- https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal

This aligns our behavior with Blink and Gecko.

* LayoutTests/fast/dom/Window/window-postmessage-clone-expected.txt:
* LayoutTests/fast/dom/Window/window-postmessage-clone.html:
* LayoutTests/fast/events/message-port-multi-expected.txt:
* LayoutTests/fast/events/resources/message-port-multi.js:
* LayoutTests/fast/storage/serialized-script-value.html:
* LayoutTests/imported/w3c/web-platform-tests/IndexedDB/structured-clone.any.worker_81-100-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/IndexedDB/structured-clone.any_81-100-expected.txt:
* 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/structured-cloning-error-stack-optional.sub.window-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/structuredclone_0-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/workers/semantics/structured-clone/dedicated-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/workers/semantics/structured-clone/shared-expected.txt:
* LayoutTests/storage/indexeddb/resources/structured-clone.js:
* LayoutTests/storage/indexeddb/structured-clone-expected.txt:
* LayoutTests/userscripts/window-onerror-for-isolated-world-1-expected.txt:
* LayoutTests/userscripts/window-onerror-for-isolated-world-2-expected.txt:
* Source/JavaScriptCore/runtime/ErrorInstance.cpp:
(JSC::ErrorInstance::finishCreation):
* Source/JavaScriptCore/runtime/ErrorInstance.h:
(JSC::ErrorInstance::createWithoutStackTrace):
* Source/WebCore/bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneSerializer::dumpIfTerminal):
(WebCore::CloneDeserializer::readTerminal):

Canonical link: https://commits.webkit.org/264552@main
@webkit-commit-queue webkit-commit-queue force-pushed the 257268_ErrorInstance_structured_clone branch from cbf266e to 7bd6b87 Compare May 26, 2023 02:42
@webkit-commit-queue
Copy link
Collaborator

Committed 264552@main (7bd6b87): https://commits.webkit.org/264552@main

Reviewed commits have been landed. Closing PR #14296 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 7bd6b87 into WebKit:main May 26, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DOM For bugs specific to XML/HTML DOM elements (including parsing).
Projects
None yet
6 participants