Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: frog/gen.dart

Issue 9365050: Fix for issue 1623: bind does not work on safari. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « frog/corejs.dart ('k') | frog/minfrog » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 if (MethodGenerator._maybeGenerateBoundGetter(m, writer)) {
546 world.gen.corejs.ensureBind();
547 }
546 } 548 }
547 } 549 }
548 550
549 writeGlobals() { 551 writeGlobals() {
550 if (globals.length > 0) { 552 if (globals.length > 0) {
551 writer.comment('// ********** Globals **************'); 553 writer.comment('// ********** Globals **************');
552 var list = globals.getValues(); 554 var list = globals.getValues();
553 list.sort((a, b) => a.compareTo(b)); 555 list.sort((a, b) => a.compareTo(b));
554 556
555 // put all static field initializations in a method 557 // put all static field initializations in a method
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 if (_usedTemps.length > 0 || _freeTemps.length > 0) { 899 if (_usedTemps.length > 0 || _freeTemps.length > 0) {
898 //TODO(jimhug): assert(_usedTemps.length == 0); // all temps should be fre ed. 900 //TODO(jimhug): assert(_usedTemps.length == 0); // all temps should be fre ed.
899 _freeTemps.addAll(_usedTemps); 901 _freeTemps.addAll(_usedTemps);
900 _freeTemps.sort((x, y) => x.compareTo(y)); 902 _freeTemps.sort((x, y) => x.compareTo(y));
901 defWriter.writeln('var ${Strings.join(_freeTemps, ", ")};'); 903 defWriter.writeln('var ${Strings.join(_freeTemps, ", ")};');
902 } 904 }
903 905
904 // TODO(jimhug): Lots of string translation here - perf bottleneck? 906 // TODO(jimhug): Lots of string translation here - perf bottleneck?
905 defWriter.writeln(writer.text); 907 defWriter.writeln(writer.text);
906 908
909 bool usesBind = false;
907 if (names != null) { 910 if (names != null) {
908 // TODO(jmesserly): bind isn't implemented in older Safari. 911 usesBind = true;
909 defWriter.exitBlock('}).bind(null, ${Strings.join(names, ", ")})'); 912 defWriter.exitBlock('}).bind(null, ${Strings.join(names, ", ")})');
910 } else if (isClosure && method.name == '') { 913 } else if (isClosure && method.name == '') {
911 defWriter.exitBlock('})'); 914 defWriter.exitBlock('})');
912 } else { 915 } else {
913 defWriter.exitBlock(suffix); 916 defWriter.exitBlock(suffix);
914 } 917 }
915 if (method.isConstructor && method.constructorName != '') { 918 if (method.isConstructor && method.constructorName != '') {
916 defWriter.writeln( 919 defWriter.writeln(
917 '${method.declaringType.jsname}.${method.constructorName}\$ctor.prototyp e = ' + 920 '${method.declaringType.jsname}.${method.constructorName}\$ctor.prototyp e = ' +
918 '${method.declaringType.jsname}.prototype;'); 921 '${method.declaringType.jsname}.prototype;');
919 } 922 }
920 923
921 _provideOptionalParamInfo(defWriter); 924 _provideOptionalParamInfo(defWriter);
922 925
923 if (method is MethodMember) { 926 if (method is MethodMember) {
924 _maybeGenerateBoundGetter(method, defWriter); 927 if (_maybeGenerateBoundGetter(method, defWriter)) {
928 usesBind = true;
929 }
925 } 930 }
931
932 if (usesBind) world.gen.corejs.ensureBind();
926 } 933 }
927 934
928 static _maybeGenerateBoundGetter(MethodMember m, CodeWriter defWriter) { 935 static bool _maybeGenerateBoundGetter(MethodMember m, CodeWriter defWriter) {
929 if (m._provideGetter) { 936 if (m._provideGetter) {
930 String suffix = world.gen._writePrototypePatch(m.declaringType, 937 String suffix = world.gen._writePrototypePatch(m.declaringType,
931 'get\$' + m.jsname, 'function() {', defWriter, false); 938 '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);'); 939 defWriter.writeln('return this.${m.jsname}.bind(this);');
934 defWriter.exitBlock(suffix); 940 defWriter.exitBlock(suffix);
941 return true;
935 } 942 }
943 return false;
936 } 944 }
937 945
938 /** 946 /**
939 * Generates information about the default/named arguments into the JS code. 947 * 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 948 * Only methods that are passed as bound methods to "var" need this. It is
941 * generated to support run time stub creation. 949 * generated to support run time stub creation.
942 */ 950 */
943 _provideOptionalParamInfo(CodeWriter defWriter) { 951 _provideOptionalParamInfo(CodeWriter defWriter) {
944 if (method is MethodMember) { 952 if (method is MethodMember) {
945 MethodMember meth = method; 953 MethodMember meth = method;
(...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 return true; 2458 return true;
2451 } 2459 }
2452 2460
2453 } 2461 }
2454 2462
2455 class ReturnKind { 2463 class ReturnKind {
2456 static final int IGNORE = 1; 2464 static final int IGNORE = 1;
2457 static final int POST = 2; 2465 static final int POST = 2;
2458 static final int PRE = 3; 2466 static final int PRE = 3;
2459 } 2467 }
OLDNEW
« no previous file with comments | « frog/corejs.dart ('k') | frog/minfrog » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698