Permalink
Browse files

Adds support to return RemoteObjects by value, meaning that they will…

… not be serialized to JSON. Console completion is one use case.
  • Loading branch information...
1 parent e7c2337 commit 654535bdab16f9131a0a3b29717ef2402a3d33fe @c4milo committed May 3, 2012
Showing with 22 additions and 20 deletions.
  1. +22 −20 lib/runtime.js
View
@@ -3,11 +3,11 @@ var helpers = require('./helpers');
//so that console.log operations in the browser can show up on it too.
//Code was based on /WebKit/Source/WebCore/inspector/InjectedScriptSource.js
var _objectId = 0;
-var RemoteObject = function(object) {
+var RemoteObject = function(object, forceValueType) {
this.type = typeof object;
if (helpers.isPrimitiveValue(object) ||
- object === null) {
+ object === null || forceValueType) {
// We don't send undefined values over JSON.
if (typeof object !== "undefined") {
this.value = object;
@@ -103,20 +103,21 @@ function RuntimeAgent() {
try {
result = eval.call(global, "with ({}) {\n" + params.expression + "\n}");
} catch (e) {
- return sendResult(this.createThrownValue(e));
+ return sendResult(this.createThrownValue(e, param.objectGroup));
}
sendResult({
result: this.wrapObject(result, params.objectGroup),
- wasThrown: err ? true : false
+ wasThrown: false
});
};
this.getProperties = function(params, sendResult) {
var object = this.objects[params.objectId];
if (helpers.isUndefined(object)) {
- return sendResult(new Error('Unknown object'));
+ console.error('RuntimeAgent.getProperties: Unknown object');
+ return;
}
object = object.value;
@@ -165,17 +166,17 @@ function RuntimeAgent() {
});
};
- this.wrapObject = function(object, objectGroup) {
+ this.wrapObject = function(object, objectGroup, forceValueType) {
var remoteObject;
try {
- remoteObject = new RemoteObject(object);
+ remoteObject = new RemoteObject(object, forceValueType);
} catch (e) {
var description = "<failed to convert exception to string>";
try {
description = helpers.describe(e);
} catch (ex) {}
- remoteObject = new RemoteObject(description);
+ remoteObject = new RemoteObject(description, forceValueType);
}
this.objects[remoteObject.objectId] = {
@@ -185,8 +186,8 @@ function RuntimeAgent() {
return remoteObject;
};
- this.createThrownValue = function(value) {
- var remoteObject = this.wrapObject(value);
+ this.createThrownValue = function(value, objectGroup) {
+ var remoteObject = this.wrapObject(value, objectGroup);
try {
remoteObject.description = '' + value;
} catch (e) {}
@@ -201,7 +202,8 @@ function RuntimeAgent() {
var object = this.objects[params.objectId];
if (helpers.isUndefined(object)) {
- return sendResult(new Error('Unknown object'));
+ console.error('RuntimeAgent.callFunctionOn: Unknown object');
+ return;
}
object = object.value;
@@ -215,7 +217,8 @@ function RuntimeAgent() {
if (objectId) {
var resolvedArg = this.objects[objectId];
if (!resolvedArg) {
- return sendResult(new Error('Unknown object'));
+ console.error('RuntimeAgent.callFunctionOn: Unknown object');
+ return;
}
resolvedArgs.push(resolvedArg.value);
@@ -228,21 +231,20 @@ function RuntimeAgent() {
}
try {
- var func = eval("(" + params.functionDeclaration + ")");
+ var func = eval.call(global, ("(" + params.functionDeclaration + ")"));
if (typeof func !== "function") {
- return sendResult(new Error("Expression does not evaluate to a function"));
+ console.error('RuntimeAgent.callFunctionOn: Expression does ' +
+ 'not evaluate to a function');
+ return;
}
+ var objectGroup = this.objects[params.objectId].objectGroup;
return sendResult({
- result: {
- type: 'object',
- value: func.apply(object, resolvedArgs)
- },
- //result: this.wrapObject(func.apply(object, resolvedArgs)),
+ result: this.wrapObject(func.apply(object, resolvedArgs), objectGroup, params.returnByValue),
wasThrown: false
});
} catch (e) {
- return sendResult(this.createThrownValue(e));
+ return sendResult(this.createThrownValue(e, objectGroup));
}
};

0 comments on commit 654535b

Please sign in to comment.