| 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 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 } else if (cls == compiler.boundClosureClass) { | 804 } else if (cls == compiler.boundClosureClass) { |
| 805 // TODO(ngeoffray): Move the bound closure class in the | 805 // TODO(ngeoffray): Move the bound closure class in the |
| 806 // backend. | 806 // backend. |
| 807 enqueueClass(enqueuer, compiler.boundClosureClass, elements); | 807 enqueueClass(enqueuer, compiler.boundClosureClass, elements); |
| 808 } else if (Elements.isNativeOrExtendsNative(cls)) { | 808 } else if (Elements.isNativeOrExtendsNative(cls)) { |
| 809 enqueue(enqueuer, getNativeInterceptorMethod, elements); | 809 enqueue(enqueuer, getNativeInterceptorMethod, elements); |
| 810 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); | 810 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); |
| 811 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, elements); | 811 enqueueClass(enqueuer, jsPlainJavaScriptObjectClass, elements); |
| 812 } | 812 } |
| 813 } | 813 } |
| 814 if (cls == compiler.closureClass) { |
| 815 enqueue(enqueuer, |
| 816 compiler.findHelper('closureFromTearOff'), |
| 817 elements); |
| 818 } |
| 814 ClassElement result = null; | 819 ClassElement result = null; |
| 815 if (cls == compiler.stringClass || cls == jsStringClass) { | 820 if (cls == compiler.stringClass || cls == jsStringClass) { |
| 816 addInterceptors(jsStringClass, enqueuer, elements); | 821 addInterceptors(jsStringClass, enqueuer, elements); |
| 817 } else if (cls == compiler.listClass | 822 } else if (cls == compiler.listClass |
| 818 || cls == jsArrayClass | 823 || cls == jsArrayClass |
| 819 || cls == jsFixedArrayClass | 824 || cls == jsFixedArrayClass |
| 820 || cls == jsExtendableArrayClass) { | 825 || cls == jsExtendableArrayClass) { |
| 821 addInterceptors(jsArrayClass, enqueuer, elements); | 826 addInterceptors(jsArrayClass, enqueuer, elements); |
| 822 addInterceptors(jsMutableArrayClass, enqueuer, elements); | 827 addInterceptors(jsMutableArrayClass, enqueuer, elements); |
| 823 addInterceptors(jsFixedArrayClass, enqueuer, elements); | 828 addInterceptors(jsFixedArrayClass, enqueuer, elements); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 void registerTypeVariableExpression(TreeElements elements) { | 989 void registerTypeVariableExpression(TreeElements elements) { |
| 985 enqueueInResolution(getSetRuntimeTypeInfo(), elements); | 990 enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
| 986 enqueueInResolution(getGetRuntimeTypeInfo(), elements); | 991 enqueueInResolution(getGetRuntimeTypeInfo(), elements); |
| 987 registerGetRuntimeTypeArgument(elements); | 992 registerGetRuntimeTypeArgument(elements); |
| 988 enqueueClass(compiler.enqueuer.resolution, compiler.listClass, elements); | 993 enqueueClass(compiler.enqueuer.resolution, compiler.listClass, elements); |
| 989 enqueueInResolution(getRuntimeTypeToString(), elements); | 994 enqueueInResolution(getRuntimeTypeToString(), elements); |
| 990 enqueueInResolution(getCreateRuntimeType(), elements); | 995 enqueueInResolution(getCreateRuntimeType(), elements); |
| 991 } | 996 } |
| 992 | 997 |
| 993 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { | 998 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { |
| 999 enqueueInResolution(getThrowRuntimeError(), elements); |
| 994 type = type.unalias(compiler); | 1000 type = type.unalias(compiler); |
| 995 enqueueClass(world, compiler.boolClass, elements); | 1001 enqueueClass(world, compiler.boolClass, elements); |
| 996 bool inCheckedMode = compiler.enableTypeAssertions; | 1002 bool inCheckedMode = compiler.enableTypeAssertions; |
| 997 // [registerIsCheck] is also called for checked mode checks, so we | 1003 // [registerIsCheck] is also called for checked mode checks, so we |
| 998 // need to register checked mode helpers. | 1004 // need to register checked mode helpers. |
| 999 if (inCheckedMode) { | 1005 if (inCheckedMode) { |
| 1000 if (!world.isResolutionQueue) { | 1006 if (!world.isResolutionQueue) { |
| 1001 // All helpers are added to resolution queue in enqueueHelpers. These | 1007 // All helpers are added to resolution queue in enqueueHelpers. These |
| 1002 // calls to enqueueInResolution serve as assertions that the helper was | 1008 // calls to enqueueInResolution serve as assertions that the helper was |
| 1003 // in fact added. | 1009 // in fact added. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 // We will neeed to add the "$is" and "$as" properties on the | 1047 // We will neeed to add the "$is" and "$as" properties on the |
| 1042 // JavaScript object prototype, so we make sure | 1048 // JavaScript object prototype, so we make sure |
| 1043 // [:defineProperty:] is compiled. | 1049 // [:defineProperty:] is compiled. |
| 1044 enqueue(world, | 1050 enqueue(world, |
| 1045 compiler.findHelper('defineProperty'), | 1051 compiler.findHelper('defineProperty'), |
| 1046 elements); | 1052 elements); |
| 1047 } | 1053 } |
| 1048 } | 1054 } |
| 1049 | 1055 |
| 1050 void registerAsCheck(DartType type, Enqueuer world, TreeElements elements) { | 1056 void registerAsCheck(DartType type, Enqueuer world, TreeElements elements) { |
| 1057 enqueueInResolution(getThrowRuntimeError(), elements); |
| 1051 type = type.unalias(compiler); | 1058 type = type.unalias(compiler); |
| 1052 if (!world.isResolutionQueue) { | 1059 if (!world.isResolutionQueue) { |
| 1053 // All helpers are added to resolution queue in enqueueHelpers. These | 1060 // All helpers are added to resolution queue in enqueueHelpers. These |
| 1054 // calls to enqueueInResolution serve as assertions that the helper was in | 1061 // calls to enqueueInResolution serve as assertions that the helper was in |
| 1055 // fact added. | 1062 // fact added. |
| 1056 // TODO(13155): Find a way to enqueue helpers lazily. | 1063 // TODO(13155): Find a way to enqueue helpers lazily. |
| 1057 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: true); | 1064 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: true); |
| 1058 enqueueInResolution(helper.getElement(compiler), elements); | 1065 enqueueInResolution(helper.getElement(compiler), elements); |
| 1059 // We also need the native variant of the check (for DOM types). | 1066 // We also need the native variant of the check (for DOM types). |
| 1060 helper = getNativeCheckedModeHelper(type, typeCast: true); | 1067 helper = getNativeCheckedModeHelper(type, typeCast: true); |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1725 /** | 1732 /** |
| 1726 * Returns `true` if [element] can be accessed through reflection, that is, | 1733 * Returns `true` if [element] can be accessed through reflection, that is, |
| 1727 * is in the set of elements covered by a `MirrorsUsed` annotation. | 1734 * is in the set of elements covered by a `MirrorsUsed` annotation. |
| 1728 * | 1735 * |
| 1729 * This property is used to tag emitted elements with a marker which is | 1736 * This property is used to tag emitted elements with a marker which is |
| 1730 * checked by the runtime system to throw an exception if an element is | 1737 * checked by the runtime system to throw an exception if an element is |
| 1731 * accessed (invoked, get, set) that is not accessible for the reflective | 1738 * accessed (invoked, get, set) that is not accessible for the reflective |
| 1732 * system. | 1739 * system. |
| 1733 */ | 1740 */ |
| 1734 bool isAccessibleByReflection(Element element) { | 1741 bool isAccessibleByReflection(Element element) { |
| 1742 // TODO(ahe): This isn't sufficient: simply importing dart:mirrors |
| 1743 // causes hasInsufficientMirrorsUsed to become true. |
| 1735 if (hasInsufficientMirrorsUsed) return true; | 1744 if (hasInsufficientMirrorsUsed) return true; |
| 1736 return isNeededForReflection(element); | 1745 return isNeededForReflection(element); |
| 1737 } | 1746 } |
| 1738 | 1747 |
| 1739 /** | 1748 /** |
| 1740 * Returns `true` if the emitter must emit the element even though there | 1749 * Returns `true` if the emitter must emit the element even though there |
| 1741 * is no direct use in the program, but because the reflective system may | 1750 * is no direct use in the program, but because the reflective system may |
| 1742 * need to access it. | 1751 * need to access it. |
| 1743 */ | 1752 */ |
| 1744 bool isNeededForReflection(Element element) { | 1753 bool isNeededForReflection(Element element) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1955 copy(constant.values); | 1964 copy(constant.values); |
| 1956 copy(constant.protoValue); | 1965 copy(constant.protoValue); |
| 1957 copy(constant); | 1966 copy(constant); |
| 1958 } | 1967 } |
| 1959 | 1968 |
| 1960 void visitConstructed(ConstructedConstant constant) { | 1969 void visitConstructed(ConstructedConstant constant) { |
| 1961 copy(constant.fields); | 1970 copy(constant.fields); |
| 1962 copy(constant); | 1971 copy(constant); |
| 1963 } | 1972 } |
| 1964 } | 1973 } |
| OLD | NEW |