Skip to content

yocontra/puzzle-box

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

NPM version

Information

Packagepuzzle-box
Description Sandboxing with call tracing and more
Node Version >= 10

Usage

This was made to be used by blackboard.

var puzzleBox = require('puzzle-box');

var test = puzzleBox.create();

// set a global context for the sandbox
test.context({
  math: {
    add: function(a, b){
      return a+b;
    }
  }
});

// specify the code to execute
// a global function called finished will be created
// in the sandbox. call this when you are done
test.code('add(1,2); var hi = 123; finished();');

// track calls to a function in the context
test.track('math.add');

// execute the code in the sandbox
test.run();

test.on('finished', function(){
  // you can get a list of function calls
  // in order with name, arguments, and return value
  console.log(test.calls()); // logs [ { fn: 'math.add', args: [ 1, 2 ], result: 3 } ]

  // you can access the sandbox context
  // this means you can check if values have been
  // modified, created, or removed
  // in the process of running the code
  console.log(test.sandbox().hi); // logs 123

  // free the memory when we are done
  test.dispose();
});

Examples

You can view more examples in the example folder.

About

Sandboxing with call tracing and more

Resources

License

Stars

Watchers

Forks

Packages

No packages published