abb11c80d1
didn't consider objects with [[Call]]
This commit is contained in:
parent
d6fbfa55b6
commit
ddd6e9a48b
|
@ -813,7 +813,7 @@
|
||||||
}
|
}
|
||||||
if (this.isNew) {
|
if (this.isNew) {
|
||||||
idt = this.tab + TAB;
|
idt = this.tab + TAB;
|
||||||
return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" && result !== null ? result : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function() {})";
|
return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args), t = typeof result;\n" + idt + "return t == \"object\" || t == \"function\" ? result || child : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function(){})";
|
||||||
}
|
}
|
||||||
base = new Value(this.variable);
|
base = new Value(this.variable);
|
||||||
if ((name = base.properties.pop()) && base.isComplex()) {
|
if ((name = base.properties.pop()) && base.isComplex()) {
|
||||||
|
|
|
@ -586,9 +586,9 @@ exports.Call = class Call extends Base
|
||||||
return """
|
return """
|
||||||
(function(func, args, ctor) {
|
(function(func, args, ctor) {
|
||||||
#{idt}ctor.prototype = func.prototype;
|
#{idt}ctor.prototype = func.prototype;
|
||||||
#{idt}var child = new ctor, result = func.apply(child, args);
|
#{idt}var child = new ctor, result = func.apply(child, args), t = typeof result;
|
||||||
#{idt}return typeof result === "object" && result !== null ? result : child;
|
#{idt}return t == "object" || t == "function" ? result || child : child;
|
||||||
#{@tab}})(#{ @variable.compile o, LEVEL_LIST }, #{splatArgs}, function() {})
|
#{@tab}})(#{ @variable.compile o, LEVEL_LIST }, #{splatArgs}, function(){})
|
||||||
"""
|
"""
|
||||||
base = new Value @variable
|
base = new Value @variable
|
||||||
if (name = base.properties.pop()) and base.isComplex()
|
if (name = base.properties.pop()) and base.isComplex()
|
||||||
|
|
|
@ -392,11 +392,17 @@ test "#1011: passing a splat to a method of a number", ->
|
||||||
eq '1011', (131.0).toString [5]...
|
eq '1011', (131.0).toString [5]...
|
||||||
|
|
||||||
|
|
||||||
test "splats and the `new` operator: functions that return `null` should produce their instance", ->
|
test "splats and the `new` operator: functions that return `null` should construct their instance", ->
|
||||||
args = []
|
args = []
|
||||||
child = new (constructor = -> null) args...
|
child = new (constructor = -> null) args...
|
||||||
ok child instanceof constructor
|
ok child instanceof constructor
|
||||||
|
|
||||||
|
test "splats and the `new` operator: functions that return functions should construct their return value", ->
|
||||||
|
args = []
|
||||||
|
fn = ->
|
||||||
|
child = new (constructor = -> fn) args...
|
||||||
|
ok child not instanceof constructor
|
||||||
|
eq fn, child
|
||||||
|
|
||||||
test "implicit return", ->
|
test "implicit return", ->
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue