1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00

Fix .length property of functions via .bind

This commit is contained in:
Robert Krimen 2014-01-20 12:52:52 -08:00
parent a36c19873f
commit 2d6125ee2c
2 changed files with 13 additions and 2 deletions

View File

@ -210,6 +210,13 @@ func TestFunction_bind(t *testing.T) {
}
[ ghi ];
`, "true")
test(`
var abc = function (def, ghi) {};
var jkl = abc.bind({});
var mno = abc.bind({}, 1, 2);
[ jkl.length, mno.length ];
`, "2,0")
}
func TestFunction_toString(t *testing.T) {

View File

@ -38,8 +38,12 @@ func (runtime *_runtime) newBoundFunctionObject(target *_object, this Value, arg
call: newBoundCallFunction(target, this, argumentList),
construct: defaultConstructFunction,
}
// FIXME
self.defineProperty("length", toValue_int(0), 0000, false)
length := int(toInt32(target.get("length")))
length -= len(argumentList)
if length < 0 {
length = 0
}
self.defineProperty("length", toValue_int(length), 0000, false)
return self
}