Skip to content

Commit

Permalink
test(xsnap): property name space exhaustion
Browse files Browse the repository at this point in the history
  - lint: globals, ava devDependencies
  • Loading branch information
dckc committed Mar 18, 2021
1 parent 3629e2c commit 0a83182
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/xsnap/test/test-xsnap.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global setTimeout, __filename */
// eslint-disable-next-line import/no-extraneous-dependencies
import test from 'ava';
import * as childProcess from 'child_process';
import * as os from 'os';
Expand Down Expand Up @@ -386,3 +388,30 @@ test('heap exhaustion: orderly fail-stop', async t => {
await t.throwsAsync(vat.evaluate(grow));
}
});

test('property name space exhaustion: orderly fail-stop', async t => {
const grow = qty => `
const objmap = {};
for (let ix = 0; ix < ${qty}; ix += 1) {
const key = \`k\${ix}\`;
objmap[key] = 1;
if (!(key in objmap)) {
throw Error(key);
}
}
`;
for (const debug of [false, true]) {
const vat = xsnap({ ...xsnapOptions, meteringLimit: 0, debug });
t.teardown(() => vat.terminate());
console.log({ debug, qty: 31000 });
// eslint-disable-next-line no-await-in-loop
await t.notThrowsAsync(vat.evaluate(grow(31000)));
console.log({ debug, qty: 4000000000 });
// eslint-disable-next-line no-await-in-loop
await t.throwsAsync(
vat.evaluate(grow(4000000000)),
undefined,
'not enough keys',
);
}
});

0 comments on commit 0a83182

Please sign in to comment.