Comparing version 3.0.0 to 3.1.0
{ | ||
"name": "eshost", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Invoke ECMAScript scripts in any command line JS engine.", | ||
@@ -5,0 +5,0 @@ "main": "lib/eshost.js", |
@@ -98,3 +98,3 @@ ## eshost | ||
#### $.createRealm(globals) | ||
#### $.createRealm(options) | ||
Creates a new realm, returning that realm's runtime library ($). | ||
@@ -109,2 +109,19 @@ | ||
You can also use a destroy callback that gets called when the code inside the realm calls `$.destroy()`. For example: | ||
```js | ||
$sub = $.createRealm({ | ||
destroy: function () { | ||
print('destroyed!') | ||
} | ||
}); | ||
$sub.evalScript('$.destroy()'); // prints "destroyed!" | ||
``` | ||
Options: | ||
* globals: an object containing properties to add to the global object in the new realm. | ||
* destroy: a callback that is called when the code executing in the realm destroys its realm (ie. by calling `$.destroy()`). | ||
#### $.evalScript(code) | ||
@@ -115,2 +132,5 @@ Creates a new script and evals `code` in that realm. If an error is thrown, it will be passed to the onError callback. | ||
#### $.destroy() | ||
Destroys the realm. Note that in some hosts, $.destroy may not actually stop executing code in the realm or even destroy the realm. | ||
#### $.getGlobal(name) | ||
@@ -117,0 +137,0 @@ Gets a global property name. |
@@ -9,2 +9,7 @@ var $ = { | ||
realm.$.source = this.source; | ||
realm.$.destroy = function () { | ||
if (options.destroy) { | ||
options.destroy(); | ||
} | ||
}; | ||
@@ -11,0 +16,0 @@ for(var glob in options.globals) { |
@@ -13,3 +13,7 @@ var $ = { | ||
Realm.shared = void 0; | ||
$child.destroy = function () { | ||
if (options.destroy) { | ||
options.destroy(); | ||
} | ||
}; | ||
for(var glob in options.globals) { | ||
@@ -16,0 +20,0 @@ $child.setGlobal(glob, options.globals[glob]); |
@@ -13,2 +13,7 @@ var $ = { | ||
realm.$.source = this.source; | ||
realm.$.destroy = function () { | ||
if (options.destroy) { | ||
options.destroy(); | ||
} | ||
}; | ||
@@ -15,0 +20,0 @@ for(var glob in options.globals) { |
@@ -10,2 +10,7 @@ var $ = { | ||
realm.$.source = this.source; | ||
realm.$.destroy = function () { | ||
if (options.destroy) { | ||
options.destroy(); | ||
} | ||
}; | ||
@@ -12,0 +17,0 @@ for(var glob in options.globals) { |
@@ -21,2 +21,7 @@ var vm = require('vm'); | ||
context.$.context = context; | ||
context.$.destroy = function () { | ||
if (options.destroy) { | ||
options.destroy(); | ||
} | ||
}; | ||
return context.$; | ||
@@ -23,0 +28,0 @@ }, |
@@ -10,3 +10,7 @@ var $ = { | ||
realm.$.source = this.source; | ||
realm.$.destroy = function () { | ||
if (options.destroy) { | ||
options.destroy(); | ||
} | ||
}; | ||
for(var glob in options.globals) { | ||
@@ -13,0 +17,0 @@ realm.$.global[glob] = options.globals[glob]; |
19
test.js
var fs = require('fs'); | ||
var esh = require('./'); | ||
var payload = fs.readFileSync('./inproc.js', 'utf8'); | ||
//var agent = esh.createAgent('ch', { hostPath: 'c:/users/brterlso/projects/chakracore/build/vcbuild/bin/x64_test/ch.exe'}); | ||
//esh.createAgent('firefox').then(agent => { | ||
var payload = fs.readFileSync('./test-promise.js', 'utf8'); | ||
var agent; | ||
//esh.createAgent('chrome', { hostPath: undefined }).then(a => { | ||
esh.createAgent('ch', { hostPath: 'c:/users/brterlso/projects/chakracore/build/vcbuild/bin/x64_test/ch.exe'}).then(a => { | ||
esh.createAgent('chrome', { hostPath: 'C:/Users/brterlso/AppData/Local/Google/Chrome SxS/Application/chrome.exe'}).then(a => { | ||
agent = a; | ||
return agent.evalScript('function Foo1Error(msg) { this.message = msg } throw new Foo1Error("FAIL");'); | ||
return agent.evalScript(payload, { async: true }); | ||
}).then(result => { | ||
console.log('result', result); | ||
agent.destroy(); | ||
}) | ||
@@ -17,10 +15,1 @@ .catch(err => console.log(err)) | ||
function check() { | ||
var res = process._getActiveHandles().map(p => p.fd); | ||
console.log(res); | ||
if (res.length > 3) { | ||
setTimeout(check, 1000); | ||
} | ||
} |
@@ -11,5 +11,5 @@ 'use strict'; | ||
['../v8/build/Release/d8.exe', 'd8'], | ||
['C:/Users/brterlso/AppData/Local/Google/Chrome SxS/Application/chrome.exe', 'chrome'], | ||
[undefined, 'chrome'], | ||
['C:/Program Files (x86)/Mozilla Firefox/firefox.exe', 'firefox'], | ||
//['C:/Users/brterlso/AppData/Local/Google/Chrome SxS/Application/chrome.exe', 'chrome'], | ||
//[undefined, 'chrome'], | ||
//['C:/Program Files (x86)/Mozilla Firefox/firefox.exe', 'firefox'], | ||
['C:/Program Files (x86)/Nightly/firefox.exe', 'firefox'], | ||
@@ -202,2 +202,12 @@ ]; | ||
it('accepts destroy callbacks', function () { | ||
return agent.evalScript(` | ||
$child = $.createRealm({ destroy: function () { print("destroyed") }}); | ||
$child.destroy(); | ||
`) | ||
.then(result => { | ||
assert(result.stdout.match(/destroyed/), 'Unexpected stdout: ' + result.stdout + result.stderr); | ||
}); | ||
}); | ||
it('runs in the proper mode', function () { | ||
@@ -204,0 +214,0 @@ return agent.evalScript(` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
64470687
113
1519
138
65