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

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..1eb6125b31f66b5d87a3279e2be0c8e9a77f970b 100644
--- a/third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js
+++ b/third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js
@@ -607,11 +607,45 @@ InjectedScript.prototype = {
},
/**
- * @return {!CommandLineAPI}
+ * @param {!Object} nativeCommandLineAPI
+ * @return {!Object}
*/
- commandLineAPI: function()
+ installCommandLineAPI: function(nativeCommandLineAPI)
{
- return new CommandLineAPI(this._commandLineAPIImpl);
+ var commandLineAPIImpl = this._commandLineAPIImpl;
+ /**
+ * @param {string} name The name of the method for which a toString method should be generated.
+ * @return {function():string}
+ */
+ function customToStringMethod(name)
dgozman 2016/04/25 18:09:50 Let's have a big map {method -> toString} for all
kozy 2016/04/25 19:31:06 Done.
+ {
+ 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 < CommandLineAPIImpl.members_.length; ++i) {
+ var member = CommandLineAPIImpl.members_[i];
+ nativeCommandLineAPI[member] = bind(commandLineAPIImpl[member], commandLineAPIImpl);
+ nativeCommandLineAPI[member].toString = customToStringMethod(member);
+ }
+
+ for (var i = 0; i < 5; ++i) {
+ var member = "$" + i;
+ nativeCommandLineAPI[member] = bind(commandLineAPIImpl._inspectedObject, commandLineAPIImpl, i);
+ }
+ return nativeCommandLineAPI;
},
/**
@@ -1136,65 +1170,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.
// 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_ = [
+ "$", "$$", "$x", "monitorEvents", "unmonitorEvents", "inspect", "copy", "getEventListeners"
];
-/**
- * @constructor
- */
-function CommandLineAPIImpl()
-{
-}
-
CommandLineAPIImpl.prototype = {
/**
* @param {string} selector
@@ -1256,57 +1246,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 +1302,6 @@ CommandLineAPIImpl.prototype = {
InjectedScriptHost.inspect(remoteObject, hints);
},
- clear: function()
- {
- InjectedScriptHost.clearConsoleMessages();
- },
-
/**
* @param {!Node} node
* @return {!Object|undefined}
@@ -1416,31 +1350,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