Skip to content

Commit

Permalink
feat(xs-vat-worker): TextDecoder, HandledPromise before lockdown
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Jan 21, 2021
1 parent 5044f11 commit 09153ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/xs-vat-worker/src/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './console-shim';
import './text-shim';
import './lockdown-shim';
import '@agoric/eventual-send/shim';

harden(console);
9 changes: 9 additions & 0 deletions packages/xs-vat-worker/src/text-shim.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
/* eslint-disable max-classes-per-file */
/* eslint-disable class-methods-use-this */

// Save this XS extension before SES shim deletes it.
const { fromString } = ArrayBuffer;
const { fromArrayBuffer } = String;

class TextEncoder {
encode(s) {
return new Uint8Array(fromString(s));
}
}

class TextDecoder {
decode(bs) {
return fromArrayBuffer(bs);
}
}

globalThis.TextEncoder = TextEncoder;
globalThis.TextDecoder = TextDecoder;
4 changes: 2 additions & 2 deletions packages/xs-vat-worker/test/test-boot-lockdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ test('bootstrap to SES lockdown', async t => {
globalThis.send = msg => issueCommand(encoder.encode(JSON.stringify(msg)).buffer);
`);
await vat.evaluate(`
send([ typeof harden, typeof Compartment ]);
send([ typeof harden, typeof Compartment, typeof HandledPromise ]);
`);
await vat.close();
t.deepEqual(['["function","function"]'], messages);
t.deepEqual(['["function","function","function"]'], messages);
});

test('child compartment cannot access start powers', async t => {
Expand Down

0 comments on commit 09153ed

Please sign in to comment.