All Projects → maple3142 → Wasm Jseval

maple3142 / Wasm Jseval

Licence: mit
A safe eval library based on WebAssembly and Duktape/QuickJS.

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Wasm Jseval

Wasm Forth
A Forth implementation compiling to WebAssembly.
Stars: ✭ 92 (-17.12%)
Mutual labels:  webassembly
Blake3
BLAKE3 hashing for JavaScript: native Node bindings (where available) and WebAssembly
Stars: ✭ 100 (-9.91%)
Mutual labels:  webassembly
Wasmplay
WASM Web "Framework" Playground
Stars: ✭ 105 (-5.41%)
Mutual labels:  webassembly
Assortedwidgets
OpenGL GUI library
Stars: ✭ 92 (-17.12%)
Mutual labels:  webassembly
Evm2wasm
[ORPHANED] Transcompiles EVM code to eWASM
Stars: ✭ 96 (-13.51%)
Mutual labels:  webassembly
Cobol Js Emscripten
Stars: ✭ 101 (-9.01%)
Mutual labels:  webassembly
Wasmer
🚀 The leading WebAssembly Runtime supporting WASI and Emscripten
Stars: ✭ 11,047 (+9852.25%)
Mutual labels:  webassembly
Runbox7
Runbox 7 web app
Stars: ✭ 107 (-3.6%)
Mutual labels:  webassembly
Wasi Fs Access
This is a demo shell powered by WebAssembly, WASI, Asyncify and File System Access API.
Stars: ✭ 98 (-11.71%)
Mutual labels:  webassembly
Csharp Eval Unity3d
C# Expression Parser for Unity3D
Stars: ✭ 102 (-8.11%)
Mutual labels:  eval
Dcmjs
dcmjs is a javascript cross-compile of dcmtk (dcmtk.org).
Stars: ✭ 92 (-17.12%)
Mutual labels:  webassembly
Telegram React
Experimental Telegram web client with tdlib, webassembly and react js under the hood
Stars: ✭ 1,332 (+1100%)
Mutual labels:  webassembly
Greenwasm
An implementation of the Webassembly spec in Rust
Stars: ✭ 102 (-8.11%)
Mutual labels:  webassembly
Emscripten Docker
Docker image with Emscripten to compile ASM.js and WebAssembly
Stars: ✭ 92 (-17.12%)
Mutual labels:  webassembly
Blockchain
Learning on block chain, step by step
Stars: ✭ 105 (-5.41%)
Mutual labels:  webassembly
Webnbt
An HTML5 NBT-editor based on emscripten
Stars: ✭ 91 (-18.02%)
Mutual labels:  webassembly
Wasmer Go
🐹🕸️ WebAssembly runtime for Go
Stars: ✭ 1,365 (+1129.73%)
Mutual labels:  webassembly
Shimmer
Image transformation in wasm using Go
Stars: ✭ 110 (-0.9%)
Mutual labels:  webassembly
Sod
An Embedded Computer Vision & Machine Learning Library (CPU Optimized & IoT Capable)
Stars: ✭ 1,460 (+1215.32%)
Mutual labels:  webassembly
Webassembly Raytracer
a performance comparison of a simple raytracer in JavaScript, asm.js, WebAssembly, and GLSL
Stars: ✭ 102 (-8.11%)
Mutual labels:  webassembly

wasm-jseval

A safe eval library based on WebAssembly and Duktape/QuickJS.

Duktape Demo | Source code of Duktape Demo

Usage

In node:

const { duktapeEval, quickjsEval } = require('wasm-jseval')
duktapeEval.getInstance().then(mod => {
	console.log(mod.eval('1+1')) // 2
	const add = mod.newFunction(['a', 'b'], 'return a+b')
	console.log(add(1, 2)) // 3
})
quickjsEval.getInstance().then(mod => {
	console.log(mod.eval('1+1')) // 2
	const add = mod.newFunction(['a', 'b'], 'return a+b')
	console.log(add(1, 2)) // 3
})

In browser:

<script src="https://unpkg.com/wasm-jseval/duktapeEval.js"></script>
<!-- <script src="https://unpkg.com/wasm-jseval/quickjsEval.js"></script> -->
<script>
	// or quickjsEval
	duktapeEval.getInstance().then(mod => {
		console.log(mod.eval('1+1')) // 2
		const add = mod.newFunction(['a', 'b'], 'return a+b')
		console.log(add(1, 2)) // 3
	})
</script>

API

duktapeEval.getInstance(): Promise<Instance>

Returns a Promise to resolve the duktapeEval instance.

quickjsEval.getInstance(): Promise<Instance>

Returns a Promise to resolve the quickjsEval instance.

Instance

Instance#eval(code: string): any

Evaluate JavaScript string in Duktape engine, and return a value.

Instance#newFunction(argnames: string[], body: string): (...any) => any

Create a function like new Function to be called afterward.

Q&A

What can it runs?

duktapeEval can run ES5 syntax and some ES6, ES7 capabilities. quickjsEval can run almost complete feature set of ES10.

Why two version?

duktapeEval is smaller, but less feature. quickjsEval has a more complete JavaScript support, but it result in bigger size.

How can I pass data to it?

JSON.stringify is your friend. newFunction is a good choice too.

How can I return data from it?

Just like normal eval, for example var a={};a.prop=1;a will return { prop: 1 }. But keep in mind, only JSON serializable data can be returned.

How big is this?

duktapeEval is about 348kB, and gzipped version is 154kB. quickjsEval is about 484kB, and gzipped version is 225kB.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].