Skip to content

Commit 1ecf7bb

Browse files
IdanHorwaldron
authored andcommitted
Add 'serenity-js' synonym to LibJS, fix a couple of tests
1 parent db04624 commit 1ecf7bb

File tree

6 files changed

+46
-35
lines changed

6 files changed

+46
-35
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ npm install eshost
1818

1919
## Supported Hosts
2020

21-
| Host | Name | Type | Supported Platforms | Download | Notes |
22-
|------|------|------|---------------------|----------|-------|
23-
| ch¹ | ChakraCore | CLI | Any | [Download](https://github.com/Microsoft/ChakraCore/releases) or [build](https://github.com/Microsoft/ChakraCore/wiki/Building-ChakraCore) | Chakra console host. |
24-
| 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. |
25-
| engine262 | Engine262 | CLI | Any | Build [from source](https://github.com/engine262/engine262) | An implementation of ECMA-262 in JavaScript. |
26-
| graaljs | GraalJS | CLI | Any | [Download](https://github.com/graalvm/graalvm-ce-builds) | |
27-
| jsshell¹ | SpiderMonkey | CLI | Any | [Download](https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/) | SpiderMonkey console host. |
28-
| jsc¹ | JavaScriptCore | CLI | Mac² | Build [from source](http://trac.webkit.org/wiki/JavaScriptCore)³ | |
29-
| libjs | LibJS | CLI | Any | Build [from source](https://github.com/SerenityOS/serenity) | |
30-
| nashorn | Nashorn | CLI | Any | Build [from source](https://wiki.openjdk.java.net/display/Nashorn/Building+Nashorn) | |
31-
| node | Node.js | CLI | Any | https://nodejs.org | [Active LTS versions only](https://nodejs.org/en/about/releases/) |
32-
| qjs<sup>4</sup> | QuickJS | CLI | Any | Build [from source](https://bellard.org/quickjs/) | |
33-
| xs | Moddable XS | CLI | Any | Build [from source](https://github.com/Moddable-OpenSource/moddable-xst) | |
34-
| chrome | Google Chrome | Browser | Any | | Requires [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/downloads) in your path.|
35-
| edge | Microsoft Edge | Browser | Windows | | Errors reported from Microsoft Edge are all of type Error. Requires [Microsoft WebDriver](https://developer.microsoft.com/en-us/microsoft-edge/platform/documentation/dev-guide/tools/webdriver/) in your path. |
36-
| firefox | Mozilla Firefox | Browser | Any | | Requires [GeckoDriver](https://github.com/mozilla/geckodriver/releases) in your path (possibly renamed to `wires`).|
37-
| safari | Apple Safari | Browser | Mac | | Requires [SafariDriver browser extension](https://github.com/SeleniumHQ/selenium/wiki/SafariDriver). |
21+
| Host | Name | Type | Supported Platforms | Download | Notes |
22+
|-----------------|-----------------|------|---------------------|----------|-------|
23+
| ch¹ | ChakraCore | CLI | Any | [Download](https://github.com/Microsoft/ChakraCore/releases) or [build](https://github.com/Microsoft/ChakraCore/wiki/Building-ChakraCore) | Chakra console host. |
24+
| 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. |
25+
| engine262 | Engine262 | CLI | Any | Build [from source](https://github.com/engine262/engine262) | An implementation of ECMA-262 in JavaScript. |
26+
| graaljs | GraalJS | CLI | Any | [Download](https://github.com/graalvm/graalvm-ce-builds) | |
27+
| jsshell¹ | SpiderMonkey | CLI | Any | [Download](https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/) | SpiderMonkey console host. |
28+
| jsc¹ | JavaScriptCore | CLI | Mac² | Build [from source](http://trac.webkit.org/wiki/JavaScriptCore)³ | |
29+
| serenity-js | Serenity LibJS | CLI | Any | Build [from source](https://github.com/SerenityOS/serenity) | |
30+
| nashorn | Nashorn | CLI | Any | Build [from source](https://wiki.openjdk.java.net/display/Nashorn/Building+Nashorn) | |
31+
| node | Node.js | CLI | Any | https://nodejs.org | [Active LTS versions only](https://nodejs.org/en/about/releases/) |
32+
| qjs<sup>4</sup> | QuickJS | CLI | Any | Build [from source](https://bellard.org/quickjs/) | |
33+
| xs | Moddable XS | CLI | Any | Build [from source](https://github.com/Moddable-OpenSource/moddable-xst) | |
34+
| chrome | Google Chrome | Browser | Any | | Requires [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/downloads) in your path.|
35+
| edge | Microsoft Edge | Browser | Windows | | Errors reported from Microsoft Edge are all of type Error. Requires [Microsoft WebDriver](https://developer.microsoft.com/en-us/microsoft-edge/platform/documentation/dev-guide/tools/webdriver/) in your path. |
36+
| firefox | Mozilla Firefox | Browser | Any | | Requires [GeckoDriver](https://github.com/mozilla/geckodriver/releases) in your path (possibly renamed to `wires`).|
37+
| safari | Apple Safari | Browser | Mac | | Requires [SafariDriver browser extension](https://github.com/SeleniumHQ/selenium/wiki/SafariDriver). |
3838

3939
* 1: `eshost` accepts `esvu` or `jsvu` style binary name values as the first argument to `eshost.createAgent(type: string, options = {}): Agent`. See [Installing Engines](#installing-engines).
4040
* 2: It is possible to build `jsc` on other platforms, but not supported.
@@ -85,7 +85,7 @@ Creates an instance of a host agent for a particular host type. See the table ab
8585
| GraalJS | `graaljs` |
8686
| Hermes | `hermes` |
8787
| JavaScriptCore | `javascriptcore`, `jsc` |
88-
| LibJS | `libjs` |
88+
| Serenity LibJS | `serenity-js`, `libjs` |
8989
| Nashorn | `nashorn` |
9090
| Node | `node` |
9191
| QuickJS | `qjs` <sup>1</sup> |

lib/agents/libjs.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require('fs');
44
const runtimePath = require('../runtime-path');
55
const ConsoleAgent = require('../ConsoleAgent');
66

7-
const errorRe = /^Uncaught exception:(?: \[(.+?)])?(?: (.+))?((?:\n -> .+|\n \d+? more calls)*)?\n?/gm;
7+
const errorRe = /^Uncaught exception:(?: \[(.+?)])?(?: (.+))?((?:\n -> .+|\n \d+? more calls)*)?\n?/m;
88

99
class LibJSAgent extends ConsoleAgent {
1010
constructor(options) {
@@ -26,13 +26,22 @@ class LibJSAgent extends ConsoleAgent {
2626
}
2727

2828
parseError(str) {
29-
const match = errorRe.exec(str);
29+
const match = str.match(errorRe);
3030

3131
if (!match)
3232
return null;
3333

3434
const name = match[1] ? match[1].trim() : "";
35-
const message = match[2] ? match[2].trim() : "";
35+
let message = match[2] ? match[2].trim() : "";
36+
37+
try {
38+
const parsedMessage = JSON.parse(message);
39+
if (typeof parsedMessage["message"] === 'string')
40+
message = parsedMessage["message"];
41+
} catch (e) {
42+
// ignored
43+
}
44+
3645
const stack = [];
3746
if (match[3]) {
3847
const stackTrace = match[3].trim().split('\n');
@@ -62,8 +71,12 @@ class LibJSAgent extends ConsoleAgent {
6271
const match = result.stdout.match(errorRe);
6372

6473
if (match) {
65-
result.stdout = result.stdout.replace(errorRe, '');
6674
result.stderr = match[0];
75+
result.stdout = result.stdout.replace(errorRe, '').trim();
76+
77+
const expectedHintMarker = '^\n' + match[2];
78+
if (result.stdout.endsWith(expectedHintMarker)) // syntax error source location hint marker
79+
result.stdout = result.stdout.split('\n').slice(0, -3).join('\n');
6780
}
6881

6982
return result;

lib/supported-hosts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const supportedHostsMap = Object.assign({
2020
// jsc: 'jsc',
2121
// jsshell: 'jsshell',
2222
// libjs: 'libjs',
23+
'serenity-js': 'libjs',
2324
// nashorn: 'nashorn',
2425
// node: 'node',
2526
// qjs: 'qjs',

runtimes/libjs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ var $262 = {
77
return gc();
88
},
99
createRealm(options) {
10-
throw new Test262Error('createRealm() not yet supported.');
10+
throw new InternalError('createRealm() not yet supported.');
1111
},
1212
evalScript(code) {
13-
throw new Test262Error('evalScript() not yet supported.');
13+
throw new InternalError('evalScript() not yet supported.');
1414
},
1515
getGlobal(name) {
1616
return this.global[name];
@@ -22,6 +22,6 @@ var $262 = {
2222
IsHTMLDDA() { return {}; },
2323
source: $SOURCE,
2424
get agent() {
25-
throw new Test262Error('agent.* not yet supported.');
25+
throw new InternalError('agent.* not yet supported.');
2626
}
2727
};

test/runify.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const hosts = [
3333
["hermes", { hostPath: makeHostPath("hermes") }],
3434
["jsshell", { hostPath: makeHostPath("sm") }],
3535
["jsc", { hostPath: makeHostPath("jsc") }],
36-
["libjs", { hostPath: "js" }], // Not provided by esvu
36+
["libjs", { hostPath: makeHostPath("serenity-js") }],
3737
["node", { hostPath: "node" }], // Not provided by esvu
3838
["qjs", { hostPath: makeHostPath("quickjs-run-test262") }],
3939
["xs", { hostPath: makeHostPath("xs") }],
@@ -126,7 +126,7 @@ hosts.forEach(function (record) {
126126
describe("Normal script evaluation", function () {
127127
describe("Code evaluation modes", () => {
128128
// As of 2021-05-04, hermes and xs fail these tests.
129-
if (["hermes", "xs", "libjs"].includes(type)) {
129+
if (["hermes", "xs"].includes(type)) {
130130
return;
131131
}
132132

@@ -284,9 +284,6 @@ hosts.forEach(function (record) {
284284
});
285285

286286
it("handles thrown custom Errors that don't have Error.prototype", async () => {
287-
if (["libjs"].includes(type)) {
288-
return;
289-
}
290287
const result = await agent.evalScript(stripIndent`
291288
function Foo2Error(msg) {
292289
this.message = msg;
@@ -302,7 +299,8 @@ hosts.forEach(function (record) {
302299
expect(result.stdout).toBe("");
303300
expect(result.error).toBeTruthy();
304301
expect(result.error.message).toBe("FAIL!");
305-
expect(result.error.name).toBe("Foo2Error");
302+
if (type !== "libjs") // libjs gets this wrong
303+
expect(result.error.name).toBe("Foo2Error");
306304
});
307305

308306
it("handles thrown Errors without messages", async () => {
@@ -345,7 +343,7 @@ hosts.forEach(function (record) {
345343
print(false);
346344
print(0);
347345
print(1);
348-
print(1.2);
346+
print(1.3);
349347
print(-1);
350348
`);
351349

@@ -359,9 +357,7 @@ hosts.forEach(function (record) {
359357
expect(values[4]).toBe("false");
360358
expect(values[5]).toBe("0");
361359
expect(values[6]).toBe("1");
362-
if (type !== "libjs") {
363-
expect(values[7]).toBe("1.2");
364-
}
360+
expect(values[7]).toBe("1.3");
365361
expect(values[8]).toBe("-1");
366362
});
367363

test/supported-hosts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const supportedHostsMap = {
2222
javascriptcore: 'jsc',
2323
jsc: 'jsc',
2424
jsshell: 'jsshell',
25+
'serenity-js': 'libjs',
2526
libjs: 'libjs',
2627
nashorn: 'nashorn',
2728
node: 'node',

0 commit comments

Comments
 (0)