Skip to content

Commit

Permalink
[Fix] in IE 8, global can !== window despite them being prototypes of…
Browse files Browse the repository at this point in the history
… each other
  • Loading branch information
ljharb committed Oct 19, 2023
1 parent f354848 commit 30d0859
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions index.js
Expand Up @@ -239,12 +239,13 @@ module.exports = function inspect_(obj, options, depth, seen) {
if (isString(obj)) {
return markBoxed(inspect(String(obj)));
}
// note: in IE 8, sometimes `global !== window` but both are the prototypes of each other
/* eslint-env browser */
if (typeof window !== 'undefined' && obj === window) {
return '{ [object Window] }';
}
if (obj === global) {
/* eslint-env browser */
if (typeof window !== 'undefined') {
return '{ [object Window] }';
}
return '{ [object global] }';
return '{ [object globalThis] }';
}
if (!isDate(obj) && !isRegExp(obj)) {
var ys = arrObjKeys(obj, inspect);
Expand Down
2 changes: 1 addition & 1 deletion test/global.js
Expand Up @@ -7,7 +7,7 @@ var globalThis = require('globalthis')();

test('global object', function (t) {
/* eslint-env browser */
var expected = typeof window === 'undefined' ? 'global' : 'Window';
var expected = typeof window === 'undefined' ? 'globalThis' : 'Window';
t.equal(
inspect([globalThis]),
'[ { [object ' + expected + '] } ]'
Expand Down

0 comments on commit 30d0859

Please sign in to comment.