Fix globalThis
MODIFY
packages/compartment-shim/src/globalObject.js
packages/compartment-shim/src/globalObject.js
@@ -106,7 +106,7 @@ export function createGlobalObject(realmRec, { globalTransforms }) {
// *** 18.2, 18.3, 18.4 etc.
for (const name of globalPropertyNames) {
if (!objectHasOwnProperty(realmRec.intrinsics, name)) {
- // only create the global is the intrinsic exists.
+ // only create the global if the intrinsic exists.
// eslint-disable-next-line no-continue
continue;
}

MODIFY
packages/compartment-shim/test/integration/globalObject-properties.test.js
packages/compartment-shim/test/integration/globalObject-properties.test.js
@@ -6,7 +6,7 @@ import stubFunctionConstructors from '../stubFunctionConstructors.js';
const { test } = tap;
test('globalObject properties', t => {
- t.plan(9);
+ t.plan(10);
// Mimic repairFunctions.
stubFunctionConstructors(sinon);
@@ -17,6 +17,7 @@ test('globalObject properties', t => {
t.notEqual(c.global, this);
t.notEqual(c.global, globalThis);
+ t.equal(c.global.globalThis, c.global);
t.equal(c.global.Array, Array);
t.equal(c.global.Array, globalThis.Array);

MODIFY
packages/compartment-shim/test/unit/globalObject.test.js
packages/compartment-shim/test/unit/globalObject.test.js
@@ -6,7 +6,7 @@ import stubFunctionConstructors from '../stubFunctionConstructors.js';
const { test } = tap;
test('globalObject', t => {
- t.plan(32);
+ t.plan(38);
// Mimic repairFunctions.
stubFunctionConstructors(sinon);
@@ -16,6 +16,7 @@ test('globalObject', t => {
Date: {},
eval: globalThis.eval,
Function: globalThis.Function,
+ globalThis: {}
},
};
@@ -25,8 +26,9 @@ test('globalObject', t => {
t.equal(Object.getPrototypeOf(globalObject), Object.prototype);
t.ok(!Object.isFrozen(globalObject));
t.notEqual(globalObject, globalThis);
+ t.equal(globalObject.globalThis, globalObject);
- t.equals(Object.getOwnPropertyNames(globalObject).length, 6);
+ t.equals(Object.getOwnPropertyNames(globalObject).length, 7);
const descs = Object.getOwnPropertyDescriptors(globalObject);
for (const [name, desc] of Object.entries(descs)) {
@@ -38,7 +40,7 @@ test('globalObject', t => {
t.ok(isNaN(desc.value), `${name} should be NaN`);
} else if (name === 'undefined') {
t.equal(desc.value, undefined, `${name} should be undefined`);
- } else if (['eval', 'Function'].includes(name)) {
+ } else if (['eval', 'Function', 'globalThis'].includes(name)) {
t.notEqual(
desc.value,
realmRec.intrinsics[name],

Fix globalThis