-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
34 lines (28 loc) · 876 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const supportedVersions = ['20210327'];
class Qjsc {
constructor(options = {}) {
let version = options.version || '20210327';
if (supportedVersions.indexOf(version) === -1) {
throw new Error('Unsupported QuickJS version: ' + version);
}
// TODO: Multiple quickjs version switch are removed because of prebuilt library.
this._bindings = require('node-gyp-build')(__dirname);
}
help() {
console.log('Supported QuckJS versions: ' + supportedVersions.join(', '));
}
getSupportedVersions() {
return supportedVersions;
}
compile(code, options = {}) {
let sourceURL = options.sourceURL || 'internal://';
return this._bindings.dumpByteCode(code, sourceURL);
}
get version() {
return this._bindings.version;
}
_evalByteCode(buffer) {
return this._bindings.evalByteCode(buffer);
}
}
module.exports = Qjsc;