Skip to content

Commit

Permalink
feat(contractHost): support new moduleFormat bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Oct 12, 2019
1 parent a34dad1 commit 185016e
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions core/contractHost.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,27 @@ No invites left`;
// number of functions with names beginning 'check', each of which can be
// used by clients to help validate that they have terms that match the
// contract.
install(contractSrcs) {
const installation = extractCheckFunctions(contractSrcs);
const startFn = evaluateStringToFn(contractSrcs.start);
install(contractSrcs, moduleFormat = 'object') {
let installation;
let startFn;
if (moduleFormat === 'object') {
installation = extractCheckFunctions(contractSrcs);
startFn = evaluateStringToFn(contractSrcs.start);
} else if (moduleFormat === 'getExport') {
const getExports = evaluateStringToFn(contractSrcs);
const ns = getExports();
installation = {};
for (const fname of Object.getOwnPropertyNames(ns)) {
if (typeof fname === 'string' && fname.startsWith('check')) {
const fn = ns[fname];
installation[fname] = (...args) => fn(installation, ...args);
}
}
startFn = ns.default;
} else {
insist(false)`\
Unrecognized moduleFormat ${moduleFormat}`;
}

// TODO: The `spawn` method should spin off a new vat for each new
// contract instance. In the current single-vat implementation we
Expand Down

0 comments on commit 185016e

Please sign in to comment.