From 8253e1481823e462fcfa325259df2729cadfc954 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 13 Sep 2021 18:08:56 +0100 Subject: [PATCH] LibJS: Convert Intl.NumberFormat.prototype to be a PrototypeObject --- .../Runtime/Intl/NumberFormatPrototype.cpp | 20 ++----------------- .../Runtime/Intl/NumberFormatPrototype.h | 7 ++++--- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp index cb3477d1b3..40f7d7e4f9 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.cpp @@ -11,25 +11,9 @@ namespace JS::Intl { -static NumberFormat* typed_this(GlobalObject& global_object) -{ - auto& vm = global_object.vm(); - - auto* this_object = vm.this_value(global_object).to_object(global_object); - if (!this_object) - return nullptr; - - if (!is(this_object)) { - vm.throw_exception(global_object, ErrorType::NotAnObjectOfType, "Intl.NumberFormat"); - return nullptr; - } - - return static_cast(this_object); -} - // 15.4 Properties of the Intl.NumberFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-numberformat-prototype-object NumberFormatPrototype::NumberFormatPrototype(GlobalObject& global_object) - : Object(*global_object.object_prototype()) + : PrototypeObject(*global_object.object_prototype()) { } @@ -53,7 +37,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options) // 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then // a. Set nf to ? UnwrapNumberFormat(nf). // 3. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]). - auto* number_format = typed_this(global_object); + auto* number_format = typed_this_object(global_object); if (vm.exception()) return {}; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.h b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.h index f392ab7824..16a7408c58 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormatPrototype.h @@ -6,12 +6,13 @@ #pragma once -#include +#include +#include namespace JS::Intl { -class NumberFormatPrototype final : public Object { - JS_OBJECT(NumberFormatPrototype, Object); +class NumberFormatPrototype final : public PrototypeObject { + JS_PROTOTYPE_OBJECT(NumberFormatPrototype, NumberFormat, Intl.NumberFormat); public: explicit NumberFormatPrototype(GlobalObject&);