mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
LibJS: Implement the Error Cause proposal
Currently stage 3. https://github.com/tc39/proposal-error-cause
This commit is contained in:
parent
8d77a3297a
commit
862ba64037
11 changed files with 130 additions and 42 deletions
|
@ -31,13 +31,23 @@ Value ErrorConstructor::call()
|
|||
Value ErrorConstructor::construct(Function&)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
String message;
|
||||
// FIXME: Use OrdinaryCreateFromConstructor(newTarget, "%Error.prototype%")
|
||||
auto* error = Error::create(global_object());
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
|
||||
if (!vm.argument(0).is_undefined()) {
|
||||
message = vm.argument(0).to_string(global_object());
|
||||
auto message = vm.argument(0).to_string(global_object());
|
||||
if (vm.exception())
|
||||
return {};
|
||||
error->define_property(vm.names.message, js_string(vm, message), attr);
|
||||
}
|
||||
return Error::create(global_object(), message);
|
||||
|
||||
error->install_error_cause(vm.argument(1));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||
|
@ -64,13 +74,24 @@ Value ErrorConstructor::construct(Function&)
|
|||
Value ConstructorName::construct(Function&) \
|
||||
{ \
|
||||
auto& vm = this->vm(); \
|
||||
String message = ""; \
|
||||
/* FIXME: Use OrdinaryCreateFromConstructor( \
|
||||
* FIXME: newTarget, "%NativeError.prototype%"). */ \
|
||||
auto* error = ClassName::create(global_object()); \
|
||||
\
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable; \
|
||||
\
|
||||
if (!vm.argument(0).is_undefined()) { \
|
||||
message = vm.argument(0).to_string(global_object()); \
|
||||
auto message = vm.argument(0).to_string(global_object()); \
|
||||
if (vm.exception()) \
|
||||
return {}; \
|
||||
error->define_property(vm.names.message, js_string(vm, message), attr); \
|
||||
} \
|
||||
return ClassName::create(global_object(), message); \
|
||||
\
|
||||
error->install_error_cause(vm.argument(1)); \
|
||||
if (vm.exception()) \
|
||||
return {}; \
|
||||
\
|
||||
return error; \
|
||||
}
|
||||
|
||||
JS_ENUMERATE_NATIVE_ERRORS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue