New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

isolated-vm

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isolated-vm - npm Package Compare versions

Comparing version 1.4.2 to 1.5.0

parallel-sort-example.js

4

inspector-example.js

@@ -35,3 +35,3 @@ 'use strict';

// Relay messages from frontend to backend
ws.on('message', function(message) {
ws.on('message', function(message) {
try {

@@ -43,3 +43,3 @@ channel.dispatchProtocolMessage(message);

}
});
});

@@ -46,0 +46,0 @@ // Relay messages from backend to frontend

@@ -64,2 +64,32 @@ declare module 'isolated-vm' {

/**
* The total CPU and wall time spent in this isolate. CPU time is the amount
* of time the isolate has spent actively doing work on the CPU. Wall time
* is the amount of time the isolate has been running, including passive
* time spent waiting (think "wall" like a clock on the wall). For instance,
* if an isolate makes a call into another isolate, wall time will continue
* increasing while CPU time will remain the same.
*
* The return format is [ seconds, nanoseconds ], which is the same as the
* nodejs method [process.hrtime](https://nodejs.org/api/process.html#process_process_hrtime_time).
* To convert this value to milliseconds you could do something like: (ret[0] + ret[1] / 1e9) * 1000.
* Some precision is lost in this conversion but for most applications it's probably not a big deal.
*
* Note that CPU time may vary drastically if there is contention for the CPU.
* This could occur if other processes are trying to do work, or if you have
* more than require('os').cpus().length isolates currently doing work in the same nodejs process.
*/
cpuTime: [number, number];
wallTime: [number, number];
/**
* Returns the total count of active Reference instances that belong to this isolate.
* Note that in certain cases many Reference instances in JavaScript will point to
* the same underlying reference handle, in which case this number will only reflect
* the underlying reference handle. This happens when you transfer a Reference instance
* via some method which accepts transferable values. This will also include underlying
* reference handles created by isolated-vm like Script or Context objects.
*/
referenceCount: number;
/**
* Flag that indicates whether this isolate has been disposed.

@@ -181,2 +211,3 @@ */

*/
global: Reference<Object>;
globalReference(): Reference<Object>;

@@ -280,2 +311,16 @@

applySync(receiver?: any, arguments?: Transferable[], options?: ScriptRunOptions): any;
/**
* `applySyncPromise` is a special version of `applySync` which may only be
* invoked on functions belonging to the default isolate AND may only be
* invoked from a non-default thread. Functions invoked in this way may
* return a promise and the invoking isolate will wait for that promise to
* resolve before resuming execution. You can use this to implement functions
* like readFileSync in a way that doesn't block the default isolate. Note that
* the invoking isolate will not respond to any async functions until this
* promise is resolved, however synchronous functions will still function
* correctly. Misuse of this feature may result in deadlocked isolates, though
* the default isolate will never be at risk of a deadlock.
*/
applySyncPromise(receiver?: any, arguments?: Transferable[], options?: ScriptRunOptions): any;
}

@@ -282,0 +327,0 @@

{
"name": "isolated-vm",
"version": "1.4.2",
"version": "1.5.0",
"description": "Access to multiple isolates",

@@ -5,0 +5,0 @@ "main": "isolated-vm.js",

@@ -159,3 +159,3 @@ [![npm version](https://img.shields.io/npm/v/isolated-vm.svg)](https://www.npmjs.com/package/isolated-vm) [![isc license](https://img.shields.io/npm/l/isolated-vm.svg)](https://github.com/laverdet/isolated-vm/blob/master/LICENSE) [![travis build](https://img.shields.io/travis/laverdet/isolated-vm/master.svg)](https://travis-ci.org/laverdet/isolated-vm)

The return format is `[ seconds, nanoseconds ]`, which is the same as the nodejs method
`[process.hrtime](https://nodejs.org/api/process.html#process_process_hrtime_time)`. To convert this
[`process.hrtime`](https://nodejs.org/api/process.html#process_process_hrtime_time). To convert this
value to milliseconds you could do something like: `(ret[0] + ret[1] / 1e9) * 1000`. Some precision

@@ -195,7 +195,15 @@ is lost in this conversion but for most applications it's probably not a big deal.

##### `script.run(context)` *[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)*
##### `script.runIgnored(context)`
##### `script.runSync(context)`
##### `script.release()`
Releases the reference to this script, allowing the script data to be garbage collected. Functions
and data created in the isolate by previous invocations to `script.run(...)` will still be alive in
their respective contexts-- this only means that you can't invoke `script.run(...)` again with this
reference.
##### `script.run(context, options)` *[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)*
##### `script.runIgnored(context, options)`
##### `script.runSync(context, options)`
* `context` *[`Context`](#class-context-transferable)* - The context in which this script will run.
* `options` *[object]*
* `release` *[boolean]* - If true `release()` will automatically be called on this instance.
* `timeout` *[number]* - Maximum amount of time this script is allowed to run before execution is

@@ -210,2 +218,3 @@ canceled. Default is no timeout.

### Class: `Reference` *[transferable]*

@@ -287,5 +296,6 @@ A instance of [`Reference`](#class-reference-transferable) is a pointer to a value stored in any isolate.

async functions until this promise is resolved, however synchronous functions will still function
correctly. Misuse of this feature may result in deadlocked isolates, though the default isolate
correctly. Misuse of this feature may result in deadlocked isolates, though the default isolate
will never be at risk of a deadlock.
### Class: `ExternalCopy` *[transferable]*

@@ -480,27 +490,3 @@ Instances of this class represent some value that is stored outside of any v8 isolate. This value

A quick example which shows how the snapshot feature works.
```js
let ivm = require('isolated-vm');
// Create a new snapshot which adds the `sum` function to all contexts created
let snapshot = ivm.Isolate.createSnapshot([ { code: 'function sum(a,b) { return a + b }' } ]);
// v8 provides the ability to "warmup" snapshots by calling the functions inside your snapshot which
// will trigger a code compilation, you can use the second parameter for that. A much easier way to
// included compiled code in the snapshot would be to run node with `--nolazy` when you generate the
// snapshot, then you can load the snapshot into your node instances using no special flags.
//
// `snapshot` is an ExternalCopy[ArrayBuffer]. If you wanted to save this snapshot to a file you
// would do this:
// fs.writeFileSync('snapshot.bin', Buffer.from(snapshot.copy()))
//
// And then to read it in again:
// snapshot = new ivm.ExternalCopy(fs.readFileSync('snapshot.bin').buffer);
// Here we'll create a new isolate using this snapshot and confirm that our `sum` function is there
let isolate = new ivm.Isolate({ snapshot });
let context = isolate.createContextSync();
let script = isolate.compileScriptSync('sum(1, 2)');
console.log(script.runSync(context));
// logs: 3
```
Included in the repository is an example of how you can write quicksort using a SharedArrayBuffer to
sort over multiple threads. See: [parallel-sort-example.js](https://github.com/laverdet/isolated-vm/blob/master/parallel-sort-example.js).

@@ -7,3 +7,13 @@ // For some reason this simple case triggered a bug that was due to unexpected ordering of static

let script = isolate.compileScriptSync('1');
script.runSync(context);
console.log('pass');
script.runSync(context, { release: true });
try {
script.runSync(context);
} catch (err) {
let script = isolate.compileScriptSync('1');
script.release();
try {
script.run(context);
} catch (err) {
console.log('pass');
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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