| 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; | 9 import '../common/resolution.dart' show Resolution; |
| 10 import '../compiler.dart' show Compiler; | 10 import '../compiler.dart' show Compiler; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 _find(jsHelperLibrary, name); | 210 _find(jsHelperLibrary, name); |
| 211 Element _findAsyncHelper(String name) => _find(asyncLibrary, name); | 211 Element _findAsyncHelper(String name) => _find(asyncLibrary, name); |
| 212 Element _findInterceptor(String name) => _find(interceptorsLibrary, name); | 212 Element _findInterceptor(String name) => _find(interceptorsLibrary, name); |
| 213 Element _find(LibraryElement library, String name) { | 213 Element _find(LibraryElement library, String name) { |
| 214 Element element = library.implementation.findLocal(name); | 214 Element element = library.implementation.findLocal(name); |
| 215 assert(invariant(library, element != null, | 215 assert(invariant(library, element != null, |
| 216 message: "Element '$name' not found in '${library.canonicalUri}'.")); | 216 message: "Element '$name' not found in '${library.canonicalUri}'.")); |
| 217 return element; | 217 return element; |
| 218 } | 218 } |
| 219 | 219 |
| 220 Element findCoreHelper(String name) => | 220 Element findCoreHelper(String name) { |
| 221 compiler.commonElements.coreLibrary.implementation.localLookup(name); | 221 LibraryElement coreLibrary = compiler.commonElements.coreLibrary; |
| 222 return coreLibrary.implementation.localLookup(name); |
| 223 } |
| 222 | 224 |
| 223 ConstructorElement _findConstructor(ClassElement cls, String name) { | 225 ConstructorElement _findConstructor(ClassElement cls, String name) { |
| 224 cls.ensureResolved(resolution); | 226 cls.ensureResolved(resolution); |
| 225 ConstructorElement constructor = cls.lookupConstructor(name); | 227 ConstructorElement constructor = cls.lookupConstructor(name); |
| 226 assert(invariant(cls, constructor != null, | 228 assert(invariant(cls, constructor != null, |
| 227 message: "Constructor '$name' not found in '${cls}'.")); | 229 message: "Constructor '$name' not found in '${cls}'.")); |
| 228 return constructor; | 230 return constructor; |
| 229 } | 231 } |
| 230 | 232 |
| 231 void onLibraryCreated(LibraryElement library) { | 233 void onLibraryCreated(LibraryElement library) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 assert(loadedLibraries.containsLibrary(DART_INTERCEPTORS)); | 351 assert(loadedLibraries.containsLibrary(DART_INTERCEPTORS)); |
| 350 assert(loadedLibraries.containsLibrary(DART_JS_HELPER)); | 352 assert(loadedLibraries.containsLibrary(DART_JS_HELPER)); |
| 351 | 353 |
| 352 if (jsInvocationMirrorClass != null) { | 354 if (jsInvocationMirrorClass != null) { |
| 353 jsInvocationMirrorClass.ensureResolved(resolution); | 355 jsInvocationMirrorClass.ensureResolved(resolution); |
| 354 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON); | 356 invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON); |
| 355 } | 357 } |
| 356 | 358 |
| 357 // [LinkedHashMap] is reexported from dart:collection and can therefore not | 359 // [LinkedHashMap] is reexported from dart:collection and can therefore not |
| 358 // be loaded from dart:core in [onLibraryScanned]. | 360 // be loaded from dart:core in [onLibraryScanned]. |
| 359 mapLiteralClass = compiler.commonElements.coreLibrary.find('LinkedHashMap'); | 361 LibraryElement coreLibrary = compiler.commonElements.coreLibrary; |
| 362 mapLiteralClass = coreLibrary.find('LinkedHashMap'); |
| 360 assert(invariant( | 363 assert(invariant( |
| 361 compiler.commonElements.coreLibrary, mapLiteralClass != null, | 364 compiler.commonElements.coreLibrary, mapLiteralClass != null, |
| 362 message: "Element 'LinkedHashMap' not found in 'dart:core'.")); | 365 message: "Element 'LinkedHashMap' not found in 'dart:core'.")); |
| 363 | 366 |
| 364 // TODO(kasperl): Some tests do not define the special JSArray | 367 // TODO(kasperl): Some tests do not define the special JSArray |
| 365 // subclasses, so we check to see if they are defined before | 368 // subclasses, so we check to see if they are defined before |
| 366 // trying to resolve them. | 369 // trying to resolve them. |
| 367 if (jsFixedArrayClass != null) { | 370 if (jsFixedArrayClass != null) { |
| 368 jsFixedArrayClass.ensureResolved(resolution); | 371 jsFixedArrayClass.ensureResolved(resolution); |
| 369 } | 372 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 388 jsArrayClass.ensureResolved(resolution); | 391 jsArrayClass.ensureResolved(resolution); |
| 389 jsArrayTypedConstructor = compiler.lookupElementIn(jsArrayClass, 'typed'); | 392 jsArrayTypedConstructor = compiler.lookupElementIn(jsArrayClass, 'typed'); |
| 390 jsArrayRemoveLast = compiler.lookupElementIn(jsArrayClass, 'removeLast'); | 393 jsArrayRemoveLast = compiler.lookupElementIn(jsArrayClass, 'removeLast'); |
| 391 jsArrayAdd = compiler.lookupElementIn(jsArrayClass, 'add'); | 394 jsArrayAdd = compiler.lookupElementIn(jsArrayClass, 'add'); |
| 392 | 395 |
| 393 jsStringClass.ensureResolved(resolution); | 396 jsStringClass.ensureResolved(resolution); |
| 394 jsStringSplit = compiler.lookupElementIn(jsStringClass, 'split'); | 397 jsStringSplit = compiler.lookupElementIn(jsStringClass, 'split'); |
| 395 jsStringOperatorAdd = compiler.lookupElementIn(jsStringClass, '+'); | 398 jsStringOperatorAdd = compiler.lookupElementIn(jsStringClass, '+'); |
| 396 jsStringToString = compiler.lookupElementIn(jsStringClass, 'toString'); | 399 jsStringToString = compiler.lookupElementIn(jsStringClass, 'toString'); |
| 397 | 400 |
| 398 objectEquals = compiler.lookupElementIn(commonElements.objectClass, '=='); | 401 ClassElement objectClass = commonElements.objectClass; |
| 402 objectEquals = compiler.lookupElementIn(objectClass, '=='); |
| 399 } | 403 } |
| 400 | 404 |
| 401 ConstructorElement _mapLiteralConstructor; | 405 ConstructorElement _mapLiteralConstructor; |
| 402 ConstructorElement _mapLiteralConstructorEmpty; | 406 ConstructorElement _mapLiteralConstructorEmpty; |
| 403 Element _mapLiteralUntypedMaker; | 407 Element _mapLiteralUntypedMaker; |
| 404 Element _mapLiteralUntypedEmptyMaker; | 408 Element _mapLiteralUntypedEmptyMaker; |
| 405 | 409 |
| 406 ConstructorElement get mapLiteralConstructor { | 410 ConstructorElement get mapLiteralConstructor { |
| 407 _ensureMapLiteralHelpers(); | 411 _ensureMapLiteralHelpers(); |
| 408 return _mapLiteralConstructor; | 412 return _mapLiteralConstructor; |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 } | 844 } |
| 841 | 845 |
| 842 ClassElement get stackTraceClass { | 846 ClassElement get stackTraceClass { |
| 843 return _findHelper('_StackTrace'); | 847 return _findHelper('_StackTrace'); |
| 844 } | 848 } |
| 845 | 849 |
| 846 MethodElement _objectNoSuchMethod; | 850 MethodElement _objectNoSuchMethod; |
| 847 | 851 |
| 848 MethodElement get objectNoSuchMethod { | 852 MethodElement get objectNoSuchMethod { |
| 849 if (_objectNoSuchMethod == null) { | 853 if (_objectNoSuchMethod == null) { |
| 850 _objectNoSuchMethod = commonElements.objectClass | 854 ClassElement objectClass = commonElements.objectClass; |
| 851 .lookupLocalMember(Identifiers.noSuchMethod_); | 855 _objectNoSuchMethod = |
| 856 objectClass.lookupLocalMember(Identifiers.noSuchMethod_); |
| 852 } | 857 } |
| 853 return _objectNoSuchMethod; | 858 return _objectNoSuchMethod; |
| 854 } | 859 } |
| 855 | 860 |
| 856 ClassElement get constantMapClass => | 861 ClassElement get constantMapClass => |
| 857 _findHelper(JavaScriptMapConstant.DART_CLASS); | 862 _findHelper(JavaScriptMapConstant.DART_CLASS); |
| 858 ClassElement get constantStringMapClass => | 863 ClassElement get constantStringMapClass => |
| 859 _findHelper(JavaScriptMapConstant.DART_STRING_CLASS); | 864 _findHelper(JavaScriptMapConstant.DART_STRING_CLASS); |
| 860 ClassElement get constantProtoMapClass => | 865 ClassElement get constantProtoMapClass => |
| 861 _findHelper(JavaScriptMapConstant.DART_PROTO_CLASS); | 866 _findHelper(JavaScriptMapConstant.DART_PROTO_CLASS); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 875 } | 880 } |
| 876 | 881 |
| 877 MethodElement get toStringForNativeObject { | 882 MethodElement get toStringForNativeObject { |
| 878 return _findHelper('toStringForNativeObject'); | 883 return _findHelper('toStringForNativeObject'); |
| 879 } | 884 } |
| 880 | 885 |
| 881 MethodElement get hashCodeForNativeObject { | 886 MethodElement get hashCodeForNativeObject { |
| 882 return _findHelper('hashCodeForNativeObject'); | 887 return _findHelper('hashCodeForNativeObject'); |
| 883 } | 888 } |
| 884 } | 889 } |
| OLD | NEW |