mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
fixes #1630: in
should check indices of the right operand when it can
pass a `hasOwnProperty` check for them
This commit is contained in:
parent
8686e31271
commit
2ff6c4c3fc
5 changed files with 35 additions and 24 deletions
|
@ -9,7 +9,7 @@
|
|||
return child;
|
||||
}, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __indexOf = Array.prototype.indexOf || function(item) {
|
||||
for (var i = 0, l = this.length; i < l; i++) {
|
||||
if (this[i] === item) return i;
|
||||
if (__hasProp.call(this, i) && this[i] === item) return i;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
@ -680,7 +680,6 @@
|
|||
}
|
||||
Extends.prototype.children = ['child', 'parent'];
|
||||
Extends.prototype.compile = function(o) {
|
||||
utility('hasProp');
|
||||
return new Call(new Value(new Literal(utility('extends'))), [this.child, this.parent]).compile(o);
|
||||
};
|
||||
return Extends;
|
||||
|
@ -2083,11 +2082,21 @@
|
|||
return ifn;
|
||||
};
|
||||
UTILITIES = {
|
||||
"extends": 'function(child, parent) {\n for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n child.__super__ = parent.prototype;\n return child;\n}',
|
||||
bind: 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }',
|
||||
indexOf: 'Array.prototype.indexOf || function(item) {\n for (var i = 0, l = this.length; i < l; i++) {\n if (this[i] === item) return i;\n }\n return -1;\n}',
|
||||
hasProp: 'Object.prototype.hasOwnProperty',
|
||||
slice: 'Array.prototype.slice'
|
||||
"extends": function() {
|
||||
return "function(child, parent) {\n for (var key in parent) { if (" + (utility('hasProp')) + ".call(parent, key)) child[key] = parent[key]; }\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n child.__super__ = parent.prototype;\n return child;\n}";
|
||||
},
|
||||
bind: function() {
|
||||
return 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }';
|
||||
},
|
||||
indexOf: function() {
|
||||
return "Array.prototype.indexOf || function(item) {\n for (var i = 0, l = this.length; i < l; i++) {\n if (" + (utility('hasProp')) + ".call(this, i) && this[i] === item) return i;\n }\n return -1;\n}";
|
||||
},
|
||||
hasProp: function() {
|
||||
return 'Object.prototype.hasOwnProperty';
|
||||
},
|
||||
slice: function() {
|
||||
return 'Array.prototype.slice';
|
||||
}
|
||||
};
|
||||
LEVEL_TOP = 1;
|
||||
LEVEL_PAREN = 2;
|
||||
|
@ -2104,7 +2113,7 @@
|
|||
utility = function(name) {
|
||||
var ref;
|
||||
ref = "__" + name;
|
||||
Scope.root.assign(ref, UTILITIES[name]);
|
||||
Scope.root.assign(ref, UTILITIES[name]());
|
||||
return ref;
|
||||
};
|
||||
multident = function(code, tab) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue