ses 0.15.23 → 0.16.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "0.15.23",
3
+ "version": "0.16.0",
4
4
  "description": "Hardened JavaScript for Fearless Cooperation",
5
5
  "keywords": [
6
6
  "lockdown",
@@ -56,12 +56,12 @@
56
56
  "prepublish": "yarn run clean && yarn build",
57
57
  "qt": "ava",
58
58
  "test": "tsd && ava",
59
- "test:platform-compatability": "node test/package/test.cjs"
59
+ "test:platform-compatibility": "node test/package/test.cjs"
60
60
  },
61
61
  "devDependencies": {
62
- "@endo/compartment-mapper": "^0.7.13",
62
+ "@endo/compartment-mapper": "^0.7.14",
63
63
  "@endo/eslint-config": "^0.5.1",
64
- "@endo/static-module-record": "^0.7.12",
64
+ "@endo/static-module-record": "^0.7.13",
65
65
  "@endo/test262-runner": "^0.1.28",
66
66
  "ava": "^3.12.1",
67
67
  "babel-eslint": "^10.0.3",
@@ -179,5 +179,5 @@
179
179
  ],
180
180
  "timeout": "2m"
181
181
  },
182
- "gitHead": "2d3f1a5c472aaef102e8919cbf8d0c53238d155f"
182
+ "gitHead": "8da6dc1002417c0f18cd43b351f8f62d7010260c"
183
183
  }
package/src/commons.js CHANGED
@@ -66,6 +66,7 @@ export const {
66
66
  preventExtensions,
67
67
  setPrototypeOf,
68
68
  values,
69
+ fromEntries,
69
70
  } = Object;
70
71
 
71
72
  export const {
@@ -81,22 +82,6 @@ export const { isInteger } = Number;
81
82
 
82
83
  export const { stringify: stringifyJson } = JSON;
83
84
 
84
- // At time of this writing, we still support Node 10 which doesn't have
85
- // `Object.fromEntries`. If it is absent, this should be an adequate
86
- // replacement.
87
- // By the terminology of https://ponyfoo.com/articles/polyfills-or-ponyfills
88
- // it is a ponyfill rather than a polyfill or shim because we do not
89
- // install it on `Object`.
90
- const objectFromEntries = entryPairs => {
91
- const result = {};
92
- for (const [prop, val] of entryPairs) {
93
- result[prop] = val;
94
- }
95
- return result;
96
- };
97
-
98
- export const fromEntries = Object.fromEntries || objectFromEntries;
99
-
100
85
  // Needed only for the Safari bug workaround below
101
86
  const { defineProperty: originalDefineProperty } = Object;
102
87
 
@@ -165,22 +165,27 @@ export const severeEnablements = {
165
165
  ...moderateEnablements,
166
166
 
167
167
  /**
168
- * Rollup(as used at least by vega) and webpack
168
+ * Rollup (as used at least by vega) and webpack
169
169
  * (as used at least by regenerator) both turn exports into assignments
170
170
  * to a big `exports` object that inherits directly from
171
- * `Object.prototype`.Some of the exported names we've seen include
171
+ * `Object.prototype`. Some of the exported names we've seen include
172
172
  * `hasOwnProperty`, `constructor`, and `toString`. But the strategy used
173
- * by rollup and webpack means potentionally turns any exported name
174
- * into an assignment rejected by the override mistake.That's why
175
- * we take the extreme step of enabling everything on`Object.prototype`.
173
+ * by rollup and webpack potentionally turns any exported name
174
+ * into an assignment rejected by the override mistake. That's why
175
+ * the `severe` enablements takes the extreme step of enabling
176
+ * everything on `Object.prototype`.
176
177
  *
177
178
  * In addition, code doing inheritance manually will often override
178
179
  * the `constructor` property on the new prototype by assignment. We've
179
180
  * seen this several times.
180
181
  *
181
182
  * The cost of enabling all these is that they create a miserable debugging
182
- * experience. https://github.com/Agoric/agoric-sdk/issues/2324 explains
183
- * how it confused the Node console.
183
+ * experience specifically on Node.
184
+ * https://github.com/Agoric/agoric-sdk/issues/2324
185
+ * explains how it confused the Node console.
186
+ *
187
+ * (TODO Reexamine the vscode situation. I think it may have improved
188
+ * since the following paragraph was written.)
184
189
  *
185
190
  * The vscode debugger's object inspector shows the own data properties of
186
191
  * an object, which is typically what you want, but also shows both getter
@@ -197,8 +202,8 @@ export const severeEnablements = {
197
202
  * The widely used Buffer defined at https://github.com/feross/buffer
198
203
  * on initialization, manually creates the equivalent of a subclass of
199
204
  * `TypedArray`, which it then initializes by assignment. These assignments
200
- * include enough of the `TypeArray` methods that here, we just enable
201
- * them all.
205
+ * include enough of the `TypeArray` methods that here, the `severe`
206
+ * enablements just enable them all.
202
207
  */
203
208
  '%TypedArrayPrototype%': '*',
204
209
  };
@@ -66,40 +66,52 @@ const getTypedArrayToStringTag = typedArrayToStringTag.get;
66
66
  assert(getTypedArrayToStringTag);
67
67
 
68
68
  // Exported for tests.
69
- /** @param {unknown} object */
69
+ /**
70
+ * Duplicates packages/marshal/src/helpers/passStyle-helpers.js to avoid a dependency.
71
+ *
72
+ * @param {unknown} object
73
+ */
70
74
  export const isTypedArray = object => {
71
75
  // The object must pass a brand check or toStringTag will return undefined.
72
76
  const tag = apply(getTypedArrayToStringTag, object, []);
73
77
  return tag !== undefined;
74
78
  };
75
79
 
80
+ /**
81
+ * Tests if a property key is an integer-valued canonical numeric index.
82
+ * https://tc39.es/ecma262/#sec-canonicalnumericindexstring
83
+ *
84
+ * @param {string | symbol} propertyKey
85
+ */
86
+ const isCanonicalIntegerIndexString = propertyKey => {
87
+ const n = +String(propertyKey);
88
+ return isInteger(n) && String(n) === propertyKey;
89
+ };
90
+
76
91
  /**
77
92
  * @template T
78
93
  * @param {ArrayLike<T>} array
79
94
  */
80
95
  const freezeTypedArray = array => {
81
- const descs = getOwnPropertyDescriptors(array);
82
-
83
96
  preventExtensions(array);
84
97
 
85
98
  // 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.
99
+ // We get each descriptor individually rather than using
100
+ // getOwnPropertyDescriptors in order to fail safe when encountering
101
+ // an obscure GraalJS issue where getOwnPropertyDescriptor returns
102
+ // undefined for a property that does exist.
103
+ arrayForEach(ownKeys(array), (/** @type {string | symbol} */ name) => {
104
+ const desc = getOwnPropertyDescriptor(array, name);
105
+ assert(desc);
106
+ // TypedArrays are integer-indexed exotic objects, which define special
107
+ // treatment for property names in canonical numeric form:
108
+ // integers in range are permanently writable and non-configurable.
100
109
  // https://tc39.es/ecma262/#sec-integer-indexed-exotic-objects
101
- const number = +String(name);
102
- if (!isInteger(number)) {
110
+ //
111
+ // This is analogous to the data of a hardened Map or Set,
112
+ // so we carve out this exceptional behavior but make all other
113
+ // properties non-configurable.
114
+ if (!isCanonicalIntegerIndexString(name)) {
103
115
  defineProperty(array, name, {
104
116
  ...desc,
105
117
  writable: false,