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

async-eval

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-eval

Execute arbitrary JS with callbacks

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

async-eval

Execute arbitrary JS with callbacks in node.js. Also counts asynchronous operations and does not return until all callbacks have been executed.

Note: This library actually uses vm.runInNewContext() instead of eval() for a bit more added security, though it doesn't fork a process, so it's best used with trusted code.

Installation

npm install async-eval
npm test

or

git clone https://github.com/dallonf/async-eval
npm install
npm test 

Example usage

var asyncEval = require('async-eval');

var someObject = {x: 5, y: 10};

function waitOneSecond(callback) {
  setTimeout(callback, 1000);
}

var options = {
  this: someObject,
  asyncFunctions: {
    waitOneSecond: waitOneSecond
  }
}

asyncEval('waitOneSecond(function() { this.x += 2; });', options, function() {
  console.log(someObject.x); // 7
});

Usage

asyncEval(code, [options], [callback])

asyncEval() will interpret and execute code and run callback when the code and every asynchronous function it calls has finished running.

Options

this

Default: {}

Sets the object that will be used as this in the executed code and any nested callbacks.

context

Default: {}

Sets the global context in the executed code. Put any synchronous DSL functions and global variables here.

asyncFunctions

Default: {}

Registers asynchronous functions into the context. Asynchronous functions must be listed in the asyncFunctions property so that asyncEval can count pending callbacks.

The functions registered in asyncFunctions must take a callback as the last argument.

These functions can be namespaced with objects, for example:

asyncFunctions: {
  users: {
    get: function(callback) { /* ... */ },
    create: function(user, callback) { /* ... */ },
  },
  posts: {
    get: function(callback) { /* ... */ },
    create: function(post, callback) { /* ... */ },
  }
}

FAQs

Package last updated on 05 Nov 2012

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