From d0d9a4f43dbd58c694c706b17996157fede20bdf Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Fri, 13 Dec 2019 20:59:32 -0500 Subject: Bug 1316098 - Optimize out result object allocation for await/return in async function. Tag #1287 --- js/src/frontend/BytecodeEmitter.cpp | 25 ++++++++++++++++++++++--- js/src/frontend/BytecodeEmitter.h | 1 + js/src/frontend/SharedContext.h | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) (limited to 'js/src/frontend') diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 77a480bff..a98016d63 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -8552,7 +8552,7 @@ bool BytecodeEmitter::emitYield(ParseNode* pn) { MOZ_ASSERT(sc->isFunctionBox()); - MOZ_ASSERT(pn->getOp() == JSOP_YIELD || pn->getOp() == JSOP_AWAIT); + MOZ_ASSERT(pn->getOp() == JSOP_YIELD); bool needsIteratorResult = sc->asFunctionBox()->needsIteratorResult(); if (needsIteratorResult) { @@ -8574,12 +8574,27 @@ BytecodeEmitter::emitYield(ParseNode* pn) if (!emitGetDotGenerator()) return false; - if (!emitYieldOp(pn->getOp())) + if (!emitYieldOp(JSOP_YIELD)) return false; return true; } +bool +BytecodeEmitter::emitAwait(ParseNode* pn) +{ + MOZ_ASSERT(sc->isFunctionBox()); + MOZ_ASSERT(pn->getOp() == JSOP_AWAIT); + + if (!emitTree(pn->pn_kid)) + return false; + if (!emitGetDotGenerator()) + return false; + if (!emitYieldOp(JSOP_AWAIT)) + return false; + return true; +} + bool BytecodeEmitter::emitYieldStar(ParseNode* iter) { @@ -10630,11 +10645,15 @@ BytecodeEmitter::emitTree(ParseNode* pn, ValueUsage valueUsage /* = ValueUsage:: break; case PNK_YIELD: - case PNK_AWAIT: if (!emitYield(pn)) return false; break; + case PNK_AWAIT: + if (!emitAwait(pn)) + return false; + break; + case PNK_STATEMENTLIST: if (!emitStatementList(pn)) return false; diff --git a/js/src/frontend/BytecodeEmitter.h b/js/src/frontend/BytecodeEmitter.h index 08638f48a..f3f78df16 100644 --- a/js/src/frontend/BytecodeEmitter.h +++ b/js/src/frontend/BytecodeEmitter.h @@ -613,6 +613,7 @@ struct MOZ_STACK_CLASS BytecodeEmitter MOZ_MUST_USE bool emitYield(ParseNode* pn); MOZ_MUST_USE bool emitYieldOp(JSOp op); MOZ_MUST_USE bool emitYieldStar(ParseNode* iter); + MOZ_MUST_USE bool emitAwait(ParseNode* pn); MOZ_MUST_USE bool emitPropLHS(ParseNode* pn); MOZ_MUST_USE bool emitPropOp(ParseNode* pn, JSOp op); diff --git a/js/src/frontend/SharedContext.h b/js/src/frontend/SharedContext.h index 2d478308e..8a5f6c0bd 100644 --- a/js/src/frontend/SharedContext.h +++ b/js/src/frontend/SharedContext.h @@ -553,7 +553,7 @@ class FunctionBox : public ObjectBox, public SharedContext } bool needsIteratorResult() const { - return isStarGenerator() || isAsync(); + return isStarGenerator(); } bool isAsync() const { return asyncKind() == AsyncFunction; } -- cgit v1.2.3