- // This function assumes an input string that would result in a single anonymous function expression.
- StatementNode* exprStatement = program->singleStatement();
- RELEASE_ASSERT(exprStatement);
- RELEASE_ASSERT(exprStatement->isExprStatement());
- ExpressionNode* funcExpr = static_cast<ExprStatementNode*>(exprStatement)->expr();
- RELEASE_ASSERT(funcExpr);
- RELEASE_ASSERT(funcExpr->isFuncExprNode());
- FunctionBodyNode* body = static_cast<FuncExprNode*>(funcExpr)->body();
- RELEASE_ASSERT(!program->hasCapturedVariables());
+ // This function assumes an input string that would result in a single function declaration.
+ StatementNode* statement = program->singleStatement();
+ ASSERT(statement);
+ ASSERT(statement->isBlock());
+ if (!statement || !statement->isBlock())
+ return nullptr;
+
+ StatementNode* funcDecl = static_cast<BlockNode*>(statement)->singleStatement();
+ ASSERT(funcDecl);
+ ASSERT(funcDecl->isFuncDeclNode());
+ if (!funcDecl || !funcDecl->isFuncDeclNode())
+ return nullptr;
+
+ FunctionBodyNode* body = static_cast<FuncDeclNode*>(funcDecl)->body();
+ ASSERT(body);
+ if (!body)
+ return nullptr;