ses 2.0.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/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
@@ -338,7 +340,7 @@ arrayForEach(['caller', 'arguments'], prop => {
338
340
  strict[prop];
339
341
  } catch (e) {
340
342
  // https://github.com/facebook/hermes/blob/main/test/hermes/function-non-strict.js
341
- if (e.message === 'Restricted in strict mode') {
343
+ if (/** @type {Error} */ (e).message === 'Restricted in strict mode') {
342
344
  // Fixed in Static Hermes: https://github.com/facebook/hermes/issues/1582
343
345
  FunctionInstance[prop] = accessor;
344
346
  }
@@ -865,6 +867,8 @@ export const permitted = {
865
867
  getYear: fn,
866
868
  setYear: fn,
867
869
  toGMTString: fn,
870
+
871
+ toTemporalInstant: fn,
868
872
  },
869
873
 
870
874
  // Text Processing
@@ -1253,6 +1257,8 @@ export const permitted = {
1253
1257
  entries: fn,
1254
1258
  forEach: fn,
1255
1259
  get: fn,
1260
+ getOrInsert: fn,
1261
+ getOrInsertComputed: fn,
1256
1262
  has: fn,
1257
1263
  keys: fn,
1258
1264
  set: fn,
@@ -1324,6 +1330,8 @@ export const permitted = {
1324
1330
  constructor: 'WeakMap',
1325
1331
  delete: fn,
1326
1332
  get: fn,
1333
+ getOrInsert: fn,
1334
+ getOrInsertComputed: fn,
1327
1335
  has: fn,
1328
1336
  set: fn,
1329
1337
  '@@toStringTag': 'string',
@@ -1735,6 +1743,346 @@ export const permitted = {
1735
1743
  revocable: fn,
1736
1744
  },
1737
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
+
1738
2086
  // Appendix B
1739
2087
 
1740
2088
  // Annex B: Additional Properties of the Global Object
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  arrayFilter,
3
3
  arrayIncludes,
4
+ freezeRegexp,
4
5
  getOwnPropertyDescriptor,
5
6
  getOwnPropertyNames,
6
7
  hasOwn,
7
- regexpExec,
8
+ regexpSearch,
8
9
  Set,
9
10
  setHas,
10
11
  } from './commons.js';
@@ -91,7 +92,7 @@ const reservedNames = new Set([
91
92
  * Note: \w is equivalent [a-zA-Z_0-9]
92
93
  * See 11.6.1 Identifier Names
93
94
  */
94
- const identifierPattern = /^[a-zA-Z_$][\w$]*$/;
95
+ const identifierPattern = freezeRegexp(/^[a-zA-Z_$][\w$]*$/);
95
96
 
96
97
  /**
97
98
  * isValidIdentifierName()
@@ -100,7 +101,7 @@ const identifierPattern = /^[a-zA-Z_$][\w$]*$/;
100
101
  * @param {string} name
101
102
  */
102
103
  export const isValidIdentifierName = name =>
103
- !setHas(reservedNames, name) && !!regexpExec(identifierPattern, name);
104
+ !setHas(reservedNames, name) && regexpSearch(identifierPattern, name) !== -1;
104
105
 
105
106
  /*
106
107
  * isImmutableDataProperty
@@ -3,6 +3,7 @@ import {
3
3
  String,
4
4
  TypeError,
5
5
  defineProperty,
6
+ freezeRegexp,
6
7
  getOwnPropertyNames,
7
8
  isPrimitive,
8
9
  regexpExec,
@@ -11,7 +12,7 @@ import { assert } from './error/assert.js';
11
12
 
12
13
  const { Fail, quote: q } = assert;
13
14
 
14
- const localePattern = /^(\w*[a-z])Locale([A-Z]\w*)$/;
15
+ const localePattern = freezeRegexp(/^(\w*[a-z])Locale([A-Z]\w*)$/);
15
16
 
16
17
  // Use concise methods to obtain named functions without constructor
17
18
  // behavior or `.prototype` property.