Skip to content

Commit

Permalink
[Refactor] use gopd
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 29, 2024
1 parent 3e41644 commit 0209ccb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"shim"
],
"dependencies": {
"define-properties": "^1.2.1"
"define-properties": "^1.2.1",
"gopd": "^1.0.1"
},
"devDependencies": {
"@es-shims/api": "^2.5.0",
Expand Down
11 changes: 9 additions & 2 deletions shim.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
'use strict';

var define = require('define-properties');
var gOPD = require('gopd');
var getPolyfill = require('./polyfill');

module.exports = function shimGlobal() {
var polyfill = getPolyfill();
if (define.supportsDescriptors) {
var descriptor = Object.getOwnPropertyDescriptor(polyfill, 'globalThis');
if (!descriptor || (descriptor.configurable && (descriptor.enumerable || !descriptor.writable || globalThis !== polyfill))) { // eslint-disable-line max-len
var descriptor = gOPD(polyfill, 'globalThis');
if (
!descriptor
|| (
descriptor.configurable
&& (descriptor.enumerable || !descriptor.writable || globalThis !== polyfill)
)
) {
Object.defineProperty(polyfill, 'globalThis', {
configurable: true,
enumerable: false,
Expand Down

0 comments on commit 0209ccb

Please sign in to comment.