Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / inspector / InjectedScriptSource.js
index 3cabdc1..3c29246 100644 (file)
@@ -118,7 +118,7 @@ function bind(func, thisObject, var_args)
      */
     function bound(var_args)
     {
-        return func.apply(thisObject, concat(args, slice(arguments)));
+        return InjectedScriptHost.callFunction(func, thisObject, concat(args, slice(arguments)));
     }
     bound.toString = function()
     {
@@ -151,12 +151,8 @@ function isArrayLike(obj)
             return false;
         if (typeof obj.splice === "function")
             return isFinite(obj.length);
-        var str = Object.prototype.toString.call(obj);
-        if (str === "[object Array]" ||
-            str === "[object Arguments]" ||
-            str === "[object HTMLCollection]" ||
-            str === "[object NodeList]" ||
-            str === "[object DOMTokenList]")
+        var str = InjectedScriptHost.callFunction(Object.prototype.toString, obj);
+        if (str === "[object Arguments]")
             return isFinite(obj.length);
     } catch (e) {
     }
@@ -351,7 +347,7 @@ InjectedScript.prototype = {
      */
     _parseObjectId: function(objectId)
     {
-        return nullifyObjectProto(InjectedScriptHost.evaluate("(" + objectId + ")"));
+        return nullifyObjectProto(InjectedScriptHost.eval("(" + objectId + ")"));
     },
 
     /**
@@ -359,6 +355,8 @@ InjectedScript.prototype = {
      */
     releaseObjectGroup: function(objectGroupName)
     {
+        if (objectGroupName === "console")
+            delete this._lastResult;
         var group = this._objectGroups[objectGroupName];
         if (!group)
             return;
@@ -374,8 +372,8 @@ InjectedScript.prototype = {
      */
     dispatch: function(methodName, args)
     {
-        var argsArray = InjectedScriptHost.evaluate("(" + args + ")");
-        var result = this[methodName].apply(this, argsArray);
+        var argsArray = InjectedScriptHost.eval("(" + args + ")");
+        var result = InjectedScriptHost.callFunction(this[methodName], this, argsArray);
         if (typeof result === "undefined") {
             inspectedWindow.console.error("Web Inspector error: InjectedScript.%s returns undefined", methodName);
             result = null;
@@ -516,7 +514,7 @@ InjectedScript.prototype = {
 
                 try {
                     propertyProcessed[property] = true;
-                    var descriptor = nullifyObjectProto(InjectedScriptHost.suppressWarningsAndCall(Object, Object.getOwnPropertyDescriptor, o, property));
+                    var descriptor = nullifyObjectProto(InjectedScriptHost.suppressWarningsAndCallFunction(Object.getOwnPropertyDescriptor, Object, [o, property]));
                     if (descriptor) {
                         if (accessorPropertiesOnly && !("get" in descriptor || "set" in descriptor))
                             continue;
@@ -578,7 +576,7 @@ InjectedScript.prototype = {
      */
     evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview)
     {
-        return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScriptHost, expression, objectGroup, false, injectCommandLineAPI, returnByValue, generatePreview);
+        return this._evaluateAndWrap(null, null, expression, objectGroup, false, injectCommandLineAPI, returnByValue, generatePreview);
     },
 
     /**
@@ -597,7 +595,7 @@ InjectedScript.prototype = {
 
         if (args) {
             var resolvedArgs = [];
-            args = InjectedScriptHost.evaluate(args);
+            args = InjectedScriptHost.eval(args);
             for (var i = 0; i < args.length; ++i) {
                 try {
                     resolvedArgs[i] = this._resolveCallArgument(args[i]);
@@ -609,15 +607,15 @@ InjectedScript.prototype = {
 
         try {
             var objectGroup = this._idToObjectGroupName[parsedObjectId.id];
-            var func = InjectedScriptHost.evaluate("(" + expression + ")");
+            var func = InjectedScriptHost.eval("(" + expression + ")");
             if (typeof func !== "function")
                 return "Given expression does not evaluate to a function";
 
             return { wasThrown: false,
-                     result: this._wrapObject(func.apply(object, resolvedArgs), objectGroup, returnByValue),
+                     result: this._wrapObject(InjectedScriptHost.callFunction(func, object, resolvedArgs), objectGroup, returnByValue),
                      __proto__: null };
         } catch (e) {
-            return this._createThrownValue(e, objectGroup);
+            return this._createThrownValue(e, objectGroup, false);
         }
     },
 
@@ -651,8 +649,8 @@ InjectedScript.prototype = {
     },
 
     /**
-     * @param {!Function} evalFunction
-     * @param {!Object} object
+     * @param {?function(string):*} evalFunction
+     * @param {?Object} object
      * @param {string} expression
      * @param {string} objectGroup
      * @param {boolean} isEvalOnCallFrame
@@ -664,32 +662,36 @@ InjectedScript.prototype = {
      */
     _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, isEvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview, scopeChain)
     {
-        try {
+        var wrappedResult = this._evaluateOn(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI, scopeChain);
+        if (!wrappedResult.exceptionDetails) {
             return { wasThrown: false,
-                     result: this._wrapObject(this._evaluateOn(evalFunction, object, objectGroup, expression, isEvalOnCallFrame, injectCommandLineAPI, scopeChain), objectGroup, returnByValue, generatePreview),
+                     result: this._wrapObject(wrappedResult.result, objectGroup, returnByValue, generatePreview),
                      __proto__: null };
-        } catch (e) {
-            return this._createThrownValue(e, objectGroup);
         }
+        return this._createThrownValue(wrappedResult.result, objectGroup, generatePreview, wrappedResult.exceptionDetails);
     },
 
     /**
      * @param {*} value
      * @param {string} objectGroup
+     * @param {boolean} generatePreview
+     * @param {!DebuggerAgent.ExceptionDetails=} exceptionDetails
      * @return {!Object}
      */
-    _createThrownValue: function(value, objectGroup)
+    _createThrownValue: function(value, objectGroup, generatePreview, exceptionDetails)
     {
-        var remoteObject = this._wrapObject(value, objectGroup);
-        try {
-            remoteObject.description = toStringDescription(value);
-        } catch (e) {}
-        return { wasThrown: true, result: remoteObject, __proto__: null };
+        var remoteObject = this._wrapObject(value, objectGroup, false, generatePreview && !(value instanceof Error));
+        if (!remoteObject.description){
+            try {
+                remoteObject.description = toStringDescription(value);
+            } catch (e) {}
+        }
+        return { wasThrown: true, result: remoteObject, exceptionDetails: exceptionDetails, __proto__: null };
     },
 
     /**
-     * @param {!Function} evalFunction
-     * @param {!Object} object
+     * @param {?function(string):*} evalFunction
+     * @param {?Object} object
      * @param {string} objectGroup
      * @param {string} expression
      * @param {boolean} isEvalOnCallFrame
@@ -727,10 +729,10 @@ InjectedScript.prototype = {
 
             if (prefix)
                 expression = prefix + "\n" + expression + "\n" + suffix;
-            var result = evalFunction.call(object, expression);
-            if (objectGroup === "console")
-                this._lastResult = result;
-            return result;
+            var wrappedResult = evalFunction ? InjectedScriptHost.callFunction(evalFunction, object, [expression]) : InjectedScriptHost.evaluateWithExceptionDetails(expression);
+            if (objectGroup === "console" && !wrappedResult.exceptionDetails)
+                this._lastResult = wrappedResult.result;
+            return wrappedResult;
         } finally {
             if (injectCommandLineAPI)
                 delete inspectedWindow.__commandLineAPI;
@@ -772,13 +774,13 @@ InjectedScript.prototype = {
      */
     evaluateOnCallFrame: function(topCallFrame, asyncCallStacks, callFrameId, expression, objectGroup, injectCommandLineAPI, returnByValue, generatePreview)
     {
-        var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate("(" + callFrameId + ")"));
+        var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.eval("(" + 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._evaluateAndWrap(callFrame.evaluate, callFrame, expression, objectGroup, true, injectCommandLineAPI, returnByValue, generatePreview);
+            return this._evaluateAndWrap(null, null, expression, objectGroup, false, injectCommandLineAPI, returnByValue, generatePreview, callFrame.scopeChain);
+        return this._evaluateAndWrap(callFrame.evaluateWithExceptionDetails, callFrame, expression, objectGroup, true, injectCommandLineAPI, returnByValue, generatePreview);
     },
 
     /**
@@ -840,7 +842,7 @@ InjectedScript.prototype = {
         }
         var newValueJson;
         try {
-            newValueJson = InjectedScriptHost.evaluate("(" + newValueJsonString + ")");
+            newValueJson = InjectedScriptHost.eval("(" + newValueJsonString + ")");
         } catch (e) {
             return "Failed to parse new value JSON " + newValueJsonString + " : " + e;
         }
@@ -865,7 +867,7 @@ InjectedScript.prototype = {
      */
     _callFrameForId: function(topCallFrame, callFrameId)
     {
-        var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.evaluate("(" + callFrameId + ")"));
+        var parsedCallFrameId = nullifyObjectProto(InjectedScriptHost.eval("(" + callFrameId + ")"));
         return this._callFrameForParsedId(topCallFrame, parsedCallFrameId, []);
     },
 
@@ -935,12 +937,12 @@ InjectedScript.prototype = {
     injectModule: function(name, source)
     {
         delete this._modules[name];
-        var moduleFunction = InjectedScriptHost.evaluate("(" + source + ")");
+        var moduleFunction = InjectedScriptHost.eval("(" + source + ")");
         if (typeof moduleFunction !== "function") {
             inspectedWindow.console.error("Web Inspector error: A function was expected for module %s evaluation", name);
             return null;
         }
-        var module = moduleFunction.call(inspectedWindow, InjectedScriptHost, inspectedWindow, injectedScriptId, this);
+        var module = InjectedScriptHost.callFunction(moduleFunction, inspectedWindow, [InjectedScriptHost, inspectedWindow, injectedScriptId, this]);
         this._modules[name] = module;
         return module;
     },
@@ -976,9 +978,6 @@ InjectedScript.prototype = {
         if (this.isPrimitiveValue(obj))
             return null;
 
-        if (this._isHTMLAllCollection(obj))
-            return "array";
-
         var preciseType = InjectedScriptHost.type(obj);
         if (preciseType)
             return preciseType;
@@ -1035,19 +1034,15 @@ InjectedScript.prototype = {
 
         if (isSymbol(obj)) {
             try {
-                return Symbol.prototype.toString.call(obj) || "Symbol";
+                return InjectedScriptHost.callFunction(Symbol.prototype.toString, obj) || "Symbol";
             } catch (e) {
                 return "Symbol";
             }
         }
 
-        if (className === "Object") {
-            // In Chromium DOM wrapper prototypes will have Object as their constructor name,
-            // get the real DOM wrapper name from the constructor property.
-            var constructorName = obj.constructor && obj.constructor.name;
-            if (constructorName)
-                return constructorName;
-        }
+        if (obj instanceof Error && !!obj.message)
+            return className + ": " + obj.message;
+
         return className;
     }
 }
@@ -1168,7 +1163,7 @@ InjectedScript.RemoteObject.prototype = {
 
     /**
      * @param {!RuntimeAgent.ObjectPreview} preview
-     * @param {!Array.<Object>} descriptors
+     * @param {!Array.<!Object>} descriptors
      * @param {!Object} propertiesThreshold
      * @param {?Array.<string>=} secondLevelKeys
      * @param {boolean=} isTable
@@ -1502,7 +1497,7 @@ CommandLineAPIImpl.prototype = {
      */
     dir: function(var_args)
     {
-        return inspectedWindow.console.dir.apply(inspectedWindow.console, arguments)
+        return InjectedScriptHost.callFunction(inspectedWindow.console.dir, inspectedWindow.console, slice(arguments));
     },
 
     /**
@@ -1510,7 +1505,7 @@ CommandLineAPIImpl.prototype = {
      */
     dirxml: function(var_args)
     {
-        return inspectedWindow.console.dirxml.apply(inspectedWindow.console, arguments)
+        return InjectedScriptHost.callFunction(inspectedWindow.console.dirxml, inspectedWindow.console, slice(arguments));
     },
 
     /**
@@ -1537,7 +1532,7 @@ CommandLineAPIImpl.prototype = {
      */
     profile: function(opt_title)
     {
-        return inspectedWindow.console.profile.apply(inspectedWindow.console, arguments)
+        return InjectedScriptHost.callFunction(inspectedWindow.console.profile, inspectedWindow.console, slice(arguments));
     },
 
     /**
@@ -1545,7 +1540,7 @@ CommandLineAPIImpl.prototype = {
      */
     profileEnd: function(opt_title)
     {
-        return inspectedWindow.console.profileEnd.apply(inspectedWindow.console, arguments)
+        return InjectedScriptHost.callFunction(inspectedWindow.console.profileEnd, inspectedWindow.console, slice(arguments));
     },
 
     /**
@@ -1656,7 +1651,7 @@ CommandLineAPIImpl.prototype = {
 
     table: function(data, opt_columns)
     {
-        inspectedWindow.console.table.apply(inspectedWindow.console, arguments);
+        InjectedScriptHost.callFunction(inspectedWindow.console.table, inspectedWindow.console, slice(arguments));
     },
 
     /**