From 62356cff409134f60a2d7ca890fa63fca9718477 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 4 Jan 2022 22:15:07 +0100 Subject: [PATCH] LibJS: Convert FunctionObject::bind() to ThrowCompletionOr --- Userland/Libraries/LibJS/Runtime/FunctionObject.cpp | 9 +++++---- Userland/Libraries/LibJS/Runtime/FunctionObject.h | 2 +- Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp index ff6e3925330..1051536a416 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionObject.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -20,7 +21,7 @@ FunctionObject::~FunctionObject() { } -BoundFunction* FunctionObject::bind(Value bound_this_value, Vector arguments) +ThrowCompletionOr FunctionObject::bind(Value bound_this_value, Vector arguments) { auto& vm = this->vm(); FunctionObject& target_function = is(*this) ? static_cast(*this).bound_target_function() : *this; @@ -38,15 +39,15 @@ BoundFunction* FunctionObject::bind(Value bound_this_value, Vector argume return TRY(bound_this_value.to_object(global_object())); } }; - auto bound_this_object = TRY_OR_DISCARD(get_bound_this_object()); + auto bound_this_object = TRY(get_bound_this_object()); i32 computed_length = 0; - auto length_property = TRY_OR_DISCARD(get(vm.names.length)); + auto length_property = TRY(get(vm.names.length)); if (length_property.is_number()) computed_length = max(0, length_property.as_i32() - static_cast(arguments.size())); Object* constructor_prototype = nullptr; - auto prototype_property = TRY_OR_DISCARD(target_function.get(vm.names.prototype)); + auto prototype_property = TRY(target_function.get(vm.names.prototype)); if (prototype_property.is_object()) constructor_prototype = &prototype_property.as_object(); diff --git a/Userland/Libraries/LibJS/Runtime/FunctionObject.h b/Userland/Libraries/LibJS/Runtime/FunctionObject.h index ef2267564a4..0aa9d2a33e0 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionObject.h +++ b/Userland/Libraries/LibJS/Runtime/FunctionObject.h @@ -25,7 +25,7 @@ public: virtual const FlyString& name() const = 0; - BoundFunction* bind(Value bound_this_value, Vector arguments); + ThrowCompletionOr bind(Value bound_this_value, Vector arguments); virtual bool is_strict_mode() const { return false; } diff --git a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp index f74654d991a..ea37349f929 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -72,7 +72,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::bind) arguments.remove(0); } - return this_function.bind(bound_this_arg, move(arguments)); + return TRY(this_function.bind(bound_this_arg, move(arguments))); } // 20.2.3.3 Function.prototype.call ( thisArg, ...args ), https://tc39.es/ecma262/#sec-function.prototype.call