From dbda5a9a4ccfa3ab8e2e913800559f95dde48291 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 26 Jun 2021 19:06:55 +0100 Subject: [PATCH] LibJS: Move install_error_cause() from Object to Error This is only used by Error and its subclasses, so it doesn't need to be available to all objects. --- Userland/Libraries/LibJS/Runtime/Error.cpp | 15 +++++++++++++++ Userland/Libraries/LibJS/Runtime/Error.h | 2 ++ Userland/Libraries/LibJS/Runtime/Object.cpp | 15 --------------- Userland/Libraries/LibJS/Runtime/Object.h | 2 -- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Error.cpp b/Userland/Libraries/LibJS/Runtime/Error.cpp index c2fb594ce5..8eddcc68b8 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.cpp +++ b/Userland/Libraries/LibJS/Runtime/Error.cpp @@ -29,6 +29,21 @@ Error::Error(Object& prototype) { } +// 20.5.8.1 InstallErrorCause ( O, options ), https://tc39.es/proposal-error-cause/#sec-errorobjects-install-error-cause +void Error::install_error_cause(Value options) +{ + auto& vm = this->vm(); + if (!options.is_object()) + return; + auto& options_object = options.as_object(); + if (!options_object.has_property(vm.names.cause)) + return; + auto cause = options_object.get(vm.names.cause).value_or(js_undefined()); + if (vm.exception()) + return; + define_property(vm.names.cause, cause, Attribute::Writable | Attribute::Configurable); +} + #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ ClassName* ClassName::create(GlobalObject& global_object) \ { \ diff --git a/Userland/Libraries/LibJS/Runtime/Error.h b/Userland/Libraries/LibJS/Runtime/Error.h index 774a376dd5..765ff8d27b 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.h +++ b/Userland/Libraries/LibJS/Runtime/Error.h @@ -21,6 +21,8 @@ public: explicit Error(Object& prototype); virtual ~Error() override = default; + + void install_error_cause(Value options); }; // NOTE: Making these inherit from Error is not required by the spec but diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index b0dd99ba16..3571e23541 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -1125,21 +1125,6 @@ Value Object::ordinary_to_primitive(Value::PreferredType preferred_type) const return {}; } -// 20.5.8.1 InstallErrorCause ( O, options ), https://tc39.es/proposal-error-cause/#sec-errorobjects-install-error-cause -void Object::install_error_cause(Value options) -{ - auto& vm = this->vm(); - if (!options.is_object()) - return; - auto& options_object = options.as_object(); - if (!options_object.has_property(vm.names.cause)) - return; - auto cause = options_object.get(vm.names.cause).value_or(js_undefined()); - if (vm.exception()) - return; - define_property(vm.names.cause, cause, Attribute::Writable | Attribute::Configurable); -} - Value Object::invoke_internal(const StringOrSymbol& property_name, Optional arguments) { auto& vm = this->vm(); diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 91f47be76c..bd8fb0575e 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -135,8 +135,6 @@ public: IndexedProperties& indexed_properties() { return m_indexed_properties; } void set_indexed_property_elements(Vector&& values) { m_indexed_properties = IndexedProperties(move(values)); } - void install_error_cause(Value options); - [[nodiscard]] Value invoke_internal(const StringOrSymbol& property_name, Optional arguments); template