private JsValue Bind(JsValue thisObj, JsValue[] arguments) { var target = thisObj.TryCast<ICallable>(x => { throw new JavaScriptException(Engine.TypeError); }); var thisArg = arguments.At(0); var f = new BindFunctionInstance(Engine) {Extensible = true}; f.TargetFunction = thisObj; f.BoundThis = thisArg; f.BoundArgs = arguments.Skip(1).ToArray(); f.Prototype = Engine.Function.PrototypeObject; var o = target as FunctionInstance; if (o != null) { var l = TypeConverter.ToNumber(o.Get("length")) - (arguments.Length - 1); f.FastAddProperty("length", System.Math.Max(l, 0), false, false, false); } else { f.FastAddProperty("length", 0, false, false, false); } var thrower = Engine.Function.ThrowTypeError; f.DefineOwnProperty("caller", new PropertyDescriptor(thrower, thrower, false, false), false); f.DefineOwnProperty("arguments", new PropertyDescriptor(thrower, thrower, false, false), false); return f; }