Fixes #2749. Restricting to instance methods in class bodies, where it actually has a chance in hell of calling the correct thing.

This commit is contained in:
Jeremy Ashkenas 2013-03-04 21:26:01 +13:00
parent 667b96b495
commit 47f0ea69b8
2 changed files with 11 additions and 17 deletions

View File

@ -796,23 +796,19 @@
};
Call.prototype.superReference = function(o) {
var accesses, method, name;
var accesses, method;
method = o.scope.namedMethod();
if (!method) {
throw SyntaxError('cannot call super outside of a named function.');
}
name = method.name;
if (method.klass) {
if (method != null ? method.klass : void 0) {
accesses = [new Access(new Literal('__super__'))];
if (method["static"]) {
accesses.push(new Access(new Literal('constructor')));
}
accesses.push(new Access(new Literal(name)));
accesses.push(new Access(new Literal(method.name)));
return (new Value(new Literal(method.klass), accesses)).compile(o);
} else if (method.ctor) {
return "" + name + ".__super__.constructor";
} else if (method != null ? method.ctor : void 0) {
return "" + method.name + ".__super__.constructor";
} else {
return "this.constructor.__super__." + name;
throw SyntaxError('cannot call super outside of an instance method.');
}
};

View File

@ -515,17 +515,15 @@ exports.Call = class Call extends Base
# method.
superReference: (o) ->
method = o.scope.namedMethod()
throw SyntaxError 'cannot call super outside of a named function.' unless method
{name} = method
if method.klass
if method?.klass
accesses = [new Access(new Literal '__super__')]
accesses.push new Access new Literal 'constructor' if method.static
accesses.push new Access new Literal name
accesses.push new Access new Literal method.name
(new Value (new Literal method.klass), accesses).compile o
else if method.ctor
"#{name}.__super__.constructor"
else if method?.ctor
"#{method.name}.__super__.constructor"
else
"this.constructor.__super__.#{name}"
throw SyntaxError 'cannot call super outside of an instance method.'
# The appropriate `this` value for a `super` call.
superThis : (o) ->