| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart2js.js_emitter.full_emitter; | 5 library dart2js.js_emitter.full_emitter; |
| 6 | 6 |
| 7 import 'dart:collection' show HashMap; | 7 import 'dart:collection' show HashMap; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 jsAst.Expression generateFunctionThatReturnsNull() { | 790 jsAst.Expression generateFunctionThatReturnsNull() { |
| 791 return js("#.#", | 791 return js("#.#", |
| 792 [namer.isolateName, backend.rtiEncoder.getFunctionThatReturnsNullName]); | 792 [namer.isolateName, backend.rtiEncoder.getFunctionThatReturnsNullName]); |
| 793 } | 793 } |
| 794 | 794 |
| 795 buildMain(jsAst.Statement invokeMain) { | 795 buildMain(jsAst.Statement invokeMain) { |
| 796 if (compiler.isMockCompilation) return js.comment("Mock compilation"); | 796 if (compiler.isMockCompilation) return js.comment("Mock compilation"); |
| 797 | 797 |
| 798 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 798 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
| 799 | 799 |
| 800 if (NativeGenerator.needsIsolateAffinityTagInitialization(backend)) { | 800 if (NativeGenerator |
| 801 .needsIsolateAffinityTagInitialization(_closedWorld.backendUsage)) { |
| 801 parts.add(NativeGenerator.generateIsolateAffinityTagInitialization( | 802 parts.add(NativeGenerator.generateIsolateAffinityTagInitialization( |
| 802 backend, | 803 _closedWorld.backendUsage, |
| 803 generateEmbeddedGlobalAccess, | 804 generateEmbeddedGlobalAccess, |
| 804 js( | 805 js( |
| 805 """ | 806 """ |
| 806 // On V8, the 'intern' function converts a string to a symbol, which | 807 // On V8, the 'intern' function converts a string to a symbol, which |
| 807 // makes property access much faster. | 808 // makes property access much faster. |
| 808 function (s) { | 809 function (s) { |
| 809 var o = {}; | 810 var o = {}; |
| 810 o[s] = 1; | 811 o[s] = 1; |
| 811 return Object.keys(convertToFastObject(o))[0]; | 812 return Object.keys(convertToFastObject(o))[0]; |
| 812 }""", | 813 }""", |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 | 1089 |
| 1089 void assemblePrecompiledConstructor( | 1090 void assemblePrecompiledConstructor( |
| 1090 OutputUnit outputUnit, | 1091 OutputUnit outputUnit, |
| 1091 jsAst.Name constructorName, | 1092 jsAst.Name constructorName, |
| 1092 jsAst.Expression constructorAst, | 1093 jsAst.Expression constructorAst, |
| 1093 List<jsAst.Name> fields) { | 1094 List<jsAst.Name> fields) { |
| 1094 cspPrecompiledFunctionFor(outputUnit) | 1095 cspPrecompiledFunctionFor(outputUnit) |
| 1095 .add(new jsAst.FunctionDeclaration(constructorName, constructorAst)); | 1096 .add(new jsAst.FunctionDeclaration(constructorName, constructorAst)); |
| 1096 | 1097 |
| 1097 String fieldNamesProperty = FIELD_NAMES_PROPERTY_NAME; | 1098 String fieldNamesProperty = FIELD_NAMES_PROPERTY_NAME; |
| 1098 bool hasIsolateSupport = backend.backendUsage.isIsolateInUse; | 1099 bool hasIsolateSupport = _closedWorld.backendUsage.isIsolateInUse; |
| 1099 jsAst.Node fieldNamesArray; | 1100 jsAst.Node fieldNamesArray; |
| 1100 if (hasIsolateSupport) { | 1101 if (hasIsolateSupport) { |
| 1101 fieldNamesArray = | 1102 fieldNamesArray = |
| 1102 new jsAst.ArrayInitializer(fields.map(js.quoteName).toList()); | 1103 new jsAst.ArrayInitializer(fields.map(js.quoteName).toList()); |
| 1103 } else { | 1104 } else { |
| 1104 fieldNamesArray = new jsAst.LiteralNull(); | 1105 fieldNamesArray = new jsAst.LiteralNull(); |
| 1105 } | 1106 } |
| 1106 | 1107 |
| 1107 cspPrecompiledFunctionFor(outputUnit).add(js.statement( | 1108 cspPrecompiledFunctionFor(outputUnit).add(js.statement( |
| 1108 r''' | 1109 r''' |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1488 "disableVariableRenaming": js.comment("/* ::norenaming:: */"), | 1489 "disableVariableRenaming": js.comment("/* ::norenaming:: */"), |
| 1489 "isProgramSplit": isProgramSplit, | 1490 "isProgramSplit": isProgramSplit, |
| 1490 "supportsDirectProtoAccess": buildSupportsDirectProtoAccess(), | 1491 "supportsDirectProtoAccess": buildSupportsDirectProtoAccess(), |
| 1491 "globalsHolder": globalsHolder, | 1492 "globalsHolder": globalsHolder, |
| 1492 "globalObjectSetup": buildGlobalObjectSetup(isProgramSplit), | 1493 "globalObjectSetup": buildGlobalObjectSetup(isProgramSplit), |
| 1493 "isolateName": namer.isolateName, | 1494 "isolateName": namer.isolateName, |
| 1494 "isolatePropertiesName": js(isolatePropertiesName), | 1495 "isolatePropertiesName": js(isolatePropertiesName), |
| 1495 "initName": initName, | 1496 "initName": initName, |
| 1496 "functionThatReturnsNull": buildFunctionThatReturnsNull(), | 1497 "functionThatReturnsNull": buildFunctionThatReturnsNull(), |
| 1497 "mangledNames": buildMangledNames(), | 1498 "mangledNames": buildMangledNames(), |
| 1498 "setupProgram": | 1499 "setupProgram": buildSetupProgram( |
| 1499 buildSetupProgram(program, compiler, backend, namer, this), | 1500 program, compiler, backend, namer, this, _closedWorld), |
| 1500 "setupProgramName": setupProgramName, | 1501 "setupProgramName": setupProgramName, |
| 1501 "descriptors": descriptorsAst, | 1502 "descriptors": descriptorsAst, |
| 1502 "cspPrecompiledFunctions": | 1503 "cspPrecompiledFunctions": |
| 1503 buildCspPrecompiledFunctionFor(mainOutputUnit), | 1504 buildCspPrecompiledFunctionFor(mainOutputUnit), |
| 1504 "getInterceptorMethods": | 1505 "getInterceptorMethods": |
| 1505 interceptorEmitter.buildGetInterceptorMethods(), | 1506 interceptorEmitter.buildGetInterceptorMethods(), |
| 1506 "oneShotInterceptors": interceptorEmitter.buildOneShotInterceptors(), | 1507 "oneShotInterceptors": interceptorEmitter.buildOneShotInterceptors(), |
| 1507 "makeConstantList": | 1508 "makeConstantList": |
| 1508 buildMakeConstantList(program.outputContainsConstantList), | 1509 buildMakeConstantList(program.outputContainsConstantList), |
| 1509 "compileTimeConstants": buildCompileTimeConstants( | 1510 "compileTimeConstants": buildCompileTimeConstants( |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 // boilerplate JS code, like the sourcemap directives or the hash | 1641 // boilerplate JS code, like the sourcemap directives or the hash |
| 1641 // itself. | 1642 // itself. |
| 1642 Map<OutputUnit, String> deferredLoadHashes = | 1643 Map<OutputUnit, String> deferredLoadHashes = |
| 1643 emitDeferredOutputUnits(deferredParts); | 1644 emitDeferredOutputUnits(deferredParts); |
| 1644 | 1645 |
| 1645 deferredHashTokens.forEach((OutputUnit key, _DeferredOutputUnitHash token) { | 1646 deferredHashTokens.forEach((OutputUnit key, _DeferredOutputUnitHash token) { |
| 1646 token.setHash(deferredLoadHashes[key]); | 1647 token.setHash(deferredLoadHashes[key]); |
| 1647 }); | 1648 }); |
| 1648 emitMainOutputUnit(program.mainFragment.outputUnit, mainOutput); | 1649 emitMainOutputUnit(program.mainFragment.outputUnit, mainOutput); |
| 1649 | 1650 |
| 1650 if (backend.backendUsage.requiresPreamble && !backend.htmlLibraryIsLoaded) { | 1651 if (_closedWorld.backendUsage.requiresPreamble && |
| 1652 !backend.htmlLibraryIsLoaded) { |
| 1651 reporter.reportHintMessage(NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE); | 1653 reporter.reportHintMessage(NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE); |
| 1652 } | 1654 } |
| 1653 // Return the total program size. | 1655 // Return the total program size. |
| 1654 return outputBuffers.values.fold(0, (a, b) => a + b.length); | 1656 return outputBuffers.values.fold(0, (a, b) => a + b.length); |
| 1655 } | 1657 } |
| 1656 | 1658 |
| 1657 ClassBuilder getStaticMethodDescriptor( | 1659 ClassBuilder getStaticMethodDescriptor( |
| 1658 MethodElement element, Fragment fragment) { | 1660 MethodElement element, Fragment fragment) { |
| 1659 Element owner = element.library; | 1661 Element owner = element.library; |
| 1660 if (!_nativeData.isNativeMember(element)) { | 1662 if (!_nativeData.isNativeMember(element)) { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1937 // data. | 1939 // data. |
| 1938 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 1940 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
| 1939 "needed for a given deferred library import."; | 1941 "needed for a given deferred library import."; |
| 1940 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 1942 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
| 1941 compiler.outputProvider( | 1943 compiler.outputProvider( |
| 1942 compiler.options.deferredMapUri.path, '', OutputType.info) | 1944 compiler.options.deferredMapUri.path, '', OutputType.info) |
| 1943 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 1945 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
| 1944 ..close(); | 1946 ..close(); |
| 1945 } | 1947 } |
| 1946 } | 1948 } |
| OLD | NEW |