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

marionette-client

Package Overview
Dependencies
Maintainers
2
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

marionette-client - npm Package Compare versions

Comparing version 0.5.4 to 0.6.0-alpha.0

bin/marionette-http-proxy

46

lib/marionette/client.js

@@ -71,2 +71,15 @@ (function(module, ns) {

this.defaultCallback = options.defaultCallback || false;
// pick up some options from the driver
if (driver.defaultCallback && !this.defaultCallback) {
this.defaultCallback = driver.defaultCallback;
}
if (driver.isSync) {
this.isSync = driver.isSync;
}
if (!this.defaultCallback && driver.defaultCallback) {
this.defaultCallback = driver.defaultCallback;
}
}

@@ -133,4 +146,8 @@

this.driver.send(cmd, cb);
var driverSent = this.driver.send(cmd, cb);
if (this.isSync) {
return driverSent;
}
return this;

@@ -152,3 +169,3 @@ },

callback.apply(this, args);
return callback.apply(this, args);
},

@@ -170,8 +187,13 @@

var self = this;
var result;
this.send(command, function(data) {
var value = self._transformResultValue(data[responseKey]);
self._handleCallback(callback, data.error, value);
return this.send(command, function(data) {
var value;
try {
value = self._transformResultValue(data[responseKey]);
} catch(e) {
console.log(data, '<___ WTF?');
}
return self._handleCallback(callback, data.error, value);
});
return this;
},

@@ -211,6 +233,6 @@

self.session = data.value;
self._handleCallback(callback, data.error, data);
return self._handleCallback(callback, data.error, data);
}
this.send({ type: 'newSession' }, newSession);
return this.send({ type: 'newSession' }, newSession);
},

@@ -226,2 +248,4 @@

startSession: function startSession(callback) {
callback = callback || this.defaultCallback;
var self = this;

@@ -246,8 +270,6 @@ return this._getActorId(function() {

this._sendCommand(cmd, 'ok', function(err, value) {
return this._sendCommand(cmd, 'ok', function(err, value) {
self.driver.close();
self._handleCallback(callback, err, value);
});
return this;
},

@@ -667,3 +689,3 @@

}
self._handleCallback(callback, err, element);
return self._handleCallback(callback, err, element);
});

@@ -670,0 +692,0 @@ },

@@ -8,2 +8,5 @@ (function(module, ns) {

var isXpc = !isNode && (typeof(window.xpcModule) !== 'undefined');
var wire = typeof jsonWireProtocol !== 'undefined' ?
jsonWireProtocol :
require('json-wire-protocol');

@@ -27,10 +30,10 @@ if (isNode) {

function CommandStream(socket) {
this.buffer = '';
this.inCommand = false;
this.commandLength = 0;
this.socket = socket;
this._handler = new wire.Stream();
this._handler.on('data', this.emit.bind(this, this.commandEvent));
Responder.apply(this);
socket.on('data', this.add.bind(this));
socket.on('data', this._handler.write.bind(this._handler));
socket.on('error', function() {

@@ -46,10 +49,2 @@ console.log(arguments);

/**
* Length prefix
*
* @property prefix
* @type String
*/
proto.prefix = ':';
/**
* name of the event this class

@@ -74,75 +69,6 @@ * will emit when a response to a

proto.stringify = function stringify(command) {
var string;
if (typeof(command) === 'string') {
string = command;
} else {
string = JSON.stringify(command);
}
return String(string.length) + this.prefix + string;
return wire.stringify(command);
};
/**
* Accepts raw string command parses it and
* emits a commandEvent.
*
* @private
* @method _handleCommand
* @param {String} string raw response from marionette.
*/
proto._handleCommand = function _handleCommand(string) {
debug('got raw bytes ', string);
var data = JSON.parse(string);
debug('sending event', data);
this.emit(this.commandEvent, data);
};
/**
* Checks if current buffer is ready to read.
*
* @private
* @method _checkBuffer
* @return {Boolean} true when in a command and buffer \
* is ready to begin reading.
*/
proto._checkBuffer = function _checkBuffer() {
var lengthIndex;
if (!this.inCommand) {
lengthIndex = this.buffer.indexOf(this.prefix);
if (lengthIndex !== -1) {
this.commandLength = parseInt(this.buffer.slice(0, lengthIndex));
this.buffer = this.buffer.slice(lengthIndex + 1);
this.inCommand = true;
}
}
return this.inCommand;
};
/**
* Read current buffer.
* Drain and emit all comands from the buffer.
*
* @method _readBuffer
* @private
* @return {Object} self.
*/
proto._readBuffer = function _readBuffer() {
var commandString;
if (this._checkBuffer()) {
if (this.buffer.length >= this.commandLength) {
commandString = this.buffer.slice(0, this.commandLength);
this._handleCommand(commandString);
this.buffer = this.buffer.slice(this.commandLength);
this.inCommand = false;
this._readBuffer();
}
}
return this;
};
/**
* Writes a command to the socket.

@@ -173,6 +99,12 @@ * Handles conversion and formatting of object.

proto.add = function add(buffer) {
var lengthIndex, command;
if (typeof buffer === 'string') {
if (typeof Buffer !== 'undefined') {
buffer = new Buffer(buffer);
} else if (typeof TextEncoder !== 'undefined') {
var encoder = new TextEncoder();
buffer = encoder.encode(buffer);
}
}
this.buffer += buffer.toString();
this._readBuffer();
this._handler.write(buffer);
};

@@ -179,0 +111,0 @@

@@ -5,3 +5,4 @@ (function(module, ns) {

Abstract: ns.require('drivers/abstract'),
HttpdPolling: ns.require('drivers/httpd-polling')
HttpdPolling: ns.require('drivers/httpd-polling'),
HttpProxy: ns.require('drivers/http-proxy')
};

@@ -8,0 +9,0 @@

@@ -108,3 +108,3 @@ /**

this.waiting = true;
xhr.send(this._seralize());
return xhr.send(this._seralize());
}

@@ -111,0 +111,0 @@ };

@@ -27,2 +27,3 @@ /**

var https = require('https');
var syncOp = require('sync-operation');

@@ -281,43 +282,12 @@ // Holds http.js objects

} else { // Synchronous
// Create a temporary file for communication with the other Node process
var syncFile = ".node-xmlhttprequest-sync-" + process.pid;
fs.writeFileSync(syncFile, "", "utf8");
// The async request the other Node process executes
var execString = "var http = require('http'), https = require('https'), fs = require('fs');"
+ "var doRequest = http" + (ssl?"s":"") + ".request;"
+ "var options = " + JSON.stringify(options) + ";"
+ "var responseText = '';"
+ "var req = doRequest(options, function(response) {"
+ "response.setEncoding('utf8');"
+ "response.on('data', function(chunk) {"
+ "responseText += chunk;"
+ "});"
+ "response.on('end', function() {"
+ "fs.writeFileSync('" + syncFile + "', 'NODE-XMLHTTPREQUEST-STATUS:' + response.statusCode + ',' + responseText, 'utf8');"
+ "});"
+ "response.on('error', function(error) {"
+ "fs.writeFileSync('" + syncFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
+ "});"
+ "}).on('error', function(error) {"
+ "fs.writeFileSync('" + syncFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
+ "});"
+ (data ? "req.write('" + data.replace(/'/g, "\\'") + "');":"")
+ "req.end();";
// Start the other Node Process, executing this string
syncProc = spawn(process.argv[0], ["-e", execString]);
while((self.responseText = fs.readFileSync(syncFile, 'utf8')) == "") {
// Wait while the file is empty
}
// Kill the child process once the file has data
syncProc.stdin.end();
// Remove the temporary file
fs.unlinkSync(syncFile);
if(self.responseText.match(/^NODE-XMLHTTPREQUEST-ERROR:/)) {
// If the file returned an error, handle it
var errorObj = self.responseText.replace(/^NODE-XMLHTTPREQUEST-ERROR:/, "");
self.handleError(errorObj);
var result = syncOp.run(
__dirname + '/xhr-reader.js',
{ ssl: ssl, request: options, data: data }
);
if (result.error) {
self.handleError(result.error);
} else {
// If the file returned okay, parse its data and move to the DONE state
self.status = self.responseText.replace(/^NODE-XMLHTTPREQUEST-STATUS:([0-9]*),.*/, "$1");
self.responseText = self.responseText.replace(/^NODE-XMLHTTPREQUEST-STATUS:[0-9]*,(.*)/, "$1");
self.status = result.status;
self.responseText = result.responseText;
setState(self.DONE);

@@ -330,3 +300,3 @@ }

this.status = 503;
this.statusText = error;
this.statusText = error.message;
this.responseText = error.stack;

@@ -333,0 +303,0 @@ errorFlag = true;

{
"name": "marionette-client",
"version": "0.5.4",
"version": "0.6.0-alpha.0",
"main": "lib/marionette/index",

@@ -9,3 +9,5 @@ "description": "Marionette Javascript Client",

"dependencies" : {
"debug": "~0.6"
"debug": "~0.6",
"json-wire-protocol": "0.1",
"sync-operation": "~0.0.2"
},

@@ -12,0 +14,0 @@

Sorry, the diff of this file is too big to display

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