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

Side by Side Diff: frog/minfrog

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/gen.dart ('k') | tests/language/BindTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env node 1 #!/usr/bin/env node
2 // ********** Library dart:core ************** 2 // ********** Library dart:core **************
3 // ********** Natives dart:core ************** 3 // ********** Natives dart:core **************
4 function $defProp(obj, prop, value) { 4 function $defProp(obj, prop, value) {
5 Object.defineProperty(obj, prop, 5 Object.defineProperty(obj, prop,
6 {value: value, enumerable: false, writable: true, configurable: true}); 6 {value: value, enumerable: false, writable: true, configurable: true});
7 } 7 }
8 Function.prototype.bind = Function.prototype.bind ||
9 function(thisObj, args) {
10 var func = this;
11 if (typeof args !== 'undefined') {
12 var boundArgs = Array.prototype.slice.call(arguments, 3);
13 return function() {
14 // Prepend the bound arguments to the current arguments.
15 var newArgs = Array.prototype.slice.call(arguments);
16 Array.prototype.unshift.apply(newArgs, boundArgs);
17 return func.apply(thisObj, newArgs);
18 };
19 } else {
20 return function() {
21 return func.apply(thisObj, arguments);
22 };
23 }
24 };
8 function $throw(e) { 25 function $throw(e) {
9 // If e is not a value, we can use V8's captureStackTrace utility method. 26 // If e is not a value, we can use V8's captureStackTrace utility method.
10 // TODO(jmesserly): capture the stack trace on other JS engines. 27 // TODO(jmesserly): capture the stack trace on other JS engines.
11 if (e && (typeof e == 'object') && Error.captureStackTrace) { 28 if (e && (typeof e == 'object') && Error.captureStackTrace) {
12 // TODO(jmesserly): this will clobber the e.stack property 29 // TODO(jmesserly): this will clobber the e.stack property
13 Error.captureStackTrace(e, $throw); 30 Error.captureStackTrace(e, $throw);
14 } 31 }
15 throw e; 32 throw e;
16 } 33 }
17 $defProp(Object.prototype, '$index', function(i) { 34 $defProp(Object.prototype, '$index', function(i) {
(...skipping 2741 matching lines...) Expand 10 before | Expand all | Expand 10 after
2759 this.useIsolates = false; 2776 this.useIsolates = false;
2760 this._generatedTypeNameOf = false; 2777 this._generatedTypeNameOf = false;
2761 this._usedOperators = new HashMapImplementation(); 2778 this._usedOperators = new HashMapImplementation();
2762 this._generatedInherits = false; 2779 this._generatedInherits = false;
2763 this.useNotNullBool = false; 2780 this.useNotNullBool = false;
2764 this._generatedDynamicSetMetadata = false; 2781 this._generatedDynamicSetMetadata = false;
2765 this.writer = new CodeWriter(); 2782 this.writer = new CodeWriter();
2766 this.useWrap0 = false; 2783 this.useWrap0 = false;
2767 this.useThrow = false; 2784 this.useThrow = false;
2768 this._generatedDynamicProto = false; 2785 this._generatedDynamicProto = false;
2786 this._generatedBind = false;
2769 this.useWrap1 = false; 2787 this.useWrap1 = false;
2770 this.useSetIndex = false; 2788 this.useSetIndex = false;
2771 this.useIndex = false; 2789 this.useIndex = false;
2772 this._generatedDefProp = false; 2790 this._generatedDefProp = false;
2773 } 2791 }
2774 CoreJs.prototype.get$writer = function() { return this.writer; }; 2792 CoreJs.prototype.get$writer = function() { return this.writer; };
2775 CoreJs.prototype.set$writer = function(value) { return this.writer = value; }; 2793 CoreJs.prototype.set$writer = function(value) { return this.writer = value; };
2776 CoreJs.prototype.useOperator = function(name) { 2794 CoreJs.prototype.useOperator = function(name) {
2777 if ($ne(this._usedOperators.$index(name))) return; 2795 if ($ne(this._usedOperators.$index(name))) return;
2778 var code; 2796 var code;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2846 CoreJs.prototype.ensureInheritsHelper = function() { 2864 CoreJs.prototype.ensureInheritsHelper = function() {
2847 if (this._generatedInherits) return; 2865 if (this._generatedInherits) return;
2848 this._generatedInherits = true; 2866 this._generatedInherits = true;
2849 this.writer.writeln("/** Implements extends for Dart classes on JavaScript pro totypes. */\nfunction $inherits(child, parent) {\n if (child.prototype.__proto_ _) {\n child.prototype.__proto__ = parent.prototype;\n } else {\n functio n tmp() {};\n tmp.prototype = parent.prototype;\n child.prototype = new tm p();\n child.prototype.constructor = child;\n }\n}"); 2867 this.writer.writeln("/** Implements extends for Dart classes on JavaScript pro totypes. */\nfunction $inherits(child, parent) {\n if (child.prototype.__proto_ _) {\n child.prototype.__proto__ = parent.prototype;\n } else {\n functio n tmp() {};\n tmp.prototype = parent.prototype;\n child.prototype = new tm p();\n child.prototype.constructor = child;\n }\n}");
2850 } 2868 }
2851 CoreJs.prototype.ensureDefProp = function() { 2869 CoreJs.prototype.ensureDefProp = function() {
2852 if (this._generatedDefProp) return; 2870 if (this._generatedDefProp) return;
2853 this._generatedDefProp = true; 2871 this._generatedDefProp = true;
2854 this.writer.writeln("function $defProp(obj, prop, value) {\n Object.definePro perty(obj, prop,\n {value: value, enumerable: false, writable: true, config urable: true});\n}"); 2872 this.writer.writeln("function $defProp(obj, prop, value) {\n Object.definePro perty(obj, prop,\n {value: value, enumerable: false, writable: true, config urable: true});\n}");
2855 } 2873 }
2874 CoreJs.prototype.ensureBind = function() {
2875 if (this._generatedBind) return;
2876 this._generatedBind = true;
2877 this.writer.writeln("Function.prototype.bind = Function.prototype.bind ||\n f unction(thisObj, args) {\n var func = this;\n if (typeof args !== 'undefin ed') {\n var boundArgs = Array.prototype.slice.call(arguments, 3);\n r eturn function() {\n // Prepend the bound arguments to the current argume nts.\n var newArgs = Array.prototype.slice.call(arguments);\n Arra y.prototype.unshift.apply(newArgs, boundArgs);\n return func.apply(thisOb j, newArgs);\n };\n } else {\n return function() {\n return func.apply(thisObj, arguments);\n };\n }\n };");
2878 }
2856 CoreJs.prototype.generate = function(w) { 2879 CoreJs.prototype.generate = function(w) {
2857 w.write(this.writer.get$text()); 2880 w.write(this.writer.get$text());
2858 this.writer = w; 2881 this.writer = w;
2859 if (this.useNotNullBool) { 2882 if (this.useNotNullBool) {
2860 this.useThrow = true; 2883 this.useThrow = true;
2861 w.writeln("function $notnull_bool(test) {\n if (test === true || test === f alse) return test;\n $throw(new TypeError(test, 'bool'));\n}"); 2884 w.writeln("function $notnull_bool(test) {\n if (test === true || test === f alse) return test;\n $throw(new TypeError(test, 'bool'));\n}");
2862 } 2885 }
2863 if (this.useThrow) { 2886 if (this.useThrow) {
2864 w.writeln("function $throw(e) {\n // If e is not a value, we can use V8's c aptureStackTrace utility method.\n // TODO(jmesserly): capture the stack trace on other JS engines.\n if (e && (typeof e == 'object') && Error.captureStackTra ce) {\n // TODO(jmesserly): this will clobber the e.stack property\n Error .captureStackTrace(e, $throw);\n }\n throw e;\n}"); 2887 w.writeln("function $throw(e) {\n // If e is not a value, we can use V8's c aptureStackTrace utility method.\n // TODO(jmesserly): capture the stack trace on other JS engines.\n if (e && (typeof e == 'object') && Error.captureStackTra ce) {\n // TODO(jmesserly): this will clobber the e.stack property\n Error .captureStackTrace(e, $throw);\n }\n throw e;\n}");
2865 } 2888 }
2866 if (this.useIndex) { 2889 if (this.useIndex) {
2867 this.ensureDefProp(); 2890 this.ensureDefProp();
2868 w.writeln($globals.options.disableBoundsChecks ? "$defProp(Object.prototype, '$index', function(i) {\n var proto = Object.getPrototypeOf(this);\n if (prot o !== Object) {\n proto.$index = function(i) { return this[i]; }\n }\n retu rn this[i];\n});\n$defProp(Array.prototype, '$index', function(i) { \n return t his[i]; \n});\n$defProp(String.prototype, '$index', function(i) { \n return thi s[i]; \n});" : "$defProp(Object.prototype, '$index', function(i) {\n var proto = Object.getPrototypeOf(this);\n if (proto !== Object) {\n proto.$index = fu nction(i) { return this[i]; }\n }\n return this[i];\n});\n$defProp(Array.proto type, '$index', function(index) {\n var i = index | 0;\n if (i !== index) {\n throw new IllegalArgumentException('index is not int');\n } else if (i < 0 | | i >= this.length) {\n throw new IndexOutOfRangeException(index);\n }\n re turn this[i];\n});\n$defProp(String.prototype, '$index', function(i) {\n return this[i];\n});"); 2891 w.writeln($globals.options.disableBoundsChecks ? "$defProp(Object.prototype, '$index', function(i) {\n var proto = Object.getPrototypeOf(this);\n if (prot o !== Object) {\n proto.$index = function(i) { return this[i]; }\n }\n retu rn this[i];\n});\n$defProp(Array.prototype, '$index', function(i) {\n return th is[i];\n});\n$defProp(String.prototype, '$index', function(i) {\n return this[i ];\n});" : "$defProp(Object.prototype, '$index', function(i) {\n var proto = Ob ject.getPrototypeOf(this);\n if (proto !== Object) {\n proto.$index = functi on(i) { return this[i]; }\n }\n return this[i];\n});\n$defProp(Array.prototype , '$index', function(index) {\n var i = index | 0;\n if (i !== index) {\n t hrow new IllegalArgumentException('index is not int');\n } else if (i < 0 || i >= this.length) {\n throw new IndexOutOfRangeException(index);\n }\n return this[i];\n});\n$defProp(String.prototype, '$index', function(i) {\n return thi s[i];\n});");
2869 } 2892 }
2870 if (this.useSetIndex) { 2893 if (this.useSetIndex) {
2871 this.ensureDefProp(); 2894 this.ensureDefProp();
2872 w.writeln($globals.options.disableBoundsChecks ? "$defProp(Object.prototype, '$setindex', function(i, value) {\n var proto = Object.getPrototypeOf(this);\n if (proto !== Object) {\n proto.$setindex = function(i, value) { return thi s[i] = value; }\n }\n return this[i] = value;\n});\n$defProp(Array.prototype, '$setindex',\n function(i, value) { return this[i] = value; });" : "$defProp( Object.prototype, '$setindex', function(i, value) {\n var proto = Object.getPro totypeOf(this);\n if (proto !== Object) {\n proto.$setindex = function(i, va lue) { return this[i] = value; }\n }\n return this[i] = value;\n});\n$defProp( Array.prototype, '$setindex', function(index, value) {\n var i = index | 0;\n if (i !== index) {\n throw new IllegalArgumentException('index is not int');\ n } else if (i < 0 || i >= this.length) {\n throw new IndexOutOfRangeExcepti on(index);\n }\n return this[i] = value;\n});"); 2895 w.writeln($globals.options.disableBoundsChecks ? "$defProp(Object.prototype, '$setindex', function(i, value) {\n var proto = Object.getPrototypeOf(this);\n if (proto !== Object) {\n proto.$setindex = function(i, value) { return thi s[i] = value; }\n }\n return this[i] = value;\n});\n$defProp(Array.prototype, '$setindex',\n function(i, value) { return this[i] = value; });" : "$defProp( Object.prototype, '$setindex', function(i, value) {\n var proto = Object.getPro totypeOf(this);\n if (proto !== Object) {\n proto.$setindex = function(i, va lue) { return this[i] = value; }\n }\n return this[i] = value;\n});\n$defProp( Array.prototype, '$setindex', function(index, value) {\n var i = index | 0;\n if (i !== index) {\n throw new IllegalArgumentException('index is not int');\ n } else if (i < 0 || i >= this.length) {\n throw new IndexOutOfRangeExcepti on(index);\n }\n return this[i] = value;\n});");
2873 } 2896 }
2874 if (this.useIsolates) { 2897 if (this.useIsolates) {
2875 if (this.useWrap0) { 2898 if (this.useWrap0) {
2876 w.writeln("// Wrap a 0-arg dom-callback to bind it with the current isolat e:\nfunction $wrap_call$0(fn) { return fn && fn.wrap$call$0(); }\nFunction.proto type.wrap$call$0 = function() {\n var isolateContext = $globalState.currentCont ext;\n var self = this;\n this.wrap$0 = function() {\n isolateContext.eval( self);\n $globalState.topEventLoop.run();\n };\n this.wrap$call$0 = functio n() { return this.wrap$0; };\n return this.wrap$0;\n}"); 2899 w.writeln("// Wrap a 0-arg dom-callback to bind it with the current isolat e:\nfunction $wrap_call$0(fn) { return fn && fn.wrap$call$0(); }\nFunction.proto type.wrap$call$0 = function() {\n var isolateContext = $globalState.currentCont ext;\n var self = this;\n this.wrap$0 = function() {\n isolateContext.eval( self);\n $globalState.topEventLoop.run();\n };\n this.wrap$call$0 = functio n() { return this.wrap$0; };\n return this.wrap$0;\n}");
2877 } 2900 }
2878 if (this.useWrap1) { 2901 if (this.useWrap1) {
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
3439 } 3462 }
3440 if (property.setter != null) { 3463 if (property.setter != null) {
3441 this.writer.writeln(("set: " + property.declaringType.get$jsname() + ".pro totype." + property.setter.get$jsname())); 3464 this.writer.writeln(("set: " + property.declaringType.get$jsname() + ".pro totype." + property.setter.get$jsname()));
3442 } 3465 }
3443 this.writer.exitBlock("});"); 3466 this.writer.exitBlock("});");
3444 } 3467 }
3445 } 3468 }
3446 WorldGenerator.prototype._writeMethod = function(m) { 3469 WorldGenerator.prototype._writeMethod = function(m) {
3447 m.get$methodData().writeDefinition(m, this.writer); 3470 m.get$methodData().writeDefinition(m, this.writer);
3448 if (m.get$isNative() && m._provideGetter) { 3471 if (m.get$isNative() && m._provideGetter) {
3449 MethodGenerator._maybeGenerateBoundGetter(m, this.writer); 3472 if (MethodGenerator._maybeGenerateBoundGetter(m, this.writer)) {
3473 $globals.world.gen.corejs.ensureBind();
3474 }
3450 } 3475 }
3451 } 3476 }
3452 WorldGenerator.prototype.get$_writeMethod = function() { 3477 WorldGenerator.prototype.get$_writeMethod = function() {
3453 return this._writeMethod.bind(this); 3478 return this._writeMethod.bind(this);
3454 } 3479 }
3455 WorldGenerator.prototype.writeGlobals = function() { 3480 WorldGenerator.prototype.writeGlobals = function() {
3456 if (this.globals.get$length() > (0)) { 3481 if (this.globals.get$length() > (0)) {
3457 this.writer.comment("// ********** Globals **************"); 3482 this.writer.comment("// ********** Globals **************");
3458 var list = this.globals.getValues(); 3483 var list = this.globals.getValues();
3459 list.sort((function (a, b) { 3484 list.sort((function (a, b) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
3757 } 3782 }
3758 if (this._usedTemps.get$length() > (0) || this._freeTemps.get$length() > (0)) { 3783 if (this._usedTemps.get$length() > (0) || this._freeTemps.get$length() > (0)) {
3759 this._freeTemps.addAll(this._usedTemps); 3784 this._freeTemps.addAll(this._usedTemps);
3760 this._freeTemps.sort((function (x, y) { 3785 this._freeTemps.sort((function (x, y) {
3761 return x.compareTo(y); 3786 return x.compareTo(y);
3762 }) 3787 })
3763 ); 3788 );
3764 defWriter.writeln(("var " + Strings.join(this._freeTemps, ", ") + ";")); 3789 defWriter.writeln(("var " + Strings.join(this._freeTemps, ", ") + ";"));
3765 } 3790 }
3766 defWriter.writeln(this.writer.get$text()); 3791 defWriter.writeln(this.writer.get$text());
3792 var usesBind = false;
3767 if ($ne(names)) { 3793 if ($ne(names)) {
3794 usesBind = true;
3768 defWriter.exitBlock(("}).bind(null, " + Strings.join(names, ", ") + ")")); 3795 defWriter.exitBlock(("}).bind(null, " + Strings.join(names, ", ") + ")"));
3769 } 3796 }
3770 else if (this.get$isClosure() && this.method.name == "") { 3797 else if (this.get$isClosure() && this.method.name == "") {
3771 defWriter.exitBlock("})"); 3798 defWriter.exitBlock("})");
3772 } 3799 }
3773 else { 3800 else {
3774 defWriter.exitBlock(suffix); 3801 defWriter.exitBlock(suffix);
3775 } 3802 }
3776 if (this.method.get$isConstructor() && this.method.get$constructorName() != "" ) { 3803 if (this.method.get$isConstructor() && this.method.get$constructorName() != "" ) {
3777 defWriter.writeln($add(("" + this.method.declaringType.get$jsname() + "." + this.method.get$constructorName() + "$ctor.prototype = "), ("" + this.method.dec laringType.get$jsname() + ".prototype;"))); 3804 defWriter.writeln($add(("" + this.method.declaringType.get$jsname() + "." + this.method.get$constructorName() + "$ctor.prototype = "), ("" + this.method.dec laringType.get$jsname() + ".prototype;")));
3778 } 3805 }
3779 this._provideOptionalParamInfo(defWriter); 3806 this._provideOptionalParamInfo(defWriter);
3780 if ((this.method instanceof MethodMember)) { 3807 if ((this.method instanceof MethodMember)) {
3781 MethodGenerator._maybeGenerateBoundGetter(this.method, defWriter); 3808 if (MethodGenerator._maybeGenerateBoundGetter(this.method, defWriter)) {
3809 usesBind = true;
3810 }
3782 } 3811 }
3812 if (usesBind) $globals.world.gen.corejs.ensureBind();
3783 } 3813 }
3784 MethodGenerator._maybeGenerateBoundGetter = function(m, defWriter) { 3814 MethodGenerator._maybeGenerateBoundGetter = function(m, defWriter) {
3785 if (m._provideGetter) { 3815 if (m._provideGetter) {
3786 var suffix = $globals.world.gen._writePrototypePatch(m.declaringType, $add(" get$", m.get$jsname()), "function() {", defWriter, false); 3816 var suffix = $globals.world.gen._writePrototypePatch(m.declaringType, $add(" get$", m.get$jsname()), "function() {", defWriter, false);
3787 defWriter.writeln(("return this." + m.get$jsname() + ".bind(this);")); 3817 defWriter.writeln(("return this." + m.get$jsname() + ".bind(this);"));
3788 defWriter.exitBlock(suffix); 3818 defWriter.exitBlock(suffix);
3819 return true;
3789 } 3820 }
3821 return false;
3790 } 3822 }
3791 MethodGenerator.prototype._provideOptionalParamInfo = function(defWriter) { 3823 MethodGenerator.prototype._provideOptionalParamInfo = function(defWriter) {
3792 if ((this.method instanceof MethodMember)) { 3824 if ((this.method instanceof MethodMember)) {
3793 var meth = this.method; 3825 var meth = this.method;
3794 if (meth._provideOptionalParamInfo) { 3826 if (meth._provideOptionalParamInfo) {
3795 var optNames = []; 3827 var optNames = [];
3796 var optValues = []; 3828 var optValues = [];
3797 meth.genParameterValues(this); 3829 meth.genParameterValues(this);
3798 var $$list = meth.parameters; 3830 var $$list = meth.parameters;
3799 for (var $$i = $$list.iterator(); $$i.hasNext(); ) { 3831 for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
(...skipping 10753 matching lines...) Expand 10 before | Expand all | Expand 10 after
14553 } 14585 }
14554 var const$0000 = Object.create(_DeletedKeySentinel.prototype, {}); 14586 var const$0000 = Object.create(_DeletedKeySentinel.prototype, {});
14555 var const$0001 = Object.create(NoMoreElementsException.prototype, {}); 14587 var const$0001 = Object.create(NoMoreElementsException.prototype, {});
14556 var const$0002 = Object.create(EmptyQueueException.prototype, {}); 14588 var const$0002 = Object.create(EmptyQueueException.prototype, {});
14557 var const$0006 = Object.create(IllegalAccessException.prototype, {}); 14589 var const$0006 = Object.create(IllegalAccessException.prototype, {});
14558 var const$0007 = ImmutableList.ImmutableList$from$factory([]); 14590 var const$0007 = ImmutableList.ImmutableList$from$factory([]);
14559 var const$0009 = new JSSyntaxRegExp("^[a-zA-Z]:/"); 14591 var const$0009 = new JSSyntaxRegExp("^[a-zA-Z]:/");
14560 var $globals = {}; 14592 var $globals = {};
14561 $static_init(); 14593 $static_init();
14562 main(); 14594 main();
OLDNEW
« no previous file with comments | « frog/gen.dart ('k') | tests/language/BindTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698