Skip to content

Commit

Permalink
fix! insert "await null"s needed for await safety
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jul 12, 2024
1 parent a1740bd commit f462910
Show file tree
Hide file tree
Showing 55 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/base64/test/bench-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async function main() {
const log = (typeof console !== 'undefined' && console.log) || print;
/** @type {typeof Date.now} */
const now = await (async () => {
await null;
try {
const { performance } = await import('perf_hooks');
if (performance.now) {
Expand Down
1 change: 1 addition & 0 deletions packages/captp/test/export-hook.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test('exportHook', async t => {
);

// Prime the pump.
await null;
t.deepEqual(await E(bs).echo(), [], 'echoed');
t.is(exports.length, 1, 'loopback metaprotocol');
exports.splice(0);
Expand Down
1 change: 1 addition & 0 deletions packages/captp/test/gc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const isolated = async (t, makeFar) => {
method: () => 'local',
});
const far = makeFar(local);
await null;
t.is(await E(far).method(), 'local');
};

Expand Down
1 change: 1 addition & 0 deletions packages/captp/test/trap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const makeWorkerTests = isHost => async t => {

const bs = getBootstrap();
// console.error('have bs', bs);
await null;
if (Trap) {
await runTrapTests(t, Trap, bs, true);
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/captp/test/traplib.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const runTrapTests = async (t, Trap, bs, unwrapsPromises) => {
// Demonstrate async compatibility of traps.
const pn = E(E(bs).getTraps(3)).getN();
t.is(Promise.resolve(pn), pn);
await null;
t.is(await pn, 3);

// Demonstrate Trap cannot be used on a promise.
Expand Down
1 change: 1 addition & 0 deletions packages/check-bundle/lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const checkBundle = async (
X`checkBundle cannot hash non-bundle, moduleFormat must be a string, got ${typeof moduleFormat}`,
);

await null;
if (moduleFormat === 'endoZipBase64') {
const { endoZipBase64, endoZipBase64Sha512 } = bundle;
assert.typeof(
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const provideEndoClient = async (
cancelled,
bootstrap,
) => {
await null;
try {
// It is okay to fail to connect because the daemon is not running.
return await makeEndoClient(name, sockPath, cancelled, bootstrap);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/accept.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const fromAsync = async iterable => {

export const accept = async ({ guestName, agentNames }) => {
process.stdin.setEncoding('utf-8');
await null;
const invitationLocator = (await fromAsync(process.stdin)).join('').trim();
return withEndoAgent(agentNames, { os, process }, async ({ agent }) => {
await E(agent).accept(invitationLocator.trim(), guestName);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const list = async ({ directory, follow, json, verbose }) =>
const directoryPath = parsePetNamePath(directory);
agent = E(agent).lookup(...directoryPath);
}
await null;
if (follow) {
const topic = await E(agent).followNameChanges();
const iterator = makeRefIterator(topic);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const log = async ({ follow, ping }) =>

const logPath = path.join(statePath, 'endo.log');

await null;
do {
// Scope cancellation and propagate.
const { promise: followCancelled, reject: cancelFollower } =
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const makeCommand = async ({
let bundleReaderRef;
/** @type {string | undefined} */
let temporaryBundleName;
await null;
if (filePath !== undefined) {
if (bundleName === undefined) {
// TODO alternately, make a temporary session-scoped GC pet store
Expand All @@ -62,6 +63,7 @@ export const makeCommand = async ({

await withEndoAgent(agentNames, { os, process }, async ({ agent }) => {
// Prepare a bundle, with the given name.
await null;
if (bundleReaderRef !== undefined) {
await E(agent).storeBlob(bundleReaderRef, bundleName);
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const run = async ({
powersP = E(agent).provideGuest(powersName);
}

await null;
if (importPath !== undefined) {
if (bundleName !== undefined) {
console.error(
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const store = async ({
const parsedName = parsePetNamePath(name);

await withEndoAgent(agentNames, { os, process }, async ({ agent }) => {
await null;
if (storeText !== undefined) {
await E(agent).storeValue(storeText, parsedName);
} else if (storeJson !== undefined) {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const withInterrupt = async callback => {
cancelled.catch(() => {});
process.once('SIGINT', () => cancel(Error('SIGINT')));

await null;
try {
await callback({ cancel, cancelled });
cancel(Error('normal termination'));
Expand Down
1 change: 1 addition & 0 deletions packages/common/test/apply-labeling-error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test('test applyLabelingError', async t => {
applyLabelingError(x => x * 2, [8], 'foo'),
16,
);
await null;
t.is(await applyLabelingError(async x => x * 2, [8], 'foo'), 16);
t.throws(() => applyLabelingError(x => Fail`${x}`, ['e']), {
message: '"e"',
Expand Down
1 change: 1 addition & 0 deletions packages/compartment-mapper/src/archive-lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ const renameSources = (sources, compartmentRenames) => {
* @param {Sources} sources
*/
const addSourcesToArchive = async (archive, sources) => {
await null;
for (const compartment of keys(sources).sort()) {
const modules = sources[compartment];
const compartmentLocation = resolveLocation(`${compartment}/`, 'file:///');
Expand Down
2 changes: 2 additions & 0 deletions packages/compartment-mapper/src/import-archive-lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const makeArchiveImportHookMaker = (
const importHook = async moduleSpecifier => {
// per-module:
const module = modules[moduleSpecifier];
await null;
if (module === undefined) {
if (exitModuleImportHook) {
// At this point in archive importing, if a module is not found and
Expand Down Expand Up @@ -354,6 +355,7 @@ export const parseArchive = async (
// Archive integrity checks: ensure every module is pre-loaded so its hash
// gets checked, and ensure that every file in the archive is used, and
// therefore checked.
await null;
if (computeSha512 !== undefined) {
const makeImportHook = makeArchiveImportHookMaker(
get,
Expand Down
1 change: 1 addition & 0 deletions packages/compartment-mapper/src/import-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export const makeImportHookMaker = (
// third-party dependency.
// The `moduleMapHook` captures all third-party dependencies, unless
// we allow importing any exit.
await null;
if (moduleSpecifier !== '.' && !moduleSpecifier.startsWith('./')) {
if (exitModuleImportHook) {
const record = await exitModuleImportHook(moduleSpecifier);
Expand Down
1 change: 1 addition & 0 deletions packages/compartment-mapper/src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const makeExtensionParser = (

let sourceMap;

await null;
if (has(moduleTransforms, language)) {
try {
({
Expand Down
1 change: 1 addition & 0 deletions packages/compartment-mapper/src/node-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const readDescriptorWithMemo = async (memo, maybeRead, packageLocation) => {
* } | undefined>}
*/
const findPackage = async (readDescriptor, canonical, directory, name) => {
await null;
for (;;) {
// eslint-disable-next-line no-await-in-loop
const packageLocation = await canonical(
Expand Down
2 changes: 2 additions & 0 deletions packages/compartment-mapper/src/node-powers.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const makeReadPowersSloppy = ({ fs, url = undefined, crypto = undefined }) => {
* @param {string} location
*/
const canonical = async location => {
await null;
try {
if (location.endsWith('/')) {
const realPath = await fs.promises.realpath(
Expand Down Expand Up @@ -157,6 +158,7 @@ const makeWritePowersSloppy = ({ fs, url = undefined }) => {
* @param {Uint8Array} data
*/
const write = async (location, data) => {
await null;
try {
return await fs.promises.writeFile(fileURLToPath(location), data);
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions packages/compartment-mapper/src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const resolveLocation = (rel, abs) => new URL(rel, abs).toString();
*/
export const searchDescriptor = async (location, readDescriptor) => {
let directory = resolveLocation('./', location);
await null;
for (;;) {
const packageDescriptorLocation = resolveLocation(
'package.json',
Expand Down
1 change: 1 addition & 0 deletions packages/compartment-mapper/test/policy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { moduleify, scaffold, sanitizePaths } from './scaffold.js';

function combineAssertions(...assertionFunctions) {
return async (...args) => {
await null;
for (const assertion of assertionFunctions) {
// eslint-disable-next-line no-await-in-loop
await assertion(...args);
Expand Down
2 changes: 2 additions & 0 deletions packages/compartment-mapper/test/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const builtinLocation = new URL(
// application package.

export async function setup() {
await null;
if (modules === undefined) {
const utility = await loadLocation(readPowers, builtinLocation);
const { namespace } = await utility.import({ globals });
Expand Down Expand Up @@ -100,6 +101,7 @@ export function scaffold(
return testFunc(title, async t => {
const compartmentInstrumentation = compartmentInstrumentationFactory();
let namespace;
await null;
try {
namespace = await implementation(
t,
Expand Down
1 change: 1 addition & 0 deletions packages/compartment-mapper/test/stack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ test('archive stack trace source', async t => {
// have a fully qualified file URL in the stack trace.
test('disk stack trace source', async t => {
let error;
await null;
try {
await importLocation(readPowers, fixtureLocation);
} catch (_error) {
Expand Down
1 change: 1 addition & 0 deletions packages/daemon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const enoentOk = error => {
};

export const clean = async (config = defaultConfig) => {
await null;
if (process.platform !== 'win32') {
await removePath(config.sockPath).catch(enoentOk);
}
Expand Down
1 change: 1 addition & 0 deletions packages/daemon/src/daemon-node-powers.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ export const makeDaemonicPersistencePowers = (
return filePowers.readFileText(storagePath);
};
const json = async () => {
await null;
return JSON.parse(await text());
};
return harden({
Expand Down
1 change: 1 addition & 0 deletions packages/daemon/src/serve-private-port-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const servePrivatePortHttp = (
const connectionClosedPromises = new Set();

const respond = async request => {
await null;
if (request.method === 'GET') {
if (request.url === '/') {
return {
Expand Down
1 change: 1 addition & 0 deletions packages/daemon/src/web-server-node-powers.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const makeHttpPowers = ({ http, ws }) => {
return;
}

await null;
try {
await sendResponse(req, res);
} catch (_error) {
Expand Down
1 change: 1 addition & 0 deletions packages/daemon/src/web-server-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export const make = async (_powers, context) => {
E.sendOnly(webletBootstrap).ping();

// eslint-disable-next-line no-use-before-define
await null;
E(webletBootstrap)
.makeBundle(
await E(/** @type {any} */ (webletBundle)).json(),
Expand Down
1 change: 1 addition & 0 deletions packages/daemon/test/context-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const ContextConsumerInterface = M.interface(
export const make = async (_powers, context) => {
return makeExo('Context consumer', ContextConsumerInterface, {
async awaitCancellation() {
await null;
try {
await E(context).whenCancelled();
} catch {
Expand Down
3 changes: 3 additions & 0 deletions packages/eventual-send/test/e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ test('E method calls', async t => {
};
const d = E(x).double(6);
t.is(typeof d.then, 'function', 'return is a thenable');
await null;
t.is(await d, 12, 'method call works');
const methodProxy = E(x);
t.assert(Object.isFrozen(methodProxy));
Expand Down Expand Up @@ -156,6 +157,7 @@ test('E shortcuts', async t => {
return `${greeting}, ${this.name}!`;
},
};
await null;
t.is(await E(x).hello('Hello'), 'Hello, buddy!', 'method call works');
t.is(
await E(await E.get(await E.get(x).y).fn)(4),
Expand Down Expand Up @@ -183,6 +185,7 @@ test('E.get', async t => {
return `${greeting}, ${this.name}!`;
},
};
await null;
t.assert(Object.isFrozen(await E.get(x).output), 'get output is frozen');
t.assert(
Object.isFrozen(await E(E.get(x).testFrozen)({ arg: 123 })),
Expand Down
3 changes: 3 additions & 0 deletions packages/eventual-send/test/eventual-send.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ test('new HandledPromise expected errors', async t => {

// Full handler succeeds.
let fullObj;
await null;
t.is(
await new HandledPromise((_, _2, rwp) => (fullObj = rwp(handler))),
fullObj,
Expand Down Expand Up @@ -281,6 +282,7 @@ test('new HandledPromise(executor, undefined)', async t => {
}, 200);
});

await null;
t.is(
await HandledPromise.applyMethod(handledP, 'hello', ['World', '!']),
'Hello, World!',
Expand Down Expand Up @@ -308,6 +310,7 @@ test('handled promises are promises', t => {
});

test('eventual send expected errors', async t => {
await null;
t.is(
await HandledPromise.get(true, 'toString'),
true.toString,
Expand Down
1 change: 1 addition & 0 deletions packages/eventual-send/test/thenable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const verifyThenAttack = async (t, resolve) => {
t.not(p, p2, 'an own "then" should cause coercion');
t.is(getHappened, false, `getter not called too early`);
t.is(callHappened, false, `then not called too early`);
await null;
t.is(await p2, 'done', `p2 is resolved`);
t.is(getHappened, true, `getter not called too early`);
t.is(callHappened, true, `then not called too early`);
Expand Down
1 change: 1 addition & 0 deletions packages/exo/test/exo-only-throwables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ test('exo only throwables', async t => {
t.true(isPassable(caught));
t.log('throw caught', caught);

await null;
try {
await thrower.reject(e);
} catch (thrown) {
Expand Down
1 change: 1 addition & 0 deletions packages/exo/test/legacy-guard-tolerance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ test('legacy guard tolerance', async t => {
mg1: meth,
mg2: meth,
});
await null;
t.deepEqual(await f1.mg1(77, 88), [77, 88]);
await t.throwsAsync(async () => f1.mg1(77, laag), {
message:
Expand Down
3 changes: 3 additions & 0 deletions packages/far/test/e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ test('E method calls', async t => {
};
const d = E(x).double(6);
t.is(typeof d.then, 'function', 'return is a thenable');
await null;
t.is(await d, 12, 'method call works');
});

Expand Down Expand Up @@ -178,6 +179,7 @@ test('E shortcuts', async t => {
return `${greeting}, ${this.name}!`;
},
};
await null;
t.is(await E(x).hello('Hello'), 'Hello, buddy!', 'method call works');
t.is(
await E(await E.get(await E.get(x).y).fn)(4),
Expand All @@ -200,6 +202,7 @@ test('E.get', async t => {
return `${greeting}, ${this.name}!`;
},
};
await null;
t.is(
await E(await E.get(await E.get(x).y).fn)(4),
8,
Expand Down
1 change: 1 addition & 0 deletions packages/import-bundle/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export async function importBundle(bundle, options = {}, powers = {}) {
}

const { moduleFormat } = bundle;
await null;
if (moduleFormat === 'endoZipBase64') {
const { endoZipBase64 } = bundle;
const bytes = decodeBase64(endoZipBase64);
Expand Down
1 change: 1 addition & 0 deletions packages/import-bundle/test/import-bundle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ test('test import', async t => {
// bundleSource (in 'getExport' mode) uses rollup() in a way that uses
// Math.random, which is disabled under SES
console.log(`TODO: skipping test that needs Math.random`);
await null;
// eslint-disable-next-line no-constant-condition
if (false) {
const b1getExport = await bundleSource(
Expand Down
1 change: 1 addition & 0 deletions packages/lp32/test/lp32.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ test('round-trip varying messages', async t => {
const producer = (async () => {
/** @type {import('@endo/stream').Writer<Uint8Array, undefined>} */
const w = makeLp32Writer(output);
await null;
for (let i = 0; i < array.length; i += 1) {
// eslint-disable-next-line no-await-in-loop
await w.next(encoder.encode(array[i]));
Expand Down
Loading

0 comments on commit f462910

Please sign in to comment.