Skip to content

Commit 9dde370

Browse files
committed
[Fix] avoid relying on __proto__ accessor
Fixes #4
1 parent c39dd06 commit 9dde370

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

Diff for: index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var forEach = require('for-each');
44
var callBind = require('call-bind');
5+
var gPO = require('reflect.getprototypeof/polyfill')();
56

67
var typedArrays = require('available-typed-arrays')();
78

@@ -10,7 +11,6 @@ var typedArrays = require('available-typed-arrays')();
1011

1112
/** @type {Object.<typeof typedArrays, ByteOffsetGetter>} */
1213
var getters = {};
13-
var hasProto = require('has-proto')();
1414

1515
var gOPD = require('gopd');
1616
var oDP = Object.defineProperty;
@@ -25,8 +25,8 @@ if (gOPD) {
2525
var Proto = global[typedArray].prototype;
2626
// @ts-expect-error TS can't guarantee the callback is invoked sync
2727
var descriptor = gOPD(Proto, 'byteOffset');
28-
if (!descriptor && hasProto) {
29-
var superProto = Proto.__proto__; // eslint-disable-line no-proto
28+
if (!descriptor) {
29+
var superProto = gPO(Proto);
3030
// @ts-expect-error TS can't guarantee the callback is invoked sync
3131
descriptor = gOPD(superProto, 'byteOffset');
3232
}

Diff for: package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@
6262
"for-each": "^0.3.3",
6363
"gopd": "^1.0.1",
6464
"has-proto": "^1.0.3",
65-
"is-typed-array": "^1.1.13"
65+
"is-typed-array": "^1.1.13",
66+
"reflect.getprototypeof": "^1.0.6"
6667
},
6768
"devDependencies": {
6869
"@arethetypeswrong/cli": "^0.17.0",
6970
"@ljharb/eslint-config": "^21.1.1",
7071
"@ljharb/tsconfig": "^0.2.0",
7172
"@types/call-bind": "^1.0.5",
73+
"@types/es-abstract": "^1.17.9",
7274
"@types/for-each": "^0.3.3",
7375
"@types/gopd": "^1.0.3",
7476
"@types/is-callable": "^1.1.2",
@@ -107,7 +109,8 @@
107109
},
108110
"publishConfig": {
109111
"ignore": [
110-
".github/workflows"
112+
".github/workflows",
113+
"types"
111114
]
112115
}
113116
}

Diff for: tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "@ljharb/tsconfig",
33
"compilerOptions": {
44
"target": "ES2021",
5+
"maxNodeModuleJsDepth": 0,
56
},
67
"exclude": [
78
"coverage",

Diff for: types/reflect.getprototypeof/polyfill.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module 'reflect.getprototypeof/polyfill' {
2+
function getPolyfill(): typeof Reflect.getPrototypeOf;
3+
4+
export = getPolyfill;
5+
}

0 commit comments

Comments
 (0)