| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.full_emitter; | 5 part of dart2js.js_emitter.full_emitter; |
| 6 | 6 |
| 7 // TODO(ahe): Share these with js_helper.dart. | 7 // TODO(ahe): Share these with js_helper.dart. |
| 8 const FUNCTION_INDEX = 0; | 8 const FUNCTION_INDEX = 0; |
| 9 const NAME_INDEX = 1; | 9 const NAME_INDEX = 1; |
| 10 const CALL_NAME_INDEX = 2; | 10 const CALL_NAME_INDEX = 2; |
| 11 const REQUIRED_PARAMETER_INDEX = 3; | 11 const REQUIRED_PARAMETER_INDEX = 3; |
| 12 const OPTIONAL_PARAMETER_INDEX = 4; | 12 const OPTIONAL_PARAMETER_INDEX = 4; |
| 13 const DEFAULT_ARGUMENTS_INDEX = 5; | 13 const DEFAULT_ARGUMENTS_INDEX = 5; |
| 14 | 14 |
| 15 const bool VALIDATE_DATA = false; | 15 const bool VALIDATE_DATA = false; |
| 16 | 16 |
| 17 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; | 17 const RANGE1_SIZE = RANGE1_LAST - RANGE1_FIRST + 1; |
| 18 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; | 18 const RANGE2_SIZE = RANGE2_LAST - RANGE2_FIRST + 1; |
| 19 const RANGE1_ADJUST = -(FIRST_FIELD_CODE - RANGE1_FIRST); | 19 const RANGE1_ADJUST = -(FIRST_FIELD_CODE - RANGE1_FIRST); |
| 20 const RANGE2_ADJUST = -(FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); | 20 const RANGE2_ADJUST = -(FIRST_FIELD_CODE + RANGE1_SIZE - RANGE2_FIRST); |
| 21 const RANGE3_ADJUST = | 21 const RANGE3_ADJUST = |
| 22 -(FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); | 22 -(FIRST_FIELD_CODE + RANGE1_SIZE + RANGE2_SIZE - RANGE3_FIRST); |
| 23 | 23 |
| 24 const String setupProgramName = 'setupProgram'; | 24 const String setupProgramName = 'setupProgram'; |
| 25 // TODO(floitsch): make sure this property can't clash with anything. It's | 25 // TODO(floitsch): make sure this property can't clash with anything. It's |
| 26 // unlikely since it lives on types, but still. | 26 // unlikely since it lives on types, but still. |
| 27 const String typeNameProperty = r'builtin$cls'; | 27 const String typeNameProperty = r'builtin$cls'; |
| 28 | 28 |
| 29 jsAst.Statement buildSetupProgram(Program program, Compiler compiler, | 29 jsAst.Statement buildSetupProgram( |
| 30 JavaScriptBackend backend, Namer namer, Emitter emitter) { | 30 Program program, |
| 31 Compiler compiler, |
| 32 JavaScriptBackend backend, |
| 33 Namer namer, |
| 34 Emitter emitter, |
| 35 ClosedWorld closedWorld) { |
| 31 jsAst.Expression typeInformationAccess = | 36 jsAst.Expression typeInformationAccess = |
| 32 emitter.generateEmbeddedGlobalAccess(embeddedNames.TYPE_INFORMATION); | 37 emitter.generateEmbeddedGlobalAccess(embeddedNames.TYPE_INFORMATION); |
| 33 jsAst.Expression globalFunctionsAccess = | 38 jsAst.Expression globalFunctionsAccess = |
| 34 emitter.generateEmbeddedGlobalAccess(embeddedNames.GLOBAL_FUNCTIONS); | 39 emitter.generateEmbeddedGlobalAccess(embeddedNames.GLOBAL_FUNCTIONS); |
| 35 jsAst.Expression staticsAccess = | 40 jsAst.Expression staticsAccess = |
| 36 emitter.generateEmbeddedGlobalAccess(embeddedNames.STATICS); | 41 emitter.generateEmbeddedGlobalAccess(embeddedNames.STATICS); |
| 37 jsAst.Expression interceptedNamesAccess = | 42 jsAst.Expression interceptedNamesAccess = |
| 38 emitter.generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTED_NAMES); | 43 emitter.generateEmbeddedGlobalAccess(embeddedNames.INTERCEPTED_NAMES); |
| 39 jsAst.Expression mangledGlobalNamesAccess = | 44 jsAst.Expression mangledGlobalNamesAccess = |
| 40 emitter.generateEmbeddedGlobalAccess(embeddedNames.MANGLED_GLOBAL_NAMES); | 45 emitter.generateEmbeddedGlobalAccess(embeddedNames.MANGLED_GLOBAL_NAMES); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 Map<String, dynamic> holes = { | 101 Map<String, dynamic> holes = { |
| 97 'needsClassSupport': emitter.needsClassSupport, | 102 'needsClassSupport': emitter.needsClassSupport, |
| 98 'libraries': librariesAccess, | 103 'libraries': librariesAccess, |
| 99 'mangledNames': mangledNamesAccess, | 104 'mangledNames': mangledNamesAccess, |
| 100 'mangledGlobalNames': mangledGlobalNamesAccess, | 105 'mangledGlobalNames': mangledGlobalNamesAccess, |
| 101 'statics': staticsAccess, | 106 'statics': staticsAccess, |
| 102 'staticsPropertyName': namer.staticsPropertyName, | 107 'staticsPropertyName': namer.staticsPropertyName, |
| 103 'staticsPropertyNameString': js.quoteName(namer.staticsPropertyName), | 108 'staticsPropertyNameString': js.quoteName(namer.staticsPropertyName), |
| 104 'typeInformation': typeInformationAccess, | 109 'typeInformation': typeInformationAccess, |
| 105 'globalFunctions': globalFunctionsAccess, | 110 'globalFunctions': globalFunctionsAccess, |
| 106 'enabledInvokeOn': backend.backendUsage.isInvokeOnUsed, | 111 'enabledInvokeOn': closedWorld.backendUsage.isInvokeOnUsed, |
| 107 'interceptedNames': interceptedNamesAccess, | 112 'interceptedNames': interceptedNamesAccess, |
| 108 'interceptedNamesSet': emitter.generateInterceptedNamesSet(), | 113 'interceptedNamesSet': emitter.generateInterceptedNamesSet(), |
| 109 'notInCspMode': !compiler.options.useContentSecurityPolicy, | 114 'notInCspMode': !compiler.options.useContentSecurityPolicy, |
| 110 'inCspMode': compiler.options.useContentSecurityPolicy, | 115 'inCspMode': compiler.options.useContentSecurityPolicy, |
| 111 'deferredAction': namer.deferredAction, | 116 'deferredAction': namer.deferredAction, |
| 112 'hasIsolateSupport': program.hasIsolateSupport, | 117 'hasIsolateSupport': program.hasIsolateSupport, |
| 113 'fieldNamesProperty': js.string(Emitter.FIELD_NAMES_PROPERTY_NAME), | 118 'fieldNamesProperty': js.string(Emitter.FIELD_NAMES_PROPERTY_NAME), |
| 114 'createNewIsolateFunction': createNewIsolateFunctionAccess, | 119 'createNewIsolateFunction': createNewIsolateFunctionAccess, |
| 115 'isolateName': namer.isolateName, | 120 'isolateName': namer.isolateName, |
| 116 'classIdExtractor': classIdExtractorAccess, | 121 'classIdExtractor': classIdExtractorAccess, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 131 'isObject': namer.operatorIs(compiler.commonElements.objectClass), | 136 'isObject': namer.operatorIs(compiler.commonElements.objectClass), |
| 132 'specProperty': js.string(namer.nativeSpecProperty), | 137 'specProperty': js.string(namer.nativeSpecProperty), |
| 133 'trivialNsmHandlers': emitter.buildTrivialNsmHandlers(), | 138 'trivialNsmHandlers': emitter.buildTrivialNsmHandlers(), |
| 134 'hasRetainedMetadata': backend.mirrorsData.hasRetainedMetadata, | 139 'hasRetainedMetadata': backend.mirrorsData.hasRetainedMetadata, |
| 135 'types': typesAccess, | 140 'types': typesAccess, |
| 136 'objectClassName': js.quoteName(namer.runtimeTypeName( | 141 'objectClassName': js.quoteName(namer.runtimeTypeName( |
| 137 // ignore: UNNECESSARY_CAST | 142 // ignore: UNNECESSARY_CAST |
| 138 compiler.commonElements.objectClass as Entity)), | 143 compiler.commonElements.objectClass as Entity)), |
| 139 'needsStructuredMemberInfo': emitter.needsStructuredMemberInfo, | 144 'needsStructuredMemberInfo': emitter.needsStructuredMemberInfo, |
| 140 'usesMangledNames': compiler.commonElements.mirrorsLibrary != null || | 145 'usesMangledNames': compiler.commonElements.mirrorsLibrary != null || |
| 141 backend.backendUsage.isFunctionApplyUsed, | 146 closedWorld.backendUsage.isFunctionApplyUsed, |
| 142 'tearOffCode': buildTearOffCode(compiler.options, backend.emitter.emitter, | 147 'tearOffCode': buildTearOffCode( |
| 143 backend.namer, compiler.commonElements), | 148 compiler.options, emitter, namer, compiler.commonElements), |
| 144 'nativeInfoHandler': nativeInfoHandler, | 149 'nativeInfoHandler': nativeInfoHandler, |
| 145 'operatorIsPrefix': js.string(namer.operatorIsPrefix), | 150 'operatorIsPrefix': js.string(namer.operatorIsPrefix), |
| 146 'deferredActionString': js.string(namer.deferredAction) | 151 'deferredActionString': js.string(namer.deferredAction) |
| 147 }; | 152 }; |
| 148 String skeleton = ''' | 153 String skeleton = ''' |
| 149 function $setupProgramName(programData, typesOffset) { | 154 function $setupProgramName(programData, typesOffset) { |
| 150 "use strict"; | 155 "use strict"; |
| 151 if (#needsClassSupport) { | 156 if (#needsClassSupport) { |
| 152 | 157 |
| 153 function generateAccessor(fieldDescriptor, accessors, cls) { | 158 function generateAccessor(fieldDescriptor, accessors, cls) { |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 (function() { | 849 (function() { |
| 845 var result = $array[$index]; | 850 var result = $array[$index]; |
| 846 if ($check) { | 851 if ($check) { |
| 847 throw new Error( | 852 throw new Error( |
| 848 name + ": expected value of type \'$type\' at index " + ($index) + | 853 name + ": expected value of type \'$type\' at index " + ($index) + |
| 849 " but got " + (typeof result)); | 854 " but got " + (typeof result)); |
| 850 } | 855 } |
| 851 return result; | 856 return result; |
| 852 })()'''; | 857 })()'''; |
| 853 } | 858 } |
| OLD | NEW |