Skip to content

Commit

Permalink
refactor: inherit HandledPromise from install-ses
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Aug 14, 2020
1 parent 5574462 commit 49d1271
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 47 deletions.
3 changes: 0 additions & 3 deletions packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { isTamed, tameMetering } from '@agoric/tame-metering';
import bundleSource from '@agoric/bundle-source';
import { importBundle } from '@agoric/import-bundle';
import { initSwingStore } from '@agoric/swing-store-simple';
import { HandledPromise } from '@agoric/eventual-send';
import { makeMeteringTransformer } from '@agoric/transform-metering';
import { makeTransform } from '@agoric/transform-eventual-send';

Expand Down Expand Up @@ -258,7 +257,6 @@ export async function buildVatController(
endowments: {
console: makeConsole(`${debugPrefix}SwingSet:kernel`),
require: kernelRequire,
HandledPromise,
},
});
const buildKernel = kernelNS.default;
Expand Down Expand Up @@ -292,7 +290,6 @@ export async function buildVatController(
function makeVatEndowments(consoleTag) {
return harden({
console: makeConsole(`${debugPrefix}SwingSet:${consoleTag}`),
HandledPromise,
// re2 is a RegExp work-a-like that disables backtracking expressions for
// safer memory consumption
RegExp: re2,
Expand Down
3 changes: 1 addition & 2 deletions packages/SwingSet/src/kernel/liveSlots.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global harden */
/* global harden HandledPromise */

import { HandledPromise } from '@agoric/eventual-send';
import {
QCLASS,
Remotable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import anylogger from 'anylogger';
import { assert } from '@agoric/assert';
import { importBundle } from '@agoric/import-bundle';
import { Remotable, getInterfaceOf } from '@agoric/marshal';
import { HandledPromise } from '@agoric/eventual-send';
import { waitUntilQuiescent } from '../../waitUntilQuiescent';
import { makeLiveSlots } from '../liveSlots';

Expand Down Expand Up @@ -77,7 +76,6 @@ parentPort.on('message', ([type, ...margs]) => {
const [bundle, vatParameters] = margs;
const endowments = {
console: makeConsole(`SwingSet:vatWorker`),
HandledPromise,
};
importBundle(bundle, { endowments }).then(vatNS => {
workerLog(`got vatNS:`, Object.keys(vatNS).join(','));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Netstring from 'netstring-stream';
import { assert } from '@agoric/assert';
import { importBundle } from '@agoric/import-bundle';
import { Remotable, getInterfaceOf } from '@agoric/marshal';
import { HandledPromise } from '@agoric/eventual-send';
import { waitUntilQuiescent } from '../../waitUntilQuiescent';
import { makeLiveSlots } from '../liveSlots';

Expand Down Expand Up @@ -92,7 +91,6 @@ fromParent.on('data', data => {
const [bundle, vatParameters] = margs;
const endowments = {
console: makeConsole(`SwingSet:vatWorker`),
HandledPromise,
};
importBundle(bundle, { endowments }).then(vatNS => {
workerLog(`got vatNS:`, Object.keys(vatNS).join(','));
Expand Down
2 changes: 1 addition & 1 deletion packages/captp/lib/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This logic was mostly lifted from @agoric/swingset-vat liveSlots.js
// Defects in it are mfig's fault.
import { Remotable, makeMarshal, QCLASS } from '@agoric/marshal';
import { E, HandledPromise } from '@agoric/eventual-send';
import { E, HandledPromise } from '@agoric/eventual-send/shim';
import { isPromise } from '@agoric/promise-kit';

export { E, HandledPromise };
Expand Down
3 changes: 1 addition & 2 deletions packages/cosmic-swingset/lib/ag-solo/vats/repl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global harden Compartment */

import { isPromise } from '@agoric/promise-kit';
import { E, HandledPromise } from '@agoric/eventual-send';
import { E } from '@agoric/eventual-send';

import makeUIAgentMakers from './ui-agent';

Expand Down Expand Up @@ -158,7 +158,6 @@ export function getReplHandler(replObjects, send, vatPowers) {
getInterfaceOf,
console: replConsole,
E,
HandledPromise,
commands,
history,
harden,
Expand Down
4 changes: 2 additions & 2 deletions packages/cosmic-swingset/test/captp-fixture.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spawn } from 'child_process';
import WebSocket from 'ws';
import { makeCapTP, E, HandledPromise } from '@agoric/captp';
import { makeCapTP, E } from '@agoric/captp';

const PORT = 8000;

Expand Down Expand Up @@ -93,7 +93,7 @@ export function makeFixture() {
});
}

return new HandledPromise((resolve, reject) => {
return new Promise((resolve, reject) => {
cp.addListener('exit', code => {
if (!expectedToExit) {
// Display all our output.
Expand Down
2 changes: 1 addition & 1 deletion packages/eventual-send/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Create a HandledPromise class to implement the eventual-send API. This API is u

> Note: If you're writing an application, you probably don't want to use this package directly. You'll want to use the eventual-send `~.` operator (tildot) provided in [SES](https://github.com/Agoric/SES) or other platforms.
After importing `@agoric/eventual-send`, the exported `HandledPromise` class can be used as described in `test/test.js`.
After importing `@agoric/eventual-send/shim`, the global `HandledPromise` class can be used as described in `test/test.js`.

[circleci-svg]: https://circleci.com/gh/Agoric/eventual-send.svg?style=svg
[circleci-url]: https://circleci.com/gh/Agoric/eventual-send
Expand Down
2 changes: 1 addition & 1 deletion packages/eventual-send/src/E.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ export default function makeE(HandledPromise) {
E.when = (x, onfulfilled = undefined, onrejected = undefined) =>
HandledPromise.resolve(x).then(onfulfilled, onrejected);

return harden(E);
return Object.freeze(E);
}
6 changes: 3 additions & 3 deletions packages/eventual-send/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export function makeHandledPromise(Promise) {
);
}

const staticMethods = harden({
const staticMethods = {
get(target, key) {
return handle(target, 'get', key);
},
Expand Down Expand Up @@ -354,7 +354,7 @@ export function makeHandledPromise(Promise) {
promiseResolve().then(_ => new HandledPromise(executeThen)),
);
},
});
};

defineProperties(HandledPromise, getOwnPropertyDescriptors(staticMethods));

Expand Down Expand Up @@ -458,5 +458,5 @@ export function makeHandledPromise(Promise) {
};

promiseResolve = Promise.resolve.bind(Promise);
return harden(HandledPromise);
return HandledPromise;
}
5 changes: 5 additions & 0 deletions packages/eventual-send/test/get-hp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import makeE from '../src/E';
import makeHandledPromise from '../src/handled-promise';

export const HandledPromise = makeHandledPromise(Promise);
export const E = makeE(HandledPromise);
1 change: 1 addition & 0 deletions packages/install-ses/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"tape": "^4.13.2"
},
"dependencies": {
"@agoric/eventual-send": "^0.9.3",
"ses": "^0.10.0"
},
"files": [
Expand Down
10 changes: 5 additions & 5 deletions packages/produce-promise/src/producePromise.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* global harden */
/* global harden globalThis */
// @ts-check

// eslint-disable-next-line spaced-comment
/// <reference types="ses"/>

import { HandledPromise } from '@agoric/eventual-send';
const BestPromise = globalThis.HandledPromise || Promise;

/**
* @template T
Expand All @@ -20,7 +20,7 @@ import { HandledPromise } from '@agoric/eventual-send';
const NOOP_INITIALIZER = harden(_ => {});

/**
* producePromise() builds a HandledPromise object, and returns a record
* producePromise() builds a Promise, and returns a record
* containing the promise itself, as well as separate facets for resolving
* and rejecting it.
*
Expand All @@ -34,7 +34,7 @@ export function producePromise() {
/** @type {(reason: any) => void} */
let rej = NOOP_INITIALIZER;

const p = new HandledPromise((resolve, reject) => {
const p = new BestPromise((resolve, reject) => {
res = resolve;
rej = reject;
});
Expand Down Expand Up @@ -68,6 +68,6 @@ harden(producePromise);
* @returns {maybePromise is Promise} Whether it is a promise
*/
export function isPromise(maybePromise) {
return HandledPromise.resolve(maybePromise) === maybePromise;
return BestPromise.resolve(maybePromise) === maybePromise;
}
harden(isPromise);
10 changes: 5 additions & 5 deletions packages/promise-kit/src/promiseKit.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* global harden */
/* global harden globalThis */
// @ts-check

// eslint-disable-next-line spaced-comment
/// <reference types="ses"/>

import { HandledPromise } from '@agoric/eventual-send';
const BestPromise = globalThis.HandledPromise || Promise;

/**
* @template T
Expand All @@ -29,7 +29,7 @@ import { HandledPromise } from '@agoric/eventual-send';
const NOOP_INITIALIZER = harden(_ => {});

/**
* makePromiseKit() builds a HandledPromise object, and returns a record
* makePromiseKit() builds a Promise object, and returns a record
* containing the promise itself, as well as separate facets for resolving
* and rejecting it.
*
Expand All @@ -42,7 +42,7 @@ export function makePromiseKit() {
/** @type {(reason: any) => void} */
let rej = NOOP_INITIALIZER;

const p = new HandledPromise((resolve, reject) => {
const p = new BestPromise((resolve, reject) => {
res = resolve;
rej = reject;
});
Expand Down Expand Up @@ -75,6 +75,6 @@ harden(makePromiseKit);
* @returns {maybePromise is Promise} Whether it is a promise
*/
export function isPromise(maybePromise) {
return HandledPromise.resolve(maybePromise) === maybePromise;
return BestPromise.resolve(maybePromise) === maybePromise;
}
harden(isPromise);
14 changes: 1 addition & 13 deletions packages/spawner/src/contractHost.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2019 Agoric, under Apache License 2.0

/* global harden */
/* global harden HandledPromise */

import Nat from '@agoric/nat';
import { importBundle } from '@agoric/import-bundle';
Expand All @@ -9,7 +9,6 @@ import { assert, details } from '@agoric/assert';
import { allComparable } from '@agoric/same-structure';
import makeIssuerKit from '@agoric/ertp';
import { makePromiseKit } from '@agoric/promise-kit';
import { E, HandledPromise } from '@agoric/eventual-send';

export { makeCollect } from './makeCollect';

Expand Down Expand Up @@ -48,19 +47,8 @@ function makeContractHost(vatPowers, additionalEndowments = {}) {
});
}

// TODO: this should really have console and HandledPromise. We need
// 'require' until we change the environment definition (and
// bundle-source's "externals" list) to get 'harden' from a global, not an
// import, and then change the nestedEvaluate format to stop needing
// 'require' even though nobody calls it. The bundles we install here
// should be standalone, with no remaining require() calls. Probably.
const defaultEndowments = {
console,
E,
harden,
Nat,
makePromiseKit,
HandledPromise,
};

// note: support for check functions was removed during warner's
Expand Down
4 changes: 2 additions & 2 deletions packages/zoe/src/contractSupport/zoeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { assert, details } from '@agoric/assert';
import { sameStructure } from '@agoric/same-structure';
import { E, HandledPromise } from '@agoric/eventual-send';
import { E } from '@agoric/eventual-send';
import { satisfiesWant, isOfferSafe } from '../offerSafety';

import '../../exported';
Expand Down Expand Up @@ -362,7 +362,7 @@ export const makeZoeHelpers = zcf => {
* @returns {Promise<OfferHandle>}
*/
makeEmptyOffer: () =>
new HandledPromise(resolve => {
new Promise(resolve => {
const invite = zcf.makeInvitation(
offerHandle => resolve(offerHandle),
'empty offer',
Expand Down
5 changes: 2 additions & 3 deletions packages/zoe/src/evalContractCode.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* global HandledPromise */
import Nat from '@agoric/nat';

import makeIssuerKit from '@agoric/ertp';
import { assert } from '@agoric/assert';
import { makePromiseKit } from '@agoric/promise-kit';
import { sameStructure } from '@agoric/same-structure';
import { importBundle } from '@agoric/import-bundle';
import { HandledPromise } from '@agoric/eventual-send';

const evalContractBundle = (bundle, additionalEndowments = {}) => {
// Make the console more verbose.
Expand All @@ -14,7 +14,7 @@ const evalContractBundle = (bundle, additionalEndowments = {}) => {
log: console.info,
};

// TODO: this should really only be console and HandledPromise
// TODO: this should really only be console
const defaultEndowments = {
assert,
console: louderConsole,
Expand All @@ -23,7 +23,6 @@ const evalContractBundle = (bundle, additionalEndowments = {}) => {
makeIssuerKit,
makePromiseKit,
sameStructure,
HandledPromise,
};

const fullEndowments = Object.create(null, {
Expand Down

0 comments on commit 49d1271

Please sign in to comment.