Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: sky/framework/inspector/runtime-agent.sky

Issue 674823003: Add basic console support to Sky's inspector. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: No need to change abarth.sky now Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/framework/inspector/page-agent.sky ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/inspector/runtime-agent.sky
diff --git a/sky/framework/inspector/runtime-agent.sky b/sky/framework/inspector/runtime-agent.sky
new file mode 100644
index 0000000000000000000000000000000000000000..6f12cefda0a0f40d5803a912e453777b0a8db2c4
--- /dev/null
+++ b/sky/framework/inspector/runtime-agent.sky
@@ -0,0 +1,130 @@
+<script>
+
+function Runtime(delegate) {
+ this.delegate_ = delegate;
+}
+
+function logParams(name, params) {
+ console.log(name + "(" + JSON.stringify(params, null, " ") + ")")
+}
+
+function debug(name) {
+ return function(params) {
+ logParams(name, params);
+ }
+}
abarth-chromium 2014/10/29 00:58:24 Should we factor these into a separate module? Th
+
+Runtime.prototype.enable = function() {
+ this.delegate_.sendMessage("Runtime.executionContextCreated", {
+ "context": {
+ "frameId": 1,
+ "id": 1,
+ }
+ });
+ return {
+ result: true,
+ };
+};
+
+Runtime.prototype.callFunctionOn = function(params) {
+ logParams("callFunctionOn", params);
+ var object = g_objectRegistry.lookup(params.objectId);
+ // This is a horrible hack:
+ var functionName = params.functionDeclaration.match(/^function (\w+)\(/)[1];
+ var expression = params.functionDeclaration + "; return " + functionName + ";";
+ var wasThrown = false;
+ var value;
+ try {
+ var func = new Function('', expression)();
+ value = func(object);
+ } catch (e) {
+ value = e;
+ wasThrown = true;
+ }
+
+ return makeResult(params, value, wasThrown);
+}
+
+Runtime.prototype.releaseObjectGroup = debug("releaseObjectGroup");
+
+// See InjectedScript._bind for a fancier version of this:
+
+function RemoteObjectRegistery() {
+ this.lastObjectId = 0;
+ this.objectsById = [];
abarth-chromium 2014/10/29 00:58:24 this.objectsById = new Map() ? Presumably you'll
+}
+
+RemoteObjectRegistery.prototype.register = function(object) {
+ var objectId = ++this.lastObjectId;
+ this.objectsById[objectId] = object;
+ return String(objectId);
+}
+
+RemoteObjectRegistery.prototype.lookup = function(objectId) {
+ return this.objectsById[Number(objectId)];
+}
+
+var g_objectRegistry = new RemoteObjectRegistery();
+
+
+function makeResult(params, value, wasThrown) {
+ var type = typeof(value)
+ var result = {
+ "result": {
+ "type": type,
+ },
+ "wasThrown": wasThrown,
+ };
+
+ // Unclear why this often fails with:
+ // "TypeError: Cannot convert object to primitive value"
+ try {
+ result['result']['description'] = String(value);
+ } catch (e) {}
+
+ if (type == "object") {
+ result["result"]["objectId"] = g_objectRegistry.register(value);
+ }
+
+ if (params.returnByValue) {
+ result["result"]["value"] = value;
+ }
+
+ if (wasThrown) {
+ // If we don"t have exceptionDetails, inspector hits an exception.
+ result["exceptionDetails"] = {
+ "text": value.message,
+ "url": "",
+ "line": 0,
+ "column": 0,
+ "stackTrace": [{
+ "functionName": "",
+ "scriptId": "1",
+ "url": "",
+ "lineNumber": 0,
+ "columnNumber": 0
+ }]
+ }
+ }
+ return result;
+}
+
+// FIXME: See Blink"s inspected-script-source.js InjectedScript.RemoteObject.
+Runtime.prototype.evaluate = function(params) {
+ logParams("evaluate", params);
+ var wasThrown = false;
+ var value;
+ try {
+ value = eval(params.expression);
pfeldman 2014/10/29 06:12:36 I need to get this running myself to get to know w
+ } catch (e) {
+ value = e;
+ wasThrown = true;
+ }
+
+ return makeResult(params, value, wasThrown);
+}
+
+Runtime.prototype.getProperties = debug("getProperties");
+
+this.exports = Runtime;
+</script>
« no previous file with comments | « sky/framework/inspector/page-agent.sky ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698