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

Unified Diff: Source/core/inspector/InjectedScriptSource.js

Issue 289423002: DevTools: added injectedScript.evaluateWithDetails, that return exception details if it occured (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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 | « Source/bindings/core/v8/custom/V8InjectedScriptHostCustom.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/InjectedScriptSource.js
diff --git a/Source/core/inspector/InjectedScriptSource.js b/Source/core/inspector/InjectedScriptSource.js
index 3cabdc116cb13ebc3333229b66f9ec8ae4151367..d8db8f3f379913cd75cb2bd56c9ce9d9afa3117f 100644
--- a/Source/core/inspector/InjectedScriptSource.js
+++ b/Source/core/inspector/InjectedScriptSource.js
@@ -351,7 +351,7 @@ InjectedScript.prototype = {
*/
_parseObjectId: function(objectId)
{
- return nullifyObjectProto(InjectedScriptHost.evaluate("(" + objectId + ")"));
+ return nullifyObjectProto(this._injectedScriptHostEvaluateThrowable("(" + objectId + ")"));
},
/**
@@ -374,7 +374,7 @@ InjectedScript.prototype = {
*/
dispatch: function(methodName, args)
{
- var argsArray = InjectedScriptHost.evaluate("(" + args + ")");
+ var argsArray = this._injectedScriptHostEvaluateThrowable("(" + args + ")");
var result = this[methodName].apply(this, argsArray);
if (typeof result === "undefined") {
inspectedWindow.console.error("Web Inspector error: InjectedScript.%s returns undefined", methodName);
@@ -578,7 +578,7 @@ InjectedScript.prototype = {
*/
evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview)
{
- return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, generatePreview);
+ return this._evaluateAndWrapWithDetails(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, generatePreview);
},
/**
@@ -597,7 +597,7 @@ InjectedScript.prototype = {
if (args) {
var resolvedArgs = [];
- args = InjectedScriptHost.evaluate(args);
+ args = this._injectedScriptHostEvaluateThrowable(args);
for (var i = 0; i < args.length; ++i) {
try {
resolvedArgs[i] = this._resolveCallArgument(args[i]);
@@ -610,6 +610,9 @@ InjectedScript.prototype = {
try {
var objectGroup = this._idToObjectGroupName[parsedObjectId.id];
var func = InjectedScriptHost.evaluate("(" + expression + ")");
+ if (func.exceptionDetails)
vsevik 2014/07/04 06:54:58 Everything except func.apply could me moved out of
+ return this._createThrownValue(func.result, objectGroup, func.exceptionDetails);
+ func = func.result;
if (typeof func !== "function")
return "Given expression does not evaluate to a function";
@@ -674,17 +677,41 @@ InjectedScript.prototype = {
},
/**
+ * @param {!Function} evalFunction
+ * @param {!Object} object
+ * @param {string} expression
+ * @param {string} objectGroup
+ * @param {boolean} isEvalOnCallFrame
+ * @param {boolean} injectCommandLineAPI
+ * @param {boolean} returnByValue
+ * @param {boolean} generatePreview
+ * @param {!Array.<!Object>=} scopeChain
+ * @return {!Object}
+ */
+ _evaluateAndWrapWithDetails: function(evalFunction, object, expression, objectGroup, isEvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview, scopeChain)
vsevik 2014/07/04 06:54:58 This one could be changed accordingly, making it _
+ {
+ var result = this._evaluateOn(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI, scopeChain), objectGroup, returnByValue, generatePreview;
+ if (!result.exceptionDetails)
+ return { wasThrown: false,
+ result: this._wrapObject(result.result),
+ __proto__: null };
+ else
+ return this._createThrownValue(result.result, objectGroup, result.exceptionDetails);
+ },
+
+ /**
* @param {*} value
* @param {string} objectGroup
+ * @param {!Object=} exceptionDetails
* @return {!Object}
*/
- _createThrownValue: function(value, objectGroup)
+ _createThrownValue: function(value, objectGroup, exceptionDetails)
{
var remoteObject = this._wrapObject(value, objectGroup);
try {
remoteObject.description = toStringDescription(value);
} catch (e) {}
- return { wasThrown: true, result: remoteObject, __proto__: null };
+ return { wasThrown: true, result: remoteObject, __proto__: null, exceptionDetails: exceptionDetails, objectGroup };
},
/**
@@ -772,12 +799,12 @@ InjectedScript.prototype = {
*/
evaluateOnCallFrame: function(topCallFrame, asyncCallStacks, callFrameId, expression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview)
{
- var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate("(" + callFrameId + ")"));
+ var parsedCallFrameId = nullifyObjectProto(this._injectedScriptHostEvaluateThrowable("(" + callFrameId + ")"));
var callFrame = this._callFrameForParsedId(topCallFrame, parsedCallFrameId, asyncCallStacks);
if (!callFrame)
return "Could not find call frame with given id";
if (parsedCallFrameId["asyncOrdinal"])
- return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, generatePreview, callFrame.scopeChain);
+ return this._evaluateAndWrapWithDetails(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, generatePreview, callFrame.scopeChain);
return this._evaluateAndWrap(callFrame.evaluate, callFrame, expression, objectGroup, true, injectCommandLineAPI, returnByValue, generatePreview);
vsevik 2014/07/04 06:54:58 So we are still missing exceptionDetails in case o
},
@@ -814,6 +841,18 @@ InjectedScript.prototype = {
},
/**
+ * @param {string} expression
+ * @return {*} expression result value
+ */
+ _injectedScriptHostEvaluateThrowable: function(expression) {
vsevik 2014/07/04 06:54:59 We could probably name this one _evaluateOrThrow
+ var wrappedResult = InjectedScriptHost.evaluate(expression);
+ return wrappedResult.result;
vsevik 2014/07/04 06:54:58 Return early? :)
+ if (wrappedResult.exceptionDetails)
+ throw wrappedResult.result;
+ return wrappedResult.result;
+ },
+
+ /**
* Either callFrameId or functionObjectId must be specified.
* @param {!Object} topCallFrame
* @param {string|boolean} callFrameId or false
@@ -840,7 +879,7 @@ InjectedScript.prototype = {
}
var newValueJson;
try {
- newValueJson = InjectedScriptHost.evaluate("(" + newValueJsonString + ")");
+ newValueJson = this._injectedScriptHostEvaluateThrowable("(" + newValueJsonString + ")");
} catch (e) {
return "Failed to parse new value JSON " + newValueJsonString + " : " + e;
}
@@ -865,7 +904,7 @@ InjectedScript.prototype = {
*/
_callFrameForId: function(topCallFrame, callFrameId)
{
- var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate("(" + callFrameId + ")"));
+ var parsedCallFrameId = nullifyObjectProto(this._injectedScriptHostEvaluateThrowable("(" + callFrameId + ")"));
return this._callFrameForParsedId(topCallFrame, parsedCallFrameId, []);
},
@@ -935,7 +974,7 @@ InjectedScript.prototype = {
injectModule: function(name, source)
{
delete this._modules[name];
- var moduleFunction = InjectedScriptHost.evaluate("(" + source + ")");
+ var moduleFunction = this._injectedScriptHostEvaluateThrowable("(" + source + ")");
if (typeof moduleFunction !== "function") {
inspectedWindow.console.error("Web Inspector error: A function was expected for module %s evaluation", name);
return null;
« no previous file with comments | « Source/bindings/core/v8/custom/V8InjectedScriptHostCustom.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698