Skip to content

Commit d6be751

Browse files
committed
README.md: cleanup docs, put all options object properties and descriptions into tables; reorganize sections; add missing documentation
1 parent 3dc6f73 commit d6be751

File tree

1 file changed

+71
-50
lines changed

1 file changed

+71
-50
lines changed

README.md

Lines changed: 71 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## eshost
1+
# eshost
22

33
[![Travis Build Status](https://travis-ci.org/bterlson/eshost.svg?branch=master)](https://travis-ci.org/bterlson/eshost)
44
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/bterlson/eshost?branch=master&svg=true)](https://ci.appveyor.com/project/bterlson/eshost)
@@ -10,13 +10,13 @@ Using eshost, you can create an agent (eg. a web browser or a command-line ECMAS
1010

1111
eshost consists of a wrapper around the various ways of executing a host and processing its output (called an Agent) and a runtime library for host-agnostic scripts to use.
1212

13-
### Installation
13+
## Installation
1414

1515
```
1616
npm install eshost
1717
```
1818

19-
### Supported Hosts
19+
## Supported Hosts
2020

2121
| Host | Supported Platforms | Download | Notes |
2222
|------|---------------------|----------|-------|
@@ -35,11 +35,11 @@ npm install eshost
3535
* 1: It is possible to build jsc on other platforms, but not supported.
3636
* 2: Also available on your Mac system at `/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc`.
3737

38-
### Examples
38+
## Example Usage
3939

4040
```js
41-
const esh = require('eshost');
42-
const agent = esh.createAgent('d8', { hostPath: 'path/to/d8.exe' });
41+
const eshost = require('eshost');
42+
const agent = await eshost.createAgent('d8', { hostPath: 'path/to/d8.exe' });
4343
const result = await agent.evalScript(`
4444
print(1+1);
4545
`);
@@ -48,73 +48,90 @@ console.log(result.stdout);
4848

4949
## Documentation
5050

51-
### eshost API
52-
#### supportedHosts
51+
### `eshost`
52+
53+
The `eshost` object is the main export of the "eshost" module.
54+
55+
#### `eshost.supportedHosts`
5356

5457
An array of supported host types.
5558

56-
#### createAgent(type: string, options = {}): Runner
57-
Gets an instance of a runner for a particular host type. See the table above for supported host types.
59+
#### `eshost.createAgent(type: string, options = {}): Agent`
60+
61+
Creates an instance of a host agent for a particular host type. See the table above for supported host types.
62+
63+
`options`:
64+
65+
| Property | Description |
66+
|-|-|
67+
| `hostPath` | Path to host to execute. For console hosts, this argument is required. For the specific browser runners, hostPath is optional and if omitted, the location for that browser will be detected automatically. |
68+
| `hostArguments` | Command line arguments used when invoking your host. Not supported for browser hosts. `hostArguments` is an array of strings as you might pass to Node's spawn API. |
69+
| `transform` | A function to map the source to some other source before running the result on the underlying host. |
70+
| `webHost` | for web browser hosts only; URL host name from which to serve browser assets; optional; defaults to `"localhost"` |
71+
| `webPort` | for web browser hosts only; URL port number from which to serve browser assets; optional; defaults to `1337` |
72+
| `capabilities` | for `remote` host only; the Selenium/WebDriver capabilities to request for the remote session; all specified attributes will be forwarded to the server; [a listing of available attributes is available in the Selenium project's wiki](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities); the following attributes are required: ` { browserName, platform, version }` |
73+
| `webdriverServer` | for `remote` host only; URL of the WebDriver server to which commands should be issued |
74+
5875

59-
##### Options
6076

61-
* **hostPath**: Path to host to execute. For console hosts, this argument is required. For the specific browser runners, hostPath is optional and if omitted, the location for that browser will be detected automatically.
62-
* **hostArguments**: Command line arguments used when invoking your host. Not supported for browser hosts. **hostArguments** is an array of strings as you might pass to Node's spawn API.
63-
* **transform**: A function to map the source to some other source before running the result on the underlying host.
64-
* **webHost**: for web browser hosts only; URL host name from which to serve browser assets; optional; defaults to `"localhost"`
65-
* **webPort**: for web browser hosts only; URL port number from which to serve browser assets; optional; defaults to `1337`
66-
* **capabilities**: for `remote` host only; the Selenium/WebDriver capabilities to request for the remote session; all specified attributes will be forwarded to the server; [a listing of available attributes is available in the Selenium project's wiki](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities); the following attributes are required:
67-
* **capabilities.browserName**
68-
* **capabilities.platform**
69-
* **capabilities.version**
70-
* **webdriverServer**: for `remote` host only; URL of the WebDriver server to which commands should be issued
77+
### `Agent`
7178

72-
### Agent API
73-
#### initialize(): Promise<void>
79+
#### `initialize(): Promise<void>`
7480
Initializes the host and returns a promise that is resolved once the host is initialized. Command line hosts have no initialization as a new process is started for each execution.
7581

7682
This is called for you if you use the createAgent factory.
7783

78-
#### evalScript(code, options = {}): Promise<Result>
84+
#### `evalScript(code, options = {}): Promise<Result>`
7985
Executes `code` in the host using the _Script_ goal symbol. Returns a promise for a result object.
8086

81-
By default, a script will run in Eshost until the realm is destroyed. For most command-line hosts, this is done automatically when the script execution queues are empty. However, browsers will remain open waiting for more code to become available. Therefore, eshost will automatically append `$.destroy()` to the end of your scripts. This behavior is not correct if you are attempting to execute asynchronous code. In such cases, add `async: true` to the options.
87+
#### `evalScript(record, options = {}): Promise<Result>`
8288

83-
Options:
89+
When `evalScript` receives a `Test262Stream` test record, it executes `record.contents` in the host using the _Script_ goal symbol, unless `record.attrs.flags.module === true`, in which case it will execute `record.contents` in the host using the _Module_ goal symbol. Returns a promise for a result object.
8490

85-
* async: True if the test is expected to call `$.destroy()` on the root realm when it's finished. When false, $.destroy() is added for you.
91+
By default, a script will run in `eshost` until the realm is destroyed. For most command-line hosts, this is done automatically when the script execution queues are empty. However, browsers will remain open waiting for more code to become available. Therefore, `eshost` will automatically append `$.destroy()` to the end of your scripts. This behavior is not correct if you are attempting to execute asynchronous code. In such cases, add `async: true` to the options.
8692

87-
#### stop(): Promise<void>
93+
`options`:
94+
95+
| Property | Description | Default Value |
96+
|-|-|-|
97+
| `async` | Set to `true` if the test is expected to call `$.destroy()` on the root realm when it's finished. When false, `$.destroy()` is added for you. | `false` |
98+
99+
#### `stop(): Promise<void>`
88100
Stops the currently executing script. For a console host, this simply kills the child process. For browser hosts, it will kill the current window and create a new one.
89101

90-
#### destroy(): Promise<void>
102+
#### `destroy(): Promise<void>`
91103
Destroys the agent, closing any of its associated resources (eg. browser windows, child processes, etc.).
92104

93-
##### Result Object
105+
##### `Result Object`
94106
An object with the following keys:
95107

96-
* stdout: anything printed to stdout (mostly what you print using `print`).
97-
* stderr: anything printed to stderr
98-
* error: if the script threw an error, it will be an error object. Else, it will be null.
108+
| Property | Description |
109+
|-|-|
110+
| `stdout` | Anything printed to stdout (mostly what you print using `print`). |
111+
| `stderr` | Anything printed to stderr |
112+
| `error` | If the script threw an error, it will be an error object. Else, it will be null. |
113+
99114

100-
The error object is similar to the error object you get in the host itself. Namely, it has the following keys:
115+
The `error` object is similar to an error object you get in the host itself. Namely, it has the following keys:
101116

102-
* name: Error name (eg. SyntaxError, TypeError, etc.)
103-
* message: Error message
104-
* stack: An array of stack frames.
117+
| Property | Description |
118+
|-|-|
119+
| `name` | Error name (eg. SyntaxError, TypeError, etc.) |
120+
| `message` | Error message |
121+
| `stack` | An array of stack frames. |
105122

106-
#### destroy(): Promise<void>
123+
#### `destroy(): Promise<void>`
107124
Tears down the agent. For browsers, this will close the browser window.
108125

109126
### Runtime Library
110127

111-
#### print(str)
128+
#### `print(str)`
112129
Prints `str` to stdout.
113130

114-
#### $.global
131+
#### `$.global`
115132
A reference to the global object.
116133

117-
#### $.createRealm(options)
134+
#### `$.createRealm(options)`
118135
Creates a new realm, returning that realm's runtime library ($).
119136

120137
For example, creating two nested realms:
@@ -128,34 +145,38 @@ You can also use a destroy callback that gets called when the code inside the re
128145

129146
```js
130147
$sub = $.createRealm({
131-
destroy: function () {
148+
destroy() {
132149
print('destroyed!')
133150
}
134151
});
135152

136153
$sub.evalScript('$.destroy()'); // prints "destroyed!"
137154
```
138155

139-
Options:
156+
`options`:
157+
158+
| Property | Description |
159+
|-|-|
160+
| `globals` | An object containing properties to add to the global object in the new realm. |
161+
| `destroy` | A callback that is called when the code executing in the realm destroys its realm (ie. by calling `$.destroy()`). |
162+
140163

141-
* globals: an object containing properties to add to the global object in the new realm.
142-
* destroy: a callback that is called when the code executing in the realm destroys its realm (ie. by calling `$.destroy()`).
143164

144-
#### $.evalScript(code)
165+
#### `$.evalScript(code)`
145166
Creates a new script and evals `code` in that realm. If an error is thrown, it will be passed to the onError callback.
146167

147168
Scripts are different from eval in that lexical bindings go into the global lexical contour rather than being scoped to the eval.
148169

149-
#### $.destroy()
170+
#### `$.destroy()`
150171
Destroys the realm. Note that in some hosts, $.destroy may not actually stop executing code in the realm or even destroy the realm.
151172

152-
#### $.getGlobal(name)
173+
#### `$.getGlobal(name)`
153174
Gets a global property name.
154175

155-
#### $.setGlobal(name, value)
176+
#### `$.setGlobal(name, value)`
156177
Sets a global property name to value.
157178

158-
### Running the tests
179+
## Running the tests
159180

160181
This project's tests can be executed with the following command:
161182

0 commit comments

Comments
 (0)