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

Unified Diff: third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js

Issue 1917733002: [DevTools] Move part of CommandLineAPI to native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
Index: third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js
diff --git a/third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js b/third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js
index 3673b57bbdabec1e0d932aed839e62ad907dfd11..85dc1fdca9a42b5d822f674989c9b7f53ef0ed5f 100644
--- a/third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js
+++ b/third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js
@@ -607,11 +607,42 @@ InjectedScript.prototype = {
},
/**
- * @return {!CommandLineAPI}
+ * @param {!Object} nativeCommandLineAPI
+ * @return {!Object}
*/
- commandLineAPI: function()
+ installCommandLineAPI: function(nativeCommandLineAPI)
{
- return new CommandLineAPI(this._commandLineAPIImpl);
+ var commandLineAPIImpl = this._commandLineAPIImpl;
+ for (var member of CommandLineAPIImpl.members_)
+ nativeCommandLineAPI[member] = bind(commandLineAPIImpl[member], commandLineAPIImpl);
+
+ for (var i = 0; i < 5; ++i) {
+ var member = "$" + i;
+ nativeCommandLineAPI[member] = bind(commandLineAPIImpl._inspectedObject, commandLineAPIImpl, i);
+ }
+
+ nativeCommandLineAPI["$"].toString = function() { return "function $(selector, [startNode]) { [Command Line API] }"};
dgozman 2016/04/25 20:55:08 Let's make it an explicit map.
kozy 2016/04/25 21:33:58 Done.
+ nativeCommandLineAPI["$$"].toString = function() { return "function $$(selector, [startNode]) { [Command Line API] }"};
+ nativeCommandLineAPI["$x"].toString = function() { return "function $x(xpath, [startNode]) { [Command Line API] }"};
+ nativeCommandLineAPI["dir"].toString = function() { return "function dir(value) { [Command Line API] }"};
+ nativeCommandLineAPI["dirxml"].toString = function() { return "function dirxml(value) { [Command Line API] }"};
+ nativeCommandLineAPI["keys"].toString = function() { return "function keys(object) { [Command Line API] }"};
+ nativeCommandLineAPI["values"].toString = function() { return "function values(object) { [Command Line API] }"};
+ nativeCommandLineAPI["profile"].toString = function() { return "function profile(value) { [Command Line API] }"};
+ nativeCommandLineAPI["profileEnd"].toString = function() { return "function profileEnd(value) { [Command Line API] }"};
+ nativeCommandLineAPI["monitorEvents"].toString = function() { return "function monitorEvents(object, [types]) { [Command Line API] }"};
+ nativeCommandLineAPI["unmonitorEvents"].toString = function() { return "function unmonitorEvents(object, [types]) { [Command Line API] }"};
+ nativeCommandLineAPI["inspect"].toString = function() { return "function inspect(object) { [Command Line API] }"};
+ nativeCommandLineAPI["copy"].toString = function() { return "function copy(value) { [Command Line API] }"};
+ nativeCommandLineAPI["clear"].toString = function() { return "function clear() { [Command Line API] }"};
+ nativeCommandLineAPI["getEventListeners"].toString = function() { return "function getEventListeners(node) { [Command Line API] }"};
+ nativeCommandLineAPI["debug"].toString = function() { return "function debug(function) { [Command Line API] }"};
+ nativeCommandLineAPI["undebug"].toString = function() { return "function undebug(function) { [Command Line API] }"};
+ nativeCommandLineAPI["monitor"].toString = function() { return "function monitor(function) { [Command Line API] }"};
+ nativeCommandLineAPI["unmonitor"].toString = function() { return "function unmonitor(function) { [Command Line API] }"};
+ nativeCommandLineAPI["table"].toString = function() { return "function table(value) { [Command Line API] }"};
+
+ return nativeCommandLineAPI;
},
/**
@@ -1136,65 +1167,21 @@ InjectedScript.RemoteObject.prototype = {
/**
* @constructor
- * @param {!CommandLineAPIImpl} commandLineAPIImpl
*/
-function CommandLineAPI(commandLineAPIImpl)
+function CommandLineAPIImpl()
{
- /**
- * @param {string} name The name of the method for which a toString method should be generated.
- * @return {function():string}
- */
- function customToStringMethod(name)
- {
- return function()
- {
- var funcArgsSyntax = "";
- try {
- var funcSyntax = "" + commandLineAPIImpl[name];
- funcSyntax = funcSyntax.replace(/\n/g, " ");
- funcSyntax = funcSyntax.replace(/^function[^\(]*\(([^\)]*)\).*$/, "$1");
- funcSyntax = funcSyntax.replace(/\s*,\s*/g, ", ");
- funcSyntax = funcSyntax.replace(/\bopt_(\w+)\b/g, "[$1]");
- funcArgsSyntax = funcSyntax.trim();
- } catch (e) {
- }
- return "function " + name + "(" + funcArgsSyntax + ") { [Command Line API] }";
- };
- }
-
- for (var i = 0; i < CommandLineAPI.members_.length; ++i) {
- var member = CommandLineAPI.members_[i];
- this[member] = bind(commandLineAPIImpl[member], commandLineAPIImpl);
- this[member].toString = customToStringMethod(member);
- }
-
- for (var i = 0; i < 5; ++i) {
- var member = "$" + i;
- this[member] = bind(commandLineAPIImpl._inspectedObject, commandLineAPIImpl, i);
- }
- this.__proto__ = null;
}
-// NOTE: Please keep the list of API methods below synchronized to that in WebInspector.RuntimeModel
-// and V8InjectedScriptHost!
+// NOTE: This list contains only not native Command Line API methods. For full list: V8InjectedScriptHost.
dgozman 2016/04/25 20:55:08 V8InjectedScriptHost -> V8Console
kozy 2016/04/25 21:33:58 Done.
// NOTE: Argument names of these methods will be printed in the console, so use pretty names!
/**
* @type {!Array.<string>}
* @const
*/
-CommandLineAPI.members_ = [
- "$", "$$", "$x", "dir", "dirxml", "keys", "values", "profile", "profileEnd",
- "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "getEventListeners",
- "debug", "undebug", "monitor", "unmonitor", "table"
+CommandLineAPIImpl.members_ = [
dgozman 2016/04/25 20:55:08 nit: inline this, but keep the comment.
kozy 2016/04/25 21:33:58 Done.
+ "$", "$$", "$x", "monitorEvents", "unmonitorEvents", "inspect", "copy", "getEventListeners"
];
-/**
- * @constructor
- */
-function CommandLineAPIImpl()
-{
-}
-
CommandLineAPIImpl.prototype = {
/**
* @param {string} selector
@@ -1256,57 +1243,6 @@ CommandLineAPIImpl.prototype = {
},
/**
- * @return {*}
- */
- dir: function(var_args)
- {
- return InjectedScriptHost.callFunction(inspectedGlobalObject.console.dir, inspectedGlobalObject.console, slice(arguments));
- },
-
- /**
- * @return {*}
- */
- dirxml: function(var_args)
- {
- return InjectedScriptHost.callFunction(inspectedGlobalObject.console.dirxml, inspectedGlobalObject.console, slice(arguments));
- },
-
- /**
- * @return {!Array.<string>}
- */
- keys: function(object)
- {
- return Object.keys(object);
- },
-
- /**
- * @return {!Array.<*>}
- */
- values: function(object)
- {
- var result = [];
- for (var key in object)
- push(result, object[key]);
- return result;
- },
-
- /**
- * @return {*}
- */
- profile: function(opt_title)
- {
- return InjectedScriptHost.callFunction(inspectedGlobalObject.console.profile, inspectedGlobalObject.console, slice(arguments));
- },
-
- /**
- * @return {*}
- */
- profileEnd: function(opt_title)
- {
- return InjectedScriptHost.callFunction(inspectedGlobalObject.console.profileEnd, inspectedGlobalObject.console, slice(arguments));
- },
-
- /**
* @param {!Object} object
* @param {!Array.<string>|string=} opt_types
*/
@@ -1363,11 +1299,6 @@ CommandLineAPIImpl.prototype = {
InjectedScriptHost.inspect(remoteObject, hints);
},
- clear: function()
- {
- InjectedScriptHost.clearConsoleMessages();
- },
-
/**
* @param {!Node} node
* @return {!Object|undefined}
@@ -1416,31 +1347,6 @@ CommandLineAPIImpl.prototype = {
return result;
},
- debug: function(fn)
- {
- InjectedScriptHost.debugFunction(fn);
- },
-
- undebug: function(fn)
- {
- InjectedScriptHost.undebugFunction(fn);
- },
-
- monitor: function(fn)
- {
- InjectedScriptHost.monitorFunction(fn);
- },
-
- unmonitor: function(fn)
- {
- InjectedScriptHost.unmonitorFunction(fn);
- },
-
- table: function(data, opt_columns)
- {
- InjectedScriptHost.callFunction(inspectedGlobalObject.console.table, inspectedGlobalObject.console, slice(arguments));
- },
-
/**
* @param {number} num
*/

Powered by Google App Engine
This is Rietveld 408576698