summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-06-11 20:40:08 +0100
committerLinus Groh <mail@linusgroh.de>2021-06-11 21:34:05 +0100
commit862ba6403738224ce683397d496ac43dcb806e1c (patch)
tree2adb774b7ad77455113279c280dc59e01d52c33f /Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp
parent8d77a3297a0722e6f6dcb0ffb564ed016c0cfc20 (diff)
downloadserenity-862ba6403738224ce683397d496ac43dcb806e1c.zip
LibJS: Implement the Error Cause proposal
Currently stage 3. https://github.com/tc39/proposal-error-cause
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp
index f7eae02791..bae4f731e7 100644
--- a/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp
@@ -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