kopia lustrzana https://github.com/c9/core
remove unused files
rodzic
0ebda2c66a
commit
45aa5f21c8
|
@ -1,148 +0,0 @@
|
|||
chrome-remote-interface
|
||||
=======================
|
||||
|
||||
[Remote Debugging Protocol][1] interface that helps to instrument Chrome by
|
||||
providing a simple abstraction of the two main objects exposed by the protocol
|
||||
in a Node.js fashion: commands and notifications.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
npm install chrome-remote-interface
|
||||
|
||||
Chrome setup
|
||||
------------
|
||||
|
||||
Chrome needs to be started with the `--remote-debugging-port=<port>` option to
|
||||
enable the [Remote Debugging Protocol][1], for example:
|
||||
|
||||
google-chrome --remote-debugging-port=9222
|
||||
|
||||
Sample usage
|
||||
------------
|
||||
|
||||
The following snippet loads `https://github.com` and dumps every request made.
|
||||
|
||||
```javascript
|
||||
var Chrome = require('chrome-remote-interface');
|
||||
Chrome(function (chrome) {
|
||||
with (chrome) {
|
||||
on('Network.requestWillBeSent', function (message) {
|
||||
console.log(message.request.url);
|
||||
});
|
||||
on('Page.loadEventFired', close);
|
||||
Network.enable();
|
||||
Page.enable();
|
||||
Page.navigate({'url': 'https://github.com'});
|
||||
}
|
||||
}).on('error', function () {
|
||||
console.error('Cannot connect to Chrome');
|
||||
});
|
||||
```
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
### module([options], [callback])
|
||||
|
||||
Connects to a remote instance of Chrome using the [Remote Debugging
|
||||
Protocol][1].
|
||||
|
||||
`options` is an object with the following optional properties:
|
||||
|
||||
- `host`: [Remote Debugging Protocol][1] host. Defaults to `localhost`;
|
||||
- `port`: [Remote Debugging Protocol][1] port. Defaults to `9222`;
|
||||
- `chooseTab`: callback used to determine which remote tab attach to. Takes the
|
||||
JSON array returned by `http://host:port/json` containing the tab list and
|
||||
must return the numeric index of a tab. Defaults to a function that returns
|
||||
the active one (`function (tabs) { return 0; }`).
|
||||
|
||||
`callback` is a listener automatically added to the `connect` event of the
|
||||
returned `EventEmitter`.
|
||||
|
||||
Returns an `EventEmitter` that supports the following events:
|
||||
|
||||
#### Event: 'connect'
|
||||
|
||||
function (chrome) {}
|
||||
|
||||
Emitted when the connection to Chrome is established.
|
||||
|
||||
`chrome` is an instance of the `Chrome` class.
|
||||
|
||||
#### Event: 'error'
|
||||
|
||||
function (error) {}
|
||||
|
||||
Emitted if `http://host:port/json` can't be reached or if it's not possible to
|
||||
connect to Chrome's remote debugging WebSocket.
|
||||
|
||||
`error` is an instance of `Error`.
|
||||
|
||||
### Class: Chrome
|
||||
|
||||
#### Event: 'event'
|
||||
|
||||
function (message) {}
|
||||
|
||||
Emitted when Chrome sends a notification through the WebSocket.
|
||||
|
||||
`message` is the object received, it has the following properties:
|
||||
|
||||
- `method`: a string describing the message.
|
||||
- `params`: an object containing the payload.
|
||||
|
||||
Refer to the [Remote Debugging Protocol specifications][1] for more information.
|
||||
|
||||
#### Event: method
|
||||
|
||||
function (params) {}
|
||||
|
||||
Emitted when Chrome sends a notification classified as `method` through the
|
||||
WebSocket.
|
||||
|
||||
`params` is an object containing the payload.
|
||||
|
||||
This is just a utility event that allows to easily filter out specific
|
||||
notifications (see the documentation of `event`), for example:
|
||||
|
||||
chrome.on('Network.requestWillBeSent', console.log);
|
||||
|
||||
#### chrome.send(method, [params], [callback])
|
||||
|
||||
Issue a command to Chrome.
|
||||
|
||||
`method` is a string describing the message.
|
||||
|
||||
`params` is an object containing the payload.
|
||||
|
||||
`callback` is executed when Chrome sends a response to this command, it gets the
|
||||
following arguments:
|
||||
|
||||
- `error`: a boolean value indicating the success status;
|
||||
- `response`: an object containing either the response sent from Chrome or the
|
||||
indication of the error.
|
||||
|
||||
Note that the field `id` mentioned in the [Remote Debugging Protocol
|
||||
specifications][1] is managed internally and it's not exposed to the user.
|
||||
|
||||
#### chrome.Domain.method([params], [callback])
|
||||
|
||||
Just a shorthand for:
|
||||
|
||||
chrome.send('Domain.method', params, callback)
|
||||
|
||||
For example:
|
||||
|
||||
chrome.Page.navigate({'url': 'https://github.com'})
|
||||
|
||||
#### chrome.close()
|
||||
|
||||
Close the connection to Chrome.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
- [Chrome Developer Tools: Remote Debugging Protocol v1.0][1]
|
||||
|
||||
[1]: https://developers.google.com/chrome-developer-tools/docs/protocol/1.0/
|
|
@ -1,174 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2013 Andrea Cardaci <cyrus.and@gmail.com>
|
||||
I.S.T.I. - C.N.R. Pisa
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
define(function(require, exports, module) {
|
||||
var protocol = require('./protocol.js');
|
||||
var util = require("ace/lib/oop");
|
||||
var events = require('events');
|
||||
var http = require('http');
|
||||
var WebSocket = require('ws');
|
||||
|
||||
var Chrome = function (options, callback) {
|
||||
if (!(this instanceof Chrome))
|
||||
return new Chrome(options, callback);
|
||||
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = undefined;
|
||||
}
|
||||
options = options || {};
|
||||
options.host = options.host || 'localhost';
|
||||
options.port = options.port || 9222;
|
||||
options.chooseTab = options.chooseTab || function () { return 0; };
|
||||
|
||||
var notifier = new events.EventEmitter();
|
||||
if (typeof callback === 'function')
|
||||
notifier.on('connect', callback);
|
||||
|
||||
setTimeout(function() {
|
||||
// the default listener just disconnects from Chrome, this can be used
|
||||
// to simply check the connection
|
||||
if (notifier.listeners('connect').length === 0) {
|
||||
notifier.on('connect', function(chrome) {
|
||||
chrome.close();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var self = this;
|
||||
addCommandShorthands.call(self);
|
||||
self.notifier = notifier;
|
||||
self.callbacks = {};
|
||||
self.nextCommandId = 1;
|
||||
connectToChrome.call(self, options.host, options.port, options.chooseTab);
|
||||
|
||||
return notifier;
|
||||
};
|
||||
|
||||
util.inherits(Chrome, events.EventEmitter);
|
||||
|
||||
Chrome.prototype.send = function (method, params, callback) {
|
||||
var self = this;
|
||||
var id = self.nextCommandId++;
|
||||
if (typeof params === 'function') {
|
||||
callback = params;
|
||||
params = undefined;
|
||||
}
|
||||
var message = { 'id': id, 'method': method, 'params': params };
|
||||
self.ws.send(JSON.stringify(message));
|
||||
// register command response callback
|
||||
if (typeof callback === 'function') {
|
||||
self.callbacks[id] = callback;
|
||||
}
|
||||
};
|
||||
|
||||
Chrome.prototype.close = function () {
|
||||
var self = this;
|
||||
self.ws.removeAllListeners();
|
||||
self.ws.close();
|
||||
};
|
||||
|
||||
function addCommand(domain, command) {
|
||||
var self = this;
|
||||
Chrome.prototype[domain][command] = function (params, callback) {
|
||||
self.send(domain + '.' + command, params, callback);
|
||||
};
|
||||
}
|
||||
|
||||
function addCommandShorthands() {
|
||||
var self = this;
|
||||
for (var domain in protocol.commands) {
|
||||
Chrome.prototype[domain] = {};
|
||||
var commands = protocol.commands[domain];
|
||||
for (var i = 0; i < commands.length; i++) {
|
||||
var command = commands[i];
|
||||
addCommand.call(self, domain, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function connectToChrome(host, port, chooseTab) {
|
||||
var self = this;
|
||||
var options = { 'host': host, 'port': port, 'path': '/json' };
|
||||
var request = http.get(options, function (response) {
|
||||
var data = '';
|
||||
response.on('data', function (chunk) {
|
||||
data += chunk;
|
||||
});
|
||||
response.on('end', function () {
|
||||
var error;
|
||||
var tabs = JSON.parse(data);
|
||||
var tab = tabs[chooseTab(tabs)];
|
||||
if (tab) {
|
||||
var tabDebuggerUrl = tab.webSocketDebuggerUrl;
|
||||
if (tabDebuggerUrl) {
|
||||
connectToWebSocket.call(self, tabDebuggerUrl);
|
||||
} else {
|
||||
// a WebSocket is already connected to this tab?
|
||||
error = new Error('Unable to connect to the WebSocket');
|
||||
self.notifier.emit('error', error);
|
||||
}
|
||||
} else {
|
||||
error = new Error('Invalid tab index');
|
||||
self.notifier.emit('error', error);
|
||||
}
|
||||
});
|
||||
});
|
||||
request.on('error', function (error) {
|
||||
self.notifier.emit('error', error);
|
||||
});
|
||||
}
|
||||
|
||||
function connectToWebSocket(url) {
|
||||
var self = this;
|
||||
self.ws = new WebSocket(url);
|
||||
self.ws.on('open', function() {
|
||||
self.notifier.emit('connect', self);
|
||||
});
|
||||
self.ws.on('message', function (data) {
|
||||
var message = JSON.parse(data);
|
||||
// command response
|
||||
if (message.id) {
|
||||
var callback = self.callbacks[message.id];
|
||||
if (callback) {
|
||||
if (message.result) {
|
||||
callback(false, message.result);
|
||||
} else if (message.error) {
|
||||
callback(true, message.error);
|
||||
}
|
||||
// unregister command response callback
|
||||
delete self.callbacks[message.id];
|
||||
}
|
||||
}
|
||||
// event
|
||||
else if (message.method) {
|
||||
self.emit('event', message);
|
||||
self.emit(message.method, message.params);
|
||||
}
|
||||
});
|
||||
self.ws.on('error', function (error) {
|
||||
self.notifier.emit('error', error);
|
||||
});
|
||||
}
|
||||
|
||||
return Chrome;
|
||||
});
|
|
@ -1,209 +0,0 @@
|
|||
/*global describe it before */
|
||||
|
||||
"use client";
|
||||
|
||||
|
||||
require([
|
||||
"plugins/c9.ide.run.debug/debuggers/chrome/lib/chrome",
|
||||
"lib/chai/chai"
|
||||
], function (Chrome, chai) {
|
||||
var assert = chai.assert;
|
||||
|
||||
describe('connecting to Chrome', function () {
|
||||
describe('with default parameters', function () {
|
||||
it('should succeed with "connect" callback passed as an argument', function (done) {
|
||||
Chrome(function(chrome) {
|
||||
chrome.close();
|
||||
done();
|
||||
}).on('error', function () {
|
||||
assert(false);
|
||||
});
|
||||
});
|
||||
it('should succeed with "connect" callback registered later', function (done) {
|
||||
Chrome().on('connect', function(chrome) {
|
||||
chrome.close();
|
||||
done();
|
||||
}).on('error', function () {
|
||||
assert(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('with custom parameters', function () {
|
||||
it('should succeed with "connect" callback passed as an argument', function (done) {
|
||||
Chrome({ 'host': 'localhost', 'port': 9222 }, function(chrome) {
|
||||
chrome.close();
|
||||
done();
|
||||
}).on('error', function () {
|
||||
assert(false);
|
||||
});
|
||||
});
|
||||
it('should succeed with "connect" callback registered later', function (done) {
|
||||
Chrome({ 'host': 'localhost', 'port': 9222 }).on('connect', function(chrome) {
|
||||
chrome.close();
|
||||
done();
|
||||
}).on('error', function () {
|
||||
assert(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('with custom (wrong) parameters', function () {
|
||||
it('should fail (wrong port)', function (done) {
|
||||
Chrome({ 'port': 1 }, function () {
|
||||
assert(false);
|
||||
}).on('error', function (error) {
|
||||
assert(error instanceof Error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should fail (wrong host)', function (done) {
|
||||
Chrome({ 'host': '255.255.255.255' }, function () {
|
||||
assert(false);
|
||||
}).on('error', function (error) {
|
||||
assert(error instanceof Error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should fail (wrong tab)', function (done) {
|
||||
Chrome({ 'chooseTab': function () { return -1; } }, function () {
|
||||
assert(false);
|
||||
}).on('error', function (error) {
|
||||
assert(error instanceof Error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('two times', function () {
|
||||
it('should fail', function (done) {
|
||||
Chrome(function (chrome) {
|
||||
Chrome(function () {
|
||||
assert(false);
|
||||
}).on('error', function (error) {
|
||||
chrome.close();
|
||||
assert(error instanceof Error);
|
||||
done();
|
||||
});
|
||||
}).on('error', function () {
|
||||
assert(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('closing a connection', function () {
|
||||
it('should allow a subsequent new connection', function (done) {
|
||||
Chrome(function (chrome) {
|
||||
chrome.close();
|
||||
Chrome(function (chrome) {
|
||||
chrome.close();
|
||||
done();
|
||||
}).on('error', function (error) {
|
||||
assert(false);
|
||||
});
|
||||
}).on('error', function () {
|
||||
assert(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('registering event', function () {
|
||||
describe('"event"', function () {
|
||||
it('should give the raw message', function (done) {
|
||||
Chrome(function(chrome) {
|
||||
chrome.once('event', function(message) {
|
||||
chrome.close();
|
||||
assert(message.method);
|
||||
done();
|
||||
});
|
||||
chrome.send('Network.enable');
|
||||
chrome.send('Tab.reload');
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('"Console.messagesCleared"', function () {
|
||||
it('should give the payload ony', function (done) {
|
||||
Chrome(function(chrome) {
|
||||
chrome.once('Network.requestWillBeSent', function(message) {
|
||||
chrome.close();
|
||||
assert(!message.method);
|
||||
done();
|
||||
});
|
||||
chrome.send('Network.enable');
|
||||
chrome.send('Tab.reload');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sending a command', function () {
|
||||
describe('without checking the result and without specifyng parameters', function () {
|
||||
it('should succeed', function (done) {
|
||||
Chrome(function(chrome) {
|
||||
chrome.once('Network.requestWillBeSent', function() {
|
||||
chrome.close();
|
||||
done();
|
||||
});
|
||||
chrome.send('Network.enable');
|
||||
chrome.send('Tab.reload');
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('checking the result and without specifyng parameters', function () {
|
||||
it('should succeed', function (done) {
|
||||
Chrome(function(chrome) {
|
||||
chrome.send('Tab.enable', function (error, response) {
|
||||
chrome.close();
|
||||
assert(!error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('checking the result and specifyng parameters', function () {
|
||||
it('should succeed', function (done) {
|
||||
Chrome(function(chrome) {
|
||||
chrome.send('Network.setCacheDisabled', { 'cacheDisabled': true }, function (error, response) {
|
||||
chrome.close();
|
||||
assert(!error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('without checking the result and without specifyng parameters (shorthand)', function () {
|
||||
it('should succeed', function (done) {
|
||||
Chrome(function(chrome) {
|
||||
chrome.once('Network.requestWillBeSent', function() {
|
||||
chrome.close();
|
||||
done();
|
||||
});
|
||||
chrome.Network.enable();
|
||||
chrome.Tab.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('checking the result and without specifyng parameters (shorthand)', function () {
|
||||
it('should succeed', function (done) {
|
||||
Chrome(function(chrome) {
|
||||
chrome.Tab.enable(function (error, response) {
|
||||
chrome.close();
|
||||
assert(!error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('checking the result and specifyng parameters (shorthand)', function () {
|
||||
it('should succeed', function (done) {
|
||||
Chrome(function(chrome) {
|
||||
chrome.Network.setCacheDisabled({ 'cacheDisabled': true }, function (error, response) {
|
||||
chrome.close();
|
||||
assert(!error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
onload && onload();
|
||||
});
|
|
@ -1,109 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2013 Andrea Cardaci <cyrus.and@gmail.com>
|
||||
I.S.T.I. - C.N.R. Pisa
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
define(function(require, exports, module) {
|
||||
exports.commands = {
|
||||
'Console': [
|
||||
'clearMessages',
|
||||
'disable',
|
||||
'enable'
|
||||
],
|
||||
'Debugger': [
|
||||
'canSetScriptSource',
|
||||
'continueToLocation',
|
||||
'disable',
|
||||
'enable',
|
||||
'evaluateOnCallFrame',
|
||||
'getScriptSource',
|
||||
'pause',
|
||||
'removeBreakpoint',
|
||||
'resume',
|
||||
'searchInContent',
|
||||
'setBreakpoint',
|
||||
'setBreakpointByUrl',
|
||||
'setBreakpointsActive',
|
||||
'setPauseOnExceptions',
|
||||
'setScriptSource',
|
||||
'stepInto',
|
||||
'stepOut',
|
||||
'stepOver'
|
||||
],
|
||||
'DOM': [
|
||||
'getAttributes',
|
||||
'getDocument',
|
||||
'getOuterHTML',
|
||||
'hideHighlight',
|
||||
'highlightNode',
|
||||
'highlightRect',
|
||||
'moveTo',
|
||||
'querySelector',
|
||||
'querySelectorAll',
|
||||
'removeAttribute',
|
||||
'removeNode',
|
||||
'requestChildNodes',
|
||||
'requestNode',
|
||||
'resolveNode',
|
||||
'setAttributeValue',
|
||||
'setAttributesAsText',
|
||||
'setNodeName',
|
||||
'setNodeValue',
|
||||
'setOuterHTML'
|
||||
],
|
||||
'DOMDebugger': [
|
||||
'removeDOMBreakpoint',
|
||||
'removeEventListenerBreakpoint',
|
||||
'removeXHRBreakpoint',
|
||||
'setDOMBreakpoint',
|
||||
'setEventListenerBreakpoint',
|
||||
'setXHRBreakpoint'
|
||||
],
|
||||
'Network': [
|
||||
'canClearBrowserCache',
|
||||
'canClearBrowserCookies',
|
||||
'clearBrowserCache',
|
||||
'clearBrowserCookies',
|
||||
'disable',
|
||||
'enable',
|
||||
'getResponseBody',
|
||||
'setCacheDisabled',
|
||||
'setExtraHTTPHeaders',
|
||||
'setUserAgentOverride'
|
||||
],
|
||||
'Tab': [
|
||||
'disable',
|
||||
'enable',
|
||||
'navigate',
|
||||
'reload'
|
||||
],
|
||||
'Runtime': [
|
||||
'callFunctionOn',
|
||||
'evaluate',
|
||||
'getProperties',
|
||||
'releaseObject',
|
||||
'releaseObjectGroup'
|
||||
],
|
||||
'Timeline': [
|
||||
'start',
|
||||
'stop'
|
||||
]
|
||||
};
|
||||
});
|
|
@ -1,130 +0,0 @@
|
|||
/**
|
||||
* V8Debugger
|
||||
*
|
||||
* Copyright (c) 2010 Ajax.org B.V.
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var Breakpoint = module.exports = function(source, line, column, dbg) {
|
||||
this.source = source;
|
||||
this.line = line;
|
||||
this.column = column || 0;
|
||||
|
||||
this.enabled = true;
|
||||
this.condition = "";
|
||||
this.ignoreCount = 0;
|
||||
|
||||
if (dbg) {
|
||||
this.$dbg = dbg;
|
||||
this.state = "connected";
|
||||
this.$listen();
|
||||
}
|
||||
else
|
||||
this.state = "initialized";
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
||||
this.attach = function(dbg, callback) {
|
||||
var self = this;
|
||||
|
||||
if (this.state !== "initialized")
|
||||
throw new Error("Already attached");
|
||||
|
||||
this.$dbg = dbg;
|
||||
this.state = "connecting";
|
||||
|
||||
this.$listen();
|
||||
dbg.setbreakpoint("script", self.source, self.line, self.column, self.enabled, self.condition, self.ignoreCount, function(body) {
|
||||
self.state = "connected";
|
||||
self.$id = body.breakpoint;
|
||||
self.line = body.line;
|
||||
callback(self);
|
||||
});
|
||||
};
|
||||
|
||||
this.$listen = function() {
|
||||
var self = this;
|
||||
this.$onbreak = function(e) {
|
||||
if (self.state !== "connected")
|
||||
return;
|
||||
|
||||
// TODO: how will this ever work??
|
||||
//if (e.data.breakpoints.indexOf(self.$id) !== -1)
|
||||
// self.$dbg.emit("break");
|
||||
};
|
||||
this.$dbg.on("break", this.$onbreak);
|
||||
};
|
||||
|
||||
this.clear = function(callback) {
|
||||
if (this.state !== "connected")
|
||||
throw new Error("Not connected!");
|
||||
|
||||
var self = this;
|
||||
this.$dbg.clearbreakpoint(this.$id, function() {
|
||||
this.$id = null;
|
||||
this.$dbg = null;
|
||||
this.state = "initialized";
|
||||
callback && callback(self);
|
||||
});
|
||||
};
|
||||
|
||||
this.setEnabled = function(enabled) {
|
||||
this.enabled = enabled;
|
||||
};
|
||||
|
||||
this.setCondition = function(condition) {
|
||||
this.condition = condition;
|
||||
};
|
||||
|
||||
this.setIgnoreCount = function(ignoreCount) {
|
||||
this.ignoreCount = ignoreCount;
|
||||
};
|
||||
|
||||
this.flush = function(callback) {
|
||||
if (this.state !== "connected")
|
||||
throw new Error("Not connected");
|
||||
|
||||
this.$dbg.changeBreakpoint(this.$id, this.enabled, this.condition, this.ignoreCount, callback);
|
||||
};
|
||||
|
||||
this.destroy = function() {
|
||||
dbg.removeListener("break", this.$onbreak);
|
||||
};
|
||||
|
||||
}).call(Breakpoint.prototype);
|
||||
|
||||
Breakpoint.fromJson = function(breakpoint, dbg) {
|
||||
if (breakpoint.type != "scriptName")
|
||||
throw new Error("unsupported breakpoint type: " + breakpoint.type);
|
||||
|
||||
var bp = new Breakpoint(breakpoint.script_name, breakpoint.line, breakpoint.column, dbg);
|
||||
bp.condition = breakpoint.condition || "";
|
||||
bp.ignoreCount = breakpoint.ignoreCount || 0;
|
||||
bp.enabled = breakpoint.active;
|
||||
bp.$id = breakpoint.number;
|
||||
return bp;
|
||||
};
|
||||
|
||||
});
|
|
@ -1,99 +0,0 @@
|
|||
/**
|
||||
* V8Debugger
|
||||
*
|
||||
* Copyright (c) 2010 Ajax.org B.V.
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var Util = require("./util");
|
||||
var EventEmitter = Util.EventEmitter;
|
||||
|
||||
var ChromeDebugMessageStream = module.exports = function(socket) {
|
||||
this.$socket = socket;
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
||||
Util.implement(this, EventEmitter);
|
||||
|
||||
this.$received = "";
|
||||
|
||||
this.connect = function() {
|
||||
var socket = this.$socket;
|
||||
var self = this;
|
||||
socket.on("connect", function() {
|
||||
self.$onconnect();
|
||||
});
|
||||
socket.on("data", function(data) {
|
||||
self.$onhandshake(data);
|
||||
});
|
||||
socket.connect();
|
||||
};
|
||||
|
||||
this.sendRequest = function(message) {
|
||||
//console.log("> Sent to Chrome:\n", message.stringify());
|
||||
this.$socket.send(message.stringify());
|
||||
};
|
||||
|
||||
this.$onconnect = function() {
|
||||
this.$socket.send(this.MSG_HANDSHAKE);
|
||||
};
|
||||
|
||||
this.$onhandshake = function(data) {
|
||||
this.$received += data;
|
||||
//this.$socket.clearBuffer();
|
||||
|
||||
if (this.$received.length < this.MSG_HANDSHAKE.length)
|
||||
return;
|
||||
|
||||
if (this.$received.indexOf(this.MSG_HANDSHAKE) !== 0) {
|
||||
this.$socket.removeAllListeners("data");
|
||||
return this.$onerror();
|
||||
}
|
||||
|
||||
this.$received = this.$received.substring(this.MSG_HANDSHAKE.length);
|
||||
this.$socket.removeAllListeners("data");
|
||||
this.$reader = new MessageReader(this.$socket, this.$onMessage.bind(this));
|
||||
|
||||
this.emit("connect");
|
||||
};
|
||||
|
||||
this.$onMessage = function(messageText) {
|
||||
var self = this;
|
||||
setTimeout(function() {
|
||||
//console.log("> Received from Chrome:\n", messageText);
|
||||
var response = new DevToolsMessage.fromString(messageText);
|
||||
self.emit("message", { data: response });
|
||||
}, 0);
|
||||
};
|
||||
|
||||
this.$onerror = function() {
|
||||
this.emit("error");
|
||||
};
|
||||
|
||||
this.MSG_HANDSHAKE = "ChromeDevToolsHandshake\r\n";
|
||||
|
||||
}).call(ChromeDebugMessageStream.prototype);
|
||||
|
||||
});
|
|
@ -1,68 +0,0 @@
|
|||
/**
|
||||
* V8Debugger
|
||||
*
|
||||
* Copyright (c) 2010 Ajax.org B.V.
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var DevToolsMessage = require("./DevToolsMessage");
|
||||
|
||||
var DevToolsService = module.exports = function(msgStream) {
|
||||
this.$msgStream = msgStream;
|
||||
this.$pending = [];
|
||||
|
||||
var self = this;
|
||||
this.$msgStream.on("message", function(e) {
|
||||
var response = e.data;
|
||||
if (response.getHeaders()["Tool"] !== "DevToolsService")
|
||||
return;
|
||||
|
||||
if (self.$pending.length)
|
||||
self.$pending.shift()(JSON.parse(response.getContent()).data);
|
||||
});
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
||||
this.ping = function(callback) {
|
||||
this.$send("ping", callback);
|
||||
};
|
||||
|
||||
this.getVersion = function(callback) {
|
||||
this.$send("version", callback);
|
||||
};
|
||||
|
||||
this.listTabs = function(callback) {
|
||||
this.$send("list_tabs", callback);
|
||||
};
|
||||
|
||||
this.$send = function(command, callback) {
|
||||
var msg = new DevToolsMessage(null, '{"command":"' + command + '"}');
|
||||
this.$msgStream.sendRequest(msg);
|
||||
this.$pending.push(callback);
|
||||
};
|
||||
|
||||
}).call(DevToolsService.prototype);
|
||||
|
||||
});
|
|
@ -1,88 +0,0 @@
|
|||
/**
|
||||
* V8Debugger
|
||||
*
|
||||
* Copyright (c) 2010 Ajax.org B.V.
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
if (typeof process !== "undefined")
|
||||
require("amd-loader");
|
||||
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var assert = require("assert");
|
||||
var MsgStreamMock = require("./MsgStreamMock");
|
||||
var DevToolsService = require("./DevToolsService");
|
||||
|
||||
module.exports = {
|
||||
|
||||
name: "DevToolsService",
|
||||
|
||||
setUp: function() {
|
||||
this.$msgStream = new MsgStreamMock();
|
||||
this.$service = new DevToolsService(this.$msgStream);
|
||||
},
|
||||
|
||||
sendMessage: function(content) {
|
||||
this.$msgStream.$send(null, content);
|
||||
},
|
||||
|
||||
"test: ping": function() {
|
||||
var called = false;
|
||||
this.$service.ping(function() {
|
||||
called = true;
|
||||
});
|
||||
this.sendMessage('{"command":"ping", "result":0, "data":"ok"}');
|
||||
|
||||
assert.ok(called);
|
||||
},
|
||||
|
||||
"test: getVersion": function() {
|
||||
var called = false;
|
||||
this.$service.getVersion(function(version) {
|
||||
called = true;
|
||||
assert.equal("0.1", version);
|
||||
});
|
||||
this.sendMessage('{"command":"version","data":"0.1","result":0}');
|
||||
|
||||
assert.ok(called);
|
||||
},
|
||||
|
||||
"test: listTabs": function() {
|
||||
var called = false;
|
||||
this.$service.listTabs(function(tabs) {
|
||||
called = true;
|
||||
assert.equal(1, tabs.length);
|
||||
assert.equal(2, tabs[0].length);
|
||||
assert.equal(2, tabs[0][0]);
|
||||
assert.equal("file:///index.html", tabs[0][1]);
|
||||
});
|
||||
this.sendMessage('{"command":"list_tabs","data":[[2,"file:///index.html"]],"result":0}');
|
||||
|
||||
assert.ok(called);
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof module !== "undefined" && !module.parent)
|
||||
require("asyncjs").test.testcase(module.exports).exec();
|
||||
|
||||
});
|
|
@ -1,132 +0,0 @@
|
|||
/**
|
||||
* V8Debugger
|
||||
*
|
||||
* Copyright (c) 2010 Ajax.org B.V.
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var net = require("net");
|
||||
var EventEmitter = require("events").EventEmitter;
|
||||
|
||||
var NodeSocket = module.exports = function(ip, port) {
|
||||
EventEmitter.call(this);
|
||||
var _self = this;
|
||||
// connection status flag
|
||||
var connected = false;
|
||||
// the number of left connect retries
|
||||
// TODO: retrieve retry count from configuration
|
||||
var connectRetryCount = 30;
|
||||
// the amount of interval in msec between each retry
|
||||
// TODO: retrieve retry count from configuration
|
||||
var connectRetryInterval = 50; // 50 msec
|
||||
// note: total time for retry: 50msc * 30 = 1.5 sec
|
||||
|
||||
function initStream() {
|
||||
_self.$stream = new net.Stream();
|
||||
_self.$stream.setEncoding("utf8");
|
||||
|
||||
_self.$stream.addListener("data", function(data) {
|
||||
_self.$onData(data);
|
||||
});
|
||||
|
||||
_self.$stream.addListener("end", onEnd);
|
||||
_self.$stream.addListener("error", onError);
|
||||
|
||||
_self.$stream.addListener("connect", function () {
|
||||
// set connection flag to true (connected)
|
||||
connected = true;
|
||||
_self.emit("connect");
|
||||
});
|
||||
}
|
||||
|
||||
// create the initial connection object
|
||||
initStream();
|
||||
|
||||
function onEnd(errorInfo) {
|
||||
// set connection flag to false (not connected)
|
||||
connected = false;
|
||||
_self.$stream.end();
|
||||
_self.state = "initialized";
|
||||
_self.emit("end", errorInfo);
|
||||
}
|
||||
|
||||
function onError() {
|
||||
// if currently not connected and there re-tries left to perform
|
||||
if (!connected && connectRetryCount > 0) {
|
||||
// decrease number of re-tries
|
||||
connectRetryCount--;
|
||||
// since the connection has failed the entire connection object is dead.
|
||||
// close the existing connection object
|
||||
_self.$stream.end();
|
||||
// create a new connection object.
|
||||
initStream();
|
||||
// sleep and afterward try to connect again
|
||||
setTimeout(function() {
|
||||
//console.log("retrying. " + ( connectRetryCount + 1 ) + " attempts left");
|
||||
_self.connect();
|
||||
}, connectRetryInterval);
|
||||
}
|
||||
else {
|
||||
// TODO: replace error message with exception instance.
|
||||
onEnd("Could not connect to the debugger");
|
||||
}
|
||||
}
|
||||
|
||||
this.$ip = ip;
|
||||
this.$port = port;
|
||||
};
|
||||
|
||||
require("./util").inherits(NodeSocket, EventEmitter);
|
||||
|
||||
(function() {
|
||||
|
||||
this.receivedText = "";
|
||||
|
||||
this.close = function() {
|
||||
this.$stream.end();
|
||||
};
|
||||
|
||||
this.clearBuffer = function() { };
|
||||
|
||||
this.send = function(msg) {
|
||||
//console.log("> sent to socket:\n", msg)
|
||||
this.$stream.write(msg, "utf8");
|
||||
};
|
||||
|
||||
this.setMinReceiveSize = function(minSize) { };
|
||||
|
||||
this.$onData = function(data) {
|
||||
this.receivedText = data;
|
||||
//console.log("> received from socket:\n", this.receivedText, this.receivedText.length)
|
||||
this.emit("data", this.receivedText);
|
||||
};
|
||||
|
||||
this.connect = function() {
|
||||
//console.log("Connecting to: " + this.$ip + ":" + this.$port);
|
||||
this.$stream.connect(this.$port, this.$ip);
|
||||
};
|
||||
|
||||
}).call(NodeSocket.prototype);
|
||||
|
||||
});
|
|
@ -1,107 +0,0 @@
|
|||
/**
|
||||
* V8Debugger
|
||||
*
|
||||
* Copyright (c) 2010 Ajax.org B.V.
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var Util = require("./util");
|
||||
var EventEmitter = Util.EventEmitter;
|
||||
var DevToolsMessage = require("./DevToolsMessage");
|
||||
|
||||
var V8DebuggerService = module.exports = function(msgStream) {
|
||||
this.$msgStream = msgStream;
|
||||
this.$pending = {};
|
||||
|
||||
var self = this;
|
||||
this.$msgStream.addEventListener("message", function(e) {
|
||||
var response = e.data;
|
||||
if (response.getHeaders()["Tool"] !== "V8Debugger")
|
||||
return;
|
||||
|
||||
var content = JSON.parse(response.getContent());
|
||||
var command = content.command;
|
||||
|
||||
var queue = self.$pending[command];
|
||||
if (queue && queue.length)
|
||||
queue.shift()(content.data);
|
||||
|
||||
var event = command;
|
||||
var tabId = response.getHeaders()["Destination"];
|
||||
if (tabId)
|
||||
event += "_" + tabId;
|
||||
|
||||
self.emit(event, { data: content.data });
|
||||
});
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
||||
Util.implement(this, EventEmitter);
|
||||
|
||||
this.attach = function(tabId, callback) {
|
||||
this.$send(tabId, "attach", null, callback);
|
||||
};
|
||||
|
||||
this.detach = function(tabId, callback) {
|
||||
this.$send(tabId, "detach", null, callback);
|
||||
};
|
||||
|
||||
this.evaluateJavaScript = function(tabId, jsCode) {
|
||||
this.$send(tabId, "evaluate_javascript", '"' + jsCode + '"', null);
|
||||
};
|
||||
|
||||
this.debuggerCommand = function(tabId, v8Command) {
|
||||
this.$send(tabId, "debugger_command", v8Command);
|
||||
var self = this;
|
||||
setTimeout(function() {
|
||||
self.$send(tabId, "evaluate_javascript", '"javascript:void(0);"', null);
|
||||
}, 100);
|
||||
};
|
||||
|
||||
this.$send = function(destination, command, data, callback) {
|
||||
var headers = {
|
||||
"Tool": "V8Debugger",
|
||||
"Destination": destination
|
||||
};
|
||||
|
||||
var commandJson = ['{"command":"', command, '"'];
|
||||
data && commandJson.push(',"data":', data);
|
||||
commandJson.push("}");
|
||||
|
||||
var msg = new DevToolsMessage(headers, commandJson.join(""));
|
||||
this.$msgStream.sendRequest(msg);
|
||||
|
||||
if (callback) {
|
||||
if (!this.$pending[command])
|
||||
this.$pending[command] = [];
|
||||
|
||||
this.$pending[command].push(callback);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}).call(V8DebuggerService.prototype);
|
||||
|
||||
});
|
|
@ -1,91 +0,0 @@
|
|||
/**
|
||||
* V8Debugger
|
||||
*
|
||||
* Copyright (c) 2010 Ajax.org B.V.
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
if (typeof process !== "undefined")
|
||||
require("amd-loader");
|
||||
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var assert = require("assert");
|
||||
var MsgStreamMock = require("./MsgStreamMock");
|
||||
var V8DebuggerService = require("./V8DebuggerService");
|
||||
|
||||
module.exports = {
|
||||
|
||||
name: "V8DebuggerService",
|
||||
|
||||
setUp: function(next) {
|
||||
this.$msgStream = new MsgStreamMock();
|
||||
this.$service = new V8DebuggerService(this.$msgStream);
|
||||
next();
|
||||
},
|
||||
|
||||
sendMessage: function(destination, content) {
|
||||
var headers = {
|
||||
Tool: "V8Debugger",
|
||||
Destination: destination
|
||||
};
|
||||
this.$msgStream.$send(headers, content);
|
||||
},
|
||||
|
||||
"test: attach": function() {
|
||||
var called = false;
|
||||
this.$service.attach(2, function() {
|
||||
called = true;
|
||||
});
|
||||
this.sendMessage(2, '{"command":"attach","result":0}');
|
||||
|
||||
assert.ok(called);
|
||||
},
|
||||
|
||||
"test: detach": function() {
|
||||
var called = false;
|
||||
this.$service.detach(2, function() {
|
||||
called = true;
|
||||
});
|
||||
this.sendMessage(2, '{"command":"detach", "result":0}');
|
||||
|
||||
assert.ok(called);
|
||||
},
|
||||
|
||||
"test: debugger command": function() {
|
||||
var called = false;
|
||||
var data = '{"seq":1,"type":"request","command":"version"}';
|
||||
this.$service.debuggerCommand(2, data);
|
||||
this.sendMessage(2, '{"command":"debugger_command","result":0,"data":{"seq":1,"request_seq":1,"type":"response","command":"version","success":true,"body":{"V8Version":"2.1.10.5"},"refs":[],"running":true}}');
|
||||
assert.equal('{"command":"debugger_command","data":{"seq":1,"type":"request","command":"version"}}', this.$msgStream.requests[0].getContent());
|
||||
},
|
||||
|
||||
"test: evaluate javascript": function() {
|
||||
this.$service.evaluateJavaScript(2, "javascript:void(0);");
|
||||
assert.equal('{"command":"evaluate_javascript","data":"javascript:void(0);"}', this.$msgStream.requests[0].getContent());
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof module !== "undefined" && !module.parent)
|
||||
require("asyncjs").test.testcase(module.exports).exec();
|
||||
|
||||
});
|
|
@ -1,83 +0,0 @@
|
|||
/**
|
||||
* V8Debugger
|
||||
*
|
||||
* Copyright (c) 2010 Ajax.org B.V.
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var Util = require("./util");
|
||||
var EventEmitter = Util.EventEmitter;
|
||||
|
||||
var WSChromeDebugMessageStream = module.exports = function(socket) {
|
||||
this.$socket = socket;
|
||||
this.$attached = false;
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
||||
Util.implement(this, EventEmitter);
|
||||
|
||||
this.$received = "";
|
||||
|
||||
this.connect = function() {
|
||||
if (this.$attached)
|
||||
return;
|
||||
|
||||
var self = this;
|
||||
|
||||
this.$socket.on("message", function(e) {
|
||||
var message;
|
||||
try {
|
||||
message = JSON.parse(data);
|
||||
}
|
||||
catch (e) {
|
||||
return _self.$onerror();
|
||||
}
|
||||
|
||||
if (message.type == "chrome-debug-ready") {
|
||||
self._dispatchEvent("connect");
|
||||
}
|
||||
else {
|
||||
var response = new DevToolsMessage.fromString(e.body);
|
||||
self._dispatchEvent("message", { data: response });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.sendRequest = function(message) {
|
||||
//console.log("> Sent to Chrome:\n", message.stringify());
|
||||
var command = {
|
||||
command: "debugChrome",
|
||||
message: message.stringify()
|
||||
};
|
||||
this.$socket.send(JSON.stringify(message));
|
||||
};
|
||||
|
||||
this.$onerror = function() {
|
||||
this.$dispatchEvent("error");
|
||||
};
|
||||
|
||||
}).call(WSChromeDebugMessageStream.prototype);
|
||||
|
||||
});
|
|
@ -1,93 +0,0 @@
|
|||
/**
|
||||
* V8Debugger
|
||||
*
|
||||
* Copyright (c) 2010 Ajax.org B.V.
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var Util = require("./util");
|
||||
var EventEmitter = Util.EventEmitter;
|
||||
|
||||
var WSV8DebuggerService = module.exports = function(socket) {
|
||||
this.$socket = socket;
|
||||
this.$state = "initialized";
|
||||
this.$onAttach = [];
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
||||
Util.implement(this, EventEmitter);
|
||||
|
||||
this.attach = function(tabId, callback) {
|
||||
if (this.$state == "connected")
|
||||
return callback(new Error("already attached!"));
|
||||
|
||||
this.$onAttach.push(callback);
|
||||
if (this.$state == "initialized") {
|
||||
this.$socket.send(JSON.stringify({ command: "DebugAttachNode", runner: "node" }));
|
||||
this.$onMessageHandler = this.$onMessage.bind(this);
|
||||
this.$socket.on("message", this.$onMessageHandler);
|
||||
this.$state = "connecting";
|
||||
}
|
||||
};
|
||||
|
||||
this.$onMessage = function(data) {
|
||||
var message;
|
||||
//console.log("INCOMING: ", data);
|
||||
try {
|
||||
message = JSON.parse(data);
|
||||
}
|
||||
catch (ex) {
|
||||
return;
|
||||
}
|
||||
if (message.type == "node-debug-ready") {
|
||||
this.pid = message.pid;
|
||||
this.$state = "connected";
|
||||
for (var i = 0, l = this.$onAttach.length; i < l; i++)
|
||||
this.$onAttach[i]();
|
||||
this.$onAttach = [];
|
||||
}
|
||||
else if (message.type == "node-debug") {
|
||||
this.emit("debugger_command_0", { data: message.body });
|
||||
}
|
||||
};
|
||||
|
||||
this.detach = function(tabId, callback) {
|
||||
this.$state = "initialized";
|
||||
this.$socket.removeListener("message", this.$onMessageHandler);
|
||||
callback();
|
||||
};
|
||||
|
||||
this.debuggerCommand = function(tabId, v8Command) {
|
||||
this.$socket.send(JSON.stringify({
|
||||
command: "debugNode",
|
||||
pid: this.pid,
|
||||
runner: "node",
|
||||
body: JSON.parse(v8Command)
|
||||
}));
|
||||
};
|
||||
|
||||
}).call(WSV8DebuggerService.prototype);
|
||||
|
||||
});
|
|
@ -1,38 +0,0 @@
|
|||
/**
|
||||
* V8Debugger
|
||||
*
|
||||
* Copyright (c) 2010 Ajax.org B.V.
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
require("amd-loader");
|
||||
var fs = require("fs");
|
||||
|
||||
fs.readdirSync(__dirname).forEach(function(filename) {
|
||||
var m = filename.match(/^([A-Z].*)(Test)?\.js$/);
|
||||
|
||||
if (m && !m[2]) {
|
||||
var name = m[1];
|
||||
exports.__defineGetter__(name, function() {
|
||||
return require("./" + name);
|
||||
});
|
||||
}
|
||||
});
|
|
@ -2,7 +2,6 @@ var modules = require("module");
|
|||
var oldResolve = modules._resolveFilename;
|
||||
var extraPaths = [
|
||||
__dirname + "/../plugins/node_modules/ace/lib",
|
||||
__dirname + "/../node_modules/v8debug/lib",
|
||||
__dirname + "/../"
|
||||
];
|
||||
var extraPathOverrides = [
|
||||
|
|
Ładowanie…
Reference in New Issue