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

Side by Side Diff: frog/corejs.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 | « no previous file | frog/gen.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 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 * Generates JS helpers for dart:core. This used to be in a file "core.js". 6 * Generates JS helpers for dart:core. This used to be in a file "core.js".
7 * Having them in Dart code means we can easily control which are generated. 7 * Having them in Dart code means we can easily control which are generated.
8 */ 8 */
9 // TODO(jmesserly): one idea to make this cleaner: put these as private "native" 9 // TODO(jmesserly): one idea to make this cleaner: put these as private "native"
10 // methods somewhere in a library that we import. This would be rather elegant 10 // methods somewhere in a library that we import. This would be rather elegant
(...skipping 10 matching lines...) Expand all
21 bool useWrap1 = false; 21 bool useWrap1 = false;
22 bool useIsolates = false; 22 bool useIsolates = false;
23 23
24 // These helpers had to switch to a new pattern, because they can be generated 24 // These helpers had to switch to a new pattern, because they can be generated
25 // after everything else. 25 // after everything else.
26 bool _generatedTypeNameOf = false; 26 bool _generatedTypeNameOf = false;
27 bool _generatedDynamicProto = false; 27 bool _generatedDynamicProto = false;
28 bool _generatedDynamicSetMetadata = false; 28 bool _generatedDynamicSetMetadata = false;
29 bool _generatedInherits = false; 29 bool _generatedInherits = false;
30 bool _generatedDefProp = false; 30 bool _generatedDefProp = false;
31 bool _generatedBind = false;
31 32
32 33
33 Map<String, String> _usedOperators; 34 Map<String, String> _usedOperators;
34 35
35 CodeWriter writer; 36 CodeWriter writer;
36 37
37 CoreJs(): _usedOperators = {}, writer = new CodeWriter(); 38 CoreJs(): _usedOperators = {}, writer = new CodeWriter();
38 39
39 /** 40 /**
40 * Generates the special operator method, e.g. $add. 41 * Generates the special operator method, e.g. $add.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 writer.writeln(_INHERITS_FUNCTION); 122 writer.writeln(_INHERITS_FUNCTION);
122 } 123 }
123 124
124 /** Generates the $defProp function when it's first used. */ 125 /** Generates the $defProp function when it's first used. */
125 void ensureDefProp() { 126 void ensureDefProp() {
126 if (_generatedDefProp) return; 127 if (_generatedDefProp) return;
127 _generatedDefProp = true; 128 _generatedDefProp = true;
128 writer.writeln(_DEF_PROP_FUNCTION); 129 writer.writeln(_DEF_PROP_FUNCTION);
129 } 130 }
130 131
132 void ensureBind() {
133 if (_generatedBind) return;
134 _generatedBind = true;
135 writer.writeln(_BIND_CODE);
136 }
137
131 void generate(CodeWriter w) { 138 void generate(CodeWriter w) {
132 // Write any stuff we had queued up, then replace our writer with the one 139 // Write any stuff we had queued up, then replace our writer with the one
133 // in WorldGenerator so anything we discover that we need later on will be 140 // in WorldGenerator so anything we discover that we need later on will be
134 // generated on-demand. 141 // generated on-demand.
135 w.write(writer.text); 142 w.write(writer.text);
136 writer = w; 143 writer = w;
137 144
138 if (useNotNullBool) { 145 if (useNotNullBool) {
139 useThrow = true; 146 useThrow = true;
140 w.writeln(_NOTNULL_BOOL_FUNCTION); 147 w.writeln(_NOTNULL_BOOL_FUNCTION);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 // prototype. TODO(jmesserly): make this go away by handling index more 437 // prototype. TODO(jmesserly): make this go away by handling index more
431 // like a normal method. 438 // like a normal method.
432 final String _INDEX_OPERATORS = @""" 439 final String _INDEX_OPERATORS = @"""
433 $defProp(Object.prototype, '$index', function(i) { 440 $defProp(Object.prototype, '$index', function(i) {
434 var proto = Object.getPrototypeOf(this); 441 var proto = Object.getPrototypeOf(this);
435 if (proto !== Object) { 442 if (proto !== Object) {
436 proto.$index = function(i) { return this[i]; } 443 proto.$index = function(i) { return this[i]; }
437 } 444 }
438 return this[i]; 445 return this[i];
439 }); 446 });
440 $defProp(Array.prototype, '$index', function(i) { 447 $defProp(Array.prototype, '$index', function(i) {
441 return this[i]; 448 return this[i];
442 }); 449 });
443 $defProp(String.prototype, '$index', function(i) { 450 $defProp(String.prototype, '$index', function(i) {
444 return this[i]; 451 return this[i];
445 });"""; 452 });""";
446 453
447 final String _CHECKED_INDEX_OPERATORS = @""" 454 final String _CHECKED_INDEX_OPERATORS = @"""
448 $defProp(Object.prototype, '$index', function(i) { 455 $defProp(Object.prototype, '$index', function(i) {
449 var proto = Object.getPrototypeOf(this); 456 var proto = Object.getPrototypeOf(this);
450 if (proto !== Object) { 457 if (proto !== Object) {
451 proto.$index = function(i) { return this[i]; } 458 proto.$index = function(i) { return this[i]; }
452 } 459 }
453 return this[i]; 460 return this[i];
454 }); 461 });
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 540
534 /** Snippet for `$wrap_call$1`, in case it was not necessary. */ 541 /** Snippet for `$wrap_call$1`, in case it was not necessary. */
535 final String _EMPTY_WRAP_CALL1_FUNCTION = 542 final String _EMPTY_WRAP_CALL1_FUNCTION =
536 @"function $wrap_call$1(fn) { return fn; }"; 543 @"function $wrap_call$1(fn) { return fn; }";
537 544
538 /** Snippet that initializes the isolates state. */ 545 /** Snippet that initializes the isolates state. */
539 final String _ISOLATE_INIT_CODE = @""" 546 final String _ISOLATE_INIT_CODE = @"""
540 var $globalThis = this; 547 var $globalThis = this;
541 var $globals = null; 548 var $globals = null;
542 var $globalState = null;"""; 549 var $globalState = null;""";
550
551
552 /** Snippet that initializes Function.prototype.bind. */
553 final String _BIND_CODE = @"""
554 Function.prototype.bind = Function.prototype.bind ||
555 function(thisObj, args) {
556 var func = this;
557 if (typeof args !== 'undefined') {
558 var boundArgs = Array.prototype.slice.call(arguments, 3);
559 return function() {
560 // Prepend the bound arguments to the current arguments.
561 var newArgs = Array.prototype.slice.call(arguments);
562 Array.prototype.unshift.apply(newArgs, boundArgs);
563 return func.apply(thisObj, newArgs);
564 };
565 } else {
566 return function() {
567 return func.apply(thisObj, arguments);
568 };
569 }
570 };""";
OLDNEW
« no previous file with comments | « no previous file | frog/gen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698