ses 1.14.0 → 1.15.1
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/README.md +2 -2
- package/dist/lockdown.cjs +506 -274
- package/dist/lockdown.mjs +506 -274
- package/dist/lockdown.umd.js +506 -274
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +506 -274
- package/dist/ses.cjs +506 -274
- package/dist/ses.mjs +506 -274
- package/dist/ses.umd.js +506 -274
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +110 -141
- package/package.json +15 -22
- package/src/assert-shim.js +2 -2
- package/src/commons.js +99 -39
- package/src/enablements.js +7 -8
- package/src/error/assert.js +124 -99
- package/src/error/stringify-utils.js +2 -2
- package/src/error/tame-v8-error-constructor.js +15 -12
- package/src/error/types.js +1 -1
- package/src/get-anonymous-intrinsics.js +0 -1
- package/src/lockdown.js +34 -12
- package/src/module-instance.js +22 -18
- package/src/permits.js +5 -0
- package/src/reporting.js +48 -12
- package/src/scope-constants.js +17 -23
- package/src/transforms.js +99 -12
- package/types.d.ts +110 -141
- package/src/error/README.md +0 -99
package/src/module-instance.js
CHANGED
|
@@ -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
|
-
//
|
|
429
|
+
// Set up reexport notifiers instantly so they are available in cycles.
|
|
411
430
|
for (const [localName, exportedName] of reexportMap[specifier]) {
|
|
412
|
-
|
|
431
|
+
wireUpExportNotifier(exportedName, importNotifiers[localName]);
|
|
413
432
|
}
|
|
414
433
|
}
|
|
415
434
|
}
|
|
416
435
|
|
|
417
436
|
for (const [exportName, notify] of entries(candidateAll)) {
|
|
418
|
-
|
|
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 {
|
|
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
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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);
|
package/src/scope-constants.js
CHANGED
|
@@ -4,15 +4,18 @@ import {
|
|
|
4
4
|
getOwnPropertyDescriptor,
|
|
5
5
|
getOwnPropertyNames,
|
|
6
6
|
hasOwn,
|
|
7
|
-
|
|
7
|
+
regexpExec,
|
|
8
|
+
Set,
|
|
9
|
+
setHas,
|
|
8
10
|
} from './commons.js';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
|
-
*
|
|
12
|
-
* In JavaScript you cannot use
|
|
13
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
|
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
|
|
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,9 @@
|
|
|
3
3
|
import {
|
|
4
4
|
FERAL_REG_EXP,
|
|
5
5
|
SyntaxError,
|
|
6
|
-
|
|
6
|
+
regexpExec,
|
|
7
|
+
regexpReplace,
|
|
8
|
+
sealRegexp,
|
|
7
9
|
stringSearch,
|
|
8
10
|
stringSlice,
|
|
9
11
|
stringSplit,
|
|
@@ -35,7 +37,9 @@ function getLineNumber(src, pattern) {
|
|
|
35
37
|
|
|
36
38
|
// /////////////////////////////////////////////////////////////////////////////
|
|
37
39
|
|
|
38
|
-
const htmlCommentPattern =
|
|
40
|
+
const htmlCommentPattern = sealRegexp(
|
|
41
|
+
new FERAL_REG_EXP(`(?:${'<'}!--|--${'>'})`, 'g'),
|
|
42
|
+
);
|
|
39
43
|
|
|
40
44
|
/**
|
|
41
45
|
* Conservatively reject the source text if it may contain text that some
|
|
@@ -100,16 +104,85 @@ export const rejectHtmlComments = src => {
|
|
|
100
104
|
*/
|
|
101
105
|
export const evadeHtmlCommentTest = src => {
|
|
102
106
|
const replaceFn = match => (match[0] === '<' ? '< ! --' : '-- >');
|
|
103
|
-
return
|
|
107
|
+
return regexpReplace(htmlCommentPattern, src, replaceFn);
|
|
104
108
|
};
|
|
105
109
|
|
|
106
110
|
// /////////////////////////////////////////////////////////////////////////////
|
|
107
111
|
|
|
108
|
-
const importPattern =
|
|
109
|
-
'(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(
|
|
110
|
-
|
|
112
|
+
const importPattern = sealRegexp(
|
|
113
|
+
new FERAL_REG_EXP('(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|\\.|/[/*]))', 'g'),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Matches one line of a run of `//# sourceURL=` and `//# sourceMappingURL=`
|
|
118
|
+
* comments at the very end of the source (`sourceMetaTrailerStart` finds
|
|
119
|
+
* the run), as module-source, compartment-mapper and
|
|
120
|
+
* bundlers append to evaluated code (a module's location may well contain
|
|
121
|
+
* `import.`, as in `conditional-import.js`).
|
|
122
|
+
*
|
|
123
|
+
* Each line must begin at a line start and its value must hold no whitespace
|
|
124
|
+
* and none of `*`, backtick, `$`, quotes or backslash. Such a line is inert
|
|
125
|
+
* wherever it stands: outside any literal it is a line comment; a regular
|
|
126
|
+
* expression literal cannot span lines; and inside a block comment, a string
|
|
127
|
+
* continued from the line before or a template literal, the line can neither
|
|
128
|
+
* close that context (no `*`, quote or backtick) nor open a substitution (no
|
|
129
|
+
* `$`). Since nothing but whitespace follows the run, an unclosed context
|
|
130
|
+
* there is a SyntaxError. So `rejectImportExpressions` need not scan it.
|
|
131
|
+
*
|
|
132
|
+
* A `/*# sourceMappingURL=` block comment is not skipped but scanned like
|
|
133
|
+
* any other code, which can only make the check stricter.
|
|
134
|
+
*/
|
|
135
|
+
const sourceMetaLinePattern = sealRegexp(
|
|
136
|
+
new FERAL_REG_EXP('^//# source(?:Mapping)?URL=[^\\s*`$\'"\\\\]*$'),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const whitespacePattern = sealRegexp(new FERAL_REG_EXP('^\\s$'));
|
|
140
|
+
|
|
141
|
+
const lineTerminatorPattern = sealRegexp(
|
|
142
|
+
new FERAL_REG_EXP('^[\\n\\r\\u2028\\u2029]$'),
|
|
111
143
|
);
|
|
112
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Returns the index at which the trailing run of source meta comments
|
|
147
|
+
* begins, at its leading line terminator if it has one, or the length of
|
|
148
|
+
* the source if there is no such run. It reads the source backward, one
|
|
149
|
+
* line at a time, and tests each line with `sourceMetaLinePattern` alone,
|
|
150
|
+
* so it takes time linear in the length of the source. A single regular
|
|
151
|
+
* expression for the whole run, `(?:(?:^|[\n\r\u2028\u2029])<line>)+\s*$`,
|
|
152
|
+
* finds the same run, but a search retries it at every line terminator,
|
|
153
|
+
* which takes time quadratic in the number of lines of the run.
|
|
154
|
+
*
|
|
155
|
+
* @param {string} src
|
|
156
|
+
* @returns {number}
|
|
157
|
+
*/
|
|
158
|
+
const sourceMetaTrailerStart = src => {
|
|
159
|
+
let end = src.length;
|
|
160
|
+
while (end > 0 && regexpExec(whitespacePattern, src[end - 1]) !== null) {
|
|
161
|
+
end -= 1;
|
|
162
|
+
}
|
|
163
|
+
let start = src.length;
|
|
164
|
+
for (;;) {
|
|
165
|
+
let lineStart = end;
|
|
166
|
+
while (
|
|
167
|
+
lineStart > 0 &&
|
|
168
|
+
regexpExec(lineTerminatorPattern, src[lineStart - 1]) === null
|
|
169
|
+
) {
|
|
170
|
+
lineStart -= 1;
|
|
171
|
+
}
|
|
172
|
+
if (
|
|
173
|
+
regexpExec(sourceMetaLinePattern, stringSlice(src, lineStart, end)) ===
|
|
174
|
+
null
|
|
175
|
+
) {
|
|
176
|
+
return start;
|
|
177
|
+
}
|
|
178
|
+
if (lineStart === 0) {
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
start = lineStart - 1;
|
|
182
|
+
end = lineStart - 1;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
113
186
|
/**
|
|
114
187
|
* Conservatively reject the source text if it may contain a dynamic
|
|
115
188
|
* import expression. To reject without parsing, `rejectImportExpressions` will
|
|
@@ -125,10 +198,23 @@ const importPattern = new FERAL_REG_EXP(
|
|
|
125
198
|
* apparent import expressions in literal strings or comments.
|
|
126
199
|
*
|
|
127
200
|
* The current conservative rule looks for the identifier "import"
|
|
128
|
-
* followed by either an open paren or something that looks like
|
|
129
|
-
* beginning of a comment.
|
|
130
|
-
*
|
|
131
|
-
*
|
|
201
|
+
* followed by either an open paren, a dot, or something that looks like
|
|
202
|
+
* the beginning of a comment. The dot case rejects not just a
|
|
203
|
+
* phase-qualified call such as `import.source(...)` or `import.defer(...)`,
|
|
204
|
+
* but any property access under `import` at all, including `import.meta`,
|
|
205
|
+
* regardless of whether the property is then called. This is broader than
|
|
206
|
+
* strictly necessary: the substring "import." can occur incidentally, for
|
|
207
|
+
* example in a module path or a comment, and such source text is rejected
|
|
208
|
+
* too. That tradeoff is intentional: covering every `import.<name>` form,
|
|
209
|
+
* called or not, without naming specific property names, is judged simpler
|
|
210
|
+
* and safer than narrowing the match to the shape of a call. We assume that
|
|
211
|
+
* we do not need to worry about html comment syntax because that was
|
|
212
|
+
* already rejected by rejectHtmlComments.
|
|
213
|
+
*
|
|
214
|
+
* The scan stops short of a trailing run of `//# sourceURL=` or
|
|
215
|
+
* `//# sourceMappingURL=` comments whose values could not end a comment,
|
|
216
|
+
* string or template (see `sourceMetaTrailerStart`), so that a module
|
|
217
|
+
* whose location contains `import.` still loads.
|
|
132
218
|
*
|
|
133
219
|
* this \s *must* match all kinds of syntax-defined whitespace. If e.g.
|
|
134
220
|
* U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) is treated as
|
|
@@ -141,7 +227,8 @@ const importPattern = new FERAL_REG_EXP(
|
|
|
141
227
|
* @returns {string}
|
|
142
228
|
*/
|
|
143
229
|
export const rejectImportExpressions = src => {
|
|
144
|
-
const
|
|
230
|
+
const scanned = stringSlice(src, 0, sourceMetaTrailerStart(src));
|
|
231
|
+
const lineNumber = getLineNumber(scanned, importPattern);
|
|
145
232
|
if (lineNumber < 0) {
|
|
146
233
|
return src;
|
|
147
234
|
}
|
|
@@ -170,7 +257,7 @@ export const rejectImportExpressions = src => {
|
|
|
170
257
|
*/
|
|
171
258
|
export const evadeImportExpressionTest = src => {
|
|
172
259
|
const replaceFn = (_, p1, p2) => `${p1}__import__${p2}`;
|
|
173
|
-
return
|
|
260
|
+
return regexpReplace(importPattern, src, replaceFn);
|
|
174
261
|
};
|
|
175
262
|
|
|
176
263
|
// /////////////////////////////////////////////////////////////////////////////
|