diff --git a/function_test.go b/function_test.go index e4c2f62..00fac39 100644 --- a/function_test.go +++ b/function_test.go @@ -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) { diff --git a/type_function.go b/type_function.go index 4203551..64d1233 100644 --- a/type_function.go +++ b/type_function.go @@ -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 }