| 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 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1558 emitClassConstructor(classElement, builder); | 1558 emitClassConstructor(classElement, builder); |
| 1559 emitSuper(superName, builder); | 1559 emitSuper(superName, builder); |
| 1560 emitRuntimeName(runtimeName, builder); | 1560 emitRuntimeName(runtimeName, builder); |
| 1561 emitClassFields(classElement, builder, superName); | 1561 emitClassFields(classElement, builder, superName); |
| 1562 emitClassGettersSetters(classElement, builder); | 1562 emitClassGettersSetters(classElement, builder); |
| 1563 if (!classElement.isMixinApplication) { | 1563 if (!classElement.isMixinApplication) { |
| 1564 emitInstanceMembers(classElement, builder); | 1564 emitInstanceMembers(classElement, builder); |
| 1565 } | 1565 } |
| 1566 emitIsTests(classElement, builder); | 1566 emitIsTests(classElement, builder); |
| 1567 | 1567 |
| 1568 // TODO(ahe): This method (generateClass) should return a jsAst.Expression. |
| 1568 if (!buffer.isEmpty) { | 1569 if (!buffer.isEmpty) { |
| 1569 buffer.write(',$n$n'); | 1570 buffer.write(',$n$n'); |
| 1570 } | 1571 } |
| 1571 buffer.write('$className:$_'); | 1572 buffer.write('$className:$_'); |
| 1572 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler)); | 1573 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler)); |
| 1573 } | 1574 } |
| 1574 | 1575 |
| 1575 bool get getterAndSetterCanBeImplementedByFieldSpec => true; | 1576 bool get getterAndSetterCanBeImplementedByFieldSpec => true; |
| 1576 | 1577 |
| 1577 /// If this is true then we can generate the noSuchMethod handlers at startup | 1578 /// If this is true then we can generate the noSuchMethod handlers at startup |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1775 '${_}null)$N'); | 1776 '${_}null)$N'); |
| 1776 | 1777 |
| 1777 // Reset the map. | 1778 // Reset the map. |
| 1778 buffer.write("$classesCollector$_=${_}null$N$n"); | 1779 buffer.write("$classesCollector$_=${_}null$N$n"); |
| 1779 } | 1780 } |
| 1780 } | 1781 } |
| 1781 | 1782 |
| 1782 void emitStaticFunction(CodeBuffer buffer, | 1783 void emitStaticFunction(CodeBuffer buffer, |
| 1783 String name, | 1784 String name, |
| 1784 jsAst.Expression functionExpression) { | 1785 jsAst.Expression functionExpression) { |
| 1786 // TODO(ahe): This method (emitStaticFunction) should return a |
| 1787 // jsAst.Expression. |
| 1785 if (!buffer.isEmpty) { | 1788 if (!buffer.isEmpty) { |
| 1786 buffer.write(',$n$n'); | 1789 buffer.write(',$n$n'); |
| 1787 } | 1790 } |
| 1788 buffer.write('$name:$_'); | 1791 buffer.write('$name:$_'); |
| 1789 buffer.write(jsAst.prettyPrint(functionExpression, compiler)); | 1792 buffer.write(jsAst.prettyPrint(functionExpression, compiler)); |
| 1790 } | 1793 } |
| 1791 | 1794 |
| 1792 void emitStaticFunctions(CodeBuffer eagerBuffer) { | 1795 void emitStaticFunctions(CodeBuffer eagerBuffer) { |
| 1793 bool isStaticFunction(Element element) => | 1796 bool isStaticFunction(Element element) => |
| 1794 !element.isInstanceMember() && !element.isField(); | 1797 !element.isInstanceMember() && !element.isField(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1822 emitStaticFunction(buffer, namer.getBailoutName(element), bailoutCode); | 1825 emitStaticFunction(buffer, namer.getBailoutName(element), bailoutCode); |
| 1823 } | 1826 } |
| 1824 } | 1827 } |
| 1825 | 1828 |
| 1826 final Map<Element, Element> staticGetters = new Map<Element, Element>(); | 1829 final Map<Element, Element> staticGetters = new Map<Element, Element>(); |
| 1827 | 1830 |
| 1828 void emitStaticFunctionGetters(CodeBuffer eagerBuffer) { | 1831 void emitStaticFunctionGetters(CodeBuffer eagerBuffer) { |
| 1829 for (FunctionElement element in | 1832 for (FunctionElement element in |
| 1830 Elements.sortedByPosition(staticGetters.keys)) { | 1833 Elements.sortedByPosition(staticGetters.keys)) { |
| 1831 Element closure = staticGetters[element]; | 1834 Element closure = staticGetters[element]; |
| 1832 // CodeBuffer buffer = bufferForElement(element, eagerBuffer); | 1835 // TODO(ahe): This should be emitted as a constant. Currently, |
| 1836 // this breaks deferred loading. |
| 1833 CodeBuffer buffer = eagerBuffer; | 1837 CodeBuffer buffer = eagerBuffer; |
| 1834 String closureClass = namer.isolateAccess(closure); | 1838 String closureClass = namer.isolateAccess(closure); |
| 1835 String name = namer.getStaticClosureName(element); | 1839 String name = namer.getStaticClosureName(element); |
| 1836 String staticName = namer.getName(element); | 1840 String staticName = namer.getName(element); |
| 1837 | 1841 |
| 1838 String closureName = namer.getStaticClosureName(element); | 1842 String closureName = namer.getStaticClosureName(element); |
| 1839 jsAst.Node assignment = js('$isolateProperties.$name = ' | 1843 jsAst.Node assignment = js('$isolateProperties.$name = ' |
| 1840 'new $closureClass($isolateProperties.$staticName, "$closureName")'); | 1844 'new $closureClass($isolateProperties.$staticName, "$closureName")'); |
| 1841 buffer.write(jsAst.prettyPrint(assignment, compiler)); | 1845 buffer.write(jsAst.prettyPrint(assignment, compiler)); |
| 1842 buffer.write('$N'); | 1846 buffer.write('$N'); |
| (...skipping 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3206 // The code supports the following hooks: | 3210 // The code supports the following hooks: |
| 3207 // dartPrint(message) - if this function is defined it is called | 3211 // dartPrint(message) - if this function is defined it is called |
| 3208 // instead of the Dart [print] method. | 3212 // instead of the Dart [print] method. |
| 3209 // dartMainRunner(main) - if this function is defined, the Dart [main] | 3213 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 3210 // method will not be invoked directly. | 3214 // method will not be invoked directly. |
| 3211 // Instead, a closure that will invoke [main] is | 3215 // Instead, a closure that will invoke [main] is |
| 3212 // passed to [dartMainRunner]. | 3216 // passed to [dartMainRunner]. |
| 3213 """; | 3217 """; |
| 3214 | 3218 |
| 3215 // TODO(ahe): This code should be integrated in finishClasses. | 3219 // TODO(ahe): This code should be integrated in finishClasses. |
| 3220 // TODO(ahe): The uri field below is fake. |
| 3216 const String REFLECTION_DATA_PARSER = r''' | 3221 const String REFLECTION_DATA_PARSER = r''' |
| 3217 (function (reflectionData) { | 3222 (function (reflectionData) { |
| 3223 if (!init.libraries) init.libraries = []; |
| 3224 var libraries = init.libraries; |
| 3218 var hasOwnProperty = Object.prototype.hasOwnProperty; | 3225 var hasOwnProperty = Object.prototype.hasOwnProperty; |
| 3219 var length = reflectionData.length; | 3226 var length = reflectionData.length; |
| 3220 for (var i = 0; i < length; i++) { | 3227 for (var i = 0; i < length; i++) { |
| 3221 var data = reflectionData[i]; | 3228 var data = reflectionData[i]; |
| 3222 var name = data[0]; | 3229 var name = data[0]; |
| 3223 var descriptor = data[1]; | 3230 var descriptor = data[1]; |
| 3231 var classes = []; |
| 3232 var functions = []; |
| 3224 for (var property in descriptor) { | 3233 for (var property in descriptor) { |
| 3225 if (!hasOwnProperty.call(descriptor, property)) continue; | 3234 if (!hasOwnProperty.call(descriptor, property)) continue; |
| 3226 var element = descriptor[property]; | 3235 var element = descriptor[property]; |
| 3227 if (typeof element === "function") { | 3236 if (typeof element === "function") { |
| 3228 $[property] = element; | 3237 $[property] = element; |
| 3238 functions.push(property); |
| 3229 } else { | 3239 } else { |
| 3230 $$[property] = element; | 3240 $$[property] = element; |
| 3241 classes.push(property); |
| 3242 classes.push(element[""]); |
| 3231 } | 3243 } |
| 3232 } | 3244 } |
| 3245 var uri = ".../library" + i + ".dart"; |
| 3246 libraries.push([name, uri, classes, functions]); |
| 3233 } | 3247 } |
| 3234 })'''; | 3248 })'''; |
| OLD | NEW |