Fixed #669: Wrapper arguments

This commit is contained in:
Stan Angeloff
2010-09-08 15:18:08 +03:00
parent 9290e508c6
commit cd6261d477
2 changed files with 16 additions and 3 deletions

View File

@@ -523,7 +523,7 @@
return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + (args) + ")"; return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + (args) + ")";
}; };
CallNode.prototype.compileSplat = function(o) { CallNode.prototype.compileSplat = function(o) {
var meth, obj, temp; var _b, _c, _d, mentionsArgs, meth, obj, temp;
meth = this.meth || this.superReference(o); meth = this.meth || this.superReference(o);
obj = this.variable && this.variable.source || 'this'; obj = this.variable && this.variable.source || 'this';
if (obj.match(/\(/)) { if (obj.match(/\(/)) {
@@ -532,8 +532,18 @@
meth = ("(" + (temp) + " = " + (this.variable.source) + ")" + (this.variable.last)); meth = ("(" + (temp) + " = " + (this.variable.source) + ")" + (this.variable.last));
} }
if (this.isNew) { if (this.isNew) {
mentionsArgs = false;
_c = this.args;
for (_b = 0, _d = _c.length; _b < _d; _b++) {
(function() {
var arg = _c[_b];
return arg.contains(function(n) {
return mentionsArgs || (mentionsArgs = (n instanceof LiteralNode && (n.value === 'arguments')));
});
})();
}
utility('extends'); utility('extends');
return "" + (this.first) + "(function() {\n" + (this.idt(1)) + "var ctor = function(){};\n" + (this.idt(1)) + "__extends(ctor, " + (meth) + ");\n" + (this.idt(1)) + "return " + (meth) + ".apply(new ctor, " + (this.compileSplatArguments(o)) + ");\n" + (this.tab) + "}).call(this)" + (this.last); return "" + (this.first) + "(function() {\n" + (this.idt(1)) + "var ctor = function(){};\n" + (this.idt(1)) + "__extends(ctor, " + (meth) + ");\n" + (this.idt(1)) + "return " + (meth) + ".apply(new ctor, " + (this.compileSplatArguments(o)) + ");\n" + (this.tab) + "})." + (mentionsArgs ? 'apply(this, arguments)' : 'call(this)') + (this.last);
} else { } else {
return "" + (this.first) + (this.prefix()) + (meth) + ".apply(" + (obj) + ", " + (this.compileSplatArguments(o)) + ")" + (this.last); return "" + (this.first) + (this.prefix()) + (meth) + ".apply(" + (obj) + ", " + (this.compileSplatArguments(o)) + ")" + (this.last);
} }

View File

@@ -474,13 +474,16 @@ exports.CallNode = class CallNode extends BaseNode
obj = temp obj = temp
meth = "(#{temp} = #{ @variable.source })#{ @variable.last }" meth = "(#{temp} = #{ @variable.source })#{ @variable.last }"
if @isNew if @isNew
mentionsArgs = no
for arg in @args
arg.contains (n) -> mentionsArgs or= n instanceof LiteralNode and (n.value is 'arguments')
utility 'extends' utility 'extends'
""" """
#{@first}(function() { #{@first}(function() {
#{@idt(1)}var ctor = function(){}; #{@idt(1)}var ctor = function(){};
#{@idt(1)}__extends(ctor, #{meth}); #{@idt(1)}__extends(ctor, #{meth});
#{@idt(1)}return #{meth}.apply(new ctor, #{ @compileSplatArguments(o) }); #{@idt(1)}return #{meth}.apply(new ctor, #{ @compileSplatArguments(o) });
#{@tab}}).call(this)#{@last} #{@tab}}).#{ if mentionsArgs then 'apply(this, arguments)' else 'call(this)'}#{@last}
""" """
else else
"#{@first}#{@prefix()}#{meth}.apply(#{obj}, #{ @compileSplatArguments(o) })#{@last}" "#{@first}#{@prefix()}#{meth}.apply(#{obj}, #{ @compileSplatArguments(o) })#{@last}"