ses 0.17.0 → 0.18.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/NEWS.md +22 -0
- package/README.md +4 -7
- package/dist/lockdown.cjs +307 -262
- package/dist/lockdown.mjs +307 -262
- package/dist/lockdown.umd.js +307 -262
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +307 -262
- package/dist/ses.mjs +307 -262
- package/dist/ses.umd.js +307 -262
- package/dist/ses.umd.min.js +1 -1
- package/index.d.ts +3 -2
- package/package.json +11 -10
- package/src/compartment-evaluate.js +7 -11
- package/src/compartment-shim.js +0 -30
- package/src/environment-options.js +4 -7
- package/src/error/assert.js +4 -0
- package/src/error/console.js +2 -6
- package/src/error/types.js +84 -11
- package/src/eval-scope.js +2 -5
- package/src/get-anonymous-intrinsics.js +4 -2
- package/src/lockdown-shim.js +17 -27
- package/src/make-evaluate.js +10 -10
- package/src/make-function-constructor.js +6 -8
- package/src/make-safe-evaluator.js +5 -6
- package/src/module-instance.js +24 -14
- package/src/module-link.js +24 -42
- package/src/module-load.js +61 -27
- package/src/scope-constants.js +8 -8
- package/src/strict-scope-terminator.js +2 -5
- package/src/tame-function-constructors.js +3 -2
- package/src/tame-locale-methods.js +6 -10
- package/src/tame-math-object.js +2 -3
- package/CHANGELOG.md +0 -577
|
@@ -9,7 +9,7 @@ import { applyTransforms, mandatoryTransforms } from './transforms.js';
|
|
|
9
9
|
import { makeEvaluate } from './make-evaluate.js';
|
|
10
10
|
import { assert } from './error/assert.js';
|
|
11
11
|
|
|
12
|
-
const {
|
|
12
|
+
const { Fail } = assert;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* makeSafeEvaluator()
|
|
@@ -18,13 +18,13 @@ const { details: d } = assert;
|
|
|
18
18
|
*
|
|
19
19
|
* @param {Object} options
|
|
20
20
|
* @param {Object} options.globalObject
|
|
21
|
-
* @param {Object} [options.
|
|
21
|
+
* @param {Object} [options.moduleLexicals]
|
|
22
22
|
* @param {Array<Transform>} [options.globalTransforms]
|
|
23
23
|
* @param {bool} [options.sloppyGlobalsMode]
|
|
24
24
|
*/
|
|
25
25
|
export const makeSafeEvaluator = ({
|
|
26
26
|
globalObject,
|
|
27
|
-
|
|
27
|
+
moduleLexicals = {},
|
|
28
28
|
globalTransforms = [],
|
|
29
29
|
sloppyGlobalsMode = false,
|
|
30
30
|
} = {}) => {
|
|
@@ -36,7 +36,7 @@ export const makeSafeEvaluator = ({
|
|
|
36
36
|
|
|
37
37
|
const evaluateContext = freeze({
|
|
38
38
|
evalScope,
|
|
39
|
-
|
|
39
|
+
moduleLexicals,
|
|
40
40
|
globalObject,
|
|
41
41
|
scopeTerminator,
|
|
42
42
|
});
|
|
@@ -100,8 +100,7 @@ export const makeSafeEvaluator = ({
|
|
|
100
100
|
evalScopeKit.revoked = { err };
|
|
101
101
|
// TODO A GOOD PLACE TO PANIC(), i.e., kill the vat incarnation.
|
|
102
102
|
// See https://github.com/Agoric/SES-shim/issues/490
|
|
103
|
-
|
|
104
|
-
assert.fail(d`handler did not reset allowNextEvalToBeUnsafe ${err}`);
|
|
103
|
+
Fail`handler did not reset allowNextEvalToBeUnsafe ${err}`;
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
106
|
};
|
package/src/module-instance.js
CHANGED
|
@@ -134,6 +134,7 @@ export const makeModuleInstance = (
|
|
|
134
134
|
__syncModuleProgram__: functorSource,
|
|
135
135
|
__fixedExportMap__: fixedExportMap = {},
|
|
136
136
|
__liveExportMap__: liveExportMap = {},
|
|
137
|
+
__reexportMap__: reexportMap = {},
|
|
137
138
|
__needsImportMeta__: needsImportMeta = false,
|
|
138
139
|
} = staticModuleRecord;
|
|
139
140
|
|
|
@@ -152,10 +153,10 @@ export const makeModuleInstance = (
|
|
|
152
153
|
// object (eventually proxied).
|
|
153
154
|
const exportsProps = create(null);
|
|
154
155
|
|
|
155
|
-
// {_localName_: accessor} proxy traps for
|
|
156
|
-
// The
|
|
157
|
-
//
|
|
158
|
-
const
|
|
156
|
+
// {_localName_: accessor} proxy traps for moduleLexicals and live bindings.
|
|
157
|
+
// The moduleLexicals object is frozen and the corresponding properties of
|
|
158
|
+
// moduleLexicals must be immutable, so we copy the descriptors.
|
|
159
|
+
const moduleLexicals = create(null);
|
|
159
160
|
|
|
160
161
|
// {_localName_: init(initValue) -> initValue} used by the
|
|
161
162
|
// rewritten code to initialize exported fixed bindings.
|
|
@@ -321,7 +322,7 @@ export const makeModuleInstance = (
|
|
|
321
322
|
|
|
322
323
|
localGetNotify[localName] = liveGetNotify;
|
|
323
324
|
if (setProxyTrap) {
|
|
324
|
-
defineProperty(
|
|
325
|
+
defineProperty(moduleLexicals, localName, {
|
|
325
326
|
get,
|
|
326
327
|
set,
|
|
327
328
|
enumerable: true,
|
|
@@ -387,26 +388,35 @@ export const makeModuleInstance = (
|
|
|
387
388
|
}
|
|
388
389
|
if (arrayIncludes(exportAlls, specifier)) {
|
|
389
390
|
// Make all these imports candidates.
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
391
|
+
// Note names don't change in reexporting all
|
|
392
|
+
for (const [importAndExportName, importNotify] of entries(
|
|
393
|
+
importNotifiers,
|
|
394
|
+
)) {
|
|
395
|
+
if (candidateAll[importAndExportName] === undefined) {
|
|
396
|
+
candidateAll[importAndExportName] = importNotify;
|
|
393
397
|
} else {
|
|
394
398
|
// Already a candidate: remove ambiguity.
|
|
395
|
-
candidateAll[
|
|
399
|
+
candidateAll[importAndExportName] = false;
|
|
396
400
|
}
|
|
397
401
|
}
|
|
398
402
|
}
|
|
403
|
+
if (reexportMap[specifier]) {
|
|
404
|
+
// Make named reexports candidates too.
|
|
405
|
+
for (const [localName, exportedName] of reexportMap[specifier]) {
|
|
406
|
+
candidateAll[exportedName] = importNotifiers[localName];
|
|
407
|
+
}
|
|
408
|
+
}
|
|
399
409
|
}
|
|
400
410
|
|
|
401
|
-
for (const [
|
|
402
|
-
if (!notifiers[
|
|
403
|
-
notifiers[
|
|
411
|
+
for (const [exportName, notify] of entries(candidateAll)) {
|
|
412
|
+
if (!notifiers[exportName] && notify !== false) {
|
|
413
|
+
notifiers[exportName] = notify;
|
|
404
414
|
|
|
405
415
|
// exported live binding state
|
|
406
416
|
let value;
|
|
407
417
|
const update = newValue => (value = newValue);
|
|
408
418
|
notify(update);
|
|
409
|
-
exportsProps[
|
|
419
|
+
exportsProps[exportName] = {
|
|
410
420
|
get() {
|
|
411
421
|
return value;
|
|
412
422
|
},
|
|
@@ -437,7 +447,7 @@ export const makeModuleInstance = (
|
|
|
437
447
|
let optFunctor = compartmentEvaluate(compartmentFields, functorSource, {
|
|
438
448
|
globalObject: compartment.globalThis,
|
|
439
449
|
transforms: __shimTransforms__,
|
|
440
|
-
__moduleShimLexicals__:
|
|
450
|
+
__moduleShimLexicals__: moduleLexicals,
|
|
441
451
|
});
|
|
442
452
|
let didThrow = false;
|
|
443
453
|
let thrownError;
|
package/src/module-link.js
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
weakmapGet,
|
|
27
27
|
} from './commons.js';
|
|
28
28
|
|
|
29
|
-
const { quote: q } = assert;
|
|
29
|
+
const { Fail, quote: q } = assert;
|
|
30
30
|
|
|
31
31
|
// `link` creates `ModuleInstances` and `ModuleNamespaces` for a module and its
|
|
32
32
|
// transitive dependencies and connects their imports and exports.
|
|
@@ -70,18 +70,14 @@ function validatePrecompiledStaticModuleRecord(
|
|
|
70
70
|
moduleSpecifier,
|
|
71
71
|
) {
|
|
72
72
|
const { __fixedExportMap__, __liveExportMap__ } = staticModuleRecord;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
`Property '__fixedExportMap__' of a precompiled module record must be an object, got ${q(
|
|
73
|
+
isObject(__fixedExportMap__) ||
|
|
74
|
+
Fail`Property '__fixedExportMap__' of a precompiled module record must be an object, got ${q(
|
|
76
75
|
__fixedExportMap__,
|
|
77
|
-
)}, for module ${q(moduleSpecifier)}
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
isObject(__liveExportMap__),
|
|
81
|
-
`Property '__liveExportMap__' of a precompiled module record must be an object, got ${q(
|
|
76
|
+
)}, for module ${q(moduleSpecifier)}`;
|
|
77
|
+
isObject(__liveExportMap__) ||
|
|
78
|
+
Fail`Property '__liveExportMap__' of a precompiled module record must be an object, got ${q(
|
|
82
79
|
__liveExportMap__,
|
|
83
|
-
)}, for module ${q(moduleSpecifier)}
|
|
84
|
-
);
|
|
80
|
+
)}, for module ${q(moduleSpecifier)}`;
|
|
85
81
|
}
|
|
86
82
|
|
|
87
83
|
function isThirdParty(staticModuleRecord) {
|
|
@@ -93,40 +89,30 @@ function validateThirdPartyStaticModuleRecord(
|
|
|
93
89
|
moduleSpecifier,
|
|
94
90
|
) {
|
|
95
91
|
const { exports } = staticModuleRecord;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
`Property 'exports' of a third-party static module record must be an array, got ${q(
|
|
92
|
+
isArray(exports) ||
|
|
93
|
+
Fail`Property 'exports' of a third-party static module record must be an array, got ${q(
|
|
99
94
|
exports,
|
|
100
|
-
)}, for module ${q(moduleSpecifier)}
|
|
101
|
-
);
|
|
95
|
+
)}, for module ${q(moduleSpecifier)}`;
|
|
102
96
|
}
|
|
103
97
|
|
|
104
98
|
function validateStaticModuleRecord(staticModuleRecord, moduleSpecifier) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
`Static module records must be of type object, got ${q(
|
|
99
|
+
isObject(staticModuleRecord) ||
|
|
100
|
+
Fail`Static module records must be of type object, got ${q(
|
|
108
101
|
staticModuleRecord,
|
|
109
|
-
)}, for module ${q(moduleSpecifier)}
|
|
110
|
-
);
|
|
102
|
+
)}, for module ${q(moduleSpecifier)}`;
|
|
111
103
|
const { imports, exports, reexports = [] } = staticModuleRecord;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
`Property 'imports' of a static module record must be an array, got ${q(
|
|
104
|
+
isArray(imports) ||
|
|
105
|
+
Fail`Property 'imports' of a static module record must be an array, got ${q(
|
|
115
106
|
imports,
|
|
116
|
-
)}, for module ${q(moduleSpecifier)}
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
isArray(exports),
|
|
120
|
-
`Property 'exports' of a precompiled module record must be an array, got ${q(
|
|
107
|
+
)}, for module ${q(moduleSpecifier)}`;
|
|
108
|
+
isArray(exports) ||
|
|
109
|
+
Fail`Property 'exports' of a precompiled module record must be an array, got ${q(
|
|
121
110
|
exports,
|
|
122
|
-
)}, for module ${q(moduleSpecifier)}
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
isArray(reexports),
|
|
126
|
-
`Property 'reexports' of a precompiled module record must be an array if present, got ${q(
|
|
111
|
+
)}, for module ${q(moduleSpecifier)}`;
|
|
112
|
+
isArray(reexports) ||
|
|
113
|
+
Fail`Property 'reexports' of a precompiled module record must be an array if present, got ${q(
|
|
127
114
|
reexports,
|
|
128
|
-
)}, for module ${q(moduleSpecifier)}
|
|
129
|
-
);
|
|
115
|
+
)}, for module ${q(moduleSpecifier)}`;
|
|
130
116
|
}
|
|
131
117
|
|
|
132
118
|
export const instantiate = (
|
|
@@ -134,12 +120,8 @@ export const instantiate = (
|
|
|
134
120
|
moduleAliases,
|
|
135
121
|
moduleRecord,
|
|
136
122
|
) => {
|
|
137
|
-
const {
|
|
138
|
-
|
|
139
|
-
moduleSpecifier,
|
|
140
|
-
resolvedImports,
|
|
141
|
-
staticModuleRecord,
|
|
142
|
-
} = moduleRecord;
|
|
123
|
+
const { compartment, moduleSpecifier, resolvedImports, staticModuleRecord } =
|
|
124
|
+
moduleRecord;
|
|
143
125
|
const { instances } = weakmapGet(compartmentPrivateFields, compartment);
|
|
144
126
|
|
|
145
127
|
// Memoize.
|
package/src/module-load.js
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from './commons.js';
|
|
28
28
|
import { assert } from './error/assert.js';
|
|
29
29
|
|
|
30
|
-
const { details: d, quote: q } = assert;
|
|
30
|
+
const { Fail, details: d, quote: q } = assert;
|
|
31
31
|
|
|
32
32
|
const noop = () => {};
|
|
33
33
|
|
|
@@ -54,7 +54,7 @@ const resolveAll = (imports, resolveHook, fullReferrerSpecifier) => {
|
|
|
54
54
|
return freeze(resolvedImports);
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
const loadRecord =
|
|
57
|
+
const loadRecord = (
|
|
58
58
|
compartmentPrivateFields,
|
|
59
59
|
moduleAliases,
|
|
60
60
|
compartment,
|
|
@@ -170,35 +170,69 @@ const loadWithoutErrorAnnotation = async (
|
|
|
170
170
|
const staticModuleRecord = await importHook(moduleSpecifier);
|
|
171
171
|
|
|
172
172
|
if (staticModuleRecord === null || typeof staticModuleRecord !== 'object') {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
moduleSpecifier,
|
|
177
|
-
)} in compartment ${q(compartment.name)}`,
|
|
178
|
-
);
|
|
173
|
+
Fail`importHook must return a promise for an object, for module ${q(
|
|
174
|
+
moduleSpecifier,
|
|
175
|
+
)} in compartment ${q(compartment.name)}`;
|
|
179
176
|
}
|
|
180
177
|
|
|
181
|
-
if
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
record
|
|
186
|
-
|
|
187
|
-
|
|
178
|
+
// check if record is a RedirectStaticModuleInterface
|
|
179
|
+
if (staticModuleRecord.specifier !== undefined) {
|
|
180
|
+
// check if this redirect with an explicit record
|
|
181
|
+
if (staticModuleRecord.record !== undefined) {
|
|
182
|
+
// ensure expected record shape
|
|
183
|
+
if (staticModuleRecord.compartment !== undefined) {
|
|
184
|
+
throw new TypeError(
|
|
185
|
+
'Cannot redirect to an explicit record with a specified compartment',
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
const {
|
|
189
|
+
compartment: aliasCompartment = compartment,
|
|
190
|
+
specifier: aliasSpecifier = moduleSpecifier,
|
|
191
|
+
record: aliasModuleRecord,
|
|
192
|
+
importMeta,
|
|
193
|
+
} = staticModuleRecord;
|
|
188
194
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
195
|
+
const aliasRecord = loadRecord(
|
|
196
|
+
compartmentPrivateFields,
|
|
197
|
+
moduleAliases,
|
|
198
|
+
aliasCompartment,
|
|
199
|
+
aliasSpecifier,
|
|
200
|
+
aliasModuleRecord,
|
|
201
|
+
pendingJobs,
|
|
202
|
+
moduleLoads,
|
|
203
|
+
errors,
|
|
204
|
+
importMeta,
|
|
205
|
+
);
|
|
206
|
+
mapSet(moduleRecords, moduleSpecifier, aliasRecord);
|
|
207
|
+
return aliasRecord;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// check if this redirect with an explicit compartment
|
|
211
|
+
if (staticModuleRecord.compartment !== undefined) {
|
|
212
|
+
// ensure expected record shape
|
|
213
|
+
if (staticModuleRecord.importMeta !== undefined) {
|
|
214
|
+
throw new TypeError(
|
|
215
|
+
'Cannot redirect to an implicit record with a specified importMeta',
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
// Behold: recursion.
|
|
219
|
+
// eslint-disable-next-line no-use-before-define
|
|
220
|
+
const aliasRecord = await memoizedLoadWithErrorAnnotation(
|
|
221
|
+
compartmentPrivateFields,
|
|
222
|
+
moduleAliases,
|
|
223
|
+
staticModuleRecord.compartment,
|
|
224
|
+
staticModuleRecord.specifier,
|
|
225
|
+
pendingJobs,
|
|
226
|
+
moduleLoads,
|
|
227
|
+
errors,
|
|
228
|
+
);
|
|
229
|
+
mapSet(moduleRecords, moduleSpecifier, aliasRecord);
|
|
230
|
+
return aliasRecord;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
throw new TypeError(
|
|
234
|
+
'Unnexpected RedirectStaticModuleInterface record shape',
|
|
199
235
|
);
|
|
200
|
-
mapSet(moduleRecords, moduleSpecifier, aliasRecord);
|
|
201
|
-
return aliasRecord;
|
|
202
236
|
}
|
|
203
237
|
|
|
204
238
|
return loadRecord(
|
package/src/scope-constants.js
CHANGED
|
@@ -144,20 +144,20 @@ function isImmutableDataProperty(obj, name) {
|
|
|
144
144
|
* safe and only prevent performance optimization.
|
|
145
145
|
*
|
|
146
146
|
* @param {Object} globalObject
|
|
147
|
-
* @param {Object}
|
|
147
|
+
* @param {Object} moduleLexicals
|
|
148
148
|
*/
|
|
149
|
-
export const getScopeConstants = (globalObject,
|
|
149
|
+
export const getScopeConstants = (globalObject, moduleLexicals = {}) => {
|
|
150
150
|
// getOwnPropertyNames() does ignore Symbols so we don't need to
|
|
151
151
|
// filter them out.
|
|
152
152
|
const globalObjectNames = getOwnPropertyNames(globalObject);
|
|
153
|
-
const
|
|
153
|
+
const moduleLexicalNames = getOwnPropertyNames(moduleLexicals);
|
|
154
154
|
|
|
155
155
|
// Collect all valid & immutable identifiers from the endowments.
|
|
156
|
-
const
|
|
157
|
-
|
|
156
|
+
const moduleLexicalConstants = arrayFilter(
|
|
157
|
+
moduleLexicalNames,
|
|
158
158
|
name =>
|
|
159
159
|
isValidIdentifierName(name) &&
|
|
160
|
-
isImmutableDataProperty(
|
|
160
|
+
isImmutableDataProperty(moduleLexicals, name),
|
|
161
161
|
);
|
|
162
162
|
|
|
163
163
|
// Collect all valid & immutable identifiers from the global that
|
|
@@ -167,13 +167,13 @@ export const getScopeConstants = (globalObject, globalLexicals = {}) => {
|
|
|
167
167
|
name =>
|
|
168
168
|
// Can't define a constant: it would prevent a
|
|
169
169
|
// lookup on the endowments.
|
|
170
|
-
!arrayIncludes(
|
|
170
|
+
!arrayIncludes(moduleLexicalNames, name) &&
|
|
171
171
|
isValidIdentifierName(name) &&
|
|
172
172
|
isImmutableDataProperty(globalObject, name),
|
|
173
173
|
);
|
|
174
174
|
|
|
175
175
|
return {
|
|
176
176
|
globalObjectConstants,
|
|
177
|
-
|
|
177
|
+
moduleLexicalConstants,
|
|
178
178
|
};
|
|
179
179
|
};
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from './commons.js';
|
|
12
12
|
import { assert } from './error/assert.js';
|
|
13
13
|
|
|
14
|
-
const {
|
|
14
|
+
const { Fail, quote: q } = assert;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* alwaysThrowHandler
|
|
@@ -24,10 +24,7 @@ export const alwaysThrowHandler = new Proxy(
|
|
|
24
24
|
immutableObject,
|
|
25
25
|
freeze({
|
|
26
26
|
get(_shadow, prop) {
|
|
27
|
-
|
|
28
|
-
assert.fail(
|
|
29
|
-
d`Please report unexpected scope handler trap: ${q(String(prop))}`,
|
|
30
|
-
);
|
|
27
|
+
Fail`Please report unexpected scope handler trap: ${q(String(prop))}`;
|
|
31
28
|
},
|
|
32
29
|
}),
|
|
33
30
|
);
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
defineProperties,
|
|
6
6
|
getPrototypeOf,
|
|
7
7
|
setPrototypeOf,
|
|
8
|
+
freeze,
|
|
8
9
|
} from './commons.js';
|
|
9
10
|
|
|
10
11
|
// This module replaces the original `Function` constructor, and the original
|
|
@@ -49,7 +50,7 @@ export default function tameFunctionConstructors() {
|
|
|
49
50
|
FERAL_FUNCTION.prototype.constructor('return 1');
|
|
50
51
|
} catch (ignore) {
|
|
51
52
|
// Throws, no need to patch.
|
|
52
|
-
return
|
|
53
|
+
return freeze({});
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
const newIntrinsics = {};
|
|
@@ -82,7 +83,7 @@ export default function tameFunctionConstructors() {
|
|
|
82
83
|
// Prevents the evaluation of source when calling constructor on the
|
|
83
84
|
// prototype of functions.
|
|
84
85
|
// eslint-disable-next-line func-names
|
|
85
|
-
const InertConstructor = function() {
|
|
86
|
+
const InertConstructor = function () {
|
|
86
87
|
throw new TypeError(
|
|
87
88
|
'Function.prototype.constructor is not a valid constructor.',
|
|
88
89
|
);
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from './commons.js';
|
|
10
10
|
import { assert } from './error/assert.js';
|
|
11
11
|
|
|
12
|
-
const {
|
|
12
|
+
const { Fail, quote: q } = assert;
|
|
13
13
|
|
|
14
14
|
const localePattern = /^(\w*[a-z])Locale([A-Z]\w*)$/;
|
|
15
15
|
|
|
@@ -31,7 +31,7 @@ const tamedMethods = {
|
|
|
31
31
|
if (s > that) {
|
|
32
32
|
return 1;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
s === that || Fail`expected ${q(s)} and ${q(that)} to compare`;
|
|
35
35
|
return 0;
|
|
36
36
|
},
|
|
37
37
|
|
|
@@ -61,16 +61,12 @@ export default function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
|
|
|
61
61
|
for (const methodName of getOwnPropertyNames(intrinsic)) {
|
|
62
62
|
const match = regexpExec(localePattern, methodName);
|
|
63
63
|
if (match) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
d`expected ${q(methodName)} to be a function`,
|
|
67
|
-
);
|
|
64
|
+
typeof intrinsic[methodName] === 'function' ||
|
|
65
|
+
Fail`expected ${q(methodName)} to be a function`;
|
|
68
66
|
const nonLocaleMethodName = `${match[1]}${match[2]}`;
|
|
69
67
|
const method = intrinsic[nonLocaleMethodName];
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
d`function ${q(nonLocaleMethodName)} not found`,
|
|
73
|
-
);
|
|
68
|
+
typeof method === 'function' ||
|
|
69
|
+
Fail`function ${q(nonLocaleMethodName)} not found`;
|
|
74
70
|
defineProperty(intrinsic, methodName, { value: method });
|
|
75
71
|
}
|
|
76
72
|
}
|
package/src/tame-math-object.js
CHANGED
|
@@ -13,9 +13,8 @@ export default function tameMathObject(mathTaming = 'safe') {
|
|
|
13
13
|
const originalMath = Math;
|
|
14
14
|
const initialMath = originalMath; // to follow the naming pattern
|
|
15
15
|
|
|
16
|
-
const { random: _, ...otherDescriptors } =
|
|
17
|
-
originalMath
|
|
18
|
-
);
|
|
16
|
+
const { random: _, ...otherDescriptors } =
|
|
17
|
+
getOwnPropertyDescriptors(originalMath);
|
|
19
18
|
|
|
20
19
|
const sharedMath = create(objectPrototype, otherDescriptors);
|
|
21
20
|
|