Allow thisArg to be null or undefined in Function.prototype.bind()
git-svn-id: svn://10.0.0.236/trunk@261594 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
983b37f5ef
commit
6ec33d9ff5
@ -309,11 +309,11 @@ public class BaseFunction extends IdScriptableObject implements Function
|
||||
final Scriptable boundThis;
|
||||
final Object[] boundArgs;
|
||||
if (argc > 0) {
|
||||
boundThis = ScriptRuntime.toObject(cx, scope, args[0]);
|
||||
boundThis = ScriptRuntime.toObjectOrNull(cx, args[0], scope);
|
||||
boundArgs = new Object[argc-1];
|
||||
System.arraycopy(args, 1, boundArgs, 0, argc-1);
|
||||
} else {
|
||||
boundThis = ScriptRuntime.toObject(cx, scope, Undefined.instance);
|
||||
boundThis = null;
|
||||
boundArgs = ScriptRuntime.emptyArgs;
|
||||
}
|
||||
return new BoundFunction(cx, scope, targetFunction, boundThis, boundArgs);
|
||||
|
||||
@ -79,7 +79,8 @@ public class BoundFunction extends BaseFunction {
|
||||
@Override
|
||||
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] extraArgs)
|
||||
{
|
||||
return targetFunction.call(cx, scope, boundThis, concat(boundArgs, extraArgs));
|
||||
Scriptable callThis = boundThis != null ? boundThis : ScriptRuntime.getTopCallScope(cx);
|
||||
return targetFunction.call(cx, scope, callThis, concat(boundArgs, extraArgs));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user