A JavaScript Runtime implement in JavaScript.
Inspired by QuickJS.
- Provide a easy way to learning JavaScript engine. No needs to learn C.
- Only support
strict modeand modern JavaScript feature.- Such as
let,const,async,await,arrow function,class, etc. - Not implement
with,eval,var,labeletc.
- Such as
- Please do not using this project for your production without any tested.
- Flexable, you can only use the part of JavaScript.
- Some prototype function of Builtin Object depends on the host environmnet.
- For example, if you want to use
Array.prototype.atin vm, you need make sure it can been used in host vm. Or you need to load ployfill.
- For example, if you want to use
# instal as global
npm install @xgheaven/jsscript -gIt's like Node.js cli without special module.
jsscript run your-file.js# install
npm install @xgheaven/jsscriptimport { Runtime, Features, parseScript, parseBytecode, toHostValue } from 'jsscript'
const runtime = new Runtime({
features: [
// inject builtin features
new Features.ECMA262Feature(), // inject All ECMA262 Spec object, like `Promise`/`RegExp`/...
// you can write your self feature
],
})
const context = runtime.newContext()
const script = `<your-script>`;
// parse it to function object
const fn = parseScript(context, script)
// or compile it bytecode then parse it
const bc = compileToBytecode(script)
const fn = parseBytecode(context, bc)
// run it
const ret = context.run(fn)
// convert js value of vm to host vm
console.log(toHostValue(ret))TODO
TODO
The performance is not the core of jsscript. But It's still important for using. Using v8-7 version benchmark test. (It's so old, only support es5. I will find more newer test cases in the future to replace it)
| jsscript | sablejs | eval5 | |
|---|---|---|---|
| Language | TypeScript | JavaScript | TypeScript |
| Support Version | ES6(target) | ES5 | ES5 |
| Version | see package.json |
1.1.0 |
1.4.7 |
crypto Score |
- | - | - |
deltablue Score |
- | - | - |
earley-boyer Score |
- | - | - |
navier-stokes Score |
- | - | - |
raytrace Score |
- | - | - |
regexp Score |
- | - | - |
richards Score |
- | - | - |
splay Score |
- | - | - |
| Total Score | - | - | - |
I want to use jsscript as package name.
But it too similar to the package js-script which published 10+ years ago.
I have to add the personal scope in the package name.