Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tootallnate/quickjs-emscripten

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tootallnate/quickjs-emscripten

Javascript/Typescript bindings for QuickJS, a modern Javascript interpreter, compiled to WebAssembly.

  • 0.23.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.7M
decreased by-16.83%
Maintainers
1
Weekly downloads
 
Created

What is @tootallnate/quickjs-emscripten?

The @tootallnate/quickjs-emscripten package allows you to run a QuickJS JavaScript engine in a web browser or Node.js environment using Emscripten-compiled WebAssembly. This enables you to execute JavaScript code within a separate QuickJS virtual machine, providing a sandboxed environment for running scripts.

What are @tootallnate/quickjs-emscripten's main functionalities?

Evaluating JavaScript code

This feature allows you to evaluate arbitrary JavaScript code within the QuickJS virtual machine. The code sample demonstrates how to create a new QuickJS VM, evaluate a simple expression, and log the result.

const { getQuickJS } = require('@tootallnate/quickjs-emscripten');

async function main() {
  const QuickJS = await getQuickJS();
  const vm = QuickJS.createVm();

  const result = vm.evalCode('1 + 1');
  console.log(result.value); // 2

  vm.dispose();
}

main();

Compiling JavaScript code to bytecode

This feature allows you to compile JavaScript code to bytecode and then execute it within the QuickJS VM. The code sample shows how to compile a script and then evaluate the compiled bytecode.

const { getQuickJS } = require('@tootallnate/quickjs-emscripten');

async function main() {
  const QuickJS = await getQuickJS();
  const vm = QuickJS.createVm();

  const { bytecode } = vm.compileCode('console.log("Hello, World!")');
  vm.evalBinary(bytecode);

  vm.dispose();
}

main();

Marshalling values between JS and QuickJS

This feature allows you to marshal values between the native JavaScript environment and the QuickJS VM. The code sample demonstrates creating a new object in QuickJS from a JavaScript object and then dumping it back to a JavaScript value.

const { getQuickJS } = require('@tootallnate/quickjs-emscripten');

async function main() {
  const QuickJS = await getQuickJS();
  const vm = QuickJS.createVm();

  const jsValue = { hello: 'world' };
  const quickjsValue = vm.newObject(jsValue);

  const result = vm.dump(quickjsValue);
  console.log(result); // { hello: 'world' }

  vm.dispose();
}

main();

Other packages similar to @tootallnate/quickjs-emscripten

Keywords

FAQs

Package last updated on 18 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc