mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +00:00
LibJS: Allow assigning an error message after Error object creation
This will be used by structured deserialization in LibWeb.
This commit is contained in:
parent
fd6d868ae2
commit
3fb4e769d8
Notes:
github-actions[bot]
2025-07-18 14:11:17 +00:00
Author: https://github.com/trflynn89
Commit: 3fb4e769d8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5492
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/shannonbooth
2 changed files with 33 additions and 27 deletions
|
@ -41,10 +41,8 @@ GC::Ref<Error> Error::create(Realm& realm)
|
|||
|
||||
GC::Ref<Error> Error::create(Realm& realm, String message)
|
||||
{
|
||||
auto& vm = realm.vm();
|
||||
auto error = Error::create(realm);
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
error->define_direct_property(vm.names.message, PrimitiveString::create(vm, move(message)), attr);
|
||||
error->set_message(move(message));
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -77,6 +75,14 @@ ThrowCompletionOr<void> Error::install_error_cause(Value options)
|
|||
return {};
|
||||
}
|
||||
|
||||
void Error::set_message(String message)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_direct_property(vm.names.message, PrimitiveString::create(vm, move(message)), attr);
|
||||
}
|
||||
|
||||
void Error::populate_stack()
|
||||
{
|
||||
auto stack_trace = vm().stack_trace();
|
||||
|
@ -165,10 +171,8 @@ String Error::stack_string(CompactTraceback compact) const
|
|||
\
|
||||
GC::Ref<ClassName> ClassName::create(Realm& realm, String message) \
|
||||
{ \
|
||||
auto& vm = realm.vm(); \
|
||||
auto error = ClassName::create(realm); \
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable; \
|
||||
error->define_direct_property(vm.names.message, PrimitiveString::create(vm, move(message)), attr); \
|
||||
error->set_message(move(message)); \
|
||||
return error; \
|
||||
} \
|
||||
\
|
||||
|
|
|
@ -41,6 +41,8 @@ public:
|
|||
|
||||
ThrowCompletionOr<void> install_error_cause(Value options);
|
||||
|
||||
void set_message(String);
|
||||
|
||||
Vector<TracebackFrame, 32> const& traceback() const { return m_traceback; }
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue