Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Escargot engine #152

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ To update the installed JavaScript engines later on, just run `jsvu` again.
| [**V8**][v8] | `v8` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [**V8 debug**][v8] | `v8-debug` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [**XS**][xs] | `xs` | ✅ | ✅ | ❌ | ✅ | ❌ | ✅ |
| [**Escargot**][escargot] | `escargot` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |

<sup>\*</sup> JavaScriptCore requires external dependencies to run on Windows:
- On 32-bit Windows, install [iTunes](https://www.apple.com/itunes/download/).
Expand All @@ -58,6 +59,7 @@ To update the installed JavaScript engines later on, just run `jsvu` again.
[sm]: https://bugzilla.mozilla.org/show_bug.cgi?id=1336514
[v8]: https://bugs.chromium.org/p/chromium/issues/detail?id=936383
[xs]: https://github.com/Moddable-OpenSource/moddable-xst
[escargot]: https://github.com/Samsung/escargot

## Integration with `eshost-cli`

Expand Down Expand Up @@ -88,6 +90,7 @@ eshost --add 'SpiderMonkey' jsshell ~/.jsvu/bin/spidermonkey
eshost --add 'V8 --harmony' d8 ~/.jsvu/bin/v8 --args '--harmony'
eshost --add 'V8' d8 ~/.jsvu/bin/v8
eshost --add 'XS' xs ~/.jsvu/bin/xs
eshost --add 'Escargot' escargot ~/.jsvu/bin/escargot
```

### Windows
Expand All @@ -100,6 +103,7 @@ eshost --add "SpiderMonkey" jsshell "%USERPROFILE%\.jsvu\bin\spidermonkey.cmd"
eshost --add "V8 --harmony" d8 "%USERPROFILE%\.jsvu\bin\v8.cmd" --args "--harmony"
eshost --add "V8" d8 "%USERPROFILE%\.jsvu\bin\v8.cmd"
eshost --add "XS" xs "%USERPROFILE%\.jsvu\bin\xs.cmd"
eshost --add "Escargot" escargot "%USERPROFILE%\.jsvu\bin\escargot.cmd"
```

That’s it! You can now run code snippets in all those engines with a single command:
Expand All @@ -121,7 +125,7 @@ However, there are use cases for running jsvu within non-interactive environment
```sh
jsvu --os=linux64 --engines=all
# Equivalent to:
jsvu --os=linux64 --engines=chakra,graaljs,hermes,javascriptcore,quickjs,spidermonkey,v8,xs
jsvu --os=linux64 --engines=chakra,graaljs,hermes,javascriptcore,quickjs,spidermonkey,v8,xs,escargot
```

If the operating system and architecture are not known in advance, the `--os=default` flag attempts to guess the correct value from the running environment. This might not be right for example if running a 32-bit Node.js process on a 64-bit machine.
Expand Down Expand Up @@ -150,6 +154,7 @@ jsvu spidermonkey@66.0b13
jsvu v8@7.2.502
jsvu v8-debug@7.1.302
jsvu xs@8.7.0
jsvu escargot@4.2.0
```

If you pass in an invalid version number, or if the JavaScript engine creators don’t provide a precompiled binary for that specific version, jsvu shows an error.
Expand Down
5 changes: 5 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ const engineChoices = [
value: 'xs',
checked: true,
},
{
name: 'Escargot',
value: 'escargot',
checked: true,
},
];

const promptEngines = () => {
Expand Down
67 changes: 67 additions & 0 deletions engines/escargot/extract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2019 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// <https://apache.org/licenses/LICENSE-2.0>.
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an “AS IS” BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const path = require('path');

const { Installer } = require('../../shared/installer.js');
const unzip = require('../../shared/unzip.js');

const extract = ({ filePath, binary, alias, os }) => {
return new Promise(async (resolve, reject) => {
const tmpPath = path.dirname(filePath);
await unzip({
from: filePath,
to: tmpPath,
});
const installer = new Installer({
engine: binary,
path: tmpPath,
});
switch (os) {
case 'win32':
case 'win64': {
installer.installBinary(
{ 'escargot.exe': `${binary}.exe` },
{ symlink: false }
);
installer.installScript({
name: `${binary}.cmd`,
generateScript: (targetPath) => {
return `
@echo off
"${targetPath}\\escargot.exe" %*
`;
}
});
break;
}
case 'mac64':
case 'mac64arm': {
installer.installLibraryGlob('*.dylib');
installer.installBinary({ 'escargot': binary }, { symlink: true });
break;
}
case 'linux32':
case 'linux64': {
installer.installLibraryGlob('*.so.*');
installer.installBinary({ 'escargot': binary }, { symlink: true });
break;
}
}
resolve();
});
};

module.exports = extract;
28 changes: 28 additions & 0 deletions engines/escargot/get-latest-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2019 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// <https://apache.org/licenses/LICENSE-2.0>.
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an “AS IS” BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const get = require('../../shared/get.js');

const getLatestVersion = async () => {
const url = 'https://api.github.com/repos/Samsung/escargot/releases/latest';
const response = await get(url, {
json: true,
});
const data = response.body;
const version = data.tag_name.replace(/^v/, '');
return version;
};

module.exports = getLatestVersion;
23 changes: 23 additions & 0 deletions engines/escargot/get-specific-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2019 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// <https://apache.org/licenses/LICENSE-2.0>.
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an “AS IS” BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const getSpecificVersion = (version) => {
// If we ever want to add logic that maps e.g. `'2019-08'` to the
// latest available version in that range (e.g. `'2019-08-18'`), it
// can go here.
return version;
};

module.exports = getSpecificVersion;
20 changes: 20 additions & 0 deletions engines/escargot/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2019 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// <https://apache.org/licenses/LICENSE-2.0>.
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an “AS IS” BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

module.exports = {
name: 'Escargot',
id: 'escargot',
alias: false,
};
48 changes: 48 additions & 0 deletions engines/escargot/predict-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2019 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// <https://apache.org/licenses/LICENSE-2.0>.
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an “AS IS” BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const predictFileName = (os) => {
switch (os) {
case 'win32': {
return 'win-x86';
}
case 'win64': {
return 'win-x64';
}
case 'linux32': {
return 'linux-x86';
}
case 'linux64': {
return 'linux-x64';
}
case 'mac64':
case 'mac64arm': {
return os;
}
default: {
throw new Error(
`Escargot does not offer precompiled ${os} binaries.`
);
}
}
};

const predictUrl = (version, os) => {
const fileName = predictFileName(os);
const url = `https://github.com/Samsung/escargot/releases/download/v${version}/escargot-${fileName}.zip`;
return url;
};

module.exports = predictUrl;
36 changes: 36 additions & 0 deletions engines/escargot/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2019 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// <https://apache.org/licenses/LICENSE-2.0>.
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an “AS IS” BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const fs = require('fs');

const execa = require('execa');
const tempy = require('tempy');

const config = require('../../shared/config.js');
const jsvuBinPath = config.binPath;

const test = async ({ binary }) => {
const path = tempy.file();
const program = `print('Hi!');\n`;
fs.writeFileSync(path, program);
console.assert(
(await execa(`${jsvuBinPath}/${binary}`, ['-f', path])).stdout === 'Hi!'
);
console.assert(
(await execa(`${jsvuBinPath}/${binary}`, ['-e', program])).stdout === 'Hi!'
);
};

module.exports = test;
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
},
"scripts": {
"test": "echo 'Use `npm run test-$os` where `$os` reflects your system.'; echo 'See `npm run` for the full list.' && exit 1",
"test-mac64": "npm link; jsvu --os=mac64 --engines=all && echo '{\"os\":\"mac64\",\"engines\":[\"chakra\",\"hermes\",\"javascriptcore\",\"spidermonkey\",\"v8\"],\"chakra\":\"0\",\"javascriptcore\":\"0\",\"spidermonkey\":\"0\",\"v8\":\"0\"}' > ~/.jsvu/status.json && jsvu",
"test-mac64arm": "npm link; jsvu --os=mac64arm --engines=all && echo '{\"os\":\"mac64arm\",\"engines\":[\"chakra\",\"hermes\",\"javascriptcore\",\"spidermonkey\",\"v8\"],\"chakra\":\"0\",\"javascriptcore\":\"0\",\"spidermonkey\":\"0\",\"v8\":\"0\"}' > ~/.jsvu/status.json && jsvu",
"test-linux32": "npm link; jsvu --os=linux32 --engines=all && echo '{\"os\":\"linux32\",\"engines\":[\"chakra\",\"javascriptcore\",\"spidermonkey\",\"v8\"],\"chakra\":\"0\",\"javascriptcore\":\"0\",\"spidermonkey\":\"0\",\"v8\":\"0\"}' > ~/.jsvu/status.json && jsvu",
"test-linux64": "npm link; jsvu --os=linux64 --engines=all && echo '{\"os\":\"linux64\",\"engines\":[\"chakra\",\"hermes\",\"javascriptcore\",\"quickjs\",\"spidermonkey\",\"v8\"],\"chakra\":\"0\",\"javascriptcore\":\"0\",\"spidermonkey\":\"0\",\"v8\":\"0\"}' > ~/.jsvu/status.json && jsvu",
"test-mac64": "npm link; jsvu --os=mac64 --engines=all && echo '{\"os\":\"mac64\",\"engines\":[\"chakra\",\"hermes\",\"javascriptcore\",\"spidermonkey\",\"v8\",\"escargot\"],\"chakra\":\"0\",\"javascriptcore\":\"0\",\"spidermonkey\":\"0\",\"v8\":\"0\"}' > ~/.jsvu/status.json && jsvu",
"test-mac64arm": "npm link; jsvu --os=mac64arm --engines=all && echo '{\"os\":\"mac64arm\",\"engines\":[\"chakra\",\"hermes\",\"javascriptcore\",\"spidermonkey\",\"v8\",\"escargot\"],\"chakra\":\"0\",\"javascriptcore\":\"0\",\"spidermonkey\":\"0\",\"v8\":\"0\"}' > ~/.jsvu/status.json && jsvu",
"test-linux32": "npm link; jsvu --os=linux32 --engines=all && echo '{\"os\":\"linux32\",\"engines\":[\"chakra\",\"javascriptcore\",\"spidermonkey\",\"v8\",\"escargot\"],\"chakra\":\"0\",\"javascriptcore\":\"0\",\"spidermonkey\":\"0\",\"v8\":\"0\"}' > ~/.jsvu/status.json && jsvu",
"test-linux64": "npm link; jsvu --os=linux64 --engines=all && echo '{\"os\":\"linux64\",\"engines\":[\"chakra\",\"hermes\",\"javascriptcore\",\"quickjs\",\"spidermonkey\",\"v8\",\"escargot\"],\"chakra\":\"0\",\"javascriptcore\":\"0\",\"spidermonkey\":\"0\",\"v8\":\"0\"}' > ~/.jsvu/status.json && jsvu",
"test-win32": "npm link; jsvu --os=win32 --engines=all && echo '{\"os\":\"win32\",\"engines\":[\"chakra\",\"javascriptcore\",\"spidermonkey\",\"v8\"],\"chakra\":\"0\",\"javascriptcore\":\"0\",\"spidermonkey\":\"0\",\"v8\":\"0\"}' > ~/.jsvu/status.json && jsvu",
"test-win64": "npm link; jsvu --os=win64 --engines=all && jsvu && echo '{\"os\":\"win64\",\"engines\":[\"chakra\",\"hermes\",\"javascriptcore\",\"spidermonkey\",\"v8\"],\"chakra\":\"0\",\"javascriptcore\":\"0\",\"spidermonkey\":\"0\",\"v8\":\"0\"}' > ~/.jsvu/status.json && jsvu"
},
Expand Down