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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | frog/gen.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/corejs.dart
===================================================================
--- frog/corejs.dart (revision 4212)
+++ frog/corejs.dart (working copy)
@@ -28,6 +28,7 @@
bool _generatedDynamicSetMetadata = false;
bool _generatedInherits = false;
bool _generatedDefProp = false;
+ bool _generatedBind = false;
Map<String, String> _usedOperators;
@@ -128,6 +129,12 @@
writer.writeln(_DEF_PROP_FUNCTION);
}
+ void ensureBind() {
+ if (_generatedBind) return;
+ _generatedBind = true;
+ writer.writeln(_BIND_CODE);
+ }
+
void generate(CodeWriter w) {
// Write any stuff we had queued up, then replace our writer with the one
// in WorldGenerator so anything we discover that we need later on will be
@@ -437,11 +444,11 @@
}
return this[i];
});
-$defProp(Array.prototype, '$index', function(i) {
- return this[i];
+$defProp(Array.prototype, '$index', function(i) {
+ return this[i];
});
-$defProp(String.prototype, '$index', function(i) {
- return this[i];
+$defProp(String.prototype, '$index', function(i) {
+ return this[i];
});""";
final String _CHECKED_INDEX_OPERATORS = @"""
@@ -540,3 +547,24 @@
var $globalThis = this;
var $globals = null;
var $globalState = null;""";
+
+
+/** Snippet that initializes Function.prototype.bind. */
+final String _BIND_CODE = @"""
+Function.prototype.bind = Function.prototype.bind ||
+ function(thisObj, args) {
+ var func = this;
+ if (typeof args !== 'undefined') {
+ var boundArgs = Array.prototype.slice.call(arguments, 3);
+ return function() {
+ // Prepend the bound arguments to the current arguments.
+ var newArgs = Array.prototype.slice.call(arguments);
+ Array.prototype.unshift.apply(newArgs, boundArgs);
+ return func.apply(thisObj, newArgs);
+ };
+ } else {
+ return function() {
+ return func.apply(thisObj, arguments);
+ };
+ }
+ };""";
« 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