Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Feb 26, 2024
1 parent 88ff949 commit 15f8982
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 28 deletions.
56 changes: 44 additions & 12 deletions node_modules/function-bind/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,75 @@
/* eslint no-invalid-this: 1 */

var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
var slice = Array.prototype.slice;
var toStr = Object.prototype.toString;
var max = Math.max;
var funcType = '[object Function]';

var concatty = function concatty(a, b) {
var arr = [];

for (var i = 0; i < a.length; i += 1) {
arr[i] = a[i];
}
for (var j = 0; j < b.length; j += 1) {
arr[j + a.length] = b[j];
}

return arr;
};

var slicy = function slicy(arrLike, offset) {
var arr = [];
for (var i = offset || 0, j = 0; i < arrLike.length; i += 1, j += 1) {
arr[j] = arrLike[i];
}
return arr;
};

var joiny = function (arr, joiner) {
var str = '';
for (var i = 0; i < arr.length; i += 1) {
str += arr[i];
if (i + 1 < arr.length) {
str += joiner;
}
}
return str;
};

module.exports = function bind(that) {
var target = this;
if (typeof target !== 'function' || toStr.call(target) !== funcType) {
if (typeof target !== 'function' || toStr.apply(target) !== funcType) {
throw new TypeError(ERROR_MESSAGE + target);
}
var args = slice.call(arguments, 1);
var args = slicy(arguments, 1);

var bound;
var binder = function () {
if (this instanceof bound) {
var result = target.apply(
this,
args.concat(slice.call(arguments))
concatty(args, arguments)
);
if (Object(result) === result) {
return result;
}
return this;
} else {
return target.apply(
that,
args.concat(slice.call(arguments))
);
}
return target.apply(
that,
concatty(args, arguments)
);

};

var boundLength = Math.max(0, target.length - args.length);
var boundLength = max(0, target.length - args.length);
var boundArgs = [];
for (var i = 0; i < boundLength; i++) {
boundArgs.push('$' + i);
boundArgs[i] = '$' + i;
}

bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
bound = Function('binder', 'return function (' + joiny(boundArgs, ',') + '){ return binder.apply(this,arguments); }')(binder);

if (target.prototype) {
var Empty = function Empty() {};
Expand Down
52 changes: 38 additions & 14 deletions node_modules/function-bind/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "function-bind",
"version": "1.1.1",
"version": "1.1.2",
"description": "Implementation of Function.prototype.bind",
"keywords": [
"function",
Expand All @@ -9,7 +9,13 @@
"es5"
],
"author": "Raynos <[email protected]>",
"repository": "git://github.com/Raynos/function-bind.git",
"repository": {
"type": "git",
"url": "https://github.com/Raynos/function-bind.git"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"main": "index",
"homepage": "https://github.com/Raynos/function-bind",
"contributors": [
Expand All @@ -25,24 +31,29 @@
"url": "https://github.com/Raynos/function-bind/issues",
"email": "[email protected]"
},
"dependencies": {},
"devDependencies": {
"@ljharb/eslint-config": "^12.2.1",
"covert": "^1.1.0",
"eslint": "^4.5.0",
"jscs": "^3.0.7",
"tape": "^4.8.0"
"@ljharb/eslint-config": "^21.1.0",
"aud": "^2.0.3",
"auto-changelog": "^2.4.0",
"eslint": "=8.8.0",
"in-publish": "^2.0.1",
"npmignore": "^0.3.0",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.7.1"
},
"license": "MIT",
"scripts": {
"prepublishOnly": "safe-publish-latest",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepack": "npmignore --auto --commentLines=autogenerated",
"pretest": "npm run lint",
"test": "npm run tests-only",
"posttest": "npm run coverage -- --quiet",
"tests-only": "node test",
"coverage": "covert test/*.js",
"lint": "npm run jscs && npm run eslint",
"jscs": "jscs *.js */*.js",
"eslint": "eslint *.js */*.js"
"posttest": "aud --production",
"tests-only": "nyc tape 'test/**/*.js'",
"lint": "eslint --ext=js,mjs .",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"testling": {
"files": "test/index.js",
Expand All @@ -59,5 +70,18 @@
"iphone/6.0..latest",
"android-browser/4.2..latest"
]
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}
8 changes: 6 additions & 2 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -6046,9 +6046,13 @@
}
},
"node_modules/function-bind": {
"version": "1.1.1",
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"inBundle": true,
"license": "MIT"
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/function-loop": {
"version": "2.0.1",
Expand Down

0 comments on commit 15f8982

Please sign in to comment.