refactor(ses): split initGlobalObject into constants and properties
Preparations for shared evaluate, no observable changes
MODIFY
packages/ses/src/compartment-shim.js
packages/ses/src/compartment-shim.js
@@ -20,7 +20,10 @@ import {
weakmapSet,
weaksetHas,
} from './commons.js';
-import { initGlobalObject } from './global-object.js';
+import {
+ initGlobalObjectConstants,
+ initGlobalObjectProperties,
+} from './global-object.js';
import { isValidIdentifierName } from './scope-constants.js';
import { sharedGlobalPropertyNames } from './whitelist.js';
import { load } from './module-load.js';
@@ -269,7 +272,9 @@ export const makeCompartmentConstructor = (
const knownScopeProxies = new WeakSet();
const globalObject = {};
- initGlobalObject(
+
+ initGlobalObjectConstants(globalObject);
+ initGlobalObjectProperties(
globalObject,
intrinsics,
sharedGlobalPropertyNames,

MODIFY
packages/ses/src/global-object.js
packages/ses/src/global-object.js
@@ -4,7 +4,27 @@ import { makeFunctionConstructor } from './make-function-constructor.js';
import { constantProperties, universalPropertyNames } from './whitelist.js';
/**
- * initGlobalObject()
+ * initGlobalObjectConstants()
+ * Create new global object using a process similar to ECMA specifications
+ * (portions of SetRealmGlobalObject and SetDefaultGlobalBindings).
+ * `newGlobalPropertyNames` should be either `initialGlobalPropertyNames` or
+ * `sharedGlobalPropertyNames`.
+ *
+ * @param {Object} globalObject
+ */
+export const initGlobalObjectConstants = globalObject => {
+ for (const [name, constant] of entries(constantProperties)) {
+ defineProperty(globalObject, name, {
+ value: constant,
+ writable: false,
+ enumerable: false,
+ configurable: false,
+ });
+ }
+};
+
+/**
+ * initGlobalObjectProperties()
* Create new global object using a process similar to ECMA specifications
* (portions of SetRealmGlobalObject and SetDefaultGlobalBindings).
* `newGlobalPropertyNames` should be either `initialGlobalPropertyNames` or
@@ -19,7 +39,7 @@ import { constantProperties, universalPropertyNames } from './whitelist.js';
* @param {Array<Transform>} [options.globalTransforms]
* @param {(Object) => void} [options.markVirtualizedNativeFunction]
*/
-export const initGlobalObject = (
+export const initGlobalObjectProperties = (
globalObject,
intrinsics,
newGlobalPropertyNames,
@@ -27,15 +47,6 @@ export const initGlobalObject = (
compartmentPrototype,
{ globalTransforms, markVirtualizedNativeFunction },
) => {
- for (const [name, constant] of entries(constantProperties)) {
- defineProperty(globalObject, name, {
- value: constant,
- writable: false,
- enumerable: false,
- configurable: false,
- });
- }
-
for (const [name, intrinsicName] of entries(universalPropertyNames)) {
if (objectHasOwnProperty(intrinsics, intrinsicName)) {
defineProperty(globalObject, name, {

MODIFY
packages/ses/src/lockdown-shim.js
packages/ses/src/lockdown-shim.js
@@ -24,7 +24,10 @@ import tameMathObject from './tame-math-object.js';
import tameRegExpConstructor from './tame-regexp-constructor.js';
import enablePropertyOverrides from './enable-property-overrides.js';
import tameLocaleMethods from './tame-locale-methods.js';
-import { initGlobalObject } from './global-object.js';
+import {
+ initGlobalObjectConstants,
+ initGlobalObjectProperties,
+} from './global-object.js';
import { initialGlobalPropertyNames } from './whitelist.js';
import { tameFunctionToString } from './tame-function-tostring.js';
import { tameDomains } from './tame-domains.js';
@@ -289,7 +292,8 @@ export const repairIntrinsics = (
// Initialize the powerful initial global, i.e., the global of the
// start compartment, from the intrinsics.
- initGlobalObject(
+ initGlobalObjectConstants(globalThis);
+ initGlobalObjectProperties(
globalThis,
intrinsics,
initialGlobalPropertyNames,

MODIFY
packages/ses/test/test-global-object.js
packages/ses/test/test-global-object.js
import '../index.js';
import './lockdown-safe.js';
import test from 'ava';
-import { initGlobalObject } from '../src/global-object.js';
+import {
+ initGlobalObjectConstants,
+ initGlobalObjectProperties,
+} from '../src/global-object.js';
import { sharedGlobalPropertyNames } from '../src/whitelist.js';
import {
makeCompartmentConstructor,
@@ -20,7 +23,8 @@ test('globalObject', t => {
};
const globalObject = {};
- initGlobalObject(
+ initGlobalObjectConstants(globalObject);
+ initGlobalObjectProperties(
globalObject,
intrinsics,
sharedGlobalPropertyNames,

refactor(ses): split initGlobalObject into constants and properties
Preparations for shared evaluate, no observable changes