Function literals, switch bcc to collect generic JS2Objects.
git-svn-id: svn://10.0.0.236/trunk@137889 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -57,58 +57,37 @@ namespace MetaData {
|
||||
|
||||
js2val Function_Constructor(JS2Metadata *meta, const js2val thisValue, js2val argv[], uint32 argc)
|
||||
{
|
||||
js2val thatValue = OBJECT_TO_JS2VAL(new FunctionInstance(meta->functionClass->prototype, meta->functionClass));
|
||||
FunctionInstance *fnInst = checked_cast<FunctionInstance *>(JS2VAL_TO_OBJECT(thatValue));
|
||||
JS2Object::RootIterator ri = JS2Object::addRoot(&fnInst);
|
||||
fnInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_INACCESSIBLE, true));
|
||||
|
||||
if (argc) {
|
||||
const String *str = meta->toString(argv[0]);
|
||||
const String &srcLoc = widenCString("Function constructor source");
|
||||
const String *bodyStr = meta->toString(argv[argc - 1]);
|
||||
String functionExpr(widenCString("("));
|
||||
if (argc > 1) {
|
||||
for (uint32 i = 0; i < (argc - 1); i++) {
|
||||
functionExpr += *meta->toString(argv[i]);
|
||||
if (i < (argc - 2))
|
||||
functionExpr += ",";
|
||||
}
|
||||
}
|
||||
functionExpr += widenCString("){") + *bodyStr + widenCString("}");
|
||||
|
||||
Arena a;
|
||||
Pragma::Flags flags = Pragma::js1; // XXX get flags from meta/context ?
|
||||
Parser parser(meta->world, a, flags, *str, srcLoc);
|
||||
CompilationData *oldData = NULL;
|
||||
try {
|
||||
StmtNode *parsedStatements = parser.parseProgram();
|
||||
ASSERT(parser.lexer.peek(true).hasKind(Token::end));
|
||||
if (meta->showTrees)
|
||||
{
|
||||
PrettyPrinter f(stdOut, 80);
|
||||
{
|
||||
PrettyPrinter::Block b(f, 2);
|
||||
f << "Program =";
|
||||
f.linearBreak(1);
|
||||
StmtNode::printStatements(f, parsedStatements);
|
||||
}
|
||||
f.end();
|
||||
stdOut << '\n';
|
||||
}
|
||||
if (parsedStatements) {
|
||||
oldData = meta->startCompilationUnit(fnInst->fWrap->bCon, *str, srcLoc);
|
||||
meta->ValidateStmtList(parsedStatements);
|
||||
StmtNode *p = parsedStatements;
|
||||
size_t lastPos = p->pos;
|
||||
while (p) {
|
||||
meta->SetupStmt(meta->env, RunPhase, p);
|
||||
lastPos = p->pos;
|
||||
p = p->next;
|
||||
}
|
||||
fnInst->fWrap->bCon->emitOp(eReturnVoid, lastPos);
|
||||
}
|
||||
}
|
||||
catch (Exception &x) {
|
||||
if (oldData)
|
||||
meta->restoreCompilationUnit(oldData);
|
||||
JS2Object::removeRoot(ri);
|
||||
throw x;
|
||||
}
|
||||
if (oldData)
|
||||
meta->restoreCompilationUnit(oldData);
|
||||
Parser parser(meta->world, a, flags, functionExpr, srcLoc);
|
||||
FunctionExprNode *fnExpr = parser.parseFunctionExpression(meta->engine->errorPos());
|
||||
ASSERT(parser.lexer.peek(true).hasKind(Token::end));
|
||||
ASSERT(fnExpr); // otherwise, an exception would have been thrown out of here
|
||||
JS2Class *exprType;
|
||||
meta->ValidateExpression(&meta->cxt, meta->env, fnExpr);
|
||||
meta->SetupExprNode(meta->env, RunPhase, fnExpr, &exprType);
|
||||
ASSERT(fnExpr);
|
||||
return OBJECT_TO_JS2VAL(fnExpr->obj);
|
||||
}
|
||||
JS2Object::removeRoot(ri);
|
||||
return thatValue;
|
||||
else { // construct an empty function wrapper
|
||||
js2val thatValue = OBJECT_TO_JS2VAL(new FunctionInstance(meta->functionClass->prototype, meta->functionClass));
|
||||
FunctionInstance *fnInst = checked_cast<FunctionInstance *>(JS2VAL_TO_OBJECT(thatValue));
|
||||
fnInst->fWrap = new FunctionWrapper(true, new ParameterFrame(JS2VAL_INACCESSIBLE, true));
|
||||
return thatValue;
|
||||
}
|
||||
}
|
||||
|
||||
static js2val Function_Call(JS2Metadata *meta, const js2val thisValue, js2val argv[], uint32 argc)
|
||||
|
||||
Reference in New Issue
Block a user