fixes #1966: external constructors should produce their return value

This commit is contained in:
Michael Ficarra
2011-12-24 06:37:09 -05:00
parent 0c4cb309b0
commit 080ed2e8dd
3 changed files with 8 additions and 0 deletions

View File

@@ -1255,6 +1255,7 @@
if (this.externalCtor) {
this.ctor.body.push(new Literal("" + this.externalCtor + ".apply(this, arguments)"));
}
this.ctor.body.makeReturn();
this.body.expressions.unshift(this.ctor);
}
this.ctor.ctor = this.ctor.name = name;

View File

@@ -923,6 +923,7 @@ exports.Class = class Class extends Base
@ctor = new Code
@ctor.body.push new Literal "#{name}.__super__.constructor.apply(this, arguments)" if @parent
@ctor.body.push new Literal "#{@externalCtor}.apply(this, arguments)" if @externalCtor
@ctor.body.makeReturn()
@body.expressions.unshift @ctor
@ctor.ctor = @ctor.name = name
@ctor.klass = null

View File

@@ -490,6 +490,7 @@ test "#1182: execution order needs to be considered as well", ->
test "#1182: external constructors with bound functions", ->
fn = ->
{one: 1}
this
class B
class A
constructor: fn
@@ -604,3 +605,8 @@ test "#494: Named classes", ->
class A.B["C"]
ok A.B.C.name isnt 'C'
test "#1966: external constructors should produce their return value", ->
ctor = -> {}
class A then constructor: ctor
ok (new A) not instanceof A