Chromium Code Reviews| 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 /** | 5 /** |
| 6 * Top level generator object for writing code and keeping track of | 6 * Top level generator object for writing code and keeping track of |
| 7 * dependencies. | 7 * dependencies. |
| 8 * | 8 * |
| 9 * Should have two compilation models, but only one implemented so far. | 9 * Should have two compilation models, but only one implemented so far. |
| 10 * | 10 * |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 'set: ${property.declaringType.jsname}.prototype.${property.setter.jsn ame}'); | 535 'set: ${property.declaringType.jsname}.prototype.${property.setter.jsn ame}'); |
| 536 } | 536 } |
| 537 writer.exitBlock('});'); | 537 writer.exitBlock('});'); |
| 538 } | 538 } |
| 539 } | 539 } |
| 540 | 540 |
| 541 _writeMethod(MethodMember m) { | 541 _writeMethod(MethodMember m) { |
| 542 m.methodData.writeDefinition(m, writer); | 542 m.methodData.writeDefinition(m, writer); |
| 543 | 543 |
| 544 if (m.isNative && m._provideGetter) { | 544 if (m.isNative && m._provideGetter) { |
| 545 MethodGenerator._maybeGenerateBoundGetter(m, writer); | 545 MethodGenerator._maybeGenerateBoundGetter(m, writer); |
|
kasperl
2012/02/14 11:53:37
Do you have to ensure bind if maybeGenerateBoundGe
ngeoffray
2012/02/14 11:59:21
maybeGenerateBoundGetter looks for 'provideGetter'
| |
| 546 world.gen.corejs.ensureBind(); | |
| 546 } | 547 } |
| 547 } | 548 } |
| 548 | 549 |
| 549 writeGlobals() { | 550 writeGlobals() { |
| 550 if (globals.length > 0) { | 551 if (globals.length > 0) { |
| 551 writer.comment('// ********** Globals **************'); | 552 writer.comment('// ********** Globals **************'); |
| 552 var list = globals.getValues(); | 553 var list = globals.getValues(); |
| 553 list.sort((a, b) => a.compareTo(b)); | 554 list.sort((a, b) => a.compareTo(b)); |
| 554 | 555 |
| 555 // put all static field initializations in a method | 556 // put all static field initializations in a method |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 897 if (_usedTemps.length > 0 || _freeTemps.length > 0) { | 898 if (_usedTemps.length > 0 || _freeTemps.length > 0) { |
| 898 //TODO(jimhug): assert(_usedTemps.length == 0); // all temps should be fre ed. | 899 //TODO(jimhug): assert(_usedTemps.length == 0); // all temps should be fre ed. |
| 899 _freeTemps.addAll(_usedTemps); | 900 _freeTemps.addAll(_usedTemps); |
| 900 _freeTemps.sort((x, y) => x.compareTo(y)); | 901 _freeTemps.sort((x, y) => x.compareTo(y)); |
| 901 defWriter.writeln('var ${Strings.join(_freeTemps, ", ")};'); | 902 defWriter.writeln('var ${Strings.join(_freeTemps, ", ")};'); |
| 902 } | 903 } |
| 903 | 904 |
| 904 // TODO(jimhug): Lots of string translation here - perf bottleneck? | 905 // TODO(jimhug): Lots of string translation here - perf bottleneck? |
| 905 defWriter.writeln(writer.text); | 906 defWriter.writeln(writer.text); |
| 906 | 907 |
| 908 bool usesBind = false; | |
| 907 if (names != null) { | 909 if (names != null) { |
| 908 // TODO(jmesserly): bind isn't implemented in older Safari. | 910 usesBind = true; |
| 909 defWriter.exitBlock('}).bind(null, ${Strings.join(names, ", ")})'); | 911 defWriter.exitBlock('}).bind(null, ${Strings.join(names, ", ")})'); |
| 910 } else if (isClosure && method.name == '') { | 912 } else if (isClosure && method.name == '') { |
| 911 defWriter.exitBlock('})'); | 913 defWriter.exitBlock('})'); |
| 912 } else { | 914 } else { |
| 913 defWriter.exitBlock(suffix); | 915 defWriter.exitBlock(suffix); |
| 914 } | 916 } |
| 915 if (method.isConstructor && method.constructorName != '') { | 917 if (method.isConstructor && method.constructorName != '') { |
| 916 defWriter.writeln( | 918 defWriter.writeln( |
| 917 '${method.declaringType.jsname}.${method.constructorName}\$ctor.prototyp e = ' + | 919 '${method.declaringType.jsname}.${method.constructorName}\$ctor.prototyp e = ' + |
| 918 '${method.declaringType.jsname}.prototype;'); | 920 '${method.declaringType.jsname}.prototype;'); |
| 919 } | 921 } |
| 920 | 922 |
| 921 _provideOptionalParamInfo(defWriter); | 923 _provideOptionalParamInfo(defWriter); |
| 922 | 924 |
| 923 if (method is MethodMember) { | 925 if (method is MethodMember) { |
| 924 _maybeGenerateBoundGetter(method, defWriter); | 926 usesBind = _maybeGenerateBoundGetter(method, defWriter); |
| 925 } | 927 } |
| 928 | |
| 929 if (usesBind) world.gen.corejs.ensureBind(); | |
| 926 } | 930 } |
| 927 | 931 |
| 928 static _maybeGenerateBoundGetter(MethodMember m, CodeWriter defWriter) { | 932 static bool _maybeGenerateBoundGetter(MethodMember m, CodeWriter defWriter) { |
| 929 if (m._provideGetter) { | 933 if (m._provideGetter) { |
| 930 String suffix = world.gen._writePrototypePatch(m.declaringType, | 934 String suffix = world.gen._writePrototypePatch(m.declaringType, |
| 931 'get\$' + m.jsname, 'function() {', defWriter, false); | 935 'get\$' + m.jsname, 'function() {', defWriter, false); |
| 932 // TODO(jimhug): Bind not available in older Safari, need fallback? | |
| 933 defWriter.writeln('return this.${m.jsname}.bind(this);'); | 936 defWriter.writeln('return this.${m.jsname}.bind(this);'); |
| 934 defWriter.exitBlock(suffix); | 937 defWriter.exitBlock(suffix); |
| 938 return true; | |
| 935 } | 939 } |
| 940 return false; | |
| 936 } | 941 } |
| 937 | 942 |
| 938 /** | 943 /** |
| 939 * Generates information about the default/named arguments into the JS code. | 944 * Generates information about the default/named arguments into the JS code. |
| 940 * Only methods that are passed as bound methods to "var" need this. It is | 945 * Only methods that are passed as bound methods to "var" need this. It is |
| 941 * generated to support run time stub creation. | 946 * generated to support run time stub creation. |
| 942 */ | 947 */ |
| 943 _provideOptionalParamInfo(CodeWriter defWriter) { | 948 _provideOptionalParamInfo(CodeWriter defWriter) { |
| 944 if (method is MethodMember) { | 949 if (method is MethodMember) { |
| 945 MethodMember meth = method; | 950 MethodMember meth = method; |
| (...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2450 return true; | 2455 return true; |
| 2451 } | 2456 } |
| 2452 | 2457 |
| 2453 } | 2458 } |
| 2454 | 2459 |
| 2455 class ReturnKind { | 2460 class ReturnKind { |
| 2456 static final int IGNORE = 1; | 2461 static final int IGNORE = 1; |
| 2457 static final int POST = 2; | 2462 static final int POST = 2; |
| 2458 static final int PRE = 3; | 2463 static final int PRE = 3; |
| 2459 } | 2464 } |
| OLD | NEW |