-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(xs-vat-worker): bootstrap SES shim on xsnap
- add ses dependency - noop console, since xsnap no longer provides `print` - re-package XS ArrayBuffer.fromString() extension as TextEncoder.prototype.encode - use `xsStringBuffer()` C API rather than `String.fromArrayBuffer` JS API so that xsnap eval continues to work after `lockdown()`.
- Loading branch information
Showing
8 changed files
with
73 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import './console-shim'; | ||
import './text-shim'; | ||
import './lockdown-shim'; | ||
|
||
harden(console); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const noop = _ => undefined; | ||
|
||
globalThis.console = { | ||
debug: noop, | ||
log: noop, | ||
info: noop, | ||
warn: noop, | ||
error: noop, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* global lockdown */ | ||
|
||
import 'ses/lockdown'; | ||
|
||
lockdown(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* eslint-disable class-methods-use-this */ | ||
|
||
// Save this XS extension before SES shim deletes it. | ||
const { fromString } = ArrayBuffer; | ||
|
||
class TextEncoder { | ||
encode(s) { | ||
return new Uint8Array(fromString(s)); | ||
} | ||
} | ||
|
||
globalThis.TextEncoder = TextEncoder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import test from 'ava'; | ||
import * as childProcess from 'child_process'; | ||
import * as os from 'os'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { xsnap } from '@agoric/xsnap'; | ||
|
||
const dist = async name => | ||
fs.promises.readFile(path.join(__filename, '..', '..', 'dist', name)); | ||
|
||
const decoder = new TextDecoder(); | ||
|
||
const xsnapOptions = { | ||
spawn: childProcess.spawn, | ||
os: os.type(), | ||
}; | ||
|
||
test('bootstrap to SES lockdown', async t => { | ||
const bootScript = await dist('bootstrap.umd.js'); | ||
const messages = []; | ||
async function handleCommand(message) { | ||
messages.push(decoder.decode(message)); | ||
return new Uint8Array(); | ||
} | ||
const name = 'SES lockdown worker'; | ||
const vat = xsnap({ ...xsnapOptions, handleCommand, name }); | ||
await vat.evaluate(bootScript); | ||
t.deepEqual([], messages); | ||
|
||
const SESinfo = '[typeof harden, typeof Compartment]'; | ||
const toBytes = expr => | ||
`new TextEncoder().encode(JSON.stringify(${expr})).buffer`; | ||
await vat.evaluate(`issueCommand(${toBytes(SESinfo)});`); | ||
await vat.close(); | ||
t.deepEqual(['["function","function"]'], messages); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters