Chromium Code Reviews| Index: compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java |
| =================================================================== |
| --- compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java (revision 480) |
| +++ compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java (working copy) |
| @@ -106,7 +106,6 @@ |
| import com.google.dart.compiler.backend.js.ast.JsIf; |
| import com.google.dart.compiler.backend.js.ast.JsInvocation; |
| import com.google.dart.compiler.backend.js.ast.JsLabel; |
| -import com.google.dart.compiler.backend.js.ast.JsLiteral; |
| import com.google.dart.compiler.backend.js.ast.JsName; |
| import com.google.dart.compiler.backend.js.ast.JsNameRef; |
| import com.google.dart.compiler.backend.js.ast.JsNew; |
| @@ -228,6 +227,7 @@ |
| private static final String STATIC_UNINITIALIZED = "static$uninitialized"; |
| private static final String STATIC_INITIALIZING = "static$initializing"; |
| + private static final String ISOLATE_PROTO = "isolate$Isolate.prototype"; |
| private static final String ISOLATE_CURRENT = "isolate$current"; |
| private static final String ISOLATE_INITS = "isolate$inits"; |
| private static final String ISOLATE_DEFAULT_FACTORY = "default$factory"; |
| @@ -287,19 +287,7 @@ |
| */ |
| public void addStaticInitsToBlock(JsBlock block) { |
| if (staticInit.isEmpty()) return; |
| - JsFunction init = new JsFunction(globalScope); |
| - JsBlock body = new JsBlock(); |
| - body.getStatements().addAll(staticInit); |
| - init.setBody(body); |
| - staticInit.clear(); |
| - |
| - // All the static variable initialization code belonging to the |
| - // current compilation unit is appended to the initialization |
| - // list (isolate$inits) through Array.prototype.push. |
| - JsNameRef pushRef = AstUtil.newNameRef(new JsNameRef(ISOLATE_INITS), "push"); |
| - JsInvocation invokePush = AstUtil.newInvocation(pushRef); |
| - invokePush.getArguments().add(init); |
| - block.getStatements().add(new JsExprStmt(invokePush)); |
| + block.getStatements().addAll(staticInit); |
| } |
| /** |
| @@ -1587,12 +1575,17 @@ |
| inFactoryOrStaticContext = true; |
| // There's an initializer, so emit an assignment statement. |
| + boolean defer; |
| JsNameRef fieldName; |
| if (isDeclaredAsStaticOrImplicitlyStatic(element)) { |
| - JsExpression qualifier = getGetterSetterQualifier(element); |
| + defer = true; |
| + JsExpression qualifier = AstUtil.newQualifiedNameRef(ISOLATE_PROTO); |
| fieldName = AstUtil.newNameRef(qualifier, translationContext.getNames().getName(element)); |
| } else { |
| - fieldName = AstUtil.newNameRef(new JsThisRef(), getJsName(element)); |
|
floitsch
2011/10/21 22:57:53
was this correct?
|
| + // These values go on the prototype |
| + defer = false; |
| + JsExpression qualifier = AstUtil.newNameRef(getJsName(element.getEnclosingElement()).makeRef(), "prototype"); |
|
floitsch
2011/10/21 22:57:53
100 chars
|
| + fieldName = AstUtil.newNameRef(qualifier, getJsName(element)); |
|
floitsch
2011/10/21 22:57:53
Afaics fieldName is only used if defer == true, wh
|
| } |
| JsExpression initExpr; |
| @@ -1607,14 +1600,14 @@ |
| (initializer == null || initExpr instanceof JsValueLiteral)) { |
| makeConstantValueGetter(element, initExpr); |
| emitStaticInitialization = false; |
| - } else if (initializer == null || initExpr instanceof JsLiteral) { |
| + } else if (initializer == null || initExpr instanceof JsValueLiteral) { |
| makePropertyGetter(element); |
| } else { |
| makeInitializingGetter(element, initExpr); |
| initExpr = new JsNameRef(STATIC_UNINITIALIZED); |
| } |
| - if (emitStaticInitialization) { |
| + if (emitStaticInitialization && defer == true) { |
| JsBinaryOperation assignment = AstUtil.newAssignment(fieldName, initExpr); |
| assignment.setSourceRef(x); |
| result = new JsExprStmt(assignment); |