src/privateMember.js
function _functionBelongsToObject(self, caller, target, protectedMode = false) {
    if (!caller) return false;

    // We are caching the results for better performance.
    let cacheOfResultsForSelf = resultCache.get(self);

    if (cacheOfResultsForSelf && cacheOfResultsForSelf.has(caller)) {
        return cacheOfResultsForSelf.get(caller);
    }

    let proto = Object.getPrototypeOf(self);

    // proto !== target - means that extend was made.
    let check;
    if ((caller.name === 'get' || caller.name === 'set')) {
        check = !getterOrSetterBelongsToObject(caller, target);
    } else {
        check = !(target[caller.name] || target.constructor === caller);
    }
    if (target && proto !== target && check) {
        if (protectedMode) {
            if (!checkIfTargetIsRelated(proto, target)) {
                return false;
            }
        } else {
            return false;
        }
    }

    let result = false;

    while (proto !== Object && result === false && proto.constructor !== Object) {
        result = functionBelongsToObjectInternal(proto, caller);
        proto = Object.getPrototypeOf(proto);
    }

    if (!cacheOfResultsForSelf) {
        cacheOfResultsForSelf = new WeakMap();
    }

    cacheOfResultsForSelf.set(caller, result);
    resultCache.set(self, cacheOfResultsForSelf);
    return result;
}
function _functionBelongsToObject(self, caller, target, protectedMode = false) {
    if (!caller) return false;

    // We are caching the results for better performance.
    let cacheOfResultsForSelf = resultCache.get(self);

    if (cacheOfResultsForSelf && cacheOfResultsForSelf.has(caller)) {
        return cacheOfResultsForSelf.get(caller);
    }

    let proto = Object.getPrototypeOf(self);

    // proto !== target - means that extend was made.
    let check;
    if ((caller.name === 'get' || caller.name === 'set')) {
        check = !getterOrSetterBelongsToObject(caller, target);
    } else {
        check = !(target[caller.name] || target.constructor === caller);
    }
    if (target && proto !== target && check) {
        if (protectedMode) {
            if (!checkIfTargetIsRelated(proto, target)) {
                return false;
            }
        } else {
            return false;
        }
    }

    let result = false;

    while (proto !== Object && result === false && proto.constructor !== Object) {
        result = functionBelongsToObjectInternal(proto, caller);
        proto = Object.getPrototypeOf(proto);
    }

    if (!cacheOfResultsForSelf) {
        cacheOfResultsForSelf = new WeakMap();
    }

    cacheOfResultsForSelf.set(caller, result);
    resultCache.set(self, cacheOfResultsForSelf);
    return result;
}
function _functionBelongsToObject ( self , caller , target , protectedMode = false ) { if ( ! caller ) return false ; // We are caching the results for better performance. let cacheOfResultsForSelf = resultCache . get ( self ) ; if ( cacheOfResultsForSelf && cacheOfResultsForSelf . has ( caller ) ) { return cacheOfResultsForSelf . get ( caller ) ; } let proto = Object . getPrototypeOf ( self ) ; // proto !== target - means that extend was made. let check ; if ( ( caller . name === 'get' || caller . name === 'set' ) ) { check = ! getterOrSetterBelongsToObject ( caller , target ) ; } else { check = ! ( target [ caller . name ] || target . constructor === caller ) ; } if ( target && proto !== target && check ) { if ( protectedMode ) { if ( ! checkIfTargetIsRelated ( proto , target ) ) { return false ; } } else { return false ; } } let result = false ; while ( proto !== Object && result === false && proto . constructor !== Object ) { result = functionBelongsToObjectInternal ( proto , caller ) ; proto = Object . getPrototypeOf ( proto ) ; } if ( ! cacheOfResultsForSelf ) { cacheOfResultsForSelf = new WeakMap ( ) ; } cacheOfResultsForSelf . set ( caller , result ) ; resultCache . set ( self , cacheOfResultsForSelf ) ; return result ; }
Checks if `caller` belongs to `self`.
@param {Object} self - The current `this`.
@param {Object} caller - The caller function.
@param {Object} target - The original define property target.
@param {boolean} protectedMode - Whether this should be protected instead of private.
@returns {bool}
@private
Checks if caller belongs to self .