| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library js_backend.backend; | 5 library js_backend.backend; |
| 6 | 6 |
| 7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 import '../io/position_information.dart' show PositionSourceInformationStrategy; | 39 import '../io/position_information.dart' show PositionSourceInformationStrategy; |
| 40 import '../io/source_information.dart' show SourceInformationStrategy; | 40 import '../io/source_information.dart' show SourceInformationStrategy; |
| 41 import '../io/start_end_information.dart' | 41 import '../io/start_end_information.dart' |
| 42 show StartEndSourceInformationStrategy; | 42 show StartEndSourceInformationStrategy; |
| 43 import '../js/js.dart' as jsAst; | 43 import '../js/js.dart' as jsAst; |
| 44 import '../js/js.dart' show js; | 44 import '../js/js.dart' show js; |
| 45 import '../js/js_source_mapping.dart' show JavaScriptSourceInformationStrategy; | 45 import '../js/js_source_mapping.dart' show JavaScriptSourceInformationStrategy; |
| 46 import '../js/rewrite_async.dart'; | 46 import '../js/rewrite_async.dart'; |
| 47 import '../js_emitter/js_emitter.dart' show CodeEmitterTask; | 47 import '../js_emitter/js_emitter.dart' show CodeEmitterTask; |
| 48 import '../kernel/task.dart'; | 48 import '../kernel/task.dart'; |
| 49 import '../library_loader.dart' show LibraryLoader, LoadedLibraries; | 49 import '../library_loader.dart' show LoadedLibraries; |
| 50 import '../native/native.dart' as native; | 50 import '../native/native.dart' as native; |
| 51 import '../native/resolver.dart'; | 51 import '../native/resolver.dart'; |
| 52 import '../ssa/ssa.dart' show SsaFunctionCompiler; | 52 import '../ssa/ssa.dart' show SsaFunctionCompiler; |
| 53 import '../tracer.dart'; | 53 import '../tracer.dart'; |
| 54 import '../tree/tree.dart'; | 54 import '../tree/tree.dart'; |
| 55 import '../types/types.dart'; | 55 import '../types/types.dart'; |
| 56 import '../universe/call_structure.dart' show CallStructure; | 56 import '../universe/call_structure.dart' show CallStructure; |
| 57 import '../universe/selector.dart' show Selector; | 57 import '../universe/selector.dart' show Selector; |
| 58 import '../universe/world_builder.dart'; | 58 import '../universe/world_builder.dart'; |
| 59 import '../universe/use.dart' show ConstantUse, StaticUse; | 59 import '../universe/use.dart' show ConstantUse, StaticUse; |
| (...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 element == commonElements.intClass || | 1090 element == commonElements.intClass || |
| 1091 element == commonElements.doubleClass || | 1091 element == commonElements.doubleClass || |
| 1092 element == helpers.jsArrayClass || | 1092 element == helpers.jsArrayClass || |
| 1093 element == helpers.jsMutableArrayClass || | 1093 element == helpers.jsMutableArrayClass || |
| 1094 element == helpers.jsExtendableArrayClass || | 1094 element == helpers.jsExtendableArrayClass || |
| 1095 element == helpers.jsFixedArrayClass || | 1095 element == helpers.jsFixedArrayClass || |
| 1096 element == helpers.jsUnmodifiableArrayClass; | 1096 element == helpers.jsUnmodifiableArrayClass; |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 /// This method is called immediately after the [library] and its parts have | 1099 /// This method is called immediately after the [library] and its parts have |
| 1100 /// been scanned. | 1100 /// been loaded. |
| 1101 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { | 1101 void setAnnotations(LibraryElement library) { |
| 1102 if (!compiler.serialization.isDeserialized(library)) { | 1102 if (!compiler.serialization.isDeserialized(library)) { |
| 1103 if (canLibraryUseNative(library)) { | 1103 if (canLibraryUseNative(library)) { |
| 1104 library.forEachLocalMember((Element element) { | 1104 library.forEachLocalMember((Element element) { |
| 1105 if (element.isClass) { | 1105 if (element.isClass) { |
| 1106 checkNativeAnnotation(compiler, element, nativeBaseDataBuilder); | 1106 checkNativeAnnotation(compiler, element, nativeBaseDataBuilder); |
| 1107 } | 1107 } |
| 1108 }); | 1108 }); |
| 1109 } | 1109 } |
| 1110 checkJsInteropClassAnnotations(compiler, library, nativeBaseDataBuilder); | 1110 checkJsInteropClassAnnotations(compiler, library, nativeBaseDataBuilder); |
| 1111 } | 1111 } |
| 1112 if (library.isPlatformLibrary && | |
| 1113 // Don't patch library currently disallowed. | |
| 1114 !library.isSynthesized && | |
| 1115 !library.isPatched && | |
| 1116 // Don't patch deserialized libraries. | |
| 1117 !compiler.serialization.isDeserialized(library)) { | |
| 1118 // Apply patch, if any. | |
| 1119 Uri patchUri = compiler.resolvePatchUri(library.canonicalUri.path); | |
| 1120 if (patchUri != null) { | |
| 1121 return compiler.patchParser.patchLibrary(loader, patchUri, library); | |
| 1122 } | |
| 1123 } | |
| 1124 Uri uri = library.canonicalUri; | 1112 Uri uri = library.canonicalUri; |
| 1125 if (uri == Uris.dart_html) { | 1113 if (uri == Uris.dart_html) { |
| 1126 htmlLibraryIsLoaded = true; | 1114 htmlLibraryIsLoaded = true; |
| 1127 } else if (uri == LookupMapResolutionAnalysis.PACKAGE_LOOKUP_MAP) { | 1115 } else if (uri == LookupMapResolutionAnalysis.PACKAGE_LOOKUP_MAP) { |
| 1128 lookupMapResolutionAnalysis.init(library); | 1116 lookupMapResolutionAnalysis.init(library); |
| 1129 } | 1117 } |
| 1130 annotations.onLibraryScanned(library); | 1118 annotations.onLibraryLoaded(library); |
| 1131 return new Future.value(); | |
| 1132 } | 1119 } |
| 1133 | 1120 |
| 1134 /// This method is called when all new libraries loaded through | 1121 /// This method is called when all new libraries loaded through |
| 1135 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | 1122 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports |
| 1136 /// have been computed. | 1123 /// have been computed. |
| 1137 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { | 1124 void onLibrariesLoaded(LoadedLibraries loadedLibraries) { |
| 1138 if (!loadedLibraries.containsLibrary(Uris.dart_core)) { | 1125 if (loadedLibraries.containsLibrary(Uris.dart_core)) { |
| 1139 return new Future.value(); | 1126 helpers.onLibrariesLoaded(loadedLibraries); |
| 1127 |
| 1128 // These methods are overwritten with generated versions. |
| 1129 inlineCache.markAsNonInlinable(helpers.getInterceptorMethod, |
| 1130 insideLoop: true); |
| 1131 |
| 1132 specialOperatorEqClasses |
| 1133 ..add(commonElements.objectClass) |
| 1134 ..add(helpers.jsInterceptorClass) |
| 1135 ..add(helpers.jsNullClass); |
| 1140 } | 1136 } |
| 1141 | |
| 1142 helpers.onLibrariesLoaded(loadedLibraries); | |
| 1143 | |
| 1144 // These methods are overwritten with generated versions. | |
| 1145 inlineCache.markAsNonInlinable(helpers.getInterceptorMethod, | |
| 1146 insideLoop: true); | |
| 1147 | |
| 1148 specialOperatorEqClasses | |
| 1149 ..add(commonElements.objectClass) | |
| 1150 ..add(helpers.jsInterceptorClass) | |
| 1151 ..add(helpers.jsNullClass); | |
| 1152 | |
| 1153 return new Future.value(); | |
| 1154 } | 1137 } |
| 1155 | 1138 |
| 1156 jsAst.Call generateIsJsIndexableCall( | 1139 jsAst.Call generateIsJsIndexableCall( |
| 1157 jsAst.Expression use1, jsAst.Expression use2) { | 1140 jsAst.Expression use1, jsAst.Expression use2) { |
| 1158 String dispatchPropertyName = embeddedNames.DISPATCH_PROPERTY_NAME; | 1141 String dispatchPropertyName = embeddedNames.DISPATCH_PROPERTY_NAME; |
| 1159 jsAst.Expression dispatchProperty = | 1142 jsAst.Expression dispatchProperty = |
| 1160 emitter.generateEmbeddedGlobalAccess(dispatchPropertyName); | 1143 emitter.generateEmbeddedGlobalAccess(dispatchPropertyName); |
| 1161 | 1144 |
| 1162 // We pass the dispatch property record to the isJsIndexable | 1145 // We pass the dispatch property record to the isJsIndexable |
| 1163 // helper rather than reading it inside the helper to increase the | 1146 // helper rather than reading it inside the helper to increase the |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1390 emitter.staticFunctionAccess(helpers.yieldStar), | 1373 emitter.staticFunctionAccess(helpers.yieldStar), |
| 1391 bodyName: namer.deriveAsyncBodyName(name)); | 1374 bodyName: namer.deriveAsyncBodyName(name)); |
| 1392 break; | 1375 break; |
| 1393 default: | 1376 default: |
| 1394 assert(element.asyncMarker == AsyncMarker.SYNC); | 1377 assert(element.asyncMarker == AsyncMarker.SYNC); |
| 1395 return code; | 1378 return code; |
| 1396 } | 1379 } |
| 1397 return rewriter.rewrite(code); | 1380 return rewriter.rewrite(code); |
| 1398 } | 1381 } |
| 1399 | 1382 |
| 1400 /// The locations of js patch-files relative to the sdk-descriptors. | |
| 1401 static const _patchLocations = const <String, String>{ | |
| 1402 "async": "_internal/js_runtime/lib/async_patch.dart", | |
| 1403 "collection": "_internal/js_runtime/lib/collection_patch.dart", | |
| 1404 "convert": "_internal/js_runtime/lib/convert_patch.dart", | |
| 1405 "core": "_internal/js_runtime/lib/core_patch.dart", | |
| 1406 "developer": "_internal/js_runtime/lib/developer_patch.dart", | |
| 1407 "io": "_internal/js_runtime/lib/io_patch.dart", | |
| 1408 "isolate": "_internal/js_runtime/lib/isolate_patch.dart", | |
| 1409 "math": "_internal/js_runtime/lib/math_patch.dart", | |
| 1410 "mirrors": "_internal/js_runtime/lib/mirrors_patch.dart", | |
| 1411 "typed_data": "_internal/js_runtime/lib/typed_data_patch.dart", | |
| 1412 "_internal": "_internal/js_runtime/lib/internal_patch.dart" | |
| 1413 }; | |
| 1414 | |
| 1415 /// Returns the location of the patch-file associated with [libraryName] | |
| 1416 /// resolved from [plaformConfigUri]. | |
| 1417 /// | |
| 1418 /// Returns null if there is none. | |
| 1419 Uri resolvePatchUri(String libraryName, Uri platformConfigUri) { | |
| 1420 String patchLocation = _patchLocations[libraryName]; | |
| 1421 if (patchLocation == null) return null; | |
| 1422 return platformConfigUri.resolve(patchLocation); | |
| 1423 } | |
| 1424 | |
| 1425 /// Creates an impact strategy to use for compilation. | 1383 /// Creates an impact strategy to use for compilation. |
| 1426 ImpactStrategy createImpactStrategy( | 1384 ImpactStrategy createImpactStrategy( |
| 1427 {bool supportDeferredLoad: true, | 1385 {bool supportDeferredLoad: true, |
| 1428 bool supportDumpInfo: true, | 1386 bool supportDumpInfo: true, |
| 1429 bool supportSerialization: true}) { | 1387 bool supportSerialization: true}) { |
| 1430 return new JavaScriptImpactStrategy(resolution, compiler.dumpInfoTask, | 1388 return new JavaScriptImpactStrategy(resolution, compiler.dumpInfoTask, |
| 1431 supportDeferredLoad: supportDeferredLoad, | 1389 supportDeferredLoad: supportDeferredLoad, |
| 1432 supportDumpInfo: supportDumpInfo, | 1390 supportDumpInfo: supportDumpInfo, |
| 1433 supportSerialization: supportSerialization); | 1391 supportSerialization: supportSerialization); |
| 1434 } | 1392 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1603 return _backend.defaultSuperclass(element); | 1561 return _backend.defaultSuperclass(element); |
| 1604 } | 1562 } |
| 1605 | 1563 |
| 1606 @override | 1564 @override |
| 1607 bool isNativeClass(ClassEntity element) => | 1565 bool isNativeClass(ClassEntity element) => |
| 1608 _backend.nativeBaseData.isNativeClass(element); | 1566 _backend.nativeBaseData.isNativeClass(element); |
| 1609 | 1567 |
| 1610 @override | 1568 @override |
| 1611 bool isForeign(Element element) => _backend.isForeign(element); | 1569 bool isForeign(Element element) => _backend.isForeign(element); |
| 1612 } | 1570 } |
| OLD | NEW |