Skip to content

Commit

Permalink
[Refactor] use Reflect.setPrototypeOf and dunder-proto in `setPro…
Browse files Browse the repository at this point in the history
…to` helper
  • Loading branch information
ljharb committed Dec 30, 2024
1 parent 50cfd7e commit 21ee4a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
21 changes: 14 additions & 7 deletions helpers/setProto.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

var GetIntrinsic = require('get-intrinsic');

var reflectSetProto = GetIntrinsic('%Reflect.setPrototypeOf%', true);
var originalSetProto = GetIntrinsic('%Object.setPrototypeOf%', true);

var hasProto = require('has-proto')();
var setDunderProto = require('dunder-proto/set');

module.exports = originalSetProto || (
var $TypeError = require('es-errors/type');

hasProto
? function (O, proto) {
O.__proto__ = proto; // eslint-disable-line no-proto, no-param-reassign
module.exports = reflectSetProto
? function setProto(O, proto) {
if (reflectSetProto(O, proto)) {
return O;
}
: null
);
throw new $TypeError('Reflect.setPrototypeOf: failed to set [[Prototype]]');
}
: originalSetProto || (
setDunderProto ? function setProto(O, proto) {
setDunderProto(O, proto);
return O;
} : null
);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"data-view-buffer": "^1.0.2",
"data-view-byte-length": "^1.0.2",
"data-view-byte-offset": "^1.0.1",
"dunder-proto": "^1.0.1",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.0.0",
Expand Down

0 comments on commit 21ee4a3

Please sign in to comment.