util.promisify
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -8,2 +8,24 @@ # Changelog | ||
## [v1.1.2](https://github.com/ljharb/util.promisify/compare/v1.1.1...v1.1.2) - 2023-04-20 | ||
### Fixed | ||
- [Fix] avoid crashing with `--disable-proto=throw` [`#26`](https://github.com/ljharb/util.promisify/issues/26) | ||
### Commits | ||
- [actions] reuse common workflows [`2736cb6`](https://github.com/ljharb/util.promisify/commit/2736cb6c8ea7c1cfeca6ddc3c9cf1615aab9a1a8) | ||
- [meta] use `npmignore` to autogenerate an npmignore file [`0eb5abb`](https://github.com/ljharb/util.promisify/commit/0eb5abbe3d3e78fccd20c9f6cac665a7687b54b8) | ||
- [meta] reorganize package.json [`e610642`](https://github.com/ljharb/util.promisify/commit/e610642b27f1498a2114d970ce327b29cfd3bde6) | ||
- [Fix] proper error name [`727c30c`](https://github.com/ljharb/util.promisify/commit/727c30c330b829ee5946226f69b114fae9c761cf) | ||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `aud`, `auto-changelog`, `safe-publish-latest`, `tape` [`ecc9281`](https://github.com/ljharb/util.promisify/commit/ecc9281821e111f04c3f57e5f28e01386721da30) | ||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `tape` [`91c385d`](https://github.com/ljharb/util.promisify/commit/91c385d7c500678ae87c9b022cc5003815b2bf89) | ||
- [actions] update rebase action [`c62f4bf`](https://github.com/ljharb/util.promisify/commit/c62f4bfac476b1cdf4836d2e554dca712e2552b8) | ||
- [Refactor] use `has-proto` [`e423ed0`](https://github.com/ljharb/util.promisify/commit/e423ed024de422aa75264f2cfd13a16455da2fc4) | ||
- [Dev Deps] update `@es-shims/api`, `ljharb/eslint-config`,` aud`, `tape` [`62717c1`](https://github.com/ljharb/util.promisify/commit/62717c13f97227771f0b72c3d0638976d04e472a) | ||
- [Refactor] use `safe-array-concat` [`d068529`](https://github.com/ljharb/util.promisify/commit/d068529b46fbff46960111dfe857d43734f3a0f1) | ||
- [Deps] update `define-properties`, `has-symbols`, `object.getownpropertydescriptors` [`bd8a7be`](https://github.com/ljharb/util.promisify/commit/bd8a7be795d349176a667a69755a6472facbb2af) | ||
- [Deps] update `call-bind`, `has-symbols`, `object.getownpropertydescriptors` [`7473409`](https://github.com/ljharb/util.promisify/commit/7473409dbc10974549a869c8bed8172342a40728) | ||
- [Deps] update `define-properties`, `object.getownpropertydescriptors` [`4f244be`](https://github.com/ljharb/util.promisify/commit/4f244beb8e8f51011f265bef0bb87e2a8972f320) | ||
## [v1.1.1](https://github.com/ljharb/util.promisify/compare/v1.1.0...v1.1.1) - 2021-01-08 | ||
@@ -10,0 +32,0 @@ |
@@ -7,6 +7,8 @@ 'use strict'; | ||
var hasProto = [].__proto__ === Array.prototype; // eslint-disable-line no-proto | ||
var gPO = Object.getPrototypeOf; | ||
var sPO = Object.setPrototypeOf; | ||
var hasProto = require('has-proto')() || (typeof gPO === 'function' && gPO([]) === Array.prototype); | ||
if (!isES5 || !hasProto) { | ||
throw new TypeError('util.promisify requires a true ES5 environment, that also supports `__proto__`'); | ||
throw new TypeError('util.promisify requires a true ES5+ environment, that also supports `__proto__` and/or `Object.getPrototypeOf`'); | ||
} | ||
@@ -20,9 +22,12 @@ | ||
var oDP = Object.defineProperty; | ||
var $Promise = Promise; | ||
var $TypeError = TypeError; | ||
var safeConcat = require('safe-array-concat'); | ||
var callBound = require('call-bind/callBound'); | ||
var $slice = callBound('Array.prototype.slice'); | ||
var $concat = callBound('Array.prototype.concat'); | ||
var $forEach = callBound('Array.prototype.forEach'); | ||
var hasSymbols = require('has-symbols')(); | ||
var hasSymbols = require('has-symbols/shams')(); | ||
@@ -35,5 +40,7 @@ // eslint-disable-next-line no-restricted-properties | ||
if (typeof orig !== 'function') { | ||
var error = new TypeError('The "original" argument must be of type function'); | ||
error.name = 'TypeError [ERR_INVALID_ARG_TYPE]'; | ||
var error = new $TypeError('The "original" argument must be of type function'); | ||
error.code = 'ERR_INVALID_ARG_TYPE'; | ||
error.toString = function value() { | ||
return this.name + '[' + this.code + ']: ' + this.message; | ||
}; | ||
throw error; | ||
@@ -45,5 +52,10 @@ } | ||
if (typeof customFunction !== 'function') { | ||
throw new TypeError('The [util.promisify.custom] property must be a function'); | ||
var customError = $TypeError('The [util.promisify.custom] property must be of type function.'); | ||
customError.code = 'ERR_INVALID_ARG_TYPE'; | ||
customError.toString = function value() { | ||
return this.name + '[' + this.code + ']: ' + this.message; | ||
}; | ||
throw customError; | ||
} | ||
Object.defineProperty(customFunction, kCustomPromisifiedSymbol, { | ||
oDP(customFunction, kCustomPromisifiedSymbol, { | ||
configurable: true, | ||
@@ -64,4 +76,4 @@ enumerable: false, | ||
var self = this; // eslint-disable-line no-invalid-this | ||
return new Promise(function (resolve, reject) { | ||
orig.apply(self, $concat(args, function (err) { | ||
return new $Promise(function (resolve, reject) { | ||
orig.apply(self, safeConcat(args, function (err) { | ||
var values = arguments.length > 1 ? $slice(arguments, 1) : []; | ||
@@ -72,3 +84,3 @@ if (err) { | ||
var obj = {}; | ||
$forEach(argumentNames, function (name, index) { | ||
forEach(argumentNames, function (name, index) { | ||
obj[name] = values[index]; | ||
@@ -84,5 +96,9 @@ }); | ||
promisified.__proto__ = orig.__proto__; // eslint-disable-line no-proto | ||
if (typeof sPO === 'function' && typeof gPO === 'function') { | ||
sPO(promisified, gPO(orig)); | ||
} else { | ||
promisified.__proto__ = orig.__proto__; // eslint-disable-line no-proto | ||
} | ||
Object.defineProperty(promisified, kCustomPromisifiedSymbol, { | ||
oDP(promisified, kCustomPromisifiedSymbol, { | ||
configurable: true, | ||
@@ -96,3 +112,3 @@ enumerable: false, | ||
try { | ||
Object.defineProperty(promisified, k, v); | ||
oDP(promisified, k, v); | ||
} catch (e) { | ||
@@ -99,0 +115,0 @@ // handle nonconfigurable function properties |
{ | ||
"name": "util.promisify", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Polyfill/shim for util.promisify in node versions < v8", | ||
"main": "index.js", | ||
"dependencies": { | ||
"call-bind": "^1.0.0", | ||
"define-properties": "^1.1.3", | ||
"for-each": "^0.3.3", | ||
"has-symbols": "^1.0.1", | ||
"object.getownpropertydescriptors": "^2.1.1" | ||
}, | ||
"devDependencies": { | ||
"@es-shims/api": "^2.1.2", | ||
"@ljharb/eslint-config": "^17.3.0", | ||
"aud": "^1.1.3", | ||
"auto-changelog": "^2.2.1", | ||
"eslint": "^7.17.0", | ||
"nyc": "^10.3.2", | ||
"safe-publish-latest": "^1.1.4", | ||
"tape": "^5.1.1" | ||
}, | ||
"scripts": { | ||
"prepublish": "safe-publish-latest", | ||
"lint": "eslint .", | ||
"prepack": "npmignore --auto --commentLines=autogenerated", | ||
"prepublishOnly": "safe-publish-latest", | ||
"prepublish": "not-in-publish || npm run prepublishOnly", | ||
"lint": "eslint --ext=js,mjs.", | ||
"postlint": "es-shim-api --bound", | ||
@@ -55,2 +40,23 @@ "pretest": "npm run lint", | ||
"homepage": "https://github.com/ljharb/util.promisify#readme", | ||
"dependencies": { | ||
"call-bind": "^1.0.2", | ||
"define-properties": "^1.2.0", | ||
"for-each": "^0.3.3", | ||
"has-proto": "^1.0.1", | ||
"has-symbols": "^1.0.3", | ||
"object.getownpropertydescriptors": "^2.1.6", | ||
"safe-array-concat": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@es-shims/api": "^2.3.1", | ||
"@ljharb/eslint-config": "^21.0.1", | ||
"aud": "^2.0.2", | ||
"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.6.3" | ||
}, | ||
"auto-changelog": { | ||
@@ -63,3 +69,8 @@ "output": "CHANGELOG.md", | ||
"hideCredit": true | ||
}, | ||
"publishConfig": { | ||
"ignore": [ | ||
".github/workflows" | ||
] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
23503
227
7
10
16
+ Addedhas-proto@^1.0.1
+ Addedsafe-array-concat@^1.0.0
Updatedcall-bind@^1.0.2
Updateddefine-properties@^1.2.0
Updatedhas-symbols@^1.0.3