Skip to content

Commit

Permalink
feat(xsnap): integrate native TextEncoder / TextDecoder
Browse files Browse the repository at this point in the history
 - test null handling in TextDecoder
 - update xsnap meter details, determinism hashes in tests
   for xs-meter-11
  • Loading branch information
dckc committed Sep 9, 2021
1 parent 5fc4b2e commit 9d65dbe
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 41 deletions.
6 changes: 3 additions & 3 deletions packages/SwingSet/test/test-xsnap-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ test('XS + SES snapshots are deterministic', async t => {

t.is(
h1,
'9255590eabf7884184a2c6ad435a543f66cdcc80209cc251085f22cdf9d1e5f5',
'879fe6ca1c58473713eba28201eb1397e663c78278f41b07c2cc6c77935a6850',
'initial snapshot',
);

Expand All @@ -167,15 +167,15 @@ test('XS + SES snapshots are deterministic', async t => {
const h2 = await store.save(vat.snapshot);
t.is(
h2,
'3b87e5509acf7e8ae40cca0686d0a64aeca6ed32df1279f6afa608651debd492',
'566457a540de7e295294e24319a10d62716dba304e4283a65315b64690d56cad',
'after SES boot',
);

await vat.evaluate('globalThis.x = harden({a: 1})');
const h3 = await store.save(vat.snapshot);
t.is(
h3,
'2aaab1080ea8c3c6aa9cd3faeaf2d89c68f01252c5d325e2f7694f53eca6f36d',
'ec5fac2d8c3756a10898dd36064fd235e2961bdef51039f7fe4c9b7a90a656f1',
'after use of harden()',
);
});
1 change: 0 additions & 1 deletion packages/xsnap/lib/ses-boot-debug.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import './console-shim.js';
import './text-shim.js';
import '@agoric/eventual-send/shim.js';
import './lockdown-shim-debug.js';

Expand Down
1 change: 0 additions & 1 deletion packages/xsnap/lib/ses-boot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import './console-shim.js';
import './text-shim.js';
import '@agoric/eventual-send/shim.js';
import './lockdown-shim.js';

Expand Down
30 changes: 0 additions & 30 deletions packages/xsnap/lib/text-shim.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/xsnap/test/test-replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const transcript1 = [
'/xsnap-tests/00001-evaluate.dat',
'issueCommand(ArrayBuffer.fromString("Hello, World!"));',
],
['/xsnap-tests/00002-command.dat', '{"compute":54'],
['/xsnap-tests/00002-command.dat', '{"compute":58'],
['/xsnap-tests/00003-reply.dat', ''],
];

Expand Down
23 changes: 20 additions & 3 deletions packages/xsnap/test/test-xs-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,27 @@ test('accept std regex range', async t => {
await vat.terminate();
});

test('simple TextEncoder / TextDecoder are available', async t => {
const opts = options(io);
const vat = xsnap(opts);
t.teardown(() => vat.terminate());
await vat.evaluate(`
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const send = it => issueCommand(encoder.encode(JSON.stringify(it)).buffer);
send("Hello! 😊")
send(decoder.decode(new Uint8Array([65, 0, 65]).buffer));
`);
t.deepEqual(opts.messages, ['"Hello! 😊"', '"A\\u0000A"']);
});

test('bigint map key', async t => {
const opts = options(io);
const vat = xsnap(opts);
t.teardown(() => vat.terminate());
await vat.evaluate(`
const send = it => issueCommand(ArrayBuffer.fromString(JSON.stringify(it)));
const encoder = new TextEncoder();
const send = it => issueCommand(encoder.encode(JSON.stringify(it)).buffer);
const store = new Map([[1n, "abc"]]);
send(store.get(1n))
`);
Expand All @@ -53,7 +68,8 @@ test('bigint toString', async t => {
const vat = xsnap(opts);
t.teardown(() => vat.terminate());
await vat.evaluate(`
const send = it => issueCommand(ArrayBuffer.fromString(JSON.stringify(it)));
const encoder = new TextEncoder();
const send = it => issueCommand(encoder.encode(JSON.stringify(it)).buffer);
const txt = \`number: 1 2 3 bigint: \${0n} \${1n} \${BigInt(2)} \${BigInt(3)} .\`;
send(txt)
`);
Expand All @@ -65,7 +81,8 @@ test('keyword in destructuring', async t => {
const vat = xsnap(opts);
t.teardown(() => vat.terminate());
await vat.evaluate(`
const send = it => issueCommand(ArrayBuffer.fromString(JSON.stringify(it)));
const encoder = new TextEncoder();
const send = it => issueCommand(encoder.encode(JSON.stringify(it)).buffer);
const { default: d, in: i } = { default: 1, in: 2 };
send({ d, i })
`);
Expand Down
4 changes: 2 additions & 2 deletions packages/xsnap/test/test-xs-perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test('meter details', async t => {

t.like(
meters,
{ compute: 1_260_182, allocate: 42_074_144 },
{ compute: 1_380_192, allocate: 42_074_144 },
'compute, allocate meters should be stable; update METER_TYPE?',
);

Expand Down Expand Up @@ -93,7 +93,7 @@ test('metering regex - REDOS', async t => {
'aaaaaaaaa!'.match(/^(([a-z])+.)+/)
`);
const { meterUsage: meters } = result;
t.like(meters, { compute: 149 });
t.like(meters, { compute: 153 });
});

test('meter details are still available with no limit', async t => {
Expand Down

0 comments on commit 9d65dbe

Please sign in to comment.