Fixes #2630 -- Class bodies shouldn't be able to reference arguments.

This commit is contained in:
Jeremy Ashkenas
2013-01-06 19:08:32 -10:00
parent 69ef1abdf6
commit 82aeb70380
3 changed files with 9 additions and 0 deletions

View File

@@ -2886,6 +2886,9 @@
func = new Code([], Block.wrap([expressions]));
args = [];
if ((mentionsArgs = expressions.contains(this.literalArgs)) || expressions.contains(this.literalThis)) {
if (mentionsArgs && expressions.classBody) {
throw SyntaxError("Class bodies don't have arguments");
}
meth = new Literal(mentionsArgs ? 'apply' : 'call');
args = [new Literal('this')];
if (mentionsArgs) {

View File

@@ -1934,6 +1934,8 @@ Closure =
func = new Code [], Block.wrap [expressions]
args = []
if (mentionsArgs = expressions.contains @literalArgs) or expressions.contains @literalThis
if mentionsArgs and expressions.classBody
throw SyntaxError "Class bodies don't have arguments"
meth = new Literal if mentionsArgs then 'apply' else 'call'
args = [new Literal 'this']
args.push new Literal 'arguments' if mentionsArgs

View File

@@ -676,3 +676,7 @@ test "#2052: classes should work in strict mode", ->
class A
catch e
ok no
test "#2630: class bodies can't reference arguments", ->
throws ->
CoffeeScript.compile('class Test then arguments')