Skip to content

Commit

Permalink
toward integration with ag-solo: device src Resources
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Nov 25, 2019
1 parent e01f55f commit 6479fde
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
33 changes: 21 additions & 12 deletions src/controller.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
// eslint-disable-next-line no-redeclare
/* global setImmediate */
// import { rollup } from 'rollup';
import assert from 'assert';
import harden from '@agoric/harden';
import Nat from '@agoric/nat';
import bundleSource from '@agoric/bundle-source';
//@@ import bundleSource from '@agoric/bundle-source';
import SES from 'ses';

import makeDefaultEvaluateOptions from '@agoric/default-evaluate-options';
//@@ import makeDefaultEvaluateOptions from '@agoric/default-evaluate-options';

import kernelSourceFunc from './bundles/kernel';
import buildKernelNonSES from './kernel/index';
//@@ import kernelSourceFunc from './bundles/kernel';
import Resource from 'Resource';

//@@ import buildKernelNonSES from './kernel/index';
import { insist } from './insist';
import { insistStorageAPI } from './storageAPI';
import { insistCapData } from './capdata';
import { parseVatSlot } from './parseVatSlots';
import { buildStorageInMemory } from './hostStorage';

const evaluateOptions = makeDefaultEvaluateOptions();
//@@ const evaluateOptions = makeDefaultEvaluateOptions();
const evaluateOptions = { shims: [] };
// globalThis is standard, we want it to be frozen
// as one of our root realm's global properties.
evaluateOptions.shims.unshift('this.globalThis = this');
//@@ evaluateOptions.shims.unshift('this.globalThis = this');

export function nodeSourceAccess({
fs,
Expand Down Expand Up @@ -124,7 +126,11 @@ export function loadBasedir(basedirRd, requireModule) {
}

function getKernelSource() {
return `(${kernelSourceFunc})`;
const kernelRes = new Resource("agoric.kernel.js");
const src = String.fromArrayBuffer(kernelRes.slice(0));
console.log(src.slice(0, 60) + '...');
const kernelExpr = `(${src.slice('export default '.length)})`;
return kernelExpr;
}

// this feeds the SES realm's (real/safe) confine*() back into the Realm
Expand Down Expand Up @@ -168,7 +174,7 @@ function makeEvaluate(e) {
});
}

function buildSESKernel(hostStorage) {
function buildSESKernel(hostStorage, setImmediate) {
// console.log('transforms', transforms);
const s = SES.makeSESRootRealm({
...evaluateOptions,
Expand All @@ -194,7 +200,7 @@ function buildSESKernel(hostStorage) {
return { kernel, s, r };
}

function buildNonSESKernel(hostStorage) {
function buildNonSESKernel(hostStorage, setImmediate) {
// Evaluate shims to produce desired globals.
// eslint-disable-next-line no-eval
(evaluateOptions.shims || []).forEach(shim => (1, eval)(shim));
Expand All @@ -213,8 +219,8 @@ export async function buildVatController(
const hostStorage = configRd.hostStorage || buildStorageInMemory().storage;
insistStorageAPI(hostStorage);
const { kernel, s, r } = withSES
? buildSESKernel(hostStorage)
: buildNonSESKernel(hostStorage);
? buildSESKernel(hostStorage, configRd.setImmediate)
: buildNonSESKernel(hostStorage, configRd.setImmediate);
// console.log('kernel', kernel);

async function addGenesisVatRd(name, sourceIndexRd, options = {}) {
Expand All @@ -236,6 +242,7 @@ export async function buildVatController(
// Vat so it doesn't really help anyways
// const r = s.makeRequire({ '@agoric/harden': true, '@agoric/nat': Nat });
const { source, sourceMap } = await sourceIndexRd.bundleSource();
console.log('@@bundleSource in controller done.');
const actualSource = `(${source})\n${sourceMap}`;
setup = s.evaluate(actualSource, { require: r })().default;
} else {
Expand All @@ -247,7 +254,9 @@ export async function buildVatController(
async function addGenesisDeviceRd(name, sourceIndexRd, endowments) {
let setup;
if (withSES) {
console.log('@@genesis device', { sourceIndexRd });
const { source, sourceMap } = await sourceIndexRd.bundleSource();
console.log('bundeSource done@@@');
const actualSource = `(${source})\n${sourceMap}`;
setup = s.evaluate(actualSource, { require: r })().default;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/devices/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function buildCommand(broadcastCallback) {
throw new Error(`broadcastCallback must be provided.`);
}
let inboundCallback;
const srcPath = require.resolve('./command-src');
const srcPath = '@agoric.command-src.js';
let nextCount = 0;
const responses = new Map();

Expand Down
2 changes: 1 addition & 1 deletion src/devices/mailbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function buildMailboxStateMap() {
}

export function buildMailbox(state) {
const srcPath = require.resolve('./mailbox-src');
const srcPath = '@agoric.mailbox-src.js';

// endowments made available to the inner half
let inboundCallback;
Expand Down
2 changes: 1 addition & 1 deletion src/devices/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Nat from '@agoric/nat';
* controller.run() when it returns true.
*/
export function buildTimer() {
const srcPath = require.resolve('./timer-src');
const srcPath = '@agoric.timer-src.js';
let devicePollFunction;

function registerDevicePollFunction(pollFn) {
Expand Down

0 comments on commit 6479fde

Please sign in to comment.