forked from endojs/endo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,53 @@ | ||
// TODO: equivalent of: | ||
// import '../dist/ses.cjs'; | ||
// import '../src/assert-shim.js'; | ||
// Since Hermes has no native support for I/O | ||
|
||
// Test lockdown | ||
|
||
lockdown(); | ||
|
||
// Test Compartment | ||
|
||
const c = new Compartment(); | ||
|
||
c.evaluate('1+1'); | ||
c.evaluate("const c2 = new Compartment(); c2.evaluate('1+2')"); | ||
|
||
// Test importHook and resolveHook | ||
|
||
// https://github.com/facebook/hermes/blob/main/doc/Features.md | ||
// In Progress: ES modules (`import` and `export`) | ||
|
||
const resolveHook = (a) => a; | ||
|
||
async function importHook() { | ||
return { | ||
imports: [], | ||
exports: ['meaning'], | ||
execute(exports) { | ||
exports.meaning = 42; | ||
}, | ||
}; | ||
} | ||
|
||
const compartment = new Compartment({}, {}, { resolveHook, importHook }); | ||
|
||
const module = compartment.module('.'); | ||
|
||
// const { | ||
// namespace: { _meaning }, | ||
// } = await compartment.import('.'); | ||
|
||
assert(module); | ||
// t.is(meaning, 42, 'exports seen'); | ||
// t.is(module.meaning, 42, 'exports seen through deferred proxy'); | ||
// Hermes doesn't support native I/O, | ||
// so we concat the SES shim above, | ||
// when running this test on the `hermesc`. | ||
|
||
/** | ||
* Test calling SES lockdown. | ||
*/ | ||
const testLockdown = () => { | ||
lockdown(); | ||
}; | ||
|
||
testLockdown(); | ||
|
||
/** | ||
* TODO: Test creating a new Compartment. | ||
*/ | ||
// eslint-disable-next-line no-unused-vars | ||
const testCompartment = () => { | ||
// eslint-disable-next-line no-unused-vars | ||
const c = new Compartment(); | ||
}; | ||
|
||
// testCompartment(); | ||
|
||
/** | ||
* TODO: Test Compartment import hook and resolve hook. | ||
*/ | ||
// eslint-disable-next-line no-unused-vars | ||
const testCompartmentHooks = async () => { | ||
const resolveHook = a => a; | ||
|
||
async function importHook() { | ||
return { | ||
imports: [], | ||
exports: ['meaning'], | ||
execute(exports) { | ||
exports.meaning = 42; | ||
}, | ||
}; | ||
} | ||
|
||
const compartment = new Compartment({}, {}, { resolveHook, importHook }); | ||
|
||
const module = compartment.module('.'); | ||
|
||
const { | ||
namespace: { _meaning }, | ||
} = await compartment.import('.'); | ||
|
||
assert(module); | ||
}; | ||
|
||
// testCompartmentHooks(); |