mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibWeb: Serialize Error#cause in StructuredSerialize
The spec doesn't include this behavior (at least, not yet), but all browsers do this, as can be seen in several subtests in https://wpt.live/html/infrastructure/safe-passing-of-structured-data/messagechannel.any.html
This commit is contained in:
committed by
Shannon Booth
parent
f558cd9f0d
commit
515828d971
Notes:
github-actions[bot]
2026-01-07 23:57:13 +00:00
Author: https://github.com/CountBleck Commit: https://github.com/LadybirdBrowser/ladybird/commit/515828d971f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7307 Reviewed-by: https://github.com/shannonbooth ✅
@@ -404,11 +404,21 @@ public:
|
||||
if (value_message_descriptor.has_value() && value_message_descriptor->is_data_descriptor())
|
||||
message = TRY(value_message_descriptor->value->to_utf16_string(m_vm));
|
||||
|
||||
// FIXME: Spec bug - https://github.com/whatwg/html/issues/11321
|
||||
// MISSING STEP: Let valueCauseDesc be ? value.[[GetOwnProperty]]("cause").
|
||||
auto value_cause_descriptor = TRY(object.internal_get_own_property(m_vm.names.cause));
|
||||
|
||||
// MISSING STEP: Let cause be undefined if IsDataDescriptor(valueCauseDesc) is false, and ? ToString(valueCauseDesc.[[Value]]) otherwise.
|
||||
Optional<Utf16String> cause;
|
||||
if (value_cause_descriptor.has_value() && value_cause_descriptor->is_data_descriptor())
|
||||
cause = TRY(value_cause_descriptor->value->to_utf16_string(m_vm));
|
||||
|
||||
// 5. Set serialized to { [[Type]]: "Error", [[Name]]: name, [[Message]]: message }.
|
||||
// FIXME: 6. User agents should attach a serialized representation of any interesting accompanying data which are not yet specified, notably the stack property, to serialized.
|
||||
serialized.encode(ValueTag::ErrorObject);
|
||||
serialized.encode(type);
|
||||
serialized.encode(message);
|
||||
serialized.encode(cause);
|
||||
}
|
||||
|
||||
// 18. Otherwise, if value is an Array exotic object, then:
|
||||
@@ -802,6 +812,7 @@ public:
|
||||
case ValueTag::ErrorObject: {
|
||||
auto type = m_serialized.decode<ErrorType>();
|
||||
auto message = m_serialized.decode<Optional<Utf16String>>();
|
||||
auto cause = m_serialized.decode<Optional<Utf16String>>();
|
||||
|
||||
GC::Ptr<JS::Error> error;
|
||||
|
||||
@@ -822,6 +833,9 @@ public:
|
||||
if (message.has_value())
|
||||
error->set_message(message.release_value());
|
||||
|
||||
if (cause.has_value())
|
||||
error->create_non_enumerable_data_property_or_throw(m_vm.names.cause, JS::PrimitiveString::create(m_vm, cause.release_value()));
|
||||
|
||||
value = error;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user