Skip to content

Commit

Permalink
[Robustness] use call-bind rather than .apply
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 9, 2024
1 parent ace3782 commit f43f860
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
10 changes: 6 additions & 4 deletions index.js
Expand Up @@ -6,24 +6,26 @@ var nextTick = typeof setImmediate === 'undefined'
? process.nextTick
: setImmediate;

var callBind = require('call-bind');

/** @type {import('.')} */
module.exports = function resumer(write, end) {
var tr = through(write, end);
tr.pause();
var resume = tr.resume;
var pause = tr.pause;
var resume = callBind.apply(tr.resume);
var pause = callBind.apply(tr.pause);
var paused = false;

tr.pause = function () {
paused = true;
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/57164
return pause.apply(this, arguments);
return pause(this, arguments);
};

tr.resume = function () {
paused = false;
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/57164
return resume.apply(this, arguments);
return resume(this, arguments);
};

nextTick(function () {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -18,12 +18,14 @@
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"dependencies": {
"@ljharb/through": "^2.3.13"
"@ljharb/through": "^2.3.13",
"call-bind": "^1.0.7"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.1",
"@ljharb/eslint-config": "^21.1.0",
"@ljharb/tsconfig": "^0.1.1",
"@types/call-bind": "^1.0.5",
"@types/node": "^20.11.25",
"aud": "^2.0.4",
"auto-changelog": "^2.4.0",
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
@@ -1,5 +1,8 @@
{
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"target": "es2021",
},
"exclude": [
"coverage/**",
"example/**",
Expand Down

0 comments on commit f43f860

Please sign in to comment.