diff --git a/README.md b/README.md index a8e12f1..70a9af4 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ npm install eshost | Host | Name | Type | Supported Platforms | Download | Notes | |-----------------|-----------------|------|---------------------|----------|-------| +| boa | Boa | CLI | Any | [Download](https://github.com/boa-dev/boa/releases/tag/nightly) | | | ch¹ | ChakraCore | CLI | Any | [Download](https://github.com/Microsoft/ChakraCore/releases) or [build](https://github.com/Microsoft/ChakraCore/wiki/Building-ChakraCore) | Chakra console host. | | d8¹ | V8 | CLI | Any | Build [from source](https://github.com/v8/v8) | V8 console host. Errors are reported on stdout. Use `$262.getGlobal` and `$262.setGlobal` to get and set properties of global objects in other realms. | | engine262 | Engine262 | CLI | Any | Build [from source](https://github.com/engine262/engine262) | An implementation of ECMA-262 in JavaScript. | @@ -80,6 +81,7 @@ Creates an instance of a host agent for a particular host type. See the table ab | Host Type | All Acceptable `type` Values | | ---- | -------------------- | + | Boa | `boa` | | ChakraCore | `chakra`, `ch` | | Engine262 | `engine262` | | GraalJS | `graaljs` | diff --git a/lib/agents/boa.js b/lib/agents/boa.js new file mode 100644 index 0000000..ff01a9a --- /dev/null +++ b/lib/agents/boa.js @@ -0,0 +1,57 @@ +'use strict'; + +const fs = require('fs'); +const runtimePath = require('../runtime-path'); +const ConsoleAgent = require('../ConsoleAgent'); + +const errorRe = /Uncaught: (.*): (.*)/; + +class BoaAgent extends ConsoleAgent { + constructor(options) { + super(options); + + this.args.unshift('--debug-object'); + } + + async evalScript(code, options = {}) { + if (options.module && this.args[0] !== '--module') { + this.args.unshift('--module'); + } + + if (!options.module && this.args[0] === '--module') { + this.args.shift(); + } + + return super.evalScript(code, options); + } + + parseError(str) { + const match = str.match(errorRe); + if(!match) { + return null; + } + + return { + name: match[1], + message: match[2], + stack: '', + }; + } + + normalizeResult(result) { + const match = result.stdout.match(errorRe); + + if (match) { + result.stdout = result.stdout.replace(errorRe, ''); + result.stderr = match[0]; + } + + if (result.stdout === 'undefined\n') result.stdout = ''; + + return result; + } +} + +BoaAgent.runtime = fs.readFileSync(runtimePath.for('boa'), 'utf8'); + +module.exports = BoaAgent; diff --git a/lib/supported-hosts.js b/lib/supported-hosts.js index 86f94fc..1749e97 100644 --- a/lib/supported-hosts.js +++ b/lib/supported-hosts.js @@ -12,6 +12,7 @@ const hostAgents = agents.reduce((accum, agent) => { // directory. const supportedHostsMap = Object.assign({ /* Shells */ + // boa: 'boa', // chakra: 'chakra', ch: 'chakra', engine262: 'engine262', diff --git a/runtimes/boa.js b/runtimes/boa.js new file mode 100644 index 0000000..387568d --- /dev/null +++ b/runtimes/boa.js @@ -0,0 +1,7 @@ +var $262 = { + destroy() { /* noop */ }, + gc() { + return $boa.gc.collect(); + }, + global: globalThis, +};