Skip to content

Commit

Permalink
[Fix] avoid crashing with --disable-proto=throw
Browse files Browse the repository at this point in the history
Fixes #26.
  • Loading branch information
ljharb committed Sep 14, 2022
1 parent 727c30c commit 2e3c8b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/node-noproto.yml
@@ -0,0 +1,18 @@
name: 'Tests: node --disable-proto=throw'

on: [pull_request, push]

jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 12.17'
type: minors
command: 'NODE_OPTIONS="--disable-proto=throw" npx tape "test/**/*.js"'

node:
name: 'node --disable-proto=throw'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: 'echo tests completed'
12 changes: 9 additions & 3 deletions implementation.js
Expand Up @@ -4,10 +4,12 @@ var forEach = require('for-each');

var isES5 = typeof Object.defineProperty === 'function';

var hasProto = require('has-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`');
}

var getOwnPropertyDescriptors = require('object.getownpropertydescriptors');
Expand Down Expand Up @@ -85,7 +87,11 @@ module.exports = function promisify(orig) {
});
};

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
}

oDP(promisified, kCustomPromisifiedSymbol, {
configurable: true,
Expand Down

0 comments on commit 2e3c8b3

Please sign in to comment.