From 4ed49e05a9bcc5db8986b2c3523098a0b6ceebb7 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 16 Jan 2022 14:14:42 +0100 Subject: [PATCH] LibJS: Rename GeneratorObjectPrototype to GeneratorPrototype Given we usually call objects Foo{Object,Constructor,Prototype} or Foo{,Constructor,Prototype}, this name was an odd choice. The new one matches the spec better, which calls it the "Generator Prototype Object", so we simply omit the Object suffix as usual as it's implied. --- Userland/Libraries/LibJS/CMakeLists.txt | 2 +- Userland/Libraries/LibJS/Forward.h | 2 +- .../LibJS/Runtime/ECMAScriptFunctionObject.cpp | 4 ++-- .../LibJS/Runtime/FunctionConstructor.cpp | 4 ++-- .../LibJS/Runtime/GeneratorFunctionPrototype.cpp | 8 ++++---- .../Libraries/LibJS/Runtime/GeneratorObject.cpp | 4 ++-- ...rObjectPrototype.cpp => GeneratorPrototype.cpp} | 14 +++++++------- ...ratorObjectPrototype.h => GeneratorPrototype.h} | 10 +++++----- Userland/Libraries/LibJS/Runtime/GlobalObject.cpp | 8 ++++---- Userland/Libraries/LibJS/Runtime/GlobalObject.h | 4 ++-- 10 files changed, 30 insertions(+), 30 deletions(-) rename Userland/Libraries/LibJS/Runtime/{GeneratorObjectPrototype.cpp => GeneratorPrototype.cpp} (78%) rename Userland/Libraries/LibJS/Runtime/{GeneratorObjectPrototype.h => GeneratorPrototype.h} (51%) diff --git a/Userland/Libraries/LibJS/CMakeLists.txt b/Userland/Libraries/LibJS/CMakeLists.txt index 4c104dbda5..01321beeb5 100644 --- a/Userland/Libraries/LibJS/CMakeLists.txt +++ b/Userland/Libraries/LibJS/CMakeLists.txt @@ -82,7 +82,7 @@ set(SOURCES Runtime/GeneratorFunctionConstructor.cpp Runtime/GeneratorFunctionPrototype.cpp Runtime/GeneratorObject.cpp - Runtime/GeneratorObjectPrototype.cpp + Runtime/GeneratorPrototype.cpp Runtime/GlobalEnvironment.cpp Runtime/GlobalObject.cpp Runtime/IndexedProperties.cpp diff --git a/Userland/Libraries/LibJS/Forward.h b/Userland/Libraries/LibJS/Forward.h index e67045445c..2e002917a5 100644 --- a/Userland/Libraries/LibJS/Forward.h +++ b/Userland/Libraries/LibJS/Forward.h @@ -185,7 +185,7 @@ class ProxyObject; class ProxyConstructor; // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor -class GeneratorObjectPrototype; +class GeneratorPrototype; class AsyncFromSyncIteratorPrototype; class TypedArrayConstructor; diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index e7db4a8109..dce4c693d9 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -111,7 +111,7 @@ void ECMAScriptFunctionObject::initialize(GlobalObject& global_object) break; case FunctionKind::Generator: // prototype is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png) - prototype = global_object.generator_object_prototype(); + prototype = global_object.generator_prototype(); break; case FunctionKind::Async: break; diff --git a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp index 12b76a334e..3c65465b86 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include @@ -242,7 +242,7 @@ ThrowCompletionOr FunctionConstructor::create_dynamic // 33. If kind is generator, then if (kind == FunctionKind::Generator) { // a. Let prototype be ! OrdinaryObjectCreate(%GeneratorFunction.prototype.prototype%). - prototype = Object::create(global_object, global_object.generator_object_prototype()); + prototype = Object::create(global_object, global_object.generator_prototype()); // b. Perform DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }). function->define_direct_property(vm.names.prototype, prototype, Attribute::Writable); diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp index 34e5b786ca..08df300e5b 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include namespace JS { @@ -20,9 +20,9 @@ void GeneratorFunctionPrototype::initialize(GlobalObject& global_object) auto& vm = this->vm(); Object::initialize(global_object); - // 27.3.3.2 %GeneratorFunction.prototype% prototype, https://tc39.es/ecma262/#sec-generatorfunction.prototype.prototype - define_direct_property(vm.names.prototype, global_object.generator_object_prototype(), Attribute::Configurable); - // 27.3.3.3 %GeneratorFunction.prototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-generatorfunction.prototype-@@tostringtag + // 27.3.3.2 GeneratorFunction.prototype.prototype, https://tc39.es/ecma262/#sec-generatorfunction.prototype.prototype + define_direct_property(vm.names.prototype, global_object.generator_prototype(), Attribute::Configurable); + // 27.3.3.3 GeneratorFunction.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-generatorfunction.prototype-@@tostringtag define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "GeneratorFunction"), Attribute::Configurable); } diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp index 7f37c6d084..fb6d3819b9 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include namespace JS { @@ -21,7 +21,7 @@ ThrowCompletionOr GeneratorObject::create(GlobalObject& global // We implement async functions by transforming them to generator function in the bytecode // interpreter. However an async function does not have a prototype and should not be // changed thus we hardcode the prototype. - generating_function_prototype = global_object.generator_object_prototype(); + generating_function_prototype = global_object.generator_prototype(); } else { generating_function_prototype = TRY(generating_function->get(global_object.vm().names.prototype)); } diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp similarity index 78% rename from Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.cpp rename to Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp index 4b1e709bfc..c920afd36c 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorPrototype.cpp @@ -4,17 +4,17 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include namespace JS { -GeneratorObjectPrototype::GeneratorObjectPrototype(GlobalObject& global_object) +GeneratorPrototype::GeneratorPrototype(GlobalObject& global_object) : PrototypeObject(*global_object.iterator_prototype()) { } -void GeneratorObjectPrototype::initialize(GlobalObject& global_object) +void GeneratorPrototype::initialize(GlobalObject& global_object) { auto& vm = this->vm(); Object::initialize(global_object); @@ -27,19 +27,19 @@ void GeneratorObjectPrototype::initialize(GlobalObject& global_object) define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Generator"), Attribute::Configurable); } -GeneratorObjectPrototype::~GeneratorObjectPrototype() +GeneratorPrototype::~GeneratorPrototype() { } // 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(GeneratorPrototype::next) { auto* generator_object = TRY(typed_this_object(global_object)); return generator_object->next_impl(vm, global_object, vm.argument(0), {}); } // 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(GeneratorPrototype::return_) { auto* generator_object = TRY(typed_this_object(global_object)); generator_object->set_done(); @@ -47,7 +47,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_) +JS_DEFINE_NATIVE_FUNCTION(GeneratorPrototype::throw_) { auto* generator_object = TRY(typed_this_object(global_object)); 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/GeneratorPrototype.h similarity index 51% rename from Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.h rename to Userland/Libraries/LibJS/Runtime/GeneratorPrototype.h index 776c5da123..8d49b23ff2 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/GeneratorPrototype.h @@ -11,14 +11,14 @@ namespace JS { -// 27.5.1 %GeneratorFunction.prototype.prototype%, https://tc39.es/ecma262/#sec-properties-of-generator-prototype -class GeneratorObjectPrototype final : public PrototypeObject { - JS_PROTOTYPE_OBJECT(GeneratorObjectPrototype, GeneratorObject, Generator); +// 27.5.1 Properties of the Generator Prototype Object, https://tc39.es/ecma262/#sec-properties-of-generator-prototype +class GeneratorPrototype final : public PrototypeObject { + JS_PROTOTYPE_OBJECT(GeneratorPrototype, GeneratorObject, Generator); public: - explicit GeneratorObjectPrototype(GlobalObject&); + explicit GeneratorPrototype(GlobalObject&); virtual void initialize(GlobalObject&) override; - virtual ~GeneratorObjectPrototype() override; + virtual ~GeneratorPrototype() override; private: JS_DECLARE_NATIVE_FUNCTION(next); diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index 423a0ab75e..9b8240d5b2 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include #include @@ -168,8 +168,8 @@ void GlobalObject::initialize_global_object() // %GeneratorFunction.prototype.prototype% must be initialized separately as it has no // companion constructor - m_generator_object_prototype = heap().allocate(*this, *this); - m_generator_object_prototype->define_direct_property(vm.names.constructor, m_generator_function_constructor, Attribute::Configurable); + m_generator_prototype = heap().allocate(*this, *this); + m_generator_prototype->define_direct_property(vm.names.constructor, m_generator_function_constructor, Attribute::Configurable); m_async_from_sync_iterator_prototype = heap().allocate(*this, *this); @@ -305,7 +305,7 @@ void GlobalObject::visit_edges(Visitor& visitor) visitor.visit(m_new_object_shape); visitor.visit(m_new_ordinary_function_prototype_object_shape); visitor.visit(m_proxy_constructor); - visitor.visit(m_generator_object_prototype); + visitor.visit(m_generator_prototype); visitor.visit(m_array_prototype_values_function); visitor.visit(m_date_constructor_now_function); visitor.visit(m_eval_function); diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.h b/Userland/Libraries/LibJS/Runtime/GlobalObject.h index 9810979456..2329ff514a 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.h @@ -35,7 +35,7 @@ public: ProxyConstructor* proxy_constructor() { return m_proxy_constructor; } // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor - GeneratorObjectPrototype* generator_object_prototype() { return m_generator_object_prototype; } + GeneratorPrototype* generator_prototype() { return m_generator_prototype; } AsyncFromSyncIteratorPrototype* async_from_sync_iterator_prototype() { return m_async_from_sync_iterator_prototype; } FunctionObject* array_prototype_values_function() const { return m_array_prototype_values_function; } @@ -102,7 +102,7 @@ private: ProxyConstructor* m_proxy_constructor { nullptr }; // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor - GeneratorObjectPrototype* m_generator_object_prototype { nullptr }; + GeneratorPrototype* m_generator_prototype { nullptr }; AsyncFromSyncIteratorPrototype* m_async_from_sync_iterator_prototype { nullptr }; FunctionObject* m_array_prototype_values_function { nullptr };