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 21, 2020
1 parent 0926a2d commit 88264c0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/ses/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ User-visible changes in SES:
by aliasing them to their non-locale equivalents. `localeCompare` had no builtin
non-locale equivalent, so we provide one.
* Adds a TypeScript definition for `harden`.
* 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.0 (13-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 @@ -235,6 +235,16 @@ export class Compartment {
});
}

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 @@ -1548,6 +1548,7 @@ export default {
evaluate: fn,
globalThis: getter,
import: asyncFn,
load: asyncFn,
importNow: fn,
module: fn,
},
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 88264c0

Please sign in to comment.