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 mode
and modern JavaScript feature.- Such as
let
,const
,async
,await
,arrow function
,class
, etc. - Not implement
with
,eval
,var
,label
etc.
- 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.at
in 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 -g
It's like Node.js
cli without special module.
jsscript run your-file.js
# install
npm install @xgheaven/jsscript
import { 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
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.