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 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 } else if (cls == compiler.boundClosureClass) { | 793 } else if (cls == compiler.boundClosureClass) { |
794 // TODO(ngeoffray): Move the bound closure class in the | 794 // TODO(ngeoffray): Move the bound closure class in the |
795 // backend. | 795 // backend. |
796 enqueueClass(enqueuer, compiler.boundClosureClass, elements); | 796 enqueueClass(enqueuer, compiler.boundClosureClass, elements); |
797 } else if (Elements.isNativeOrExtendsNative(cls)) { | 797 } else if (Elements.isNativeOrExtendsNative(cls)) { |
798 enqueue(enqueuer, getNativeInterceptorMethod, elements); | 798 enqueue(enqueuer, getNativeInterceptorMethod, elements); |
799 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); | 799 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); |
800 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, elements); | 800 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, elements); |
801 } | 801 } |
802 } | 802 } |
| 803 if (cls == compiler.closureClass) { |
| 804 enqueue(enqueuer, |
| 805 compiler.findHelper('closureFromTearOff'), |
| 806 elements); |
| 807 } |
803 ClassElement result = null; | 808 ClassElement result = null; |
804 if (cls == compiler.stringClass || cls == jsStringClass) { | 809 if (cls == compiler.stringClass || cls == jsStringClass) { |
805 addInterceptors(jsStringClass, enqueuer, elements); | 810 addInterceptors(jsStringClass, enqueuer, elements); |
806 } else if (cls == compiler.listClass | 811 } else if (cls == compiler.listClass |
807 || cls == jsArrayClass | 812 || cls == jsArrayClass |
808 || cls == jsFixedArrayClass | 813 || cls == jsFixedArrayClass |
809 || cls == jsExtendableArrayClass) { | 814 || cls == jsExtendableArrayClass) { |
810 addInterceptors(jsArrayClass, enqueuer, elements); | 815 addInterceptors(jsArrayClass, enqueuer, elements); |
811 addInterceptors(jsMutableArrayClass, enqueuer, elements); | 816 addInterceptors(jsMutableArrayClass, enqueuer, elements); |
812 addInterceptors(jsFixedArrayClass, enqueuer, elements); | 817 addInterceptors(jsFixedArrayClass, enqueuer, elements); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 void registerTypeVariableExpression(TreeElements elements) { | 976 void registerTypeVariableExpression(TreeElements elements) { |
972 enqueueInResolution(getSetRuntimeTypeInfo(), elements); | 977 enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
973 enqueueInResolution(getGetRuntimeTypeInfo(), elements); | 978 enqueueInResolution(getGetRuntimeTypeInfo(), elements); |
974 registerGetRuntimeTypeArgument(elements); | 979 registerGetRuntimeTypeArgument(elements); |
975 enqueueClass(compiler.enqueuer.resolution, compiler.listClass, elements); | 980 enqueueClass(compiler.enqueuer.resolution, compiler.listClass, elements); |
976 enqueueInResolution(getRuntimeTypeToString(), elements); | 981 enqueueInResolution(getRuntimeTypeToString(), elements); |
977 enqueueInResolution(getCreateRuntimeType(), elements); | 982 enqueueInResolution(getCreateRuntimeType(), elements); |
978 } | 983 } |
979 | 984 |
980 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { | 985 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { |
| 986 enqueueInResolution(getThrowRuntimeError(), elements); |
981 type = type.unalias(compiler); | 987 type = type.unalias(compiler); |
982 enqueueClass(world, compiler.boolClass, elements); | 988 enqueueClass(world, compiler.boolClass, elements); |
983 bool inCheckedMode = compiler.enableTypeAssertions; | 989 bool inCheckedMode = compiler.enableTypeAssertions; |
984 // [registerIsCheck] is also called for checked mode checks, so we | 990 // [registerIsCheck] is also called for checked mode checks, so we |
985 // need to register checked mode helpers. | 991 // need to register checked mode helpers. |
986 if (inCheckedMode) { | 992 if (inCheckedMode) { |
987 if (!world.isResolutionQueue) { | 993 if (!world.isResolutionQueue) { |
988 // All helpers are added to resolution queue in enqueueHelpers. These | 994 // All helpers are added to resolution queue in enqueueHelpers. These |
989 // calls to enqueueInResolution serve as assertions that the helper was | 995 // calls to enqueueInResolution serve as assertions that the helper was |
990 // in fact added. | 996 // in fact added. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 // We will neeed to add the "$is" and "$as" properties on the | 1034 // We will neeed to add the "$is" and "$as" properties on the |
1029 // JavaScript object prototype, so we make sure | 1035 // JavaScript object prototype, so we make sure |
1030 // [:defineProperty:] is compiled. | 1036 // [:defineProperty:] is compiled. |
1031 enqueue(world, | 1037 enqueue(world, |
1032 compiler.findHelper('defineProperty'), | 1038 compiler.findHelper('defineProperty'), |
1033 elements); | 1039 elements); |
1034 } | 1040 } |
1035 } | 1041 } |
1036 | 1042 |
1037 void registerAsCheck(DartType type, Enqueuer world, TreeElements elements) { | 1043 void registerAsCheck(DartType type, Enqueuer world, TreeElements elements) { |
| 1044 enqueueInResolution(getThrowRuntimeError(), elements); |
1038 type = type.unalias(compiler); | 1045 type = type.unalias(compiler); |
1039 if (!world.isResolutionQueue) { | 1046 if (!world.isResolutionQueue) { |
1040 // All helpers are added to resolution queue in enqueueHelpers. These | 1047 // All helpers are added to resolution queue in enqueueHelpers. These |
1041 // calls to enqueueInResolution serve as assertions that the helper was in | 1048 // calls to enqueueInResolution serve as assertions that the helper was in |
1042 // fact added. | 1049 // fact added. |
1043 // TODO(13155): Find a way to enqueue helpers lazily. | 1050 // TODO(13155): Find a way to enqueue helpers lazily. |
1044 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: true); | 1051 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: true); |
1045 enqueueInResolution(helper.getElement(compiler), elements); | 1052 enqueueInResolution(helper.getElement(compiler), elements); |
1046 // We also need the native variant of the check (for DOM types). | 1053 // We also need the native variant of the check (for DOM types). |
1047 helper = getNativeCheckedModeHelper(type, typeCast: true); | 1054 helper = getNativeCheckedModeHelper(type, typeCast: true); |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1705 /** | 1712 /** |
1706 * Returns `true` if [element] can be accessed through reflection, that is, | 1713 * Returns `true` if [element] can be accessed through reflection, that is, |
1707 * is in the set of elements covered by a `MirrorsUsed` annotation. | 1714 * is in the set of elements covered by a `MirrorsUsed` annotation. |
1708 * | 1715 * |
1709 * This property is used to tag emitted elements with a marker which is | 1716 * This property is used to tag emitted elements with a marker which is |
1710 * checked by the runtime system to throw an exception if an element is | 1717 * checked by the runtime system to throw an exception if an element is |
1711 * accessed (invoked, get, set) that is not accessible for the reflective | 1718 * accessed (invoked, get, set) that is not accessible for the reflective |
1712 * system. | 1719 * system. |
1713 */ | 1720 */ |
1714 bool isAccessibleByReflection(Element element) { | 1721 bool isAccessibleByReflection(Element element) { |
| 1722 // TODO(ahe): This isn't sufficient: simply importing dart:mirrors |
| 1723 // causes hasInsufficientMirrorsUsed to become true. |
1715 if (hasInsufficientMirrorsUsed) return true; | 1724 if (hasInsufficientMirrorsUsed) return true; |
1716 return isNeededForReflection(element); | 1725 return isNeededForReflection(element); |
1717 } | 1726 } |
1718 | 1727 |
1719 /** | 1728 /** |
1720 * Returns `true` if the emitter must emit the element even though there | 1729 * Returns `true` if the emitter must emit the element even though there |
1721 * is no direct use in the program, but because the reflective system may | 1730 * is no direct use in the program, but because the reflective system may |
1722 * need to access it. | 1731 * need to access it. |
1723 */ | 1732 */ |
1724 bool isNeededForReflection(Element element) { | 1733 bool isNeededForReflection(Element element) { |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1942 copy(constant.values); | 1951 copy(constant.values); |
1943 copy(constant.protoValue); | 1952 copy(constant.protoValue); |
1944 copy(constant); | 1953 copy(constant); |
1945 } | 1954 } |
1946 | 1955 |
1947 void visitConstructed(ConstructedConstant constant) { | 1956 void visitConstructed(ConstructedConstant constant) { |
1948 copy(constant.fields); | 1957 copy(constant.fields); |
1949 copy(constant); | 1958 copy(constant); |
1950 } | 1959 } |
1951 } | 1960 } |
OLD | NEW |