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

eshost

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eshost - npm Package Compare versions

Comparing version 3.5.1 to 3.6.0

31

lib/agents/BrowserAgent.js

@@ -21,2 +21,5 @@ 'use strict';

});
// A method for cancelling the current `evalScript` operation (if any)
this._cancelEval = null;
}

@@ -26,5 +29,21 @@

code = this.compile(code, options);
return Server.waitForClientId(this.id).then(handler => {
let cancelled = false;
const whenCancelled = new Promise(resolve => {
this._cancelEval = () => {
cancelled = true;
resolve({ stdout: '', stderr: '', error: null });
};
});
const whenEvaluated = Server.waitForClientId(this.id).then(handler => {
if (cancelled) {
return;
}
handler._socket.emit('exec', code);
return Server.waitForResult(this.id).then(result => {
if (cancelled) {
return;
}
// normalize empty string to undefined

@@ -38,4 +57,14 @@ if (result.error) {

});
return Promise.race([whenEvaluated, whenCancelled]);
}
stop() {
if (this._cancelEval) {
this._cancelEval();
}
return Promise.resolve();
}
destroy() {

@@ -42,0 +71,0 @@ return super.destroy().then(() => Server.stop(this.id));

51

lib/ConsoleAgent.js

@@ -14,2 +14,6 @@ 'use strict';

this.printCommand = 'print';
// Promise for the child process created by the most recent invocation of
// `evalScript`
this._cp = null;
}

@@ -30,28 +34,29 @@

evalScript(code) {
const d = deferred();
const tempfile = temp.path({ suffix: '.js' });
code = this.compile(code);
writeFile(tempfile, code)
.then(_ => {
this._cp = this.createChildProcess([tempfile]);
this._cp = writeFile(tempfile, code)
.then(_ => this.createChildProcess([tempfile]));
return this._cp.then(child => {
let stdout = '';
let stderr = '';
this._cp.stdout.on('data', str => { stdout += this.receiveOut(this._cp, str); });
this._cp.stderr.on('data', str => { stderr += this.receiveErr(this._cp, str); });
this._cp.on('close', () => {
this._cp = null;
fs.unlink(tempfile, function () { /* ignore */ });
child.stdout.on('data', str => { stdout += this.receiveOut(child, str); });
child.stderr.on('data', str => { stderr += this.receiveErr(child, str); });
const result = this.normalizeResult({ stderr: stderr, stdout: stdout });
return new Promise(resolve => {
child.on('close', () => {
resolve({stdout, stderr});
});
});
}).then(({stdout, stderr}) => {
fs.unlink(tempfile, function () { /* ignore */ });
result.error = this.parseError(result.stderr);
d.resolve(result);
});
}).catch(err => {
d.reject(err);
const result = this.normalizeResult({ stderr: stderr, stdout: stdout });
result.error = this.parseError(result.stderr);
return result;
});
return d.promise;
}

@@ -61,3 +66,3 @@

if (this._cp) {
this._cp.kill('SIGKILL');
this._cp.then(child => child.kill('SIGKILL'));
}

@@ -107,12 +112,2 @@

function deferred() {
let res, rej;
const p = new Promise(function (resolve, reject) {
res = resolve;
rej = reject;
});
return { promise: p, resolve: res, reject: rej };
}
function promisify(api) {

@@ -119,0 +114,0 @@ return function () {

@@ -51,3 +51,4 @@ 'use strict';

Server.clientIdStopped(this.id);
this._restartP = Promise.all([quitP, getP]);
this._restartP = super.stop()
.then(() => Promise.all([quitP, getP]));
return this._restartP.then(_ => {

@@ -54,0 +55,0 @@ this._restartP = null;

{
"name": "eshost",
"version": "3.5.1",
"version": "3.6.0",
"description": "Invoke ECMAScript scripts in any command line JS engine.",

@@ -5,0 +5,0 @@ "main": "lib/eshost.js",

@@ -47,3 +47,3 @@ (function() {

}
}
};

@@ -89,2 +89,5 @@ return f$;

},
IsHTMLDDA() {
return document.all;
},
source: $SOURCE

@@ -91,0 +94,0 @@ };

@@ -36,3 +36,4 @@ var $ = {

destroy() { /* noop */ },
IsHTMLDDA() { return {}; },
source: $SOURCE
};
var $ = {
global: this,
createRealm: function (options) {
createRealm(options) {
options = options || {};

@@ -24,3 +24,3 @@ options.globals = options.globals || {};

},
evalScript: function (code) {
evalScript(code) {
try {

@@ -33,11 +33,12 @@ Realm.eval(this.realm ? this.realm : Realm.current(), code);

},
getGlobal: function (name) {
getGlobal(name) {
return this.global[name];
},
setGlobal: function (name, value) {
setGlobal(name, value) {
this.global[name] = value;
},
destroy: function() { /* noop */ },
destroy() { /* noop */ },
IsHTMLDDA() { return {}; },
source: $SOURCE
};
Realm.shared = $;

@@ -46,3 +46,4 @@ var $ = {

},
destroy: function() { /* noop */ },
destroy() { /* noop */ },
IsHTMLDDA() { return {}; },
source: $SOURCE,

@@ -49,0 +50,0 @@ file: $FILE,

@@ -37,3 +37,4 @@ var $ = {

destroy: function() { /* noop */ },
IsHTMLDDA: function() { return {}; },
source: $SOURCE
};
var vm = require('vm');
var $ = {
global: this,
createRealm: function (options) {
createRealm(options) {
options = options || {};

@@ -28,3 +28,3 @@ options.globals = options.globals || {};

},
evalScript: function (code) {
evalScript(code) {
try {

@@ -42,11 +42,12 @@ if (this.context) {

},
getGlobal: function (name) {
getGlobal(name) {
return this.global[name];
},
setGlobal: function (name, value) {
setGlobal(name, value) {
this.global[name] = value;
},
destroy: function() { /* noop */ },
destroy() { /* noop */ },
IsHTMLDDA() { return {}; },
source: $SOURCE
};
function print() { console.log.apply(console, arguments) }

@@ -35,5 +35,6 @@ var $ = {

},
destroy: function() { /* noop */ },
destroy() { /* noop */ },
IsHTMLDDA() { return objectEmulatingUndefined(); },
source: $SOURCE
};

@@ -0,0 +0,0 @@ module.exports = [

@@ -5,2 +5,3 @@ 'use strict';

const assert = require('assert');
const fs = require('fs');

@@ -10,2 +11,3 @@ const isWindows = process.platform === 'win32' ||

process.env.OSTYPE === 'msys';
const remoteCapabilities = {

@@ -47,2 +49,6 @@ browserName: process.env.ESHOST_REMOTE_BROWSERNAME || 'firefox',

if (options.hostPath && !fs.existsSync(options.hostPath)) {
throw new Error('Unable to run tests - host not found: ' + options.hostPath);
}
describe(`${type} (${options.hostPath || effectiveType})`, function () {

@@ -430,2 +436,16 @@ this.timeout(20000);

// The host may need to perform a number of asynchronous operations in
// order to evaluate a script. If the `stop` method is invoked while
// these operations are taking place, the host should not evaluate the
// script.
it('avoids race conditions in `stop`', function () {
const evalScript = agent.evalScript('print(1);');
agent.stop();
return evalScript.then(result => {
assert.equal(result.stdout, '');
});
});
// mostly this test shouldn't hang (if it hangs, it's a bug)

@@ -535,3 +555,19 @@ it('can kill infinite loops', function () {

});
describe('`IsHTMLDDA`', function () {
it('has a default IsHTMLDDA', function () {
return runify.createAgent(type, options).then(agent => {
let p = agent.evalScript('print(typeof $.IsHTMLDDA);').then(result => {
assert(result.error === null, 'no error');
assert.equal(result.stdout.indexOf('function'), 0);
agent.destroy();
});
p.catch(function() {}).then(() => agent.destroy());
return p;
});
});
});
});
});
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