incorporate the debugger
This commit is contained in:
parent
05fd6df8fe
commit
0847bc73c5
29 changed files with 944 additions and 19 deletions
62
experiments/msg_stream.html
Normal file
62
experiments/msg_stream.html
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script type="text/javascript" src="../src/debug/d8.js"></script>
|
||||||
|
<script type="text/javascript" src="../src/debug/o3.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="../src/ace/lib/core.js"></script>
|
||||||
|
<script type="text/javascript" src="../src/ace/lib/oop.js"></script>
|
||||||
|
<script type="text/javascript" src="../src/ace/lib/lang.js"></script>
|
||||||
|
<script type="text/javascript" src="../src/ace/MEventEmitter.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="../src/debug/O3Socket.js"></script>
|
||||||
|
<script type="text/javascript" src="../src/debug/V8DebugMessageStream.js"></script>
|
||||||
|
<script type="text/javascript" src="../src/debug/DevToolsService.js"></script>
|
||||||
|
<script type="text/javascript" src="../src/debug/DevToolsMessage.js"></script>
|
||||||
|
<script type="text/javascript" src="../src/debug/V8DebuggerService.js"></script>
|
||||||
|
<script type="text/javascript" src="../src/debug/V8Debugger.js"></script>
|
||||||
|
<script type="text/javascript" src="../src/debug/V8Message.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<embed type="application/o3stem-aaaaaaaa-1111-bbbb-1111-cccccccccccc" width="0" height="0" />
|
||||||
|
|
||||||
|
<button onClick="testChrome()">start test</button>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
function testChrome() {
|
||||||
|
var o3obj = document.getElementsByTagName("embed")[0];
|
||||||
|
var socket = new O3Socket("127.0.0.1", 9222, o3obj);
|
||||||
|
var msgStream = new V8DebugMessageStream(socket);
|
||||||
|
|
||||||
|
msgStream.addEventListener("connect", function() {
|
||||||
|
|
||||||
|
var dts = new DevToolsService(msgStream);
|
||||||
|
var v8ds = new V8DebuggerService(msgStream);
|
||||||
|
|
||||||
|
dts.getVersion(function(version) {
|
||||||
|
console.log("ChromeDevTools Version:", version);
|
||||||
|
|
||||||
|
dts.listTabs(function(tabs) {
|
||||||
|
console.log(tabs);
|
||||||
|
|
||||||
|
var tabId = tabs[0][0];
|
||||||
|
v8ds.attach(tabId, function() {
|
||||||
|
console.log("attached");
|
||||||
|
|
||||||
|
var v8debugger = new V8Debugger(tabId, v8ds);
|
||||||
|
v8debugger.version(function(version) {
|
||||||
|
console.log("V8 version:", version.V8Version);
|
||||||
|
});
|
||||||
|
|
||||||
|
v8debugger.scripts(4, null, true, function(scripts) {
|
||||||
|
console.log("scripts", scripts);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
msgStream.connect();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</html>
|
||||||
293
experiments/o3.js
Normal file
293
experiments/o3.js
Normal file
|
|
@ -0,0 +1,293 @@
|
||||||
|
/*
|
||||||
|
* See the NOTICE file distributed with this work for additional
|
||||||
|
* information regarding copyright ownership.
|
||||||
|
*
|
||||||
|
* This is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2.1 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this software; if not, write to the Free
|
||||||
|
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// #ifdef __WITH_O3
|
||||||
|
/**
|
||||||
|
* Helper class that aids in creating and controlling Ajax O3 instances
|
||||||
|
*
|
||||||
|
* @author Mike de Boer
|
||||||
|
* @version %I%, %G%
|
||||||
|
* @since 2.1
|
||||||
|
* @namespace o3
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
(function(global) {
|
||||||
|
var sId = "Ajax.org",
|
||||||
|
sDefProduct = "O3Stem",
|
||||||
|
bAvailable = null,
|
||||||
|
iVersion = null,
|
||||||
|
embedded = false,
|
||||||
|
oO3Count = 0;
|
||||||
|
bEmbed = false,
|
||||||
|
sPlatform = null,
|
||||||
|
oInstMap = {};
|
||||||
|
|
||||||
|
function detect(o) {
|
||||||
|
var version;
|
||||||
|
var name = o && o.fullname ? o.fullname : "Ajax.org O3";
|
||||||
|
|
||||||
|
if (window.external && window.external.o3) {
|
||||||
|
version = window.external.o3.versionInfo.match(/v([\d]+\.[\d]+)/)[1];
|
||||||
|
embedded = true;
|
||||||
|
}
|
||||||
|
else if (navigator.plugins && navigator.plugins[name]) {
|
||||||
|
version = navigator.plugins[name].description.match(/v([\d]+\.[\d]+)/)[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
var axo = new ActiveXObject(name);
|
||||||
|
version = axo.versionInfo.match(/v([\d]+\.[\d]+)/)[1];
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version) {
|
||||||
|
iVersion = parseFloat(version);
|
||||||
|
bAvailable = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
iVersion = 0;
|
||||||
|
bAvailable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sniff() {
|
||||||
|
var sAgent = navigator.userAgent.toLowerCase();
|
||||||
|
var is_opera = sAgent.indexOf("opera") !== -1;
|
||||||
|
var is_konqueror = sAgent.indexOf("konqueror") != -1;
|
||||||
|
var is_safari = !is_opera && ((navigator.vendor
|
||||||
|
&& navigator.vendor.match(/Apple/) ? true : false)
|
||||||
|
|| sAgent.indexOf("safari") != -1 || is_konqueror);
|
||||||
|
var is_ie = (document.all && !is_opera && !is_safari);
|
||||||
|
bEmbed = !(is_ie && !is_opera);
|
||||||
|
|
||||||
|
// OS sniffing:
|
||||||
|
|
||||||
|
// windows...
|
||||||
|
if (sAgent.indexOf("win") != -1 || sAgent.indexOf("16bit") != -1) {
|
||||||
|
sPlatform = "win";
|
||||||
|
if (sAgent.indexOf("win16") != -1
|
||||||
|
|| sAgent.indexOf("16bit") != -1
|
||||||
|
|| sAgent.indexOf("windows 3.1") != -1
|
||||||
|
|| sAgent.indexOf("windows 16-bit") != -1)
|
||||||
|
sPlatform += "16";
|
||||||
|
else if (sAgent.indexOf("win32") != -1
|
||||||
|
|| sAgent.indexOf("32bit") != -1)
|
||||||
|
sPlatform += "32";
|
||||||
|
else if (sAgent.indexOf("win32") != -1
|
||||||
|
|| sAgent.indexOf("32bit") != -1)
|
||||||
|
sPlatform += "64";
|
||||||
|
}
|
||||||
|
// mac...
|
||||||
|
if (sAgent.indexOf("mac") != -1) {
|
||||||
|
sPlatform = "mac";
|
||||||
|
if (sAgent.indexOf("ppc") != -1 || sAgent.indexOf("powerpc") != -1)
|
||||||
|
sPlatform += "ppc";
|
||||||
|
else if (sAgent.indexOf("os x") != -1)
|
||||||
|
sPlatform += "osx";
|
||||||
|
}
|
||||||
|
// linux...
|
||||||
|
if (sAgent.indexOf("inux") != -1) {
|
||||||
|
sPlatform = "linux";
|
||||||
|
if (sAgent.indexOf("i686") > -1 || sAgent.indexOf("i386") > -1)
|
||||||
|
sPlatform += "32";
|
||||||
|
else if (sAgent.indexOf("86_64"))
|
||||||
|
sPlatform += "64";
|
||||||
|
else if (sAgent.indexOf("arm"))
|
||||||
|
sPlatform += "arm";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function installerUrl(o) {
|
||||||
|
return "http://www.ajax.org/o3/installer"
|
||||||
|
+ (sPlatform ? "/platform/" + sPlatform : "")
|
||||||
|
+ (o.guid ? "/guid/" + encodeURIComponent(o.guid) : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHtml(s) {
|
||||||
|
var c, ret = "";
|
||||||
|
|
||||||
|
if (s == null) return null;
|
||||||
|
|
||||||
|
for (var i = 0, j = s.length; i < j; i++) {
|
||||||
|
c = s.charCodeAt(i);
|
||||||
|
if (((c > 96) && (c < 123)) || (( c > 64) && (c < 91))
|
||||||
|
|| ((c > 43) && (c < 58) && (c != 47)) || (c == 95))
|
||||||
|
ret = ret + String.fromCharCode(c);
|
||||||
|
else
|
||||||
|
ret = ret + "&#" + c + ";";
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createHtml(options) {
|
||||||
|
var out = [];
|
||||||
|
if (typeof options.width == "undefined")
|
||||||
|
options.width = 0;
|
||||||
|
if (typeof options.height == "undefined")
|
||||||
|
options.height = 0;
|
||||||
|
|
||||||
|
out.push(bEmbed
|
||||||
|
? '<embed id="' + options.id + '" width="' + options.width
|
||||||
|
+ '" height="' + options.height + '" '
|
||||||
|
: '<object id="' + options.id + '" width="' + options.width
|
||||||
|
+ '" height="' + options.height + '"' + (options.guid
|
||||||
|
? ' classid="CLSID:' + options.guid + '"'
|
||||||
|
: '') + '>');
|
||||||
|
if (options.params) {
|
||||||
|
var i, n, v;
|
||||||
|
for (i in options.params) {
|
||||||
|
if (!options.params[i]) continue;
|
||||||
|
n = escapeHtml(i);
|
||||||
|
v = escapeHtml(options.params[i]);
|
||||||
|
out.push(bEmbed
|
||||||
|
? n + '="' + v + '" '
|
||||||
|
: '<param name="' + n + '" value="' + v + '" /> ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.push(bEmbed ? '> </embed>' : '</object>');
|
||||||
|
|
||||||
|
return out.join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
function register(o, options) {
|
||||||
|
// do some funky registering stuff...
|
||||||
|
var key = (options.guid ? options.guid : "ajax.o3")
|
||||||
|
+ (options.name ? "." + options.name : "");
|
||||||
|
|
||||||
|
if (!oInstMap[key])
|
||||||
|
oInstMap[key] = [];
|
||||||
|
oInstMap[key].push(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get(guid) {
|
||||||
|
for (var i in oInstMap) {
|
||||||
|
if (i.indexOf(guid) > -1)
|
||||||
|
return oInstMap[i][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function destroy(o) {
|
||||||
|
if (typeof o == "string") //guid provided
|
||||||
|
o = get(o);
|
||||||
|
if (!o) return;
|
||||||
|
// destroy references and domNode of this/ each plugin instance...
|
||||||
|
var i, j, k, inst;
|
||||||
|
for (i in oInstMap) {
|
||||||
|
inst = oInstMap[i];
|
||||||
|
if (!inst.length) continue;
|
||||||
|
for (j = inst.length -1; j >= 0; j--) {
|
||||||
|
// if we're searching for 'o', check for a match first
|
||||||
|
if (o && inst[j] != o) continue;
|
||||||
|
for (k in o) {
|
||||||
|
if (typeof o[k] == "function")
|
||||||
|
o[k] = null;
|
||||||
|
}
|
||||||
|
inst[j].parentNode.removeChild(inst[j]);
|
||||||
|
inst.splice(j, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!o)
|
||||||
|
oInstMap = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// global API:
|
||||||
|
global.o3 = {
|
||||||
|
isAvailable: function(o) {
|
||||||
|
if (bAvailable === null)
|
||||||
|
detect(o);
|
||||||
|
|
||||||
|
return bAvailable && ((o && o.version) ? iVersion === o.version : true);
|
||||||
|
},
|
||||||
|
|
||||||
|
getVersion: function() {
|
||||||
|
if (iVersion === null)
|
||||||
|
detect();
|
||||||
|
|
||||||
|
return iVersion;
|
||||||
|
},
|
||||||
|
|
||||||
|
create: function(guid, options) {
|
||||||
|
if (!options && typeof guid == "object") {
|
||||||
|
options = guid;
|
||||||
|
options.guid = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
options = options || {};
|
||||||
|
options.guid = guid || false;
|
||||||
|
}
|
||||||
|
if (!options["fullname"]) {
|
||||||
|
options.fullname = (options.product || sDefProduct)
|
||||||
|
+ (options.guid ? "-" + options.guid : "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// mini-browser sniffing:
|
||||||
|
sniff();
|
||||||
|
|
||||||
|
if (!this.isAvailable(options)) {
|
||||||
|
var sUrl = installerUrl(options);
|
||||||
|
return typeof options["oninstallprompt"] == "function"
|
||||||
|
? options.oninstallprompt(sUrl)
|
||||||
|
: window.open(sUrl, "_blank");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof options["params"] == "undefined")
|
||||||
|
options.params = {};
|
||||||
|
if (typeof options.params["type"] == "undefined")
|
||||||
|
options.params.type = "application/" + (options.fullname || "o3-XXXXXXXX");
|
||||||
|
|
||||||
|
options.id = sId + (options.name ? options.name : "");
|
||||||
|
|
||||||
|
var oO3;
|
||||||
|
if (!embedded) {
|
||||||
|
(options["parent"] || document.body).appendChild(
|
||||||
|
document.createElement("div")).innerHTML = createHtml(options);
|
||||||
|
|
||||||
|
oO3 = document.getElementById(options.id);
|
||||||
|
} else {
|
||||||
|
oO3 = window.external.o3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oO3) {
|
||||||
|
register(oO3, options);
|
||||||
|
if (typeof options["onready"] == "function")
|
||||||
|
options.onready(oO3);
|
||||||
|
|
||||||
|
return oO3;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
destroy: destroy,
|
||||||
|
|
||||||
|
get: get
|
||||||
|
};
|
||||||
|
|
||||||
|
})(this);
|
||||||
|
|
||||||
|
// #endif
|
||||||
532
experiments/o3debugger.html
Normal file
532
experiments/o3debugger.html
Normal file
|
|
@ -0,0 +1,532 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script type="text/javascript" src="d8.js"></script>
|
||||||
|
<script type="text/javascript" src="o3.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<embed type="application/o3stem-aaaaaaaa-1111-bbbb-1111-cccccccccccc" width="0" height="0" />
|
||||||
|
|
||||||
|
<button onClick="testChrome()">start test</button>
|
||||||
|
<br></br>
|
||||||
|
<textarea name="log" id="log" cols="100" rows="25">
|
||||||
|
</textarea>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
var o3obj = document.getElementsByTagName("embed")[0];;
|
||||||
|
// creating an o3 instance, we need the UID and the name of the product
|
||||||
|
// the o3.js file will take care of all the details
|
||||||
|
//o3obj = o3.create("AAAAAAAA-1111-BBBB-1111-CCCCCCCCCCCC", {
|
||||||
|
//o3obj = o3.create("aaaaaaaa-1111-bbbb-1111-cccccccccccc", {
|
||||||
|
// oninstallprompt : function(){ alert("can't find o3 plugin");},
|
||||||
|
// product : 'o3stem'
|
||||||
|
//} );
|
||||||
|
|
||||||
|
function getValueFromHeader(name,data,from) {
|
||||||
|
var ret;
|
||||||
|
if (!from)
|
||||||
|
from = 0;
|
||||||
|
|
||||||
|
var s = data.indexOf(name,from);
|
||||||
|
if (s == -1)
|
||||||
|
return ret;
|
||||||
|
var e = data.indexOf("\r\n",s);
|
||||||
|
if (e == -1)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = data.substring(s+name.length+1,e);
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
|
var MSG = {
|
||||||
|
handshake: "ChromeDevToolsHandshake\r\n"
|
||||||
|
};
|
||||||
|
|
||||||
|
var STATE = {
|
||||||
|
seq_id: 0,
|
||||||
|
client: o3obj.socketTCP(),
|
||||||
|
connectionEstabilished: false,
|
||||||
|
received : '',
|
||||||
|
tabID: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
var EVENTS = {
|
||||||
|
DevToolsService : {
|
||||||
|
event : {
|
||||||
|
|
||||||
|
},
|
||||||
|
response : {
|
||||||
|
"list_tabs": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
V8Debugger : {
|
||||||
|
event : {
|
||||||
|
"break": {
|
||||||
|
"fromCode": nativeBreak
|
||||||
|
},
|
||||||
|
"exception": function(r){log("\n> exception event occured\n");},
|
||||||
|
"afterCompile": function(r){log("\n> after compile event occured\n");},
|
||||||
|
"navigated": function(r){log("\n> navigated event occured\n");},
|
||||||
|
"closed": function(r){log("\n> tab closed event occured\n");}
|
||||||
|
},
|
||||||
|
response : {
|
||||||
|
"attach": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
defaults : {
|
||||||
|
v8event : unknownV8Event,
|
||||||
|
v8response : unknownV8Response,
|
||||||
|
devToolResponse : unknownDevToolResponse,
|
||||||
|
connected : connected
|
||||||
|
},
|
||||||
|
pending : {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function reportError(e) {
|
||||||
|
alert(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
function v8eventDispatcher(responseObj) {
|
||||||
|
var eventType = responseObj.data.event,
|
||||||
|
eventID,
|
||||||
|
brNo,
|
||||||
|
cbGroup = EVENTS.V8Debugger.event[eventType];
|
||||||
|
|
||||||
|
if (cbGroup) {
|
||||||
|
if (eventType == "break") {
|
||||||
|
if (responseObj.data.body.breakpoints)
|
||||||
|
brNo = responseObj.data.body.breakpoints[0];
|
||||||
|
if (brNo)
|
||||||
|
cbGroup[brNo](responseObj);
|
||||||
|
else
|
||||||
|
cbGroup["fromCode"](responseObj);
|
||||||
|
}else
|
||||||
|
cbGroup(responseObj);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENTS.defaults.v8event(responseObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
function v8responseDispatcher(responseObj) {
|
||||||
|
var command = (responseObj.data && responseObj.data.command) ?
|
||||||
|
responseObj.data.command : responseObj.command,
|
||||||
|
|
||||||
|
reqSeq = responseObj.data ? responseObj.data.request_seq : -1,
|
||||||
|
cbGroup = EVENTS.V8Debugger.response[command],
|
||||||
|
eventToListen;
|
||||||
|
|
||||||
|
// TODO: check the result report error if something is wrong
|
||||||
|
|
||||||
|
// set up listener for an already specified event
|
||||||
|
if (eventToListen = EVENTS.pending[reqSeq]) {
|
||||||
|
var brNo = responseObj.data.body.breakpoint;
|
||||||
|
EVENTS.V8Debugger.event[eventToListen.event][brNo] =
|
||||||
|
eventToListen.ontrigger;
|
||||||
|
EVENTS.pending.reqSeq = null;
|
||||||
|
delete EVENTS.pending.reqSeq;
|
||||||
|
}
|
||||||
|
|
||||||
|
// lookup reponse callback based on 'request_seq' property
|
||||||
|
if (cbGroup) {
|
||||||
|
// some v8 responses, added for chrome only...
|
||||||
|
if (reqSeq==-1) {
|
||||||
|
cbGroup(responseObj);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cbGroup[reqSeq]) {
|
||||||
|
cbGroup[reqSeq](responseObj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENTS.defaults.v8response(responseObj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
function devtoolResponseDispatcher(responseObj) {
|
||||||
|
var cbGroup = EVENTS.DevToolsService.response[responseObj.command];
|
||||||
|
if (cbGroup) {
|
||||||
|
cbGroup(responseObj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENTS.defaults.devToolResponse(responseObj);
|
||||||
|
}
|
||||||
|
function nativeBreak(responseObj) {
|
||||||
|
log("\n>event: native javascript breakpoint\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function unknownV8Event(e) {
|
||||||
|
log("\n>event: unknownV8Event\n");
|
||||||
|
};
|
||||||
|
function unknownV8Response(e){
|
||||||
|
log("\n>event: unknownV8Response\n");
|
||||||
|
};
|
||||||
|
function unknownDevToolResponse(e){
|
||||||
|
log("\n>event: unknownDevToolResponse\n");
|
||||||
|
};
|
||||||
|
function connected(e){
|
||||||
|
log("\n>event: connected\n");
|
||||||
|
setTimeout("start()",0);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function objectifyResponse(responseText){
|
||||||
|
var responseObj = null;
|
||||||
|
try {
|
||||||
|
//headers = responseText.match(/\[w_-]+\:[^\n\r]+[\n\r]/g);
|
||||||
|
var content,d = responseText.indexOf('\r\n\r\n'),
|
||||||
|
content = responseText.substring(d+4);
|
||||||
|
responseObj = eval('(' + content + ')');
|
||||||
|
}
|
||||||
|
catch(e){
|
||||||
|
debugger;
|
||||||
|
}
|
||||||
|
return responseObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkForWholeMessage() {
|
||||||
|
var i,c,l,responseLength,fullResponse = false;
|
||||||
|
if ((i = STATE.received.indexOf('\r\n\r\n')) != -1) {
|
||||||
|
if ((c = STATE.received.indexOf('Content-Length:')) != -1) {
|
||||||
|
l = STATE.received.substring(c+15);
|
||||||
|
l = l.substring(0, l.indexOf('\r\n'));
|
||||||
|
responseLength = i+4+parseInt(l,10)
|
||||||
|
if (responseLength<=STATE.received.length) {
|
||||||
|
fullResponse = STATE.received.substring(0,responseLength);
|
||||||
|
STATE.received = STATE.received.substring(responseLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fullResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
function dispatchResponse(fullResponse) {
|
||||||
|
var responseObj = objectifyResponse(fullResponse),
|
||||||
|
tool = getValueFromHeader("Tool", fullResponse),
|
||||||
|
dest = getValueFromHeader("Destination", fullResponse);
|
||||||
|
|
||||||
|
if (!responseObj) {
|
||||||
|
alert("broken message!!!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tool == "V8Debugger"){
|
||||||
|
if (responseObj.data && responseObj.data.type) {
|
||||||
|
if (responseObj.data.type == "event") {
|
||||||
|
v8eventDispatcher(responseObj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (responseObj.data.type == "response") {
|
||||||
|
v8responseDispatcher(responseObj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reportError("unknown V8 message type: "
|
||||||
|
+ responseObj.data.type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// v8debugger tool messages were extended with some
|
||||||
|
// special messages only for chrome
|
||||||
|
v8responseDispatcher(responseObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tool == "DevToolsService") {
|
||||||
|
devtoolResponseDispatcher(responseObj);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reportError("tool not supported: " + tool);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// receives the next chunk on the socket, and handles the message if there were any
|
||||||
|
function globalReceiveFunction() {
|
||||||
|
var lastChunk = STATE.client.receivedText;
|
||||||
|
STATE.client.clearBuf();
|
||||||
|
STATE.received += lastChunk;
|
||||||
|
log("\n>receiving: \n" + lastChunk + "\n");
|
||||||
|
|
||||||
|
if (!STATE.connectionEstabilished &&
|
||||||
|
STATE.received == MSG.handshake)
|
||||||
|
{
|
||||||
|
EVENTS.defaults.connected();
|
||||||
|
STATE.received = '';
|
||||||
|
STATE.connectionEstabilished = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there are whole messages on the pipe let's dispatch them
|
||||||
|
while (fullResponse = checkForWholeMessage())
|
||||||
|
dispatchResponse(fullResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
var RequestHandler = {
|
||||||
|
sendMessage: function(requestObj) {
|
||||||
|
log("\n>send message:\n" + requestObj.msg + '\n');
|
||||||
|
var command = requestObj.v8command ? requestObj.v8command :
|
||||||
|
requestObj.command;
|
||||||
|
|
||||||
|
EVENTS[requestObj.tool]["response"][command] ?
|
||||||
|
EVENTS[requestObj.tool]["response"][command]
|
||||||
|
: (EVENTS[requestObj.tool]["response"][command] = {});
|
||||||
|
|
||||||
|
// set callback for the receive response event
|
||||||
|
if (requestObj.seq){
|
||||||
|
if (!EVENTS[requestObj.tool]["response"][command]);
|
||||||
|
EVENTS[requestObj.tool]["response"][command] = {};
|
||||||
|
EVENTS[requestObj.tool]["response"][command][requestObj.seq] = requestObj.ondone;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
EVENTS[requestObj.tool]["response"][command] = requestObj.ondone;
|
||||||
|
|
||||||
|
// after the response we might want to listen for an event
|
||||||
|
// (like for example setbreakpoint request)
|
||||||
|
if (requestObj.event)
|
||||||
|
EVENTS.pending[requestObj.seq] = {
|
||||||
|
ontrigger: requestObj.ontrigger,
|
||||||
|
event: requestObj.event
|
||||||
|
};
|
||||||
|
|
||||||
|
STATE.client.send(requestObj.msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function protocolStringifier() {
|
||||||
|
var s='';
|
||||||
|
for(var i=0; i<this.headers.length; i++) {
|
||||||
|
s += this.headers[i] + "\r\n";
|
||||||
|
}
|
||||||
|
s += "\r\n";
|
||||||
|
s += this.content;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectAndHandshake()
|
||||||
|
{
|
||||||
|
STATE.client.onconnect = function()
|
||||||
|
{
|
||||||
|
log("\n>connect cb\n");
|
||||||
|
STATE.client.receive();
|
||||||
|
STATE.client.send(MSG.handshake);
|
||||||
|
STATE.client.onconnect = 0;
|
||||||
|
}
|
||||||
|
STATE.client.onreceive = globalReceiveFunction;
|
||||||
|
STATE.client.connect('127.0.0.1', 9222);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function listTabs(ondone)
|
||||||
|
{
|
||||||
|
var LIST_TABS = '{"command":"list_tabs"}',
|
||||||
|
contentLength = LIST_TABS.length,
|
||||||
|
protocolObj = {
|
||||||
|
headers: [],
|
||||||
|
content: LIST_TABS,
|
||||||
|
toString: protocolStringifier
|
||||||
|
};
|
||||||
|
|
||||||
|
protocolObj.headers.push(
|
||||||
|
'Content-Length:' + contentLength,
|
||||||
|
'Tool:DevToolsService'
|
||||||
|
);
|
||||||
|
|
||||||
|
var requestObj = {
|
||||||
|
msg: protocolObj.toString(),
|
||||||
|
command: "list_tabs",
|
||||||
|
tool: "DevToolsService",
|
||||||
|
ondone: ondone
|
||||||
|
};
|
||||||
|
|
||||||
|
RequestHandler.sendMessage(requestObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
function attach(tabID, ondone)
|
||||||
|
{
|
||||||
|
var ATTACH_TABS = '{"command":"attach"}',
|
||||||
|
contentLength = ATTACH_TABS.length,
|
||||||
|
protocolObj = {
|
||||||
|
headers: [],
|
||||||
|
content: ATTACH_TABS,
|
||||||
|
toString: protocolStringifier
|
||||||
|
};
|
||||||
|
|
||||||
|
protocolObj.headers.push(
|
||||||
|
'Content-Length:' + contentLength,
|
||||||
|
'Tool:V8Debugger',
|
||||||
|
'Destination:' + tabID
|
||||||
|
);
|
||||||
|
|
||||||
|
var requestObj = {
|
||||||
|
msg: protocolObj.toString(),
|
||||||
|
command: "attach",
|
||||||
|
tool: "V8Debugger",
|
||||||
|
ondone: ondone
|
||||||
|
};
|
||||||
|
|
||||||
|
RequestHandler.sendMessage(requestObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
function debuggerCmd(cmd, ondone, v8command, seq, event)
|
||||||
|
{
|
||||||
|
var debCmd = '{"command":"debugger_command","data":'
|
||||||
|
+ cmd +'}',
|
||||||
|
contentLength = debCmd.length,
|
||||||
|
protocolObj = {
|
||||||
|
headers: [],
|
||||||
|
content: debCmd,
|
||||||
|
toString: protocolStringifier
|
||||||
|
};
|
||||||
|
|
||||||
|
protocolObj.headers.push(
|
||||||
|
'Content-Length:' + contentLength,
|
||||||
|
'Tool:V8Debugger',
|
||||||
|
'Destination:' + STATE.tabID
|
||||||
|
);
|
||||||
|
|
||||||
|
var requestObj = {
|
||||||
|
msg: protocolObj.toString(),
|
||||||
|
command: "debugger_command",
|
||||||
|
v8command: v8command,
|
||||||
|
tool: "V8Debugger",
|
||||||
|
ondone: ondone
|
||||||
|
};
|
||||||
|
|
||||||
|
if (seq)
|
||||||
|
requestObj.seq = seq;
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
requestObj.event = event.type;
|
||||||
|
requestObj.ontrigger = event.ontrigger;
|
||||||
|
}
|
||||||
|
|
||||||
|
RequestHandler.sendMessage(requestObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
function breakpoint(target, line, ondone, ontrigger)
|
||||||
|
{
|
||||||
|
var v8req = {
|
||||||
|
seq:++STATE.seq_id,
|
||||||
|
type:"request",
|
||||||
|
command: "setbreakpoint",
|
||||||
|
arguments: {
|
||||||
|
enabled: true,
|
||||||
|
target: target,
|
||||||
|
line: line,
|
||||||
|
type: "script"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var req = SimpleObjectToJSON_(v8req);
|
||||||
|
var event = {type: "break", ontrigger: ontrigger};
|
||||||
|
debuggerCmd(req, ondone, v8req.command, v8req.seq, event);
|
||||||
|
evalDummy();
|
||||||
|
}
|
||||||
|
|
||||||
|
function source(ondone)
|
||||||
|
{
|
||||||
|
var v8req = {
|
||||||
|
seq:++STATE.seq_id,
|
||||||
|
type:"request",
|
||||||
|
command: "source",
|
||||||
|
arguments: {}
|
||||||
|
};
|
||||||
|
var req = SimpleObjectToJSON_(v8req);
|
||||||
|
debuggerCmd(req, ondone);
|
||||||
|
}
|
||||||
|
|
||||||
|
function scripts(ondone)
|
||||||
|
{
|
||||||
|
var v8req = {
|
||||||
|
seq:++STATE.seq_id,
|
||||||
|
type:"request",
|
||||||
|
command: "scripts"
|
||||||
|
};
|
||||||
|
var req = SimpleObjectToJSON_(v8req);
|
||||||
|
debuggerCmd(req, ondone, v8req.command, v8req.seq);
|
||||||
|
evalDummy();
|
||||||
|
}
|
||||||
|
|
||||||
|
function evalDummy()
|
||||||
|
{
|
||||||
|
var debCmd = '{"command":"evaluate_javascript","data":"javascript:void(0);"}',
|
||||||
|
contentLength = debCmd.length,
|
||||||
|
protocolObj = {
|
||||||
|
headers: [],
|
||||||
|
content: debCmd,
|
||||||
|
toString: protocolStringifier
|
||||||
|
};
|
||||||
|
|
||||||
|
protocolObj.headers.push(
|
||||||
|
'Content-Length:' + contentLength,
|
||||||
|
'Tool:V8Debugger',
|
||||||
|
'Destination:' + STATE.tabID
|
||||||
|
);
|
||||||
|
|
||||||
|
var requestObj = {
|
||||||
|
msg: protocolObj.toString(),
|
||||||
|
command: "debugger_command",
|
||||||
|
tool: "V8Debugger",
|
||||||
|
ondone: function(){}
|
||||||
|
};
|
||||||
|
|
||||||
|
RequestHandler.sendMessage(requestObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
function log(text) {
|
||||||
|
var prev;
|
||||||
|
if (document.all) {
|
||||||
|
document.getElementById('log').innerText += text;
|
||||||
|
} else {
|
||||||
|
document.getElementById('log').textContent += text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testChrome() {
|
||||||
|
connectAndHandshake();
|
||||||
|
}
|
||||||
|
|
||||||
|
function start() {
|
||||||
|
listTabs(onReceiveTabs);
|
||||||
|
}
|
||||||
|
|
||||||
|
var tabid_;
|
||||||
|
function onReceiveTabs(responseObj) {
|
||||||
|
log("\nreceived tabs...\n");
|
||||||
|
tabid_ = responseObj.data[0][0];
|
||||||
|
attach(responseObj.data[0][0], onAttached);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onAttached(responseObj) {
|
||||||
|
log("\onAttach: " + responseObj.result + "\n");
|
||||||
|
STATE.tabID = tabid_;
|
||||||
|
scripts(onReceiveActiveScripts);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onReceiveActiveScripts(responseObj) {
|
||||||
|
var scripts = responseObj.data.body;
|
||||||
|
log("\n> received scripts:\n")
|
||||||
|
var debugjs;
|
||||||
|
for (var i=0; i<scripts.length; i++) {
|
||||||
|
if (!scripts[i].name)
|
||||||
|
continue;
|
||||||
|
log(scripts[i].name + "\n");
|
||||||
|
if (!debugjs && scripts[i].name.indexOf("debug.js")!=-1)
|
||||||
|
debugjs = scripts[i].name;
|
||||||
|
}
|
||||||
|
breakpoint(debugjs, 2, onsetBreakPoint, onBreak);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onsetBreakPoint(responseObj) {
|
||||||
|
log("\n> breakpoint set id: " + responseObj.data.body.breakpoint + "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
function onBreak(responseObj) {
|
||||||
|
log("\n> breakpoint hit.");
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</html>
|
||||||
43
experiments/socket.html
Normal file
43
experiments/socket.html
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script type="text/javascript" src="src/d8.js"></script>
|
||||||
|
<script type="text/javascript" src="src/o3.js"></script>
|
||||||
|
<script type="text/javascript" src="src/O3Socket.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<embed type="application/o3stem-aaaaaaaa-1111-bbbb-1111-cccccccccccc" width="0" height="0" />
|
||||||
|
|
||||||
|
<button onClick="testChrome()">start test</button>
|
||||||
|
<br>
|
||||||
|
<textarea name="log" id="log" cols="100" rows="25">
|
||||||
|
</textarea>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var o3obj = document.getElementsByTagName("embed")[0];
|
||||||
|
var socket = new O3Socket("127.0.0.1", 9222, o3obj);
|
||||||
|
|
||||||
|
socket.onconnect = function() {
|
||||||
|
log("connect");
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.onreceive = function() {
|
||||||
|
log("receive");
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.connect();
|
||||||
|
|
||||||
|
function log(text) {
|
||||||
|
var prev;
|
||||||
|
if (document.all) {
|
||||||
|
document.getElementById('log').innerText += text;
|
||||||
|
} else {
|
||||||
|
document.getElementById('log').textContent += text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</html>
|
||||||
|
|
@ -11,5 +11,8 @@ load:
|
||||||
- src/ace/layer/*.js
|
- src/ace/layer/*.js
|
||||||
- src/ace/*.js
|
- src/ace/*.js
|
||||||
|
|
||||||
- src/test/*.js
|
- src/debug/*.js
|
||||||
- src/test/mode/*.js
|
|
||||||
|
- src/test/ace/*.js
|
||||||
|
- src/test/ace/mode/*.js
|
||||||
|
- src/test/debug/*.js
|
||||||
|
|
@ -33,8 +33,6 @@ ace.BackgroundTokenizer = function(tokenizer) {
|
||||||
|
|
||||||
self.fireUpdateEvent(startLine, textLines.length - 1);
|
self.fireUpdateEvent(startLine, textLines.length - 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$initEvents();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
(function(){
|
(function(){
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
ace.provide("ace.Document");
|
ace.provide("ace.Document");
|
||||||
|
|
||||||
ace.Document = function(text, mode) {
|
ace.Document = function(text, mode) {
|
||||||
this.$initEvents();
|
|
||||||
|
|
||||||
this.lines = [];
|
this.lines = [];
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
this.selection = new ace.Selection(this);
|
this.selection = new ace.Selection(this);
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,9 @@ ace.provide("ace.MEventEmitter");
|
||||||
|
|
||||||
ace.MEventEmitter = function() {
|
ace.MEventEmitter = function() {
|
||||||
|
|
||||||
this.$initEvents = function() {
|
|
||||||
this.$eventRegistry = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
this.$dispatchEvent = function(eventName, e) {
|
this.$dispatchEvent = function(eventName, e) {
|
||||||
|
this.$eventRegistry = this.$eventRegistry || {};
|
||||||
|
|
||||||
var listeners = this.$eventRegistry[eventName];
|
var listeners = this.$eventRegistry[eventName];
|
||||||
if (!listeners || !listeners.length) return;
|
if (!listeners || !listeners.length) return;
|
||||||
|
|
||||||
|
|
@ -19,6 +17,8 @@ ace.MEventEmitter = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.addEventListener = function(eventName, callback) {
|
this.addEventListener = function(eventName, callback) {
|
||||||
|
this.$eventRegistry = this.$eventRegistry || {};
|
||||||
|
|
||||||
var listeners = this.$eventRegistry[eventName];
|
var listeners = this.$eventRegistry[eventName];
|
||||||
if (!listeners) {
|
if (!listeners) {
|
||||||
var listeners = this.$eventRegistry[eventName] = [];
|
var listeners = this.$eventRegistry[eventName] = [];
|
||||||
|
|
@ -29,6 +29,8 @@ ace.MEventEmitter = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.removeEventListener = function(eventName, callback) {
|
this.removeEventListener = function(eventName, callback) {
|
||||||
|
this.$eventRegistry = this.$eventRegistry || {};
|
||||||
|
|
||||||
var listeners = this.$eventRegistry[eventName];
|
var listeners = this.$eventRegistry[eventName];
|
||||||
if (!listeners) {
|
if (!listeners) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
ace.provide("ace.ScrollBar");
|
ace.provide("ace.ScrollBar");
|
||||||
|
|
||||||
ace.ScrollBar = function(parent) {
|
ace.ScrollBar = function(parent) {
|
||||||
this.$initEvents();
|
|
||||||
|
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "sb";
|
this.element.className = "sb";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ ace.provide("ace.Selection");
|
||||||
ace.Selection = function(doc) {
|
ace.Selection = function(doc) {
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
|
|
||||||
this.$initEvents();
|
|
||||||
|
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.selectionLead = {
|
this.selectionLead = {
|
||||||
row: 0,
|
row: 0,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
var EventEmitter = function() {
|
var EventEmitter = function() {};
|
||||||
this.$initEvents();
|
|
||||||
};
|
|
||||||
ace.implement(EventEmitter.prototype, ace.MEventEmitter);
|
ace.implement(EventEmitter.prototype, ace.MEventEmitter);
|
||||||
|
|
||||||
var EventEmitterTest = new TestCase("EventEmitterTest", {
|
var EventEmitterTest = new TestCase("EventEmitterTest", {
|
||||||
|
|
@ -16,5 +15,4 @@ var EventEmitterTest = new TestCase("EventEmitterTest", {
|
||||||
emitter.$dispatchEvent("juhu");
|
emitter.$dispatchEvent("juhu");
|
||||||
assertTrue(called);
|
assertTrue(called);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue