浏览代码

LibJS: Add getters for %{Async,}GeneratorFunction.prototype.prototype%

These exist as {Async,}GeneratorPrototype of course, but the spec
doesn't always refer to them by the direct name.
Linus Groh 3 年之前
父节点
当前提交
dd547c3374

+ 1 - 1
Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp

@@ -243,7 +243,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> 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_prototype());
+        prototype = Object::create(global_object, global_object.generator_function_prototype_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);

+ 5 - 0
Userland/Libraries/LibJS/Runtime/GlobalObject.h

@@ -40,6 +40,11 @@ public:
     Object* async_generator_prototype() { return m_async_generator_prototype; }
     Object* generator_prototype() { return m_generator_prototype; }
 
+    // Alias for the AsyncGenerator Prototype Object used by the spec (%AsyncGeneratorFunction.prototype.prototype%)
+    Object* async_generator_function_prototype_prototype() { return m_async_generator_prototype; }
+    // Alias for the Generator Prototype Object used by the spec (%GeneratorFunction.prototype.prototype%)
+    Object* generator_function_prototype_prototype() { return m_generator_prototype; }
+
     // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
     Object* intl_segments_prototype() { return m_intl_segments_prototype; }