1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:07:34 +00:00

LibJS: Convert GeneratorObject.prototype to be a PrototypeObject

The added #include in GeneratorObject.h is to resolve usage of
Bytecode::RegisterWindow.
This commit is contained in:
Timothy Flynn 2021-09-11 16:23:42 -04:00 committed by Andreas Kling
parent 43e4cec3e2
commit 9e57ea71af
3 changed files with 10 additions and 20 deletions

View file

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <LibJS/Bytecode/Interpreter.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/OrdinaryFunctionObject.h> #include <LibJS/Runtime/OrdinaryFunctionObject.h>

View file

@ -5,25 +5,13 @@
*/ */
#include <LibJS/Bytecode/Interpreter.h> #include <LibJS/Bytecode/Interpreter.h>
#include <LibJS/Runtime/GeneratorObject.h>
#include <LibJS/Runtime/GeneratorObjectPrototype.h> #include <LibJS/Runtime/GeneratorObjectPrototype.h>
#include <LibJS/Runtime/GlobalObject.h>
namespace JS { 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<GeneratorObject>(this_object)) {
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Generator");
return nullptr;
}
return static_cast<GeneratorObject*>(this_object);
}
GeneratorObjectPrototype::GeneratorObjectPrototype(GlobalObject& global_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 // 27.5.1.2 Generator.prototype.next ( value ), https://tc39.es/ecma262/#sec-generator.prototype.next
JS_DEFINE_NATIVE_FUNCTION(GeneratorObjectPrototype::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) if (!generator_object)
return {}; return {};
return generator_object->next_impl(vm, global_object, {}); 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 // 27.5.1.3 Generator.prototype.next ( value ), https://tc39.es/ecma262/#sec-generator.prototype.return
JS_DEFINE_NATIVE_FUNCTION(GeneratorObjectPrototype::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) if (!generator_object)
return {}; return {};
generator_object->set_done(); 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 // 27.5.1.4 Generator.prototype.next ( value ), https://tc39.es/ecma262/#sec-generator.prototype.throw
JS_DEFINE_NATIVE_FUNCTION(GeneratorObjectPrototype::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) if (!generator_object)
return {}; return {};
return generator_object->next_impl(vm, global_object, vm.argument(0)); return generator_object->next_impl(vm, global_object, vm.argument(0));

View file

@ -6,13 +6,14 @@
#pragma once #pragma once
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GeneratorObject.h>
#include <LibJS/Runtime/PrototypeObject.h>
namespace JS { namespace JS {
// 27.5.1 %GeneratorFunction.prototype.prototype%, https://tc39.es/ecma262/#sec-properties-of-generator-prototype // 27.5.1 %GeneratorFunction.prototype.prototype%, https://tc39.es/ecma262/#sec-properties-of-generator-prototype
class GeneratorObjectPrototype final : public Object { class GeneratorObjectPrototype final : public PrototypeObject<GeneratorObjectPrototype, GeneratorObject> {
JS_OBJECT(GeneratorObjectPrototype, Object); JS_PROTOTYPE_OBJECT(GeneratorObjectPrototype, GeneratorObject, Generator);
public: public:
explicit GeneratorObjectPrototype(GlobalObject&); explicit GeneratorObjectPrototype(GlobalObject&);