From b256b50476f97697c111d646d7e0a70845c3e2f2 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 13 Sep 2021 18:03:27 +0100 Subject: [PATCH] LibJS: Convert Intl.DisplayNames.prototype to be a PrototypeObject --- .../Runtime/Intl/DisplayNamesPrototype.cpp | 22 +++---------------- .../Runtime/Intl/DisplayNamesPrototype.h | 7 +++--- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp index 320bcb126a..ed0c94b8f1 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp @@ -12,25 +12,9 @@ namespace JS::Intl { -static DisplayNames* 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.DisplayNames"); - return nullptr; - } - - return static_cast(this_object); -} - // 12.4 Properties of the Intl.DisplayNames Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-displaynames-prototype-object DisplayNamesPrototype::DisplayNamesPrototype(GlobalObject& global_object) - : Object(*global_object.object_prototype()) + : PrototypeObject(*global_object.object_prototype()) { } @@ -55,7 +39,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of) // 1. Let displayNames be this value. // 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]). - auto* display_names = typed_this(global_object); + auto* display_names = typed_this_object(global_object); if (!display_names) return {}; @@ -107,7 +91,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options) { // 1. Let displayNames be this value. // 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]). - auto* display_names = typed_this(global_object); + auto* display_names = typed_this_object(global_object); if (!display_names) return {}; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.h b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.h index 38cc6a7c6a..30e4d23f11 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.h @@ -6,12 +6,13 @@ #pragma once -#include +#include +#include namespace JS::Intl { -class DisplayNamesPrototype final : public Object { - JS_OBJECT(DisplayNamesPrototype, Object); +class DisplayNamesPrototype final : public PrototypeObject { + JS_PROTOTYPE_OBJECT(DisplayNamesPrototype, DisplayNames, Intl.DisplayNames); public: explicit DisplayNamesPrototype(GlobalObject&);