create repairDataProperties in SES via makeRepairDataProperties
MODIFY
src/bundle/createSES.js
src/bundle/createSES.js
@@ -24,7 +24,7 @@ import getAllPrimordials from './getAllPrimordials';
import whitelist from './whitelist';
import makeConsole from './make-console';
import makeMakeRequire from './make-require';
-import { repairDataProperties } from './mutable';
+import makeRepairDataProperties from './mutable';
const FORWARDED_REALMS_OPTIONS = ['sloppyGlobals', 'transforms'];
@@ -111,6 +111,9 @@ export function createSESWithRealmConstructor(creatorStrings, Realm) {
const r = Realm.makeRootRealm({ ...realmsOptions, shims });
+ const makeRepairDataPropertiesSrc = `(${makeRepairDataProperties})`
+ const repairDataProperties = r.evaluate(makeRepairDataPropertiesSrc)()
+
// Build a harden() with an empty fringe. It will be populated later when
// we call harden(allIntrinsics).
const makeHardenerSrc = `(${makeHardener})`;
@@ -132,6 +135,7 @@ export function createSESWithRealmConstructor(creatorStrings, Realm) {
r.global,
anonIntrinsics,
);
+
repairDataProperties(allIntrinsics);
harden(allIntrinsics);

MODIFY
src/bundle/mutable.js
src/bundle/mutable.js
// https://github.com/google/caja/blob/master/src/com/google/caja/ses/startSES.js
// https://github.com/google/caja/blob/master/src/com/google/caja/ses/repairES5.js
-import {
+export default function makeRepairDataProperties () {
+
+ const {
defineProperties,
getOwnPropertyDescriptor,
getOwnPropertyDescriptors,
- ownKeys,
- objectHasOwnProperty
-} from '../../realms-shim/src/commons';
-
+ hasOwnProperty
+ } = Object;
+ const { ownKeys } = Reflect;
/**
* For a special set of properties (defined below), it ensures that the
@@ -49,7 +50,7 @@ function beMutable(obj, prop, desc) {
if (obj === this) {
throw new TypeError(`Cannot assign to read only property '${prop}' of object '${obj}'`);
}
- if (objectHasOwnProperty.call(this, prop)) {
+ if (hasOwnProperty.call(this, prop)) {
this[prop] = newValue;
} else {
defineProperty(this, prop, {
@@ -70,7 +71,7 @@ function beMutable(obj, prop, desc) {
}
}
-export function beMutableProperties(obj) {
+ function beMutableProperties(obj) {
if (!obj) {
return;
}
@@ -81,7 +82,7 @@ export function beMutableProperties(obj) {
ownKeys(obj).forEach(prop => beMutable(obj, prop, descs[prop]));
}
-export function beMutableProperty(obj, prop) {
+ function beMutableProperty(obj, prop) {
const desc = getOwnPropertyDescriptor(obj, prop);
beMutable(obj, prop, desc);
}
@@ -90,10 +91,10 @@ export function beMutableProperty(obj, prop) {
* These properties are subject to the override mistake
* and must be converted before freezing.
*/
-export function repairDataProperties(intrinsics) {
+ function repairDataProperties(intrinsics) {
const { global: g, anonIntrinsics: a } = intrinsics;
- [
+ const toBeRepaired = [
g.Object.prototype,
g.Array.prototype,
g.Boolean.prototype,
@@ -109,7 +110,6 @@ export function repairDataProperties(intrinsics) {
a.IteratorPrototype,
a.ArrayIteratorPrototype,
- g.Promise.prototype,
g.DataView.prototype,
a.TypedArray,
@@ -127,7 +127,15 @@ export function repairDataProperties(intrinsics) {
g.SyntaxError.prototype,
g.TypeError.prototype,
g.URIError.prototype
- ].forEach(beMutableProperties);
+ ]
+
+ // Promise may be removed from the whitelist
+ const PromisePrototype = g.Promise && g.Promise.prototype;
+ if (PromisePrototype) {
+ toBeRepaired.push(PromisePrototype)
+ }
+
+ toBeRepaired.forEach(beMutableProperties);
}
// Object.defineProperty is allowed to fail silently,
@@ -135,3 +143,6 @@ export function repairDataProperties(intrinsics) {
function defineProperty (obj, prop, desc) {
defineProperties(obj, { [prop]: desc });
}
+
+ return repairDataProperties;
+}
\ No newline at end of file

create repairDataProperties in SES via makeRepairDataProperties