shim: remove BaseRealm, we no longer need it as a distinct object
MODIFY
shim/src/realm.js
shim/src/realm.js
@@ -104,21 +104,7 @@ function createRealmRec(unsafeRec) {
return realmRec;
}
-// Define newRealm onto new sharedGlobalDescs, so it can be defined in
-// the safeGlobal like the rest of the shared globals.
-function createRealmGlobalObject(unsafeRec) {
- // eslint-disable-next-line no-use-before-define
- const Realm = createRealmFacade(unsafeRec, BaseRealm);
- unsafeRec.sharedGlobalDescs.Realm = {
- value: Realm,
- writable: true,
- configurable: true
- };
- return Realm;
-}
-
-const BaseRealm = {
- initializeRootRealm(selfClass, self) {
+function initRootRealm(selfClass, self) {
// note: 'self' is the instance of the Realm, and 'selfClass' is the
// Realm constructor (facade) we build in buildChildRealm().
@@ -130,14 +116,16 @@ const BaseRealm = {
// Define Realm onto new sharedGlobalDescs, so it can be copied onto the
// safeGlobal like the rest of the .
+ // eslint-disable-next-line no-use-before-define
const Realm = createRealmGlobalObject(unsafeRec);
registerUnsafeRecForRealm(Realm, unsafeRec);
const realmRec = createRealmRec(unsafeRec);
registerRealmRecForRealmInstance(self, realmRec);
// todo: is this where we run shims? but only in RootRealms, not compartments
- },
- initializeCompartment(selfClass, self) {
+}
+
+function initCompartment(selfClass, self) {
// note: 'self' is the instance of the Realm, and 'selfClass' is the
// Realm constructor (facade) we build in buildChildRealm().
@@ -148,21 +136,44 @@ const BaseRealm = {
const realmRec = createRealmRec(unsafeRec);
registerRealmRecForRealmInstance(self, realmRec);
- },
- getGlobal(self) {
+}
+
+function getRealmGlobal(self) {
const { safeGlobal } = getRealmRecForRealmInstance(self);
return safeGlobal;
- },
- evaluate(self, x) {
+}
+
+function realmEvaluate(self, x) {
const { safeEval } = getRealmRecForRealmInstance(self);
return safeEval(x);
}
+
+// Define Realm onto new sharedGlobalDescs, so it can be defined in the
+// safeGlobal like the rest of the shared globals.
+function createRealmGlobalObject(unsafeRec) {
+ const Realm = createRealmFacade(unsafeRec, {
+ initRootRealm,
+ initCompartment,
+ getRealmGlobal,
+ realmEvaluate
+ });
+ unsafeRec.sharedGlobalDescs.Realm = {
+ value: Realm,
+ writable: true,
+ configurable: true
};
+ return Realm;
+}
// Create the current unsafeRec from the current "primal" realm (the realm
// where the Realm shim is loaded and executed).
const currentUnsafeRec = createCurrentUnsafeRec();
-const Realm = createRealmFacade(currentUnsafeRec, BaseRealm);
+const Realm = createRealmFacade(currentUnsafeRec, {
+ initRootRealm,
+ initCompartment,
+ getRealmGlobal,
+ realmEvaluate
+});
registerUnsafeRecForRealm(Realm, currentUnsafeRec);
export default Realm;

MODIFY
shim/src/realmFacade.js
shim/src/realmFacade.js
// buildChildRealm is immediately turned into a string, and this function is
// never referenced again, because it closes over the wrong intrinsics
-function buildChildRealm(BaseRealm) {
+function buildChildRealm({ initRootRealm, initCompartment, getRealmGlobal, realmEvaluate }) {
// This Object and Reflect are brand new, from a new unsafeRec, so no user
// code has been run or had a chance to manipulate them. We extract these
// properties for brevity, not for security. Don't ever run this function
@@ -64,20 +64,15 @@ function buildChildRealm(BaseRealm) {
}
}
- const baseInitializeRootRealm = BaseRealm.initializeRootRealm;
- const baseInitializeCompartment = BaseRealm.initializeCompartment;
- const baseGetGlobal = BaseRealm.getGlobal;
- const baseEvaluate = BaseRealm.evaluate;
-
class Realm {
static makeRootRealm(...args) {
const r = new Realm();
- callAndWrapError(baseInitializeRootRealm, Realm, r, ...args);
+ callAndWrapError(initRootRealm, Realm, r, ...args);
return r;
}
static makeCompartment(...args) {
const r = new Realm();
- callAndWrapError(baseInitializeCompartment, Realm, r, ...args);
+ callAndWrapError(initCompartment, Realm, r, ...args);
return r;
}
@@ -90,11 +85,11 @@ function buildChildRealm(BaseRealm) {
// baseGetGlobal immediately does a trademark check (it fails unless
// this 'this' is present in a weakmap that is only populated with
// legitimate Realm instances)
- return callAndWrapError(baseGetGlobal, this);
+ return callAndWrapError(getRealmGlobal, this);
}
evaluate(...args) {
// safe against strange 'this', as above
- return callAndWrapError(baseEvaluate, this, ...args);
+ return callAndWrapError(realmEvaluate, this, ...args);
}
}

shim: remove BaseRealm, we no longer need it as a distinct object