-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add support for structured cloning of ErrorInstance objects #14296
Conversation
EWS run on previous version of this PR (hash 8727198) |
8727198
to
9c7f8f5
Compare
9c7f8f5
to
b626b87
Compare
EWS run on previous version of this PR (hash b626b87)
|
b626b87
to
73823ed
Compare
EWS run on previous version of this PR (hash 73823ed)
|
73823ed
to
a22af47
Compare
EWS run on previous version of this PR (hash a22af47)
|
a22af47
to
44107e9
Compare
EWS run on previous version of this PR (hash 44107e9)
|
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" |
There was a problem hiding this comment.
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.
65e5923
to
6722405
Compare
EWS run on previous version of this PR (hash 65e5923)
|
EWS run on previous version of this PR (hash 6722405)
|
auto errorTypeString = errorInstance->get(m_lexicalGlobalObject, vm.propertyNames->name).toWTFString(m_lexicalGlobalObject); | ||
RETURN_IF_EXCEPTION(scope, false); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
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; |
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
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.
6722405
to
cbf266e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me
EWS run on current version of this PR (hash cbf266e)
|
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
to
7bd6b87
Compare
Committed 264552@main (7bd6b87): https://commits.webkit.org/264552@main Reviewed commits have been landed. Closing PR #14296 and removing active labels. |
7bd6b87
cbf266e
π§ͺ api-mac