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
package/dist/lockdown.mjs
CHANGED
|
@@ -567,7 +567,7 @@ freeze(bestEffortStringify);
|
|
|
567
567
|
*/
|
|
568
568
|
|
|
569
569
|
/**
|
|
570
|
-
* @typedef {
|
|
570
|
+
* @typedef {object} AssertMakeErrorOptions
|
|
571
571
|
* @property {string=} errorName
|
|
572
572
|
*/
|
|
573
573
|
|
|
@@ -614,51 +614,65 @@ freeze(bestEffortStringify);
|
|
|
614
614
|
*/
|
|
615
615
|
|
|
616
616
|
// Type all the overloads of the assertTypeof function.
|
|
617
|
-
// There may eventually be a better way to do this, but
|
|
618
|
-
// Typescript 4.0.
|
|
617
|
+
// There may eventually be a better way to do this, but
|
|
618
|
+
// thems the breaks with Typescript 4.0.
|
|
619
619
|
/**
|
|
620
620
|
* @callback AssertTypeofBigint
|
|
621
621
|
* @param {any} specimen
|
|
622
622
|
* @param {'bigint'} typename
|
|
623
623
|
* @param {Details=} optDetails
|
|
624
624
|
* @returns {asserts specimen is bigint}
|
|
625
|
-
|
|
625
|
+
*/
|
|
626
|
+
|
|
627
|
+
/**
|
|
626
628
|
* @callback AssertTypeofBoolean
|
|
627
629
|
* @param {any} specimen
|
|
628
630
|
* @param {'boolean'} typename
|
|
629
631
|
* @param {Details=} optDetails
|
|
630
632
|
* @returns {asserts specimen is boolean}
|
|
631
|
-
|
|
633
|
+
*/
|
|
634
|
+
|
|
635
|
+
/**
|
|
632
636
|
* @callback AssertTypeofFunction
|
|
633
637
|
* @param {any} specimen
|
|
634
638
|
* @param {'function'} typename
|
|
635
639
|
* @param {Details=} optDetails
|
|
636
640
|
* @returns {asserts specimen is Function}
|
|
637
|
-
|
|
641
|
+
*/
|
|
642
|
+
|
|
643
|
+
/**
|
|
638
644
|
* @callback AssertTypeofNumber
|
|
639
645
|
* @param {any} specimen
|
|
640
646
|
* @param {'number'} typename
|
|
641
647
|
* @param {Details=} optDetails
|
|
642
648
|
* @returns {asserts specimen is number}
|
|
643
|
-
|
|
649
|
+
*/
|
|
650
|
+
|
|
651
|
+
/**
|
|
644
652
|
* @callback AssertTypeofObject
|
|
645
653
|
* @param {any} specimen
|
|
646
654
|
* @param {'object'} typename
|
|
647
655
|
* @param {Details=} optDetails
|
|
648
656
|
* @returns {asserts specimen is Record<any, any> | null}
|
|
649
|
-
|
|
657
|
+
*/
|
|
658
|
+
|
|
659
|
+
/**
|
|
650
660
|
* @callback AssertTypeofString
|
|
651
661
|
* @param {any} specimen
|
|
652
662
|
* @param {'string'} typename
|
|
653
663
|
* @param {Details=} optDetails
|
|
654
664
|
* @returns {asserts specimen is string}
|
|
655
|
-
|
|
665
|
+
*/
|
|
666
|
+
|
|
667
|
+
/**
|
|
656
668
|
* @callback AssertTypeofSymbol
|
|
657
669
|
* @param {any} specimen
|
|
658
670
|
* @param {'symbol'} typename
|
|
659
671
|
* @param {Details=} optDetails
|
|
660
672
|
* @returns {asserts specimen is symbol}
|
|
661
|
-
|
|
673
|
+
*/
|
|
674
|
+
|
|
675
|
+
/**
|
|
662
676
|
* @callback AssertTypeofUndefined
|
|
663
677
|
* @param {any} specimen
|
|
664
678
|
* @param {'undefined'} typename
|
|
@@ -712,7 +726,7 @@ freeze(bestEffortStringify);
|
|
|
712
726
|
*/
|
|
713
727
|
|
|
714
728
|
/**
|
|
715
|
-
* @typedef {
|
|
729
|
+
* @typedef {object} StringablePayload
|
|
716
730
|
* Holds the payload passed to quote so that its printed form is visible.
|
|
717
731
|
* @property {() => string} toString How to print the payload
|
|
718
732
|
*/
|
|
@@ -815,6 +829,64 @@ freeze(bestEffortStringify);
|
|
|
815
829
|
* `string[]` can also be used as a template.
|
|
816
830
|
*/
|
|
817
831
|
|
|
832
|
+
/**
|
|
833
|
+
* @typedef {(template: TemplateStringsArray | string[], ...args: any) => never} FailTag
|
|
834
|
+
* The `Fail` tamplate tag supports replacing patterns like
|
|
835
|
+
* ```js
|
|
836
|
+
* assert(cond, X`...complaint...`);
|
|
837
|
+
* ```
|
|
838
|
+
* or
|
|
839
|
+
* ```js
|
|
840
|
+
* cond || assert.fail(X`...complaint...`);
|
|
841
|
+
* ```
|
|
842
|
+
* with patterns like
|
|
843
|
+
* ```js
|
|
844
|
+
* cond || Fail`...complaint...`;
|
|
845
|
+
* ```
|
|
846
|
+
*
|
|
847
|
+
* However, due to [weakness in current
|
|
848
|
+
* TypeScript](https://github.com/microsoft/TypeScript/issues/51426), the `||`
|
|
849
|
+
* patterns are not as powerful as the `assert(...)` call at enabling static
|
|
850
|
+
* reasoning. Of the `||`, again due to weaknesses in current TypeScript,
|
|
851
|
+
* the
|
|
852
|
+
* ```js
|
|
853
|
+
* cond || Fail`...complaint...`
|
|
854
|
+
* ```
|
|
855
|
+
* pattern is not as powerful as the
|
|
856
|
+
* ```js
|
|
857
|
+
* cond || assert.fail(X`...complaint...`);
|
|
858
|
+
* ```
|
|
859
|
+
* at enabling static resoning. Despite these problems, we do not want to
|
|
860
|
+
* return to the
|
|
861
|
+
* ```js
|
|
862
|
+
* assert(cond, X`...complaint...`)
|
|
863
|
+
* ```
|
|
864
|
+
* style because of the substantial overhead in
|
|
865
|
+
* evaluating the `X` template in the typical `true` case where it is not
|
|
866
|
+
* needed. And we do not want to return to the
|
|
867
|
+
* ```js
|
|
868
|
+
* assert.fail(X`...complaint...`)`
|
|
869
|
+
* ```
|
|
870
|
+
* because of the verbosity and loss of readability. Instead, until/unless
|
|
871
|
+
* https://github.com/microsoft/TypeScript/issues/51426 is fixed, for those
|
|
872
|
+
* new-style assertions where this loss of static reasoning is a problem,
|
|
873
|
+
* instead express the assertion as
|
|
874
|
+
* ```js
|
|
875
|
+
* if (!cond) {
|
|
876
|
+
* Fail`...complaint...`;
|
|
877
|
+
* }
|
|
878
|
+
* ```
|
|
879
|
+
* or, if needed,
|
|
880
|
+
* ```js
|
|
881
|
+
* if (!cond) {
|
|
882
|
+
* // `throw` is noop since `Fail` throws. But linter confused
|
|
883
|
+
* throw Fail`...complaint...`;
|
|
884
|
+
* }
|
|
885
|
+
* ```
|
|
886
|
+
* This avoid the TypeScript bugs that cause the loss of static reasoning,
|
|
887
|
+
* but with no loss of efficiency and little loss of readability.
|
|
888
|
+
*/
|
|
889
|
+
|
|
818
890
|
/**
|
|
819
891
|
* assert that expr is truthy, with an optional details to describe
|
|
820
892
|
* the assertion. It is a tagged template literal like
|
|
@@ -841,6 +913,7 @@ freeze(bestEffortStringify);
|
|
|
841
913
|
* string: AssertString,
|
|
842
914
|
* note: AssertNote,
|
|
843
915
|
* details: DetailsTag,
|
|
916
|
+
* Fail: FailTag,
|
|
844
917
|
* quote: AssertQuote,
|
|
845
918
|
* makeAssert: MakeAssert,
|
|
846
919
|
* } } Assert
|
|
@@ -1283,6 +1356,9 @@ const makeAssert= (optRaise= undefined, unredacted= false)=> {
|
|
|
1283
1356
|
};
|
|
1284
1357
|
freeze(fail);
|
|
1285
1358
|
|
|
1359
|
+
/** @type {FailTag} */
|
|
1360
|
+
const Fail= (template, ...args)=> fail(details(template, ...args));
|
|
1361
|
+
|
|
1286
1362
|
// Don't freeze or export `baseAssert` until we add methods.
|
|
1287
1363
|
// TODO If I change this from a `function` function to an arrow
|
|
1288
1364
|
// function, I seem to get type errors from TypeScript. Why?
|
|
@@ -1341,6 +1417,7 @@ const makeAssert= (optRaise= undefined, unredacted= false)=> {
|
|
|
1341
1417
|
string: assertString,
|
|
1342
1418
|
note,
|
|
1343
1419
|
details,
|
|
1420
|
+
Fail,
|
|
1344
1421
|
quote,
|
|
1345
1422
|
makeAssert});
|
|
1346
1423
|
|
|
@@ -1358,7 +1435,7 @@ const assert= makeAssert();$h_once.assert(assert);
|
|
|
1358
1435
|
|
|
1359
1436
|
|
|
1360
1437
|
|
|
1361
|
-
const {
|
|
1438
|
+
const { Fail}= assert;
|
|
1362
1439
|
|
|
1363
1440
|
// We attempt to frustrate stack bumping attacks on the safe evaluator
|
|
1364
1441
|
// (`make-safe-evaluator.js`).
|
|
@@ -1429,10 +1506,7 @@ const makeEvalScopeKit= ()=> {
|
|
|
1429
1506
|
evalScope,
|
|
1430
1507
|
allowNextEvalToBeUnsafe() {
|
|
1431
1508
|
if( evalScopeKit.revoked!== null) {
|
|
1432
|
-
|
|
1433
|
-
assert.fail(
|
|
1434
|
-
d `a handler did not reset allowNextEvalToBeUnsafe ${this.revoked.err}`);
|
|
1435
|
-
|
|
1509
|
+
Fail `a handler did not reset allowNextEvalToBeUnsafe ${this.revoked.err}`;
|
|
1436
1510
|
}
|
|
1437
1511
|
// Allow next reference to eval produce the unsafe FERAL_EVAL.
|
|
1438
1512
|
// We avoid defineProperty because it consumes an extra stack frame taming
|
|
@@ -1593,20 +1667,20 @@ function isImmutableDataProperty(obj, name) {
|
|
|
1593
1667
|
* safe and only prevent performance optimization.
|
|
1594
1668
|
*
|
|
1595
1669
|
* @param {Object} globalObject
|
|
1596
|
-
* @param {Object}
|
|
1670
|
+
* @param {Object} moduleLexicals
|
|
1597
1671
|
*/
|
|
1598
|
-
const getScopeConstants= (globalObject,
|
|
1672
|
+
const getScopeConstants= (globalObject, moduleLexicals= {})=> {
|
|
1599
1673
|
// getOwnPropertyNames() does ignore Symbols so we don't need to
|
|
1600
1674
|
// filter them out.
|
|
1601
1675
|
const globalObjectNames= getOwnPropertyNames(globalObject);
|
|
1602
|
-
const
|
|
1676
|
+
const moduleLexicalNames= getOwnPropertyNames(moduleLexicals);
|
|
1603
1677
|
|
|
1604
1678
|
// Collect all valid & immutable identifiers from the endowments.
|
|
1605
|
-
const
|
|
1606
|
-
|
|
1679
|
+
const moduleLexicalConstants= arrayFilter(
|
|
1680
|
+
moduleLexicalNames,
|
|
1607
1681
|
(name)=>
|
|
1608
1682
|
isValidIdentifierName(name)&&
|
|
1609
|
-
isImmutableDataProperty(
|
|
1683
|
+
isImmutableDataProperty(moduleLexicals, name));
|
|
1610
1684
|
|
|
1611
1685
|
|
|
1612
1686
|
// Collect all valid & immutable identifiers from the global that
|
|
@@ -1616,14 +1690,14 @@ const getScopeConstants= (globalObject, globalLexicals= {})=> {
|
|
|
1616
1690
|
(name)=>
|
|
1617
1691
|
// Can't define a constant: it would prevent a
|
|
1618
1692
|
// lookup on the endowments.
|
|
1619
|
-
!arrayIncludes(
|
|
1693
|
+
!arrayIncludes(moduleLexicalNames, name)&&
|
|
1620
1694
|
isValidIdentifierName(name)&&
|
|
1621
1695
|
isImmutableDataProperty(globalObject, name));
|
|
1622
1696
|
|
|
1623
1697
|
|
|
1624
1698
|
return {
|
|
1625
1699
|
globalObjectConstants,
|
|
1626
|
-
|
|
1700
|
+
moduleLexicalConstants};
|
|
1627
1701
|
|
|
1628
1702
|
};$h_once.getScopeConstants(getScopeConstants);
|
|
1629
1703
|
})
|
|
@@ -1657,22 +1731,22 @@ function buildOptimizer(constants, name) {
|
|
|
1657
1731
|
*
|
|
1658
1732
|
* @param {object} context
|
|
1659
1733
|
* @param {object} context.evalScope
|
|
1660
|
-
* @param {object} context.
|
|
1734
|
+
* @param {object} context.moduleLexicals
|
|
1661
1735
|
* @param {object} context.globalObject
|
|
1662
1736
|
* @param {object} context.scopeTerminator
|
|
1663
1737
|
*/
|
|
1664
1738
|
const makeEvaluate= (context)=>{
|
|
1665
|
-
const { globalObjectConstants,
|
|
1739
|
+
const { globalObjectConstants, moduleLexicalConstants}= getScopeConstants(
|
|
1666
1740
|
context.globalObject,
|
|
1667
|
-
context.
|
|
1741
|
+
context.moduleLexicals);
|
|
1668
1742
|
|
|
1669
1743
|
const globalObjectOptimizer= buildOptimizer(
|
|
1670
1744
|
globalObjectConstants,
|
|
1671
1745
|
'globalObject');
|
|
1672
1746
|
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
'
|
|
1747
|
+
const moduleLexicalOptimizer= buildOptimizer(
|
|
1748
|
+
moduleLexicalConstants,
|
|
1749
|
+
'moduleLexicals');
|
|
1676
1750
|
|
|
1677
1751
|
|
|
1678
1752
|
// Create a function in sloppy mode, so that we can use 'with'. It returns
|
|
@@ -1688,7 +1762,7 @@ const makeEvaluate= (context)=>{
|
|
|
1688
1762
|
// trigger direct eval. The direct eval semantics is what allows the
|
|
1689
1763
|
// evaluated code to lookup free variable names on the other scope
|
|
1690
1764
|
// objects and not in global scope.
|
|
1691
|
-
// b) `
|
|
1765
|
+
// b) `moduleLexicals` which provide a way to introduce free variables
|
|
1692
1766
|
// that are not available on the globalObject.
|
|
1693
1767
|
// c) `globalObject` is the global scope object of the evaluator, aka the
|
|
1694
1768
|
// Compartment's `globalThis`.
|
|
@@ -1702,7 +1776,7 @@ const makeEvaluate= (context)=>{
|
|
|
1702
1776
|
|
|
1703
1777
|
// Notes:
|
|
1704
1778
|
// - The `optimizer` strings only lookup values on the `globalObject` and
|
|
1705
|
-
// `
|
|
1779
|
+
// `moduleLexicals` objects by construct. Keywords like 'function' are
|
|
1706
1780
|
// reserved and cannot be used as a variable, so they are excluded from the
|
|
1707
1781
|
// optimizer. Furthermore to prevent shadowing 'eval', while a valid
|
|
1708
1782
|
// identifier, that name is also explicitly excluded.
|
|
@@ -1723,10 +1797,10 @@ const makeEvaluate= (context)=>{
|
|
|
1723
1797
|
const evaluateFactory= FERAL_FUNCTION( `
|
|
1724
1798
|
with (this.scopeTerminator) {
|
|
1725
1799
|
with (this.globalObject) {
|
|
1726
|
-
with (this.
|
|
1800
|
+
with (this.moduleLexicals) {
|
|
1727
1801
|
with (this.evalScope) {
|
|
1728
1802
|
${globalObjectOptimizer }
|
|
1729
|
-
${
|
|
1803
|
+
${moduleLexicalOptimizer }
|
|
1730
1804
|
return function() {
|
|
1731
1805
|
'use strict';
|
|
1732
1806
|
return eval(arguments[0]);
|
|
@@ -1755,7 +1829,7 @@ const makeEvaluate= (context)=>{
|
|
|
1755
1829
|
|
|
1756
1830
|
|
|
1757
1831
|
|
|
1758
|
-
const {
|
|
1832
|
+
const { Fail, quote: q}= assert;
|
|
1759
1833
|
|
|
1760
1834
|
/**
|
|
1761
1835
|
* alwaysThrowHandler
|
|
@@ -1768,10 +1842,7 @@ const alwaysThrowHandler= new Proxy(
|
|
|
1768
1842
|
immutableObject,
|
|
1769
1843
|
freeze({
|
|
1770
1844
|
get(_shadow, prop) {
|
|
1771
|
-
|
|
1772
|
-
assert.fail(
|
|
1773
|
-
d `Please report unexpected scope handler trap: ${q(String(prop))}`);
|
|
1774
|
-
|
|
1845
|
+
Fail `Please report unexpected scope handler trap: ${q(String(prop))}`;
|
|
1775
1846
|
}}));
|
|
1776
1847
|
|
|
1777
1848
|
|
|
@@ -2206,7 +2277,7 @@ const applyTransforms= (source, transforms)=> {
|
|
|
2206
2277
|
|
|
2207
2278
|
|
|
2208
2279
|
|
|
2209
|
-
const {
|
|
2280
|
+
const { Fail}= assert;
|
|
2210
2281
|
|
|
2211
2282
|
/**
|
|
2212
2283
|
* makeSafeEvaluator()
|
|
@@ -2215,13 +2286,13 @@ const { details: d}= assert;
|
|
|
2215
2286
|
*
|
|
2216
2287
|
* @param {Object} options
|
|
2217
2288
|
* @param {Object} options.globalObject
|
|
2218
|
-
* @param {Object} [options.
|
|
2289
|
+
* @param {Object} [options.moduleLexicals]
|
|
2219
2290
|
* @param {Array<Transform>} [options.globalTransforms]
|
|
2220
2291
|
* @param {bool} [options.sloppyGlobalsMode]
|
|
2221
2292
|
*/
|
|
2222
2293
|
const makeSafeEvaluator= ({
|
|
2223
2294
|
globalObject,
|
|
2224
|
-
|
|
2295
|
+
moduleLexicals= {},
|
|
2225
2296
|
globalTransforms= [],
|
|
2226
2297
|
sloppyGlobalsMode= false}=
|
|
2227
2298
|
{})=> {
|
|
@@ -2233,7 +2304,7 @@ const makeSafeEvaluator= ({
|
|
|
2233
2304
|
|
|
2234
2305
|
const evaluateContext= freeze({
|
|
2235
2306
|
evalScope,
|
|
2236
|
-
|
|
2307
|
+
moduleLexicals,
|
|
2237
2308
|
globalObject,
|
|
2238
2309
|
scopeTerminator});
|
|
2239
2310
|
|
|
@@ -2297,8 +2368,7 @@ const makeSafeEvaluator= ({
|
|
|
2297
2368
|
evalScopeKit.revoked= { err};
|
|
2298
2369
|
// TODO A GOOD PLACE TO PANIC(), i.e., kill the vat incarnation.
|
|
2299
2370
|
// See https://github.com/Agoric/SES-shim/issues/490
|
|
2300
|
-
|
|
2301
|
-
assert.fail(d `handler did not reset allowNextEvalToBeUnsafe ${err}`);
|
|
2371
|
+
Fail `handler did not reset allowNextEvalToBeUnsafe ${err}`;
|
|
2302
2372
|
}
|
|
2303
2373
|
}
|
|
2304
2374
|
};
|
|
@@ -2308,8 +2378,7 @@ const makeSafeEvaluator= ({
|
|
|
2308
2378
|
})
|
|
2309
2379
|
,
|
|
2310
2380
|
// === functors[13] ===
|
|
2311
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let TypeError,arrayPush,create,
|
|
2312
|
-
|
|
2381
|
+
(({ 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
2382
|
|
|
2314
2383
|
|
|
2315
2384
|
|
|
@@ -2324,10 +2393,8 @@ const makeSafeEvaluator= ({
|
|
|
2324
2393
|
|
|
2325
2394
|
|
|
2326
2395
|
const provideCompartmentEvaluator= (compartmentFields, options)=> {
|
|
2327
|
-
const {
|
|
2328
|
-
|
|
2329
|
-
__moduleShimLexicals__= undefined}=
|
|
2330
|
-
options;
|
|
2396
|
+
const { sloppyGlobalsMode= false, __moduleShimLexicals__= undefined}=
|
|
2397
|
+
options;
|
|
2331
2398
|
|
|
2332
2399
|
let safeEvaluate;
|
|
2333
2400
|
|
|
@@ -2338,9 +2405,9 @@ const provideCompartmentEvaluator= (compartmentFields, options)=> {
|
|
|
2338
2405
|
// shared evaluator so we need to build a new one
|
|
2339
2406
|
|
|
2340
2407
|
let { globalTransforms}= compartmentFields;
|
|
2341
|
-
const { globalObject
|
|
2408
|
+
const { globalObject}= compartmentFields;
|
|
2342
2409
|
|
|
2343
|
-
let
|
|
2410
|
+
let moduleLexicals;
|
|
2344
2411
|
if( __moduleShimLexicals__!== undefined) {
|
|
2345
2412
|
// When using `evaluate` for ESM modules, as should only occur from the
|
|
2346
2413
|
// module-shim's module-instance.js, we do not reveal the SES-shim's
|
|
@@ -2352,16 +2419,15 @@ const provideCompartmentEvaluator= (compartmentFields, options)=> {
|
|
|
2352
2419
|
// and `import`, at the expense of being tightly coupled to SES-shim.
|
|
2353
2420
|
globalTransforms= undefined;
|
|
2354
2421
|
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
localObject,
|
|
2422
|
+
moduleLexicals= create(
|
|
2423
|
+
null,
|
|
2358
2424
|
getOwnPropertyDescriptors(__moduleShimLexicals__));
|
|
2359
2425
|
|
|
2360
2426
|
}
|
|
2361
2427
|
|
|
2362
2428
|
({ safeEvaluate}= makeSafeEvaluator({
|
|
2363
2429
|
globalObject,
|
|
2364
|
-
|
|
2430
|
+
moduleLexicals,
|
|
2365
2431
|
globalTransforms,
|
|
2366
2432
|
sloppyGlobalsMode}));
|
|
2367
2433
|
|
|
@@ -2447,6 +2513,8 @@ const makeEvalFunction= (safeEvaluate)=>{
|
|
|
2447
2513
|
|
|
2448
2514
|
|
|
2449
2515
|
|
|
2516
|
+
const { Fail}= assert;
|
|
2517
|
+
|
|
2450
2518
|
/*
|
|
2451
2519
|
* makeFunctionConstructor()
|
|
2452
2520
|
* A safe version of the native Function which relies on
|
|
@@ -2507,14 +2575,10 @@ const makeFunctionConstructor= (safeEvaluate)=>{
|
|
|
2507
2575
|
|
|
2508
2576
|
|
|
2509
2577
|
// 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
|
-
|
|
2578
|
+
getPrototypeOf(FERAL_FUNCTION)=== FERAL_FUNCTION.prototype||
|
|
2579
|
+
Fail `Function prototype is the same accross compartments`;
|
|
2580
|
+
getPrototypeOf(newFunction)=== FERAL_FUNCTION.prototype||
|
|
2581
|
+
Fail `Function constructor prototype is the same accross compartments`;
|
|
2518
2582
|
|
|
2519
2583
|
return newFunction;
|
|
2520
2584
|
};$h_once.makeFunctionConstructor(makeFunctionConstructor);
|
|
@@ -4096,7 +4160,7 @@ const setGlobalObjectEvaluators= (
|
|
|
4096
4160
|
|
|
4097
4161
|
|
|
4098
4162
|
|
|
4099
|
-
const { details: d, quote: q}= assert;
|
|
4163
|
+
const { Fail, details: d, quote: q}= assert;
|
|
4100
4164
|
|
|
4101
4165
|
const noop= ()=> { };
|
|
4102
4166
|
|
|
@@ -4123,7 +4187,7 @@ $h_once.makeAlias(makeAlias);const resolveAll=(imports,resolveHook,fullReferr
|
|
|
4123
4187
|
return freeze(resolvedImports);
|
|
4124
4188
|
};
|
|
4125
4189
|
|
|
4126
|
-
const loadRecord=
|
|
4190
|
+
const loadRecord= (
|
|
4127
4191
|
compartmentPrivateFields,
|
|
4128
4192
|
moduleAliases,
|
|
4129
4193
|
compartment,
|
|
@@ -4239,35 +4303,69 @@ const loadWithoutErrorAnnotation= async(
|
|
|
4239
4303
|
const staticModuleRecord= await importHook(moduleSpecifier);
|
|
4240
4304
|
|
|
4241
4305
|
if( staticModuleRecord=== null|| typeof staticModuleRecord!== 'object') {
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
moduleSpecifier)
|
|
4246
|
-
} in compartment ${q(compartment.name)}`);
|
|
4247
|
-
|
|
4306
|
+
Fail `importHook must return a promise for an object, for module ${q(
|
|
4307
|
+
moduleSpecifier)
|
|
4308
|
+
} in compartment ${q(compartment.name)}`;
|
|
4248
4309
|
}
|
|
4249
4310
|
|
|
4250
|
-
if
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
record
|
|
4255
|
-
|
|
4256
|
-
|
|
4311
|
+
// check if record is a RedirectStaticModuleInterface
|
|
4312
|
+
if( staticModuleRecord.specifier!== undefined) {
|
|
4313
|
+
// check if this redirect with an explicit record
|
|
4314
|
+
if( staticModuleRecord.record!== undefined) {
|
|
4315
|
+
// ensure expected record shape
|
|
4316
|
+
if( staticModuleRecord.compartment!== undefined) {
|
|
4317
|
+
throw new TypeError(
|
|
4318
|
+
'Cannot redirect to an explicit record with a specified compartment');
|
|
4257
4319
|
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4320
|
+
}
|
|
4321
|
+
const {
|
|
4322
|
+
compartment: aliasCompartment= compartment,
|
|
4323
|
+
specifier: aliasSpecifier= moduleSpecifier,
|
|
4324
|
+
record: aliasModuleRecord,
|
|
4325
|
+
importMeta}=
|
|
4326
|
+
staticModuleRecord;
|
|
4327
|
+
|
|
4328
|
+
const aliasRecord= loadRecord(
|
|
4329
|
+
compartmentPrivateFields,
|
|
4330
|
+
moduleAliases,
|
|
4331
|
+
aliasCompartment,
|
|
4332
|
+
aliasSpecifier,
|
|
4333
|
+
aliasModuleRecord,
|
|
4334
|
+
pendingJobs,
|
|
4335
|
+
moduleLoads,
|
|
4336
|
+
errors,
|
|
4337
|
+
importMeta);
|
|
4338
|
+
|
|
4339
|
+
mapSet(moduleRecords, moduleSpecifier, aliasRecord);
|
|
4340
|
+
return aliasRecord;
|
|
4341
|
+
}
|
|
4342
|
+
|
|
4343
|
+
// check if this redirect with an explicit compartment
|
|
4344
|
+
if( staticModuleRecord.compartment!== undefined) {
|
|
4345
|
+
// ensure expected record shape
|
|
4346
|
+
if( staticModuleRecord.importMeta!== undefined) {
|
|
4347
|
+
throw new TypeError(
|
|
4348
|
+
'Cannot redirect to an implicit record with a specified importMeta');
|
|
4349
|
+
|
|
4350
|
+
}
|
|
4351
|
+
// Behold: recursion.
|
|
4352
|
+
// eslint-disable-next-line no-use-before-define
|
|
4353
|
+
const aliasRecord= await memoizedLoadWithErrorAnnotation(
|
|
4354
|
+
compartmentPrivateFields,
|
|
4355
|
+
moduleAliases,
|
|
4356
|
+
staticModuleRecord.compartment,
|
|
4357
|
+
staticModuleRecord.specifier,
|
|
4358
|
+
pendingJobs,
|
|
4359
|
+
moduleLoads,
|
|
4360
|
+
errors);
|
|
4361
|
+
|
|
4362
|
+
mapSet(moduleRecords, moduleSpecifier, aliasRecord);
|
|
4363
|
+
return aliasRecord;
|
|
4364
|
+
}
|
|
4365
|
+
|
|
4366
|
+
throw new TypeError(
|
|
4367
|
+
'Unnexpected RedirectStaticModuleInterface record shape');
|
|
4268
4368
|
|
|
4269
|
-
mapSet(moduleRecords, moduleSpecifier, aliasRecord);
|
|
4270
|
-
return aliasRecord;
|
|
4271
4369
|
}
|
|
4272
4370
|
|
|
4273
4371
|
return loadRecord(
|
|
@@ -4710,6 +4808,7 @@ $h_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
|
|
|
4710
4808
|
__syncModuleProgram__: functorSource,
|
|
4711
4809
|
__fixedExportMap__: fixedExportMap= {},
|
|
4712
4810
|
__liveExportMap__: liveExportMap= {},
|
|
4811
|
+
__reexportMap__: reexportMap= {},
|
|
4713
4812
|
__needsImportMeta__: needsImportMeta= false}=
|
|
4714
4813
|
staticModuleRecord;
|
|
4715
4814
|
|
|
@@ -4728,10 +4827,10 @@ $h_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
|
|
|
4728
4827
|
// object (eventually proxied).
|
|
4729
4828
|
const exportsProps= create(null);
|
|
4730
4829
|
|
|
4731
|
-
// {_localName_: accessor} proxy traps for
|
|
4732
|
-
// The
|
|
4733
|
-
//
|
|
4734
|
-
const
|
|
4830
|
+
// {_localName_: accessor} proxy traps for moduleLexicals and live bindings.
|
|
4831
|
+
// The moduleLexicals object is frozen and the corresponding properties of
|
|
4832
|
+
// moduleLexicals must be immutable, so we copy the descriptors.
|
|
4833
|
+
const moduleLexicals= create(null);
|
|
4735
4834
|
|
|
4736
4835
|
// {_localName_: init(initValue) -> initValue} used by the
|
|
4737
4836
|
// rewritten code to initialize exported fixed bindings.
|
|
@@ -4897,7 +4996,7 @@ $h_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
|
|
|
4897
4996
|
|
|
4898
4997
|
localGetNotify[localName]= liveGetNotify;
|
|
4899
4998
|
if( setProxyTrap) {
|
|
4900
|
-
defineProperty(
|
|
4999
|
+
defineProperty(moduleLexicals, localName, {
|
|
4901
5000
|
get,
|
|
4902
5001
|
set,
|
|
4903
5002
|
enumerable: true,
|
|
@@ -4963,26 +5062,35 @@ $h_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
|
|
|
4963
5062
|
}
|
|
4964
5063
|
if( arrayIncludes(exportAlls, specifier)) {
|
|
4965
5064
|
// Make all these imports candidates.
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
5065
|
+
// Note names don't change in reexporting all
|
|
5066
|
+
for( const [importAndExportName, importNotify]of entries(
|
|
5067
|
+
importNotifiers))
|
|
5068
|
+
{
|
|
5069
|
+
if( candidateAll[importAndExportName]=== undefined) {
|
|
5070
|
+
candidateAll[importAndExportName]= importNotify;
|
|
4969
5071
|
}else {
|
|
4970
5072
|
// Already a candidate: remove ambiguity.
|
|
4971
|
-
candidateAll[
|
|
5073
|
+
candidateAll[importAndExportName]= false;
|
|
4972
5074
|
}
|
|
4973
5075
|
}
|
|
4974
5076
|
}
|
|
5077
|
+
if( reexportMap[specifier]) {
|
|
5078
|
+
// Make named reexports candidates too.
|
|
5079
|
+
for( const [localName, exportedName]of reexportMap[specifier]) {
|
|
5080
|
+
candidateAll[exportedName]= importNotifiers[localName];
|
|
5081
|
+
}
|
|
5082
|
+
}
|
|
4975
5083
|
}
|
|
4976
5084
|
|
|
4977
|
-
for( const [
|
|
4978
|
-
if( !notifiers[
|
|
4979
|
-
notifiers[
|
|
5085
|
+
for( const [exportName, notify]of entries(candidateAll)) {
|
|
5086
|
+
if( !notifiers[exportName]&& notify!== false) {
|
|
5087
|
+
notifiers[exportName]= notify;
|
|
4980
5088
|
|
|
4981
5089
|
// exported live binding state
|
|
4982
5090
|
let value;
|
|
4983
5091
|
const update= (newValue)=> value= newValue;
|
|
4984
5092
|
notify(update);
|
|
4985
|
-
exportsProps[
|
|
5093
|
+
exportsProps[exportName]= {
|
|
4986
5094
|
get() {
|
|
4987
5095
|
return value;
|
|
4988
5096
|
},
|
|
@@ -5013,7 +5121,7 @@ $h_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
|
|
|
5013
5121
|
let optFunctor= compartmentEvaluate(compartmentFields, functorSource, {
|
|
5014
5122
|
globalObject: compartment.globalThis,
|
|
5015
5123
|
transforms: __shimTransforms__,
|
|
5016
|
-
__moduleShimLexicals__:
|
|
5124
|
+
__moduleShimLexicals__: moduleLexicals});
|
|
5017
5125
|
|
|
5018
5126
|
let didThrow= false;
|
|
5019
5127
|
let thrownError;
|
|
@@ -5080,7 +5188,7 @@ $h_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
|
|
|
5080
5188
|
|
|
5081
5189
|
|
|
5082
5190
|
|
|
5083
|
-
const { quote: q}= assert;
|
|
5191
|
+
const { Fail, quote: q}= assert;
|
|
5084
5192
|
|
|
5085
5193
|
// `link` creates `ModuleInstances` and `ModuleNamespaces` for a module and its
|
|
5086
5194
|
// transitive dependencies and connects their imports and exports.
|
|
@@ -5124,18 +5232,14 @@ function validatePrecompiledStaticModuleRecord(
|
|
|
5124
5232
|
moduleSpecifier)
|
|
5125
5233
|
{
|
|
5126
5234
|
const { __fixedExportMap__, __liveExportMap__}= staticModuleRecord;
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
`Property '__fixedExportMap__' of a precompiled module record must be an object, got ${q(
|
|
5235
|
+
isObject(__fixedExportMap__)||
|
|
5236
|
+
Fail `Property '__fixedExportMap__' of a precompiled module record must be an object, got ${q(
|
|
5130
5237
|
__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(
|
|
5238
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5239
|
+
isObject(__liveExportMap__)||
|
|
5240
|
+
Fail `Property '__liveExportMap__' of a precompiled module record must be an object, got ${q(
|
|
5136
5241
|
__liveExportMap__)
|
|
5137
|
-
}, for module ${q(moduleSpecifier)}
|
|
5138
|
-
|
|
5242
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5139
5243
|
}
|
|
5140
5244
|
|
|
5141
5245
|
function isThirdParty(staticModuleRecord) {
|
|
@@ -5147,40 +5251,30 @@ function validateThirdPartyStaticModuleRecord(
|
|
|
5147
5251
|
moduleSpecifier)
|
|
5148
5252
|
{
|
|
5149
5253
|
const { exports}= staticModuleRecord;
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
`Property 'exports' of a third-party static module record must be an array, got ${q(
|
|
5254
|
+
isArray(exports)||
|
|
5255
|
+
Fail `Property 'exports' of a third-party static module record must be an array, got ${q(
|
|
5153
5256
|
exports)
|
|
5154
|
-
}, for module ${q(moduleSpecifier)}
|
|
5155
|
-
|
|
5257
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5156
5258
|
}
|
|
5157
5259
|
|
|
5158
5260
|
function validateStaticModuleRecord(staticModuleRecord, moduleSpecifier) {
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
`Static module records must be of type object, got ${q(
|
|
5261
|
+
isObject(staticModuleRecord)||
|
|
5262
|
+
Fail `Static module records must be of type object, got ${q(
|
|
5162
5263
|
staticModuleRecord)
|
|
5163
|
-
}, for module ${q(moduleSpecifier)}
|
|
5164
|
-
|
|
5264
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5165
5265
|
const { imports, exports, reexports= []}= staticModuleRecord;
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
`Property 'imports' of a static module record must be an array, got ${q(
|
|
5266
|
+
isArray(imports)||
|
|
5267
|
+
Fail `Property 'imports' of a static module record must be an array, got ${q(
|
|
5169
5268
|
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(
|
|
5269
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5270
|
+
isArray(exports)||
|
|
5271
|
+
Fail `Property 'exports' of a precompiled module record must be an array, got ${q(
|
|
5175
5272
|
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(
|
|
5273
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5274
|
+
isArray(reexports)||
|
|
5275
|
+
Fail `Property 'reexports' of a precompiled module record must be an array if present, got ${q(
|
|
5181
5276
|
reexports)
|
|
5182
|
-
}, for module ${q(moduleSpecifier)}
|
|
5183
|
-
|
|
5277
|
+
}, for module ${q(moduleSpecifier)}`;
|
|
5184
5278
|
}
|
|
5185
5279
|
|
|
5186
5280
|
const instantiate= (
|
|
@@ -5188,12 +5282,8 @@ const instantiate= (
|
|
|
5188
5282
|
moduleAliases,
|
|
5189
5283
|
moduleRecord)=>
|
|
5190
5284
|
{
|
|
5191
|
-
const {
|
|
5192
|
-
|
|
5193
|
-
moduleSpecifier,
|
|
5194
|
-
resolvedImports,
|
|
5195
|
-
staticModuleRecord}=
|
|
5196
|
-
moduleRecord;
|
|
5285
|
+
const { compartment, moduleSpecifier, resolvedImports, staticModuleRecord}=
|
|
5286
|
+
moduleRecord;
|
|
5197
5287
|
const { instances}= weakmapGet(compartmentPrivateFields, compartment);
|
|
5198
5288
|
|
|
5199
5289
|
// Memoize.
|
|
@@ -5250,12 +5340,7 @@ const instantiate= (
|
|
|
5250
5340
|
})
|
|
5251
5341
|
,
|
|
5252
5342
|
// === 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
|
-
|
|
5343
|
+
(({ 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
5344
|
|
|
5260
5345
|
|
|
5261
5346
|
|
|
@@ -5459,7 +5544,6 @@ const makeCompartmentConstructor= (
|
|
|
5459
5544
|
name= '<unknown>',
|
|
5460
5545
|
transforms= [],
|
|
5461
5546
|
__shimTransforms__= [],
|
|
5462
|
-
globalLexicals: globalLexicalsOption= {},
|
|
5463
5547
|
resolveHook,
|
|
5464
5548
|
importHook,
|
|
5465
5549
|
moduleMapHook,
|
|
@@ -5498,28 +5582,6 @@ const makeCompartmentConstructor= (
|
|
|
5498
5582
|
}
|
|
5499
5583
|
}
|
|
5500
5584
|
|
|
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
5585
|
const globalObject= {};
|
|
5524
5586
|
|
|
5525
5587
|
setGlobalObjectSymbolUnscopables(globalObject);
|
|
@@ -5533,7 +5595,6 @@ const makeCompartmentConstructor= (
|
|
|
5533
5595
|
|
|
5534
5596
|
const { safeEvaluate}= makeSafeEvaluator({
|
|
5535
5597
|
globalObject,
|
|
5536
|
-
globalLexicals,
|
|
5537
5598
|
globalTransforms,
|
|
5538
5599
|
sloppyGlobalsMode: false});
|
|
5539
5600
|
|
|
@@ -5558,7 +5619,6 @@ const makeCompartmentConstructor= (
|
|
|
5558
5619
|
name: `${name}`,
|
|
5559
5620
|
globalTransforms,
|
|
5560
5621
|
globalObject,
|
|
5561
|
-
globalLexicals,
|
|
5562
5622
|
safeEvaluate,
|
|
5563
5623
|
resolveHook,
|
|
5564
5624
|
importHook,
|
|
@@ -6178,7 +6238,7 @@ function enablePropertyOverrides(
|
|
|
6178
6238
|
|
|
6179
6239
|
|
|
6180
6240
|
|
|
6181
|
-
const { details: X, quote: q}= assert;
|
|
6241
|
+
const { details: X, Fail, quote: q}= assert;
|
|
6182
6242
|
|
|
6183
6243
|
/**
|
|
6184
6244
|
* JavaScript module semantics resists attempts to parameterize a module's
|
|
@@ -6282,12 +6342,9 @@ const makeEnvironmentCaptor= (aGlobal)=>{
|
|
|
6282
6342
|
}
|
|
6283
6343
|
setting=== undefined||
|
|
6284
6344
|
typeof setting=== 'string'||
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
setting)
|
|
6289
|
-
}, if present, must be a string.`);
|
|
6290
|
-
|
|
6345
|
+
Fail `Environment option value ${q(
|
|
6346
|
+
setting)
|
|
6347
|
+
}, if present, must be a string.`;
|
|
6291
6348
|
return setting;
|
|
6292
6349
|
};
|
|
6293
6350
|
freeze(getEnvironmentOption);
|
|
@@ -6479,12 +6536,8 @@ freeze(ErrorInfo);
|
|
|
6479
6536
|
|
|
6480
6537
|
/** @type {MakeCausalConsole} */
|
|
6481
6538
|
const makeCausalConsole= (baseConsole, loggedErrorHandler)=> {
|
|
6482
|
-
const {
|
|
6483
|
-
|
|
6484
|
-
tagError,
|
|
6485
|
-
takeMessageLogArgs,
|
|
6486
|
-
takeNoteLogArgsArray}=
|
|
6487
|
-
loggedErrorHandler;
|
|
6539
|
+
const { getStackString, tagError, takeMessageLogArgs, takeNoteLogArgsArray}=
|
|
6540
|
+
loggedErrorHandler;
|
|
6488
6541
|
|
|
6489
6542
|
/**
|
|
6490
6543
|
* @param {ReadonlyArray<any>} logArgs
|
|
@@ -7598,8 +7651,10 @@ const getAnonymousIntrinsics= ()=> {
|
|
|
7598
7651
|
|
|
7599
7652
|
// 9.2.4.1 %ThrowTypeError%
|
|
7600
7653
|
|
|
7601
|
-
const ThrowTypeError= getOwnPropertyDescriptor(
|
|
7602
|
-
|
|
7654
|
+
const ThrowTypeError= getOwnPropertyDescriptor(
|
|
7655
|
+
makeArguments(),
|
|
7656
|
+
'callee').
|
|
7657
|
+
get;
|
|
7603
7658
|
|
|
7604
7659
|
// 21.1.5.2 The %StringIteratorPrototype% Object
|
|
7605
7660
|
|
|
@@ -8101,7 +8156,8 @@ function tameDomains(domainTaming= 'safe') {
|
|
|
8101
8156
|
})
|
|
8102
8157
|
,
|
|
8103
8158
|
// === functors[36] ===
|
|
8104
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let FERAL_FUNCTION,SyntaxError,TypeError,defineProperties,getPrototypeOf,setPrototypeOf;$h_imports([["./commons.js", [["FERAL_FUNCTION", [$h_a => (FERAL_FUNCTION = $h_a)]],["SyntaxError", [$h_a => (SyntaxError = $h_a)]],["TypeError", [$h_a => (TypeError = $h_a)]],["defineProperties", [$h_a => (defineProperties = $h_a)]],["getPrototypeOf", [$h_a => (getPrototypeOf = $h_a)]],["setPrototypeOf", [$h_a => (setPrototypeOf = $h_a)]]]]]);
|
|
8159
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let FERAL_FUNCTION,SyntaxError,TypeError,defineProperties,getPrototypeOf,setPrototypeOf,freeze;$h_imports([["./commons.js", [["FERAL_FUNCTION", [$h_a => (FERAL_FUNCTION = $h_a)]],["SyntaxError", [$h_a => (SyntaxError = $h_a)]],["TypeError", [$h_a => (TypeError = $h_a)]],["defineProperties", [$h_a => (defineProperties = $h_a)]],["getPrototypeOf", [$h_a => (getPrototypeOf = $h_a)]],["setPrototypeOf", [$h_a => (setPrototypeOf = $h_a)]],["freeze", [$h_a => (freeze = $h_a)]]]]]);
|
|
8160
|
+
|
|
8105
8161
|
|
|
8106
8162
|
|
|
8107
8163
|
|
|
@@ -8152,7 +8208,7 @@ function tameFunctionConstructors() {
|
|
|
8152
8208
|
FERAL_FUNCTION.prototype.constructor('return 1');
|
|
8153
8209
|
}catch( ignore) {
|
|
8154
8210
|
// Throws, no need to patch.
|
|
8155
|
-
return
|
|
8211
|
+
return freeze({});
|
|
8156
8212
|
}
|
|
8157
8213
|
|
|
8158
8214
|
const newIntrinsics= {};
|
|
@@ -8185,7 +8241,7 @@ function tameFunctionConstructors() {
|
|
|
8185
8241
|
// Prevents the evaluation of source when calling constructor on the
|
|
8186
8242
|
// prototype of functions.
|
|
8187
8243
|
// eslint-disable-next-line func-names
|
|
8188
|
-
const InertConstructor= function()
|
|
8244
|
+
const InertConstructor= function() {
|
|
8189
8245
|
throw new TypeError(
|
|
8190
8246
|
'Function.prototype.constructor is not a valid constructor.');
|
|
8191
8247
|
|
|
@@ -8303,7 +8359,7 @@ const tameFunctionToString= ()=> {
|
|
|
8303
8359
|
|
|
8304
8360
|
|
|
8305
8361
|
|
|
8306
|
-
const {
|
|
8362
|
+
const { Fail, quote: q}= assert;
|
|
8307
8363
|
|
|
8308
8364
|
const localePattern= /^(\w*[a-z])Locale([A-Z]\w*)$/;
|
|
8309
8365
|
|
|
@@ -8325,7 +8381,7 @@ const tamedMethods= {
|
|
|
8325
8381
|
if( s> that) {
|
|
8326
8382
|
return 1;
|
|
8327
8383
|
}
|
|
8328
|
-
|
|
8384
|
+
s=== that|| Fail `expected ${q(s)} and ${q(that)} to compare`;
|
|
8329
8385
|
return 0;
|
|
8330
8386
|
},
|
|
8331
8387
|
|
|
@@ -8355,16 +8411,12 @@ function tameLocaleMethods(intrinsics, localeTaming= 'safe') {
|
|
|
8355
8411
|
for( const methodName of getOwnPropertyNames(intrinsic)) {
|
|
8356
8412
|
const match= regexpExec(localePattern, methodName);
|
|
8357
8413
|
if( match) {
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
d `expected ${q(methodName)} to be a function`);
|
|
8361
|
-
|
|
8414
|
+
typeof intrinsic[methodName]=== 'function'||
|
|
8415
|
+
Fail `expected ${q(methodName)} to be a function`;
|
|
8362
8416
|
const nonLocaleMethodName= `${match[1]}${match[2]}`;
|
|
8363
8417
|
const method= intrinsic[nonLocaleMethodName];
|
|
8364
|
-
|
|
8365
|
-
|
|
8366
|
-
d `function ${q(nonLocaleMethodName)} not found`);
|
|
8367
|
-
|
|
8418
|
+
typeof method=== 'function'||
|
|
8419
|
+
Fail `function ${q(nonLocaleMethodName)} not found`;
|
|
8368
8420
|
defineProperty(intrinsic, methodName, { value: method});
|
|
8369
8421
|
}
|
|
8370
8422
|
}
|
|
@@ -8395,9 +8447,8 @@ function tameMathObject(mathTaming= 'safe') {
|
|
|
8395
8447
|
const originalMath= Math;
|
|
8396
8448
|
const initialMath= originalMath; // to follow the naming pattern
|
|
8397
8449
|
|
|
8398
|
-
const { random: _, ...otherDescriptors}=
|
|
8399
|
-
originalMath);
|
|
8400
|
-
|
|
8450
|
+
const { random: _, ...otherDescriptors}=
|
|
8451
|
+
getOwnPropertyDescriptors(originalMath);
|
|
8401
8452
|
|
|
8402
8453
|
const sharedMath= create(objectPrototype, otherDescriptors);
|
|
8403
8454
|
|
|
@@ -8836,7 +8887,7 @@ function whitelistIntrinsics(
|
|
|
8836
8887
|
|
|
8837
8888
|
/** @typedef {import('../index.js').LockdownOptions} LockdownOptions */
|
|
8838
8889
|
|
|
8839
|
-
const { details: d, quote: q}= assert;
|
|
8890
|
+
const { Fail, details: d, quote: q}= assert;
|
|
8840
8891
|
|
|
8841
8892
|
/** @type {Error=} */
|
|
8842
8893
|
let priorLockdown;
|
|
@@ -8863,7 +8914,6 @@ const harden= makeHardener();
|
|
|
8863
8914
|
* @param {Object} [options]
|
|
8864
8915
|
* @param {Array<Transform>} [options.transforms]
|
|
8865
8916
|
* @param {Array<Transform>} [options.__shimTransforms__]
|
|
8866
|
-
* @param {Object} [options.globalLexicals]
|
|
8867
8917
|
*/
|
|
8868
8918
|
|
|
8869
8919
|
// TODO https://github.com/endojs/endo/issues/814
|
|
@@ -8933,10 +8983,8 @@ const repairIntrinsics= (options= {})=> {
|
|
|
8933
8983
|
// [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/lockdown-options.md#stackfiltering-options)
|
|
8934
8984
|
// for an explanation.
|
|
8935
8985
|
|
|
8936
|
-
const {
|
|
8937
|
-
|
|
8938
|
-
getCapturedEnvironmentOptionNames}=
|
|
8939
|
-
makeEnvironmentCaptor(globalThis);
|
|
8986
|
+
const { getEnvironmentOption: getenv, getCapturedEnvironmentOptionNames}=
|
|
8987
|
+
makeEnvironmentCaptor(globalThis);
|
|
8940
8988
|
|
|
8941
8989
|
const {
|
|
8942
8990
|
errorTaming= getenv('LOCKDOWN_ERROR_TAMING', 'safe'),
|
|
@@ -8973,25 +9021,22 @@ const repairIntrinsics= (options= {})=> {
|
|
|
8973
9021
|
|
|
8974
9022
|
}
|
|
8975
9023
|
|
|
8976
|
-
|
|
8977
|
-
evalTaming=== '
|
|
8978
|
-
|
|
8979
|
-
|
|
8980
|
-
d `lockdown(): non supported option evalTaming: ${q(evalTaming)}`);
|
|
8981
|
-
|
|
9024
|
+
evalTaming=== 'unsafeEval'||
|
|
9025
|
+
evalTaming=== 'safeEval'||
|
|
9026
|
+
evalTaming=== 'noEval'||
|
|
9027
|
+
Fail `lockdown(): non supported option evalTaming: ${q(evalTaming)}`;
|
|
8982
9028
|
|
|
8983
9029
|
// Assert that only supported options were passed.
|
|
8984
9030
|
// Use Reflect.ownKeys to reject symbol-named properties as well.
|
|
8985
9031
|
const extraOptionsNames= ownKeys(extraOptions);
|
|
8986
|
-
|
|
8987
|
-
extraOptionsNames
|
|
8988
|
-
d `lockdown(): non supported option ${q(extraOptionsNames)}`);
|
|
8989
|
-
|
|
9032
|
+
extraOptionsNames.length=== 0||
|
|
9033
|
+
Fail `lockdown(): non supported option ${q(extraOptionsNames)}`;
|
|
8990
9034
|
|
|
8991
|
-
|
|
8992
|
-
|
|
8993
|
-
|
|
8994
|
-
|
|
9035
|
+
priorLockdown=== undefined||
|
|
9036
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
9037
|
+
assert.fail(
|
|
9038
|
+
d `Already locked down at ${priorLockdown} (SES_ALREADY_LOCKED_DOWN)`,
|
|
9039
|
+
TypeError);
|
|
8995
9040
|
|
|
8996
9041
|
priorLockdown= new TypeError('Prior lockdown (SES_ALREADY_LOCKED_DOWN)');
|
|
8997
9042
|
// Tease V8 to generate the stack string and release the closures the stack
|
|
@@ -9034,7 +9079,6 @@ const repairIntrinsics= (options= {})=> {
|
|
|
9034
9079
|
};
|
|
9035
9080
|
|
|
9036
9081
|
if( seemsToBeLockedDown()) {
|
|
9037
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
9038
9082
|
throw new TypeError(
|
|
9039
9083
|
`Already locked down but not by this SES instance (SES_MULTIPLE_INSTANCES)`);
|
|
9040
9084
|
|
|
@@ -9046,11 +9090,8 @@ const repairIntrinsics= (options= {})=> {
|
|
|
9046
9090
|
|
|
9047
9091
|
tameDomains(domainTaming);
|
|
9048
9092
|
|
|
9049
|
-
const {
|
|
9050
|
-
|
|
9051
|
-
completePrototypes,
|
|
9052
|
-
finalIntrinsics}=
|
|
9053
|
-
makeIntrinsicsCollector();
|
|
9093
|
+
const { addIntrinsics, completePrototypes, finalIntrinsics}=
|
|
9094
|
+
makeIntrinsicsCollector();
|
|
9054
9095
|
|
|
9055
9096
|
addIntrinsics({ harden});
|
|
9056
9097
|
|
|
@@ -9241,23 +9282,25 @@ assign(globalThis, {
|
|
|
9241
9282
|
,
|
|
9242
9283
|
]; // functors end
|
|
9243
9284
|
|
|
9244
|
-
|
|
9285
|
+
const cell = (name, value = undefined) => {
|
|
9245
9286
|
const observers = [];
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9287
|
+
return Object.freeze({
|
|
9288
|
+
get: Object.freeze(() => {
|
|
9289
|
+
return value;
|
|
9290
|
+
}),
|
|
9291
|
+
set: Object.freeze((newValue) => {
|
|
9292
|
+
value = newValue;
|
|
9293
|
+
for (const observe of observers) {
|
|
9294
|
+
observe(value);
|
|
9295
|
+
}
|
|
9296
|
+
}),
|
|
9297
|
+
observe: Object.freeze((observe) => {
|
|
9298
|
+
observers.push(observe);
|
|
9249
9299
|
observe(value);
|
|
9250
|
-
}
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
}
|
|
9255
|
-
function observe(observe) {
|
|
9256
|
-
observers.push(observe);
|
|
9257
|
-
observe(value);
|
|
9258
|
-
}
|
|
9259
|
-
return { get, set, observe, enumerable: true };
|
|
9260
|
-
}
|
|
9300
|
+
}),
|
|
9301
|
+
enumerable: true,
|
|
9302
|
+
});
|
|
9303
|
+
};
|
|
9261
9304
|
|
|
9262
9305
|
const cells = [
|
|
9263
9306
|
{
|
|
@@ -9562,23 +9605,24 @@ assign(globalThis, {
|
|
|
9562
9605
|
];
|
|
9563
9606
|
|
|
9564
9607
|
|
|
9565
|
-
const namespaces = cells.map(cells => Object.create(null, cells));
|
|
9608
|
+
const namespaces = cells.map(cells => Object.freeze(Object.create(null, cells)));
|
|
9566
9609
|
|
|
9567
9610
|
for (let index = 0; index < namespaces.length; index += 1) {
|
|
9568
9611
|
cells[index]['*'] = cell('*', namespaces[index]);
|
|
9569
9612
|
}
|
|
9570
9613
|
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
}
|
|
9614
|
+
function observeImports(map, importName, importIndex) {
|
|
9615
|
+
for (const [name, observers] of map.get(importName)) {
|
|
9616
|
+
const cell = cells[importIndex][name];
|
|
9617
|
+
if (cell === undefined) {
|
|
9618
|
+
throw new ReferenceError(`Cannot import name ${name}`);
|
|
9619
|
+
}
|
|
9620
|
+
for (const observer of observers) {
|
|
9621
|
+
cell.observe(observer);
|
|
9580
9622
|
}
|
|
9581
9623
|
}
|
|
9624
|
+
}
|
|
9625
|
+
|
|
9582
9626
|
|
|
9583
9627
|
functors[0]({
|
|
9584
9628
|
imports(entries) {
|
|
@@ -10034,7 +10078,6 @@ assign(globalThis, {
|
|
|
10034
10078
|
observeImports(map, "./module-link.js", 21);
|
|
10035
10079
|
observeImports(map, "./module-load.js", 18);
|
|
10036
10080
|
observeImports(map, "./module-proxy.js", 19);
|
|
10037
|
-
observeImports(map, "./scope-constants.js", 6);
|
|
10038
10081
|
observeImports(map, "./whitelist.js", 16);
|
|
10039
10082
|
},
|
|
10040
10083
|
liveVar: {
|
|
@@ -10348,4 +10391,6 @@ assign(globalThis, {
|
|
|
10348
10391
|
},
|
|
10349
10392
|
importMeta: {},
|
|
10350
10393
|
});
|
|
10394
|
+
|
|
10395
|
+
return cells[cells.length - 1]['*'].get();
|
|
10351
10396
|
})();
|