Skip to content

Commit 2f98542

Browse files
author
Kevin Smith
committed
[MERGE #6172 @rhuanjl] async generator object method and minor misc
Merge pull request #6172 from rhuanjl:asyncGeneratorFixes I missed async generator properties of objects when updating the parser in #5834 This PR: 1. fixes that omission enabling async generator properties of objects when async generators are enabled 2. adds tests for a couple of async generator syntax options that were not currently tested (including for point 1) 3. updates the async generator continue methods to use the new PerformPromiseThen from #6163 - this has no observable effect but improves internal consistency @zenparsing please could you take a look at this?
2 parents 9296ec5 + ade0a9f commit 2f98542

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

lib/Parser/Parse.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4688,9 +4688,9 @@ ParseNodePtr Parser::ParseMemberList(LPCOLESTR pNameHint, uint32* pNameHintLengt
46884688
ushort fncDeclFlags = fFncNoName | fFncMethod;
46894689
if (isGenerator)
46904690
{
4691-
if (isAsyncMethod)
4691+
if (isAsyncMethod && !m_scriptContext->GetConfig()->IsES2018AsyncIterationEnabled())
46924692
{
4693-
Error(ERRsyntax);
4693+
Error(ERRExperimental);
46944694
}
46954695

46964696
// Include star character in the function extents

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10260,7 +10260,8 @@ using namespace Js;
1026010260
// 7. Let onRejected be CreateBuiltinFunction(stepsRejected, << [[AsyncContext]] >>).
1026110261
// 8. Set onRejected.[[AsyncContext]] to asyncContext.
1026210262
// 9. Perform ! PerformPromiseThen(promise, onFulfilled, onRejected).
10263-
JavascriptPromise::CreateThenPromise(promise, generator->GetAwaitNextFunction(), generator->GetAwaitThrowFunction(), scriptContext);
10263+
JavascriptPromiseCapability* unused = JavascriptPromise::UnusedPromiseCapability(scriptContext);
10264+
JavascriptPromise::PerformPromiseThen(promise, unused, generator->GetAwaitNextFunction(), generator->GetAwaitThrowFunction(), scriptContext);
1026410265
// 10. Remove asyncContext from the execution context stack and restore the execution context that is at the top of the execution context stack as the running execution context.
1026510266
// 11. Set the code evaluation state of asyncContext such that when evaluation is resumed with a Completion completion, the following steps of the algorithm that invoked Await will be performed, with completion available.
1026610267
}
@@ -10270,14 +10271,16 @@ using namespace Js;
1027010271
{
1027110272
JavascriptPromise* promise = JavascriptPromise::InternalPromiseResolve(value, scriptContext);
1027210273

10273-
JavascriptPromise::CreateThenPromise(promise, generator->EnsureAwaitYieldStarFunction(), generator->GetAwaitThrowFunction(), scriptContext);
10274+
JavascriptPromiseCapability* unused = JavascriptPromise::UnusedPromiseCapability(scriptContext);
10275+
JavascriptPromise::PerformPromiseThen(promise, unused, generator->EnsureAwaitYieldStarFunction(), generator->GetAwaitThrowFunction(), scriptContext);
1027410276
}
1027510277

1027610278
void JavascriptOperators::OP_AsyncYield(JavascriptGenerator* generator, Var value, ScriptContext* scriptContext)
1027710279
{
1027810280
JavascriptPromise* promise = JavascriptPromise::InternalPromiseResolve(value, scriptContext);
1027910281

10280-
JavascriptPromise::CreateThenPromise(promise, generator->GetAwaitYieldFunction(), generator->GetAwaitThrowFunction(), scriptContext);
10282+
JavascriptPromiseCapability* unused = JavascriptPromise::UnusedPromiseCapability(scriptContext);
10283+
JavascriptPromise::PerformPromiseThen(promise, unused, generator->GetAwaitYieldFunction(), generator->GetAwaitThrowFunction(), scriptContext);
1028110284
}
1028210285

1028310286
Var JavascriptOperators::OP_AsyncYieldIsReturn(ResumeYieldData* yieldData)

lib/Runtime/Library/JavascriptGenerator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ namespace Js
569569
RecyclableObject* onFulfilled = library->CreateAsyncGeneratorResumeNextReturnProcessorFunction(this, false);
570570
RecyclableObject* onRejected = library->CreateAsyncGeneratorResumeNextReturnProcessorFunction(this, true);
571571

572-
JavascriptPromise::CreateThenPromise(promise, onFulfilled, onRejected, scriptContext);
572+
JavascriptPromiseCapability* unused = JavascriptPromise::UnusedPromiseCapability(scriptContext);
573+
JavascriptPromise::PerformPromiseThen(promise, unused, onFulfilled, onRejected, scriptContext);
573574
}
574575

575576
RuntimeFunction* JavascriptGenerator::EnsureAwaitYieldStarFunction()

test/es7/async-generator-apis.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const tests = [
141141
}
142142
},
143143
{
144-
name : "Async Generaotr function instances have the correct prototype object",
144+
name : "Async Generator function instances have the correct prototype object",
145145
body () {
146146
async function* agf () {}
147147
const prototype = agf.prototype;
@@ -211,6 +211,26 @@ const tests = [
211211
// found in async-generator-functionality.js test.
212212
}
213213
},
214+
{
215+
name: "Other forms of Async Generator",
216+
body: function () {
217+
const obj = {
218+
async *oagf() {}
219+
}
220+
class cla {
221+
async *cagf() {}
222+
static async *scagf() {}
223+
}
224+
225+
const instance = new cla();
226+
227+
const asyncGeneratorFunctionPrototype = Object.getPrototypeOf(async function* () { });
228+
229+
assert.areEqual(asyncGeneratorFunctionPrototype, Object.getPrototypeOf(instance.cagf), "Async generator class method should have the same prototype as async generator function");
230+
assert.areEqual(asyncGeneratorFunctionPrototype, Object.getPrototypeOf(cla.scagf), "Async generator class static method should have the same prototype as async generator function");
231+
assert.areEqual(asyncGeneratorFunctionPrototype, Object.getPrototypeOf(obj.oagf), "Async generator object method should have the same prototype as async generator function");
232+
}
233+
}
214234
];
215235

216236
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 commit comments

Comments
 (0)