summaryrefslogtreecommitdiff
path: root/Source/WebCore/inspector/CommandLineAPIModuleSource.js
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/inspector/CommandLineAPIModuleSource.js')
-rw-r--r--Source/WebCore/inspector/CommandLineAPIModuleSource.js134
1 files changed, 50 insertions, 84 deletions
diff --git a/Source/WebCore/inspector/CommandLineAPIModuleSource.js b/Source/WebCore/inspector/CommandLineAPIModuleSource.js
index 0e8baccb1..93ac8e970 100644
--- a/Source/WebCore/inspector/CommandLineAPIModuleSource.js
+++ b/Source/WebCore/inspector/CommandLineAPIModuleSource.js
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -26,6 +26,8 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+//# sourceURL=__InjectedScript_CommandLineAPIModuleSource.js
+
/**
* @param {InjectedScriptHost} InjectedScriptHost
* @param {Window} inspectedWindow
@@ -35,40 +37,13 @@
*/
(function (InjectedScriptHost, inspectedWindow, injectedScriptId, injectedScript, CommandLineAPIHost) {
-/**
- * @param {Arguments} array
- * @param {number=} index
- * @return {Array.<*>}
- */
-function slice(array, index)
-{
- var result = [];
- for (var i = index || 0; i < array.length; ++i)
- result.push(array[i]);
- return result;
-}
+// FIXME: <https://webkit.org/b/152294> Web Inspector: Parse InjectedScriptSource as a built-in to get guaranteed non-user-overriden built-ins
-/**
- * Please use this bind, not the one from Function.prototype
- * @param {function(...)} func
- * @param {Object} thisObject
- * @param {...number} var_args
- */
-function bind(func, thisObject, var_args)
+function bind(func, thisObject, ...outerArgs)
{
- var args = slice(arguments, 2);
-
- /**
- * @param {...number} var_args
- */
- function bound(var_args)
- {
- return func.apply(thisObject, args.concat(slice(arguments)));
- }
- bound.toString = function() {
- return "bound: " + func;
+ return function(...innerArgs) {
+ return func.apply(thisObject, outerArgs.concat(innerArgs));
};
- return bound;
}
/**
@@ -78,50 +53,21 @@ function bind(func, thisObject, var_args)
*/
function CommandLineAPI(commandLineAPIImpl, callFrame)
{
- /**
- * @param {string} member
- * @return {boolean}
- */
- function inScopeVariables(member)
- {
- if (!callFrame)
- return false;
-
- var scopeChain = callFrame.scopeChain;
- for (var i = 0; i < scopeChain.length; ++i) {
- if (member in scopeChain[i])
- return true;
- }
- return false;
- }
+ this.$_ = injectedScript._lastResult;
+ this.$exception = injectedScript._exceptionValue;
- /**
- * @param {string} name The name of the method for which a toString method should be generated.
- * @return {function():string}
- */
- function customToStringMethod(name)
- {
- return function () { return "function " + name + "() { [Command Line API] }"; };
- }
+ // $0
+ this.__defineGetter__("$0", bind(commandLineAPIImpl._inspectedObject, commandLineAPIImpl));
- for (var i = 0; i < CommandLineAPI.members_.length; ++i) {
- var member = CommandLineAPI.members_[i];
- if (member in inspectedWindow || inScopeVariables(member))
- continue;
+ // $1-$99
+ for (let i = 1; i <= injectedScript._savedResults.length; ++i)
+ this.__defineGetter__("$" + i, bind(injectedScript._savedResult, injectedScript, i));
+ // Command Line API methods.
+ for (let member of CommandLineAPI.members_) {
this[member] = bind(commandLineAPIImpl[member], commandLineAPIImpl);
- this[member].toString = customToStringMethod(member);
+ this[member].toString = function() { return "function " + member + "() { [Command Line API] }" };
}
-
- for (var i = 0; i < 5; ++i) {
- var member = "$" + i;
- if (member in inspectedWindow || inScopeVariables(member))
- continue;
-
- this.__defineGetter__("$" + i, bind(commandLineAPIImpl._inspectedObject, commandLineAPIImpl, i));
- }
-
- this.$_ = injectedScript._lastResult;
}
/**
@@ -129,7 +75,7 @@ function CommandLineAPI(commandLineAPIImpl, callFrame)
* @const
*/
CommandLineAPI.members_ = [
- "$", "$$", "$x", "dir", "dirxml", "keys", "values", "profile", "profileEnd",
+ "$", "$$", "$x", "dir", "dirxml", "keys", "values", "profile", "profileEnd", "table",
"monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "getEventListeners"
];
@@ -156,7 +102,7 @@ CommandLineAPIImpl.prototype = {
if (selector && selector[0] !== "#") {
result = inspectedWindow.document.getElementById(selector);
if (result) {
- inspectedWindow.console.warn("The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $(\"#%s\")", selector );
+ inspectedWindow.console.warn("The console function $() has changed from $=getElementById(id) to $=querySelector(selector). You might try $(\"#%s\")", selector);
return null;
}
}
@@ -170,8 +116,8 @@ CommandLineAPIImpl.prototype = {
$$: function (selector, start)
{
if (this._canQuerySelectorOnNode(start))
- return start.querySelectorAll(selector);
- return inspectedWindow.document.querySelectorAll(selector);
+ return Array.from(start.querySelectorAll(selector));
+ return Array.from(inspectedWindow.document.querySelectorAll(selector));
},
/**
@@ -180,7 +126,7 @@ CommandLineAPIImpl.prototype = {
*/
_canQuerySelectorOnNode: function(node)
{
- return !!node && InjectedScriptHost.type(node) === "node" && (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE);
+ return !!node && InjectedScriptHost.subtype(node) === "node" && (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE);
},
/**
@@ -240,6 +186,11 @@ CommandLineAPIImpl.prototype = {
return inspectedWindow.console.profileEnd.apply(inspectedWindow.console, arguments)
},
+ table: function()
+ {
+ return inspectedWindow.console.table.apply(inspectedWindow.console, arguments)
+ },
+
/**
* @param {Object} object
* @param {Array.<string>|string=} types
@@ -279,9 +230,27 @@ CommandLineAPIImpl.prototype = {
copy: function(object)
{
- if (injectedScript._subtype(object) === "node")
- object = object.outerHTML;
- CommandLineAPIHost.copyText(object);
+ var string;
+ var subtype = injectedScript._subtype(object);
+ if (subtype === "node")
+ string = object.outerHTML;
+ else if (subtype === "regexp")
+ string = "" + object;
+ else if (injectedScript.isPrimitiveValue(object))
+ string = "" + object;
+ else if (typeof object === "symbol")
+ string = String(object);
+ else if (typeof object === "function")
+ string = "" + object;
+ else {
+ try {
+ string = JSON.stringify(object, null, " ");
+ } catch (e) {
+ string = "" + object;
+ }
+ }
+
+ CommandLineAPIHost.copyText(string);
},
clear: function()
@@ -297,12 +266,9 @@ CommandLineAPIImpl.prototype = {
return CommandLineAPIHost.getEventListeners(node);
},
- /**
- * @param {number} num
- */
- _inspectedObject: function(num)
+ _inspectedObject: function()
{
- return CommandLineAPIHost.inspectedObject(num);
+ return CommandLineAPIHost.inspectedObject();
},
/**