Extend baseCreateCallback to functions bound with native Function#bind and those with __bindData__ of false.

This commit is contained in:
John-David Dalton
2013-10-04 21:24:10 -07:00
parent e114c18031
commit fd2ddca6f2
8 changed files with 131 additions and 72 deletions

View File

@@ -1106,24 +1106,30 @@
if (typeof func != 'function') {
return identity;
}
// exit early if there is no `thisArg`
if (typeof thisArg == 'undefined') {
// exit early for no `thisArg` or already bound by `Function#bind`
if (typeof thisArg == 'undefined' || !('prototype' in func)) {
return func;
}
var bindData = func.__bindData__ || (support.funcNames && !func.name);
var bindData = func.__bindData__;
if (typeof bindData == 'undefined') {
var source = reThis && fnToString.call(func);
if (!support.funcNames && source && !reFuncName.test(source)) {
bindData = true;
if (support.funcNames) {
bindData = !func.name;
}
if (support.funcNames || !bindData) {
// checks if `func` references the `this` keyword and stores the result
bindData = !support.funcDecomp || reThis.test(source);
setBindData(func, bindData);
bindData = bindData || !support.funcDecomp;
if (!bindData) {
var source = fnToString.call(func);
if (!support.funcNames) {
bindData = !reFuncName.test(source);
}
if (!bindData) {
// checks if `func` references the `this` keyword and stores the result
bindData = reThis.test(source);
setBindData(func, bindData);
}
}
}
// exit early if there are no `this` references or `func` is bound
if (bindData !== true && (bindData && bindData[1] & 1)) {
if (bindData === false || (bindData !== true && bindData[1] & 1)) {
return func;
}
switch (argCount) {
@@ -1544,7 +1550,7 @@
isPartialRight = partialRightArgs = false;
}
var bindData = func && func.__bindData__;
if (bindData) {
if (typeof bindData == 'object') {
if (isBind && !(bindData[1] & 1)) {
bindData[4] = thisArg;
}