Skip to content

Commit

Permalink
feat(ses): Add Compartment load function
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Jul 24, 2020
1 parent 9ba5ecf commit 7d3f568
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/ses/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ User-visible changes in SES:

## Next release

* No changes yet.
* Adds the `load` method to `Compartment`.
Load allows a bundler or archiver to use the `Compartment` API to gather the
transitive dependencies of modules without executing them.

## Release 0.9.1 (16-July-2020)

Expand Down
10 changes: 10 additions & 0 deletions packages/ses/src/compartment-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ const CompartmentPrototype = {
});
},

async load(specifier) {
if (typeof specifier !== 'string') {
throw new TypeError('first argument of load() must be a string');
}

assertModuleHooks(this);

return load(privateFields, moduleAnalyses, this, specifier);
},

importNow(specifier) {
if (typeof specifier !== 'string') {
throw new TypeError('first argument of importNow() must be a string');
Expand Down
1 change: 1 addition & 0 deletions packages/ses/src/whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,7 @@ export const whitelist = {
evaluate: fn,
globalThis: getter,
import: asyncFn,
load: asyncFn,
importNow: fn,
module: fn,
// Should this be proposed?
Expand Down
1 change: 1 addition & 0 deletions packages/ses/test/compartment-instance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ test('Compartment instance', t => {
'evaluate',
'import',
'importNow',
'load',
'module',
'globalThis',
'toString',
Expand Down
1 change: 1 addition & 0 deletions packages/ses/test/compartment-prototype.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test('Compartment prototype', t => {
'evaluate',
'import',
'importNow',
'load',
'module',
'globalThis',
'toString',
Expand Down

0 comments on commit 7d3f568

Please sign in to comment.