JSPM

  • Created
  • Published
  • Downloads 30
  • Score
    100M100P100Q63153F
  • License MIT

Controlled JavaScript code execution and instrumentation.

Package Exports

  • lively.vm
  • lively.vm/dist/lively.vm.js
  • lively.vm/dist/lively.vm_no-deps.js
  • lively.vm/lib/eval-strategies.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lively.vm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

lively.vm Build Status

Controlled JavaScript code execution and instrumentation.

interface

lively.vm.runEval(sourceString, options)

To evaluate an expression in the context of a module (to access and modify its internal state) you can use the runEval method.

Example: If you have a module a.js with the source code

var x = 23;
export x;

you can evaluate an expression like x + 2 via lively.vm.runEval("x + 2", {targetModule: "a.js"}). This will return a promise that resolves to an EvalResult object. The eval result will have a field value which is the actual return value of the last expression evaluated. In this example it is the number 25.

Note: Since variable x is exported by a.js the evaluation will also affect the exported value of the module. Dependent modules will automatically have access to the new exported value x.

Caveat in the current version: When evaluating new exports (exports that didn't exist when the module was first imported) you need to run lively.modules.reloadModule to properly update dependent modules!

notifications

There are two types of system-wide notifications:

  1. {type: "lively.vm/doitrequest", code, targetModule, waitForPromise}
  2. {type: "lively.vm/doitresult", code, targetModule, waitForPromise, result}

These notifications are all emitted with lively.notifications.

LICENSE

MIT