summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/runtime/FunctionConstructor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'JavaScriptCore/runtime/FunctionConstructor.cpp')
-rw-r--r--JavaScriptCore/runtime/FunctionConstructor.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/JavaScriptCore/runtime/FunctionConstructor.cpp b/JavaScriptCore/runtime/FunctionConstructor.cpp
index 2783b35..f4f5cc8 100644
--- a/JavaScriptCore/runtime/FunctionConstructor.cpp
+++ b/JavaScriptCore/runtime/FunctionConstructor.cpp
@@ -66,6 +66,32 @@ CallType FunctionConstructor::getCallData(CallData& callData)
return CallTypeHost;
}
+FunctionBodyNode* extractFunctionBody(ProgramNode* program)
+{
+ if (!program)
+ return 0;
+
+ StatementVector& children = program->children();
+ if (children.size() != 1)
+ return 0;
+
+ StatementNode* exprStatement = children[0];
+ ASSERT(exprStatement);
+ ASSERT(exprStatement->isExprStatement());
+ if (!exprStatement || !exprStatement->isExprStatement())
+ return 0;
+
+ ExpressionNode* funcExpr = static_cast<ExprStatementNode*>(exprStatement)->expr();
+ ASSERT(funcExpr);
+ ASSERT(funcExpr->isFuncExprNode());
+ if (!funcExpr || !funcExpr->isFuncExprNode())
+ return 0;
+
+ FunctionBodyNode* body = static_cast<FuncExprNode*>(funcExpr)->body();
+ ASSERT(body);
+ return body;
+}
+
// ECMA 15.3.2 The Function Constructor
JSObject* constructFunction(ExecState* exec, const ArgList& args, const Identifier& functionName, const UString& sourceURL, int lineNumber)
{
@@ -87,13 +113,15 @@ JSObject* constructFunction(ExecState* exec, const ArgList& args, const Identifi
int errLine;
UString errMsg;
SourceCode source = makeSource(program, sourceURL, lineNumber);
- RefPtr<FunctionBodyNode> body = exec->globalData().parser->parseFunctionFromGlobalCode(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
+ RefPtr<ProgramNode> programNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
+
+ FunctionBodyNode* body = extractFunctionBody(programNode.get());
if (!body)
return throwError(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url());
JSGlobalObject* globalObject = exec->lexicalGlobalObject();
ScopeChain scopeChain(globalObject, globalObject->globalData(), exec->globalThisValue());
- return new (exec) JSFunction(exec, adoptRef(new FunctionExecutable(functionName, body.get())), scopeChain.node());
+ return new (exec) JSFunction(exec, functionName, body, scopeChain.node());
}
// ECMA 15.3.2 The Function Constructor