ses 2.2.0 → 2.3.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/CHANGELOG.md +1462 -0
- package/README.md +4 -0
- package/dist/lockdown.cjs +764 -346
- package/dist/lockdown.mjs +764 -346
- package/dist/lockdown.umd.js +764 -346
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +764 -346
- package/dist/ses.cjs +764 -346
- package/dist/ses.mjs +764 -346
- package/dist/ses.umd.js +764 -346
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +31 -2
- package/package.json +38 -9
- package/src/commons.js +0 -1
- package/src/compartment.js +5 -1
- package/src/enablements.js +48 -57
- package/src/error/assert.js +59 -14
- package/src/error/console.js +201 -30
- package/src/error/fatal-assert.js +2 -2
- package/src/error/stringify-utils.js +2 -4
- package/src/error/tame-console.js +0 -2
- package/src/error/tame-error-constructor.js +1 -1
- package/src/get-anonymous-intrinsics.js +0 -12
- package/src/module-load.js +0 -2
- package/src/permits.js +55 -31
- package/src/tame-faux-data-properties.js +1 -1
- package/src/tame-function-constructors.js +1 -1
- package/src/transforms.js +91 -6
- package/types.d.ts +31 -2
package/src/transforms.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
FERAL_REG_EXP,
|
|
5
5
|
SyntaxError,
|
|
6
6
|
freezeRegexp,
|
|
7
|
+
regexpExec,
|
|
7
8
|
regexpReplace,
|
|
8
9
|
regexpSearch,
|
|
9
10
|
sealRegexp,
|
|
@@ -110,9 +111,79 @@ export const evadeHtmlCommentTest = src => {
|
|
|
110
111
|
// /////////////////////////////////////////////////////////////////////////////
|
|
111
112
|
|
|
112
113
|
const importPattern = sealRegexp(
|
|
113
|
-
new FERAL_REG_EXP('(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(
|
|
114
|
+
new FERAL_REG_EXP('(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|\\.|/[/*]))', 'g'),
|
|
114
115
|
);
|
|
115
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Matches one line of a run of `//# sourceURL=` and `//# sourceMappingURL=`
|
|
119
|
+
* comments at the very end of the source (`sourceMetaTrailerStart` finds
|
|
120
|
+
* the run), as module-source, compartment-mapper and
|
|
121
|
+
* bundlers append to evaluated code (a module's location may well contain
|
|
122
|
+
* `import.`, as in `conditional-import.js`).
|
|
123
|
+
*
|
|
124
|
+
* Each line must begin at a line start and its value must hold no whitespace
|
|
125
|
+
* and none of `*`, backtick, `$`, quotes or backslash. Such a line is inert
|
|
126
|
+
* wherever it stands: outside any literal it is a line comment; a regular
|
|
127
|
+
* expression literal cannot span lines; and inside a block comment, a string
|
|
128
|
+
* continued from the line before or a template literal, the line can neither
|
|
129
|
+
* close that context (no `*`, quote or backtick) nor open a substitution (no
|
|
130
|
+
* `$`). Since nothing but whitespace follows the run, an unclosed context
|
|
131
|
+
* there is a SyntaxError. So `rejectImportExpressions` need not scan it.
|
|
132
|
+
*
|
|
133
|
+
* A `/*# sourceMappingURL=` block comment is not skipped but scanned like
|
|
134
|
+
* any other code, which can only make the check stricter.
|
|
135
|
+
*/
|
|
136
|
+
const sourceMetaLinePattern = freezeRegexp(
|
|
137
|
+
new FERAL_REG_EXP('^//# source(?:Mapping)?URL=[^\\s*`$\'"\\\\]*$'),
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const whitespacePattern = freezeRegexp(new FERAL_REG_EXP('^\\s$'));
|
|
141
|
+
|
|
142
|
+
const lineTerminatorPattern = freezeRegexp(
|
|
143
|
+
new FERAL_REG_EXP('^[\\n\\r\\u2028\\u2029]$'),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Returns the index at which the trailing run of source meta comments
|
|
148
|
+
* begins, at its leading line terminator if it has one, or the length of
|
|
149
|
+
* the source if there is no such run. It reads the source backward, one
|
|
150
|
+
* line at a time, and tests each line with `sourceMetaLinePattern` alone,
|
|
151
|
+
* so it takes time linear in the length of the source. A single regular
|
|
152
|
+
* expression for the whole run, `(?:(?:^|[\n\r\u2028\u2029])<line>)+\s*$`,
|
|
153
|
+
* finds the same run, but a search retries it at every line terminator,
|
|
154
|
+
* which takes time quadratic in the number of lines of the run.
|
|
155
|
+
*
|
|
156
|
+
* @param {string} src
|
|
157
|
+
* @returns {number}
|
|
158
|
+
*/
|
|
159
|
+
const sourceMetaTrailerStart = src => {
|
|
160
|
+
let end = src.length;
|
|
161
|
+
while (end > 0 && regexpExec(whitespacePattern, src[end - 1]) !== null) {
|
|
162
|
+
end -= 1;
|
|
163
|
+
}
|
|
164
|
+
let start = src.length;
|
|
165
|
+
for (;;) {
|
|
166
|
+
let lineStart = end;
|
|
167
|
+
while (
|
|
168
|
+
lineStart > 0 &&
|
|
169
|
+
regexpExec(lineTerminatorPattern, src[lineStart - 1]) === null
|
|
170
|
+
) {
|
|
171
|
+
lineStart -= 1;
|
|
172
|
+
}
|
|
173
|
+
if (
|
|
174
|
+
regexpExec(sourceMetaLinePattern, stringSlice(src, lineStart, end)) ===
|
|
175
|
+
null
|
|
176
|
+
) {
|
|
177
|
+
return start;
|
|
178
|
+
}
|
|
179
|
+
if (lineStart === 0) {
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
start = lineStart - 1;
|
|
183
|
+
end = lineStart - 1;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
116
187
|
/**
|
|
117
188
|
* Conservatively reject the source text if it may contain a dynamic
|
|
118
189
|
* import expression. To reject without parsing, `rejectImportExpressions` will
|
|
@@ -128,10 +199,23 @@ const importPattern = sealRegexp(
|
|
|
128
199
|
* apparent import expressions in literal strings or comments.
|
|
129
200
|
*
|
|
130
201
|
* The current conservative rule looks for the identifier "import"
|
|
131
|
-
* followed by either an open paren or something that looks like
|
|
132
|
-
* beginning of a comment.
|
|
133
|
-
*
|
|
134
|
-
*
|
|
202
|
+
* followed by either an open paren, a dot, or something that looks like
|
|
203
|
+
* the beginning of a comment. The dot case rejects not just a
|
|
204
|
+
* phase-qualified call such as `import.source(...)` or `import.defer(...)`,
|
|
205
|
+
* but any property access under `import` at all, including `import.meta`,
|
|
206
|
+
* regardless of whether the property is then called. This is broader than
|
|
207
|
+
* strictly necessary: the substring "import." can occur incidentally, for
|
|
208
|
+
* example in a module path or a comment, and such source text is rejected
|
|
209
|
+
* too. That tradeoff is intentional: covering every `import.<name>` form,
|
|
210
|
+
* called or not, without naming specific property names, is judged simpler
|
|
211
|
+
* and safer than narrowing the match to the shape of a call. We assume that
|
|
212
|
+
* we do not need to worry about html comment syntax because that was
|
|
213
|
+
* already rejected by rejectHtmlComments.
|
|
214
|
+
*
|
|
215
|
+
* The scan stops short of a trailing run of `//# sourceURL=` or
|
|
216
|
+
* `//# sourceMappingURL=` comments whose values could not end a comment,
|
|
217
|
+
* string or template (see `sourceMetaTrailerStart`), so that a module
|
|
218
|
+
* whose location contains `import.` still loads.
|
|
135
219
|
*
|
|
136
220
|
* this \s *must* match all kinds of syntax-defined whitespace. If e.g.
|
|
137
221
|
* U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) is treated as
|
|
@@ -144,7 +228,8 @@ const importPattern = sealRegexp(
|
|
|
144
228
|
* @returns {string}
|
|
145
229
|
*/
|
|
146
230
|
export const rejectImportExpressions = src => {
|
|
147
|
-
const
|
|
231
|
+
const scanned = stringSlice(src, 0, sourceMetaTrailerStart(src));
|
|
232
|
+
const lineNumber = getLineNumber(scanned, importPattern);
|
|
148
233
|
if (lineNumber < 0) {
|
|
149
234
|
return src;
|
|
150
235
|
}
|
package/types.d.ts
CHANGED
|
@@ -242,6 +242,11 @@ export interface AssertMakeErrorOptions {
|
|
|
242
242
|
* {@link sanitizeError}.
|
|
243
243
|
*/
|
|
244
244
|
sanitize?: boolean;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The error code to assign to the error.
|
|
248
|
+
*/
|
|
249
|
+
code?: string;
|
|
245
250
|
}
|
|
246
251
|
|
|
247
252
|
// TODO inline overloading
|
|
@@ -393,11 +398,33 @@ export interface AssertionUtilities {
|
|
|
393
398
|
* Create an error with a `message` in which unquoted {@link details}
|
|
394
399
|
* substitution values may have been redacted into lossy `typeof` output but
|
|
395
400
|
* are still available for logging to an associated console.
|
|
401
|
+
*
|
|
402
|
+
* Narrows the return type to the constructor type.
|
|
403
|
+
*
|
|
404
|
+
* @template T The constructor to use
|
|
405
|
+
* @param details The details of what was asserted
|
|
406
|
+
* @param errConstructor The constructor to use
|
|
407
|
+
* @param options Options
|
|
408
|
+
* @returns Instance of `T`
|
|
409
|
+
*/
|
|
410
|
+
makeError<T extends GenericErrorConstructor>(
|
|
411
|
+
details: Details,
|
|
412
|
+
errConstructor: T,
|
|
413
|
+
options?: AssertMakeErrorOptions,
|
|
414
|
+
): InstanceType<T>;
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Create an error with a `message` in which unquoted {@link details}
|
|
418
|
+
* substitution values may have been redacted into lossy `typeof` output but
|
|
419
|
+
* are still available for logging to an associated console.
|
|
420
|
+
*
|
|
421
|
+
* @param details The details of what was asserted
|
|
422
|
+
* @param errConstructor The constructor to use
|
|
423
|
+
* @param options Options
|
|
424
|
+
* @returns Instance of `Error`
|
|
396
425
|
*/
|
|
397
426
|
makeError(
|
|
398
|
-
/** The details of what was asserted */
|
|
399
427
|
details?: Details,
|
|
400
|
-
/** An optional alternate error constructor to use */
|
|
401
428
|
errConstructor?: GenericErrorConstructor,
|
|
402
429
|
options?: AssertMakeErrorOptions,
|
|
403
430
|
): Error;
|
|
@@ -564,6 +591,8 @@ declare global {
|
|
|
564
591
|
|
|
565
592
|
get name(): string;
|
|
566
593
|
|
|
594
|
+
get __noNamespaceBox__(): boolean;
|
|
595
|
+
|
|
567
596
|
evaluate(code: string, options?: CompartmentEvaluateOptions): any;
|
|
568
597
|
|
|
569
598
|
import(
|