Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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_backend.helpers; | 5 library dart2js.js_backend.helpers; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/names.dart' show Identifiers, Uris; | 8 import '../common/names.dart' show Identifiers, Uris; |
| 9 import '../common/resolution.dart' show Resolution; | |
| 10 import '../compiler.dart' show Compiler; | 9 import '../compiler.dart' show Compiler; |
| 11 import '../core_types.dart' show CommonElements; | 10 import '../core_types.dart' show CommonElements, ElementEnvironment; |
| 12 import '../elements/elements.dart' | 11 import '../elements/elements.dart' show PublicName; |
| 13 show | 12 import '../elements/entities.dart'; |
| 14 AbstractFieldElement, | |
| 15 ClassElement, | |
| 16 ConstructorElement, | |
| 17 Element, | |
| 18 EnumClassElement, | |
| 19 FunctionElement, | |
| 20 LibraryElement, | |
| 21 MemberElement, | |
| 22 MethodElement, | |
| 23 Name, | |
| 24 PublicName; | |
| 25 import '../library_loader.dart' show LoadedLibraries; | 13 import '../library_loader.dart' show LoadedLibraries; |
| 26 import '../universe/call_structure.dart' show CallStructure; | 14 import '../universe/call_structure.dart' show CallStructure; |
| 27 import '../universe/selector.dart' show Selector; | 15 import '../universe/selector.dart' show Selector; |
| 28 import 'constant_system_javascript.dart'; | 16 import 'constant_system_javascript.dart'; |
| 29 import 'js_backend.dart'; | 17 import 'js_backend.dart'; |
| 30 | 18 |
| 31 /// Helper classes and functions for the JavaScript backend. | 19 /// Helper classes and functions for the JavaScript backend. |
| 32 class BackendHelpers { | 20 abstract class BackendHelpers { |
| 33 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); | 21 static final Uri DART_JS_HELPER = new Uri(scheme: 'dart', path: '_js_helper'); |
| 34 static final Uri DART_INTERCEPTORS = | 22 static final Uri DART_INTERCEPTORS = |
| 35 new Uri(scheme: 'dart', path: '_interceptors'); | 23 new Uri(scheme: 'dart', path: '_interceptors'); |
| 36 static final Uri DART_FOREIGN_HELPER = | 24 static final Uri DART_FOREIGN_HELPER = |
| 37 new Uri(scheme: 'dart', path: '_foreign_helper'); | 25 new Uri(scheme: 'dart', path: '_foreign_helper'); |
| 38 static final Uri DART_JS_MIRRORS = | 26 static final Uri DART_JS_MIRRORS = |
| 39 new Uri(scheme: 'dart', path: '_js_mirrors'); | 27 new Uri(scheme: 'dart', path: '_js_mirrors'); |
| 40 static final Uri DART_JS_NAMES = new Uri(scheme: 'dart', path: '_js_names'); | 28 static final Uri DART_JS_NAMES = new Uri(scheme: 'dart', path: '_js_names'); |
| 41 static final Uri DART_EMBEDDED_NAMES = | 29 static final Uri DART_EMBEDDED_NAMES = |
| 42 new Uri(scheme: 'dart', path: '_js_embedded_names'); | 30 new Uri(scheme: 'dart', path: '_js_embedded_names'); |
| 43 static final Uri DART_ISOLATE_HELPER = | 31 static final Uri DART_ISOLATE_HELPER = |
| 44 new Uri(scheme: 'dart', path: '_isolate_helper'); | 32 new Uri(scheme: 'dart', path: '_isolate_helper'); |
| 45 static final Uri PACKAGE_JS = new Uri(scheme: 'package', path: 'js/js.dart'); | 33 static final Uri PACKAGE_JS = new Uri(scheme: 'package', path: 'js/js.dart'); |
| 46 | 34 |
| 47 static const String INVOKE_ON = '_getCachedInvocation'; | 35 static const String INVOKE_ON = '_getCachedInvocation'; |
| 48 static const String START_ROOT_ISOLATE = 'startRootIsolate'; | 36 static const String START_ROOT_ISOLATE = 'startRootIsolate'; |
| 49 | 37 |
| 50 static const String JS = 'JS'; | 38 static const String JS = 'JS'; |
| 51 static const String JS_BUILTIN = 'JS_BUILTIN'; | 39 static const String JS_BUILTIN = 'JS_BUILTIN'; |
| 52 static const String JS_EMBEDDED_GLOBAL = 'JS_EMBEDDED_GLOBAL'; | 40 static const String JS_EMBEDDED_GLOBAL = 'JS_EMBEDDED_GLOBAL'; |
| 53 static const String JS_INTERCEPTOR_CONSTANT = 'JS_INTERCEPTOR_CONSTANT'; | 41 static const String JS_INTERCEPTOR_CONSTANT = 'JS_INTERCEPTOR_CONSTANT'; |
| 54 | 42 |
| 55 final Compiler compiler; | 43 ElementEnvironment get _env; |
| 56 | 44 |
| 57 Element cachedCheckConcurrentModificationError; | 45 // TODO(johnniwinther): Remove this. |
| 58 | 46 JavaScriptBackend get backend; |
| 59 BackendHelpers(this.compiler); | 47 |
| 60 | 48 CommonElements get commonElements; |
| 61 JavaScriptBackend get backend => compiler.backend; | 49 |
| 62 | 50 ClassEntity _findInterceptorsClass(String name) => |
| 63 Resolution get resolution => backend.resolution; | 51 _findClass(interceptorsLibrary, name); |
| 64 | 52 |
| 65 CommonElements get commonElements => compiler.commonElements; | 53 FunctionEntity _findInterceptorsFunction(String name) => |
| 66 | 54 _findLibraryMember(interceptorsLibrary, name); |
| 67 DiagnosticReporter get reporter => compiler.reporter; | 55 |
| 68 | 56 ClassEntity _findHelperClass(String name) => |
| 69 MethodElement assertTest; | 57 _findClass(jsHelperLibrary, name); |
| 70 MethodElement assertThrow; | 58 |
| 71 MethodElement assertHelper; | 59 FunctionEntity _findHelperFunction(String name) => |
| 72 | 60 _findLibraryMember(jsHelperLibrary, name); |
| 73 LibraryElement jsHelperLibrary; | 61 |
| 74 LibraryElement asyncLibrary; | 62 ClassEntity _findAsyncHelperClass(String name) => |
| 75 LibraryElement interceptorsLibrary; | 63 _findClass(asyncLibrary, name); |
| 76 LibraryElement foreignLibrary; | 64 |
| 77 LibraryElement isolateHelperLibrary; | 65 FunctionEntity _findAsyncHelperFunction(String name) => |
| 66 _findLibraryMember(asyncLibrary, name); | |
| 67 | |
| 68 FunctionEntity _findMirrorsFunction(String name) { | |
| 69 LibraryEntity library = _env.lookupLibrary(DART_JS_MIRRORS); | |
| 70 if (library == null) return null; | |
| 71 return _env.lookupLibraryMember(library, name, required: true); | |
| 72 } | |
| 73 | |
| 74 ClassEntity _findClass(LibraryEntity library, String name) { | |
| 75 return _env.lookupClass(library, name, required: true); | |
| 76 } | |
| 77 | |
| 78 MemberEntity _findClassMember(ClassEntity cls, String name) { | |
| 79 return _env.lookupClassMember(cls, name, required: true); | |
| 80 } | |
| 81 | |
| 82 MemberEntity _findLibraryMember(LibraryEntity library, String name) { | |
| 83 return _env.lookupLibraryMember(library, name, required: true); | |
| 84 } | |
| 85 | |
| 86 FunctionEntity findCoreHelper(String name) => _env | |
| 87 .lookupLibraryMember(commonElements.coreLibrary, name, required: true); | |
| 88 | |
| 89 ConstructorEntity _findConstructor(ClassEntity cls, String name) => | |
| 90 _env.lookupConstructor(cls, name, required: true); | |
| 91 | |
| 92 void onLibrariesLoaded(LoadedLibraries loadedLibraries) { | |
| 93 assert(loadedLibraries.containsLibrary(Uris.dart_core)); | |
| 94 assert(loadedLibraries.containsLibrary(DART_INTERCEPTORS)); | |
| 95 assert(loadedLibraries.containsLibrary(DART_JS_HELPER)); | |
| 96 | |
| 97 // TODO(johnniwinther): Avoid these. Currently needed to ensure resolution | |
| 98 // of the classes for various queries in native behavior computation, | |
| 99 // inference and codegen. | |
| 100 _env.getThisType(jsArrayClass); | |
| 101 _env.getThisType(jsExtendableArrayClass); | |
| 102 } | |
| 103 | |
| 104 LibraryEntity _jsHelperLibrary; | |
| 105 LibraryEntity get jsHelperLibrary => _jsHelperLibrary ??= _env.lookupLibrary(D ART_JS_HELPER); | |
| 106 | |
| 107 LibraryEntity _asyncLibrary; | |
| 108 LibraryEntity get asyncLibrary => _asyncLibrary ??= _env.lookupLibrary(Uris.da rt_async); | |
| 109 | |
| 110 LibraryEntity _interceptorsLibrary; | |
| 111 LibraryEntity get interceptorsLibrary => _interceptorsLibrary ??= _env.lookupL ibrary(DART_INTERCEPTORS); | |
| 112 | |
| 113 LibraryEntity _foreignLibrary; | |
| 114 LibraryEntity get foreignLibrary => _foreignLibrary ??= _env.lookupLibrary(DAR T_FOREIGN_HELPER); | |
| 115 | |
| 116 LibraryEntity _isolateHelperLibrary; | |
| 117 LibraryEntity get isolateHelperLibrary => _isolateHelperLibrary ??= _env.looku pLibrary(DART_ISOLATE_HELPER); | |
| 78 | 118 |
| 79 /// Reference to the internal library to lookup functions to always inline. | 119 /// Reference to the internal library to lookup functions to always inline. |
| 80 LibraryElement internalLibrary; | 120 LibraryEntity _internalLibrary; |
| 81 | 121 LibraryEntity get internalLibrary => _internalLibrary ??= _env.lookupLibrary(U ris.dart__internal); |
| 82 ClassElement closureClass; | 122 |
| 83 ClassElement boundClosureClass; | 123 FunctionEntity _assertTest; |
| 84 Element assertUnreachableMethod; | 124 FunctionEntity get assertTest => |
| 85 Element invokeOnMethod; | 125 _assertTest ??= _findHelperFunction('assertTest'); |
| 86 | 126 |
| 87 ClassElement jsInterceptorClass; | 127 FunctionEntity _assertThrow; |
| 88 ClassElement jsStringClass; | 128 FunctionEntity get assertThrow => |
| 89 ClassElement jsArrayClass; | 129 _assertThrow ??= _findHelperFunction('assertThrow'); |
| 90 ClassElement jsNumberClass; | 130 |
| 91 ClassElement jsIntClass; | 131 FunctionEntity _assertHelper; |
| 92 ClassElement jsDoubleClass; | 132 FunctionEntity get assertHelper => |
| 93 ClassElement jsNullClass; | 133 _assertHelper ??= _findHelperFunction('assertHelper'); |
| 94 ClassElement jsBoolClass; | 134 |
| 95 ClassElement jsPlainJavaScriptObjectClass; | 135 FunctionEntity _assertUnreachableMethod; |
| 96 ClassElement jsUnknownJavaScriptObjectClass; | 136 FunctionEntity get assertUnreachableMethod => |
| 97 ClassElement jsJavaScriptFunctionClass; | 137 _assertUnreachableMethod ??= _findHelperFunction('assertUnreachable'); |
| 98 ClassElement jsJavaScriptObjectClass; | 138 |
| 99 | 139 ClassEntity _closureClass; |
| 100 ClassElement jsIndexableClass; | 140 ClassEntity get closureClass => _closureClass ??= _findHelperClass('Closure'); |
| 101 ClassElement jsMutableIndexableClass; | 141 |
| 102 | 142 ClassEntity _boundClosureClass; |
| 103 ClassElement jsMutableArrayClass; | 143 ClassEntity get boundClosureClass => |
| 104 ClassElement jsFixedArrayClass; | 144 _boundClosureClass ??= _findHelperClass('BoundClosure'); |
| 105 ClassElement jsExtendableArrayClass; | 145 |
| 106 ClassElement jsUnmodifiableArrayClass; | 146 FunctionEntity _invokeOnMethod; |
| 107 ClassElement jsPositiveIntClass; | 147 FunctionEntity get invokeOnMethod => _invokeOnMethod ??= |
| 108 ClassElement jsUInt32Class; | 148 _env.lookupClassMember(jsInvocationMirrorClass, INVOKE_ON); |
| 109 ClassElement jsUInt31Class; | 149 |
| 110 | 150 ClassEntity _jsInterceptorClass; |
| 111 MemberElement jsIndexableLength; | 151 ClassEntity get jsInterceptorClass => |
| 112 Element jsArrayTypedConstructor; | 152 _jsInterceptorClass ??= _findInterceptorsClass('Interceptor'); |
| 113 MethodElement jsArrayRemoveLast; | 153 |
| 114 MethodElement jsArrayAdd; | 154 ClassEntity _jsStringClass; |
| 115 MethodElement jsStringSplit; | 155 ClassEntity get jsStringClass => |
| 116 MethodElement jsStringToString; | 156 _jsStringClass ??= _findInterceptorsClass('JSString'); |
| 117 MethodElement jsStringOperatorAdd; | 157 |
| 118 MethodElement objectEquals; | 158 ClassEntity _jsArrayClass; |
| 119 | 159 ClassEntity get jsArrayClass => |
| 120 ClassElement typeLiteralClass; | 160 _jsArrayClass ??= _findInterceptorsClass('JSArray'); |
| 121 ClassElement mapLiteralClass; | 161 |
| 122 ClassElement constMapLiteralClass; | 162 ClassEntity _jsNumberClass; |
| 123 ClassElement typeVariableClass; | 163 ClassEntity get jsNumberClass => |
| 124 | 164 _jsNumberClass ??= _findInterceptorsClass('JSNumber'); |
| 125 ClassElement noSideEffectsClass; | 165 |
| 126 ClassElement noThrowsClass; | 166 ClassEntity _jsIntClass; |
| 127 ClassElement noInlineClass; | 167 ClassEntity get jsIntClass => _jsIntClass ??= _findInterceptorsClass('JSInt'); |
| 128 ClassElement forceInlineClass; | 168 |
| 129 ClassElement irRepresentationClass; | 169 ClassEntity _jsDoubleClass; |
| 130 | 170 ClassEntity get jsDoubleClass => |
| 131 ClassElement jsAnnotationClass; | 171 _jsDoubleClass ??= _findInterceptorsClass('JSDouble'); |
| 132 ClassElement jsAnonymousClass; | 172 |
| 133 | 173 ClassEntity _jsNullClass; |
| 134 Element getInterceptorMethod; | 174 ClassEntity get jsNullClass => |
| 135 | 175 _jsNullClass ??= _findInterceptorsClass('JSNull'); |
| 136 ClassElement jsInvocationMirrorClass; | 176 |
| 137 | 177 ClassEntity _jsBoolClass; |
| 138 ClassElement typedArrayClass; | 178 ClassEntity get jsBoolClass => |
| 139 ClassElement typedArrayOfIntClass; | 179 _jsBoolClass ??= _findInterceptorsClass('JSBool'); |
| 180 | |
| 181 ClassEntity _jsPlainJavaScriptObjectClass; | |
| 182 ClassEntity get jsPlainJavaScriptObjectClass => | |
| 183 _jsPlainJavaScriptObjectClass ??= | |
| 184 _findInterceptorsClass('PlainJavaScriptObject'); | |
| 185 | |
| 186 ClassEntity _jsUnknownJavaScriptObjectClass; | |
| 187 ClassEntity get jsUnknownJavaScriptObjectClass => | |
| 188 _jsUnknownJavaScriptObjectClass ??= | |
| 189 _findInterceptorsClass('UnknownJavaScriptObject'); | |
| 190 | |
| 191 ClassEntity _jsJavaScriptFunctionClass; | |
| 192 ClassEntity get jsJavaScriptFunctionClass => _jsJavaScriptFunctionClass ??= | |
| 193 _findInterceptorsClass('JavaScriptFunction'); | |
| 194 | |
| 195 ClassEntity _jsJavaScriptObjectClass; | |
| 196 ClassEntity get jsJavaScriptObjectClass => | |
| 197 _jsJavaScriptObjectClass ??= _findInterceptorsClass('JavaScriptObject'); | |
| 198 | |
| 199 ClassEntity _jsIndexableClass; | |
| 200 ClassEntity get jsIndexableClass => | |
| 201 _jsIndexableClass ??= _findInterceptorsClass('JSIndexable'); | |
| 202 | |
| 203 ClassEntity _jsMutableIndexableClass; | |
| 204 ClassEntity get jsMutableIndexableClass => | |
| 205 _jsMutableIndexableClass ??= _findInterceptorsClass('JSMutableIndexable'); | |
| 206 | |
| 207 ClassEntity _jsMutableArrayClass; | |
| 208 ClassEntity get jsMutableArrayClass => | |
| 209 _jsMutableArrayClass ??= _findInterceptorsClass('JSMutableArray'); | |
| 210 | |
| 211 ClassEntity _jsFixedArrayClass; | |
| 212 ClassEntity get jsFixedArrayClass => | |
| 213 _jsFixedArrayClass ??= _findInterceptorsClass('JSFixedArray'); | |
| 214 | |
| 215 ClassEntity _jsExtendableArrayClass; | |
| 216 ClassEntity get jsExtendableArrayClass => | |
| 217 _jsExtendableArrayClass ??= _findInterceptorsClass('JSExtendableArray'); | |
| 218 | |
| 219 ClassEntity _jsUnmodifiableArrayClass; | |
| 220 ClassEntity get jsUnmodifiableArrayClass => _jsUnmodifiableArrayClass ??= | |
| 221 _findInterceptorsClass('JSUnmodifiableArray'); | |
| 222 | |
| 223 ClassEntity _jsPositiveIntClass; | |
| 224 ClassEntity get jsPositiveIntClass => | |
| 225 _jsPositiveIntClass ??= _findInterceptorsClass('JSPositiveInt'); | |
| 226 | |
| 227 ClassEntity _jsUInt32Class; | |
| 228 ClassEntity get jsUInt32Class => | |
| 229 _jsUInt32Class ??= _findInterceptorsClass('JSUInt32'); | |
| 230 | |
| 231 ClassEntity _jsUInt31Class; | |
| 232 ClassEntity get jsUInt31Class => | |
| 233 _jsUInt31Class ??= _findInterceptorsClass('JSUInt31'); | |
| 234 | |
| 235 MemberEntity _jsIndexableLength; | |
| 236 MemberEntity get jsIndexableLength => | |
| 237 _jsIndexableLength ??= _findClassMember(jsIndexableClass, 'length'); | |
| 238 | |
| 239 ConstructorEntity _jsArrayTypedConstructor; | |
| 240 ConstructorEntity get jsArrayTypedConstructor => | |
| 241 _jsArrayTypedConstructor ??= _findConstructor(jsArrayClass, 'typed'); | |
| 242 | |
| 243 FunctionEntity _jsArrayRemoveLast; | |
| 244 FunctionEntity get jsArrayRemoveLast => | |
| 245 _jsArrayRemoveLast ??= _findClassMember(jsArrayClass, 'removeLast'); | |
| 246 | |
| 247 FunctionEntity _jsArrayAdd; | |
| 248 FunctionEntity get jsArrayAdd => | |
| 249 _jsArrayAdd ??= _findClassMember(jsArrayClass, 'add'); | |
| 250 | |
| 251 FunctionEntity _jsStringSplit; | |
| 252 FunctionEntity get jsStringSplit => | |
| 253 _jsStringSplit ??= _findClassMember(jsStringClass, 'split'); | |
| 254 | |
| 255 FunctionEntity _jsStringToString; | |
| 256 FunctionEntity get jsStringToString => | |
| 257 _jsStringToString ??= _findClassMember(jsStringClass, 'toString'); | |
| 258 | |
| 259 FunctionEntity _jsStringOperatorAdd; | |
| 260 FunctionEntity get jsStringOperatorAdd => | |
| 261 _jsStringOperatorAdd ??= _findClassMember(jsStringClass, '+'); | |
| 262 | |
| 263 FunctionEntity _objectEquals; | |
| 264 FunctionEntity get objectEquals => | |
| 265 _objectEquals ??= _findClassMember(commonElements.objectClass, '=='); | |
| 266 | |
| 267 ClassEntity _typeLiteralClass; | |
| 268 ClassEntity get typeLiteralClass => | |
| 269 _typeLiteralClass ??= _findHelperClass('TypeImpl'); | |
| 270 | |
| 271 ClassEntity _mapLiteralClass; | |
| 272 ClassEntity get mapLiteralClass { | |
| 273 if (_mapLiteralClass == null) { | |
| 274 _mapLiteralClass = | |
| 275 _env.lookupClass(commonElements.coreLibrary, 'LinkedHashMap'); | |
| 276 if (_mapLiteralClass == null) { | |
| 277 _mapLiteralClass = _findClass( | |
| 278 _env.lookupLibrary(Uris.dart_collection), 'LinkedHashMap'); | |
| 279 } | |
| 280 } | |
| 281 return _mapLiteralClass; | |
| 282 } | |
| 283 | |
| 284 ClassEntity _constMapLiteralClass; | |
| 285 ClassEntity get constMapLiteralClass => | |
| 286 _constMapLiteralClass ??= _findHelperClass('ConstantMap'); | |
| 287 | |
| 288 ClassEntity _typeVariableClass; | |
| 289 ClassEntity get typeVariableClass => | |
| 290 _typeVariableClass ??= _findHelperClass('TypeVariable'); | |
| 291 | |
| 292 ClassEntity _noSideEffectsClass; | |
| 293 ClassEntity get noSideEffectsClass => | |
| 294 _noSideEffectsClass ??= _findHelperClass('NoSideEffects'); | |
| 295 | |
| 296 ClassEntity _noThrowsClass; | |
| 297 ClassEntity get noThrowsClass => | |
| 298 _noThrowsClass ??= _findHelperClass('NoThrows'); | |
| 299 | |
| 300 ClassEntity _noInlineClass; | |
| 301 ClassEntity get noInlineClass => | |
| 302 _noInlineClass ??= _findHelperClass('NoInline'); | |
| 303 | |
| 304 ClassEntity _forceInlineClass; | |
| 305 ClassEntity get forceInlineClass => | |
| 306 _forceInlineClass ??= _findHelperClass('ForceInline'); | |
| 307 | |
| 308 ClassEntity _irRepresentationClass; | |
| 309 ClassEntity get irRepresentationClass => | |
| 310 _irRepresentationClass ??= _findHelperClass('IrRepresentation'); | |
| 311 | |
| 312 ClassEntity _jsAnnotationClass; | |
| 313 ClassEntity get jsAnnotationClass { | |
| 314 if (_jsAnnotationClass == null) { | |
| 315 LibraryEntity library = _env.lookupLibrary(PACKAGE_JS); | |
| 316 if (library == null) return null; | |
| 317 _jsAnnotationClass = _findClass(library, 'JS'); | |
| 318 } | |
| 319 return _jsAnnotationClass; | |
| 320 } | |
| 321 | |
| 322 ClassEntity _jsAnonymousClass; | |
| 323 ClassEntity get jsAnonymousClass { | |
| 324 if (_jsAnonymousClass == null) { | |
| 325 LibraryEntity library = _env.lookupLibrary(PACKAGE_JS); | |
| 326 if (library == null) return null; | |
| 327 _jsAnonymousClass = _findClass(library, '_Anonymous'); | |
| 328 } | |
| 329 return _jsAnonymousClass; | |
| 330 } | |
| 331 | |
| 332 FunctionEntity _getInterceptorMethod; | |
| 333 FunctionEntity get getInterceptorMethod => | |
| 334 _getInterceptorMethod ??= _findInterceptorsFunction('getInterceptor'); | |
| 335 | |
| 336 ClassEntity _jsInvocationMirrorClass; | |
| 337 ClassEntity get jsInvocationMirrorClass => | |
| 338 _jsInvocationMirrorClass ??= _findHelperClass('JSInvocationMirror'); | |
| 339 | |
| 340 ClassEntity _typedArrayClass; | |
| 341 ClassEntity get typedArrayClass => _typedArrayClass ??= _findClass( | |
| 342 _env.lookupLibrary(Uris.dart__native_typed_data, required: true), | |
| 343 'NativeTypedArray'); | |
| 344 | |
| 345 ClassEntity _typedArrayOfIntClass; | |
| 346 ClassEntity get typedArrayOfIntClass => _typedArrayOfIntClass ??= _findClass( | |
|
Siggi Cherem (dart-lang)
2017/02/06 17:15:59
I wonder if it's worth writing a small codegen too
Johnni Winther
2017/02/07 09:12:16
Acknowledged.
| |
| 347 _env.lookupLibrary(Uris.dart__native_typed_data, required: true), | |
| 348 'NativeTypedArrayOfInt'); | |
| 140 | 349 |
| 141 /** | 350 /** |
| 142 * Interface used to determine if an object has the JavaScript | 351 * Interface used to determine if an object has the JavaScript |
| 143 * indexing behavior. The interface is only visible to specific | 352 * indexing behavior. The interface is only visible to specific |
| 144 * libraries. | 353 * libraries. |
| 145 */ | 354 */ |
| 146 ClassElement jsIndexingBehaviorInterface; | 355 ClassEntity _jsIndexingBehaviorInterface; |
| 147 | 356 ClassEntity get jsIndexingBehaviorInterface => |
| 148 MethodElement getNativeInterceptorMethod; | 357 _jsIndexingBehaviorInterface ??= |
| 358 _findHelperClass('JavaScriptIndexingBehavior'); | |
| 359 | |
| 360 FunctionEntity _getNativeInterceptorMethod; | |
| 361 FunctionEntity get getNativeInterceptorMethod => | |
| 362 _getNativeInterceptorMethod ??= | |
| 363 _findInterceptorsFunction('getNativeInterceptor'); | |
| 149 | 364 |
| 150 /// Holds the method "getIsolateAffinityTag" when dart:_js_helper has been | 365 /// Holds the method "getIsolateAffinityTag" when dart:_js_helper has been |
| 151 /// loaded. | 366 /// loaded. |
| 152 FunctionElement getIsolateAffinityTagMarker; | 367 FunctionEntity _getIsolateAffinityTagMarker; |
| 368 FunctionEntity get getIsolateAffinityTagMarker => | |
| 369 _getIsolateAffinityTagMarker ??= | |
| 370 _findHelperFunction('getIsolateAffinityTag'); | |
| 153 | 371 |
| 154 /// Holds the method "disableTreeShaking" in js_mirrors when | 372 /// Holds the method "disableTreeShaking" in js_mirrors when |
| 155 /// dart:mirrors has been loaded. | 373 /// dart:mirrors has been loaded. |
| 156 FunctionElement disableTreeShakingMarker; | 374 FunctionEntity _disableTreeShakingMarker; |
| 375 FunctionEntity get disableTreeShakingMarker => | |
| 376 _disableTreeShakingMarker ??= _findMirrorsFunction('disableTreeShaking'); | |
| 157 | 377 |
| 158 /// Holds the method "preserveNames" in js_mirrors when | 378 /// Holds the method "preserveNames" in js_mirrors when |
| 159 /// dart:mirrors has been loaded. | 379 /// dart:mirrors has been loaded. |
| 160 FunctionElement preserveNamesMarker; | 380 FunctionEntity _preserveNamesMarker; |
| 381 FunctionEntity get preserveNamesMarker { | |
| 382 if (_preserveNamesMarker == null) { | |
| 383 LibraryEntity library = _env.lookupLibrary(DART_JS_NAMES); | |
| 384 if (library != null) { | |
| 385 _preserveNamesMarker = _findLibraryMember(library, 'preserveNames'); | |
| 386 } | |
| 387 } | |
| 388 return _preserveNamesMarker; | |
| 389 } | |
| 161 | 390 |
| 162 /// Holds the method "preserveMetadata" in js_mirrors when | 391 /// Holds the method "preserveMetadata" in js_mirrors when |
| 163 /// dart:mirrors has been loaded. | 392 /// dart:mirrors has been loaded. |
| 164 FunctionElement preserveMetadataMarker; | 393 FunctionEntity _preserveMetadataMarker; |
| 394 FunctionEntity get preserveMetadataMarker => | |
| 395 _preserveMetadataMarker ??= _findMirrorsFunction('preserveMetadata'); | |
| 165 | 396 |
| 166 /// Holds the method "preserveUris" in js_mirrors when | 397 /// Holds the method "preserveUris" in js_mirrors when |
| 167 /// dart:mirrors has been loaded. | 398 /// dart:mirrors has been loaded. |
| 168 FunctionElement preserveUrisMarker; | 399 FunctionEntity _preserveUrisMarker; |
| 400 FunctionEntity get preserveUrisMarker => | |
| 401 _preserveUrisMarker ??= _findMirrorsFunction('preserveUris'); | |
| 169 | 402 |
| 170 /// Holds the method "preserveLibraryNames" in js_mirrors when | 403 /// Holds the method "preserveLibraryNames" in js_mirrors when |
| 171 /// dart:mirrors has been loaded. | 404 /// dart:mirrors has been loaded. |
| 172 FunctionElement preserveLibraryNamesMarker; | 405 FunctionEntity _preserveLibraryNamesMarker; |
| 406 FunctionEntity get preserveLibraryNamesMarker => | |
| 407 _preserveLibraryNamesMarker ??= | |
| 408 _findMirrorsFunction('preserveLibraryNames'); | |
| 173 | 409 |
| 174 /// Holds the method "requiresPreamble" in _js_helper. | 410 /// Holds the method "requiresPreamble" in _js_helper. |
| 175 FunctionElement requiresPreambleMarker; | 411 FunctionEntity _requiresPreambleMarker; |
| 412 FunctionEntity get requiresPreambleMarker => | |
| 413 _requiresPreambleMarker ??= _findHelperFunction('requiresPreamble'); | |
| 176 | 414 |
| 177 /// Holds the class for the [JsGetName] enum. | 415 /// Holds the class for the [JsGetName] enum. |
| 178 EnumClassElement jsGetNameEnum; | 416 ClassEntity _jsGetNameEnum; |
| 417 ClassEntity get jsGetNameEnum => _jsGetNameEnum ??= _findClass( | |
| 418 _env.lookupLibrary(DART_EMBEDDED_NAMES, required: true), 'JsGetName'); | |
| 179 | 419 |
| 180 /// Holds the class for the [JsBuiltins] enum. | 420 /// Holds the class for the [JsBuiltins] enum. |
| 181 EnumClassElement jsBuiltinEnum; | 421 ClassEntity _jsBuiltinEnum; |
| 182 | 422 ClassEntity get jsBuiltinEnum => _jsBuiltinEnum ??= _findClass( |
| 183 ClassElement _symbolImplementationClass; | 423 _env.lookupLibrary(DART_EMBEDDED_NAMES, required: true), 'JsBuiltin'); |
| 184 ClassElement get symbolImplementationClass { | |
| 185 return _symbolImplementationClass ??= _find(internalLibrary, 'Symbol'); | |
| 186 } | |
| 187 | 424 |
| 188 final Selector symbolValidatedConstructorSelector = | 425 final Selector symbolValidatedConstructorSelector = |
| 189 new Selector.call(const PublicName('validated'), CallStructure.ONE_ARG); | 426 new Selector.call(const PublicName('validated'), CallStructure.ONE_ARG); |
| 190 | 427 |
| 191 ConstructorElement _symbolValidatedConstructor; | 428 ConstructorEntity get symbolValidatedConstructor => |
| 192 | 429 _symbolValidatedConstructor ??= _findConstructor( |
| 193 bool isSymbolValidatedConstructor(Element element) { | 430 symbolImplementationClass, symbolValidatedConstructorSelector.name); |
| 431 | |
| 432 ClassEntity _symbolImplementationClass; | |
| 433 ClassEntity get symbolImplementationClass => | |
| 434 _symbolImplementationClass ??= _findClass(internalLibrary, 'Symbol'); | |
| 435 | |
| 436 ConstructorEntity _symbolValidatedConstructor; | |
| 437 | |
| 438 bool isSymbolValidatedConstructor(ConstructorEntity element) { | |
| 194 if (_symbolValidatedConstructor != null) { | 439 if (_symbolValidatedConstructor != null) { |
| 195 return element == _symbolValidatedConstructor; | 440 return element == _symbolValidatedConstructor; |
| 196 } | 441 } |
| 197 return false; | 442 return false; |
| 198 } | 443 } |
| 199 | 444 |
| 200 ConstructorElement get symbolValidatedConstructor { | 445 ConstructorEntity _mapLiteralConstructor; |
| 201 return _symbolValidatedConstructor ??= _findConstructor( | 446 ConstructorEntity _mapLiteralConstructorEmpty; |
| 202 symbolImplementationClass, symbolValidatedConstructorSelector.name); | 447 FunctionEntity _mapLiteralUntypedMaker; |
| 203 } | 448 FunctionEntity _mapLiteralUntypedEmptyMaker; |
| 204 | 449 |
| 205 // TODO(johnniwinther): Make these private. | 450 ConstructorEntity get mapLiteralConstructor { |
| 206 // TODO(johnniwinther): Split into _findHelperFunction and _findHelperClass | |
| 207 // and add a check that the element has the expected kind. | |
| 208 Element _findHelper(String name) => _find(jsHelperLibrary, name); | |
| 209 Element _findAsyncHelper(String name) => _find(asyncLibrary, name); | |
| 210 Element _findInterceptor(String name) => _find(interceptorsLibrary, name); | |
| 211 Element _find(LibraryElement library, String name) { | |
| 212 Element element = library.implementation.findLocal(name); | |
| 213 assert(invariant(library, element != null, | |
| 214 message: "Element '$name' not found in '${library.canonicalUri}'.")); | |
| 215 return element; | |
| 216 } | |
| 217 | |
| 218 Element findCoreHelper(String name) { | |
| 219 LibraryElement coreLibrary = compiler.commonElements.coreLibrary; | |
| 220 return coreLibrary.implementation.localLookup(name); | |
| 221 } | |
| 222 | |
| 223 ConstructorElement _findConstructor(ClassElement cls, String name) { | |
| 224 cls.ensureResolved(resolution); | |
| 225 ConstructorElement constructor = cls.lookupConstructor(name); | |
| 226 assert(invariant(cls, constructor != null, | |
| 227 message: "Constructor '$name' not found in '${cls}'.")); | |
| 228 return constructor; | |
| 229 } | |
| 230 | |
| 231 void onLibraryCreated(LibraryElement library) { | |
| 232 Uri uri = library.canonicalUri; | |
| 233 if (uri == DART_JS_HELPER) { | |
| 234 jsHelperLibrary = library; | |
| 235 } else if (uri == Uris.dart_async) { | |
| 236 asyncLibrary = library; | |
| 237 } else if (uri == Uris.dart__internal) { | |
| 238 internalLibrary = library; | |
| 239 } else if (uri == DART_INTERCEPTORS) { | |
| 240 interceptorsLibrary = library; | |
| 241 } else if (uri == DART_FOREIGN_HELPER) { | |
| 242 foreignLibrary = library; | |
| 243 } else if (uri == DART_ISOLATE_HELPER) { | |
| 244 isolateHelperLibrary = library; | |
| 245 } | |
| 246 } | |
| 247 | |
| 248 void initializeHelperClasses(DiagnosticReporter reporter) { | |
| 249 final List missingHelperClasses = []; | |
| 250 ClassElement lookupHelperClass(String name) { | |
| 251 ClassElement result = _findHelper(name); | |
| 252 if (result == null) { | |
| 253 missingHelperClasses.add(name); | |
| 254 } | |
| 255 return result; | |
| 256 } | |
| 257 | |
| 258 jsInvocationMirrorClass = lookupHelperClass('JSInvocationMirror'); | |
| 259 boundClosureClass = lookupHelperClass('BoundClosure'); | |
| 260 closureClass = lookupHelperClass('Closure'); | |
| 261 if (!missingHelperClasses.isEmpty) { | |
| 262 reporter.internalError( | |
| 263 jsHelperLibrary, | |
| 264 'dart:_js_helper library does not contain required classes: ' | |
| 265 '$missingHelperClasses'); | |
| 266 } | |
| 267 } | |
| 268 | |
| 269 void onLibraryScanned(LibraryElement library) { | |
| 270 Uri uri = library.canonicalUri; | |
| 271 | |
| 272 FunctionElement findMethod(String name) { | |
| 273 return _find(library, name); | |
| 274 } | |
| 275 | |
| 276 ClassElement findClass(String name) { | |
| 277 return _find(library, name); | |
| 278 } | |
| 279 | |
| 280 if (uri == DART_INTERCEPTORS) { | |
| 281 getInterceptorMethod = findMethod('getInterceptor'); | |
| 282 getNativeInterceptorMethod = findMethod('getNativeInterceptor'); | |
| 283 jsInterceptorClass = findClass('Interceptor'); | |
| 284 jsStringClass = findClass('JSString'); | |
| 285 jsArrayClass = findClass('JSArray'); | |
| 286 // The int class must be before the double class, because the | |
| 287 // emitter relies on this list for the order of type checks. | |
| 288 jsIntClass = findClass('JSInt'); | |
| 289 jsPositiveIntClass = findClass('JSPositiveInt'); | |
| 290 jsUInt32Class = findClass('JSUInt32'); | |
| 291 jsUInt31Class = findClass('JSUInt31'); | |
| 292 jsDoubleClass = findClass('JSDouble'); | |
| 293 jsNumberClass = findClass('JSNumber'); | |
| 294 jsNullClass = findClass('JSNull'); | |
| 295 jsBoolClass = findClass('JSBool'); | |
| 296 jsMutableArrayClass = findClass('JSMutableArray'); | |
| 297 jsFixedArrayClass = findClass('JSFixedArray'); | |
| 298 jsExtendableArrayClass = findClass('JSExtendableArray'); | |
| 299 jsUnmodifiableArrayClass = findClass('JSUnmodifiableArray'); | |
| 300 jsPlainJavaScriptObjectClass = findClass('PlainJavaScriptObject'); | |
| 301 jsJavaScriptObjectClass = findClass('JavaScriptObject'); | |
| 302 jsJavaScriptFunctionClass = findClass('JavaScriptFunction'); | |
| 303 jsUnknownJavaScriptObjectClass = findClass('UnknownJavaScriptObject'); | |
| 304 jsIndexableClass = findClass('JSIndexable'); | |
| 305 jsMutableIndexableClass = findClass('JSMutableIndexable'); | |
| 306 } else if (uri == DART_JS_HELPER) { | |
| 307 initializeHelperClasses(reporter); | |
| 308 assertTest = _findHelper('assertTest'); | |
| 309 assertThrow = _findHelper('assertThrow'); | |
| 310 assertHelper = _findHelper('assertHelper'); | |
| 311 assertUnreachableMethod = _findHelper('assertUnreachable'); | |
| 312 | |
| 313 typeLiteralClass = findClass('TypeImpl'); | |
| 314 constMapLiteralClass = findClass('ConstantMap'); | |
| 315 typeVariableClass = findClass('TypeVariable'); | |
| 316 | |
| 317 jsIndexingBehaviorInterface = findClass('JavaScriptIndexingBehavior'); | |
| 318 | |
| 319 noSideEffectsClass = findClass('NoSideEffects'); | |
| 320 noThrowsClass = findClass('NoThrows'); | |
| 321 noInlineClass = findClass('NoInline'); | |
| 322 forceInlineClass = findClass('ForceInline'); | |
| 323 irRepresentationClass = findClass('IrRepresentation'); | |
| 324 | |
| 325 getIsolateAffinityTagMarker = findMethod('getIsolateAffinityTag'); | |
| 326 | |
| 327 requiresPreambleMarker = findMethod('requiresPreamble'); | |
| 328 } else if (uri == DART_JS_MIRRORS) { | |
| 329 disableTreeShakingMarker = _find(library, 'disableTreeShaking'); | |
| 330 preserveMetadataMarker = _find(library, 'preserveMetadata'); | |
| 331 preserveUrisMarker = _find(library, 'preserveUris'); | |
| 332 preserveLibraryNamesMarker = _find(library, 'preserveLibraryNames'); | |
| 333 } else if (uri == DART_JS_NAMES) { | |
| 334 preserveNamesMarker = _find(library, 'preserveNames'); | |
| 335 } else if (uri == DART_EMBEDDED_NAMES) { | |
| 336 jsGetNameEnum = _find(library, 'JsGetName'); | |
| 337 jsBuiltinEnum = _find(library, 'JsBuiltin'); | |
| 338 } else if (uri == Uris.dart__native_typed_data) { | |
| 339 typedArrayClass = findClass('NativeTypedArray'); | |
| 340 typedArrayOfIntClass = findClass('NativeTypedArrayOfInt'); | |
| 341 } else if (uri == PACKAGE_JS) { | |
| 342 jsAnnotationClass = _find(library, 'JS'); | |
| 343 jsAnonymousClass = _find(library, '_Anonymous'); | |
| 344 } | |
| 345 } | |
| 346 | |
| 347 void onLibrariesLoaded(LoadedLibraries loadedLibraries) { | |
| 348 assert(loadedLibraries.containsLibrary(Uris.dart_core)); | |
| 349 assert(loadedLibraries.containsLibrary(DART_INTERCEPTORS)); | |
| 350 assert(loadedLibraries.containsLibrary(DART_JS_HELPER)); | |
| 351 | |
| 352 if (jsInvocationMirrorClass != null) { | |
| 353 jsInvocationMirrorClass.ensureResolved(resolution); | |
| 354 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON); | |
| 355 } | |
| 356 | |
| 357 // [LinkedHashMap] is reexported from dart:collection and can therefore not | |
| 358 // be loaded from dart:core in [onLibraryScanned]. | |
| 359 LibraryElement coreLibrary = compiler.commonElements.coreLibrary; | |
| 360 mapLiteralClass = coreLibrary.find('LinkedHashMap'); | |
| 361 assert(invariant( | |
| 362 compiler.commonElements.coreLibrary, mapLiteralClass != null, | |
| 363 message: "Element 'LinkedHashMap' not found in 'dart:core'.")); | |
| 364 | |
| 365 // TODO(kasperl): Some tests do not define the special JSArray | |
| 366 // subclasses, so we check to see if they are defined before | |
| 367 // trying to resolve them. | |
| 368 if (jsFixedArrayClass != null) { | |
| 369 jsFixedArrayClass.ensureResolved(resolution); | |
| 370 } | |
| 371 if (jsExtendableArrayClass != null) { | |
| 372 jsExtendableArrayClass.ensureResolved(resolution); | |
| 373 } | |
| 374 if (jsUnmodifiableArrayClass != null) { | |
| 375 jsUnmodifiableArrayClass.ensureResolved(resolution); | |
| 376 } | |
| 377 | |
| 378 jsIndexableClass.ensureResolved(resolution); | |
| 379 Element jsIndexableLengthElement = | |
| 380 compiler.lookupElementIn(jsIndexableClass, 'length'); | |
| 381 if (jsIndexableLengthElement != null && | |
| 382 jsIndexableLengthElement.isAbstractField) { | |
| 383 AbstractFieldElement element = jsIndexableLengthElement; | |
| 384 jsIndexableLength = element.getter; | |
| 385 } else { | |
| 386 jsIndexableLength = jsIndexableLengthElement; | |
| 387 } | |
| 388 | |
| 389 jsArrayClass.ensureResolved(resolution); | |
| 390 jsArrayTypedConstructor = compiler.lookupElementIn(jsArrayClass, 'typed'); | |
| 391 jsArrayRemoveLast = compiler.lookupElementIn(jsArrayClass, 'removeLast'); | |
| 392 jsArrayAdd = compiler.lookupElementIn(jsArrayClass, 'add'); | |
| 393 | |
| 394 jsStringClass.ensureResolved(resolution); | |
| 395 jsStringSplit = compiler.lookupElementIn(jsStringClass, 'split'); | |
| 396 jsStringOperatorAdd = compiler.lookupElementIn(jsStringClass, '+'); | |
| 397 jsStringToString = compiler.lookupElementIn(jsStringClass, 'toString'); | |
| 398 | |
| 399 ClassElement objectClass = commonElements.objectClass; | |
| 400 objectEquals = compiler.lookupElementIn(objectClass, '=='); | |
| 401 } | |
| 402 | |
| 403 ConstructorElement _mapLiteralConstructor; | |
| 404 ConstructorElement _mapLiteralConstructorEmpty; | |
| 405 Element _mapLiteralUntypedMaker; | |
| 406 Element _mapLiteralUntypedEmptyMaker; | |
| 407 | |
| 408 ConstructorElement get mapLiteralConstructor { | |
| 409 _ensureMapLiteralHelpers(); | 451 _ensureMapLiteralHelpers(); |
| 410 return _mapLiteralConstructor; | 452 return _mapLiteralConstructor; |
| 411 } | 453 } |
| 412 | 454 |
| 413 ConstructorElement get mapLiteralConstructorEmpty { | 455 ConstructorEntity get mapLiteralConstructorEmpty { |
| 414 _ensureMapLiteralHelpers(); | 456 _ensureMapLiteralHelpers(); |
| 415 return _mapLiteralConstructorEmpty; | 457 return _mapLiteralConstructorEmpty; |
| 416 } | 458 } |
| 417 | 459 |
| 418 Element get mapLiteralUntypedMaker { | 460 FunctionEntity get mapLiteralUntypedMaker { |
| 419 _ensureMapLiteralHelpers(); | 461 _ensureMapLiteralHelpers(); |
| 420 return _mapLiteralUntypedMaker; | 462 return _mapLiteralUntypedMaker; |
| 421 } | 463 } |
| 422 | 464 |
| 423 Element get mapLiteralUntypedEmptyMaker { | 465 FunctionEntity get mapLiteralUntypedEmptyMaker { |
| 424 _ensureMapLiteralHelpers(); | 466 _ensureMapLiteralHelpers(); |
| 425 return _mapLiteralUntypedEmptyMaker; | 467 return _mapLiteralUntypedEmptyMaker; |
| 426 } | 468 } |
| 427 | 469 |
| 428 void _ensureMapLiteralHelpers() { | 470 void _ensureMapLiteralHelpers() { |
| 429 if (_mapLiteralConstructor != null) return; | 471 if (_mapLiteralConstructor != null) return; |
| 430 | 472 |
| 431 // For map literals, the dependency between the implementation class | 473 _mapLiteralConstructor = |
| 432 // and [Map] is not visible, so we have to add it manually. | 474 _env.lookupConstructor(mapLiteralClass, '_literal'); |
| 433 Element getFactory(String name, int arity) { | 475 _mapLiteralConstructorEmpty = |
| 434 // The constructor is on the patch class, but dart2js unit tests don't | 476 _env.lookupConstructor(mapLiteralClass, '_empty'); |
| 435 // have a patch class. | 477 _mapLiteralUntypedMaker = |
| 436 ClassElement implementation = mapLiteralClass.implementation; | 478 _env.lookupClassMember(mapLiteralClass, '_makeLiteral'); |
| 437 ConstructorElement ctor = implementation.lookupConstructor(name); | 479 _mapLiteralUntypedEmptyMaker = |
| 438 if (ctor == null || | 480 _env.lookupClassMember(mapLiteralClass, '_makeEmpty'); |
| 439 (Name.isPrivateName(name) && | 481 } |
| 440 ctor.library != mapLiteralClass.library)) { | 482 |
| 441 reporter.internalError( | 483 FunctionEntity get badMain { |
| 442 mapLiteralClass, | 484 return _findHelperFunction('badMain'); |
|
Siggi Cherem (dart-lang)
2017/02/06 17:15:58
I am noticing more at this moment that sometimes w
Johnni Winther
2017/02/07 09:12:16
No. I just followed the existing strategy.
| |
| 443 "Map literal class ${mapLiteralClass} missing " | 485 } |
| 444 "'$name' constructor" | 486 |
| 445 " ${mapLiteralClass.constructors}"); | 487 FunctionEntity get missingMain { |
| 446 } | 488 return _findHelperFunction('missingMain'); |
| 447 return ctor; | 489 } |
| 448 } | 490 |
| 449 | 491 FunctionEntity get mainHasTooManyParameters { |
| 450 Element getMember(String name) { | 492 return _findHelperFunction('mainHasTooManyParameters'); |
| 451 // The constructor is on the patch class, but dart2js unit tests don't | 493 } |
| 452 // have a patch class. | 494 |
| 453 ClassElement implementation = mapLiteralClass.implementation; | 495 FunctionEntity get loadLibraryWrapper { |
| 454 Element element = implementation.lookupLocalMember(name); | 496 return _findHelperFunction("_loadLibraryWrapper"); |
| 455 if (element == null || !element.isFunction || !element.isStatic) { | 497 } |
| 456 reporter.internalError( | 498 |
| 457 mapLiteralClass, | 499 FunctionEntity get boolConversionCheck { |
| 458 "Map literal class ${mapLiteralClass} missing " | 500 return _findHelperFunction('boolConversionCheck'); |
| 459 "'$name' static member function"); | 501 } |
| 460 } | 502 |
| 461 return element; | 503 FunctionEntity _traceHelper; |
| 462 } | 504 |
| 463 | 505 FunctionEntity get traceHelper { |
| 464 _mapLiteralConstructor = getFactory('_literal', 1); | |
| 465 _mapLiteralConstructorEmpty = getFactory('_empty', 0); | |
| 466 _mapLiteralUntypedMaker = getMember('_makeLiteral'); | |
| 467 _mapLiteralUntypedEmptyMaker = getMember('_makeEmpty'); | |
| 468 } | |
| 469 | |
| 470 Element get badMain { | |
| 471 return _findHelper('badMain'); | |
| 472 } | |
| 473 | |
| 474 Element get missingMain { | |
| 475 return _findHelper('missingMain'); | |
| 476 } | |
| 477 | |
| 478 Element get mainHasTooManyParameters { | |
| 479 return _findHelper('mainHasTooManyParameters'); | |
| 480 } | |
| 481 | |
| 482 MethodElement get loadLibraryWrapper { | |
| 483 return _findHelper("_loadLibraryWrapper"); | |
| 484 } | |
| 485 | |
| 486 Element get boolConversionCheck { | |
| 487 return _findHelper('boolConversionCheck'); | |
| 488 } | |
| 489 | |
| 490 MethodElement _traceHelper; | |
| 491 | |
| 492 MethodElement get traceHelper { | |
| 493 return _traceHelper ??= JavaScriptBackend.TRACE_METHOD == 'console' | 506 return _traceHelper ??= JavaScriptBackend.TRACE_METHOD == 'console' |
| 494 ? _consoleTraceHelper | 507 ? _consoleTraceHelper |
| 495 : _postTraceHelper; | 508 : _postTraceHelper; |
| 496 } | 509 } |
| 497 | 510 |
| 498 MethodElement get _consoleTraceHelper { | 511 FunctionEntity get _consoleTraceHelper => |
| 499 return _findHelper('consoleTraceHelper'); | 512 _findHelperFunction('consoleTraceHelper'); |
| 500 } | 513 |
| 501 | 514 FunctionEntity get _postTraceHelper => _findHelperFunction('postTraceHelper'); |
| 502 MethodElement get _postTraceHelper { | 515 |
| 503 return _findHelper('postTraceHelper'); | 516 FunctionEntity get closureFromTearOff => |
| 504 } | 517 _findHelperFunction('closureFromTearOff'); |
| 505 | 518 |
| 506 MethodElement get closureFromTearOff { | 519 FunctionEntity get isJsIndexable => _findHelperFunction('isJsIndexable'); |
| 507 return _findHelper('closureFromTearOff'); | 520 |
| 508 } | 521 FunctionEntity get throwIllegalArgumentException => |
| 509 | 522 _findHelperFunction('iae'); |
| 510 MethodElement get isJsIndexable { | 523 |
| 511 return _findHelper('isJsIndexable'); | 524 FunctionEntity get throwIndexOutOfRangeException => |
| 512 } | 525 _findHelperFunction('ioore'); |
| 513 | 526 |
| 514 MethodElement get throwIllegalArgumentException { | 527 FunctionEntity get exceptionUnwrapper => |
| 515 return _findHelper('iae'); | 528 _findHelperFunction('unwrapException'); |
| 516 } | 529 |
| 517 | 530 FunctionEntity get throwRuntimeError => |
| 518 MethodElement get throwIndexOutOfRangeException { | 531 _findHelperFunction('throwRuntimeError'); |
| 519 return _findHelper('ioore'); | 532 |
| 520 } | 533 FunctionEntity get throwTypeError => _findHelperFunction('throwTypeError'); |
| 521 | 534 |
| 522 Element get exceptionUnwrapper { | 535 FunctionEntity get throwAbstractClassInstantiationError => |
| 523 return _findHelper('unwrapException'); | 536 _findHelperFunction('throwAbstractClassInstantiationError'); |
| 524 } | 537 |
| 525 | 538 FunctionEntity _cachedCheckConcurrentModificationError; |
| 526 Element get throwRuntimeError { | 539 FunctionEntity get checkConcurrentModificationError => |
| 527 return _findHelper('throwRuntimeError'); | 540 _cachedCheckConcurrentModificationError ??= |
| 528 } | 541 _findHelperFunction('checkConcurrentModificationError'); |
| 529 | 542 |
| 530 Element get throwTypeError { | 543 FunctionEntity get throwConcurrentModificationError => |
| 531 return _findHelper('throwTypeError'); | 544 _findHelperFunction('throwConcurrentModificationError'); |
| 532 } | 545 |
| 533 | 546 FunctionEntity _checkInt; |
| 534 Element get throwAbstractClassInstantiationError { | 547 FunctionEntity get checkInt => _checkInt ??= _findHelperFunction('checkInt'); |
| 535 return _findHelper('throwAbstractClassInstantiationError'); | 548 |
| 536 } | 549 FunctionEntity _checkNum; |
| 537 | 550 FunctionEntity get checkNum => _checkNum ??= _findHelperFunction('checkNum'); |
| 538 Element get checkConcurrentModificationError { | 551 |
| 539 if (cachedCheckConcurrentModificationError == null) { | 552 FunctionEntity _checkString; |
| 540 cachedCheckConcurrentModificationError = | 553 FunctionEntity get checkString => |
| 541 _findHelper('checkConcurrentModificationError'); | 554 _checkString ??= _findHelperFunction('checkString'); |
| 542 } | 555 |
| 543 return cachedCheckConcurrentModificationError; | 556 FunctionEntity get stringInterpolationHelper => _findHelperFunction('S'); |
| 544 } | 557 |
| 545 | 558 FunctionEntity get wrapExceptionHelper => |
| 546 MethodElement get throwConcurrentModificationError { | 559 _findHelperFunction(r'wrapException'); |
|
Siggi Cherem (dart-lang)
2017/02/06 17:15:59
nit: remove 'r' for consistency (I know it was fro
Johnni Winther
2017/02/07 09:12:16
Done.
| |
| 547 return _findHelper('throwConcurrentModificationError'); | 560 |
| 548 } | 561 FunctionEntity get throwExpressionHelper => |
| 549 | 562 _findHelperFunction('throwExpression'); |
| 550 Element get checkInt => _checkInt ??= _findHelper('checkInt'); | 563 |
| 551 Element _checkInt; | 564 FunctionEntity get closureConverter => |
| 552 | 565 _findHelperFunction('convertDartClosureToJS'); |
| 553 Element get checkNum => _checkNum ??= _findHelper('checkNum'); | 566 |
| 554 Element _checkNum; | 567 FunctionEntity get traceFromException => |
| 555 | 568 _findHelperFunction('getTraceFromException'); |
| 556 Element get checkString => _checkString ??= _findHelper('checkString'); | 569 |
| 557 Element _checkString; | 570 FunctionEntity get setRuntimeTypeInfo => |
| 558 | 571 _findHelperFunction('setRuntimeTypeInfo'); |
| 559 MethodElement get stringInterpolationHelper { | 572 |
| 560 return _findHelper('S'); | 573 FunctionEntity get getRuntimeTypeInfo => |
| 561 } | 574 _findHelperFunction('getRuntimeTypeInfo'); |
| 562 | 575 |
| 563 MethodElement get wrapExceptionHelper { | 576 FunctionEntity get getTypeArgumentByIndex => |
| 564 return _findHelper(r'wrapException'); | 577 _findHelperFunction('getTypeArgumentByIndex'); |
| 565 } | 578 |
| 566 | 579 FunctionEntity get computeSignature => |
| 567 MethodElement get throwExpressionHelper { | 580 _findHelperFunction('computeSignature'); |
| 568 return _findHelper('throwExpression'); | 581 |
| 569 } | 582 FunctionEntity get getRuntimeTypeArguments => |
| 570 | 583 _findHelperFunction('getRuntimeTypeArguments'); |
| 571 MethodElement get closureConverter { | 584 |
| 572 return _findHelper('convertDartClosureToJS'); | 585 FunctionEntity get getRuntimeTypeArgument => |
| 573 } | 586 _findHelperFunction('getRuntimeTypeArgument'); |
| 574 | 587 |
| 575 Element get traceFromException { | 588 FunctionEntity get runtimeTypeToString => |
| 576 return _findHelper('getTraceFromException'); | 589 _findHelperFunction('runtimeTypeToString'); |
| 577 } | 590 |
| 578 | 591 FunctionEntity get assertIsSubtype => _findHelperFunction('assertIsSubtype'); |
| 579 MethodElement get setRuntimeTypeInfo { | 592 |
| 580 return _findHelper('setRuntimeTypeInfo'); | 593 FunctionEntity get checkSubtype => _findHelperFunction('checkSubtype'); |
| 581 } | 594 |
| 582 | 595 FunctionEntity get assertSubtype => _findHelperFunction('assertSubtype'); |
| 583 Element get getRuntimeTypeInfo { | 596 |
| 584 return _findHelper('getRuntimeTypeInfo'); | 597 FunctionEntity get subtypeCast => _findHelperFunction('subtypeCast'); |
| 585 } | 598 |
| 586 | 599 FunctionEntity get checkSubtypeOfRuntimeType => |
| 587 MethodElement get getTypeArgumentByIndex { | 600 _findHelperFunction('checkSubtypeOfRuntimeType'); |
| 588 return _findHelper('getTypeArgumentByIndex'); | 601 |
| 589 } | 602 FunctionEntity get assertSubtypeOfRuntimeType => |
| 590 | 603 _findHelperFunction('assertSubtypeOfRuntimeType'); |
| 591 MethodElement get computeSignature { | 604 |
| 592 return _findHelper('computeSignature'); | 605 FunctionEntity get subtypeOfRuntimeTypeCast => |
| 593 } | 606 _findHelperFunction('subtypeOfRuntimeTypeCast'); |
| 594 | 607 |
| 595 Element get getRuntimeTypeArguments { | 608 FunctionEntity get checkDeferredIsLoaded => |
| 596 return _findHelper('getRuntimeTypeArguments'); | 609 _findHelperFunction('checkDeferredIsLoaded'); |
| 597 } | 610 |
| 598 | 611 FunctionEntity get throwNoSuchMethod => |
| 599 MethodElement get getRuntimeTypeArgument { | 612 _findHelperFunction('throwNoSuchMethod'); |
| 600 return _findHelper('getRuntimeTypeArgument'); | 613 |
| 601 } | 614 FunctionEntity get malformedTypeError => |
| 602 | 615 _cachedCoreHelper('_malformedTypeError'); |
| 603 Element get runtimeTypeToString { | 616 FunctionEntity get genericNoSuchMethod => |
| 604 return _findHelper('runtimeTypeToString'); | 617 _cachedCoreHelper('_genericNoSuchMethod'); |
| 605 } | 618 FunctionEntity get unresolvedConstructorError => |
| 606 | |
| 607 Element get assertIsSubtype { | |
| 608 return _findHelper('assertIsSubtype'); | |
| 609 } | |
| 610 | |
| 611 Element get checkSubtype { | |
| 612 return _findHelper('checkSubtype'); | |
| 613 } | |
| 614 | |
| 615 Element get assertSubtype { | |
| 616 return _findHelper('assertSubtype'); | |
| 617 } | |
| 618 | |
| 619 Element get subtypeCast { | |
| 620 return _findHelper('subtypeCast'); | |
| 621 } | |
| 622 | |
| 623 Element get checkSubtypeOfRuntimeType { | |
| 624 return _findHelper('checkSubtypeOfRuntimeType'); | |
| 625 } | |
| 626 | |
| 627 Element get assertSubtypeOfRuntimeType { | |
| 628 return _findHelper('assertSubtypeOfRuntimeType'); | |
| 629 } | |
| 630 | |
| 631 Element get subtypeOfRuntimeTypeCast { | |
| 632 return _findHelper('subtypeOfRuntimeTypeCast'); | |
| 633 } | |
| 634 | |
| 635 Element get checkDeferredIsLoaded { | |
| 636 return _findHelper('checkDeferredIsLoaded'); | |
| 637 } | |
| 638 | |
| 639 Element get throwNoSuchMethod { | |
| 640 return _findHelper('throwNoSuchMethod'); | |
| 641 } | |
| 642 | |
| 643 Element get malformedTypeError => _cachedCoreHelper('_malformedTypeError'); | |
| 644 Element get genericNoSuchMethod => _cachedCoreHelper('_genericNoSuchMethod'); | |
| 645 Element get unresolvedConstructorError => | |
| 646 _cachedCoreHelper('_unresolvedConstructorError'); | 619 _cachedCoreHelper('_unresolvedConstructorError'); |
| 647 Element get unresolvedStaticGetterError => | 620 FunctionEntity get unresolvedStaticGetterError => |
| 648 _cachedCoreHelper('_unresolvedStaticGetterError'); | 621 _cachedCoreHelper('_unresolvedStaticGetterError'); |
| 649 Element get unresolvedStaticSetterError => | 622 FunctionEntity get unresolvedStaticSetterError => |
| 650 _cachedCoreHelper('_unresolvedStaticSetterError'); | 623 _cachedCoreHelper('_unresolvedStaticSetterError'); |
| 651 Element get unresolvedStaticMethodError => | 624 FunctionEntity get unresolvedStaticMethodError => |
| 652 _cachedCoreHelper('_unresolvedStaticMethodError'); | 625 _cachedCoreHelper('_unresolvedStaticMethodError'); |
| 653 Element get unresolvedTopLevelGetterError => | 626 FunctionEntity get unresolvedTopLevelGetterError => |
| 654 _cachedCoreHelper('_unresolvedTopLevelGetterError'); | 627 _cachedCoreHelper('_unresolvedTopLevelGetterError'); |
| 655 Element get unresolvedTopLevelSetterError => | 628 FunctionEntity get unresolvedTopLevelSetterError => |
| 656 _cachedCoreHelper('_unresolvedTopLevelSetterError'); | 629 _cachedCoreHelper('_unresolvedTopLevelSetterError'); |
| 657 Element get unresolvedTopLevelMethodError => | 630 FunctionEntity get unresolvedTopLevelMethodError => |
| 658 _cachedCoreHelper('_unresolvedTopLevelMethodError'); | 631 _cachedCoreHelper('_unresolvedTopLevelMethodError'); |
| 659 | 632 |
| 660 Map<String, Element> _cachedCoreHelpers = <String, Element>{}; | 633 Map<String, FunctionEntity> _cachedCoreHelpers = <String, FunctionEntity>{}; |
| 661 Element _cachedCoreHelper(String name) => | 634 FunctionEntity _cachedCoreHelper(String name) => |
| 662 _cachedCoreHelpers[name] ??= findCoreHelper(name); | 635 _cachedCoreHelpers[name] ??= findCoreHelper(name); |
| 663 | 636 |
| 664 MethodElement get createRuntimeType { | 637 FunctionEntity get createRuntimeType => |
| 665 return _findHelper('createRuntimeType'); | 638 _findHelperFunction('createRuntimeType'); |
| 666 } | 639 |
| 667 | 640 FunctionEntity get fallThroughError => |
| 668 Element get fallThroughError { | 641 _findHelperFunction("getFallThroughError"); |
| 669 return _findHelper("getFallThroughError"); | 642 |
| 670 } | 643 FunctionEntity get createInvocationMirror => |
| 671 | 644 _findHelperFunction('createInvocationMirror'); |
| 672 MethodElement get createInvocationMirror { | 645 |
| 673 return _findHelper('createInvocationMirror'); | 646 FunctionEntity get cyclicThrowHelper => |
| 674 } | 647 _findHelperFunction("throwCyclicInit"); |
| 675 | 648 |
| 676 MethodElement get cyclicThrowHelper { | 649 FunctionEntity get asyncHelper => _findAsyncHelperFunction("_asyncHelper"); |
| 677 return _findHelper("throwCyclicInit"); | 650 |
| 678 } | 651 FunctionEntity get wrapBody => |
| 679 | 652 _findAsyncHelperFunction("_wrapJsFunctionForAsync"); |
| 680 MethodElement get asyncHelper { | 653 |
| 681 return _findAsyncHelper("_asyncHelper"); | 654 FunctionEntity get yieldStar => _env.lookupClassMember( |
| 682 } | 655 _findAsyncHelperClass("_IterationMarker"), "yieldStar"); |
| 683 | 656 |
| 684 MethodElement get wrapBody { | 657 FunctionEntity get yieldSingle => _env.lookupClassMember( |
| 685 return _findAsyncHelper("_wrapJsFunctionForAsync"); | 658 _findAsyncHelperClass("_IterationMarker"), "yieldSingle"); |
| 686 } | 659 |
| 687 | 660 FunctionEntity get syncStarUncaughtError => _env.lookupClassMember( |
| 688 MethodElement get yieldStar { | 661 _findAsyncHelperClass("_IterationMarker"), "uncaughtError"); |
| 689 ClassElement classElement = _findAsyncHelper("_IterationMarker"); | 662 |
| 690 classElement.ensureResolved(resolution); | 663 FunctionEntity get asyncStarHelper => |
| 691 return classElement.lookupLocalMember("yieldStar"); | 664 _findAsyncHelperFunction("_asyncStarHelper"); |
| 692 } | 665 |
| 693 | 666 FunctionEntity get streamOfController => |
| 694 MethodElement get yieldSingle { | 667 _findAsyncHelperFunction("_streamOfController"); |
| 695 ClassElement classElement = _findAsyncHelper("_IterationMarker"); | 668 |
| 696 classElement.ensureResolved(resolution); | 669 FunctionEntity get endOfIteration => _env.lookupClassMember( |
| 697 return classElement.lookupLocalMember("yieldSingle"); | 670 _findAsyncHelperClass("_IterationMarker"), "endOfIteration"); |
| 698 } | 671 |
| 699 | 672 ClassEntity get syncStarIterable => |
| 700 MethodElement get syncStarUncaughtError { | 673 _findAsyncHelperClass("_SyncStarIterable"); |
| 701 ClassElement classElement = _findAsyncHelper("_IterationMarker"); | 674 |
| 702 classElement.ensureResolved(resolution); | 675 ClassEntity get futureImplementation => _findAsyncHelperClass('_Future'); |
| 703 return classElement.lookupLocalMember("uncaughtError"); | 676 |
| 704 } | 677 ClassEntity get controllerStream => |
| 705 | 678 _findAsyncHelperClass("_ControllerStream"); |
| 706 MethodElement get asyncStarHelper { | 679 |
| 707 return _findAsyncHelper("_asyncStarHelper"); | 680 ConstructorEntity get syncStarIterableConstructor => |
| 708 } | 681 _env.lookupConstructor(syncStarIterable, ""); |
| 709 | 682 |
| 710 MethodElement get streamOfController { | 683 ConstructorEntity get syncCompleterConstructor => |
| 711 return _findAsyncHelper("_streamOfController"); | 684 _env.lookupConstructor(_findAsyncHelperClass("Completer"), "sync"); |
| 712 } | 685 |
| 713 | 686 ClassEntity get asyncStarController => |
| 714 MethodElement get endOfIteration { | 687 _findAsyncHelperClass("_AsyncStarStreamController"); |
| 715 ClassElement classElement = _findAsyncHelper("_IterationMarker"); | 688 |
| 716 classElement.ensureResolved(resolution); | 689 ConstructorEntity get asyncStarControllerConstructor => |
| 717 return classElement.lookupLocalMember("endOfIteration"); | 690 _env.lookupConstructor(asyncStarController, "", required: true); |
| 718 } | 691 |
| 719 | 692 ConstructorEntity get streamIteratorConstructor => |
| 720 ClassElement get syncStarIterable { | 693 _env.lookupConstructor(_findAsyncHelperClass("StreamIterator"), ""); |
| 721 ClassElement classElement = _findAsyncHelper("_SyncStarIterable"); | 694 |
| 722 classElement.ensureResolved(resolution); | 695 ClassEntity get VoidRuntimeType => _findHelperClass('VoidRuntimeType'); |
| 723 return classElement; | 696 |
| 724 } | 697 ClassEntity get RuntimeType => _findHelperClass('RuntimeType'); |
| 725 | 698 |
| 726 Element get futureImplementation { | 699 ClassEntity get RuntimeFunctionType => |
| 727 ClassElement classElement = _findAsyncHelper('_Future'); | 700 _findHelperClass('RuntimeFunctionType'); |
| 728 classElement.ensureResolved(resolution); | 701 |
| 729 return classElement; | 702 ClassEntity get RuntimeTypePlain => _findHelperClass('RuntimeTypePlain'); |
| 730 } | 703 |
| 731 | 704 ClassEntity get RuntimeTypeGeneric => _findHelperClass('RuntimeTypeGeneric'); |
| 732 ClassElement get controllerStream { | 705 |
| 733 ClassElement classElement = _findAsyncHelper("_ControllerStream"); | 706 ClassEntity get DynamicRuntimeType => _findHelperClass('DynamicRuntimeType'); |
| 734 classElement.ensureResolved(resolution); | 707 |
| 735 return classElement; | 708 FunctionEntity get getDynamicRuntimeType { |
| 736 } | 709 // TODO(johnniwinther): Support this in mocks. |
| 737 | 710 return _env.lookupLibraryMember(jsHelperLibrary, 'getDynamicRuntimeType'); |
| 738 ConstructorElement get syncStarIterableConstructor { | 711 } |
| 739 ClassElement classElement = syncStarIterable; | 712 |
| 740 classElement.ensureResolved(resolution); | 713 FunctionEntity get getVoidRuntimeType { |
| 741 return classElement.lookupConstructor(""); | 714 // TODO(johnniwinther): Support this in mocks. |
| 742 } | 715 return _env.lookupLibraryMember(jsHelperLibrary, 'getVoidRuntimeType'); |
| 743 | 716 } |
| 744 ConstructorElement get syncCompleterConstructor { | 717 |
| 745 ClassElement classElement = _find(asyncLibrary, "Completer"); | 718 FunctionEntity get buildInterfaceType { |
| 746 classElement.ensureResolved(resolution); | 719 // TODO(johnniwinther): Support this in mocks. |
| 747 return classElement.lookupConstructor("sync"); | 720 return _env.lookupLibraryMember(jsHelperLibrary, 'buildInterfaceType'); |
| 748 } | 721 } |
| 749 | 722 |
| 750 ClassElement get asyncStarController { | 723 FunctionEntity get buildFunctionType { |
| 751 ClassElement classElement = _findAsyncHelper("_AsyncStarStreamController"); | 724 // TODO(johnniwinther): Support this in mocks. |
|
Siggi Cherem (dart-lang)
2017/02/06 17:15:58
now that we are mainly using the memory compiler,
Johnni Winther
2017/02/07 09:12:16
Acknowledged.
| |
| 752 classElement.ensureResolved(resolution); | 725 return _env.lookupLibraryMember(jsHelperLibrary, 'buildFunctionType'); |
| 753 return classElement; | 726 } |
| 754 } | 727 |
| 755 | 728 FunctionEntity get buildNamedFunctionType { |
| 756 ConstructorElement get asyncStarControllerConstructor { | 729 // TODO(johnniwinther): Support this in mocks. |
| 757 ClassElement classElement = asyncStarController; | 730 return _env.lookupLibraryMember(jsHelperLibrary, 'buildNamedFunctionType'); |
| 758 return classElement.lookupConstructor(""); | 731 } |
| 759 } | 732 |
| 760 | 733 FunctionEntity get functionTypeTestMetaHelper => |
| 761 ConstructorElement get streamIteratorConstructor { | 734 _findHelperFunction('functionTypeTestMetaHelper'); |
| 762 ClassElement classElement = _find(asyncLibrary, "StreamIterator"); | 735 |
| 763 classElement.ensureResolved(resolution); | 736 FunctionEntity get defineProperty => _findHelperFunction('defineProperty'); |
| 764 return classElement.lookupConstructor(""); | 737 |
| 765 } | 738 FunctionEntity get startRootIsolate => |
| 766 | 739 _findLibraryMember(isolateHelperLibrary, START_ROOT_ISOLATE); |
| 767 ClassElement get VoidRuntimeType { | 740 |
| 768 return _findHelper('VoidRuntimeType'); | 741 FunctionEntity get currentIsolate => |
| 769 } | 742 _findLibraryMember(isolateHelperLibrary, '_currentIsolate'); |
| 770 | 743 |
| 771 ClassElement get RuntimeType { | 744 FunctionEntity get callInIsolate => |
| 772 return _findHelper('RuntimeType'); | 745 _findLibraryMember(isolateHelperLibrary, '_callInIsolate'); |
| 773 } | 746 |
| 774 | 747 FunctionEntity get findIndexForNativeSubclassType => |
| 775 ClassElement get RuntimeFunctionType { | 748 _findLibraryMember(interceptorsLibrary, 'findIndexForNativeSubclassType'); |
| 776 return _findHelper('RuntimeFunctionType'); | 749 |
| 777 } | 750 FunctionEntity get convertRtiToRuntimeType => |
| 778 | 751 _findHelperFunction('convertRtiToRuntimeType'); |
| 779 ClassElement get RuntimeTypePlain { | 752 |
| 780 return _findHelper('RuntimeTypePlain'); | 753 ClassEntity get stackTraceClass => _findHelperClass('_StackTrace'); |
| 781 } | 754 |
| 782 | 755 FunctionEntity _objectNoSuchMethod; |
| 783 ClassElement get RuntimeTypeGeneric { | 756 FunctionEntity get objectNoSuchMethod { |
| 784 return _findHelper('RuntimeTypeGeneric'); | 757 return _objectNoSuchMethod ??= _env.lookupClassMember( |
| 785 } | 758 commonElements.objectClass, Identifiers.noSuchMethod_); |
| 786 | 759 } |
| 787 ClassElement get DynamicRuntimeType { | 760 |
| 788 return _findHelper('DynamicRuntimeType'); | 761 ClassEntity get constantMapClass => |
| 789 } | 762 _findHelperClass(JavaScriptMapConstant.DART_CLASS); |
| 790 | 763 ClassEntity get constantStringMapClass => |
| 791 MethodElement get getDynamicRuntimeType { | 764 _findHelperClass(JavaScriptMapConstant.DART_STRING_CLASS); |
| 792 // TODO(johnniwinther): Support this in mocks. | 765 ClassEntity get constantProtoMapClass => |
| 793 return jsHelperLibrary.find('getDynamicRuntimeType'); | 766 _findHelperClass(JavaScriptMapConstant.DART_PROTO_CLASS); |
| 794 } | 767 ClassEntity get generalConstantMapClass => |
| 795 | 768 _findHelperClass(JavaScriptMapConstant.DART_GENERAL_CLASS); |
| 796 MethodElement get getVoidRuntimeType { | 769 |
| 797 // TODO(johnniwinther): Support this in mocks. | 770 ClassEntity get annotationCreatesClass => _findHelperClass('Creates'); |
| 798 return jsHelperLibrary.find('getVoidRuntimeType'); | 771 |
| 799 } | 772 ClassEntity get annotationReturnsClass => _findHelperClass('Returns'); |
| 800 | 773 |
| 801 MethodElement get buildInterfaceType { | 774 ClassEntity get annotationJSNameClass => _findHelperClass('JSName'); |
| 802 // TODO(johnniwinther): Support this in mocks. | 775 |
| 803 return jsHelperLibrary.find('buildInterfaceType'); | 776 FunctionEntity get toStringForNativeObject => |
| 804 } | 777 _findHelperFunction('toStringForNativeObject'); |
| 805 | 778 |
| 806 MethodElement get buildFunctionType { | 779 FunctionEntity get hashCodeForNativeObject => |
| 807 // TODO(johnniwinther): Support this in mocks. | 780 _findHelperFunction('hashCodeForNativeObject'); |
| 808 return jsHelperLibrary.find('buildFunctionType'); | |
| 809 } | |
| 810 | |
| 811 MethodElement get buildNamedFunctionType { | |
| 812 // TODO(johnniwinther): Support this in mocks. | |
| 813 return jsHelperLibrary.find('buildNamedFunctionType'); | |
| 814 } | |
| 815 | |
| 816 MethodElement get functionTypeTestMetaHelper { | |
| 817 return _findHelper('functionTypeTestMetaHelper'); | |
| 818 } | |
| 819 | |
| 820 MethodElement get defineProperty { | |
| 821 return _findHelper('defineProperty'); | |
| 822 } | |
| 823 | |
| 824 MethodElement get startRootIsolate { | |
| 825 return _find(isolateHelperLibrary, START_ROOT_ISOLATE); | |
| 826 } | |
| 827 | |
| 828 Element get currentIsolate { | |
| 829 return _find(isolateHelperLibrary, '_currentIsolate'); | |
| 830 } | |
| 831 | |
| 832 Element get callInIsolate { | |
| 833 return _find(isolateHelperLibrary, '_callInIsolate'); | |
| 834 } | |
| 835 | |
| 836 Element get findIndexForNativeSubclassType { | |
| 837 return _findInterceptor('findIndexForNativeSubclassType'); | |
| 838 } | |
| 839 | |
| 840 MethodElement get convertRtiToRuntimeType { | |
| 841 return _findHelper('convertRtiToRuntimeType'); | |
| 842 } | |
| 843 | |
| 844 ClassElement get stackTraceClass { | |
| 845 return _findHelper('_StackTrace'); | |
| 846 } | |
| 847 | |
| 848 MethodElement _objectNoSuchMethod; | |
| 849 | |
| 850 MethodElement get objectNoSuchMethod { | |
| 851 if (_objectNoSuchMethod == null) { | |
| 852 ClassElement objectClass = commonElements.objectClass; | |
| 853 _objectNoSuchMethod = | |
| 854 objectClass.lookupLocalMember(Identifiers.noSuchMethod_); | |
| 855 } | |
| 856 return _objectNoSuchMethod; | |
| 857 } | |
| 858 | |
| 859 ClassElement get constantMapClass => | |
| 860 _findHelper(JavaScriptMapConstant.DART_CLASS); | |
| 861 ClassElement get constantStringMapClass => | |
| 862 _findHelper(JavaScriptMapConstant.DART_STRING_CLASS); | |
| 863 ClassElement get constantProtoMapClass => | |
| 864 _findHelper(JavaScriptMapConstant.DART_PROTO_CLASS); | |
| 865 ClassElement get generalConstantMapClass => | |
| 866 _findHelper(JavaScriptMapConstant.DART_GENERAL_CLASS); | |
| 867 | |
| 868 ClassElement get annotationCreatesClass { | |
| 869 return _findHelper('Creates'); | |
| 870 } | |
| 871 | |
| 872 ClassElement get annotationReturnsClass { | |
| 873 return _findHelper('Returns'); | |
| 874 } | |
| 875 | |
| 876 ClassElement get annotationJSNameClass { | |
| 877 return _findHelper('JSName'); | |
| 878 } | |
| 879 | |
| 880 MethodElement get toStringForNativeObject { | |
| 881 return _findHelper('toStringForNativeObject'); | |
| 882 } | |
| 883 | |
| 884 MethodElement get hashCodeForNativeObject { | |
| 885 return _findHelper('hashCodeForNativeObject'); | |
| 886 } | |
| 887 } | 781 } |
| 782 | |
| 783 class BackendHelpersImpl extends BackendHelpers { | |
|
Siggi Cherem (dart-lang)
2017/02/06 17:15:58
Any reason why not make BackendHelpers concrete an
Johnni Winther
2017/02/07 09:12:16
No ;) Done.
| |
| 784 final Compiler _compiler; | |
| 785 | |
| 786 BackendHelpersImpl(this._compiler); | |
| 787 | |
| 788 ElementEnvironment get _env => _compiler.elementEnvironment; | |
| 789 | |
| 790 JavaScriptBackend get backend => _compiler.backend; | |
| 791 | |
| 792 CommonElements get commonElements => _compiler.commonElements; | |
| 793 } | |
| OLD | NEW |