*/
JsName gwtOnLoadName = topScope.declareName("gwtOnLoad");
gwtOnLoadName.setObfuscatable(false);
JsFunction gwtOnLoad = new JsFunction(topScope, gwtOnLoadName, true);
globalStmts.add(gwtOnLoad.makeStmt());
JsBlock body = new JsBlock();
gwtOnLoad.setBody(body);
JsScope fnScope = gwtOnLoad.getScope();
List<JsParameter> params = gwtOnLoad.getParameters();
JsName errFn = fnScope.declareName("errFn");
JsName modName = fnScope.declareName("modName");
JsName modBase = fnScope.declareName("modBase");
params.add(new JsParameter(errFn));
params.add(new JsParameter(modName));
params.add(new JsParameter(modBase));
JsExpression asg = createAssignment(
topScope.findExistingUnobfuscatableName("$moduleName").makeRef(),
modName.makeRef());
body.getStatements().add(asg.makeStmt());
asg = createAssignment(topScope.findExistingUnobfuscatableName(
"$moduleBase").makeRef(), modBase.makeRef());
body.getStatements().add(asg.makeStmt());
JsIf jsIf = new JsIf();
body.getStatements().add(jsIf);
jsIf.setIfExpr(errFn.makeRef());
JsTry jsTry = new JsTry();
jsIf.setThenStmt(jsTry);
JsBlock callBlock = new JsBlock();
jsIf.setElseStmt(callBlock);
jsTry.setTryBlock(callBlock);
for (int i = 0; i < entryFuncs.size(); ++i) {
JsFunction func = entryFuncs.get(i);
if (func != null) {
JsInvocation call = new JsInvocation();
call.setQualifier(func.getName().makeRef());
callBlock.getStatements().add(call.makeStmt());
}
}
JsCatch jsCatch = new JsCatch(fnScope, "e");
jsTry.getCatches().add(jsCatch);
JsBlock catchBlock = new JsBlock();
jsCatch.setBody(catchBlock);
JsInvocation errCall = new JsInvocation();
catchBlock.getStatements().add(errCall.makeStmt());
errCall.setQualifier(errFn.makeRef());
errCall.getArguments().add(modName.makeRef());
}