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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
8 | 8 |
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 static final Uri DART_FOREIGN_HELPER = | 226 static final Uri DART_FOREIGN_HELPER = |
227 new Uri(scheme: 'dart', path: '_foreign_helper'); | 227 new Uri(scheme: 'dart', path: '_foreign_helper'); |
228 static final Uri DART_JS_MIRRORS = | 228 static final Uri DART_JS_MIRRORS = |
229 new Uri(scheme: 'dart', path: '_js_mirrors'); | 229 new Uri(scheme: 'dart', path: '_js_mirrors'); |
230 static final Uri DART_JS_NAMES = | 230 static final Uri DART_JS_NAMES = |
231 new Uri(scheme: 'dart', path: '_js_names'); | 231 new Uri(scheme: 'dart', path: '_js_names'); |
232 static final Uri DART_EMBEDDED_NAMES = | 232 static final Uri DART_EMBEDDED_NAMES = |
233 new Uri(scheme: 'dart', path: '_js_embedded_names'); | 233 new Uri(scheme: 'dart', path: '_js_embedded_names'); |
234 static final Uri DART_ISOLATE_HELPER = | 234 static final Uri DART_ISOLATE_HELPER = |
235 new Uri(scheme: 'dart', path: '_isolate_helper'); | 235 new Uri(scheme: 'dart', path: '_isolate_helper'); |
236 static final Uri PACKAGE_JS = | |
237 new Uri(scheme: 'package', path: 'js/js.dart'); | |
236 static final Uri PACKAGE_LOOKUP_MAP = | 238 static final Uri PACKAGE_LOOKUP_MAP = |
237 new Uri(scheme: 'package', path: 'lookup_map/lookup_map.dart'); | 239 new Uri(scheme: 'package', path: 'lookup_map/lookup_map.dart'); |
238 | 240 |
239 static const String INVOKE_ON = '_getCachedInvocation'; | 241 static const String INVOKE_ON = '_getCachedInvocation'; |
240 static const String START_ROOT_ISOLATE = 'startRootIsolate'; | 242 static const String START_ROOT_ISOLATE = 'startRootIsolate'; |
241 | 243 |
242 | 244 |
243 String get patchVersion => emitter.patchVersion; | 245 String get patchVersion => emitter.patchVersion; |
244 | 246 |
245 bool get supportsReflection => emitter.emitter.supportsReflection; | 247 bool get supportsReflection => emitter.emitter.supportsReflection; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 ClassElement jsInterceptorClass; | 289 ClassElement jsInterceptorClass; |
288 ClassElement jsStringClass; | 290 ClassElement jsStringClass; |
289 ClassElement jsArrayClass; | 291 ClassElement jsArrayClass; |
290 ClassElement jsNumberClass; | 292 ClassElement jsNumberClass; |
291 ClassElement jsIntClass; | 293 ClassElement jsIntClass; |
292 ClassElement jsDoubleClass; | 294 ClassElement jsDoubleClass; |
293 ClassElement jsNullClass; | 295 ClassElement jsNullClass; |
294 ClassElement jsBoolClass; | 296 ClassElement jsBoolClass; |
295 ClassElement jsPlainJavaScriptObjectClass; | 297 ClassElement jsPlainJavaScriptObjectClass; |
296 ClassElement jsUnknownJavaScriptObjectClass; | 298 ClassElement jsUnknownJavaScriptObjectClass; |
299 ClassElement jsJavaScriptFunctionClass; | |
300 ClassElement jsJavaScriptObjectClass; | |
297 | 301 |
298 ClassElement jsIndexableClass; | 302 ClassElement jsIndexableClass; |
299 ClassElement jsMutableIndexableClass; | 303 ClassElement jsMutableIndexableClass; |
300 | 304 |
301 ClassElement jsMutableArrayClass; | 305 ClassElement jsMutableArrayClass; |
302 ClassElement jsFixedArrayClass; | 306 ClassElement jsFixedArrayClass; |
303 ClassElement jsExtendableArrayClass; | 307 ClassElement jsExtendableArrayClass; |
304 ClassElement jsUnmodifiableArrayClass; | 308 ClassElement jsUnmodifiableArrayClass; |
305 ClassElement jsPositiveIntClass; | 309 ClassElement jsPositiveIntClass; |
306 ClassElement jsUInt32Class; | 310 ClassElement jsUInt32Class; |
(...skipping 17 matching lines...) Expand all Loading... | |
324 ConstructorElement mapLiteralConstructorEmpty; | 328 ConstructorElement mapLiteralConstructorEmpty; |
325 Element mapLiteralUntypedMaker; | 329 Element mapLiteralUntypedMaker; |
326 Element mapLiteralUntypedEmptyMaker; | 330 Element mapLiteralUntypedEmptyMaker; |
327 | 331 |
328 ClassElement noSideEffectsClass; | 332 ClassElement noSideEffectsClass; |
329 ClassElement noThrowsClass; | 333 ClassElement noThrowsClass; |
330 ClassElement noInlineClass; | 334 ClassElement noInlineClass; |
331 ClassElement forceInlineClass; | 335 ClassElement forceInlineClass; |
332 ClassElement irRepresentationClass; | 336 ClassElement irRepresentationClass; |
333 | 337 |
338 ClassElement jsAnnotationClass; | |
339 | |
334 Element getInterceptorMethod; | 340 Element getInterceptorMethod; |
335 | 341 |
336 ClassElement jsInvocationMirrorClass; | 342 ClassElement jsInvocationMirrorClass; |
337 | 343 |
338 ClassElement typedArrayClass; | 344 ClassElement typedArrayClass; |
339 ClassElement typedArrayOfIntClass; | 345 ClassElement typedArrayOfIntClass; |
340 | 346 |
341 /// If [true], the compiler will emit code that logs whenever a method is | 347 /// If [true], the compiler will emit code that logs whenever a method is |
342 /// called. When TRACE_METHOD is 'console' this will be logged | 348 /// called. When TRACE_METHOD is 'console' this will be logged |
343 /// directly in the JavaScript console. When TRACE_METHOD is 'post' the | 349 /// directly in the JavaScript console. When TRACE_METHOD is 'post' the |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 /// Number of methods compiled before considering reflection. | 618 /// Number of methods compiled before considering reflection. |
613 int preMirrorsMethodCount = 0; | 619 int preMirrorsMethodCount = 0; |
614 | 620 |
615 /// Resolution and codegen support for generating table of interceptors and | 621 /// Resolution and codegen support for generating table of interceptors and |
616 /// constructors for custom elements. | 622 /// constructors for custom elements. |
617 CustomElementsAnalysis customElementsAnalysis; | 623 CustomElementsAnalysis customElementsAnalysis; |
618 | 624 |
619 /// Codegen support for tree-shaking entries of `LookupMap`. | 625 /// Codegen support for tree-shaking entries of `LookupMap`. |
620 LookupMapAnalysis lookupMapAnalysis; | 626 LookupMapAnalysis lookupMapAnalysis; |
621 | 627 |
628 /// Codegen support for typed JavaScript interop. | |
629 JsInteropAnalysis jsInteropAnalysis; | |
630 | |
622 /// Support for classifying `noSuchMethod` implementations. | 631 /// Support for classifying `noSuchMethod` implementations. |
623 NoSuchMethodRegistry noSuchMethodRegistry; | 632 NoSuchMethodRegistry noSuchMethodRegistry; |
624 | 633 |
625 JavaScriptConstantTask constantCompilerTask; | 634 JavaScriptConstantTask constantCompilerTask; |
626 | 635 |
627 JavaScriptResolutionCallbacks resolutionCallbacks; | 636 JavaScriptResolutionCallbacks resolutionCallbacks; |
628 | 637 |
629 PatchResolverTask patchResolverTask; | 638 PatchResolverTask patchResolverTask; |
630 | 639 |
631 bool enabledNoSuchMethod = false; | 640 bool enabledNoSuchMethod = false; |
(...skipping 14 matching lines...) Expand all Loading... | |
646 ? (useNewSourceInfo | 655 ? (useNewSourceInfo |
647 ? const PositionSourceInformationStrategy() | 656 ? const PositionSourceInformationStrategy() |
648 : const StartEndSourceInformationStrategy()) | 657 : const StartEndSourceInformationStrategy()) |
649 : const JavaScriptSourceInformationStrategy(), | 658 : const JavaScriptSourceInformationStrategy(), |
650 super(compiler) { | 659 super(compiler) { |
651 emitter = new CodeEmitterTask( | 660 emitter = new CodeEmitterTask( |
652 compiler, namer, generateSourceMap, useStartupEmitter); | 661 compiler, namer, generateSourceMap, useStartupEmitter); |
653 typeVariableHandler = new TypeVariableHandler(compiler); | 662 typeVariableHandler = new TypeVariableHandler(compiler); |
654 customElementsAnalysis = new CustomElementsAnalysis(this); | 663 customElementsAnalysis = new CustomElementsAnalysis(this); |
655 lookupMapAnalysis = new LookupMapAnalysis(this); | 664 lookupMapAnalysis = new LookupMapAnalysis(this); |
665 jsInteropAnalysis = new JsInteropAnalysis(this); | |
666 | |
656 noSuchMethodRegistry = new NoSuchMethodRegistry(this); | 667 noSuchMethodRegistry = new NoSuchMethodRegistry(this); |
657 constantCompilerTask = new JavaScriptConstantTask(compiler); | 668 constantCompilerTask = new JavaScriptConstantTask(compiler); |
658 resolutionCallbacks = new JavaScriptResolutionCallbacks(this); | 669 resolutionCallbacks = new JavaScriptResolutionCallbacks(this); |
659 patchResolverTask = new PatchResolverTask(compiler); | 670 patchResolverTask = new PatchResolverTask(compiler); |
660 functionCompiler = compiler.useCpsIr | 671 functionCompiler = compiler.useCpsIr |
661 ? new CpsFunctionCompiler( | 672 ? new CpsFunctionCompiler( |
662 compiler, this, sourceInformationStrategy) | 673 compiler, this, sourceInformationStrategy) |
663 : new SsaFunctionCompiler(this, sourceInformationStrategy); | 674 : new SsaFunctionCompiler(this, sourceInformationStrategy); |
664 } | 675 } |
665 | 676 |
666 ConstantSystem get constantSystem => constants.constantSystem; | 677 ConstantSystem get constantSystem => constants.constantSystem; |
667 | 678 |
668 Resolution get resolution => compiler.resolution; | 679 Resolution get resolution => compiler.resolution; |
669 | 680 |
670 /// Returns constant environment for the JavaScript interpretation of the | 681 /// Returns constant environment for the JavaScript interpretation of the |
671 /// constants. | 682 /// constants. |
672 JavaScriptConstantCompiler get constants { | 683 JavaScriptConstantCompiler get constants { |
673 return constantCompilerTask.jsConstantCompiler; | 684 return constantCompilerTask.jsConstantCompiler; |
674 } | 685 } |
675 | 686 |
676 FunctionElement resolveExternalFunction(FunctionElement element) { | 687 FunctionElement resolveExternalFunction(FunctionElement element) { |
677 if (isForeign(element)) return element; | 688 if (isForeign(element) || element.isJsInterop) return element; |
678 return patchResolverTask.measure(() { | 689 return patchResolverTask.measure(() { |
679 return patchResolverTask.resolveExternalFunction(element); | 690 return patchResolverTask.resolveExternalFunction(element); |
680 }); | 691 }); |
681 } | 692 } |
682 | 693 |
683 // TODO(karlklose): Split into findHelperFunction and findHelperClass and | 694 // TODO(karlklose): Split into findHelperFunction and findHelperClass and |
684 // add a check that the element has the expected kind. | 695 // add a check that the element has the expected kind. |
685 Element findHelper(String name) => find(jsHelperLibrary, name); | 696 Element findHelper(String name) => find(jsHelperLibrary, name); |
686 Element findAsyncHelper(String name) => find(asyncLibrary, name); | 697 Element findAsyncHelper(String name) => find(asyncLibrary, name); |
687 Element findInterceptor(String name) => find(interceptorsLibrary, name); | 698 Element findInterceptor(String name) => find(interceptorsLibrary, name); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
896 // differences. | 907 // differences. |
897 assert(interceptorMember.enclosingClass == interceptorClass); | 908 assert(interceptorMember.enclosingClass == interceptorClass); |
898 }); | 909 }); |
899 } | 910 } |
900 | 911 |
901 void addInterceptorsForNativeClassMembers( | 912 void addInterceptorsForNativeClassMembers( |
902 ClassElement cls, Enqueuer enqueuer) { | 913 ClassElement cls, Enqueuer enqueuer) { |
903 if (enqueuer.isResolutionQueue) { | 914 if (enqueuer.isResolutionQueue) { |
904 cls.ensureResolved(resolution); | 915 cls.ensureResolved(resolution); |
905 cls.forEachMember((ClassElement classElement, Element member) { | 916 cls.forEachMember((ClassElement classElement, Element member) { |
917 // TODO(jacobr): this is the wrong place to be reporting errors. | |
918 // Reporting the error here will result in the error being reported | |
919 // multiple times. | |
906 if (member.name == Identifiers.call) { | 920 if (member.name == Identifiers.call) { |
907 compiler.reportErrorMessage( | 921 compiler.reportErrorMessage( |
908 member, | 922 member, |
909 MessageKind.CALL_NOT_SUPPORTED_ON_NATIVE_CLASS); | 923 MessageKind.CALL_NOT_SUPPORTED_ON_NATIVE_CLASS); |
910 return; | 924 return; |
911 } | 925 } |
912 if (member.isSynthesized) return; | 926 if (member.isSynthesized) return; |
913 // All methods on [Object] are shadowed by [Interceptor]. | 927 // All methods on [Object] are shadowed by [Interceptor]. |
914 if (classElement == compiler.objectClass) return; | 928 if (classElement == compiler.objectClass) return; |
915 Set<Element> set = interceptedElements.putIfAbsent( | 929 Set<Element> set = interceptedElements.putIfAbsent( |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1070 enqueueClass(enqueuer, mapLiteralClass, registry); | 1084 enqueueClass(enqueuer, mapLiteralClass, registry); |
1071 // For map literals, the dependency between the implementation class | 1085 // For map literals, the dependency between the implementation class |
1072 // and [Map] is not visible, so we have to add it manually. | 1086 // and [Map] is not visible, so we have to add it manually. |
1073 rti.registerRtiDependency(mapLiteralClass, cls); | 1087 rti.registerRtiDependency(mapLiteralClass, cls); |
1074 } else if (cls == boundClosureClass) { | 1088 } else if (cls == boundClosureClass) { |
1075 // TODO(johnniwinther): Is this a noop? | 1089 // TODO(johnniwinther): Is this a noop? |
1076 enqueueClass(enqueuer, boundClosureClass, registry); | 1090 enqueueClass(enqueuer, boundClosureClass, registry); |
1077 } else if (Elements.isNativeOrExtendsNative(cls)) { | 1091 } else if (Elements.isNativeOrExtendsNative(cls)) { |
1078 enqueue(enqueuer, getNativeInterceptorMethod, registry); | 1092 enqueue(enqueuer, getNativeInterceptorMethod, registry); |
1079 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); | 1093 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); |
1094 enqueueClass(enqueuer, jsJavaScriptObjectClass, registry); | |
1080 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, registry); | 1095 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, registry); |
1096 enqueueClass(enqueuer, jsJavaScriptFunctionClass, registry); | |
1081 } else if (cls == mapLiteralClass) { | 1097 } else if (cls == mapLiteralClass) { |
1082 // For map literals, the dependency between the implementation class | 1098 // For map literals, the dependency between the implementation class |
1083 // and [Map] is not visible, so we have to add it manually. | 1099 // and [Map] is not visible, so we have to add it manually. |
1084 Element getFactory(String name, int arity) { | 1100 Element getFactory(String name, int arity) { |
1085 // The constructor is on the patch class, but dart2js unit tests don't | 1101 // The constructor is on the patch class, but dart2js unit tests don't |
1086 // have a patch class. | 1102 // have a patch class. |
1087 ClassElement implementation = cls.patch != null ? cls.patch : cls; | 1103 ClassElement implementation = cls.patch != null ? cls.patch : cls; |
1088 ConstructorElement ctor = implementation.lookupConstructor(name); | 1104 ConstructorElement ctor = implementation.lookupConstructor(name); |
1089 if (ctor == null | 1105 if (ctor == null |
1090 || (Name.isPrivateName(name) | 1106 || (Name.isPrivateName(name) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1147 addInterceptors(jsBoolClass, enqueuer, registry); | 1163 addInterceptors(jsBoolClass, enqueuer, registry); |
1148 } else if (cls == compiler.nullClass || cls == jsNullClass) { | 1164 } else if (cls == compiler.nullClass || cls == jsNullClass) { |
1149 addInterceptors(jsNullClass, enqueuer, registry); | 1165 addInterceptors(jsNullClass, enqueuer, registry); |
1150 } else if (cls == compiler.numClass || cls == jsNumberClass) { | 1166 } else if (cls == compiler.numClass || cls == jsNumberClass) { |
1151 addInterceptors(jsIntClass, enqueuer, registry); | 1167 addInterceptors(jsIntClass, enqueuer, registry); |
1152 addInterceptors(jsPositiveIntClass, enqueuer, registry); | 1168 addInterceptors(jsPositiveIntClass, enqueuer, registry); |
1153 addInterceptors(jsUInt32Class, enqueuer, registry); | 1169 addInterceptors(jsUInt32Class, enqueuer, registry); |
1154 addInterceptors(jsUInt31Class, enqueuer, registry); | 1170 addInterceptors(jsUInt31Class, enqueuer, registry); |
1155 addInterceptors(jsDoubleClass, enqueuer, registry); | 1171 addInterceptors(jsDoubleClass, enqueuer, registry); |
1156 addInterceptors(jsNumberClass, enqueuer, registry); | 1172 addInterceptors(jsNumberClass, enqueuer, registry); |
1173 } else if (cls == jsJavaScriptObjectClass) { | |
1174 addInterceptors(jsJavaScriptObjectClass, enqueuer, registry); | |
1157 } else if (cls == jsPlainJavaScriptObjectClass) { | 1175 } else if (cls == jsPlainJavaScriptObjectClass) { |
1158 addInterceptors(jsPlainJavaScriptObjectClass, enqueuer, registry); | 1176 addInterceptors(jsPlainJavaScriptObjectClass, enqueuer, registry); |
1159 } else if (cls == jsUnknownJavaScriptObjectClass) { | 1177 } else if (cls == jsUnknownJavaScriptObjectClass) { |
1160 addInterceptors(jsUnknownJavaScriptObjectClass, enqueuer, registry); | 1178 addInterceptors(jsUnknownJavaScriptObjectClass, enqueuer, registry); |
1179 } else if (cls == jsJavaScriptFunctionClass) { | |
1180 addInterceptors(jsJavaScriptFunctionClass, enqueuer, registry); | |
1161 } else if (Elements.isNativeOrExtendsNative(cls)) { | 1181 } else if (Elements.isNativeOrExtendsNative(cls)) { |
1162 addInterceptorsForNativeClassMembers(cls, enqueuer); | 1182 addInterceptorsForNativeClassMembers(cls, enqueuer); |
1163 } else if (cls == jsIndexingBehaviorInterface) { | 1183 } else if (cls == jsIndexingBehaviorInterface) { |
1164 // These two helpers are used by the emitter and the codegen. | 1184 // These two helpers are used by the emitter and the codegen. |
1165 // Because we cannot enqueue elements at the time of emission, | 1185 // Because we cannot enqueue elements at the time of emission, |
1166 // we make sure they are always generated. | 1186 // we make sure they are always generated. |
1167 enqueue(enqueuer, findHelper('isJsIndexable'), registry); | 1187 enqueue(enqueuer, findHelper('isJsIndexable'), registry); |
1168 } | 1188 } |
1169 | 1189 |
1170 customElementsAnalysis.registerInstantiatedClass(cls, enqueuer); | 1190 customElementsAnalysis.registerInstantiatedClass(cls, enqueuer); |
1171 if (!enqueuer.isResolutionQueue) { | 1191 if (!enqueuer.isResolutionQueue) { |
1172 lookupMapAnalysis.registerInstantiatedClass(cls); | 1192 lookupMapAnalysis.registerInstantiatedClass(cls); |
1173 } | 1193 } |
1174 } | 1194 } |
1175 | 1195 |
1176 void registerInstantiatedType(InterfaceType type, | 1196 void registerInstantiatedType(InterfaceType type, |
1177 Enqueuer enqueuer, | 1197 Enqueuer enqueuer, |
1178 Registry registry, | 1198 Registry registry, |
1179 {bool mirrorUsage: false}) { | 1199 {bool mirrorUsage: false}) { |
1180 lookupMapAnalysis.registerInstantiatedType(type, registry); | 1200 lookupMapAnalysis.registerInstantiatedType(type, registry); |
1181 super.registerInstantiatedType( | 1201 super.registerInstantiatedType( |
1182 type, enqueuer, registry, mirrorUsage: mirrorUsage); | 1202 type, enqueuer, registry, mirrorUsage: mirrorUsage); |
1183 } | 1203 } |
1184 | 1204 |
1185 void registerUseInterceptor(Enqueuer enqueuer) { | 1205 void registerUseInterceptor(Enqueuer enqueuer) { |
1186 assert(!enqueuer.isResolutionQueue); | 1206 assert(!enqueuer.isResolutionQueue); |
1187 if (!enqueuer.nativeEnqueuer.hasInstantiatedNativeClasses()) return; | 1207 if (!enqueuer.nativeEnqueuer.hasInstantiatedNativeClasses()) return; |
1188 Registry registry = compiler.globalDependencies; | 1208 Registry registry = compiler.globalDependencies; |
1189 enqueue(enqueuer, getNativeInterceptorMethod, registry); | 1209 enqueue(enqueuer, getNativeInterceptorMethod, registry); |
1210 enqueueClass(enqueuer, jsJavaScriptObjectClass, registry); | |
1190 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, registry); | 1211 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, registry); |
1212 enqueueClass(enqueuer, jsJavaScriptFunctionClass, registry); | |
1191 needToInitializeIsolateAffinityTag = true; | 1213 needToInitializeIsolateAffinityTag = true; |
1192 needToInitializeDispatchProperty = true; | 1214 needToInitializeDispatchProperty = true; |
1193 } | 1215 } |
1194 | 1216 |
1195 JavaScriptItemCompilationContext createItemCompilationContext() { | 1217 JavaScriptItemCompilationContext createItemCompilationContext() { |
1196 return new JavaScriptItemCompilationContext(); | 1218 return new JavaScriptItemCompilationContext(); |
1197 } | 1219 } |
1198 | 1220 |
1199 void enqueueHelpers(ResolutionEnqueuer world, Registry registry) { | 1221 void enqueueHelpers(ResolutionEnqueuer world, Registry registry) { |
1200 assert(interceptorsLibrary != null); | 1222 assert(interceptorsLibrary != null); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1543 | 1565 |
1544 native.NativeEnqueuer nativeResolutionEnqueuer(Enqueuer world) { | 1566 native.NativeEnqueuer nativeResolutionEnqueuer(Enqueuer world) { |
1545 return new native.NativeResolutionEnqueuer(world, compiler); | 1567 return new native.NativeResolutionEnqueuer(world, compiler); |
1546 } | 1568 } |
1547 | 1569 |
1548 native.NativeEnqueuer nativeCodegenEnqueuer(Enqueuer world) { | 1570 native.NativeEnqueuer nativeCodegenEnqueuer(Enqueuer world) { |
1549 return new native.NativeCodegenEnqueuer(world, compiler, emitter); | 1571 return new native.NativeCodegenEnqueuer(world, compiler, emitter); |
1550 } | 1572 } |
1551 | 1573 |
1552 ClassElement defaultSuperclass(ClassElement element) { | 1574 ClassElement defaultSuperclass(ClassElement element) { |
1575 if (element.isJsInterop) return jsJavaScriptObjectClass; | |
1553 // Native classes inherit from Interceptor. | 1576 // Native classes inherit from Interceptor. |
1554 return element.isNative ? jsInterceptorClass : compiler.objectClass; | 1577 return element.isNative ? jsInterceptorClass : compiler.objectClass; |
1555 } | 1578 } |
1556 | 1579 |
1557 /** | 1580 /** |
1558 * Unit test hook that returns code of an element as a String. | 1581 * Unit test hook that returns code of an element as a String. |
1559 * | 1582 * |
1560 * Invariant: [element] must be a declaration element. | 1583 * Invariant: [element] must be a declaration element. |
1561 */ | 1584 */ |
1562 String getGeneratedCode(Element element) { | 1585 String getGeneratedCode(Element element) { |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2171 jsUInt31Class = findClass('JSUInt31'); | 2194 jsUInt31Class = findClass('JSUInt31'); |
2172 jsDoubleClass = findClass('JSDouble'); | 2195 jsDoubleClass = findClass('JSDouble'); |
2173 jsNumberClass = findClass('JSNumber'); | 2196 jsNumberClass = findClass('JSNumber'); |
2174 jsNullClass = findClass('JSNull'); | 2197 jsNullClass = findClass('JSNull'); |
2175 jsBoolClass = findClass('JSBool'); | 2198 jsBoolClass = findClass('JSBool'); |
2176 jsMutableArrayClass = findClass('JSMutableArray'); | 2199 jsMutableArrayClass = findClass('JSMutableArray'); |
2177 jsFixedArrayClass = findClass('JSFixedArray'); | 2200 jsFixedArrayClass = findClass('JSFixedArray'); |
2178 jsExtendableArrayClass = findClass('JSExtendableArray'); | 2201 jsExtendableArrayClass = findClass('JSExtendableArray'); |
2179 jsUnmodifiableArrayClass = findClass('JSUnmodifiableArray'); | 2202 jsUnmodifiableArrayClass = findClass('JSUnmodifiableArray'); |
2180 jsPlainJavaScriptObjectClass = findClass('PlainJavaScriptObject'); | 2203 jsPlainJavaScriptObjectClass = findClass('PlainJavaScriptObject'); |
2204 jsJavaScriptObjectClass = findClass('JavaScriptObject'); | |
2205 jsJavaScriptFunctionClass = findClass('JavaScriptFunction'); | |
2181 jsUnknownJavaScriptObjectClass = findClass('UnknownJavaScriptObject'); | 2206 jsUnknownJavaScriptObjectClass = findClass('UnknownJavaScriptObject'); |
2182 jsIndexableClass = findClass('JSIndexable'); | 2207 jsIndexableClass = findClass('JSIndexable'); |
2183 jsMutableIndexableClass = findClass('JSMutableIndexable'); | 2208 jsMutableIndexableClass = findClass('JSMutableIndexable'); |
2184 } else if (uri == DART_JS_HELPER) { | 2209 } else if (uri == DART_JS_HELPER) { |
2185 initializeHelperClasses(); | 2210 initializeHelperClasses(); |
2186 assertTestMethod = findHelper('assertTest'); | 2211 assertTestMethod = findHelper('assertTest'); |
2187 assertThrowMethod = findHelper('assertThrow'); | 2212 assertThrowMethod = findHelper('assertThrow'); |
2188 assertHelperMethod = findHelper('assertHelper'); | 2213 assertHelperMethod = findHelper('assertHelper'); |
2189 assertUnreachableMethod = findHelper('assertUnreachable'); | 2214 assertUnreachableMethod = findHelper('assertUnreachable'); |
2190 | 2215 |
(...skipping 22 matching lines...) Expand all Loading... | |
2213 } else if (uri == DART_EMBEDDED_NAMES) { | 2238 } else if (uri == DART_EMBEDDED_NAMES) { |
2214 jsGetNameEnum = find(library, 'JsGetName'); | 2239 jsGetNameEnum = find(library, 'JsGetName'); |
2215 jsBuiltinEnum = find(library, 'JsBuiltin'); | 2240 jsBuiltinEnum = find(library, 'JsBuiltin'); |
2216 } else if (uri == Uris.dart_html) { | 2241 } else if (uri == Uris.dart_html) { |
2217 htmlLibraryIsLoaded = true; | 2242 htmlLibraryIsLoaded = true; |
2218 } else if (uri == PACKAGE_LOOKUP_MAP) { | 2243 } else if (uri == PACKAGE_LOOKUP_MAP) { |
2219 lookupMapAnalysis.init(library); | 2244 lookupMapAnalysis.init(library); |
2220 } else if (uri == Uris.dart__native_typed_data) { | 2245 } else if (uri == Uris.dart__native_typed_data) { |
2221 typedArrayClass = findClass('NativeTypedArray'); | 2246 typedArrayClass = findClass('NativeTypedArray'); |
2222 typedArrayOfIntClass = findClass('NativeTypedArrayOfInt'); | 2247 typedArrayOfIntClass = findClass('NativeTypedArrayOfInt'); |
2248 } else if (uri == PACKAGE_JS) { | |
2249 jsAnnotationClass = find(library, 'Js'); | |
2223 } | 2250 } |
2224 annotations.onLibraryScanned(library); | 2251 annotations.onLibraryScanned(library); |
2225 }); | 2252 }); |
2226 } | 2253 } |
2227 | 2254 |
2228 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { | 2255 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { |
2229 if (!loadedLibraries.containsLibrary(Uris.dart_core)) { | 2256 if (!loadedLibraries.containsLibrary(Uris.dart_core)) { |
2230 return new Future.value(); | 2257 return new Future.value(); |
2231 } | 2258 } |
2232 | 2259 |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2659 addForEmission: false); | 2686 addForEmission: false); |
2660 } | 2687 } |
2661 metadataConstants.clear(); | 2688 metadataConstants.clear(); |
2662 } | 2689 } |
2663 } | 2690 } |
2664 return true; | 2691 return true; |
2665 } | 2692 } |
2666 | 2693 |
2667 void onQueueClosed() { | 2694 void onQueueClosed() { |
2668 lookupMapAnalysis.onQueueClosed(); | 2695 lookupMapAnalysis.onQueueClosed(); |
2696 jsInteropAnalysis.onQueueClosed(); | |
Siggi Cherem (dart-lang)
2015/10/13 02:08:53
should we check that we only run this logic once?
Jacob
2015/10/13 03:10:42
Added a bool in JsInteropAnalysis to track whether
| |
2669 } | 2697 } |
2670 | 2698 |
2671 void onCodegenStart() { | 2699 void onCodegenStart() { |
2672 lookupMapAnalysis.onCodegenStart(); | 2700 lookupMapAnalysis.onCodegenStart(); |
2673 } | 2701 } |
2674 | 2702 |
2675 void onElementResolved(Element element, TreeElements elements) { | 2703 void onElementResolved(Element element, TreeElements elements) { |
2676 if ((element.isFunction || element.isGenerativeConstructor) && | 2704 if ((element.isFunction || element.isGenerativeConstructor) && |
2677 annotations.noInline(element)) { | 2705 annotations.noInline(element)) { |
2678 inlineCache.markAsNonInlinable(element); | 2706 inlineCache.markAsNonInlinable(element); |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3237 } | 3265 } |
3238 } | 3266 } |
3239 | 3267 |
3240 /// Records that [constant] is used by the element behind [registry]. | 3268 /// Records that [constant] is used by the element behind [registry]. |
3241 class Dependency { | 3269 class Dependency { |
3242 final ConstantValue constant; | 3270 final ConstantValue constant; |
3243 final Element annotatedElement; | 3271 final Element annotatedElement; |
3244 | 3272 |
3245 const Dependency(this.constant, this.annotatedElement); | 3273 const Dependency(this.constant, this.annotatedElement); |
3246 } | 3274 } |
OLD | NEW |