Skip to content

Commit

Permalink
Reject async generators during semantic validation
Browse files Browse the repository at this point in the history
Summary:
Hermes does not currently support async generators. As such, reject those early in compilation
(i.e., during ```SemanticValidation```).

Reviewed By: werew

Differential Revision: D45155647

fbshipit-source-id: a7b83c5a9956e21889f43708483441228309082b
  • Loading branch information
John Porto authored and facebook-github-bot committed Apr 21, 2023
1 parent f02a952 commit 8239e82
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 4 additions & 0 deletions lib/AST/SemanticValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,10 @@ void SemanticValidator::visitFunction(
haveActiveContext() ? curFunction()->sourceVisibility
: SourceVisibility::Default};

if (compile_ && ESTree::isAsync(node) && ESTree::isGenerator(node)) {
sm_.error(node->getSourceRange(), "async generators are unsupported");
}

// It is a Syntax Error if UniqueFormalParameters Contains YieldExpression
// is true.
// NOTE: isFormalParams_ is reset to false on encountering a new function,
Expand Down
12 changes: 0 additions & 12 deletions lib/IRGen/ESTreeIRGen-func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ EnterBlockScope::~EnterBlockScope() {

void ESTreeIRGen::genFunctionDeclaration(
ESTree::FunctionDeclarationNode *func) {
if (func->_async && func->_generator) {
Builder.getModule()->getContext().getSourceErrorManager().error(
func->getSourceRange(), Twine("async generators are unsupported"));
return;
}

// Find the name of the function.
Identifier functionName = getNameFieldFromID(func->_id);
LLVM_DEBUG(llvh::dbgs() << "IRGen function \"" << functionName << "\".\n");
Expand Down Expand Up @@ -142,12 +136,6 @@ void ESTreeIRGen::hoistCreateFunctions(ESTree::Node *containingNode) {
Value *ESTreeIRGen::genFunctionExpression(
ESTree::FunctionExpressionNode *FE,
Identifier nameHint) {
if (FE->_async && FE->_generator) {
Builder.getModule()->getContext().getSourceErrorManager().error(
FE->getSourceRange(), Twine("async generators are unsupported"));
return Builder.getLiteralUndefined();
}

LLVM_DEBUG(
llvh::dbgs()
<< "Creating anonymous closure. "
Expand Down
11 changes: 11 additions & 0 deletions test/IRGen/es6/async-generators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// RUN: (! %hermesc %s --dump-bytecode 2>&1) | %FileCheck %s

async function* f() {};
// CHECK: async generators are unsupported

0 comments on commit 8239e82

Please sign in to comment.