| 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 ClassElement jsInterceptorClass; | 282 ClassElement jsInterceptorClass; |
| 283 ClassElement jsStringClass; | 283 ClassElement jsStringClass; |
| 284 ClassElement jsArrayClass; | 284 ClassElement jsArrayClass; |
| 285 ClassElement jsNumberClass; | 285 ClassElement jsNumberClass; |
| 286 ClassElement jsIntClass; | 286 ClassElement jsIntClass; |
| 287 ClassElement jsDoubleClass; | 287 ClassElement jsDoubleClass; |
| 288 ClassElement jsNullClass; | 288 ClassElement jsNullClass; |
| 289 ClassElement jsBoolClass; | 289 ClassElement jsBoolClass; |
| 290 ClassElement jsPlainJavaScriptObjectClass; | 290 ClassElement jsPlainJavaScriptObjectClass; |
| 291 ClassElement jsUnknownJavaScriptObjectClass; | 291 ClassElement jsUnknownJavaScriptObjectClass; |
| 292 ClassElement jsJavaScriptFunctionClass; |
| 292 | 293 |
| 293 ClassElement jsIndexableClass; | 294 ClassElement jsIndexableClass; |
| 294 ClassElement jsMutableIndexableClass; | 295 ClassElement jsMutableIndexableClass; |
| 295 | 296 |
| 296 ClassElement jsMutableArrayClass; | 297 ClassElement jsMutableArrayClass; |
| 297 ClassElement jsFixedArrayClass; | 298 ClassElement jsFixedArrayClass; |
| 298 ClassElement jsExtendableArrayClass; | 299 ClassElement jsExtendableArrayClass; |
| 299 ClassElement jsUnmodifiableArrayClass; | 300 ClassElement jsUnmodifiableArrayClass; |
| 300 ClassElement jsPositiveIntClass; | 301 ClassElement jsPositiveIntClass; |
| 301 ClassElement jsUInt32Class; | 302 ClassElement jsUInt32Class; |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 654 |
| 654 ConstantSystem get constantSystem => constants.constantSystem; | 655 ConstantSystem get constantSystem => constants.constantSystem; |
| 655 | 656 |
| 656 /// Returns constant environment for the JavaScript interpretation of the | 657 /// Returns constant environment for the JavaScript interpretation of the |
| 657 /// constants. | 658 /// constants. |
| 658 JavaScriptConstantCompiler get constants { | 659 JavaScriptConstantCompiler get constants { |
| 659 return constantCompilerTask.jsConstantCompiler; | 660 return constantCompilerTask.jsConstantCompiler; |
| 660 } | 661 } |
| 661 | 662 |
| 662 FunctionElement resolveExternalFunction(FunctionElement element) { | 663 FunctionElement resolveExternalFunction(FunctionElement element) { |
| 663 if (isForeign(element)) return element; | 664 if (isForeign(element) || element.isJsInterop) return element; |
| 664 return patchResolverTask.measure(() { | 665 return patchResolverTask.measure(() { |
| 665 return patchResolverTask.resolveExternalFunction(element); | 666 return patchResolverTask.resolveExternalFunction(element); |
| 666 }); | 667 }); |
| 667 } | 668 } |
| 668 | 669 |
| 669 // TODO(karlklose): Split into findHelperFunction and findHelperClass and | 670 // TODO(karlklose): Split into findHelperFunction and findHelperClass and |
| 670 // add a check that the element has the expected kind. | 671 // add a check that the element has the expected kind. |
| 671 Element findHelper(String name) => find(jsHelperLibrary, name); | 672 Element findHelper(String name) => find(jsHelperLibrary, name); |
| 672 Element findAsyncHelper(String name) => find(asyncLibrary, name); | 673 Element findAsyncHelper(String name) => find(asyncLibrary, name); |
| 673 Element findInterceptor(String name) => find(interceptorsLibrary, name); | 674 Element findInterceptor(String name) => find(interceptorsLibrary, name); |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 // For map literals, the dependency between the implementation class | 1033 // For map literals, the dependency between the implementation class |
| 1033 // and [Map] is not visible, so we have to add it manually. | 1034 // and [Map] is not visible, so we have to add it manually. |
| 1034 rti.registerRtiDependency(mapLiteralClass, cls); | 1035 rti.registerRtiDependency(mapLiteralClass, cls); |
| 1035 } else if (cls == boundClosureClass) { | 1036 } else if (cls == boundClosureClass) { |
| 1036 // TODO(johnniwinther): Is this a noop? | 1037 // TODO(johnniwinther): Is this a noop? |
| 1037 enqueueClass(enqueuer, boundClosureClass, registry); | 1038 enqueueClass(enqueuer, boundClosureClass, registry); |
| 1038 } else if (Elements.isNativeOrExtendsNative(cls)) { | 1039 } else if (Elements.isNativeOrExtendsNative(cls)) { |
| 1039 enqueue(enqueuer, getNativeInterceptorMethod, registry); | 1040 enqueue(enqueuer, getNativeInterceptorMethod, registry); |
| 1040 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); | 1041 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); |
| 1041 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, registry); | 1042 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, registry); |
| 1043 enqueueClass(enqueuer, jsJavaScriptFunctionClass, registry); |
| 1042 } else if (cls == mapLiteralClass) { | 1044 } else if (cls == mapLiteralClass) { |
| 1043 // For map literals, the dependency between the implementation class | 1045 // For map literals, the dependency between the implementation class |
| 1044 // and [Map] is not visible, so we have to add it manually. | 1046 // and [Map] is not visible, so we have to add it manually. |
| 1045 Element getFactory(String name, int arity) { | 1047 Element getFactory(String name, int arity) { |
| 1046 // The constructor is on the patch class, but dart2js unit tests don't | 1048 // The constructor is on the patch class, but dart2js unit tests don't |
| 1047 // have a patch class. | 1049 // have a patch class. |
| 1048 ClassElement implementation = cls.patch != null ? cls.patch : cls; | 1050 ClassElement implementation = cls.patch != null ? cls.patch : cls; |
| 1049 ConstructorElement ctor = implementation.lookupConstructor(name); | 1051 ConstructorElement ctor = implementation.lookupConstructor(name); |
| 1050 if (ctor == null | 1052 if (ctor == null |
| 1051 || (Name.isPrivateName(name) | 1053 || (Name.isPrivateName(name) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 addInterceptors(jsIntClass, enqueuer, registry); | 1114 addInterceptors(jsIntClass, enqueuer, registry); |
| 1113 addInterceptors(jsPositiveIntClass, enqueuer, registry); | 1115 addInterceptors(jsPositiveIntClass, enqueuer, registry); |
| 1114 addInterceptors(jsUInt32Class, enqueuer, registry); | 1116 addInterceptors(jsUInt32Class, enqueuer, registry); |
| 1115 addInterceptors(jsUInt31Class, enqueuer, registry); | 1117 addInterceptors(jsUInt31Class, enqueuer, registry); |
| 1116 addInterceptors(jsDoubleClass, enqueuer, registry); | 1118 addInterceptors(jsDoubleClass, enqueuer, registry); |
| 1117 addInterceptors(jsNumberClass, enqueuer, registry); | 1119 addInterceptors(jsNumberClass, enqueuer, registry); |
| 1118 } else if (cls == jsPlainJavaScriptObjectClass) { | 1120 } else if (cls == jsPlainJavaScriptObjectClass) { |
| 1119 addInterceptors(jsPlainJavaScriptObjectClass, enqueuer, registry); | 1121 addInterceptors(jsPlainJavaScriptObjectClass, enqueuer, registry); |
| 1120 } else if (cls == jsUnknownJavaScriptObjectClass) { | 1122 } else if (cls == jsUnknownJavaScriptObjectClass) { |
| 1121 addInterceptors(jsUnknownJavaScriptObjectClass, enqueuer, registry); | 1123 addInterceptors(jsUnknownJavaScriptObjectClass, enqueuer, registry); |
| 1124 } else if (cls == jsJavaScriptFunctionClass) { |
| 1125 addInterceptors(jsJavaScriptFunctionClass, enqueuer, registry); |
| 1122 } else if (Elements.isNativeOrExtendsNative(cls)) { | 1126 } else if (Elements.isNativeOrExtendsNative(cls)) { |
| 1123 addInterceptorsForNativeClassMembers(cls, enqueuer); | 1127 addInterceptorsForNativeClassMembers(cls, enqueuer); |
| 1124 } else if (cls == jsIndexingBehaviorInterface) { | 1128 } else if (cls == jsIndexingBehaviorInterface) { |
| 1125 // These two helpers are used by the emitter and the codegen. | 1129 // These two helpers are used by the emitter and the codegen. |
| 1126 // Because we cannot enqueue elements at the time of emission, | 1130 // Because we cannot enqueue elements at the time of emission, |
| 1127 // we make sure they are always generated. | 1131 // we make sure they are always generated. |
| 1128 enqueue(enqueuer, findHelper('isJsIndexable'), registry); | 1132 enqueue(enqueuer, findHelper('isJsIndexable'), registry); |
| 1129 } | 1133 } |
| 1130 | 1134 |
| 1131 customElementsAnalysis.registerInstantiatedClass(cls, enqueuer); | 1135 customElementsAnalysis.registerInstantiatedClass(cls, enqueuer); |
| 1132 } | 1136 } |
| 1133 | 1137 |
| 1134 void registerUseInterceptor(Enqueuer enqueuer) { | 1138 void registerUseInterceptor(Enqueuer enqueuer) { |
| 1135 assert(!enqueuer.isResolutionQueue); | 1139 assert(!enqueuer.isResolutionQueue); |
| 1136 if (!enqueuer.nativeEnqueuer.hasInstantiatedNativeClasses()) return; | 1140 if (!enqueuer.nativeEnqueuer.hasInstantiatedNativeClasses()) return; |
| 1137 Registry registry = compiler.globalDependencies; | 1141 Registry registry = compiler.globalDependencies; |
| 1138 enqueue(enqueuer, getNativeInterceptorMethod, registry); | 1142 enqueue(enqueuer, getNativeInterceptorMethod, registry); |
| 1139 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, registry); | 1143 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, registry); |
| 1144 enqueueClass(enqueuer, jsJavaScriptFunctionClass, registry); |
| 1140 needToInitializeIsolateAffinityTag = true; | 1145 needToInitializeIsolateAffinityTag = true; |
| 1141 needToInitializeDispatchProperty = true; | 1146 needToInitializeDispatchProperty = true; |
| 1142 } | 1147 } |
| 1143 | 1148 |
| 1144 JavaScriptItemCompilationContext createItemCompilationContext() { | 1149 JavaScriptItemCompilationContext createItemCompilationContext() { |
| 1145 return new JavaScriptItemCompilationContext(); | 1150 return new JavaScriptItemCompilationContext(); |
| 1146 } | 1151 } |
| 1147 | 1152 |
| 1148 void enqueueHelpers(ResolutionEnqueuer world, Registry registry) { | 1153 void enqueueHelpers(ResolutionEnqueuer world, Registry registry) { |
| 1149 assert(interceptorsLibrary != null); | 1154 assert(interceptorsLibrary != null); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1460 | 1465 |
| 1461 native.NativeEnqueuer nativeResolutionEnqueuer(Enqueuer world) { | 1466 native.NativeEnqueuer nativeResolutionEnqueuer(Enqueuer world) { |
| 1462 return new native.NativeResolutionEnqueuer(world, compiler); | 1467 return new native.NativeResolutionEnqueuer(world, compiler); |
| 1463 } | 1468 } |
| 1464 | 1469 |
| 1465 native.NativeEnqueuer nativeCodegenEnqueuer(Enqueuer world) { | 1470 native.NativeEnqueuer nativeCodegenEnqueuer(Enqueuer world) { |
| 1466 return new native.NativeCodegenEnqueuer(world, compiler, emitter); | 1471 return new native.NativeCodegenEnqueuer(world, compiler, emitter); |
| 1467 } | 1472 } |
| 1468 | 1473 |
| 1469 ClassElement defaultSuperclass(ClassElement element) { | 1474 ClassElement defaultSuperclass(ClassElement element) { |
| 1475 if (element.isJsInterop) return jsPlainJavaScriptObjectClass; |
| 1470 // Native classes inherit from Interceptor. | 1476 // Native classes inherit from Interceptor. |
| 1471 return element.isNative ? jsInterceptorClass : compiler.objectClass; | 1477 return element.isNative ? jsInterceptorClass : compiler.objectClass; |
| 1472 } | 1478 } |
| 1473 | 1479 |
| 1474 /** | 1480 /** |
| 1475 * Unit test hook that returns code of an element as a String. | 1481 * Unit test hook that returns code of an element as a String. |
| 1476 * | 1482 * |
| 1477 * Invariant: [element] must be a declaration element. | 1483 * Invariant: [element] must be a declaration element. |
| 1478 */ | 1484 */ |
| 1479 String assembleCode(Element element) { | 1485 String assembleCode(Element element) { |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2092 jsUInt31Class = findClass('JSUInt31'); | 2098 jsUInt31Class = findClass('JSUInt31'); |
| 2093 jsDoubleClass = findClass('JSDouble'); | 2099 jsDoubleClass = findClass('JSDouble'); |
| 2094 jsNumberClass = findClass('JSNumber'); | 2100 jsNumberClass = findClass('JSNumber'); |
| 2095 jsNullClass = findClass('JSNull'); | 2101 jsNullClass = findClass('JSNull'); |
| 2096 jsBoolClass = findClass('JSBool'); | 2102 jsBoolClass = findClass('JSBool'); |
| 2097 jsMutableArrayClass = findClass('JSMutableArray'); | 2103 jsMutableArrayClass = findClass('JSMutableArray'); |
| 2098 jsFixedArrayClass = findClass('JSFixedArray'); | 2104 jsFixedArrayClass = findClass('JSFixedArray'); |
| 2099 jsExtendableArrayClass = findClass('JSExtendableArray'); | 2105 jsExtendableArrayClass = findClass('JSExtendableArray'); |
| 2100 jsUnmodifiableArrayClass = findClass('JSUnmodifiableArray'); | 2106 jsUnmodifiableArrayClass = findClass('JSUnmodifiableArray'); |
| 2101 jsPlainJavaScriptObjectClass = findClass('PlainJavaScriptObject'); | 2107 jsPlainJavaScriptObjectClass = findClass('PlainJavaScriptObject'); |
| 2108 jsJavaScriptFunctionClass = findClass('JavaScriptFunction'); |
| 2102 jsUnknownJavaScriptObjectClass = findClass('UnknownJavaScriptObject'); | 2109 jsUnknownJavaScriptObjectClass = findClass('UnknownJavaScriptObject'); |
| 2103 jsIndexableClass = findClass('JSIndexable'); | 2110 jsIndexableClass = findClass('JSIndexable'); |
| 2104 jsMutableIndexableClass = findClass('JSMutableIndexable'); | 2111 jsMutableIndexableClass = findClass('JSMutableIndexable'); |
| 2105 } else if (uri == DART_JS_HELPER) { | 2112 } else if (uri == DART_JS_HELPER) { |
| 2106 initializeHelperClasses(); | 2113 initializeHelperClasses(); |
| 2107 assertMethod = findHelper('assertHelper'); | 2114 assertMethod = findHelper('assertHelper'); |
| 2108 | 2115 |
| 2109 typeLiteralClass = findClass('TypeImpl'); | 2116 typeLiteralClass = findClass('TypeImpl'); |
| 2110 constMapLiteralClass = findClass('ConstantMap'); | 2117 constMapLiteralClass = findClass('ConstantMap'); |
| 2111 typeVariableClass = findClass('TypeVariable'); | 2118 typeVariableClass = findClass('TypeVariable'); |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3098 } | 3105 } |
| 3099 } | 3106 } |
| 3100 | 3107 |
| 3101 /// Records that [constant] is used by the element behind [registry]. | 3108 /// Records that [constant] is used by the element behind [registry]. |
| 3102 class Dependency { | 3109 class Dependency { |
| 3103 final ConstantValue constant; | 3110 final ConstantValue constant; |
| 3104 final Element annotatedElement; | 3111 final Element annotatedElement; |
| 3105 | 3112 |
| 3106 const Dependency(this.constant, this.annotatedElement); | 3113 const Dependency(this.constant, this.annotatedElement); |
| 3107 } | 3114 } |
| OLD | NEW |