Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
| index 8b77244cc1358891077732bbda6a8905614a9800..ffb3b5043cd9b4139b4604fa8286fc93f64d826b 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
| @@ -87,9 +87,11 @@ class CodeEmitterTask extends CompilerTask { |
| * negatively. So dart2js will emit these functions to a separate file that |
| * can be optionally included to support CSP mode or for faster startup. |
| */ |
| - List<jsAst.Node> precompiledFunction = <jsAst.Node>[]; |
| + Map<OutputUnit, List<jsAst.Node>> _precompiledFunctions = |
| + new Map<OutputUnit, List<jsAst.Node>>(); |
| - List<jsAst.Expression> precompiledConstructorNames = <jsAst.Expression>[]; |
| + Map<OutputUnit, List<jsAst.Expression>> _precompiledConstructorNames = |
| + new Map<OutputUnit, List<jsAst.Expression>>(); |
| // True if Isolate.makeConstantList is needed. |
| bool hasMakeConstantList = false; |
| @@ -129,6 +131,16 @@ class CodeEmitterTask extends CompilerTask { |
| templateManager.clear(); |
| } |
| + List<jsAst.Node> precompiledFunction(OutputUnit outputUnit) { |
|
floitsch
2014/09/12 17:00:18
precompiledFunctionsFor
sigurdm
2014/09/15 13:10:48
Done.
|
| + return _precompiledFunctions |
| + .putIfAbsent(outputUnit, () => new List<jsAst.Node>()); |
| + } |
| + |
| + List<jsAst.Expression> precompiledConstructorNames(OutputUnit outputUnit) { |
|
floitsch
2014/09/12 17:00:17
precompiledConstructorNamesFor
sigurdm
2014/09/15 13:10:48
Done.
|
| + return _precompiledConstructorNames |
| + .putIfAbsent(outputUnit, () => new List<jsAst.Expression>()); |
| + } |
| + |
| void addComment(String comment, CodeBuffer buffer) { |
| buffer.write(jsAst.prettyPrint(js.comment(comment), compiler)); |
| } |
| @@ -823,7 +835,7 @@ class CodeEmitterTask extends CompilerTask { |
| return ':$names'; |
| } |
| - jsAst.FunctionDeclaration buildPrecompiledFunction() { |
| + jsAst.FunctionDeclaration buildPrecompiledFunction(OutputUnit outputUnit) { |
| // TODO(ahe): Compute a hash code. |
| return js.statement(''' |
| function dart_precompiled(\$collectedClasses) { |
| @@ -831,8 +843,9 @@ class CodeEmitterTask extends CompilerTask { |
| #; |
| return #; |
| }''', [ |
| - precompiledFunction, |
| - new jsAst.ArrayInitializer.from(precompiledConstructorNames)]); |
| + precompiledFunction(outputUnit), |
| + new jsAst.ArrayInitializer.from( |
| + precompiledConstructorNames(outputUnit))]); |
| } |
| void generateClass(ClassElement classElement, ClassBuilder properties) { |
| @@ -1433,13 +1446,14 @@ class CodeEmitterTask extends CompilerTask { |
| } |
| } |
| - void emitPrecompiledConstructor(String constructorName, |
| + void emitPrecompiledConstructor(OutputUnit outputUnit, |
| + String constructorName, |
| jsAst.Expression constructorAst) { |
| - precompiledFunction.add( |
| + precompiledFunction(outputUnit).add( |
| new jsAst.FunctionDeclaration( |
| new jsAst.VariableDeclaration(constructorName), constructorAst)); |
| - precompiledFunction.add( |
| - js.statement(r'''{ |
| + precompiledFunction(outputUnit).add( |
| + js.statement(r'''{ |
| #.builtin$cls = #; |
| if (!"name" in #) |
| #.name = #; |
| @@ -1454,7 +1468,7 @@ class CodeEmitterTask extends CompilerTask { |
| constructorName |
| ])); |
| - precompiledConstructorNames.add(js('#', constructorName)); |
| + precompiledConstructorNames(outputUnit).add(js('#', constructorName)); |
| } |
| void assembleProgram() { |
| @@ -1621,7 +1635,9 @@ class CodeEmitterTask extends CompilerTask { |
| // Also emit a trivial constructor for CSP mode. |
| String constructorName = mangledName; |
| jsAst.Expression constructorAst = js('function() {}'); |
| - emitPrecompiledConstructor(constructorName, constructorAst); |
| + emitPrecompiledConstructor(mainOutputUnit, |
| + constructorName, |
| + constructorAst); |
| } |
| if (!mangledFieldNames.isEmpty) { |
| @@ -1790,7 +1806,7 @@ class CodeEmitterTask extends CompilerTask { |
| } |
| jsAst.FunctionDeclaration precompiledFunctionAst = |
| - buildPrecompiledFunction(); |
| + buildPrecompiledFunction(mainOutputUnit); |
| emitInitFunction(mainBuffer); |
| emitMain(mainBuffer); |
| mainBuffer.add('})()\n'); |
| @@ -2029,11 +2045,24 @@ class CodeEmitterTask extends CompilerTask { |
| // variable. |
| String hash = hashOfString(code); |
|
floitsch
2014/09/12 17:00:17
Can't you do the hash after the cspcode?
sigurdm
2014/09/15 13:10:48
My thinking was that the csp-code follows determin
|
| + CodeBuffer cspCode = new CodeBuffer(); |
| + if (compiler.useContentSecurityPolicy) { |
| + jsAst.FunctionDeclaration precompiledFunctionAst = |
| + buildPrecompiledFunction(outputUnit); |
| + |
| + cspCode.write( |
| + jsAst.prettyPrint( |
| + precompiledFunctionAst, compiler, |
| + monitor: compiler.dumpInfoTask, |
| + allowVariableMinification: false).getText()); |
| + } |
| + |
| outputBuffers[outputUnit] = outputBuffer; |
| compiler.outputProvider(outputUnit.partFileName(compiler), 'part.js') |
| ..add(code) |
| ..add('${deferredInitializers}["$hash"]$_=$_' |
| - '${deferredInitializers}.current') |
| + '${deferredInitializers}.current$N') |
| + ..add(cspCode.getText()) |
| ..close(); |
| hunkHashes[outputUnit] = hash; |