From 9e57ea71afd3ca3da395849908664e06e7282710 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 11 Sep 2021 16:23:42 -0400 Subject: [PATCH] LibJS: Convert GeneratorObject.prototype to be a PrototypeObject The added #include in GeneratorObject.h is to resolve usage of Bytecode::RegisterWindow. --- .../Libraries/LibJS/Runtime/GeneratorObject.h | 1 + .../Runtime/GeneratorObjectPrototype.cpp | 22 +++++-------------- .../LibJS/Runtime/GeneratorObjectPrototype.h | 7 +++--- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.h b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h index b83b627ffe..e0159ab9ab 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.h +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.cpp index 6104f62304..e9083acdb0 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.cpp @@ -5,25 +5,13 @@ */ #include -#include #include +#include namespace JS { -static GeneratorObject* typed_this(VM& vm, GlobalObject& global_object) -{ - auto* this_object = vm.this_value(global_object).to_object(global_object); - if (!this_object) - return {}; - if (!is(this_object)) { - vm.throw_exception(global_object, ErrorType::NotAnObjectOfType, "Generator"); - return nullptr; - } - return static_cast(this_object); -} - GeneratorObjectPrototype::GeneratorObjectPrototype(GlobalObject& global_object) - : Object(*global_object.iterator_prototype()) + : PrototypeObject(*global_object.iterator_prototype()) { } @@ -47,7 +35,7 @@ GeneratorObjectPrototype::~GeneratorObjectPrototype() // 27.5.1.2 Generator.prototype.next ( value ), https://tc39.es/ecma262/#sec-generator.prototype.next JS_DEFINE_NATIVE_FUNCTION(GeneratorObjectPrototype::next) { - auto generator_object = typed_this(vm, global_object); + auto generator_object = typed_this_object(global_object); if (!generator_object) return {}; return generator_object->next_impl(vm, global_object, {}); @@ -56,7 +44,7 @@ JS_DEFINE_NATIVE_FUNCTION(GeneratorObjectPrototype::next) // 27.5.1.3 Generator.prototype.next ( value ), https://tc39.es/ecma262/#sec-generator.prototype.return JS_DEFINE_NATIVE_FUNCTION(GeneratorObjectPrototype::return_) { - auto generator_object = typed_this(vm, global_object); + auto generator_object = typed_this_object(global_object); if (!generator_object) return {}; generator_object->set_done(); @@ -66,7 +54,7 @@ JS_DEFINE_NATIVE_FUNCTION(GeneratorObjectPrototype::return_) // 27.5.1.4 Generator.prototype.next ( value ), https://tc39.es/ecma262/#sec-generator.prototype.throw JS_DEFINE_NATIVE_FUNCTION(GeneratorObjectPrototype::throw_) { - auto generator_object = typed_this(vm, global_object); + auto generator_object = typed_this_object(global_object); if (!generator_object) return {}; return generator_object->next_impl(vm, global_object, vm.argument(0)); diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.h b/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.h index 4388612f90..776c5da123 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.h @@ -6,13 +6,14 @@ #pragma once -#include +#include +#include namespace JS { // 27.5.1 %GeneratorFunction.prototype.prototype%, https://tc39.es/ecma262/#sec-properties-of-generator-prototype -class GeneratorObjectPrototype final : public Object { - JS_OBJECT(GeneratorObjectPrototype, Object); +class GeneratorObjectPrototype final : public PrototypeObject { + JS_PROTOTYPE_OBJECT(GeneratorObjectPrototype, GeneratorObject, Generator); public: explicit GeneratorObjectPrototype(GlobalObject&);