ses 0.15.11 → 0.15.12

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
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @file Types of the SES environment
3
+ */
4
+
1
5
  /* eslint-disable no-restricted-globals, vars-on-top, no-var */
2
6
 
3
7
  // It's academically tempting to define a hardened type, but TypeScript doesn't
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "0.15.11",
3
+ "version": "0.15.12",
4
4
  "description": "Hardened JavaScript for Fearless Cooperation",
5
5
  "keywords": [
6
6
  "lockdown",
@@ -35,11 +35,11 @@
35
35
  "types": "./index.d.ts",
36
36
  "exports": {
37
37
  ".": {
38
- "import": "./dist/ses.umd.js",
38
+ "import": "./index.js",
39
39
  "require": "./dist/ses.cjs"
40
40
  },
41
41
  "./lockdown": {
42
- "import": "./dist/ses.umd.js",
42
+ "import": "./index.js",
43
43
  "require": "./dist/ses.cjs"
44
44
  },
45
45
  "./package.json": "./package.json"
@@ -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 -p jsconfig.json",
55
+ "lint:types": "tsc",
56
56
  "prepublish": "yarn run clean && yarn build",
57
57
  "qt": "ava",
58
- "test": "yarn build && ava",
58
+ "test": "tsd && ava",
59
59
  "test:platform-compatability": "node test/package/test.cjs"
60
60
  },
61
61
  "devDependencies": {
62
- "@endo/compartment-mapper": "^0.7.1",
63
- "@endo/eslint-config": "^0.4.6",
64
- "@endo/static-module-record": "^0.7.0",
65
- "@endo/test262-runner": "^0.1.22",
62
+ "@endo/compartment-mapper": "^0.7.2",
63
+ "@endo/eslint-config": "^0.4.7",
64
+ "@endo/static-module-record": "^0.7.1",
65
+ "@endo/test262-runner": "^0.1.23",
66
66
  "ava": "^3.12.1",
67
67
  "babel-eslint": "^10.0.3",
68
68
  "c8": "^7.7.3",
@@ -75,7 +75,8 @@
75
75
  "prettier": "^1.19.1",
76
76
  "sinon": "8.0.4",
77
77
  "terser": "^4.8.0",
78
- "typescript": "~4.5.5"
78
+ "tsd": "^0.19.1",
79
+ "typescript": "~4.6.2"
79
80
  },
80
81
  "files": [
81
82
  "LICENSE*",
@@ -178,5 +179,5 @@
178
179
  ],
179
180
  "timeout": "2m"
180
181
  },
181
- "gitHead": "9ddd58b4a26755cdba9403b0cb042b2067c69832"
182
+ "gitHead": "59e511891ab67f4fa52d67141510974e22362134"
182
183
  }
package/src/commons.js CHANGED
@@ -72,6 +72,8 @@ export const {
72
72
  toStringTag: toStringTagSymbol,
73
73
  iterator: iteratorSymbol,
74
74
  matchAll: matchAllSymbol,
75
+ keyFor: symbolKeyFor,
76
+ for: symbolFor,
75
77
  } = Symbol;
76
78
 
77
79
  export const { isInteger } = Number;
@@ -17,6 +17,7 @@ import {
17
17
  keys,
18
18
  mapGet,
19
19
  weakmapGet,
20
+ reflectHas,
20
21
  } from './commons.js';
21
22
  import { compartmentEvaluate } from './compartment-evaluate.js';
22
23
 
@@ -73,22 +74,36 @@ export const makeThirdPartyModuleInstance = (
73
74
  update(value);
74
75
  };
75
76
  });
77
+ // This is enough to support import * from cjs - the '*' field doesn't need to be in exports nor proxiedExports because import will only ever access it via notifiers
78
+ notifiers['*'] = update => {
79
+ update(proxiedExports);
80
+ };
76
81
  }
77
82
 
78
- let activated = false;
83
+ const localState = {
84
+ activated: false,
85
+ };
79
86
  return freeze({
80
87
  notifiers,
81
88
  exportsProxy,
82
89
  execute() {
83
- if (!activated) {
90
+ if (reflectHas(localState, 'errorFromExecute')) {
91
+ throw localState.errorFromExecute;
92
+ }
93
+ if (!localState.activated) {
84
94
  activate();
85
- activated = true;
86
- // eslint-disable-next-line @endo/no-polymorphic-call
87
- staticModuleRecord.execute(
88
- proxiedExports,
89
- compartment,
90
- resolvedImports,
91
- );
95
+ localState.activated = true;
96
+ try {
97
+ // eslint-disable-next-line @endo/no-polymorphic-call
98
+ staticModuleRecord.execute(
99
+ proxiedExports,
100
+ compartment,
101
+ resolvedImports,
102
+ );
103
+ } catch (err) {
104
+ localState.errorFromExecute = err;
105
+ throw err;
106
+ }
92
107
  }
93
108
  },
94
109
  });
@@ -45,35 +45,22 @@
45
45
 
46
46
  import { whitelist, FunctionInstance, isAccessorPermit } from './whitelist.js';
47
47
  import {
48
+ Map,
48
49
  String,
49
50
  TypeError,
51
+ arrayFilter,
50
52
  arrayIncludes,
53
+ arrayMap,
54
+ entries,
51
55
  getOwnPropertyDescriptor,
52
56
  getPrototypeOf,
53
57
  isObject,
58
+ mapGet,
54
59
  objectHasOwnProperty,
55
60
  ownKeys,
56
- stringSlice,
61
+ symbolKeyFor,
57
62
  } from './commons.js';
58
63
 
59
- /**
60
- * asStringPropertyName()
61
- *
62
- * @param {string} path
63
- * @param {string | symbol} prop
64
- */
65
- function asStringPropertyName(path, prop) {
66
- if (typeof prop === 'string') {
67
- return prop;
68
- }
69
-
70
- if (typeof prop === 'symbol') {
71
- return `@@${stringSlice(String(prop), 14, -1)}`;
72
- }
73
-
74
- throw new TypeError(`Unexpected property name type ${path} ${prop}`);
75
- }
76
-
77
64
  /**
78
65
  * whitelistIntrinsics()
79
66
  * Removes all non-allowed properties found by recursively and
@@ -86,9 +73,53 @@ export default function whitelistIntrinsics(
86
73
  intrinsics,
87
74
  markVirtualizedNativeFunction,
88
75
  ) {
89
- // These primities are allowed allowed for permits.
76
+ // These primitives are allowed allowed for permits.
90
77
  const primitives = ['undefined', 'boolean', 'number', 'string', 'symbol'];
91
78
 
79
+ // These symbols are allowed as well-known symbols
80
+ const wellKnownSymbolNames = new Map(
81
+ intrinsics.Symbol
82
+ ? arrayMap(
83
+ arrayFilter(
84
+ entries(whitelist.Symbol),
85
+ ([name, permit]) =>
86
+ permit === 'symbol' &&
87
+ typeof intrinsics.Symbol[name] === 'symbol',
88
+ ),
89
+ ([name]) => [intrinsics.Symbol[name], `@@${name}`],
90
+ )
91
+ : [],
92
+ );
93
+
94
+ /**
95
+ * asStringPropertyName()
96
+ *
97
+ * @param {string} path
98
+ * @param {string | symbol} prop
99
+ */
100
+ function asStringPropertyName(path, prop) {
101
+ if (typeof prop === 'string') {
102
+ return prop;
103
+ }
104
+
105
+ const wellKnownSymbol = mapGet(wellKnownSymbolNames, prop);
106
+
107
+ if (typeof prop === 'symbol') {
108
+ if (wellKnownSymbol) {
109
+ return wellKnownSymbol;
110
+ } else {
111
+ const registeredKey = symbolKeyFor(prop);
112
+ if (registeredKey !== undefined) {
113
+ return `RegisteredSymbol(${registeredKey})`;
114
+ } else {
115
+ return `Unique${String(prop)}`;
116
+ }
117
+ }
118
+ }
119
+
120
+ throw new TypeError(`Unexpected property name type ${path} ${prop}`);
121
+ }
122
+
92
123
  /*
93
124
  * visitPrototype()
94
125
  * Validate the object's [[prototype]] against a permit.
package/src/whitelist.js CHANGED
@@ -224,7 +224,10 @@ export const NativeErrors = [
224
224
  * property definition.
225
225
  * <li>"ObjectPrototype" is the default "[[Proto]]" (when not specified).
226
226
  * <li>Constants "fn" and "getter" are used to keep the structure DRY.
227
- * <li>Symbol properties are listed using the "@@name" form.
227
+ * <li>Symbol properties are listed as follow:
228
+ * <li>Well-known symbols use the "@@name" form.
229
+ * <li>Registered symbols use the "RegisteredSymbol(key)" form.
230
+ * <li>Unique symbols use the "UniqueSymbol(description)" form.
228
231
  */
229
232
 
230
233
  // Function Instances
@@ -418,6 +421,7 @@ export const whitelist = {
418
421
  getOwnPropertyNames: fn,
419
422
  getOwnPropertySymbols: fn,
420
423
  getPrototypeOf: fn,
424
+ hasOwn: fn,
421
425
  is: fn,
422
426
  isExtensible: fn,
423
427
  isFrozen: fn,
@@ -428,8 +432,6 @@ export const whitelist = {
428
432
  seal: fn,
429
433
  setPrototypeOf: fn,
430
434
  values: fn,
431
- // See https://github.com/tc39/proposal-accessible-object-hasownproperty
432
- hasOwn: fn,
433
435
  },
434
436
 
435
437
  '%ObjectPrototype%': {
@@ -724,6 +726,7 @@ export const whitelist = {
724
726
  '%StringPrototype%': {
725
727
  // Properties of the String Prototype Object
726
728
  length: 'number',
729
+ at: fn,
727
730
  charAt: fn,
728
731
  charCodeAt: fn,
729
732
  codePointAt: fn,
@@ -777,10 +780,6 @@ export const whitelist = {
777
780
  trimRight: fn,
778
781
  // See https://github.com/Moddable-OpenSource/moddable/issues/523
779
782
  compare: false,
780
-
781
- // Stage 3:
782
- // https://tc39.es/proposal-relative-indexing-method/
783
- at: fn,
784
783
  },
785
784
 
786
785
  '%StringIteratorPrototype%': {
@@ -877,6 +876,7 @@ export const whitelist = {
877
876
 
878
877
  '%ArrayPrototype%': {
879
878
  // Properties of the Array Prototype Object
879
+ at: fn,
880
880
  length: 'number',
881
881
  concat: fn,
882
882
  constructor: 'Array',
@@ -926,10 +926,10 @@ export const whitelist = {
926
926
  // Failed tc39 proposal
927
927
  // Seen on FF Nightly 88.0a1
928
928
  at: false,
929
+ // See https://github.com/tc39/proposal-array-find-from-last
930
+ findLast: 'boolean',
931
+ findLastIndex: 'boolean',
929
932
  },
930
- // Failed tc39 proposal
931
- // Seen on FF Nightly 88.0a1
932
- at: false,
933
933
  // See https://github.com/tc39/proposal-array-find-from-last
934
934
  findLast: fn,
935
935
  findLastIndex: fn,
@@ -954,6 +954,7 @@ export const whitelist = {
954
954
  },
955
955
 
956
956
  '%TypedArrayPrototype%': {
957
+ at: fn,
957
958
  buffer: getter,
958
959
  byteLength: getter,
959
960
  byteOffset: getter,
@@ -986,9 +987,6 @@ export const whitelist = {
986
987
  values: fn,
987
988
  '@@iterator': fn,
988
989
  '@@toStringTag': getter,
989
- // Failed tc39 proposal
990
- // Seen on FF Nightly 88.0a1
991
- at: false,
992
990
  // See https://github.com/tc39/proposal-array-find-from-last
993
991
  findLast: fn,
994
992
  findLastIndex: fn,
@@ -1289,6 +1287,10 @@ export const whitelist = {
1289
1287
  finally: fn,
1290
1288
  then: fn,
1291
1289
  '@@toStringTag': 'string',
1290
+ // Non-standard, used in node to prevent async_hooks from breaking
1291
+ 'UniqueSymbol(async_id_symbol)': accessor,
1292
+ 'UniqueSymbol(trigger_async_id_symbol)': accessor,
1293
+ 'UniqueSymbol(destroyed)': accessor,
1292
1294
  },
1293
1295
 
1294
1296
  '%InertAsyncFunction%': {