JsFunction seedFunc = new JsFunction(sourceInfo, topScope,
seedFuncName, true);
seedFuncName.setStaticRef(seedFunc);
JsBlock body = new JsBlock(sourceInfo);
seedFunc.setBody(body);
JsExprStmt seedFuncStmt = seedFunc.makeStmt();
globalStmts.add(seedFuncStmt);
typeForStatMap.put(seedFuncStmt, x);
// setup prototype, assign to temp
// _ = com_example_foo_Foo.prototype = new com_example_foo_FooSuper();
JsNameRef lhs = prototype.makeRef(sourceInfo);
lhs.setQualifier(seedFuncName.makeRef(sourceInfo));
JsExpression rhs;
if (x.getSuperClass() != null) {
JsNew newExpr = new JsNew(sourceInfo);
JsNameRef superPrototypeRef = names.get(x.getSuperClass()).makeRef(
sourceInfo);
newExpr.setConstructorExpression(superPrototypeRef);
rhs = newExpr;
} else {
rhs = new JsObjectLiteral(sourceInfo);
}
JsExpression protoAsg = createAssignment(lhs, rhs);
JsExpression tmpAsg = createAssignment(globalTemp.makeRef(sourceInfo),
protoAsg);
JsExprStmt tmpAsgStmt = tmpAsg.makeStmt();
globalStmts.add(tmpAsgStmt);
typeForStatMap.put(tmpAsgStmt, x);
} else {
/*
* MAGIC: java.lang.String is implemented as a JavaScript String
* primitive with a modified prototype.
*/
JsNameRef rhs = prototype.makeRef(sourceInfo);
rhs.setQualifier(jsProgram.getRootScope().declareName("String").makeRef(
sourceInfo));
JsExpression tmpAsg = createAssignment(globalTemp.makeRef(sourceInfo),
rhs);
JsExprStmt tmpAsgStmt = tmpAsg.makeStmt();
globalStmts.add(tmpAsgStmt);
typeForStatMap.put(tmpAsgStmt, x);
}
}