| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Generates the code for all used classes in the program. Static fields (even | 8 * Generates the code for all used classes in the program. Static fields (even |
| 9 * in classes) are ignored, since they can be treated as non-class elements. | 9 * in classes) are ignored, since they can be treated as non-class elements. |
| 10 * | 10 * |
| (...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 | 1523 |
| 1524 emitMain(mainBuffer); | 1524 emitMain(mainBuffer); |
| 1525 jsAst.FunctionDeclaration precompiledFunctionAst = | 1525 jsAst.FunctionDeclaration precompiledFunctionAst = |
| 1526 buildPrecompiledFunction(); | 1526 buildPrecompiledFunction(); |
| 1527 emitInitFunction(mainBuffer); | 1527 emitInitFunction(mainBuffer); |
| 1528 if (!compiler.deferredLoadTask.splitProgram) { | 1528 if (!compiler.deferredLoadTask.splitProgram) { |
| 1529 mainBuffer.add('})()\n'); | 1529 mainBuffer.add('})()\n'); |
| 1530 } else { | 1530 } else { |
| 1531 mainBuffer.add('\n'); | 1531 mainBuffer.add('\n'); |
| 1532 } | 1532 } |
| 1533 |
| 1534 if (compiler.useContentSecurityPolicy) { |
| 1535 mainBuffer.write( |
| 1536 jsAst.prettyPrint( |
| 1537 precompiledFunctionAst, compiler, |
| 1538 allowVariableMinification: false).getText()); |
| 1539 } |
| 1540 |
| 1533 String assembledCode = mainBuffer.getText(); | 1541 String assembledCode = mainBuffer.getText(); |
| 1534 String sourceMapTags = ""; | 1542 String sourceMapTags = ""; |
| 1535 if (generateSourceMap) { | 1543 if (generateSourceMap) { |
| 1536 outputSourceMap(assembledCode, mainBuffer, '', | 1544 outputSourceMap(assembledCode, mainBuffer, '', |
| 1537 compiler.sourceMapUri, compiler.outputUri); | 1545 compiler.sourceMapUri, compiler.outputUri); |
| 1538 sourceMapTags = | 1546 sourceMapTags = |
| 1539 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri); | 1547 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri); |
| 1540 } | 1548 } |
| 1541 compiler.outputProvider('', 'js') | 1549 compiler.outputProvider('', 'js') |
| 1542 ..add(assembledCode) | 1550 ..add(assembledCode) |
| 1543 ..add(sourceMapTags) | 1551 ..add(sourceMapTags) |
| 1544 ..close(); | 1552 ..close(); |
| 1545 compiler.assembledCode = assembledCode; | 1553 compiler.assembledCode = assembledCode; |
| 1546 | 1554 |
| 1547 mainBuffer.write( | 1555 if (!compiler.useContentSecurityPolicy) { |
| 1548 jsAst.prettyPrint( | 1556 mainBuffer.write(""" |
| 1549 precompiledFunctionAst, compiler, | 1557 { |
| 1550 allowVariableMinification: false).getText()); | 1558 var message = |
| 1559 'Deprecation: Automatic generation of output for Content Security\\n' + |
| 1560 'Policy is deprecated and will be removed with the next development\\n' + |
| 1561 'release. Use the --csp option to generate CSP restricted output.'; |
| 1562 if (typeof dartPrint == "function") { |
| 1563 dartPrint(message); |
| 1564 } else if (typeof console == "object" && typeof console.log == "function") { |
| 1565 console.log(message); |
| 1566 } else if (typeof print == "function") { |
| 1567 print(message); |
| 1568 } |
| 1569 }\n"""); |
| 1551 | 1570 |
| 1552 compiler.outputProvider('', 'precompiled.js') | 1571 mainBuffer.write( |
| 1553 ..add(mainBuffer.getText()) | 1572 jsAst.prettyPrint( |
| 1554 ..close(); | 1573 precompiledFunctionAst, compiler, |
| 1574 allowVariableMinification: false).getText()); |
| 1555 | 1575 |
| 1576 compiler.outputProvider('', 'precompiled.js') |
| 1577 ..add(mainBuffer.getText()) |
| 1578 ..close(); |
| 1579 } |
| 1556 emitDeferredCode(); | 1580 emitDeferredCode(); |
| 1557 | 1581 |
| 1558 }); | 1582 }); |
| 1559 return compiler.assembledCode; | 1583 return compiler.assembledCode; |
| 1560 } | 1584 } |
| 1561 | 1585 |
| 1562 String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) { | 1586 String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) { |
| 1563 if (sourceMapUri != null && fileUri != null) { | 1587 if (sourceMapUri != null && fileUri != null) { |
| 1564 // Using # is the new proposed standard. @ caused problems in Internet | 1588 // Using # is the new proposed standard. @ caused problems in Internet |
| 1565 // Explorer due to "Conditional Compilation Statements" in JScript, | 1589 // Explorer due to "Conditional Compilation Statements" in JScript, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 String sourceMap = sourceMapBuilder.build(compiledFile); | 1701 String sourceMap = sourceMapBuilder.build(compiledFile); |
| 1678 compiler.outputProvider(name, 'js.map') | 1702 compiler.outputProvider(name, 'js.map') |
| 1679 ..add(sourceMap) | 1703 ..add(sourceMap) |
| 1680 ..close(); | 1704 ..close(); |
| 1681 } | 1705 } |
| 1682 | 1706 |
| 1683 void registerReadTypeVariable(TypeVariableElement element) { | 1707 void registerReadTypeVariable(TypeVariableElement element) { |
| 1684 readTypeVariables.add(element); | 1708 readTypeVariables.add(element); |
| 1685 } | 1709 } |
| 1686 } | 1710 } |
| OLD | NEW |