From fba3c77a04f7549dedd0b0e61dcea51bf81e266c Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 19 Jun 2021 02:03:37 +0100 Subject: LibJS: Add missing exception checks to Number() constructor --- Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp index ac4f7a1917..618777388f 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp @@ -84,15 +84,26 @@ static Value get_value_from_constructor_argument(GlobalObject& global_object) // 21.1.1.1 Number ( value ), https://tc39.es/ecma262/#sec-number-constructor-number-value Value NumberConstructor::call() { - return get_value_from_constructor_argument(global_object()); + auto& vm = this->vm(); + auto& global_object = this->global_object(); + + auto number = get_value_from_constructor_argument(global_object); + if (vm.exception()) + return {}; + return number; } // 21.1.1.1 Number ( value ), https://tc39.es/ecma262/#sec-number-constructor-number-value Value NumberConstructor::construct(Function&) { - auto number = get_value_from_constructor_argument(global_object()); + auto& vm = this->vm(); + auto& global_object = this->global_object(); + + auto number = get_value_from_constructor_argument(global_object); + if (vm.exception()) + return {}; // FIXME: Use OrdinaryCreateFromConstructor(NewTarget, "%Number.prototype%") - return NumberObject::create(global_object(), number.as_double()); + return NumberObject::create(global_object, number.as_double()); } // 21.1.2.2 Number.isFinite ( number ), https://tc39.es/ecma262/#sec-number.isfinite -- cgit v1.2.3