| 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 /** | 7 /** |
| 8 * A function element that represents a closure call. The signature is copied | 8 * A function element that represents a closure call. The signature is copied |
| 9 * from the given element. | 9 * from the given element. |
| 10 */ | 10 */ |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 // for (var staticName in isolateProperties) { | 872 // for (var staticName in isolateProperties) { |
| 873 js.forIn('staticName', 'isolateProperties', [ | 873 js.forIn('staticName', 'isolateProperties', [ |
| 874 js.if_('hasOwnProperty.call(isolateProperties, staticName)', [ | 874 js.if_('hasOwnProperty.call(isolateProperties, staticName)', [ |
| 875 js('str += ("this." + staticName + "= properties." + staticName + ' | 875 js('str += ("this." + staticName + "= properties." + staticName + ' |
| 876 '";\\n")') | 876 '";\\n")') |
| 877 ]) | 877 ]) |
| 878 ]), | 878 ]), |
| 879 | 879 |
| 880 js('str += "}\\n"'), | 880 js('str += "}\\n"'), |
| 881 | 881 |
| 882 js('var Constants = #', js.fun('', [])), |
| 883 // Install 'C' as a prototype to ensure it has a hidden class. |
| 884 js('Constants.prototype = ${namer.globalObjectForConstant(null)}'), |
| 885 |
| 882 js('var newIsolate = new Function(str)'), | 886 js('var newIsolate = new Function(str)'), |
| 883 js('newIsolate.prototype = isolatePrototype'), | 887 js('newIsolate.prototype = isolatePrototype'), |
| 884 js('isolatePrototype.constructor = newIsolate'), | 888 js('isolatePrototype.constructor = newIsolate'), |
| 885 js('newIsolate.${namer.isolatePropertiesName} = isolateProperties'), | 889 js('newIsolate.${namer.isolatePropertiesName} = isolateProperties'), |
| 886 // TODO(ahe): Only copy makeConstantList when it is used. | 890 // TODO(ahe): Only copy makeConstantList when it is used. |
| 887 js('newIsolate.makeConstantList = oldIsolate.makeConstantList'), | 891 js('newIsolate.makeConstantList = oldIsolate.makeConstantList'), |
| 888 ]..addAll(copyFinishClasses) | 892 ]..addAll(copyFinishClasses) |
| 889 ..addAll([ | 893 ..addAll([ |
| 890 | 894 |
| 891 // return newIsolate; | 895 // return newIsolate; |
| (...skipping 1784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2676 jsAst.Expression buildLazyInitializedGetter(VariableElement element) { | 2680 jsAst.Expression buildLazyInitializedGetter(VariableElement element) { |
| 2677 // Nothing to do, the 'lazy' function will create the getter. | 2681 // Nothing to do, the 'lazy' function will create the getter. |
| 2678 return null; | 2682 return null; |
| 2679 } | 2683 } |
| 2680 | 2684 |
| 2681 void emitCompileTimeConstants(CodeBuffer eagerBuffer) { | 2685 void emitCompileTimeConstants(CodeBuffer eagerBuffer) { |
| 2682 ConstantHandler handler = compiler.constantHandler; | 2686 ConstantHandler handler = compiler.constantHandler; |
| 2683 List<Constant> constants = handler.getConstantsForEmission( | 2687 List<Constant> constants = handler.getConstantsForEmission( |
| 2684 compareConstants); | 2688 compareConstants); |
| 2685 bool addedMakeConstantList = false; | 2689 bool addedMakeConstantList = false; |
| 2690 eagerBuffer.write('var ${namer.globalObjectForConstant(null)}$_=$_{}$N'); |
| 2686 for (Constant constant in constants) { | 2691 for (Constant constant in constants) { |
| 2687 if (isConstantInlinedOrAlreadyEmitted(constant)) continue; | 2692 if (isConstantInlinedOrAlreadyEmitted(constant)) continue; |
| 2688 String name = namer.constantName(constant); | 2693 String name = namer.constantName(constant); |
| 2689 if (!addedMakeConstantList && constant.isList()) { | 2694 if (!addedMakeConstantList && constant.isList()) { |
| 2690 addedMakeConstantList = true; | 2695 addedMakeConstantList = true; |
| 2691 emitMakeConstantList(eagerBuffer); | 2696 emitMakeConstantList(eagerBuffer); |
| 2692 } | 2697 } |
| 2693 CodeBuffer buffer = bufferForConstant(constant, eagerBuffer); | 2698 CodeBuffer buffer = bufferForConstant(constant, eagerBuffer); |
| 2694 jsAst.Expression init = js('$isolateProperties.$name = #', | 2699 jsAst.Expression init = js( |
| 2700 '${namer.globalObjectForConstant(constant)}.$name = #', |
| 2695 constantInitializerExpression(constant)); | 2701 constantInitializerExpression(constant)); |
| 2696 buffer.write(jsAst.prettyPrint(init, compiler)); | 2702 buffer.write(jsAst.prettyPrint(init, compiler)); |
| 2697 buffer.write('$N'); | 2703 buffer.write('$N'); |
| 2698 } | 2704 } |
| 2699 } | 2705 } |
| 2700 | 2706 |
| 2701 bool isConstantInlinedOrAlreadyEmitted(Constant constant) { | 2707 bool isConstantInlinedOrAlreadyEmitted(Constant constant) { |
| 2702 if (constant.isFunction()) return true; // Already emitted. | 2708 if (constant.isFunction()) return true; // Already emitted. |
| 2703 if (constant.isPrimitive()) return true; // Inlined. | 2709 if (constant.isPrimitive()) return true; // Inlined. |
| 2704 // The name is null when the constant is already a JS constant. | 2710 // The name is null when the constant is already a JS constant. |
| (...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4064 | 4070 |
| 4065 const String HOOKS_API_USAGE = """ | 4071 const String HOOKS_API_USAGE = """ |
| 4066 // The code supports the following hooks: | 4072 // The code supports the following hooks: |
| 4067 // dartPrint(message) - if this function is defined it is called | 4073 // dartPrint(message) - if this function is defined it is called |
| 4068 // instead of the Dart [print] method. | 4074 // instead of the Dart [print] method. |
| 4069 // dartMainRunner(main) - if this function is defined, the Dart [main] | 4075 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 4070 // method will not be invoked directly. | 4076 // method will not be invoked directly. |
| 4071 // Instead, a closure that will invoke [main] is | 4077 // Instead, a closure that will invoke [main] is |
| 4072 // passed to [dartMainRunner]. | 4078 // passed to [dartMainRunner]. |
| 4073 """; | 4079 """; |
| OLD | NEW |