ses 2.1.0 → 2.2.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/dist/types.d.cts CHANGED
@@ -132,6 +132,10 @@ export type ModuleDescriptor =
132
132
  | PrecompiledModuleSource
133
133
  | string;
134
134
 
135
+ export type StrictModuleDescriptor =
136
+ | SourceModuleDescriptor
137
+ | NamespaceModuleDescriptor;
138
+
135
139
  // Deprecated type aliases:
136
140
  export type PrecompiledStaticModuleInterface = PrecompiledModuleSource;
137
141
  export type ThirdPartyStaticModuleInterface = VirtualModuleSource;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Hardened JavaScript for Fearless Cooperation",
5
5
  "keywords": [
6
6
  "lockdown",
package/src/commons.js CHANGED
@@ -45,6 +45,7 @@ export const {
45
45
  Uint8Array,
46
46
  WeakMap,
47
47
  WeakSet,
48
+ Temporal, // may be undefined on old JS engines
48
49
  } = globalThis;
49
50
 
50
51
  export const {
@@ -335,9 +335,9 @@ export const makeCompartmentConstructor = (
335
335
  { parentCompartment = undefined, enforceNew = false } = {},
336
336
  ) => {
337
337
  /**
338
- * @param {...CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
338
+ * @this {Compartment}
339
+ * @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
339
340
  */
340
- /** @this {Compartment} */
341
341
  function Compartment(...args) {
342
342
  if (enforceNew && new.target === undefined) {
343
343
  throw TypeError(
package/src/lockdown.js CHANGED
@@ -36,6 +36,7 @@ import removeUnpermittedIntrinsics from './permits-intrinsics.js';
36
36
  import tameFunctionConstructors from './tame-function-constructors.js';
37
37
  import tameDateConstructor from './tame-date-constructor.js';
38
38
  import tameMathObject from './tame-math-object.js';
39
+ import tameTemporalObject from './tame-temporal-object.js';
39
40
  import { tameNaNSideChannel } from './tame-nan-sidechannel.js';
40
41
  import tameRegExpConstructor from './tame-regexp-constructor.js';
41
42
  import enablePropertyOverrides from './enable-property-overrides.js';
@@ -354,6 +355,7 @@ export const repairIntrinsics = (options = {}) => {
354
355
  addIntrinsics(tameDateConstructor());
355
356
  addIntrinsics(tameErrorConstructor(errorTaming, stackFiltering));
356
357
  addIntrinsics(tameMathObject());
358
+ addIntrinsics(tameTemporalObject());
357
359
  tameNaNSideChannel();
358
360
  addIntrinsics(tameRegExpConstructor(regExpTaming));
359
361
  addIntrinsics(tameSymbolConstructor());
@@ -178,34 +178,26 @@ export default function removeUnpermittedIntrinsics(
178
178
  if (typeof permit === 'string') {
179
179
  // A string permit can have one of two meanings:
180
180
 
181
- if (prop === 'prototype' || prop === 'constructor') {
182
- // For prototype and constructor value properties, the permit
183
- // is the name of an intrinsic.
184
- // Assumption: prototype and constructor cannot be primitives.
185
- // Assert: the permit is the name of an intrinsic.
186
- // Assert: the property value is equal to that intrinsic.
187
-
188
- if (hasOwn(intrinsics, permit)) {
189
- if (value !== intrinsics[permit]) {
190
- throw TypeError(`Does not match permit for ${path}`);
191
- }
192
- return true;
181
+ if (arrayIncludes(primitives, permit)) {
182
+ // The permit is the name of a primitive.
183
+
184
+ if (prop === 'prototype' || prop === 'constructor') {
185
+ throw new TypeError(`At ${path} expected intrinsic, not ${permit}`);
193
186
  }
194
- } else {
195
- // For all other properties, the permit is the name of a primitive.
196
- // Assert: the permit is the name of a primitive.
197
- // Assert: the property value type is equal to that primitive.
198
-
199
- // eslint-disable-next-line no-lonely-if
200
- if (arrayIncludes(primitives, permit)) {
201
- // eslint-disable-next-line valid-typeof
202
- if (typeof value !== permit) {
203
- throw TypeError(
204
- `At ${path} expected ${permit} not ${typeof value}`,
205
- );
206
- }
207
- return true;
187
+ // eslint wants to compare typeof only to string literals
188
+ // eslint-disable-next-line valid-typeof
189
+ if (typeof value !== permit) {
190
+ throw TypeError(`At ${path} expected ${permit} not ${typeof value}`);
191
+ }
192
+ return true;
193
+ }
194
+
195
+ if (hasOwn(intrinsics, permit)) {
196
+ // the permit is the name of an intrinsic.
197
+ if (value !== intrinsics[permit]) {
198
+ throw TypeError(`Does not match permit for ${path}`);
208
199
  }
200
+ return true;
209
201
  }
210
202
  }
211
203
 
package/src/permits.js CHANGED
@@ -140,6 +140,7 @@ export const initialGlobalPropertyNames = {
140
140
  // *** Other Properties of the Global Object
141
141
 
142
142
  Math: '%InitialMath%',
143
+ Temporal: '%InitialTemporal%',
143
144
 
144
145
  // We move these from universalPropertyNames because the NaN side channel
145
146
  // means that they are not quite harmless.
@@ -186,6 +187,7 @@ export const sharedGlobalPropertyNames = {
186
187
  // *** Other Properties of the Global Object
187
188
 
188
189
  Math: '%SharedMath%',
190
+ Temporal: '%SharedTemporal%',
189
191
 
190
192
  // TODO Temporal
191
193
  // https://github.com/tc39/proposal-temporal
@@ -866,7 +868,7 @@ export const permitted = {
866
868
  setYear: fn,
867
869
  toGMTString: fn,
868
870
 
869
- toTemporalInstant: false,
871
+ toTemporalInstant: fn,
870
872
  },
871
873
 
872
874
  // Text Processing
@@ -1741,6 +1743,346 @@ export const permitted = {
1741
1743
  revocable: fn,
1742
1744
  },
1743
1745
 
1746
+ '%Temporal.PlainDatePrototype%': {
1747
+ constructor: '%Temporal.PlainDate%',
1748
+ era: accessor,
1749
+ eraYear: accessor,
1750
+ calendarId: accessor,
1751
+ year: accessor,
1752
+ month: accessor,
1753
+ monthCode: accessor,
1754
+ day: accessor,
1755
+ dayOfWeek: accessor,
1756
+ dayOfYear: accessor,
1757
+ weekOfYear: accessor,
1758
+ yearOfWeek: accessor,
1759
+ daysInWeek: accessor,
1760
+ daysInMonth: accessor,
1761
+ daysInYear: accessor,
1762
+ monthsInYear: accessor,
1763
+ inLeapYear: accessor,
1764
+ toPlainYearMonth: fn,
1765
+ toPlainMonthDay: fn,
1766
+ add: fn,
1767
+ subtract: fn,
1768
+ with: fn,
1769
+ withCalendar: fn,
1770
+ until: fn,
1771
+ since: fn,
1772
+ equals: fn,
1773
+ toPlainDateTime: fn,
1774
+ toZonedDateTime: fn,
1775
+ toString: fn,
1776
+ toLocaleString: fn,
1777
+ toJSON: fn,
1778
+ valueOf: fn,
1779
+ '@@toStringTag': 'string',
1780
+ },
1781
+ '%Temporal.PlainDate%': {
1782
+ '[[Proto]]': '%FunctionPrototype%',
1783
+ length: 'number',
1784
+ name: 'string',
1785
+ prototype: '%Temporal.PlainDatePrototype%',
1786
+ from: fn,
1787
+ compare: fn,
1788
+ },
1789
+
1790
+ '%Temporal.PlainTimePrototype%': {
1791
+ constructor: '%Temporal.PlainTime%',
1792
+ hour: accessor,
1793
+ minute: accessor,
1794
+ second: accessor,
1795
+ millisecond: accessor,
1796
+ microsecond: accessor,
1797
+ nanosecond: accessor,
1798
+ add: fn,
1799
+ subtract: fn,
1800
+ with: fn,
1801
+ until: fn,
1802
+ since: fn,
1803
+ round: fn,
1804
+ equals: fn,
1805
+ toLocaleString: fn,
1806
+ toString: fn,
1807
+ toJSON: fn,
1808
+ valueOf: fn,
1809
+ '@@toStringTag': 'string',
1810
+ },
1811
+ '%Temporal.PlainTime%': {
1812
+ '[[Proto]]': '%FunctionPrototype%',
1813
+ length: 'number',
1814
+ name: 'string',
1815
+ prototype: '%Temporal.PlainTimePrototype%',
1816
+ from: fn,
1817
+ compare: fn,
1818
+ },
1819
+
1820
+ '%Temporal.PlainDateTimePrototype%': {
1821
+ constructor: '%Temporal.PlainDateTime%',
1822
+ calendarId: accessor,
1823
+ era: accessor,
1824
+ eraYear: accessor,
1825
+ year: accessor,
1826
+ month: accessor,
1827
+ monthCode: accessor,
1828
+ day: accessor,
1829
+ hour: accessor,
1830
+ minute: accessor,
1831
+ second: accessor,
1832
+ millisecond: accessor,
1833
+ microsecond: accessor,
1834
+ nanosecond: accessor,
1835
+ dayOfWeek: accessor,
1836
+ dayOfYear: accessor,
1837
+ weekOfYear: accessor,
1838
+ yearOfWeek: accessor,
1839
+ daysInWeek: accessor,
1840
+ daysInMonth: accessor,
1841
+ daysInYear: accessor,
1842
+ monthsInYear: accessor,
1843
+ inLeapYear: accessor,
1844
+ with: fn,
1845
+ withCalendar: fn,
1846
+ withPlainTime: fn,
1847
+ add: fn,
1848
+ subtract: fn,
1849
+ until: fn,
1850
+ since: fn,
1851
+ round: fn,
1852
+ equals: fn,
1853
+ toLocaleString: fn,
1854
+ toJSON: fn,
1855
+ toString: fn,
1856
+ valueOf: fn,
1857
+ toZonedDateTime: fn,
1858
+ toPlainDate: fn,
1859
+ toPlainTime: fn,
1860
+ '@@toStringTag': 'string',
1861
+ },
1862
+ '%Temporal.PlainDateTime%': {
1863
+ '[[Proto]]': '%FunctionPrototype%',
1864
+ length: 'number',
1865
+ name: 'string',
1866
+ prototype: '%Temporal.PlainDateTimePrototype%',
1867
+ from: fn,
1868
+ compare: fn,
1869
+ },
1870
+
1871
+ '%Temporal.ZonedDateTimePrototype%': {
1872
+ constructor: '%Temporal.ZonedDateTime%',
1873
+ timeZoneId: accessor,
1874
+ calendarId: accessor,
1875
+ era: accessor,
1876
+ eraYear: accessor,
1877
+ year: accessor,
1878
+ month: accessor,
1879
+ monthCode: accessor,
1880
+ day: accessor,
1881
+ hour: accessor,
1882
+ minute: accessor,
1883
+ second: accessor,
1884
+ millisecond: accessor,
1885
+ microsecond: accessor,
1886
+ nanosecond: accessor,
1887
+ epochMilliseconds: accessor,
1888
+ epochNanoseconds: accessor,
1889
+ dayOfWeek: accessor,
1890
+ dayOfYear: accessor,
1891
+ weekOfYear: accessor,
1892
+ yearOfWeek: accessor,
1893
+ hoursInDay: accessor,
1894
+ daysInWeek: accessor,
1895
+ daysInMonth: accessor,
1896
+ daysInYear: accessor,
1897
+ monthsInYear: accessor,
1898
+ inLeapYear: accessor,
1899
+ offsetNanoseconds: accessor,
1900
+ offset: accessor,
1901
+ with: fn,
1902
+ withCalendar: fn,
1903
+ withPlainTime: fn,
1904
+ withTimeZone: fn,
1905
+ add: fn,
1906
+ subtract: fn,
1907
+ until: fn,
1908
+ since: fn,
1909
+ round: fn,
1910
+ equals: fn,
1911
+ toLocaleString: fn,
1912
+ toString: fn,
1913
+ toJSON: fn,
1914
+ valueOf: fn,
1915
+ startOfDay: fn,
1916
+ getTimeZoneTransition: fn,
1917
+ toInstant: fn,
1918
+ toPlainDate: fn,
1919
+ toPlainTime: fn,
1920
+ toPlainDateTime: fn,
1921
+ '@@toStringTag': 'string',
1922
+ },
1923
+ '%Temporal.ZonedDateTime%': {
1924
+ '[[Proto]]': '%FunctionPrototype%',
1925
+ length: 'number',
1926
+ name: 'string',
1927
+ prototype: '%Temporal.ZonedDateTimePrototype%',
1928
+ from: fn,
1929
+ compare: fn,
1930
+ },
1931
+
1932
+ '%Temporal.DurationPrototype%': {
1933
+ constructor: '%Temporal.Duration%',
1934
+ years: accessor,
1935
+ months: accessor,
1936
+ weeks: accessor,
1937
+ days: accessor,
1938
+ hours: accessor,
1939
+ minutes: accessor,
1940
+ seconds: accessor,
1941
+ milliseconds: accessor,
1942
+ microseconds: accessor,
1943
+ nanoseconds: accessor,
1944
+ sign: accessor,
1945
+ blank: accessor,
1946
+ with: fn,
1947
+ negated: fn,
1948
+ abs: fn,
1949
+ add: fn,
1950
+ subtract: fn,
1951
+ round: fn,
1952
+ total: fn,
1953
+ toLocaleString: fn,
1954
+ toString: fn,
1955
+ toJSON: fn,
1956
+ valueOf: fn,
1957
+ '@@toStringTag': 'string',
1958
+ },
1959
+ '%Temporal.Duration%': {
1960
+ '[[Proto]]': '%FunctionPrototype%',
1961
+ length: 'number',
1962
+ name: 'string',
1963
+ prototype: '%Temporal.DurationPrototype%',
1964
+ from: fn,
1965
+ compare: fn,
1966
+ },
1967
+
1968
+ '%Temporal.InstantPrototype%': {
1969
+ constructor: '%Temporal.Instant%',
1970
+ epochMilliseconds: accessor,
1971
+ epochNanoseconds: accessor,
1972
+ add: fn,
1973
+ subtract: fn,
1974
+ until: fn,
1975
+ since: fn,
1976
+ round: fn,
1977
+ equals: fn,
1978
+ toLocaleString: fn,
1979
+ toString: fn,
1980
+ toJSON: fn,
1981
+ valueOf: fn,
1982
+ toZonedDateTimeISO: fn,
1983
+ '@@toStringTag': 'string',
1984
+ },
1985
+ '%Temporal.Instant%': {
1986
+ '[[Proto]]': '%FunctionPrototype%',
1987
+ length: 'number',
1988
+ name: 'string',
1989
+ prototype: '%Temporal.InstantPrototype%',
1990
+ from: fn,
1991
+ fromEpochMilliseconds: fn,
1992
+ fromEpochNanoseconds: fn,
1993
+ compare: fn,
1994
+ },
1995
+
1996
+ '%Temporal.PlainYearMonthPrototype%': {
1997
+ constructor: '%Temporal.PlainYearMonth%',
1998
+ calendarId: accessor,
1999
+ era: accessor,
2000
+ eraYear: accessor,
2001
+ year: accessor,
2002
+ month: accessor,
2003
+ monthCode: accessor,
2004
+ daysInYear: accessor,
2005
+ daysInMonth: accessor,
2006
+ monthsInYear: accessor,
2007
+ inLeapYear: accessor,
2008
+ with: fn,
2009
+ add: fn,
2010
+ subtract: fn,
2011
+ until: fn,
2012
+ since: fn,
2013
+ equals: fn,
2014
+ toLocaleString: fn,
2015
+ toString: fn,
2016
+ toJSON: fn,
2017
+ valueOf: fn,
2018
+ toPlainDate: fn,
2019
+ '@@toStringTag': 'string',
2020
+ },
2021
+ '%Temporal.PlainYearMonth%': {
2022
+ '[[Proto]]': '%FunctionPrototype%',
2023
+ length: 'number',
2024
+ name: 'string',
2025
+ prototype: '%Temporal.PlainYearMonthPrototype%',
2026
+ from: fn,
2027
+ compare: fn,
2028
+ },
2029
+
2030
+ '%Temporal.PlainMonthDayPrototype%': {
2031
+ constructor: '%Temporal.PlainMonthDay%',
2032
+ calendarId: accessor,
2033
+ monthCode: accessor,
2034
+ day: accessor,
2035
+ with: fn,
2036
+ equals: fn,
2037
+ toLocaleString: fn,
2038
+ toString: fn,
2039
+ toJSON: fn,
2040
+ valueOf: fn,
2041
+ toPlainDate: fn,
2042
+ '@@toStringTag': 'string',
2043
+ },
2044
+ '%Temporal.PlainMonthDay%': {
2045
+ '[[Proto]]': '%FunctionPrototype%',
2046
+ length: 'number',
2047
+ name: 'string',
2048
+ prototype: '%Temporal.PlainMonthDayPrototype%',
2049
+ from: fn,
2050
+ },
2051
+
2052
+ '%Temporal.Now%': {
2053
+ instant: fn,
2054
+ timeZoneId: fn,
2055
+ plainDateTimeISO: fn,
2056
+ zonedDateTimeISO: fn,
2057
+ plainDateISO: fn,
2058
+ plainTimeISO: fn,
2059
+ '@@toStringTag': 'string',
2060
+ },
2061
+
2062
+ '%InitialTemporal%': {
2063
+ Now: '%Temporal.Now%',
2064
+ PlainDate: '%Temporal.PlainDate%',
2065
+ PlainTime: '%Temporal.PlainTime%',
2066
+ PlainDateTime: '%Temporal.PlainDateTime%',
2067
+ ZonedDateTime: '%Temporal.ZonedDateTime%',
2068
+ Duration: '%Temporal.Duration%',
2069
+ Instant: '%Temporal.Instant%',
2070
+ PlainYearMonth: '%Temporal.PlainYearMonth%',
2071
+ PlainMonthDay: '%Temporal.PlainMonthDay%',
2072
+ '@@toStringTag': 'string',
2073
+ },
2074
+ '%SharedTemporal%': {
2075
+ PlainDate: '%Temporal.PlainDate%',
2076
+ PlainTime: '%Temporal.PlainTime%',
2077
+ PlainDateTime: '%Temporal.PlainDateTime%',
2078
+ ZonedDateTime: '%Temporal.ZonedDateTime%',
2079
+ Duration: '%Temporal.Duration%',
2080
+ Instant: '%Temporal.Instant%',
2081
+ PlainYearMonth: '%Temporal.PlainYearMonth%',
2082
+ PlainMonthDay: '%Temporal.PlainMonthDay%',
2083
+ '@@toStringTag': 'string',
2084
+ },
2085
+
1744
2086
  // Appendix B
1745
2087
 
1746
2088
  // Annex B: Additional Properties of the Global Object
@@ -46,7 +46,7 @@ const dataViewGetBuffer = uncurryThis(
46
46
  *
47
47
  * See https://github.com/endojs/endo/pull/3214#discussion_r3155852021
48
48
  */
49
- const canonicalNaN64Encoding = 0x7ff8000000000000n;
49
+ const canonicalNaN64Encoding = 0x7ff8_0000_0000_0000n;
50
50
 
51
51
  /**
52
52
  * As of this writing (April 29, 2026) all implementations agree that a
@@ -63,7 +63,7 @@ const canonicalNaN64Encoding = 0x7ff8000000000000n;
63
63
  *
64
64
  * See https://github.com/endojs/endo/pull/3214#discussion_r3155852021
65
65
  */
66
- const canonicalNaN32Encoding = 0x7fc00000;
66
+ const canonicalNaN32Encoding = 0x7fc0_0000;
67
67
 
68
68
  /**
69
69
  * As of this writing (April 29, 2026) all implementations that implement
@@ -0,0 +1,75 @@
1
+ import {
2
+ freeze,
3
+ getOwnPropertyDescriptors,
4
+ create,
5
+ objectPrototype,
6
+ getPrototypeOf,
7
+ ownKeys,
8
+ fromEntries,
9
+ TypeError,
10
+ arrayPush,
11
+ Temporal, // may be undefined on old JS engines
12
+ } from './commons.js';
13
+
14
+ import { permitted } from './permits.js';
15
+
16
+ /**
17
+ * Tame the `Temporal` namespace object.
18
+ *
19
+ * The `%InitialTemporal%` is indeed the original `Temporal` namespace
20
+ * object, to remain present on the start compartment.
21
+ *
22
+ * The `%SharedTemporal%` is the safe shared `Temporal` namespace object,
23
+ * to be endowed by default on the gloabl of all constructed compartments.
24
+ * This differs only by the omission of `Temporal.Now`, which is the source of
25
+ * the dynamic non-determinism of the ever-changing current time, and the
26
+ * glacial dynamic non-determinism of current timezone and UTC offset (daylight
27
+ * savings time).
28
+ *
29
+ * The remaining source of glacial dynamic non-determinism is locale
30
+ * sensitivity, which `Temporal` provides only via `toLocaleString` methods.
31
+ * This is handled by `tame-locale-methods.js` in the same way as all other
32
+ * `*Locale*` methods.
33
+ *
34
+ * `tameTemporalObject` is modeletd on `tameMathObject` and `tameDateConstructor`
35
+ */
36
+ const tameTemporalObject = () => {
37
+ if (Temporal === undefined) {
38
+ return {};
39
+ }
40
+
41
+ if (typeof Temporal !== 'object') {
42
+ throw new TypeError(`unexpected typeof Temporal: ${typeof Temporal}`);
43
+ }
44
+ if (getPrototypeOf(Temporal) !== objectPrototype) {
45
+ throw new TypeError(
46
+ `unexpected Temporal __proto__: ${getPrototypeOf(Temporal)}`,
47
+ );
48
+ }
49
+
50
+ const initialTemporal = Temporal;
51
+ const { Now: _, ...otherDescriptors } =
52
+ getOwnPropertyDescriptors(initialTemporal);
53
+ const sharedTemporal = create(objectPrototype, otherDescriptors);
54
+
55
+ const initialTemporalPermit = permitted['%InitialTemporal%'];
56
+ const intrinsicEntries = [];
57
+ for (const topName of ownKeys(Temporal)) {
58
+ const topPermitName = initialTemporalPermit[topName];
59
+ const topPermit = permitted[topPermitName];
60
+ if (typeof topPermit === 'object') {
61
+ const topVal = initialTemporal[topName];
62
+ arrayPush(intrinsicEntries, [topPermitName, topVal]);
63
+ }
64
+ }
65
+
66
+ const result = {
67
+ ...fromEntries(intrinsicEntries),
68
+ '%InitialTemporal%': initialTemporal,
69
+ '%SharedTemporal%': sharedTemporal,
70
+ };
71
+ return result;
72
+ };
73
+ freeze(tameTemporalObject);
74
+
75
+ export default tameTemporalObject;
package/types.d.ts CHANGED
@@ -132,6 +132,10 @@ export type ModuleDescriptor =
132
132
  | PrecompiledModuleSource
133
133
  | string;
134
134
 
135
+ export type StrictModuleDescriptor =
136
+ | SourceModuleDescriptor
137
+ | NamespaceModuleDescriptor;
138
+
135
139
  // Deprecated type aliases:
136
140
  export type PrecompiledStaticModuleInterface = PrecompiledModuleSource;
137
141
  export type ThirdPartyStaticModuleInterface = VirtualModuleSource;