Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eshost

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eshost - npm Package Compare versions

Comparing version 1.1.3 to 2.0.0

.editorconfig

41

package.json
{
"name": "eshost",
"version": "1.1.3",
"description": "Run scripts in any ECMAScript host",
"bin": {
"eshost": "bin/eshost.js"
"version": "2.0.0",
"description": "Invoke ECMAScript scripts in any command line JS engine.",
"main": "lib/eshost.js",
"scripts": {
"test": "mocha test/*",
"lint": "eslint lib/* bin/* test/*"
},
"dependencies": {
"chalk": "^1.1.1",
"cli-table": "^0.3.1",
"configstore": "^1.4.0",
"es-host-wrapper": "^1.2.0",
"nconf": "^0.8.2",
"temp": "^0.8.3",
"yargs": "^3.31.0"
"author": "Brian Terlson",
"license": "MIT",
"devDependencies": {
"eslint": "^1.10.2",
"mocha": "^2.3.4"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {

@@ -25,13 +20,9 @@ "type": "git",

},
"keywords": [
"javascript",
"ecmascript",
"host"
],
"author": "Brian Terlson",
"license": "MIT",
"bugs": {
"url": "https://github.com/bterlson/eshost/issues"
"dependencies": {
"error-stack-parser": "^1.3.3",
"server-destroy": "^1.0.1",
"socket.io": "^1.3.7",
"temp": "^0.8.3"
},
"homepage": "https://github.com/bterlson/eshost"
}

@@ -1,50 +0,101 @@

## ESHost
## es-host-wrapper
ESHost makes it easy to run and compare ECMAScript code uniformly across a number of runtimes. Support for runtimes is provided by the library [es-host-wrapper](https://github.com/bterlson/es-host-wrapper). Every host is initialized with the [es-host-wrapper runtime API](https://github.com/bterlson/es-host-wrapper#runtime-library) available which provides a uniform way to print, create realms, and eval code.
Es-host-wrapper is a library for executing ECMAScript code uniformly across any ECMAScript host environment. Es-host-wrapper consists of a wrapper around the various ways of executing a host and processing its output (called a Runner) and a runtime library for host-agnostic scripts to use.
See es-host-wrapper's [supported hosts](https://github.com/bterlson/es-host-wrapper#supported-hosts) for a list of hosts, download/build locations, and other information.
For a CLI tool that uses this library to make comparing ECMAScript hosts super easy, see [eshost](https://github.com/bterlson/eshost).
### Usage
### Installation
Manage hosts with `eshost host`. Run files across all hosts using `eshost file.js`. Run a quick script using `eshost -e "script"`.
```
npm install es-host-wrapper
```
#### Examples
### Supported Hosts
| Host | Supported Platforms | Download | Notes |
|------|---------------------|----------|-------|
| browser | Any | | Errors reported from Microsoft Edge are all of type Error. |
| node | Any | https://nodejs.org | |
| ch | Windows | Built [from source](https://github.com/microsoft/chakracore)| Chakra console host. |
| d8 | Any | Built [from source](https://github.com/v8/v8) | v8 console host. Errors are reported on stdout. Use $.getGlobal and $.setGlobal to get and set properties of global objects in other realms. |
| jsshell | Any | [Download](https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/) | SpiderMonkey console host. |
| jsc | Mac | Built [from source](http://trac.webkit.org/wiki/JavaScriptCore)¹ | |
| nashorn | Any | Built [from source](https://wiki.openjdk.java.net/display/Nashorn/Building+Nashorn) | |
1: Also available on your Mac system at `/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc`.
### Examples
```js
const runner = js.getRunner('path/to/d8.exe', 'd8');
runner.exec(`
print(1+1);
`).then(result => console.log(result.stdout));
```
npm install -g eshost
eshost --help
eshost host --help
eshost host --add <name> <type> <path to host executable> --args <optional arguments>
eshost -e "print(Map.length)"
## chakra-es6
0
## Documentation
## d8
0
### es-host-wrapper API
## chakra
0
#### getRunner(path, type, arguments)
Gets an instance of a runner for a particular host type. Supported host types:
## spidermonkey
1
* browser
* node
* d8
* jsshell
* ch
## node
0
Creating a runner may start the host (eg. for the browser, creating the host executes the browser process).
You can pass command line arguments to the host process using the arguments option. It is an array of strings as you might pass to Node's spawn API.
### Runner API
#### exec(code)
Executes `code` in the host. Returns a result object.
##### Result Object
An object with the following keys:
* stdout: anything printed to stdout (mostly what you print using `print`).
* stderr: anything printed to stderr
* error: if the script threw an error, it will be an error object. Else, it will be null.
The error object is similar to the error object you get in the host itself. Namely, it has the following keys:
* name: Error name (eg. SyntaxError, TypeError, etc.)
* message: Error message
* stack: An array of stack frames.
### Runtime Library
#### print(str)
Prints `str` to stdout.
#### $.global
A reference to the global object.
#### $.createRealm(globals)
Creates a new realm, returning that realm's runtime library ($).
For example, creating two nested realms:
```js
$sub = $.createRealm();
$subsub = $sub.createRealm();
```
### Managing Hosts
#### $.evalInNewRealm(code, onError)
Creates a new realm and evals `code` in that realm. If an error is thrown, it will be passed to the onError callback.
The command `host` is used for managing hosts (see above for some examples). You can --add, --list, and --delete them. Adding a host requires a name, type, and path to the runtime executable. You can optionally pass arguments using --args. The same host can be added multiple times with different --args which makes it easy to compare the output of runtimes given different options (eg. by turning language features on and off).
#### $.evalInNewScript(code, onError)
Creates a new script and evals `code` in that realm. If an error is thrown, it will be passed to the onError callback.
Console hosts are either provided by the browser vendors or, more likely, built from source.
Scripts are different from eval in that lexical bindings go into the global lexical contour rather than being scoped to the eval.
Host types are [those provided by es-host-wrapper](https://github.com/bterlson/es-host-wrapper#supported-hosts), namely:
#### $.getGlobal(name)
Gets a global property name.
* ch
* jsshell
* d8
* jsc
* nashorn
* node
* browser
#### $.setGlobal(name, value)
Sets a global property name to value.

@@ -1,2 +0,5 @@

print('hello!');
throw new Error("fail");
var vm = require('vm');
var obj = {};
var context = vm.createContext({console: console});
vm.runInContext('var x = 1', context);
vm.runInContext('console.log(x)', context);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc