MCPcopy Index your code
hub / github.com/deployd/deployd / createWrap

Function createWrap

test-app/public/sinon.js:16119–16172  ·  view source on GitHub ↗

* Creates a function that either curries or invokes `func` with optional * `this` binding and partially applied arguments. * * @private * @param {Function|string} func The function or method name to wrap. * @param {number} bitmask The bitmask flags.

(func, bitmask, thisArg, partials, holders, argPos, ary, arity)

Source from the content-addressed store, hash-verified

16117 * @returns {Function} Returns the new wrapped function.
16118 */
16119 function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
16120 var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
16121 if (!isBindKey && typeof func != 'function') {
16122 throw new TypeError(FUNC_ERROR_TEXT);
16123 }
16124 var length = partials ? partials.length : 0;
16125 if (!length) {
16126 bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
16127 partials = holders = undefined;
16128 }
16129 ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
16130 arity = arity === undefined ? arity : toInteger(arity);
16131 length -= holders ? holders.length : 0;
16132
16133 if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
16134 var partialsRight = partials,
16135 holdersRight = holders;
16136
16137 partials = holders = undefined;
16138 }
16139 var data = isBindKey ? undefined : getData(func);
16140
16141 var newData = [
16142 func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
16143 argPos, ary, arity
16144 ];
16145
16146 if (data) {
16147 mergeData(newData, data);
16148 }
16149 func = newData[0];
16150 bitmask = newData[1];
16151 thisArg = newData[2];
16152 partials = newData[3];
16153 holders = newData[4];
16154 arity = newData[9] = newData[9] === undefined
16155 ? (isBindKey ? 0 : func.length)
16156 : nativeMax(newData[9] - length, 0);
16157
16158 if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
16159 bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
16160 }
16161 if (!bitmask || bitmask == WRAP_BIND_FLAG) {
16162 var result = createBind(func, bitmask, thisArg);
16163 } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
16164 result = createCurry(func, bitmask, arity);
16165 } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
16166 result = createPartial(func, bitmask, thisArg, partials);
16167 } else {
16168 result = createHybrid.apply(undefined, newData);
16169 }
16170 var setter = data ? baseSetData : setData;
16171 return setWrapToString(setter(result, newData), func, bitmask);
16172 }
16173
16174 /**
16175 * Used by `_.defaults` to customize its `_.assignIn` use to assign properties

Callers 5

aryFunction · 0.85
sinon.jsFile · 0.85
curryFunction · 0.85
curryRightFunction · 0.85
flipFunction · 0.85

Calls 6

toIntegerFunction · 0.85
mergeDataFunction · 0.85
createBindFunction · 0.85
createCurryFunction · 0.85
createPartialFunction · 0.85
setWrapToStringFunction · 0.85

Tested by

no test coverage detected