ses 0.15.7 → 0.15.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -194,6 +194,14 @@ export interface Assert {
194
194
  makeAssert: MakeAssert;
195
195
  }
196
196
 
197
+ interface CompartmentEvaluateOptions {
198
+ sloppyGlobalsMode?: boolean;
199
+ __moduleShimLexicals__?: Object;
200
+ __evadeHtmlCommentTest__?: boolean;
201
+ __evadeImportExpressionTest__?: boolean;
202
+ __rejectSomeDirectEvalExpressions__?: boolean;
203
+ }
204
+
197
205
  declare global {
198
206
  var harden: Harden;
199
207
 
@@ -216,7 +224,7 @@ declare global {
216
224
 
217
225
  get name(): string;
218
226
 
219
- evaluate(code: string): any;
227
+ evaluate(code: string, options?: CompartmentEvaluateOptions): any;
220
228
 
221
229
  import(specifier: string): Promise<{ namespace: ModuleExportsNamespace }>;
222
230
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "0.15.7",
3
+ "version": "0.15.8",
4
4
  "description": "Hardened JavaScript for Fearless Cooperation",
5
5
  "keywords": [
6
6
  "lockdown",
@@ -52,17 +52,17 @@
52
52
  "lint": "yarn lint:types && yarn lint:js",
53
53
  "lint-fix": "eslint --fix .",
54
54
  "lint:js": "eslint .",
55
- "lint:types": "tsc --build jsconfig.json",
55
+ "lint:types": "tsc -p jsconfig.json",
56
56
  "prepublish": "yarn run clean && yarn build",
57
57
  "qt": "ava",
58
58
  "test": "yarn build && ava",
59
59
  "test:platform-compatability": "node test/package/test.cjs"
60
60
  },
61
61
  "devDependencies": {
62
- "@endo/compartment-mapper": "^0.6.5",
63
- "@endo/eslint-config": "^0.4.2",
64
- "@endo/static-module-record": "^0.6.12",
65
- "@endo/test262-runner": "^0.1.18",
62
+ "@endo/compartment-mapper": "^0.6.6",
63
+ "@endo/eslint-config": "^0.4.3",
64
+ "@endo/static-module-record": "^0.6.13",
65
+ "@endo/test262-runner": "^0.1.19",
66
66
  "ava": "^3.12.1",
67
67
  "babel-eslint": "^10.0.3",
68
68
  "c8": "^7.7.3",
@@ -75,7 +75,7 @@
75
75
  "prettier": "^1.19.1",
76
76
  "sinon": "8.0.4",
77
77
  "terser": "^4.8.0",
78
- "typescript": "^4.2.3"
78
+ "typescript": "~4.5.5"
79
79
  },
80
80
  "files": [
81
81
  "LICENSE*",
@@ -178,5 +178,5 @@
178
178
  ],
179
179
  "timeout": "2m"
180
180
  },
181
- "gitHead": "96df4cf238b245cc92c78e4af4667f405b8cf4f0"
181
+ "gitHead": "9d2f88ab47f546bc59b6b6e7340482209b3cee56"
182
182
  }
package/src/commons.js CHANGED
@@ -62,6 +62,7 @@ export const {
62
62
  keys,
63
63
  prototype: objectPrototype,
64
64
  seal,
65
+ preventExtensions,
65
66
  setPrototypeOf,
66
67
  values,
67
68
  } = Object;
@@ -73,6 +74,8 @@ export const {
73
74
  matchAll: matchAllSymbol,
74
75
  } = Symbol;
75
76
 
77
+ export const { isInteger } = Number;
78
+
76
79
  export const { stringify: stringifyJson } = JSON;
77
80
 
78
81
  // At time of this writing, we still support Node 10 which doesn't have
@@ -137,6 +140,8 @@ export const { prototype: weaksetPrototype } = WeakSet;
137
140
  export const { prototype: functionPrototype } = Function;
138
141
  export const { prototype: promisePrototype } = Promise;
139
142
 
143
+ export const typedArrayPrototype = getPrototypeOf(Uint8Array.prototype);
144
+
140
145
  /**
141
146
  * uncurryThis()
142
147
  * This form of uncurry uses Reflect.apply()
@@ -174,6 +179,7 @@ export const mapHas = uncurryThis(mapPrototype.has);
174
179
  export const iterateMap = uncurryThis(mapPrototype[iteratorSymbol]);
175
180
  //
176
181
  export const setAdd = uncurryThis(setPrototype.add);
182
+ export const setDelete = uncurryThis(setPrototype.delete);
177
183
  export const setForEach = uncurryThis(setPrototype.forEach);
178
184
  export const setHas = uncurryThis(setPrototype.has);
179
185
  export const iterateSet = uncurryThis(setPrototype[iteratorSymbol]);
@@ -40,8 +40,8 @@ const { details: X, quote: q } = assert;
40
40
  * global `process` object holding an `env` object,
41
41
  * optionally holding a property named for the `optionName` whose value is the
42
42
  * configuration setting of that option. For example, for the optionName
43
- * `ALLOW_IMPLICIT_REMOTABLES` it would look in
44
- * `globalThis.process.env.ALLOW_IMPLICIT_REMOTABLES`.
43
+ * `FOO_BAR` it would look in
44
+ * `globalThis.process.env.FOO_BAR`.
45
45
  *
46
46
  * If setting is either absent or `undefined`, that indicates that
47
47
  * this configuration option should have its default behavior, whatever that is.
@@ -27,26 +27,88 @@ import {
27
27
  TypeError,
28
28
  WeakMap,
29
29
  WeakSet,
30
+ apply,
30
31
  arrayForEach,
32
+ defineProperty,
31
33
  freeze,
34
+ getOwnPropertyDescriptor,
32
35
  getOwnPropertyDescriptors,
33
36
  getPrototypeOf,
37
+ isInteger,
34
38
  isObject,
35
39
  objectHasOwnProperty,
36
40
  ownKeys,
41
+ preventExtensions,
37
42
  setAdd,
38
43
  setForEach,
39
44
  setHas,
45
+ toStringTagSymbol,
46
+ typedArrayPrototype,
40
47
  weakmapGet,
41
48
  weakmapSet,
42
49
  weaksetAdd,
43
50
  weaksetHas,
44
51
  } from './commons.js';
52
+ import { assert } from './error/assert.js';
45
53
 
46
54
  /**
47
55
  * @typedef {import('../index.js').Harden} Harden
48
56
  */
49
57
 
58
+ // Obtain the string tag accessor of of TypedArray so we can indirectly use the
59
+ // TypedArray brand check it employs.
60
+ const typedArrayToStringTag = getOwnPropertyDescriptor(
61
+ typedArrayPrototype,
62
+ toStringTagSymbol,
63
+ );
64
+ assert(typedArrayToStringTag);
65
+ const getTypedArrayToStringTag = typedArrayToStringTag.get;
66
+ assert(getTypedArrayToStringTag);
67
+
68
+ // Exported for tests.
69
+ /** @param {unknown} object */
70
+ export const isTypedArray = object => {
71
+ // The object must pass a brand check or toStringTag will return undefined.
72
+ const tag = apply(getTypedArrayToStringTag, object, []);
73
+ return tag !== undefined;
74
+ };
75
+
76
+ /**
77
+ * @template T
78
+ * @param {ArrayLike<T>} array
79
+ */
80
+ const freezeTypedArray = array => {
81
+ const descs = getOwnPropertyDescriptors(array);
82
+
83
+ preventExtensions(array);
84
+
85
+ // Downgrade writable expandos to readonly, even if non-configurable.
86
+ arrayForEach(ownKeys(descs), (/** @type {string | symbol} */ name) => {
87
+ const desc = descs[/** @type {string} */ (name)];
88
+ // The numbered properties are writable and non-configurable,
89
+ // and cannot be made non-writable by defineProperty.
90
+ // This is a strange behavior intrinsic to TypedArrays, but no more harmful
91
+ // than the mutability of properties of a hardened Map or Set,
92
+ // so we carve out this exceptional behavior.
93
+ //
94
+ // TypedArrays are integer-indexed exotic objects, so indexed properties
95
+ // outside the range of 0 to the typed array's length are disallowed.
96
+ // Assignment to these indexes silently fails and defining an indexed
97
+ // property throws an error.
98
+ // So, we only need to make non-index properties non-writable and
99
+ // non-configurable.
100
+ // https://tc39.es/ecma262/#sec-integer-indexed-exotic-objects
101
+ const number = +String(name);
102
+ if (!isInteger(number)) {
103
+ defineProperty(array, name, {
104
+ ...desc,
105
+ writable: false,
106
+ configurable: false,
107
+ });
108
+ }
109
+ });
110
+ };
111
+
50
112
  /**
51
113
  * Create a `harden` function.
52
114
  *
@@ -101,7 +163,12 @@ export const makeHardener = () => {
101
163
  // Object are verified before being enqueued,
102
164
  // therefore this is a valid candidate.
103
165
  // Throws if this fails (strict mode).
104
- freeze(obj);
166
+ // Also throws if the object is an ArrayBuffer or any TypedArray.
167
+ if (isTypedArray(obj)) {
168
+ freezeTypedArray(obj);
169
+ } else {
170
+ freeze(obj);
171
+ }
105
172
 
106
173
  // we rely upon certain commitments of Object.freeze and proxies here
107
174