From f43f860083eb3472a00dd470c0f2afecfc22f356 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 8 Mar 2024 22:40:20 -0800 Subject: [PATCH] [Robustness] use `call-bind` rather than `.apply` --- index.js | 10 ++++++---- package.json | 4 +++- tsconfig.json | 3 +++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 49ba021..e5621ce 100644 --- a/index.js +++ b/index.js @@ -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 () { diff --git a/package.json b/package.json index f171b02..5ac2b1a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tsconfig.json b/tsconfig.json index e991e94..422a583 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "@ljharb/tsconfig", + "compilerOptions": { + "target": "es2021", + }, "exclude": [ "coverage/**", "example/**",