Revert "Passing the arguments object directly when generating a closure."

This reverts commit 7b887f065d.
This commit is contained in:
Timothy Jones
2010-10-24 02:15:01 +13:00
parent 7b887f065d
commit 3834e7bc33
3 changed files with 11 additions and 12 deletions

View File

@@ -1734,19 +1734,19 @@
};
Closure = {
wrap: function(expressions, statement, noReturn) {
var args, call, func, mentionsArgs;
var args, call, func, mentionsArgs, meth;
if (expressions.containsPureStatement()) {
return expressions;
}
mentionsArgs = expressions.contains(this.literalArgs);
func = new Parens(new Code((mentionsArgs ? [new Literal('arguments')] : []), Expressions.wrap([expressions])));
func = new Parens(new Code([], Expressions.wrap([expressions])));
args = [];
if (mentionsArgs || expressions.contains(this.literalThis)) {
if ((mentionsArgs = expressions.contains(this.literalArgs)) || (expressions.contains(this.literalThis))) {
meth = new Literal(mentionsArgs ? 'apply' : 'call');
args = [new Literal('this')];
if (mentionsArgs) {
args.push(new Literal('arguments'));
}
func = new Value(func, [new Accessor(new Literal('call'))]);
func = new Value(func, [new Accessor(meth)]);
func.noReturn = noReturn;
}
call = new Call(func, args);

View File

@@ -1480,13 +1480,14 @@ Closure =
# then make sure that the closure wrapper preserves the original values.
wrap: (expressions, statement, noReturn) ->
return expressions if expressions.containsPureStatement()
mentionsArgs = expressions.contains @literalArgs
func = new Parens new Code (if mentionsArgs then [new Literal 'arguments'] else []), Expressions.wrap [expressions]
func = new Parens new Code [], Expressions.wrap [expressions]
args = []
if mentionsArgs or expressions.contains @literalThis
if (mentionsArgs = expressions.contains @literalArgs) or
( expressions.contains @literalThis)
meth = new Literal if mentionsArgs then 'apply' else 'call'
args = [new Literal 'this']
args.push new Literal 'arguments' if mentionsArgs
func = new Value func, [new Accessor new Literal 'call']
func = new Value func, [new Accessor meth]
func.noReturn = noReturn
call = new Call func, args
if statement then Expressions.wrap [call] else call

View File

@@ -70,9 +70,7 @@ ok result.join(' ') is '6 4 2'
# Closure-wrapped comprehensions that refer to the "arguments" object.
expr = ->
result = for item in arguments
ok arguments.callee is expr
item * item
result = item * item for item in arguments
ok expr(2, 4, 8).join(' ') is '4 16 64'