LibJS: Convert Intl.ListFormat.prototype to be a PrototypeObject

This commit is contained in:
Linus Groh 2021-09-13 18:05:23 +01:00
parent b256b50476
commit c277658ca6
Notes: sideshowbarker 2024-07-18 04:01:59 +09:00
2 changed files with 8 additions and 23 deletions

View file

@ -12,25 +12,9 @@
namespace JS::Intl {
static ListFormat* 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<ListFormat>(this_object)) {
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Intl.ListFormat");
return nullptr;
}
return static_cast<ListFormat*>(this_object);
}
// 13.4 Properties of the Intl.ListFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-listformat-prototype-object
ListFormatPrototype::ListFormatPrototype(GlobalObject& global_object)
: Object(*global_object.object_prototype())
: PrototypeObject(*global_object.object_prototype())
{
}
@ -56,7 +40,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format)
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
auto* list_format = typed_this(global_object);
auto* list_format = typed_this_object(global_object);
if (vm.exception())
return {};
@ -77,7 +61,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format_to_parts)
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
auto* list_format = typed_this(global_object);
auto* list_format = typed_this_object(global_object);
if (vm.exception())
return {};
@ -95,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
{
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
auto* list_format = typed_this(global_object);
auto* list_format = typed_this_object(global_object);
if (vm.exception())
return {};

View file

@ -6,12 +6,13 @@
#pragma once
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Intl/ListFormat.h>
#include <LibJS/Runtime/PrototypeObject.h>
namespace JS::Intl {
class ListFormatPrototype final : public Object {
JS_OBJECT(ListFormatPrototype, Object);
class ListFormatPrototype final : public PrototypeObject<ListFormatPrototype, ListFormat> {
JS_PROTOTYPE_OBJECT(ListFormatPrototype, ListFormat, Intl.ListFormat);
public:
explicit ListFormatPrototype(GlobalObject&);