ses 0.17.0 → 0.18.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/CHANGELOG.md +19 -0
- package/NEWS.md +10 -0
- package/README.md +3 -6
- package/dist/lockdown.cjs +159 -165
- package/dist/lockdown.mjs +159 -165
- package/dist/lockdown.umd.js +159 -165
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +159 -165
- package/dist/ses.mjs +159 -165
- package/dist/ses.umd.js +159 -165
- package/dist/ses.umd.min.js +1 -1
- package/index.d.ts +1 -1
- package/package.json +6 -6
- package/src/compartment-evaluate.js +5 -7
- package/src/compartment-shim.js +0 -30
- package/src/environment-options.js +4 -7
- package/src/error/assert.js +4 -0
- package/src/error/types.js +59 -0
- package/src/eval-scope.js +2 -5
- package/src/lockdown-shim.js +13 -18
- 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 +6 -6
- package/src/module-link.js +22 -36
- package/src/module-load.js +4 -7
- package/src/scope-constants.js +8 -8
- package/src/strict-scope-terminator.js +2 -5
- package/src/tame-locale-methods.js +6 -10
package/dist/lockdown.umd.js
CHANGED
|
@@ -815,6 +815,64 @@ freeze(bestEffortStringify);
|
|
|
815
815
|
* `string[]` can also be used as a template.
|
|
816
816
|
*/
|
|
817
817
|
|
|
818
|
+
/**
|
|
819
|
+
* @typedef {(template: TemplateStringsArray | string[], ...args: any) => never} FailTag
|
|
820
|
+
* The `Fail` tamplate tag supports replacing patterns like
|
|
821
|
+
* ```js
|
|
822
|
+
* assert(cond, X`...complaint...`);
|
|
823
|
+
* ```
|
|
824
|
+
* or
|
|
825
|
+
* ```js
|
|
826
|
+
* cond || assert.fail(X`...complaint...`);
|
|
827
|
+
* ```
|
|
828
|
+
* with patterns like
|
|
829
|
+
* ```js
|
|
830
|
+
* cond || Fail`...complaint...`;
|
|
831
|
+
* ```
|
|
832
|
+
*
|
|
833
|
+
* However, due to [weakness in current
|
|
834
|
+
* TypeScript](https://github.com/microsoft/TypeScript/issues/51426), the `||`
|
|
835
|
+
* patterns are not as powerful as the `assert(...)` call at enabling static
|
|
836
|
+
* reasoning. Of the `||`, again due to weaknesses in current TypeScript,
|
|
837
|
+
* the
|
|
838
|
+
* ```js
|
|
839
|
+
* cond || Fail`...complaint...`
|
|
840
|
+
* ```
|
|
841
|
+
* pattern is not as powerful as the
|
|
842
|
+
* ```js
|
|
843
|
+
* cond || assert.fail(X`...complaint...`);
|
|
844
|
+
* ```
|
|
845
|
+
* at enabling static resoning. Despite these problems, we do not want to
|
|
846
|
+
* return to the
|
|
847
|
+
* ```js
|
|
848
|
+
* assert(cond, X`...complaint...`)
|
|
849
|
+
* ```
|
|
850
|
+
* style because of the substantial overhead in
|
|
851
|
+
* evaluating the `X` template in the typical `true` case where it is not
|
|
852
|
+
* needed. And we do not want to return to the
|
|
853
|
+
* ```js
|
|
854
|
+
* assert.fail(X`...complaint...`)`
|
|
855
|
+
* ```
|
|
856
|
+
* because of the verbosity and loss of readability. Instead, until/unless
|
|
857
|
+
* https://github.com/microsoft/TypeScript/issues/51426 is fixed, for those
|
|
858
|
+
* new-style assertions where this loss of static reasoning is a problem,
|
|
859
|
+
* instead express the assertion as
|
|
860
|
+
* ```js
|
|
861
|
+
* if (!cond) {
|
|
862
|
+
* Fail`...complaint...`;
|
|
863
|
+
* }
|
|
864
|
+
* ```
|
|
865
|
+
* or, if needed,
|
|
866
|
+
* ```js
|
|
867
|
+
* if (!cond) {
|
|
868
|
+
* // `throw` is noop since `Fail` throws. But linter confused
|
|
869
|
+
* throw Fail`...complaint...`;
|
|
870
|
+
* }
|
|
871
|
+
* ```
|
|
872
|
+
* This avoid the TypeScript bugs that cause the loss of static reasoning,
|
|
873
|
+
* but with no loss of efficiency and little loss of readability.
|
|
874
|
+
*/
|
|
875
|
+
|
|
818
876
|
/**
|
|
819
877
|
* assert that expr is truthy, with an optional details to describe
|
|
820
878
|
* the assertion. It is a tagged template literal like
|
|
@@ -841,6 +899,7 @@ freeze(bestEffortStringify);
|
|
|
841
899
|
* string: AssertString,
|
|
842
900
|
* note: AssertNote,
|
|
843
901
|
* details: DetailsTag,
|
|
902
|
+
* Fail: FailTag,
|
|
844
903
|
* quote: AssertQuote,
|
|
845
904
|
* makeAssert: MakeAssert,
|
|
846
905
|
* } } Assert
|
|
@@ -1283,6 +1342,9 @@ const makeAssert= (optRaise= undefined, unredacted= false)=> {
|
|
|
1283
1342
|
};
|
|
1284
1343
|
freeze(fail);
|
|
1285
1344
|
|
|
1345
|
+
/** @type {FailTag} */
|
|
1346
|
+
const Fail= (template, ...args)=> fail(details(template, ...args));
|
|
1347
|
+
|
|
1286
1348
|
// Don't freeze or export `baseAssert` until we add methods.
|
|
1287
1349
|
// TODO If I change this from a `function` function to an arrow
|
|
1288
1350
|
// function, I seem to get type errors from TypeScript. Why?
|
|
@@ -1341,6 +1403,7 @@ const makeAssert= (optRaise= undefined, unredacted= false)=> {
|
|
|
1341
1403
|
string: assertString,
|
|
1342
1404
|
note,
|
|
1343
1405
|
details,
|
|
1406
|
+
Fail,
|
|
1344
1407
|
quote,
|
|
1345
1408
|
makeAssert});
|
|
1346
1409
|
|
|
@@ -1358,7 +1421,7 @@ const assert= makeAssert();$h_once.assert(assert);
|
|
|
1358
1421
|
|
|
1359
1422
|
|
|
1360
1423
|
|
|
1361
|
-
const {
|
|
1424
|
+
const { Fail}= assert;
|
|
1362
1425
|
|
|
1363
1426
|
// We attempt to frustrate stack bumping attacks on the safe evaluator
|
|
1364
1427
|
// (`make-safe-evaluator.js`).
|
|
@@ -1429,10 +1492,7 @@ const makeEvalScopeKit= ()=> {
|
|
|
1429
1492
|
evalScope,
|
|
1430
1493
|
allowNextEvalToBeUnsafe() {
|
|
1431
1494
|
if( evalScopeKit.revoked!== null) {
|
|
1432
|
-
|
|
1433
|
-
assert.fail(
|
|
1434
|
-
d `a handler did not reset allowNextEvalToBeUnsafe ${this.revoked.err}`);
|
|
1435
|
-
|
|
1495
|
+
Fail `a handler did not reset allowNextEvalToBeUnsafe ${this.revoked.err}`;
|
|
1436
1496
|
}
|
|
1437
1497
|
// Allow next reference to eval produce the unsafe FERAL_EVAL.
|
|
1438
1498
|
// We avoid defineProperty because it consumes an extra stack frame taming
|
|
@@ -1593,20 +1653,20 @@ function isImmutableDataProperty(obj, name) {
|
|
|
1593
1653
|
* safe and only prevent performance optimization.
|
|
1594
1654
|
*
|
|
1595
1655
|
* @param {Object} globalObject
|
|
1596
|
-
* @param {Object}
|
|
1656
|
+
* @param {Object} moduleLexicals
|
|
1597
1657
|
*/
|
|
1598
|
-
const getScopeConstants= (globalObject,
|
|
1658
|
+
const getScopeConstants= (globalObject, moduleLexicals= {})=> {
|
|
1599
1659
|
// getOwnPropertyNames() does ignore Symbols so we don't need to
|
|
1600
1660
|
// filter them out.
|
|
1601
1661
|
const globalObjectNames= getOwnPropertyNames(globalObject);
|
|
1602
|
-
const
|
|
1662
|
+
const moduleLexicalNames= getOwnPropertyNames(moduleLexicals);
|
|
1603
1663
|
|
|
1604
1664
|
// Collect all valid & immutable identifiers from the endowments.
|
|
1605
|
-
const
|
|
1606
|
-
|
|
1665
|
+
const moduleLexicalConstants= arrayFilter(
|
|
1666
|
+
moduleLexicalNames,
|
|
1607
1667
|
(name)=>
|
|
1608
1668
|
isValidIdentifierName(name)&&
|
|
1609
|
-
isImmutableDataProperty(
|
|
1669
|
+
isImmutableDataProperty(moduleLexicals, name));
|
|
1610
1670
|
|
|
1611
1671
|
|
|
1612
1672
|
// Collect all valid & immutable identifiers from the global that
|
|
@@ -1616,14 +1676,14 @@ const getScopeConstants= (globalObject, globalLexicals= {})=> {
|
|
|
1616
1676
|
(name)=>
|
|
1617
1677
|
// Can't define a constant: it would prevent a
|
|
1618
1678
|
// lookup on the endowments.
|
|
1619
|
-
!arrayIncludes(
|
|
1679
|
+
!arrayIncludes(moduleLexicalNames, name)&&
|
|
1620
1680
|
isValidIdentifierName(name)&&
|
|
1621
1681
|
isImmutableDataProperty(globalObject, name));
|
|
1622
1682
|
|
|
1623
1683
|
|
|
1624
1684
|
return {
|
|
1625
1685
|
globalObjectConstants,
|
|
1626
|
-
|
|
1686
|
+
moduleLexicalConstants};
|
|
1627
1687
|
|
|
1628
1688
|
};$h_once.getScopeConstants(getScopeConstants);
|
|
1629
1689
|
})
|
|
@@ -1657,22 +1717,22 @@ function buildOptimizer(constants, name) {
|
|
|
1657
1717
|
*
|
|
1658
1718
|
* @param {object} context
|
|
1659
1719
|
* @param {object} context.evalScope
|
|
1660
|
-
* @param {object} context.
|
|
1720
|
+
* @param {object} context.moduleLexicals
|
|
1661
1721
|
* @param {object} context.globalObject
|
|
1662
1722
|
* @param {object} context.scopeTerminator
|
|
1663
1723
|
*/
|
|
1664
1724
|
const makeEvaluate= (context)=>{
|
|
1665
|
-
const { globalObjectConstants,
|
|
1725
|
+
const { globalObjectConstants, moduleLexicalConstants}= getScopeConstants(
|
|
1666
1726
|
context.globalObject,
|
|
1667
|
-
context.
|
|
1727
|
+
context.moduleLexicals);
|
|
1668
1728
|
|
|
1669
1729
|
const globalObjectOptimizer= buildOptimizer(
|
|
1670
1730
|
globalObjectConstants,
|
|
1671
1731
|
'globalObject');
|
|
1672
1732
|
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
'
|
|
1733
|
+
const moduleLexicalOptimizer= buildOptimizer(
|
|
1734
|
+
moduleLexicalConstants,
|
|
1735
|
+
'moduleLexicals');
|
|
1676
1736
|
|
|
1677
1737
|
|
|
1678
1738
|
// Create a function in sloppy mode, so that we can use 'with'. It returns
|
|
@@ -1688,7 +1748,7 @@ const makeEvaluate= (context)=>{
|
|
|
1688
1748
|
// trigger direct eval. The direct eval semantics is what allows the
|
|
1689
1749
|
// evaluated code to lookup free variable names on the other scope
|
|
1690
1750
|
// objects and not in global scope.
|
|
1691
|
-
// b) `
|
|
1751
|
+
// b) `moduleLexicals` which provide a way to introduce free variables
|
|
1692
1752
|
// that are not available on the globalObject.
|
|
1693
1753
|
// c) `globalObject` is the global scope object of the evaluator, aka the
|
|
1694
1754
|
// Compartment's `globalThis`.
|
|
@@ -1702,7 +1762,7 @@ const makeEvaluate= (context)=>{
|
|
|
1702
1762
|
|
|
1703
1763
|
// Notes:
|
|
1704
1764
|
// - The `optimizer` strings only lookup values on the `globalObject` and
|
|
1705
|
-
// `
|
|
1765
|
+
// `moduleLexicals` objects by construct. Keywords like 'function' are
|
|
1706
1766
|
// reserved and cannot be used as a variable, so they are excluded from the
|
|
1707
1767
|
// optimizer. Furthermore to prevent shadowing 'eval', while a valid
|
|
1708
1768
|
// identifier, that name is also explicitly excluded.
|
|
@@ -1723,10 +1783,10 @@ const makeEvaluate= (context)=>{
|
|
|
1723
1783
|
const evaluateFactory= FERAL_FUNCTION( `
|
|
1724
1784
|
with (this.scopeTerminator) {
|
|
1725
1785
|
with (this.globalObject) {
|
|
1726
|
-
with (this.
|
|
1786
|
+
with (this.moduleLexicals) {
|
|
1727
1787
|
with (this.evalScope) {
|
|
1728
1788
|
${globalObjectOptimizer }
|
|
1729
|
-
${
|
|
1789
|
+
${moduleLexicalOptimizer }
|
|
1730
1790
|
return function() {
|
|
1731
1791
|
'use strict';
|
|
1732
1792
|
return eval(arguments[0]);
|
|
@@ -1755,7 +1815,7 @@ const makeEvaluate= (context)=>{
|
|
|
1755
1815
|
|
|
1756
1816
|
|
|
1757
1817
|
|
|
1758
|
-
const {
|
|
1818
|
+
const { Fail, quote: q}= assert;
|
|
1759
1819
|
|
|
1760
1820
|
/**
|
|
1761
1821
|
* alwaysThrowHandler
|
|
@@ -1768,10 +1828,7 @@ const alwaysThrowHandler= new Proxy(
|
|
|
1768
1828
|
immutableObject,
|
|
1769
1829
|
freeze({
|
|
1770
1830
|
get(_shadow, prop) {
|
|
1771
|
-
|
|
1772
|
-
assert.fail(
|
|
1773
|
-
d `Please report unexpected scope handler trap: ${q(String(prop))}`);
|
|
1774
|
-
|
|
1831
|
+
Fail `Please report unexpected scope handler trap: ${q(String(prop))}`;
|
|
1775
1832
|
}}));
|
|
1776
1833
|
|
|
1777
1834
|
|
|
@@ -2206,7 +2263,7 @@ const applyTransforms= (source, transforms)=> {
|
|
|
2206
2263
|
|
|
2207
2264
|
|
|
2208
2265
|
|
|
2209
|
-
const {
|
|
2266
|
+
const { Fail}= assert;
|
|
2210
2267
|
|
|
2211
2268
|
/**
|
|
2212
2269
|
* makeSafeEvaluator()
|
|
@@ -2215,13 +2272,13 @@ const { details: d}= assert;
|
|
|
2215
2272
|
*
|
|
2216
2273
|
* @param {Object} options
|
|
2217
2274
|
* @param {Object} options.globalObject
|
|
2218
|
-
* @param {Object} [options.
|
|
2275
|
+
* @param {Object} [options.moduleLexicals]
|
|
2219
2276
|
* @param {Array<Transform>} [options.globalTransforms]
|
|
2220
2277
|
* @param {bool} [options.sloppyGlobalsMode]
|
|
2221
2278
|
*/
|
|
2222
2279
|
const makeSafeEvaluator= ({
|
|
2223
2280
|
globalObject,
|
|
2224
|
-
|
|
2281
|
+
moduleLexicals= {},
|
|
2225
2282
|
globalTransforms= [],
|
|
2226
2283
|
sloppyGlobalsMode= false}=
|
|
2227
2284
|
{})=> {
|
|
@@ -2233,7 +2290,7 @@ const makeSafeEvaluator= ({
|
|
|
2233
2290
|
|
|
2234
2291
|
const evaluateContext= freeze({
|
|
2235
2292
|
evalScope,
|
|
2236
|
-
|
|
2293
|
+
moduleLexicals,
|
|
2237
2294
|
globalObject,
|
|
2238
2295
|
scopeTerminator});
|
|
2239
2296
|
|
|
@@ -2297,8 +2354,7 @@ const makeSafeEvaluator= ({
|
|
|
2297
2354
|
evalScopeKit.revoked= { err};
|
|
2298
2355
|
// TODO A GOOD PLACE TO PANIC(), i.e., kill the vat incarnation.
|
|
2299
2356
|
// See https://github.com/Agoric/SES-shim/issues/490
|
|
2300
|
-
|
|
2301
|
-
assert.fail(d `handler did not reset allowNextEvalToBeUnsafe ${err}`);
|
|
2357
|
+
Fail `handler did not reset allowNextEvalToBeUnsafe ${err}`;
|
|
2302
2358
|
}
|
|
2303
2359
|
}
|
|
2304
2360
|
};
|
|
@@ -2308,8 +2364,7 @@ const makeSafeEvaluator= ({
|
|
|
2308
2364
|
})
|
|
2309
2365
|
,
|
|
2310
2366
|
// === functors[13] ===
|
|
2311
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let TypeError,arrayPush,create,
|
|
2312
|
-
|
|
2367
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let TypeError,arrayPush,create,getOwnPropertyDescriptors,evadeHtmlCommentTest,evadeImportExpressionTest,rejectSomeDirectEvalExpressions,makeSafeEvaluator;$h_imports([["./commons.js", [["TypeError", [$h_a => (TypeError = $h_a)]],["arrayPush", [$h_a => (arrayPush = $h_a)]],["create", [$h_a => (create = $h_a)]],["getOwnPropertyDescriptors", [$h_a => (getOwnPropertyDescriptors = $h_a)]]]],["./transforms.js", [["evadeHtmlCommentTest", [$h_a => (evadeHtmlCommentTest = $h_a)]],["evadeImportExpressionTest", [$h_a => (evadeImportExpressionTest = $h_a)]],["rejectSomeDirectEvalExpressions", [$h_a => (rejectSomeDirectEvalExpressions = $h_a)]]]],["./make-safe-evaluator.js", [["makeSafeEvaluator", [$h_a => (makeSafeEvaluator = $h_a)]]]]]);
|
|
2313
2368
|
|
|
2314
2369
|
|
|
2315
2370
|
|
|
@@ -2338,9 +2393,9 @@ const provideCompartmentEvaluator= (compartmentFields, options)=> {
|
|
|
2338
2393
|
// shared evaluator so we need to build a new one
|
|
2339
2394
|
|
|
2340
2395
|
let { globalTransforms}= compartmentFields;
|
|
2341
|
-
const { globalObject
|
|
2396
|
+
const { globalObject}= compartmentFields;
|
|
2342
2397
|
|
|
2343
|
-
let
|
|
2398
|
+
let moduleLexicals;
|
|
2344
2399
|
if( __moduleShimLexicals__!== undefined) {
|
|
2345
2400
|
// When using `evaluate` for ESM modules, as should only occur from the
|
|
2346
2401
|
// module-shim's module-instance.js, we do not reveal the SES-shim's
|
|
@@ -2352,16 +2407,15 @@ const provideCompartmentEvaluator= (compartmentFields, options)=> {
|
|
|
2352
2407
|
// and `import`, at the expense of being tightly coupled to SES-shim.
|
|
2353
2408
|
globalTransforms= undefined;
|
|
2354
2409
|
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
localObject,
|
|
2410
|
+
moduleLexicals= create(
|
|
2411
|
+
null,
|
|
2358
2412
|
getOwnPropertyDescriptors(__moduleShimLexicals__));
|
|
2359
2413
|
|
|
2360
2414
|
}
|
|
2361
2415
|
|
|
2362
2416
|
({ safeEvaluate}= makeSafeEvaluator({
|
|
2363
2417
|
globalObject,
|
|
2364
|
-
|
|
2418
|
+
moduleLexicals,
|
|
2365
2419
|
globalTransforms,
|
|
2366
2420
|
sloppyGlobalsMode}));
|
|
2367
2421
|
|
|
@@ -2447,6 +2501,8 @@ const makeEvalFunction= (safeEvaluate)=>{
|
|
|
2447
2501
|
|
|
2448
2502
|
|
|
2449
2503
|
|
|
2504
|
+
const { Fail}= assert;
|
|
2505
|
+
|
|
2450
2506
|
/*
|
|
2451
2507
|
* makeFunctionConstructor()
|
|
2452
2508
|
* A safe version of the native Function which relies on
|
|
@@ -2507,14 +2563,10 @@ const makeFunctionConstructor= (safeEvaluate)=>{
|
|
|
2507
2563
|
|
|
2508
2564
|
|
|
2509
2565
|
// Assert identity of Function.__proto__ accross all compartments
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
assert(
|
|
2515
|
-
getPrototypeOf(newFunction)=== FERAL_FUNCTION.prototype,
|
|
2516
|
-
'Function constructor prototype is the same accross compartments');
|
|
2517
|
-
|
|
2566
|
+
getPrototypeOf(FERAL_FUNCTION)=== FERAL_FUNCTION.prototype||
|
|
2567
|
+
Fail `Function prototype is the same accross compartments`;
|
|
2568
|
+
getPrototypeOf(newFunction)=== FERAL_FUNCTION.prototype||
|
|
2569
|
+
Fail `Function constructor prototype is the same accross compartments`;
|
|
2518
2570
|
|
|
2519
2571
|
return newFunction;
|
|
2520
2572
|
};$h_once.makeFunctionConstructor(makeFunctionConstructor);
|
|
@@ -4096,7 +4148,7 @@ const setGlobalObjectEvaluators= (
|
|
|
4096
4148
|
|
|
4097
4149
|
|
|
4098
4150
|
|
|
4099
|
-
const { details: d, quote: q}= assert;
|
|
4151
|
+
const { Fail, details: d, quote: q}= assert;
|
|
4100
4152
|
|
|
4101
4153
|
const noop= ()=> { };
|
|
4102
4154
|
|
|
@@ -4239,12 +4291,9 @@ const loadWithoutErrorAnnotation= async(
|
|
|
4239
4291
|
const staticModuleRecord= await importHook(moduleSpecifier);
|
|
4240
4292
|
|
|
4241
4293
|
if( staticModuleRecord=== null|| typeof staticModuleRecord!== 'object') {
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
moduleSpecifier)
|
|
4246
|
-
} in compartment ${q(compartment.name)}`);
|
|
4247
|
-
|
|
4294
|
+
Fail `importHook must return a promise for an object, for module ${q(
|
|
4295
|
+
moduleSpecifier)
|
|
4296
|
+
} in compartment ${q(compartment.name)}`;
|
|
4248
4297
|
}
|
|
4249
4298
|
|
|
4250
4299
|
if( staticModuleRecord.record!== undefined) {
|
|
@@ -4728,10 +4777,10 @@ $h_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
|
|
|
4728
4777
|
// object (eventually proxied).
|
|
4729
4778
|
const exportsProps= create(null);
|
|
4730
4779
|
|
|
4731
|
-
// {_localName_: accessor} proxy traps for
|
|
4732
|
-
// The
|
|
4733
|
-
//
|
|
4734
|
-
const
|
|
4780
|
+
// {_localName_: accessor} proxy traps for moduleLexicals and live bindings.
|
|
4781
|
+
// The moduleLexicals object is frozen and the corresponding properties of
|
|
4782
|
+
// moduleLexicals must be immutable, so we copy the descriptors.
|
|
4783
|
+
const moduleLexicals= create(null);
|
|
4735
4784
|
|
|
4736
4785
|
// {_localName_: init(initValue) -> initValue} used by the
|
|
4737
4786
|
// rewritten code to initialize exported fixed bindings.
|
|
@@ -4897,7 +4946,7 @@ $h_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
|
|
|
4897
4946
|
|
|
4898
4947
|
localGetNotify[localName]= liveGetNotify;
|
|
4899
4948
|
if( setProxyTrap) {
|
|
4900
|
-
defineProperty(
|
|
4949
|
+
defineProperty(moduleLexicals, localName, {
|
|
4901
4950
|
get,
|
|
4902
4951
|
set,
|
|
4903
4952
|
enumerable: true,
|
|
@@ -5013,7 +5062,7 @@ $h_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
|
|
|
5013
5062
|
let optFunctor= compartmentEvaluate(compartmentFields, functorSource, {
|
|
5014
5063
|
globalObject: compartment.globalThis,
|
|
5015
5064
|
transforms: __shimTransforms__,
|
|
5016
|
-
__moduleShimLexicals__:
|
|
5065
|
+
__moduleShimLexicals__: moduleLexicals});
|
|
5017
5066
|
|
|
5018
5067
|
let didThrow= false;
|
|
5019
5068
|
let thrownError;
|
|
@@ -5080,7 +5129,7 @@ $h_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
|
|
|
5080
5129
|
|
|
5081
5130
|
|
|
5082
5131
|
|
|
5083
|
-
const { quote: q}= assert;
|
|
5132
|
+
const { Fail, quote: q}= assert;
|
|
5084
5133
|
|
|
5085
5134
|
// `link` creates `ModuleInstances` and `ModuleNamespaces` for a module and its
|
|
5086
5135
|
// transitive dependencies and connects their imports and exports.
|
|
@@ -5124,18 +5173,14 @@ function validatePrecompiledStaticModuleRecord(
|
|
|
5124
5173
|
moduleSpecifier)
|
|
5125
5174
|
{
|
|
5126
5175
|
const { __fixedExportMap__, __liveExportMap__}= staticModuleRecord;
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
`Property '__fixedExportMap__' of a precompiled module record must be an object, got ${q(
|
|
5176
|
+
isObject(__fixedExportMap__)||
|
|
5177
|
+
Fail `Property '__fixedExportMap__' of a precompiled module record must be an object, got ${q(
|
|
5130
5178
|
__fixedExportMap__)
|
|
5131
|
-
}, for module ${q(moduleSpecifier)}
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
isObject(__liveExportMap__),
|
|
5135
|
-
`Property '__liveExportMap__' of a precompiled module record must be an object, got ${q(
|
|
5179
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5180
|
+
isObject(__liveExportMap__)||
|
|
5181
|
+
Fail `Property '__liveExportMap__' of a precompiled module record must be an object, got ${q(
|
|
5136
5182
|
__liveExportMap__)
|
|
5137
|
-
}, for module ${q(moduleSpecifier)}
|
|
5138
|
-
|
|
5183
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5139
5184
|
}
|
|
5140
5185
|
|
|
5141
5186
|
function isThirdParty(staticModuleRecord) {
|
|
@@ -5147,40 +5192,30 @@ function validateThirdPartyStaticModuleRecord(
|
|
|
5147
5192
|
moduleSpecifier)
|
|
5148
5193
|
{
|
|
5149
5194
|
const { exports}= staticModuleRecord;
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
`Property 'exports' of a third-party static module record must be an array, got ${q(
|
|
5195
|
+
isArray(exports)||
|
|
5196
|
+
Fail `Property 'exports' of a third-party static module record must be an array, got ${q(
|
|
5153
5197
|
exports)
|
|
5154
|
-
}, for module ${q(moduleSpecifier)}
|
|
5155
|
-
|
|
5198
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5156
5199
|
}
|
|
5157
5200
|
|
|
5158
5201
|
function validateStaticModuleRecord(staticModuleRecord, moduleSpecifier) {
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
`Static module records must be of type object, got ${q(
|
|
5202
|
+
isObject(staticModuleRecord)||
|
|
5203
|
+
Fail `Static module records must be of type object, got ${q(
|
|
5162
5204
|
staticModuleRecord)
|
|
5163
|
-
}, for module ${q(moduleSpecifier)}
|
|
5164
|
-
|
|
5205
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5165
5206
|
const { imports, exports, reexports= []}= staticModuleRecord;
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
`Property 'imports' of a static module record must be an array, got ${q(
|
|
5207
|
+
isArray(imports)||
|
|
5208
|
+
Fail `Property 'imports' of a static module record must be an array, got ${q(
|
|
5169
5209
|
imports)
|
|
5170
|
-
}, for module ${q(moduleSpecifier)}
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
isArray(exports),
|
|
5174
|
-
`Property 'exports' of a precompiled module record must be an array, got ${q(
|
|
5210
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5211
|
+
isArray(exports)||
|
|
5212
|
+
Fail `Property 'exports' of a precompiled module record must be an array, got ${q(
|
|
5175
5213
|
exports)
|
|
5176
|
-
}, for module ${q(moduleSpecifier)}
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
isArray(reexports),
|
|
5180
|
-
`Property 'reexports' of a precompiled module record must be an array if present, got ${q(
|
|
5214
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5215
|
+
isArray(reexports)||
|
|
5216
|
+
Fail `Property 'reexports' of a precompiled module record must be an array if present, got ${q(
|
|
5181
5217
|
reexports)
|
|
5182
|
-
}, for module ${q(moduleSpecifier)}
|
|
5183
|
-
|
|
5218
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5184
5219
|
}
|
|
5185
5220
|
|
|
5186
5221
|
const instantiate= (
|
|
@@ -5250,12 +5285,7 @@ const instantiate= (
|
|
|
5250
5285
|
})
|
|
5251
5286
|
,
|
|
5252
5287
|
// === functors[22] ===
|
|
5253
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let Map,ReferenceError,TypeError,WeakMap,
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5288
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let Map,ReferenceError,TypeError,WeakMap,assign,defineProperties,entries,promiseThen,weakmapGet,weakmapSet,setGlobalObjectSymbolUnscopables,setGlobalObjectConstantProperties,setGlobalObjectMutableProperties,setGlobalObjectEvaluators,sharedGlobalPropertyNames,load,link,getDeferredExports,assert,compartmentEvaluate,makeSafeEvaluator;$h_imports([["./commons.js", [["Map", [$h_a => (Map = $h_a)]],["ReferenceError", [$h_a => (ReferenceError = $h_a)]],["TypeError", [$h_a => (TypeError = $h_a)]],["WeakMap", [$h_a => (WeakMap = $h_a)]],["assign", [$h_a => (assign = $h_a)]],["defineProperties", [$h_a => (defineProperties = $h_a)]],["entries", [$h_a => (entries = $h_a)]],["promiseThen", [$h_a => (promiseThen = $h_a)]],["weakmapGet", [$h_a => (weakmapGet = $h_a)]],["weakmapSet", [$h_a => (weakmapSet = $h_a)]]]],["./global-object.js", [["setGlobalObjectSymbolUnscopables", [$h_a => (setGlobalObjectSymbolUnscopables = $h_a)]],["setGlobalObjectConstantProperties", [$h_a => (setGlobalObjectConstantProperties = $h_a)]],["setGlobalObjectMutableProperties", [$h_a => (setGlobalObjectMutableProperties = $h_a)]],["setGlobalObjectEvaluators", [$h_a => (setGlobalObjectEvaluators = $h_a)]]]],["./whitelist.js", [["sharedGlobalPropertyNames", [$h_a => (sharedGlobalPropertyNames = $h_a)]]]],["./module-load.js", [["load", [$h_a => (load = $h_a)]]]],["./module-link.js", [["link", [$h_a => (link = $h_a)]]]],["./module-proxy.js", [["getDeferredExports", [$h_a => (getDeferredExports = $h_a)]]]],["./error/assert.js", [["assert", [$h_a => (assert = $h_a)]]]],["./compartment-evaluate.js", [["compartmentEvaluate", [$h_a => (compartmentEvaluate = $h_a)]]]],["./make-safe-evaluator.js", [["makeSafeEvaluator", [$h_a => (makeSafeEvaluator = $h_a)]]]]]);
|
|
5259
5289
|
|
|
5260
5290
|
|
|
5261
5291
|
|
|
@@ -5459,7 +5489,6 @@ const makeCompartmentConstructor= (
|
|
|
5459
5489
|
name= '<unknown>',
|
|
5460
5490
|
transforms= [],
|
|
5461
5491
|
__shimTransforms__= [],
|
|
5462
|
-
globalLexicals: globalLexicalsOption= {},
|
|
5463
5492
|
resolveHook,
|
|
5464
5493
|
importHook,
|
|
5465
5494
|
moduleMapHook,
|
|
@@ -5498,28 +5527,6 @@ const makeCompartmentConstructor= (
|
|
|
5498
5527
|
}
|
|
5499
5528
|
}
|
|
5500
5529
|
|
|
5501
|
-
const invalidNames= arrayFilter(
|
|
5502
|
-
getOwnPropertyNames(globalLexicalsOption),
|
|
5503
|
-
(identifier)=>!isValidIdentifierName(identifier));
|
|
5504
|
-
|
|
5505
|
-
if( invalidNames.length) {
|
|
5506
|
-
throw new TypeError(
|
|
5507
|
-
`Cannot create compartment with invalid names for global lexicals: ${arrayJoin(
|
|
5508
|
-
invalidNames,
|
|
5509
|
-
', ')
|
|
5510
|
-
}; these names would not be lexically mentionable`);
|
|
5511
|
-
|
|
5512
|
-
}
|
|
5513
|
-
// The caller continues to own the globalLexicals object they passed to
|
|
5514
|
-
// the compartment constructor, but the compartment only respects the
|
|
5515
|
-
// original values and they are constants in the scope of evaluated
|
|
5516
|
-
// programs and executed modules.
|
|
5517
|
-
// This shallow copy captures only the values of enumerable own
|
|
5518
|
-
// properties, erasing accessors.
|
|
5519
|
-
// The snapshot is frozen to ensure that the properties are immutable
|
|
5520
|
-
// when transferred-by-property-descriptor onto local scope objects.
|
|
5521
|
-
const globalLexicals= freeze({ ...globalLexicalsOption});
|
|
5522
|
-
|
|
5523
5530
|
const globalObject= {};
|
|
5524
5531
|
|
|
5525
5532
|
setGlobalObjectSymbolUnscopables(globalObject);
|
|
@@ -5533,7 +5540,6 @@ const makeCompartmentConstructor= (
|
|
|
5533
5540
|
|
|
5534
5541
|
const { safeEvaluate}= makeSafeEvaluator({
|
|
5535
5542
|
globalObject,
|
|
5536
|
-
globalLexicals,
|
|
5537
5543
|
globalTransforms,
|
|
5538
5544
|
sloppyGlobalsMode: false});
|
|
5539
5545
|
|
|
@@ -5558,7 +5564,6 @@ const makeCompartmentConstructor= (
|
|
|
5558
5564
|
name: `${name}`,
|
|
5559
5565
|
globalTransforms,
|
|
5560
5566
|
globalObject,
|
|
5561
|
-
globalLexicals,
|
|
5562
5567
|
safeEvaluate,
|
|
5563
5568
|
resolveHook,
|
|
5564
5569
|
importHook,
|
|
@@ -6178,7 +6183,7 @@ function enablePropertyOverrides(
|
|
|
6178
6183
|
|
|
6179
6184
|
|
|
6180
6185
|
|
|
6181
|
-
const { details: X, quote: q}= assert;
|
|
6186
|
+
const { details: X, Fail, quote: q}= assert;
|
|
6182
6187
|
|
|
6183
6188
|
/**
|
|
6184
6189
|
* JavaScript module semantics resists attempts to parameterize a module's
|
|
@@ -6282,12 +6287,9 @@ const makeEnvironmentCaptor= (aGlobal)=>{
|
|
|
6282
6287
|
}
|
|
6283
6288
|
setting=== undefined||
|
|
6284
6289
|
typeof setting=== 'string'||
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
setting)
|
|
6289
|
-
}, if present, must be a string.`);
|
|
6290
|
-
|
|
6290
|
+
Fail `Environment option value ${q(
|
|
6291
|
+
setting)
|
|
6292
|
+
}, if present, must be a string.`;
|
|
6291
6293
|
return setting;
|
|
6292
6294
|
};
|
|
6293
6295
|
freeze(getEnvironmentOption);
|
|
@@ -8303,7 +8305,7 @@ const tameFunctionToString= ()=> {
|
|
|
8303
8305
|
|
|
8304
8306
|
|
|
8305
8307
|
|
|
8306
|
-
const {
|
|
8308
|
+
const { Fail, quote: q}= assert;
|
|
8307
8309
|
|
|
8308
8310
|
const localePattern= /^(\w*[a-z])Locale([A-Z]\w*)$/;
|
|
8309
8311
|
|
|
@@ -8325,7 +8327,7 @@ const tamedMethods= {
|
|
|
8325
8327
|
if( s> that) {
|
|
8326
8328
|
return 1;
|
|
8327
8329
|
}
|
|
8328
|
-
|
|
8330
|
+
s=== that|| Fail `expected ${q(s)} and ${q(that)} to compare`;
|
|
8329
8331
|
return 0;
|
|
8330
8332
|
},
|
|
8331
8333
|
|
|
@@ -8355,16 +8357,12 @@ function tameLocaleMethods(intrinsics, localeTaming= 'safe') {
|
|
|
8355
8357
|
for( const methodName of getOwnPropertyNames(intrinsic)) {
|
|
8356
8358
|
const match= regexpExec(localePattern, methodName);
|
|
8357
8359
|
if( match) {
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
d `expected ${q(methodName)} to be a function`);
|
|
8361
|
-
|
|
8360
|
+
typeof intrinsic[methodName]=== 'function'||
|
|
8361
|
+
Fail `expected ${q(methodName)} to be a function`;
|
|
8362
8362
|
const nonLocaleMethodName= `${match[1]}${match[2]}`;
|
|
8363
8363
|
const method= intrinsic[nonLocaleMethodName];
|
|
8364
|
-
|
|
8365
|
-
|
|
8366
|
-
d `function ${q(nonLocaleMethodName)} not found`);
|
|
8367
|
-
|
|
8364
|
+
typeof method=== 'function'||
|
|
8365
|
+
Fail `function ${q(nonLocaleMethodName)} not found`;
|
|
8368
8366
|
defineProperty(intrinsic, methodName, { value: method});
|
|
8369
8367
|
}
|
|
8370
8368
|
}
|
|
@@ -8836,7 +8834,7 @@ function whitelistIntrinsics(
|
|
|
8836
8834
|
|
|
8837
8835
|
/** @typedef {import('../index.js').LockdownOptions} LockdownOptions */
|
|
8838
8836
|
|
|
8839
|
-
const { details: d, quote: q}= assert;
|
|
8837
|
+
const { Fail, details: d, quote: q}= assert;
|
|
8840
8838
|
|
|
8841
8839
|
/** @type {Error=} */
|
|
8842
8840
|
let priorLockdown;
|
|
@@ -8863,7 +8861,6 @@ const harden= makeHardener();
|
|
|
8863
8861
|
* @param {Object} [options]
|
|
8864
8862
|
* @param {Array<Transform>} [options.transforms]
|
|
8865
8863
|
* @param {Array<Transform>} [options.__shimTransforms__]
|
|
8866
|
-
* @param {Object} [options.globalLexicals]
|
|
8867
8864
|
*/
|
|
8868
8865
|
|
|
8869
8866
|
// TODO https://github.com/endojs/endo/issues/814
|
|
@@ -8973,25 +8970,22 @@ const repairIntrinsics= (options= {})=> {
|
|
|
8973
8970
|
|
|
8974
8971
|
}
|
|
8975
8972
|
|
|
8976
|
-
|
|
8977
|
-
evalTaming=== '
|
|
8978
|
-
|
|
8979
|
-
|
|
8980
|
-
d `lockdown(): non supported option evalTaming: ${q(evalTaming)}`);
|
|
8981
|
-
|
|
8973
|
+
evalTaming=== 'unsafeEval'||
|
|
8974
|
+
evalTaming=== 'safeEval'||
|
|
8975
|
+
evalTaming=== 'noEval'||
|
|
8976
|
+
Fail `lockdown(): non supported option evalTaming: ${q(evalTaming)}`;
|
|
8982
8977
|
|
|
8983
8978
|
// Assert that only supported options were passed.
|
|
8984
8979
|
// Use Reflect.ownKeys to reject symbol-named properties as well.
|
|
8985
8980
|
const extraOptionsNames= ownKeys(extraOptions);
|
|
8986
|
-
|
|
8987
|
-
extraOptionsNames
|
|
8988
|
-
d `lockdown(): non supported option ${q(extraOptionsNames)}`);
|
|
8989
|
-
|
|
8981
|
+
extraOptionsNames.length=== 0||
|
|
8982
|
+
Fail `lockdown(): non supported option ${q(extraOptionsNames)}`;
|
|
8990
8983
|
|
|
8991
|
-
|
|
8992
|
-
|
|
8993
|
-
|
|
8994
|
-
|
|
8984
|
+
priorLockdown=== undefined||
|
|
8985
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
8986
|
+
assert.fail(
|
|
8987
|
+
d `Already locked down at ${priorLockdown} (SES_ALREADY_LOCKED_DOWN)`,
|
|
8988
|
+
TypeError);
|
|
8995
8989
|
|
|
8996
8990
|
priorLockdown= new TypeError('Prior lockdown (SES_ALREADY_LOCKED_DOWN)');
|
|
8997
8991
|
// Tease V8 to generate the stack string and release the closures the stack
|
|
@@ -9034,7 +9028,6 @@ const repairIntrinsics= (options= {})=> {
|
|
|
9034
9028
|
};
|
|
9035
9029
|
|
|
9036
9030
|
if( seemsToBeLockedDown()) {
|
|
9037
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
9038
9031
|
throw new TypeError(
|
|
9039
9032
|
`Already locked down but not by this SES instance (SES_MULTIPLE_INSTANCES)`);
|
|
9040
9033
|
|
|
@@ -10034,7 +10027,6 @@ assign(globalThis, {
|
|
|
10034
10027
|
observeImports(map, "./module-link.js", 21);
|
|
10035
10028
|
observeImports(map, "./module-load.js", 18);
|
|
10036
10029
|
observeImports(map, "./module-proxy.js", 19);
|
|
10037
|
-
observeImports(map, "./scope-constants.js", 6);
|
|
10038
10030
|
observeImports(map, "./whitelist.js", 16);
|
|
10039
10031
|
},
|
|
10040
10032
|
liveVar: {
|
|
@@ -10348,4 +10340,6 @@ assign(globalThis, {
|
|
|
10348
10340
|
},
|
|
10349
10341
|
importMeta: {},
|
|
10350
10342
|
});
|
|
10343
|
+
|
|
10344
|
+
return cells[cells.length - 1]['*'].get();
|
|
10351
10345
|
})();
|