Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@agoric/transform-eventual-send

Package Overview
Dependencies
Maintainers
5
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agoric/transform-eventual-send - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

CHANGELOG.md

9

dist/transform-eventual-send.cjs.js
'use strict';
var eventualSendBundle = {"source":"function getExport() { 'use strict'; let exports = {}; const module = { exports }; 'use strict';\n\n'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nfunction _interopDefault$1 (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar harden = _interopDefault$1(require('@agoric/harden'));\n\n/* global */\n\nconst readOnlyProxy = {\n set(_target, _prop, _value) {\n return false;\n },\n isExtensible(_target) {\n return false;\n },\n setPrototypeOf(_target, _value) {\n return false;\n },\n deleteProperty(_target, _prop) {\n return false;\n },\n};\n\n/**\n * A Proxy handler for E(x).\n *\n * @param {*} x Any value passed to E(x)\n * @returns {ProxyHandler} the Proxy handler\n */\nfunction EProxyHandler(x, HandledPromise) {\n return harden({\n ...readOnlyProxy,\n get(_target, p, _receiver) {\n if (`${p}` !== p) {\n return undefined;\n }\n // Harden this Promise because it's our only opportunity to ensure\n // p1=E(x).foo() is hardened. The Handled Promise API does not (yet)\n // allow the handler to synchronously influence the promise returned\n // by the handled methods, so we must freeze it from the outside. See\n // #95 for details.\n return (...args) => harden(HandledPromise.applyMethod(x, p, args));\n },\n apply(_target, _thisArg, argArray = []) {\n return harden(HandledPromise.applyFunction(x, argArray));\n },\n has(_target, _p) {\n // We just pretend everything exists.\n return true;\n },\n });\n}\n\nfunction makeE(HandledPromise) {\n function E(x) {\n const handler = EProxyHandler(x, HandledPromise);\n return harden(new Proxy(() => {}, handler));\n }\n\n const makeEGetterProxy = x =>\n new Proxy(Object.create(null), {\n ...readOnlyProxy,\n has(_target, _prop) {\n return true;\n },\n get(_target, prop) {\n return HandledPromise.get(x, prop);\n },\n });\n\n E.G = makeEGetterProxy;\n E.resolve = HandledPromise.resolve;\n\n return harden(E);\n}\n\n/* global HandledPromise */\n\nconst { defineProperties, getOwnPropertyDescriptors } = Object;\n\n// 'E' and 'HandledPromise' are exports of the module\n\n// For now:\n// import { HandledPromise, E } from '@agoric/eventual-send';\n// ...\n\nconst hp =\n typeof HandledPromise === 'undefined'\n ? // eslint-disable-next-line no-use-before-define\n makeHandledPromise(Promise)\n : harden(HandledPromise);\nconst E = makeE(hp);\n\n// the following method (makeHandledPromise) is part\n// of the shim, and will not be exported by the module once the feature\n// becomes a part of standard javascript\n\n/**\n * Create a HandledPromise class to have it support eventual send\n * (wavy-dot) operations.\n *\n * Based heavily on nanoq\n * https://github.com/drses/nanoq/blob/master/src/nanoq.js\n *\n * Original spec for the infix-bang (predecessor to wavy-dot) desugaring:\n * https://web.archive.org/web/20161026162206/http://wiki.ecmascript.org/doku.php?id=strawman:concurrency\n *\n * @return {typeof HandledPromise} Handled promise\n */\nfunction makeHandledPromise(Promise) {\n // xs doesn't support WeakMap in pre-loaded closures\n // aka \"vetted customization code\"\n let presenceToHandler;\n let presenceToPromise;\n let promiseToHandler;\n function ensureMaps() {\n if (!presenceToHandler) {\n presenceToHandler = new WeakMap();\n presenceToPromise = new WeakMap();\n promiseToHandler = new WeakMap();\n }\n }\n\n // This special handler accepts Promises, and forwards\n // handled Promises to their corresponding fulfilledHandler.\n let forwardingHandler;\n let handle;\n let handledPromiseResolve;\n\n function HandledPromise(executor, unfulfilledHandler = undefined) {\n if (new.target === undefined) {\n throw new Error('must be invoked with \"new\"');\n }\n let handledResolve;\n let handledReject;\n let fulfilled = false;\n const superExecutor = (resolve, reject) => {\n handledResolve = value => {\n fulfilled = true;\n resolve(value);\n };\n handledReject = err => {\n fulfilled = true;\n reject(err);\n };\n };\n const handledP = harden(\n Reflect.construct(Promise, [superExecutor], new.target),\n );\n\n ensureMaps();\n let continueForwarding = () => {};\n\n if (!unfulfilledHandler) {\n // Create a simple unfulfilledHandler that just postpones until the\n // fulfilledHandler is set.\n //\n // This is insufficient for actual remote handled Promises\n // (too many round-trips), but is an easy way to create a\n // local handled Promise.\n const interlockP = new Promise((resolve, reject) => {\n continueForwarding = (err = null, targetP = undefined) => {\n if (err !== null) {\n reject(err);\n return;\n }\n // Box the target promise so that it isn't further resolved.\n resolve([targetP]);\n // Return undefined.\n };\n });\n\n const makePostponed = postponedOperation => {\n // Just wait until the handler is resolved/rejected.\n return function postpone(x, ...args) {\n // console.log(`forwarding ${postponedOperation} ${args[0]}`);\n return new HandledPromise((resolve, reject) => {\n interlockP\n .then(([targetP]) => {\n // If targetP is a handled promise, use it, otherwise x.\n const nextPromise = targetP || x;\n resolve(\n HandledPromise[postponedOperation](nextPromise, ...args),\n );\n })\n .catch(reject);\n });\n };\n };\n\n unfulfilledHandler = {\n get: makePostponed('get'),\n applyMethod: makePostponed('applyMethod'),\n };\n }\n\n const validateHandler = h => {\n if (Object(h) !== h) {\n throw TypeError(`Handler ${h} cannot be a primitive`);\n }\n };\n validateHandler(unfulfilledHandler);\n\n // Until the handled promise is resolved, we use the unfulfilledHandler.\n promiseToHandler.set(handledP, unfulfilledHandler);\n\n const rejectHandled = reason => {\n if (fulfilled) {\n return;\n }\n handledReject(reason);\n continueForwarding(reason);\n };\n\n let resolvedPresence = null;\n const resolveWithPresence = presenceHandler => {\n if (fulfilled) {\n return resolvedPresence;\n }\n try {\n // Sanity checks.\n validateHandler(presenceHandler);\n\n // Validate and install our mapped target (i.e. presence).\n resolvedPresence = Object.create(null);\n\n // Create table entries for the presence mapped to the\n // fulfilledHandler.\n presenceToPromise.set(resolvedPresence, handledP);\n presenceToHandler.set(resolvedPresence, presenceHandler);\n\n // Remove the mapping, as our presenceHandler should be\n // used instead.\n promiseToHandler.delete(handledP);\n\n // We committed to this presence, so resolve.\n handledResolve(resolvedPresence);\n continueForwarding();\n return resolvedPresence;\n } catch (e) {\n handledReject(e);\n continueForwarding();\n throw e;\n }\n };\n\n const resolveHandled = async (target, deprecatedPresenceHandler) => {\n if (fulfilled) {\n return undefined;\n }\n try {\n if (deprecatedPresenceHandler) {\n throw TypeError(\n `resolveHandled no longer accepts a handler; use resolveWithPresence`,\n );\n }\n\n // Resolve with the target when it's ready.\n handledResolve(target);\n\n const existingUnfulfilledHandler = promiseToHandler.get(target);\n if (existingUnfulfilledHandler) {\n // Reuse the unfulfilled handler.\n promiseToHandler.set(handledP, existingUnfulfilledHandler);\n return continueForwarding(null, target);\n }\n\n // See if the target is a presence we already know of.\n const presence = await target;\n const existingPresenceHandler = presenceToHandler.get(presence);\n if (existingPresenceHandler) {\n promiseToHandler.set(handledP, existingPresenceHandler);\n return continueForwarding(null, handledP);\n }\n\n // Remove the mapping, as we don't need a handler.\n promiseToHandler.delete(handledP);\n return continueForwarding();\n } catch (e) {\n handledReject(e);\n }\n return continueForwarding();\n };\n\n // Invoke the callback to let the user resolve/reject.\n executor(\n (...args) => {\n resolveHandled(...args);\n },\n rejectHandled,\n resolveWithPresence,\n );\n return handledP;\n }\n\n HandledPromise.prototype = Promise.prototype;\n\n // Uncomment this line if needed for conformance to the proposal.\n // Currently the proposal does not specify this, but we might change\n // our mind.\n // Object.setPrototypeOf(HandledPromise, Promise);\n\n const staticMethods = harden({\n get(target, key) {\n return handle(target, 'get', key);\n },\n getSendOnly(target, key) {\n handle(target, 'get', key);\n },\n applyFunction(target, args) {\n return handle(target, 'applyMethod', undefined, args);\n },\n applyFunctionSendOnly(target, args) {\n handle(target, 'applyMethod', undefined, args);\n },\n applyMethod(target, key, args) {\n return handle(target, 'applyMethod', key, args);\n },\n applyMethodSendOnly(target, key, args) {\n handle(target, 'applyMethod', key, args);\n },\n resolve(value) {\n ensureMaps();\n // Resolving a Presence returns the pre-registered handled promise.\n const handledPromise = presenceToPromise.get(value);\n if (handledPromise) {\n return handledPromise;\n }\n const basePromise = Promise.resolve(value);\n if (basePromise === value) {\n return value;\n }\n return handledPromiseResolve(value);\n },\n });\n\n defineProperties(HandledPromise, getOwnPropertyDescriptors(staticMethods));\n\n function makeForwarder(operation, localImpl) {\n return (o, ...args) => {\n // We are in another turn already, and have the naked object.\n const fulfilledHandler = presenceToHandler.get(o);\n if (\n fulfilledHandler &&\n typeof fulfilledHandler[operation] === 'function'\n ) {\n // The handler was resolved, so use it.\n return fulfilledHandler[operation](o, ...args);\n }\n\n // Not handled, so use the local implementation.\n return localImpl(o, ...args);\n };\n }\n\n // eslint-disable-next-line prefer-const\n forwardingHandler = {\n get: makeForwarder('get', (o, key) => o[key]),\n applyMethod: makeForwarder('applyMethod', (o, optKey, args) => {\n if (optKey === undefined || optKey === null) {\n return o(...args);\n }\n // console.log(`sending`, optKey, o[optKey], o);\n if (typeof o[optKey] !== 'function') {\n throw TypeError(`o[${JSON.stringify(optKey)}] is not a function`);\n }\n return o[optKey](...args);\n }),\n };\n\n handle = (p, operation, ...args) => {\n ensureMaps();\n const unfulfilledHandler = promiseToHandler.get(p);\n let executor;\n if (\n unfulfilledHandler &&\n typeof unfulfilledHandler[operation] === 'function'\n ) {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve()\n .then(() =>\n // and resolve to the answer from the specific unfulfilled handler,\n resolve(unfulfilledHandler[operation](p, ...args)),\n )\n .catch(reject);\n };\n } else {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve(p)\n .then(o => {\n // We now have the naked object,\n if (typeof forwardingHandler[operation] !== 'function') {\n throw TypeError(\n `forwardingHandler.${operation} is not a function`,\n );\n }\n // and resolve to the forwardingHandler's operation.\n resolve(forwardingHandler[operation](o, ...args));\n })\n .catch(reject);\n };\n }\n\n // We return a handled promise with the default unfulfilled handler.\n // This prevents a race between the above Promise.resolves and\n // pipelining.\n return new HandledPromise(executor);\n };\n\n handledPromiseResolve = Promise.resolve.bind(HandledPromise);\n return harden(HandledPromise);\n}\n\nexports.E = E;\nexports.HandledPromise = hp;\nexports.makeHandledPromise = makeHandledPromise;\n\n\nreturn module.exports;\n}\n","sourceMap":"//# sourceURL=/home/ubuntu/agoric-sdk/packages/eventual-send/dist/eventual-send.cjs.js\n","moduleFormat":"getExport"};
var eventualSendBundle = {"source":"function getExport() { 'use strict'; let exports = {}; const module = { exports }; 'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nfunction _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar harden = _interopDefault(require('@agoric/harden'));\n\nvar commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};\n\nfunction commonjsRequire () {\n\tthrow new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');\n}\n\nfunction unwrapExports (x) {\n\treturn x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;\n}\n\nfunction createCommonjsModule(fn, module) {\n\treturn module = { exports: {} }, fn(module, module.exports), module.exports;\n}\n\nfunction getCjsExportFromNamespace (n) {\n\treturn n && n['default'] || n;\n}\n\nvar eventualSend_cjs = createCommonjsModule(function (module, exports) {\n'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nfunction _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar harden$1 = _interopDefault(harden);\n\n/* global */\n\nconst readOnlyProxy = {\n set(_target, _prop, _value) {\n return false;\n },\n isExtensible(_target) {\n return false;\n },\n setPrototypeOf(_target, _value) {\n return false;\n },\n deleteProperty(_target, _prop) {\n return false;\n },\n};\n\n/**\n * A Proxy handler for E(x).\n *\n * @param {*} x Any value passed to E(x)\n * @returns {ProxyHandler} the Proxy handler\n */\nfunction EProxyHandler(x, HandledPromise) {\n return harden$1({\n ...readOnlyProxy,\n get(_target, p, _receiver) {\n if (`${p}` !== p) {\n return undefined;\n }\n // Harden this Promise because it's our only opportunity to ensure\n // p1=E(x).foo() is hardened. The Handled Promise API does not (yet)\n // allow the handler to synchronously influence the promise returned\n // by the handled methods, so we must freeze it from the outside. See\n // #95 for details.\n return (...args) => harden$1(HandledPromise.applyMethod(x, p, args));\n },\n apply(_target, _thisArg, argArray = []) {\n return harden$1(HandledPromise.applyFunction(x, argArray));\n },\n has(_target, _p) {\n // We just pretend everything exists.\n return true;\n },\n });\n}\n\nfunction makeE(HandledPromise) {\n function E(x) {\n const handler = EProxyHandler(x, HandledPromise);\n return harden$1(new Proxy(() => {}, handler));\n }\n\n const makeEGetterProxy = x =>\n new Proxy(Object.create(null), {\n ...readOnlyProxy,\n has(_target, _prop) {\n return true;\n },\n get(_target, prop) {\n return harden$1(HandledPromise.get(x, prop));\n },\n });\n\n E.G = makeEGetterProxy;\n E.resolve = HandledPromise.resolve;\n E.unwrap = HandledPromise.unwrap;\n\n return harden$1(E);\n}\n\n/* global HandledPromise */\n\nconst {\n defineProperties,\n getOwnPropertyDescriptors,\n getOwnPropertyDescriptor: gopd,\n getPrototypeOf,\n isFrozen,\n} = Object;\n\nconst { prototype: promiseProto } = Promise;\nconst { then: originalThen } = promiseProto;\n\n// 'E' and 'HandledPromise' are exports of the module\n\n// For now:\n// import { HandledPromise, E } from '@agoric/eventual-send';\n// ...\n\nconst hp =\n typeof HandledPromise === 'undefined'\n ? // eslint-disable-next-line no-use-before-define\n makeHandledPromise(Promise)\n : harden$1(HandledPromise);\nconst E = makeE(hp);\n\n// the following method (makeHandledPromise) is part\n// of the shim, and will not be exported by the module once the feature\n// becomes a part of standard javascript\n\n/**\n * Create a HandledPromise class to have it support eventual send\n * (wavy-dot) operations.\n *\n * Based heavily on nanoq\n * https://github.com/drses/nanoq/blob/master/src/nanoq.js\n *\n * Original spec for the infix-bang (predecessor to wavy-dot) desugaring:\n * https://web.archive.org/web/20161026162206/http://wiki.ecmascript.org/doku.php?id=strawman:concurrency\n *\n * @return {typeof HandledPromise} Handled promise\n */\nfunction makeHandledPromise(Promise) {\n // xs doesn't support WeakMap in pre-loaded closures\n // aka \"vetted customization code\"\n let presenceToHandler;\n let presenceToPromise;\n let promiseToHandler;\n let promiseToPresence; // only for HandledPromise.unwrap\n function ensureMaps() {\n if (!presenceToHandler) {\n presenceToHandler = new WeakMap();\n presenceToPromise = new WeakMap();\n promiseToHandler = new WeakMap();\n promiseToPresence = new WeakMap();\n }\n }\n\n // This special handler accepts Promises, and forwards\n // handled Promises to their corresponding fulfilledHandler.\n let forwardingHandler;\n let handle;\n let promiseResolve;\n\n function HandledPromise(executor, unfulfilledHandler = undefined) {\n if (new.target === undefined) {\n throw new Error('must be invoked with \"new\"');\n }\n let handledResolve;\n let handledReject;\n let fulfilled = false;\n const superExecutor = (resolve, reject) => {\n handledResolve = value => {\n fulfilled = true;\n resolve(value);\n };\n handledReject = err => {\n fulfilled = true;\n reject(err);\n };\n };\n const handledP = harden$1(\n Reflect.construct(Promise, [superExecutor], new.target),\n );\n\n ensureMaps();\n let continueForwarding = () => {};\n\n if (!unfulfilledHandler) {\n // Create a simple unfulfilledHandler that just postpones until the\n // fulfilledHandler is set.\n //\n // This is insufficient for actual remote handled Promises\n // (too many round-trips), but is an easy way to create a\n // local handled Promise.\n const interlockP = new Promise((resolve, reject) => {\n continueForwarding = (err = null, targetP = undefined) => {\n if (err !== null) {\n reject(err);\n return;\n }\n // Box the target promise so that it isn't further resolved.\n resolve([targetP]);\n // Return undefined.\n };\n });\n // A failed interlock should not be recorded as an unhandled rejection.\n // It will bubble up to the HandledPromise itself.\n interlockP.catch(_ => {});\n\n const makePostponed = postponedOperation => {\n // Just wait until the handler is resolved/rejected.\n return function postpone(x, ...args) {\n // console.log(`forwarding ${postponedOperation} ${args[0]}`);\n return new HandledPromise((resolve, reject) => {\n interlockP\n .then(([targetP]) => {\n // If targetP is a handled promise, use it, otherwise x.\n const nextPromise = targetP || x;\n resolve(\n HandledPromise[postponedOperation](nextPromise, ...args),\n );\n })\n .catch(reject);\n });\n };\n };\n\n unfulfilledHandler = {\n get: makePostponed('get'),\n applyMethod: makePostponed('applyMethod'),\n };\n }\n\n const validateHandler = h => {\n if (Object(h) !== h) {\n throw TypeError(`Handler ${h} cannot be a primitive`);\n }\n };\n validateHandler(unfulfilledHandler);\n\n // Until the handled promise is resolved, we use the unfulfilledHandler.\n promiseToHandler.set(handledP, unfulfilledHandler);\n\n const rejectHandled = reason => {\n if (fulfilled) {\n return;\n }\n handledReject(reason);\n continueForwarding(reason);\n };\n\n let resolvedPresence = null;\n const resolveWithPresence = presenceHandler => {\n if (fulfilled) {\n return resolvedPresence;\n }\n try {\n // Sanity checks.\n validateHandler(presenceHandler);\n\n // Validate and install our mapped target (i.e. presence).\n resolvedPresence = Object.create(null);\n\n // Create table entries for the presence mapped to the\n // fulfilledHandler.\n presenceToPromise.set(resolvedPresence, handledP);\n promiseToPresence.set(handledP, resolvedPresence);\n presenceToHandler.set(resolvedPresence, presenceHandler);\n\n // Remove the mapping, as our presenceHandler should be\n // used instead.\n promiseToHandler.delete(handledP);\n\n // We committed to this presence, so resolve.\n handledResolve(resolvedPresence);\n continueForwarding();\n return resolvedPresence;\n } catch (e) {\n handledReject(e);\n continueForwarding();\n throw e;\n }\n };\n\n const resolveHandled = async (target, deprecatedPresenceHandler) => {\n if (fulfilled) {\n return undefined;\n }\n try {\n if (deprecatedPresenceHandler) {\n throw TypeError(\n `resolveHandled no longer accepts a handler; use resolveWithPresence`,\n );\n }\n\n // Resolve with the target when it's ready.\n handledResolve(target);\n\n const existingUnfulfilledHandler = promiseToHandler.get(target);\n if (existingUnfulfilledHandler) {\n // Reuse the unfulfilled handler.\n promiseToHandler.set(handledP, existingUnfulfilledHandler);\n return continueForwarding(null, target);\n }\n\n // See if the target is a presence we already know of.\n let presence;\n try {\n presence = HandledPromise.unwrap(target);\n } catch (e) {\n presence = await target;\n }\n const existingPresenceHandler = presenceToHandler.get(presence);\n if (existingPresenceHandler) {\n promiseToHandler.set(handledP, existingPresenceHandler);\n promiseToPresence.set(handledP, presence);\n return continueForwarding(null, handledP);\n }\n\n // Remove the mapping, as we don't need a handler.\n promiseToHandler.delete(handledP);\n return continueForwarding();\n } catch (e) {\n handledReject(e);\n }\n return continueForwarding();\n };\n\n // Invoke the callback to let the user resolve/reject.\n executor(\n (...args) => {\n resolveHandled(...args);\n },\n rejectHandled,\n resolveWithPresence,\n );\n return handledP;\n }\n\n HandledPromise.prototype = promiseProto;\n Object.setPrototypeOf(HandledPromise, Promise);\n\n function isFrozenPromiseThen(p) {\n return (\n isFrozen(p) &&\n getPrototypeOf(p) === promiseProto &&\n promiseResolve(p) === p &&\n gopd(p, 'then') === undefined &&\n gopd(promiseProto, 'then').value === originalThen // unnecessary under SES\n );\n }\n\n const staticMethods = harden$1({\n get(target, key) {\n return handle(target, 'get', key);\n },\n getSendOnly(target, key) {\n handle(target, 'get', key);\n },\n applyFunction(target, args) {\n return handle(target, 'applyMethod', undefined, args);\n },\n applyFunctionSendOnly(target, args) {\n handle(target, 'applyMethod', undefined, args);\n },\n applyMethod(target, key, args) {\n return handle(target, 'applyMethod', key, args);\n },\n applyMethodSendOnly(target, key, args) {\n handle(target, 'applyMethod', key, args);\n },\n resolve(value) {\n ensureMaps();\n // Resolving a Presence returns the pre-registered handled promise.\n let resolvedPromise = presenceToPromise.get(value);\n if (!resolvedPromise) {\n resolvedPromise = promiseResolve(value);\n }\n // Prevent any proxy trickery.\n harden$1(resolvedPromise);\n if (isFrozenPromiseThen(resolvedPromise)) {\n return resolvedPromise;\n }\n // Assimilate the thenable.\n const executeThen = (resolve, reject) =>\n resolvedPromise.then(resolve, reject);\n return harden$1(\n promiseResolve().then(_ => new HandledPromise(executeThen)),\n );\n },\n // TODO verify that this is safe to provide universally, i.e.,\n // that by itself it doesn't provide access to mutable state in\n // ways that violate normal ocap module purity rules. The claim\n // that it does not rests on the handled promise itself being\n // necessary to perceive this mutable state. In that sense, we\n // can think of the right to perceive it, and of access to the\n // target, as being in the handled promise. Note that a .then on\n // the handled promise will already provide async access to the\n // target, so the only additional authorities are: 1)\n // synchronous access for handled promises only, and thus 2) the\n // ability to tell, from the client side, whether a promise is\n // handled. Or, at least, the ability to tell given that the\n // promise is already fulfilled.\n unwrap(value) {\n // This check for Thenable is safe, since in a remote-object\n // environment, our comms system will defend against remote\n // objects being represented as a tricky local Proxy, otherwise\n // it is guaranteed to be local and therefore synchronous enough.\n if (Object(value) !== value || !('then' in value)) {\n // Not a Thenable, so return it.\n // This means that local objects will pass through without error.\n return value;\n }\n\n // Try to look up the HandledPromise.\n ensureMaps();\n const pr = presenceToPromise.get(value) || value;\n\n // Find the fulfilled presence for that HandledPromise.\n const presence = promiseToPresence.get(pr);\n if (!presence) {\n throw TypeError(\n `Value is a Thenble but not a HandledPromise fulfilled to a presence`,\n );\n }\n return presence;\n },\n });\n\n defineProperties(HandledPromise, getOwnPropertyDescriptors(staticMethods));\n\n function makeForwarder(operation, localImpl) {\n return (o, ...args) => {\n // We are in another turn already, and have the naked object.\n const fulfilledHandler = presenceToHandler.get(o);\n if (\n fulfilledHandler &&\n typeof fulfilledHandler[operation] === 'function'\n ) {\n // The handler was resolved, so use it.\n return fulfilledHandler[operation](o, ...args);\n }\n\n // Not handled, so use the local implementation.\n return localImpl(o, ...args);\n };\n }\n\n // eslint-disable-next-line prefer-const\n forwardingHandler = {\n get: makeForwarder('get', (o, key) => o[key]),\n applyMethod: makeForwarder('applyMethod', (o, optKey, args) => {\n if (optKey === undefined || optKey === null) {\n return o(...args);\n }\n // console.log(`sending`, optKey, o[optKey], o);\n if (typeof o[optKey] !== 'function') {\n throw TypeError(`o[${JSON.stringify(optKey)}] is not a function`);\n }\n return o[optKey](...args);\n }),\n };\n\n handle = (p, operation, ...args) => {\n ensureMaps();\n const unfulfilledHandler = promiseToHandler.get(p);\n let executor;\n if (\n unfulfilledHandler &&\n typeof unfulfilledHandler[operation] === 'function'\n ) {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve()\n .then(() =>\n // and resolve to the answer from the specific unfulfilled handler,\n resolve(unfulfilledHandler[operation](p, ...args)),\n )\n .catch(reject);\n };\n } else {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve(p)\n .then(o => {\n // We now have the naked object,\n if (typeof forwardingHandler[operation] !== 'function') {\n throw TypeError(\n `forwardingHandler.${operation} is not a function`,\n );\n }\n // and resolve to the forwardingHandler's operation.\n resolve(forwardingHandler[operation](o, ...args));\n })\n .catch(reject);\n };\n }\n\n // We return a handled promise with the default unfulfilled handler.\n // This prevents a race between the above Promise.resolves and\n // pipelining.\n return new HandledPromise(executor);\n };\n\n promiseResolve = Promise.resolve.bind(Promise);\n return harden$1(HandledPromise);\n}\n\nexports.E = E;\nexports.HandledPromise = hp;\nexports.makeHandledPromise = makeHandledPromise;\n});\n\nvar eventualSend_cjs$1 = unwrapExports(eventualSend_cjs);\nvar eventualSend_cjs_1 = eventualSend_cjs.E;\nvar eventualSend_cjs_2 = eventualSend_cjs.HandledPromise;\nvar eventualSend_cjs_3 = eventualSend_cjs.makeHandledPromise;\n\nexports.E = eventualSend_cjs_1;\nexports.HandledPromise = eventualSend_cjs_2;\nexports.default = eventualSend_cjs$1;\nexports.makeHandledPromise = eventualSend_cjs_3;\n\n\nreturn module.exports;\n}\n","sourceMap":"//# sourceURL=/Users/michael/agoric/agoric-sdk/packages/eventual-send/dist/eventual-send.cjs.js\n","moduleFormat":"getExport"};

@@ -36,6 +36,5 @@ function makeEventualSendTransformer(parser, generate) {

try {
const ns = (evaluateProgram || ss.evaluateProgram)(
`(${evSendSrc})()`,
{ require: myRequire || require },
);
const ns = (
evaluateProgram || ss.evaluateProgram
)(`(${evSendSrc})()`, { require: myRequire || require });
HandledPromise = ns.HandledPromise;

@@ -42,0 +41,0 @@ } finally {

@@ -1,2 +0,2 @@

var eventualSendBundle = {"source":"function getExport() { 'use strict'; let exports = {}; const module = { exports }; 'use strict';\n\n'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nfunction _interopDefault$1 (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar harden = _interopDefault$1(require('@agoric/harden'));\n\n/* global */\n\nconst readOnlyProxy = {\n set(_target, _prop, _value) {\n return false;\n },\n isExtensible(_target) {\n return false;\n },\n setPrototypeOf(_target, _value) {\n return false;\n },\n deleteProperty(_target, _prop) {\n return false;\n },\n};\n\n/**\n * A Proxy handler for E(x).\n *\n * @param {*} x Any value passed to E(x)\n * @returns {ProxyHandler} the Proxy handler\n */\nfunction EProxyHandler(x, HandledPromise) {\n return harden({\n ...readOnlyProxy,\n get(_target, p, _receiver) {\n if (`${p}` !== p) {\n return undefined;\n }\n // Harden this Promise because it's our only opportunity to ensure\n // p1=E(x).foo() is hardened. The Handled Promise API does not (yet)\n // allow the handler to synchronously influence the promise returned\n // by the handled methods, so we must freeze it from the outside. See\n // #95 for details.\n return (...args) => harden(HandledPromise.applyMethod(x, p, args));\n },\n apply(_target, _thisArg, argArray = []) {\n return harden(HandledPromise.applyFunction(x, argArray));\n },\n has(_target, _p) {\n // We just pretend everything exists.\n return true;\n },\n });\n}\n\nfunction makeE(HandledPromise) {\n function E(x) {\n const handler = EProxyHandler(x, HandledPromise);\n return harden(new Proxy(() => {}, handler));\n }\n\n const makeEGetterProxy = x =>\n new Proxy(Object.create(null), {\n ...readOnlyProxy,\n has(_target, _prop) {\n return true;\n },\n get(_target, prop) {\n return HandledPromise.get(x, prop);\n },\n });\n\n E.G = makeEGetterProxy;\n E.resolve = HandledPromise.resolve;\n\n return harden(E);\n}\n\n/* global HandledPromise */\n\nconst { defineProperties, getOwnPropertyDescriptors } = Object;\n\n// 'E' and 'HandledPromise' are exports of the module\n\n// For now:\n// import { HandledPromise, E } from '@agoric/eventual-send';\n// ...\n\nconst hp =\n typeof HandledPromise === 'undefined'\n ? // eslint-disable-next-line no-use-before-define\n makeHandledPromise(Promise)\n : harden(HandledPromise);\nconst E = makeE(hp);\n\n// the following method (makeHandledPromise) is part\n// of the shim, and will not be exported by the module once the feature\n// becomes a part of standard javascript\n\n/**\n * Create a HandledPromise class to have it support eventual send\n * (wavy-dot) operations.\n *\n * Based heavily on nanoq\n * https://github.com/drses/nanoq/blob/master/src/nanoq.js\n *\n * Original spec for the infix-bang (predecessor to wavy-dot) desugaring:\n * https://web.archive.org/web/20161026162206/http://wiki.ecmascript.org/doku.php?id=strawman:concurrency\n *\n * @return {typeof HandledPromise} Handled promise\n */\nfunction makeHandledPromise(Promise) {\n // xs doesn't support WeakMap in pre-loaded closures\n // aka \"vetted customization code\"\n let presenceToHandler;\n let presenceToPromise;\n let promiseToHandler;\n function ensureMaps() {\n if (!presenceToHandler) {\n presenceToHandler = new WeakMap();\n presenceToPromise = new WeakMap();\n promiseToHandler = new WeakMap();\n }\n }\n\n // This special handler accepts Promises, and forwards\n // handled Promises to their corresponding fulfilledHandler.\n let forwardingHandler;\n let handle;\n let handledPromiseResolve;\n\n function HandledPromise(executor, unfulfilledHandler = undefined) {\n if (new.target === undefined) {\n throw new Error('must be invoked with \"new\"');\n }\n let handledResolve;\n let handledReject;\n let fulfilled = false;\n const superExecutor = (resolve, reject) => {\n handledResolve = value => {\n fulfilled = true;\n resolve(value);\n };\n handledReject = err => {\n fulfilled = true;\n reject(err);\n };\n };\n const handledP = harden(\n Reflect.construct(Promise, [superExecutor], new.target),\n );\n\n ensureMaps();\n let continueForwarding = () => {};\n\n if (!unfulfilledHandler) {\n // Create a simple unfulfilledHandler that just postpones until the\n // fulfilledHandler is set.\n //\n // This is insufficient for actual remote handled Promises\n // (too many round-trips), but is an easy way to create a\n // local handled Promise.\n const interlockP = new Promise((resolve, reject) => {\n continueForwarding = (err = null, targetP = undefined) => {\n if (err !== null) {\n reject(err);\n return;\n }\n // Box the target promise so that it isn't further resolved.\n resolve([targetP]);\n // Return undefined.\n };\n });\n\n const makePostponed = postponedOperation => {\n // Just wait until the handler is resolved/rejected.\n return function postpone(x, ...args) {\n // console.log(`forwarding ${postponedOperation} ${args[0]}`);\n return new HandledPromise((resolve, reject) => {\n interlockP\n .then(([targetP]) => {\n // If targetP is a handled promise, use it, otherwise x.\n const nextPromise = targetP || x;\n resolve(\n HandledPromise[postponedOperation](nextPromise, ...args),\n );\n })\n .catch(reject);\n });\n };\n };\n\n unfulfilledHandler = {\n get: makePostponed('get'),\n applyMethod: makePostponed('applyMethod'),\n };\n }\n\n const validateHandler = h => {\n if (Object(h) !== h) {\n throw TypeError(`Handler ${h} cannot be a primitive`);\n }\n };\n validateHandler(unfulfilledHandler);\n\n // Until the handled promise is resolved, we use the unfulfilledHandler.\n promiseToHandler.set(handledP, unfulfilledHandler);\n\n const rejectHandled = reason => {\n if (fulfilled) {\n return;\n }\n handledReject(reason);\n continueForwarding(reason);\n };\n\n let resolvedPresence = null;\n const resolveWithPresence = presenceHandler => {\n if (fulfilled) {\n return resolvedPresence;\n }\n try {\n // Sanity checks.\n validateHandler(presenceHandler);\n\n // Validate and install our mapped target (i.e. presence).\n resolvedPresence = Object.create(null);\n\n // Create table entries for the presence mapped to the\n // fulfilledHandler.\n presenceToPromise.set(resolvedPresence, handledP);\n presenceToHandler.set(resolvedPresence, presenceHandler);\n\n // Remove the mapping, as our presenceHandler should be\n // used instead.\n promiseToHandler.delete(handledP);\n\n // We committed to this presence, so resolve.\n handledResolve(resolvedPresence);\n continueForwarding();\n return resolvedPresence;\n } catch (e) {\n handledReject(e);\n continueForwarding();\n throw e;\n }\n };\n\n const resolveHandled = async (target, deprecatedPresenceHandler) => {\n if (fulfilled) {\n return undefined;\n }\n try {\n if (deprecatedPresenceHandler) {\n throw TypeError(\n `resolveHandled no longer accepts a handler; use resolveWithPresence`,\n );\n }\n\n // Resolve with the target when it's ready.\n handledResolve(target);\n\n const existingUnfulfilledHandler = promiseToHandler.get(target);\n if (existingUnfulfilledHandler) {\n // Reuse the unfulfilled handler.\n promiseToHandler.set(handledP, existingUnfulfilledHandler);\n return continueForwarding(null, target);\n }\n\n // See if the target is a presence we already know of.\n const presence = await target;\n const existingPresenceHandler = presenceToHandler.get(presence);\n if (existingPresenceHandler) {\n promiseToHandler.set(handledP, existingPresenceHandler);\n return continueForwarding(null, handledP);\n }\n\n // Remove the mapping, as we don't need a handler.\n promiseToHandler.delete(handledP);\n return continueForwarding();\n } catch (e) {\n handledReject(e);\n }\n return continueForwarding();\n };\n\n // Invoke the callback to let the user resolve/reject.\n executor(\n (...args) => {\n resolveHandled(...args);\n },\n rejectHandled,\n resolveWithPresence,\n );\n return handledP;\n }\n\n HandledPromise.prototype = Promise.prototype;\n\n // Uncomment this line if needed for conformance to the proposal.\n // Currently the proposal does not specify this, but we might change\n // our mind.\n // Object.setPrototypeOf(HandledPromise, Promise);\n\n const staticMethods = harden({\n get(target, key) {\n return handle(target, 'get', key);\n },\n getSendOnly(target, key) {\n handle(target, 'get', key);\n },\n applyFunction(target, args) {\n return handle(target, 'applyMethod', undefined, args);\n },\n applyFunctionSendOnly(target, args) {\n handle(target, 'applyMethod', undefined, args);\n },\n applyMethod(target, key, args) {\n return handle(target, 'applyMethod', key, args);\n },\n applyMethodSendOnly(target, key, args) {\n handle(target, 'applyMethod', key, args);\n },\n resolve(value) {\n ensureMaps();\n // Resolving a Presence returns the pre-registered handled promise.\n const handledPromise = presenceToPromise.get(value);\n if (handledPromise) {\n return handledPromise;\n }\n const basePromise = Promise.resolve(value);\n if (basePromise === value) {\n return value;\n }\n return handledPromiseResolve(value);\n },\n });\n\n defineProperties(HandledPromise, getOwnPropertyDescriptors(staticMethods));\n\n function makeForwarder(operation, localImpl) {\n return (o, ...args) => {\n // We are in another turn already, and have the naked object.\n const fulfilledHandler = presenceToHandler.get(o);\n if (\n fulfilledHandler &&\n typeof fulfilledHandler[operation] === 'function'\n ) {\n // The handler was resolved, so use it.\n return fulfilledHandler[operation](o, ...args);\n }\n\n // Not handled, so use the local implementation.\n return localImpl(o, ...args);\n };\n }\n\n // eslint-disable-next-line prefer-const\n forwardingHandler = {\n get: makeForwarder('get', (o, key) => o[key]),\n applyMethod: makeForwarder('applyMethod', (o, optKey, args) => {\n if (optKey === undefined || optKey === null) {\n return o(...args);\n }\n // console.log(`sending`, optKey, o[optKey], o);\n if (typeof o[optKey] !== 'function') {\n throw TypeError(`o[${JSON.stringify(optKey)}] is not a function`);\n }\n return o[optKey](...args);\n }),\n };\n\n handle = (p, operation, ...args) => {\n ensureMaps();\n const unfulfilledHandler = promiseToHandler.get(p);\n let executor;\n if (\n unfulfilledHandler &&\n typeof unfulfilledHandler[operation] === 'function'\n ) {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve()\n .then(() =>\n // and resolve to the answer from the specific unfulfilled handler,\n resolve(unfulfilledHandler[operation](p, ...args)),\n )\n .catch(reject);\n };\n } else {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve(p)\n .then(o => {\n // We now have the naked object,\n if (typeof forwardingHandler[operation] !== 'function') {\n throw TypeError(\n `forwardingHandler.${operation} is not a function`,\n );\n }\n // and resolve to the forwardingHandler's operation.\n resolve(forwardingHandler[operation](o, ...args));\n })\n .catch(reject);\n };\n }\n\n // We return a handled promise with the default unfulfilled handler.\n // This prevents a race between the above Promise.resolves and\n // pipelining.\n return new HandledPromise(executor);\n };\n\n handledPromiseResolve = Promise.resolve.bind(HandledPromise);\n return harden(HandledPromise);\n}\n\nexports.E = E;\nexports.HandledPromise = hp;\nexports.makeHandledPromise = makeHandledPromise;\n\n\nreturn module.exports;\n}\n","sourceMap":"//# sourceURL=/home/ubuntu/agoric-sdk/packages/eventual-send/dist/eventual-send.cjs.js\n","moduleFormat":"getExport"};
var eventualSendBundle = {"source":"function getExport() { 'use strict'; let exports = {}; const module = { exports }; 'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nfunction _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar harden = _interopDefault(require('@agoric/harden'));\n\nvar commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};\n\nfunction commonjsRequire () {\n\tthrow new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');\n}\n\nfunction unwrapExports (x) {\n\treturn x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;\n}\n\nfunction createCommonjsModule(fn, module) {\n\treturn module = { exports: {} }, fn(module, module.exports), module.exports;\n}\n\nfunction getCjsExportFromNamespace (n) {\n\treturn n && n['default'] || n;\n}\n\nvar eventualSend_cjs = createCommonjsModule(function (module, exports) {\n'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nfunction _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar harden$1 = _interopDefault(harden);\n\n/* global */\n\nconst readOnlyProxy = {\n set(_target, _prop, _value) {\n return false;\n },\n isExtensible(_target) {\n return false;\n },\n setPrototypeOf(_target, _value) {\n return false;\n },\n deleteProperty(_target, _prop) {\n return false;\n },\n};\n\n/**\n * A Proxy handler for E(x).\n *\n * @param {*} x Any value passed to E(x)\n * @returns {ProxyHandler} the Proxy handler\n */\nfunction EProxyHandler(x, HandledPromise) {\n return harden$1({\n ...readOnlyProxy,\n get(_target, p, _receiver) {\n if (`${p}` !== p) {\n return undefined;\n }\n // Harden this Promise because it's our only opportunity to ensure\n // p1=E(x).foo() is hardened. The Handled Promise API does not (yet)\n // allow the handler to synchronously influence the promise returned\n // by the handled methods, so we must freeze it from the outside. See\n // #95 for details.\n return (...args) => harden$1(HandledPromise.applyMethod(x, p, args));\n },\n apply(_target, _thisArg, argArray = []) {\n return harden$1(HandledPromise.applyFunction(x, argArray));\n },\n has(_target, _p) {\n // We just pretend everything exists.\n return true;\n },\n });\n}\n\nfunction makeE(HandledPromise) {\n function E(x) {\n const handler = EProxyHandler(x, HandledPromise);\n return harden$1(new Proxy(() => {}, handler));\n }\n\n const makeEGetterProxy = x =>\n new Proxy(Object.create(null), {\n ...readOnlyProxy,\n has(_target, _prop) {\n return true;\n },\n get(_target, prop) {\n return harden$1(HandledPromise.get(x, prop));\n },\n });\n\n E.G = makeEGetterProxy;\n E.resolve = HandledPromise.resolve;\n E.unwrap = HandledPromise.unwrap;\n\n return harden$1(E);\n}\n\n/* global HandledPromise */\n\nconst {\n defineProperties,\n getOwnPropertyDescriptors,\n getOwnPropertyDescriptor: gopd,\n getPrototypeOf,\n isFrozen,\n} = Object;\n\nconst { prototype: promiseProto } = Promise;\nconst { then: originalThen } = promiseProto;\n\n// 'E' and 'HandledPromise' are exports of the module\n\n// For now:\n// import { HandledPromise, E } from '@agoric/eventual-send';\n// ...\n\nconst hp =\n typeof HandledPromise === 'undefined'\n ? // eslint-disable-next-line no-use-before-define\n makeHandledPromise(Promise)\n : harden$1(HandledPromise);\nconst E = makeE(hp);\n\n// the following method (makeHandledPromise) is part\n// of the shim, and will not be exported by the module once the feature\n// becomes a part of standard javascript\n\n/**\n * Create a HandledPromise class to have it support eventual send\n * (wavy-dot) operations.\n *\n * Based heavily on nanoq\n * https://github.com/drses/nanoq/blob/master/src/nanoq.js\n *\n * Original spec for the infix-bang (predecessor to wavy-dot) desugaring:\n * https://web.archive.org/web/20161026162206/http://wiki.ecmascript.org/doku.php?id=strawman:concurrency\n *\n * @return {typeof HandledPromise} Handled promise\n */\nfunction makeHandledPromise(Promise) {\n // xs doesn't support WeakMap in pre-loaded closures\n // aka \"vetted customization code\"\n let presenceToHandler;\n let presenceToPromise;\n let promiseToHandler;\n let promiseToPresence; // only for HandledPromise.unwrap\n function ensureMaps() {\n if (!presenceToHandler) {\n presenceToHandler = new WeakMap();\n presenceToPromise = new WeakMap();\n promiseToHandler = new WeakMap();\n promiseToPresence = new WeakMap();\n }\n }\n\n // This special handler accepts Promises, and forwards\n // handled Promises to their corresponding fulfilledHandler.\n let forwardingHandler;\n let handle;\n let promiseResolve;\n\n function HandledPromise(executor, unfulfilledHandler = undefined) {\n if (new.target === undefined) {\n throw new Error('must be invoked with \"new\"');\n }\n let handledResolve;\n let handledReject;\n let fulfilled = false;\n const superExecutor = (resolve, reject) => {\n handledResolve = value => {\n fulfilled = true;\n resolve(value);\n };\n handledReject = err => {\n fulfilled = true;\n reject(err);\n };\n };\n const handledP = harden$1(\n Reflect.construct(Promise, [superExecutor], new.target),\n );\n\n ensureMaps();\n let continueForwarding = () => {};\n\n if (!unfulfilledHandler) {\n // Create a simple unfulfilledHandler that just postpones until the\n // fulfilledHandler is set.\n //\n // This is insufficient for actual remote handled Promises\n // (too many round-trips), but is an easy way to create a\n // local handled Promise.\n const interlockP = new Promise((resolve, reject) => {\n continueForwarding = (err = null, targetP = undefined) => {\n if (err !== null) {\n reject(err);\n return;\n }\n // Box the target promise so that it isn't further resolved.\n resolve([targetP]);\n // Return undefined.\n };\n });\n // A failed interlock should not be recorded as an unhandled rejection.\n // It will bubble up to the HandledPromise itself.\n interlockP.catch(_ => {});\n\n const makePostponed = postponedOperation => {\n // Just wait until the handler is resolved/rejected.\n return function postpone(x, ...args) {\n // console.log(`forwarding ${postponedOperation} ${args[0]}`);\n return new HandledPromise((resolve, reject) => {\n interlockP\n .then(([targetP]) => {\n // If targetP is a handled promise, use it, otherwise x.\n const nextPromise = targetP || x;\n resolve(\n HandledPromise[postponedOperation](nextPromise, ...args),\n );\n })\n .catch(reject);\n });\n };\n };\n\n unfulfilledHandler = {\n get: makePostponed('get'),\n applyMethod: makePostponed('applyMethod'),\n };\n }\n\n const validateHandler = h => {\n if (Object(h) !== h) {\n throw TypeError(`Handler ${h} cannot be a primitive`);\n }\n };\n validateHandler(unfulfilledHandler);\n\n // Until the handled promise is resolved, we use the unfulfilledHandler.\n promiseToHandler.set(handledP, unfulfilledHandler);\n\n const rejectHandled = reason => {\n if (fulfilled) {\n return;\n }\n handledReject(reason);\n continueForwarding(reason);\n };\n\n let resolvedPresence = null;\n const resolveWithPresence = presenceHandler => {\n if (fulfilled) {\n return resolvedPresence;\n }\n try {\n // Sanity checks.\n validateHandler(presenceHandler);\n\n // Validate and install our mapped target (i.e. presence).\n resolvedPresence = Object.create(null);\n\n // Create table entries for the presence mapped to the\n // fulfilledHandler.\n presenceToPromise.set(resolvedPresence, handledP);\n promiseToPresence.set(handledP, resolvedPresence);\n presenceToHandler.set(resolvedPresence, presenceHandler);\n\n // Remove the mapping, as our presenceHandler should be\n // used instead.\n promiseToHandler.delete(handledP);\n\n // We committed to this presence, so resolve.\n handledResolve(resolvedPresence);\n continueForwarding();\n return resolvedPresence;\n } catch (e) {\n handledReject(e);\n continueForwarding();\n throw e;\n }\n };\n\n const resolveHandled = async (target, deprecatedPresenceHandler) => {\n if (fulfilled) {\n return undefined;\n }\n try {\n if (deprecatedPresenceHandler) {\n throw TypeError(\n `resolveHandled no longer accepts a handler; use resolveWithPresence`,\n );\n }\n\n // Resolve with the target when it's ready.\n handledResolve(target);\n\n const existingUnfulfilledHandler = promiseToHandler.get(target);\n if (existingUnfulfilledHandler) {\n // Reuse the unfulfilled handler.\n promiseToHandler.set(handledP, existingUnfulfilledHandler);\n return continueForwarding(null, target);\n }\n\n // See if the target is a presence we already know of.\n let presence;\n try {\n presence = HandledPromise.unwrap(target);\n } catch (e) {\n presence = await target;\n }\n const existingPresenceHandler = presenceToHandler.get(presence);\n if (existingPresenceHandler) {\n promiseToHandler.set(handledP, existingPresenceHandler);\n promiseToPresence.set(handledP, presence);\n return continueForwarding(null, handledP);\n }\n\n // Remove the mapping, as we don't need a handler.\n promiseToHandler.delete(handledP);\n return continueForwarding();\n } catch (e) {\n handledReject(e);\n }\n return continueForwarding();\n };\n\n // Invoke the callback to let the user resolve/reject.\n executor(\n (...args) => {\n resolveHandled(...args);\n },\n rejectHandled,\n resolveWithPresence,\n );\n return handledP;\n }\n\n HandledPromise.prototype = promiseProto;\n Object.setPrototypeOf(HandledPromise, Promise);\n\n function isFrozenPromiseThen(p) {\n return (\n isFrozen(p) &&\n getPrototypeOf(p) === promiseProto &&\n promiseResolve(p) === p &&\n gopd(p, 'then') === undefined &&\n gopd(promiseProto, 'then').value === originalThen // unnecessary under SES\n );\n }\n\n const staticMethods = harden$1({\n get(target, key) {\n return handle(target, 'get', key);\n },\n getSendOnly(target, key) {\n handle(target, 'get', key);\n },\n applyFunction(target, args) {\n return handle(target, 'applyMethod', undefined, args);\n },\n applyFunctionSendOnly(target, args) {\n handle(target, 'applyMethod', undefined, args);\n },\n applyMethod(target, key, args) {\n return handle(target, 'applyMethod', key, args);\n },\n applyMethodSendOnly(target, key, args) {\n handle(target, 'applyMethod', key, args);\n },\n resolve(value) {\n ensureMaps();\n // Resolving a Presence returns the pre-registered handled promise.\n let resolvedPromise = presenceToPromise.get(value);\n if (!resolvedPromise) {\n resolvedPromise = promiseResolve(value);\n }\n // Prevent any proxy trickery.\n harden$1(resolvedPromise);\n if (isFrozenPromiseThen(resolvedPromise)) {\n return resolvedPromise;\n }\n // Assimilate the thenable.\n const executeThen = (resolve, reject) =>\n resolvedPromise.then(resolve, reject);\n return harden$1(\n promiseResolve().then(_ => new HandledPromise(executeThen)),\n );\n },\n // TODO verify that this is safe to provide universally, i.e.,\n // that by itself it doesn't provide access to mutable state in\n // ways that violate normal ocap module purity rules. The claim\n // that it does not rests on the handled promise itself being\n // necessary to perceive this mutable state. In that sense, we\n // can think of the right to perceive it, and of access to the\n // target, as being in the handled promise. Note that a .then on\n // the handled promise will already provide async access to the\n // target, so the only additional authorities are: 1)\n // synchronous access for handled promises only, and thus 2) the\n // ability to tell, from the client side, whether a promise is\n // handled. Or, at least, the ability to tell given that the\n // promise is already fulfilled.\n unwrap(value) {\n // This check for Thenable is safe, since in a remote-object\n // environment, our comms system will defend against remote\n // objects being represented as a tricky local Proxy, otherwise\n // it is guaranteed to be local and therefore synchronous enough.\n if (Object(value) !== value || !('then' in value)) {\n // Not a Thenable, so return it.\n // This means that local objects will pass through without error.\n return value;\n }\n\n // Try to look up the HandledPromise.\n ensureMaps();\n const pr = presenceToPromise.get(value) || value;\n\n // Find the fulfilled presence for that HandledPromise.\n const presence = promiseToPresence.get(pr);\n if (!presence) {\n throw TypeError(\n `Value is a Thenble but not a HandledPromise fulfilled to a presence`,\n );\n }\n return presence;\n },\n });\n\n defineProperties(HandledPromise, getOwnPropertyDescriptors(staticMethods));\n\n function makeForwarder(operation, localImpl) {\n return (o, ...args) => {\n // We are in another turn already, and have the naked object.\n const fulfilledHandler = presenceToHandler.get(o);\n if (\n fulfilledHandler &&\n typeof fulfilledHandler[operation] === 'function'\n ) {\n // The handler was resolved, so use it.\n return fulfilledHandler[operation](o, ...args);\n }\n\n // Not handled, so use the local implementation.\n return localImpl(o, ...args);\n };\n }\n\n // eslint-disable-next-line prefer-const\n forwardingHandler = {\n get: makeForwarder('get', (o, key) => o[key]),\n applyMethod: makeForwarder('applyMethod', (o, optKey, args) => {\n if (optKey === undefined || optKey === null) {\n return o(...args);\n }\n // console.log(`sending`, optKey, o[optKey], o);\n if (typeof o[optKey] !== 'function') {\n throw TypeError(`o[${JSON.stringify(optKey)}] is not a function`);\n }\n return o[optKey](...args);\n }),\n };\n\n handle = (p, operation, ...args) => {\n ensureMaps();\n const unfulfilledHandler = promiseToHandler.get(p);\n let executor;\n if (\n unfulfilledHandler &&\n typeof unfulfilledHandler[operation] === 'function'\n ) {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve()\n .then(() =>\n // and resolve to the answer from the specific unfulfilled handler,\n resolve(unfulfilledHandler[operation](p, ...args)),\n )\n .catch(reject);\n };\n } else {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve(p)\n .then(o => {\n // We now have the naked object,\n if (typeof forwardingHandler[operation] !== 'function') {\n throw TypeError(\n `forwardingHandler.${operation} is not a function`,\n );\n }\n // and resolve to the forwardingHandler's operation.\n resolve(forwardingHandler[operation](o, ...args));\n })\n .catch(reject);\n };\n }\n\n // We return a handled promise with the default unfulfilled handler.\n // This prevents a race between the above Promise.resolves and\n // pipelining.\n return new HandledPromise(executor);\n };\n\n promiseResolve = Promise.resolve.bind(Promise);\n return harden$1(HandledPromise);\n}\n\nexports.E = E;\nexports.HandledPromise = hp;\nexports.makeHandledPromise = makeHandledPromise;\n});\n\nvar eventualSend_cjs$1 = unwrapExports(eventualSend_cjs);\nvar eventualSend_cjs_1 = eventualSend_cjs.E;\nvar eventualSend_cjs_2 = eventualSend_cjs.HandledPromise;\nvar eventualSend_cjs_3 = eventualSend_cjs.makeHandledPromise;\n\nexports.E = eventualSend_cjs_1;\nexports.HandledPromise = eventualSend_cjs_2;\nexports.default = eventualSend_cjs$1;\nexports.makeHandledPromise = eventualSend_cjs_3;\n\n\nreturn module.exports;\n}\n","sourceMap":"//# sourceURL=/Users/michael/agoric/agoric-sdk/packages/eventual-send/dist/eventual-send.cjs.js\n","moduleFormat":"getExport"};

@@ -34,6 +34,5 @@ function makeEventualSendTransformer(parser, generate) {

try {
const ns = (evaluateProgram || ss.evaluateProgram)(
`(${evSendSrc})()`,
{ require: myRequire || require },
);
const ns = (
evaluateProgram || ss.evaluateProgram
)(`(${evSendSrc})()`, { require: myRequire || require });
HandledPromise = ns.HandledPromise;

@@ -40,0 +39,0 @@ } finally {

@@ -7,3 +7,3 @@ (function (global, factory) {

var eventualSendBundle = {"source":"function getExport() { 'use strict'; let exports = {}; const module = { exports }; 'use strict';\n\n'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nfunction _interopDefault$1 (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar harden = _interopDefault$1(require('@agoric/harden'));\n\n/* global */\n\nconst readOnlyProxy = {\n set(_target, _prop, _value) {\n return false;\n },\n isExtensible(_target) {\n return false;\n },\n setPrototypeOf(_target, _value) {\n return false;\n },\n deleteProperty(_target, _prop) {\n return false;\n },\n};\n\n/**\n * A Proxy handler for E(x).\n *\n * @param {*} x Any value passed to E(x)\n * @returns {ProxyHandler} the Proxy handler\n */\nfunction EProxyHandler(x, HandledPromise) {\n return harden({\n ...readOnlyProxy,\n get(_target, p, _receiver) {\n if (`${p}` !== p) {\n return undefined;\n }\n // Harden this Promise because it's our only opportunity to ensure\n // p1=E(x).foo() is hardened. The Handled Promise API does not (yet)\n // allow the handler to synchronously influence the promise returned\n // by the handled methods, so we must freeze it from the outside. See\n // #95 for details.\n return (...args) => harden(HandledPromise.applyMethod(x, p, args));\n },\n apply(_target, _thisArg, argArray = []) {\n return harden(HandledPromise.applyFunction(x, argArray));\n },\n has(_target, _p) {\n // We just pretend everything exists.\n return true;\n },\n });\n}\n\nfunction makeE(HandledPromise) {\n function E(x) {\n const handler = EProxyHandler(x, HandledPromise);\n return harden(new Proxy(() => {}, handler));\n }\n\n const makeEGetterProxy = x =>\n new Proxy(Object.create(null), {\n ...readOnlyProxy,\n has(_target, _prop) {\n return true;\n },\n get(_target, prop) {\n return HandledPromise.get(x, prop);\n },\n });\n\n E.G = makeEGetterProxy;\n E.resolve = HandledPromise.resolve;\n\n return harden(E);\n}\n\n/* global HandledPromise */\n\nconst { defineProperties, getOwnPropertyDescriptors } = Object;\n\n// 'E' and 'HandledPromise' are exports of the module\n\n// For now:\n// import { HandledPromise, E } from '@agoric/eventual-send';\n// ...\n\nconst hp =\n typeof HandledPromise === 'undefined'\n ? // eslint-disable-next-line no-use-before-define\n makeHandledPromise(Promise)\n : harden(HandledPromise);\nconst E = makeE(hp);\n\n// the following method (makeHandledPromise) is part\n// of the shim, and will not be exported by the module once the feature\n// becomes a part of standard javascript\n\n/**\n * Create a HandledPromise class to have it support eventual send\n * (wavy-dot) operations.\n *\n * Based heavily on nanoq\n * https://github.com/drses/nanoq/blob/master/src/nanoq.js\n *\n * Original spec for the infix-bang (predecessor to wavy-dot) desugaring:\n * https://web.archive.org/web/20161026162206/http://wiki.ecmascript.org/doku.php?id=strawman:concurrency\n *\n * @return {typeof HandledPromise} Handled promise\n */\nfunction makeHandledPromise(Promise) {\n // xs doesn't support WeakMap in pre-loaded closures\n // aka \"vetted customization code\"\n let presenceToHandler;\n let presenceToPromise;\n let promiseToHandler;\n function ensureMaps() {\n if (!presenceToHandler) {\n presenceToHandler = new WeakMap();\n presenceToPromise = new WeakMap();\n promiseToHandler = new WeakMap();\n }\n }\n\n // This special handler accepts Promises, and forwards\n // handled Promises to their corresponding fulfilledHandler.\n let forwardingHandler;\n let handle;\n let handledPromiseResolve;\n\n function HandledPromise(executor, unfulfilledHandler = undefined) {\n if (new.target === undefined) {\n throw new Error('must be invoked with \"new\"');\n }\n let handledResolve;\n let handledReject;\n let fulfilled = false;\n const superExecutor = (resolve, reject) => {\n handledResolve = value => {\n fulfilled = true;\n resolve(value);\n };\n handledReject = err => {\n fulfilled = true;\n reject(err);\n };\n };\n const handledP = harden(\n Reflect.construct(Promise, [superExecutor], new.target),\n );\n\n ensureMaps();\n let continueForwarding = () => {};\n\n if (!unfulfilledHandler) {\n // Create a simple unfulfilledHandler that just postpones until the\n // fulfilledHandler is set.\n //\n // This is insufficient for actual remote handled Promises\n // (too many round-trips), but is an easy way to create a\n // local handled Promise.\n const interlockP = new Promise((resolve, reject) => {\n continueForwarding = (err = null, targetP = undefined) => {\n if (err !== null) {\n reject(err);\n return;\n }\n // Box the target promise so that it isn't further resolved.\n resolve([targetP]);\n // Return undefined.\n };\n });\n\n const makePostponed = postponedOperation => {\n // Just wait until the handler is resolved/rejected.\n return function postpone(x, ...args) {\n // console.log(`forwarding ${postponedOperation} ${args[0]}`);\n return new HandledPromise((resolve, reject) => {\n interlockP\n .then(([targetP]) => {\n // If targetP is a handled promise, use it, otherwise x.\n const nextPromise = targetP || x;\n resolve(\n HandledPromise[postponedOperation](nextPromise, ...args),\n );\n })\n .catch(reject);\n });\n };\n };\n\n unfulfilledHandler = {\n get: makePostponed('get'),\n applyMethod: makePostponed('applyMethod'),\n };\n }\n\n const validateHandler = h => {\n if (Object(h) !== h) {\n throw TypeError(`Handler ${h} cannot be a primitive`);\n }\n };\n validateHandler(unfulfilledHandler);\n\n // Until the handled promise is resolved, we use the unfulfilledHandler.\n promiseToHandler.set(handledP, unfulfilledHandler);\n\n const rejectHandled = reason => {\n if (fulfilled) {\n return;\n }\n handledReject(reason);\n continueForwarding(reason);\n };\n\n let resolvedPresence = null;\n const resolveWithPresence = presenceHandler => {\n if (fulfilled) {\n return resolvedPresence;\n }\n try {\n // Sanity checks.\n validateHandler(presenceHandler);\n\n // Validate and install our mapped target (i.e. presence).\n resolvedPresence = Object.create(null);\n\n // Create table entries for the presence mapped to the\n // fulfilledHandler.\n presenceToPromise.set(resolvedPresence, handledP);\n presenceToHandler.set(resolvedPresence, presenceHandler);\n\n // Remove the mapping, as our presenceHandler should be\n // used instead.\n promiseToHandler.delete(handledP);\n\n // We committed to this presence, so resolve.\n handledResolve(resolvedPresence);\n continueForwarding();\n return resolvedPresence;\n } catch (e) {\n handledReject(e);\n continueForwarding();\n throw e;\n }\n };\n\n const resolveHandled = async (target, deprecatedPresenceHandler) => {\n if (fulfilled) {\n return undefined;\n }\n try {\n if (deprecatedPresenceHandler) {\n throw TypeError(\n `resolveHandled no longer accepts a handler; use resolveWithPresence`,\n );\n }\n\n // Resolve with the target when it's ready.\n handledResolve(target);\n\n const existingUnfulfilledHandler = promiseToHandler.get(target);\n if (existingUnfulfilledHandler) {\n // Reuse the unfulfilled handler.\n promiseToHandler.set(handledP, existingUnfulfilledHandler);\n return continueForwarding(null, target);\n }\n\n // See if the target is a presence we already know of.\n const presence = await target;\n const existingPresenceHandler = presenceToHandler.get(presence);\n if (existingPresenceHandler) {\n promiseToHandler.set(handledP, existingPresenceHandler);\n return continueForwarding(null, handledP);\n }\n\n // Remove the mapping, as we don't need a handler.\n promiseToHandler.delete(handledP);\n return continueForwarding();\n } catch (e) {\n handledReject(e);\n }\n return continueForwarding();\n };\n\n // Invoke the callback to let the user resolve/reject.\n executor(\n (...args) => {\n resolveHandled(...args);\n },\n rejectHandled,\n resolveWithPresence,\n );\n return handledP;\n }\n\n HandledPromise.prototype = Promise.prototype;\n\n // Uncomment this line if needed for conformance to the proposal.\n // Currently the proposal does not specify this, but we might change\n // our mind.\n // Object.setPrototypeOf(HandledPromise, Promise);\n\n const staticMethods = harden({\n get(target, key) {\n return handle(target, 'get', key);\n },\n getSendOnly(target, key) {\n handle(target, 'get', key);\n },\n applyFunction(target, args) {\n return handle(target, 'applyMethod', undefined, args);\n },\n applyFunctionSendOnly(target, args) {\n handle(target, 'applyMethod', undefined, args);\n },\n applyMethod(target, key, args) {\n return handle(target, 'applyMethod', key, args);\n },\n applyMethodSendOnly(target, key, args) {\n handle(target, 'applyMethod', key, args);\n },\n resolve(value) {\n ensureMaps();\n // Resolving a Presence returns the pre-registered handled promise.\n const handledPromise = presenceToPromise.get(value);\n if (handledPromise) {\n return handledPromise;\n }\n const basePromise = Promise.resolve(value);\n if (basePromise === value) {\n return value;\n }\n return handledPromiseResolve(value);\n },\n });\n\n defineProperties(HandledPromise, getOwnPropertyDescriptors(staticMethods));\n\n function makeForwarder(operation, localImpl) {\n return (o, ...args) => {\n // We are in another turn already, and have the naked object.\n const fulfilledHandler = presenceToHandler.get(o);\n if (\n fulfilledHandler &&\n typeof fulfilledHandler[operation] === 'function'\n ) {\n // The handler was resolved, so use it.\n return fulfilledHandler[operation](o, ...args);\n }\n\n // Not handled, so use the local implementation.\n return localImpl(o, ...args);\n };\n }\n\n // eslint-disable-next-line prefer-const\n forwardingHandler = {\n get: makeForwarder('get', (o, key) => o[key]),\n applyMethod: makeForwarder('applyMethod', (o, optKey, args) => {\n if (optKey === undefined || optKey === null) {\n return o(...args);\n }\n // console.log(`sending`, optKey, o[optKey], o);\n if (typeof o[optKey] !== 'function') {\n throw TypeError(`o[${JSON.stringify(optKey)}] is not a function`);\n }\n return o[optKey](...args);\n }),\n };\n\n handle = (p, operation, ...args) => {\n ensureMaps();\n const unfulfilledHandler = promiseToHandler.get(p);\n let executor;\n if (\n unfulfilledHandler &&\n typeof unfulfilledHandler[operation] === 'function'\n ) {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve()\n .then(() =>\n // and resolve to the answer from the specific unfulfilled handler,\n resolve(unfulfilledHandler[operation](p, ...args)),\n )\n .catch(reject);\n };\n } else {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve(p)\n .then(o => {\n // We now have the naked object,\n if (typeof forwardingHandler[operation] !== 'function') {\n throw TypeError(\n `forwardingHandler.${operation} is not a function`,\n );\n }\n // and resolve to the forwardingHandler's operation.\n resolve(forwardingHandler[operation](o, ...args));\n })\n .catch(reject);\n };\n }\n\n // We return a handled promise with the default unfulfilled handler.\n // This prevents a race between the above Promise.resolves and\n // pipelining.\n return new HandledPromise(executor);\n };\n\n handledPromiseResolve = Promise.resolve.bind(HandledPromise);\n return harden(HandledPromise);\n}\n\nexports.E = E;\nexports.HandledPromise = hp;\nexports.makeHandledPromise = makeHandledPromise;\n\n\nreturn module.exports;\n}\n","sourceMap":"//# sourceURL=/home/ubuntu/agoric-sdk/packages/eventual-send/dist/eventual-send.cjs.js\n","moduleFormat":"getExport"};
var eventualSendBundle = {"source":"function getExport() { 'use strict'; let exports = {}; const module = { exports }; 'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nfunction _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar harden = _interopDefault(require('@agoric/harden'));\n\nvar commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};\n\nfunction commonjsRequire () {\n\tthrow new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');\n}\n\nfunction unwrapExports (x) {\n\treturn x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;\n}\n\nfunction createCommonjsModule(fn, module) {\n\treturn module = { exports: {} }, fn(module, module.exports), module.exports;\n}\n\nfunction getCjsExportFromNamespace (n) {\n\treturn n && n['default'] || n;\n}\n\nvar eventualSend_cjs = createCommonjsModule(function (module, exports) {\n'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nfunction _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar harden$1 = _interopDefault(harden);\n\n/* global */\n\nconst readOnlyProxy = {\n set(_target, _prop, _value) {\n return false;\n },\n isExtensible(_target) {\n return false;\n },\n setPrototypeOf(_target, _value) {\n return false;\n },\n deleteProperty(_target, _prop) {\n return false;\n },\n};\n\n/**\n * A Proxy handler for E(x).\n *\n * @param {*} x Any value passed to E(x)\n * @returns {ProxyHandler} the Proxy handler\n */\nfunction EProxyHandler(x, HandledPromise) {\n return harden$1({\n ...readOnlyProxy,\n get(_target, p, _receiver) {\n if (`${p}` !== p) {\n return undefined;\n }\n // Harden this Promise because it's our only opportunity to ensure\n // p1=E(x).foo() is hardened. The Handled Promise API does not (yet)\n // allow the handler to synchronously influence the promise returned\n // by the handled methods, so we must freeze it from the outside. See\n // #95 for details.\n return (...args) => harden$1(HandledPromise.applyMethod(x, p, args));\n },\n apply(_target, _thisArg, argArray = []) {\n return harden$1(HandledPromise.applyFunction(x, argArray));\n },\n has(_target, _p) {\n // We just pretend everything exists.\n return true;\n },\n });\n}\n\nfunction makeE(HandledPromise) {\n function E(x) {\n const handler = EProxyHandler(x, HandledPromise);\n return harden$1(new Proxy(() => {}, handler));\n }\n\n const makeEGetterProxy = x =>\n new Proxy(Object.create(null), {\n ...readOnlyProxy,\n has(_target, _prop) {\n return true;\n },\n get(_target, prop) {\n return harden$1(HandledPromise.get(x, prop));\n },\n });\n\n E.G = makeEGetterProxy;\n E.resolve = HandledPromise.resolve;\n E.unwrap = HandledPromise.unwrap;\n\n return harden$1(E);\n}\n\n/* global HandledPromise */\n\nconst {\n defineProperties,\n getOwnPropertyDescriptors,\n getOwnPropertyDescriptor: gopd,\n getPrototypeOf,\n isFrozen,\n} = Object;\n\nconst { prototype: promiseProto } = Promise;\nconst { then: originalThen } = promiseProto;\n\n// 'E' and 'HandledPromise' are exports of the module\n\n// For now:\n// import { HandledPromise, E } from '@agoric/eventual-send';\n// ...\n\nconst hp =\n typeof HandledPromise === 'undefined'\n ? // eslint-disable-next-line no-use-before-define\n makeHandledPromise(Promise)\n : harden$1(HandledPromise);\nconst E = makeE(hp);\n\n// the following method (makeHandledPromise) is part\n// of the shim, and will not be exported by the module once the feature\n// becomes a part of standard javascript\n\n/**\n * Create a HandledPromise class to have it support eventual send\n * (wavy-dot) operations.\n *\n * Based heavily on nanoq\n * https://github.com/drses/nanoq/blob/master/src/nanoq.js\n *\n * Original spec for the infix-bang (predecessor to wavy-dot) desugaring:\n * https://web.archive.org/web/20161026162206/http://wiki.ecmascript.org/doku.php?id=strawman:concurrency\n *\n * @return {typeof HandledPromise} Handled promise\n */\nfunction makeHandledPromise(Promise) {\n // xs doesn't support WeakMap in pre-loaded closures\n // aka \"vetted customization code\"\n let presenceToHandler;\n let presenceToPromise;\n let promiseToHandler;\n let promiseToPresence; // only for HandledPromise.unwrap\n function ensureMaps() {\n if (!presenceToHandler) {\n presenceToHandler = new WeakMap();\n presenceToPromise = new WeakMap();\n promiseToHandler = new WeakMap();\n promiseToPresence = new WeakMap();\n }\n }\n\n // This special handler accepts Promises, and forwards\n // handled Promises to their corresponding fulfilledHandler.\n let forwardingHandler;\n let handle;\n let promiseResolve;\n\n function HandledPromise(executor, unfulfilledHandler = undefined) {\n if (new.target === undefined) {\n throw new Error('must be invoked with \"new\"');\n }\n let handledResolve;\n let handledReject;\n let fulfilled = false;\n const superExecutor = (resolve, reject) => {\n handledResolve = value => {\n fulfilled = true;\n resolve(value);\n };\n handledReject = err => {\n fulfilled = true;\n reject(err);\n };\n };\n const handledP = harden$1(\n Reflect.construct(Promise, [superExecutor], new.target),\n );\n\n ensureMaps();\n let continueForwarding = () => {};\n\n if (!unfulfilledHandler) {\n // Create a simple unfulfilledHandler that just postpones until the\n // fulfilledHandler is set.\n //\n // This is insufficient for actual remote handled Promises\n // (too many round-trips), but is an easy way to create a\n // local handled Promise.\n const interlockP = new Promise((resolve, reject) => {\n continueForwarding = (err = null, targetP = undefined) => {\n if (err !== null) {\n reject(err);\n return;\n }\n // Box the target promise so that it isn't further resolved.\n resolve([targetP]);\n // Return undefined.\n };\n });\n // A failed interlock should not be recorded as an unhandled rejection.\n // It will bubble up to the HandledPromise itself.\n interlockP.catch(_ => {});\n\n const makePostponed = postponedOperation => {\n // Just wait until the handler is resolved/rejected.\n return function postpone(x, ...args) {\n // console.log(`forwarding ${postponedOperation} ${args[0]}`);\n return new HandledPromise((resolve, reject) => {\n interlockP\n .then(([targetP]) => {\n // If targetP is a handled promise, use it, otherwise x.\n const nextPromise = targetP || x;\n resolve(\n HandledPromise[postponedOperation](nextPromise, ...args),\n );\n })\n .catch(reject);\n });\n };\n };\n\n unfulfilledHandler = {\n get: makePostponed('get'),\n applyMethod: makePostponed('applyMethod'),\n };\n }\n\n const validateHandler = h => {\n if (Object(h) !== h) {\n throw TypeError(`Handler ${h} cannot be a primitive`);\n }\n };\n validateHandler(unfulfilledHandler);\n\n // Until the handled promise is resolved, we use the unfulfilledHandler.\n promiseToHandler.set(handledP, unfulfilledHandler);\n\n const rejectHandled = reason => {\n if (fulfilled) {\n return;\n }\n handledReject(reason);\n continueForwarding(reason);\n };\n\n let resolvedPresence = null;\n const resolveWithPresence = presenceHandler => {\n if (fulfilled) {\n return resolvedPresence;\n }\n try {\n // Sanity checks.\n validateHandler(presenceHandler);\n\n // Validate and install our mapped target (i.e. presence).\n resolvedPresence = Object.create(null);\n\n // Create table entries for the presence mapped to the\n // fulfilledHandler.\n presenceToPromise.set(resolvedPresence, handledP);\n promiseToPresence.set(handledP, resolvedPresence);\n presenceToHandler.set(resolvedPresence, presenceHandler);\n\n // Remove the mapping, as our presenceHandler should be\n // used instead.\n promiseToHandler.delete(handledP);\n\n // We committed to this presence, so resolve.\n handledResolve(resolvedPresence);\n continueForwarding();\n return resolvedPresence;\n } catch (e) {\n handledReject(e);\n continueForwarding();\n throw e;\n }\n };\n\n const resolveHandled = async (target, deprecatedPresenceHandler) => {\n if (fulfilled) {\n return undefined;\n }\n try {\n if (deprecatedPresenceHandler) {\n throw TypeError(\n `resolveHandled no longer accepts a handler; use resolveWithPresence`,\n );\n }\n\n // Resolve with the target when it's ready.\n handledResolve(target);\n\n const existingUnfulfilledHandler = promiseToHandler.get(target);\n if (existingUnfulfilledHandler) {\n // Reuse the unfulfilled handler.\n promiseToHandler.set(handledP, existingUnfulfilledHandler);\n return continueForwarding(null, target);\n }\n\n // See if the target is a presence we already know of.\n let presence;\n try {\n presence = HandledPromise.unwrap(target);\n } catch (e) {\n presence = await target;\n }\n const existingPresenceHandler = presenceToHandler.get(presence);\n if (existingPresenceHandler) {\n promiseToHandler.set(handledP, existingPresenceHandler);\n promiseToPresence.set(handledP, presence);\n return continueForwarding(null, handledP);\n }\n\n // Remove the mapping, as we don't need a handler.\n promiseToHandler.delete(handledP);\n return continueForwarding();\n } catch (e) {\n handledReject(e);\n }\n return continueForwarding();\n };\n\n // Invoke the callback to let the user resolve/reject.\n executor(\n (...args) => {\n resolveHandled(...args);\n },\n rejectHandled,\n resolveWithPresence,\n );\n return handledP;\n }\n\n HandledPromise.prototype = promiseProto;\n Object.setPrototypeOf(HandledPromise, Promise);\n\n function isFrozenPromiseThen(p) {\n return (\n isFrozen(p) &&\n getPrototypeOf(p) === promiseProto &&\n promiseResolve(p) === p &&\n gopd(p, 'then') === undefined &&\n gopd(promiseProto, 'then').value === originalThen // unnecessary under SES\n );\n }\n\n const staticMethods = harden$1({\n get(target, key) {\n return handle(target, 'get', key);\n },\n getSendOnly(target, key) {\n handle(target, 'get', key);\n },\n applyFunction(target, args) {\n return handle(target, 'applyMethod', undefined, args);\n },\n applyFunctionSendOnly(target, args) {\n handle(target, 'applyMethod', undefined, args);\n },\n applyMethod(target, key, args) {\n return handle(target, 'applyMethod', key, args);\n },\n applyMethodSendOnly(target, key, args) {\n handle(target, 'applyMethod', key, args);\n },\n resolve(value) {\n ensureMaps();\n // Resolving a Presence returns the pre-registered handled promise.\n let resolvedPromise = presenceToPromise.get(value);\n if (!resolvedPromise) {\n resolvedPromise = promiseResolve(value);\n }\n // Prevent any proxy trickery.\n harden$1(resolvedPromise);\n if (isFrozenPromiseThen(resolvedPromise)) {\n return resolvedPromise;\n }\n // Assimilate the thenable.\n const executeThen = (resolve, reject) =>\n resolvedPromise.then(resolve, reject);\n return harden$1(\n promiseResolve().then(_ => new HandledPromise(executeThen)),\n );\n },\n // TODO verify that this is safe to provide universally, i.e.,\n // that by itself it doesn't provide access to mutable state in\n // ways that violate normal ocap module purity rules. The claim\n // that it does not rests on the handled promise itself being\n // necessary to perceive this mutable state. In that sense, we\n // can think of the right to perceive it, and of access to the\n // target, as being in the handled promise. Note that a .then on\n // the handled promise will already provide async access to the\n // target, so the only additional authorities are: 1)\n // synchronous access for handled promises only, and thus 2) the\n // ability to tell, from the client side, whether a promise is\n // handled. Or, at least, the ability to tell given that the\n // promise is already fulfilled.\n unwrap(value) {\n // This check for Thenable is safe, since in a remote-object\n // environment, our comms system will defend against remote\n // objects being represented as a tricky local Proxy, otherwise\n // it is guaranteed to be local and therefore synchronous enough.\n if (Object(value) !== value || !('then' in value)) {\n // Not a Thenable, so return it.\n // This means that local objects will pass through without error.\n return value;\n }\n\n // Try to look up the HandledPromise.\n ensureMaps();\n const pr = presenceToPromise.get(value) || value;\n\n // Find the fulfilled presence for that HandledPromise.\n const presence = promiseToPresence.get(pr);\n if (!presence) {\n throw TypeError(\n `Value is a Thenble but not a HandledPromise fulfilled to a presence`,\n );\n }\n return presence;\n },\n });\n\n defineProperties(HandledPromise, getOwnPropertyDescriptors(staticMethods));\n\n function makeForwarder(operation, localImpl) {\n return (o, ...args) => {\n // We are in another turn already, and have the naked object.\n const fulfilledHandler = presenceToHandler.get(o);\n if (\n fulfilledHandler &&\n typeof fulfilledHandler[operation] === 'function'\n ) {\n // The handler was resolved, so use it.\n return fulfilledHandler[operation](o, ...args);\n }\n\n // Not handled, so use the local implementation.\n return localImpl(o, ...args);\n };\n }\n\n // eslint-disable-next-line prefer-const\n forwardingHandler = {\n get: makeForwarder('get', (o, key) => o[key]),\n applyMethod: makeForwarder('applyMethod', (o, optKey, args) => {\n if (optKey === undefined || optKey === null) {\n return o(...args);\n }\n // console.log(`sending`, optKey, o[optKey], o);\n if (typeof o[optKey] !== 'function') {\n throw TypeError(`o[${JSON.stringify(optKey)}] is not a function`);\n }\n return o[optKey](...args);\n }),\n };\n\n handle = (p, operation, ...args) => {\n ensureMaps();\n const unfulfilledHandler = promiseToHandler.get(p);\n let executor;\n if (\n unfulfilledHandler &&\n typeof unfulfilledHandler[operation] === 'function'\n ) {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve()\n .then(() =>\n // and resolve to the answer from the specific unfulfilled handler,\n resolve(unfulfilledHandler[operation](p, ...args)),\n )\n .catch(reject);\n };\n } else {\n executor = (resolve, reject) => {\n // We run in a future turn to prevent synchronous attacks,\n HandledPromise.resolve(p)\n .then(o => {\n // We now have the naked object,\n if (typeof forwardingHandler[operation] !== 'function') {\n throw TypeError(\n `forwardingHandler.${operation} is not a function`,\n );\n }\n // and resolve to the forwardingHandler's operation.\n resolve(forwardingHandler[operation](o, ...args));\n })\n .catch(reject);\n };\n }\n\n // We return a handled promise with the default unfulfilled handler.\n // This prevents a race between the above Promise.resolves and\n // pipelining.\n return new HandledPromise(executor);\n };\n\n promiseResolve = Promise.resolve.bind(Promise);\n return harden$1(HandledPromise);\n}\n\nexports.E = E;\nexports.HandledPromise = hp;\nexports.makeHandledPromise = makeHandledPromise;\n});\n\nvar eventualSend_cjs$1 = unwrapExports(eventualSend_cjs);\nvar eventualSend_cjs_1 = eventualSend_cjs.E;\nvar eventualSend_cjs_2 = eventualSend_cjs.HandledPromise;\nvar eventualSend_cjs_3 = eventualSend_cjs.makeHandledPromise;\n\nexports.E = eventualSend_cjs_1;\nexports.HandledPromise = eventualSend_cjs_2;\nexports.default = eventualSend_cjs$1;\nexports.makeHandledPromise = eventualSend_cjs_3;\n\n\nreturn module.exports;\n}\n","sourceMap":"//# sourceURL=/Users/michael/agoric/agoric-sdk/packages/eventual-send/dist/eventual-send.cjs.js\n","moduleFormat":"getExport"};

@@ -41,6 +41,5 @@ function makeEventualSendTransformer(parser, generate) {

try {
const ns = (evaluateProgram || ss.evaluateProgram)(
`(${evSendSrc})()`,
{ require: myRequire || require },
);
const ns = (
evaluateProgram || ss.evaluateProgram
)(`(${evSendSrc})()`, { require: myRequire || require });
HandledPromise = ns.HandledPromise;

@@ -47,0 +46,0 @@ } finally {

{
"name": "@agoric/transform-eventual-send",
"version": "1.1.0",
"version": "1.2.0",
"description": "transform-eventual-send",
"main": "dist/transform-eventual-send.cjs.js",
"module": "dist/transform-eventual-send.esm.js",
"module": "src/index.js",
"browser": "dist/transform-eventual-send.umd.js",
"scripts": {
"test": "tape -r esm 'test/**/*.js'",
"lint-fix": "eslint --fix '**/*.{js,jsx}'",
"lint-check": "eslint '**/*.{js,jsx}'",
"lint-fix": "eslint --fix '**/*.js'",
"lint-check": "eslint '**/*.js'",
"build": "node -r esm ./scripts/build-esend.js && rollup -c rollup.config.js"

@@ -17,4 +17,4 @@ },

"@agoric/babel-parser": "^7.6.4",
"@agoric/bundle-source": "^1.0.4",
"@agoric/eventual-send": "^0.5.0",
"@agoric/bundle-source": "^1.1.0",
"@agoric/eventual-send": "^0.6.0",
"@agoric/harden": "^0.0.4",

@@ -26,3 +26,3 @@ "@babel/generator": "^7.5.0",

"rollup-plugin-node-resolve": "^5.2.0",
"ses": "^0.6.3",
"ses": "^0.6.5",
"tap-spec": "^5.0.0",

@@ -32,6 +32,6 @@ "tape": "^4.9.2",

},
"dependencies": {},
"keywords": [],
"files": [
"dist"
"dist",
"src"
],

@@ -47,3 +47,4 @@ "repository": {

},
"homepage": "https://github.com/Agoric/transform-eventual-send#readme"
"homepage": "https://github.com/Agoric/transform-eventual-send#readme",
"gitHead": "c954aea51be34003243e40837e7e579a03a034cc"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc