ses 1.14.0 → 1.15.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.
@@ -354,6 +354,25 @@ export const makeModuleInstance = (
354
354
  };
355
355
  notifiers['*'] = notifyStar;
356
356
 
357
+ const wireUpExportNotifier = (exportName, notify) => {
358
+ if (!notifiers[exportName] && notify !== false) {
359
+ notifiers[exportName] = notify;
360
+
361
+ // exported live binding state
362
+ let value;
363
+ const update = newValue => (value = newValue);
364
+ notify(update);
365
+ exportsProps[exportName] = {
366
+ get() {
367
+ return value;
368
+ },
369
+ set: undefined,
370
+ enumerable: true,
371
+ configurable: false,
372
+ };
373
+ }
374
+ };
375
+
357
376
  // Per the calling convention for the moduleFunctor generated from
358
377
  // an ESM, the `imports` function gets called once up front
359
378
  // to populate or arrange the population of imports and reexports.
@@ -407,30 +426,15 @@ export const makeModuleInstance = (
407
426
  }
408
427
  }
409
428
  if (reexportMap[specifier]) {
410
- // Make named reexports candidates too.
429
+ // Set up reexport notifiers instantly so they are available in cycles.
411
430
  for (const [localName, exportedName] of reexportMap[specifier]) {
412
- candidateAll[exportedName] = importNotifiers[localName];
431
+ wireUpExportNotifier(exportedName, importNotifiers[localName]);
413
432
  }
414
433
  }
415
434
  }
416
435
 
417
436
  for (const [exportName, notify] of entries(candidateAll)) {
418
- if (!notifiers[exportName] && notify !== false) {
419
- notifiers[exportName] = notify;
420
-
421
- // exported live binding state
422
- let value;
423
- const update = newValue => (value = newValue);
424
- notify(update);
425
- exportsProps[exportName] = {
426
- get() {
427
- return value;
428
- },
429
- set: undefined,
430
- enumerable: true,
431
- configurable: false,
432
- };
433
- }
437
+ wireUpExportNotifier(exportName, notify);
434
438
  }
435
439
 
436
440
  // Sort the module exports namespace as per spec.
package/src/permits.js CHANGED
@@ -507,6 +507,11 @@ export const permitted = {
507
507
  seal: fn,
508
508
  setPrototypeOf: fn,
509
509
  values: fn,
510
+ 'RegisteredSymbol(harden)': {
511
+ ...fn,
512
+ // Installed with hardenTaming: 'unsafe'
513
+ isFake: 'boolean',
514
+ },
510
515
  // https://github.com/tc39/proposal-accessible-object-hasownproperty
511
516
  hasOwn: fn,
512
517
  // https://github.com/tc39/proposal-array-grouping
package/src/reporting.js CHANGED
@@ -1,13 +1,45 @@
1
- import { functionBind, globalThis } from './commons.js';
1
+ import { globalThis } from './commons.js';
2
2
  import { assert } from './error/assert.js';
3
3
 
4
4
  /**
5
5
  * @import {Reporter, GroupReporter} from './reporting-types.js'
6
6
  */
7
7
 
8
+ /* eslint-disable @endo/no-polymorphic-call */
9
+ /**
10
+ * To address https://github.com/endojs/endo/issues/2908,
11
+ * the `consoleReporter` uses the current `console` rather
12
+ * than the original one.
13
+ *
14
+ * @type {GroupReporter}
15
+ */
16
+ const consoleReporter = {
17
+ warn(...args) {
18
+ globalThis.console.warn(...args);
19
+ },
20
+ error(...args) {
21
+ globalThis.console.error(...args);
22
+ },
23
+ ...(globalThis.console?.groupCollapsed
24
+ ? {
25
+ groupCollapsed(...args) {
26
+ globalThis.console.groupCollapsed(...args);
27
+ },
28
+ }
29
+ : undefined),
30
+ ...(globalThis.console?.groupEnd
31
+ ? {
32
+ groupEnd() {
33
+ globalThis.console.groupEnd();
34
+ },
35
+ }
36
+ : undefined),
37
+ };
38
+ /* eslint-enable @endo/no-polymorphic-call */
39
+
8
40
  /**
9
41
  * Creates a suitable reporter for internal errors and warnings out of the
10
- * Node.js console.error to ensure all messages to go stderr, including the
42
+ * Node.js console.error to ensure all messages go to stderr, including the
11
43
  * group label.
12
44
  * Accounts for the extra space introduced by console.error as a delimiter
13
45
  * between the indent and subsequent arguments.
@@ -51,18 +83,22 @@ export const chooseReporter = reporting => {
51
83
  if (reporting === 'none') {
52
84
  return makeReportPrinter(mute);
53
85
  }
54
- if (
55
- reporting === 'console' ||
56
- globalThis.window === globalThis ||
57
- globalThis.importScripts !== undefined
58
- ) {
59
- return console;
60
- }
61
86
  if (globalThis.console !== undefined) {
87
+ if (
88
+ reporting === 'console' || // asks for console explicitly
89
+ globalThis.window === globalThis || // likely on browser
90
+ globalThis.importScripts !== undefined // likely on worker
91
+ ) {
92
+ // reporter just delegates directly to the current console
93
+ return consoleReporter;
94
+ }
95
+ assert(reporting === 'platform');
62
96
  // On Node.js, we send all feedback to stderr, regardless of purported level.
63
- const console = globalThis.console;
64
- const error = functionBind(console.error, console);
65
- return makeReportPrinter(error);
97
+ // This uses `consoleReporter.error` instead of `console.error` because we
98
+ // want the constructed reporter to use the `console.error` of the current
99
+ // `console`, not the `console` that was installed when the reporter
100
+ // was created.
101
+ return makeReportPrinter(consoleReporter.error);
66
102
  }
67
103
  if (globalThis.print !== undefined) {
68
104
  return makeReportPrinter(globalThis.print);
@@ -4,15 +4,18 @@ import {
4
4
  getOwnPropertyDescriptor,
5
5
  getOwnPropertyNames,
6
6
  hasOwn,
7
- regexpTest,
7
+ regexpExec,
8
+ Set,
9
+ setHas,
8
10
  } from './commons.js';
9
11
 
10
12
  /**
11
- * keywords
12
- * In JavaScript you cannot use these reserved words as variables.
13
- * See 11.6.1 Identifier Names
13
+ * reservedNames
14
+ * In JavaScript you cannot use reserved words as variable names (except for
15
+ * "eval", which is specially reserved to prevent shadowing).
16
+ * https://tc39.es/ecma262/multipage/ecmascript-language-lexical-grammar.html#sec-identifier-names
14
17
  */
15
- const keywords = [
18
+ const reservedNames = new Set([
16
19
  // 11.6.2.1 Keywords
17
20
  'await',
18
21
  'break',
@@ -73,7 +76,10 @@ const keywords = [
73
76
 
74
77
  'this',
75
78
  'arguments',
76
- ];
79
+
80
+ // Reserved by us
81
+ 'eval',
82
+ ]);
77
83
 
78
84
  /**
79
85
  * identifierPattern
@@ -89,24 +95,12 @@ const identifierPattern = /^[a-zA-Z_$][\w$]*$/;
89
95
 
90
96
  /**
91
97
  * isValidIdentifierName()
92
- * What variable names might it bring into scope? These include all
93
- * property names which can be variable names, including the names
94
- * of inherited properties. It excludes symbols and names which are
95
- * keywords. We drop symbols safely. Currently, this shim refuses
96
- * service if any of the names are keywords or keyword-like. This is
97
- * safe and only prevent performance optimization.
98
+ * Is a value allowed as an arbitrary identifier name?
98
99
  *
99
100
  * @param {string} name
100
101
  */
101
- export const isValidIdentifierName = name => {
102
- // Ensure we have a valid identifier. We use regexpTest rather than
103
- // /../.test() to guard against the case where RegExp has been poisoned.
104
- return (
105
- name !== 'eval' &&
106
- !arrayIncludes(keywords, name) &&
107
- regexpTest(identifierPattern, name)
108
- );
109
- };
102
+ export const isValidIdentifierName = name =>
103
+ !setHas(reservedNames, name) && !!regexpExec(identifierPattern, name);
110
104
 
111
105
  /*
112
106
  * isImmutableDataProperty
@@ -137,12 +131,12 @@ function isImmutableDataProperty(obj, name) {
137
131
 
138
132
  /**
139
133
  * getScopeConstants()
140
- * What variable names might it bring into scope? These include all
134
+ * What variable names might be brought into scope? These include all
141
135
  * property names which can be variable names, including the names
142
136
  * of inherited properties. It excludes symbols and names which are
143
137
  * keywords. We drop symbols safely. Currently, this shim refuses
144
138
  * service if any of the names are keywords or keyword-like. This is
145
- * safe and only prevent performance optimization.
139
+ * safe and only affects performance optimization.
146
140
  *
147
141
  * @param {object} globalObject
148
142
  * @param {object} moduleLexicals
package/src/transforms.js CHANGED
@@ -3,7 +3,8 @@
3
3
  import {
4
4
  FERAL_REG_EXP,
5
5
  SyntaxError,
6
- stringReplace,
6
+ regexpReplace,
7
+ sealRegexp,
7
8
  stringSearch,
8
9
  stringSlice,
9
10
  stringSplit,
@@ -35,7 +36,9 @@ function getLineNumber(src, pattern) {
35
36
 
36
37
  // /////////////////////////////////////////////////////////////////////////////
37
38
 
38
- const htmlCommentPattern = new FERAL_REG_EXP(`(?:${'<'}!--|--${'>'})`, 'g');
39
+ const htmlCommentPattern = sealRegexp(
40
+ new FERAL_REG_EXP(`(?:${'<'}!--|--${'>'})`, 'g'),
41
+ );
39
42
 
40
43
  /**
41
44
  * Conservatively reject the source text if it may contain text that some
@@ -100,14 +103,13 @@ export const rejectHtmlComments = src => {
100
103
  */
101
104
  export const evadeHtmlCommentTest = src => {
102
105
  const replaceFn = match => (match[0] === '<' ? '< ! --' : '-- >');
103
- return stringReplace(src, htmlCommentPattern, replaceFn);
106
+ return regexpReplace(htmlCommentPattern, src, replaceFn);
104
107
  };
105
108
 
106
109
  // /////////////////////////////////////////////////////////////////////////////
107
110
 
108
- const importPattern = new FERAL_REG_EXP(
109
- '(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|/[/*]))',
110
- 'g',
111
+ const importPattern = sealRegexp(
112
+ new FERAL_REG_EXP('(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|/[/*]))', 'g'),
111
113
  );
112
114
 
113
115
  /**
@@ -170,7 +172,7 @@ export const rejectImportExpressions = src => {
170
172
  */
171
173
  export const evadeImportExpressionTest = src => {
172
174
  const replaceFn = (_, p1, p2) => `${p1}__import__${p2}`;
173
- return stringReplace(src, importPattern, replaceFn);
175
+ return regexpReplace(importPattern, src, replaceFn);
174
176
  };
175
177
 
176
178
  // /////////////////////////////////////////////////////////////////////////////