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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 600 }
601 601
602 for (var i = 0; i < jsonMLObject.length; ++i) 602 for (var i = 0; i < jsonMLObject.length; ++i)
603 this._substituteObjectTagsInCustomPreview(objectGroupName, jsonM LObject[i]); 603 this._substituteObjectTagsInCustomPreview(objectGroupName, jsonM LObject[i]);
604 } finally { 604 } finally {
605 this._customPreviewRecursionDepth--; 605 this._customPreviewRecursionDepth--;
606 } 606 }
607 }, 607 },
608 608
609 /** 609 /**
610 * @return {!CommandLineAPI} 610 * @param {!Object} nativeCommandLineAPI
611 * @return {!Object}
611 */ 612 */
612 commandLineAPI: function() 613 installCommandLineAPI: function(nativeCommandLineAPI)
613 { 614 {
614 return new CommandLineAPI(this._commandLineAPIImpl); 615 var commandLineAPIImpl = this._commandLineAPIImpl;
616 for (var member of CommandLineAPIImpl.members_)
617 nativeCommandLineAPI[member] = bind(commandLineAPIImpl[member], comm andLineAPIImpl);
618
619 for (var i = 0; i < 5; ++i) {
620 var member = "$" + i;
621 nativeCommandLineAPI[member] = bind(commandLineAPIImpl._inspectedObj ect, commandLineAPIImpl, i);
622 }
623
624 nativeCommandLineAPI["$"].toString = function() { return "function $(sel ector, [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.
625 nativeCommandLineAPI["$$"].toString = function() { return "function $$(s elector, [startNode]) { [Command Line API] }"};
626 nativeCommandLineAPI["$x"].toString = function() { return "function $x(x path, [startNode]) { [Command Line API] }"};
627 nativeCommandLineAPI["dir"].toString = function() { return "function dir (value) { [Command Line API] }"};
628 nativeCommandLineAPI["dirxml"].toString = function() { return "function dirxml(value) { [Command Line API] }"};
629 nativeCommandLineAPI["keys"].toString = function() { return "function ke ys(object) { [Command Line API] }"};
630 nativeCommandLineAPI["values"].toString = function() { return "function values(object) { [Command Line API] }"};
631 nativeCommandLineAPI["profile"].toString = function() { return "function profile(value) { [Command Line API] }"};
632 nativeCommandLineAPI["profileEnd"].toString = function() { return "funct ion profileEnd(value) { [Command Line API] }"};
633 nativeCommandLineAPI["monitorEvents"].toString = function() { return "fu nction monitorEvents(object, [types]) { [Command Line API] }"};
634 nativeCommandLineAPI["unmonitorEvents"].toString = function() { return " function unmonitorEvents(object, [types]) { [Command Line API] }"};
635 nativeCommandLineAPI["inspect"].toString = function() { return "function inspect(object) { [Command Line API] }"};
636 nativeCommandLineAPI["copy"].toString = function() { return "function co py(value) { [Command Line API] }"};
637 nativeCommandLineAPI["clear"].toString = function() { return "function c lear() { [Command Line API] }"};
638 nativeCommandLineAPI["getEventListeners"].toString = function() { return "function getEventListeners(node) { [Command Line API] }"};
639 nativeCommandLineAPI["debug"].toString = function() { return "function d ebug(function) { [Command Line API] }"};
640 nativeCommandLineAPI["undebug"].toString = function() { return "function undebug(function) { [Command Line API] }"};
641 nativeCommandLineAPI["monitor"].toString = function() { return "function monitor(function) { [Command Line API] }"};
642 nativeCommandLineAPI["unmonitor"].toString = function() { return "functi on unmonitor(function) { [Command Line API] }"};
643 nativeCommandLineAPI["table"].toString = function() { return "function t able(value) { [Command Line API] }"};
644
645 return nativeCommandLineAPI;
615 }, 646 },
616 647
617 /** 648 /**
618 * @param {string} objectGroup 649 * @param {string} objectGroup
619 * @return {!Object} 650 * @return {!Object}
620 */ 651 */
621 remoteObjectAPI: function(objectGroup) 652 remoteObjectAPI: function(objectGroup)
622 { 653 {
623 /** 654 /**
624 * @suppressReceiverCheck 655 * @suppressReceiverCheck
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 return string.substr(0, leftHalf) + "\u2026" + string.substr(string. length - rightHalf, rightHalf); 1160 return string.substr(0, leftHalf) + "\u2026" + string.substr(string. length - rightHalf, rightHalf);
1130 } 1161 }
1131 return string.substr(0, maxLength) + "\u2026"; 1162 return string.substr(0, maxLength) + "\u2026";
1132 }, 1163 },
1133 1164
1134 __proto__: null 1165 __proto__: null
1135 } 1166 }
1136 1167
1137 /** 1168 /**
1138 * @constructor 1169 * @constructor
1139 * @param {!CommandLineAPIImpl} commandLineAPIImpl
1140 */
1141 function CommandLineAPI(commandLineAPIImpl)
1142 {
1143 /**
1144 * @param {string} name The name of the method for which a toString method s hould be generated.
1145 * @return {function():string}
1146 */
1147 function customToStringMethod(name)
1148 {
1149 return function()
1150 {
1151 var funcArgsSyntax = "";
1152 try {
1153 var funcSyntax = "" + commandLineAPIImpl[name];
1154 funcSyntax = funcSyntax.replace(/\n/g, " ");
1155 funcSyntax = funcSyntax.replace(/^function[^\(]*\(([^\)]*)\).*$/ , "$1");
1156 funcSyntax = funcSyntax.replace(/\s*,\s*/g, ", ");
1157 funcSyntax = funcSyntax.replace(/\bopt_(\w+)\b/g, "[$1]");
1158 funcArgsSyntax = funcSyntax.trim();
1159 } catch (e) {
1160 }
1161 return "function " + name + "(" + funcArgsSyntax + ") { [Command Lin e API] }";
1162 };
1163 }
1164
1165 for (var i = 0; i < CommandLineAPI.members_.length; ++i) {
1166 var member = CommandLineAPI.members_[i];
1167 this[member] = bind(commandLineAPIImpl[member], commandLineAPIImpl);
1168 this[member].toString = customToStringMethod(member);
1169 }
1170
1171 for (var i = 0; i < 5; ++i) {
1172 var member = "$" + i;
1173 this[member] = bind(commandLineAPIImpl._inspectedObject, commandLineAPII mpl, i);
1174 }
1175 this.__proto__ = null;
1176 }
1177
1178 // NOTE: Please keep the list of API methods below synchronized to that in WebIn spector.RuntimeModel
1179 // and V8InjectedScriptHost!
1180 // NOTE: Argument names of these methods will be printed in the console, so use pretty names!
1181 /**
1182 * @type {!Array.<string>}
1183 * @const
1184 */
1185 CommandLineAPI.members_ = [
1186 "$", "$$", "$x", "dir", "dirxml", "keys", "values", "profile", "profileEnd",
1187 "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear", "getEventLis teners",
1188 "debug", "undebug", "monitor", "unmonitor", "table"
1189 ];
1190
1191 /**
1192 * @constructor
1193 */ 1170 */
1194 function CommandLineAPIImpl() 1171 function CommandLineAPIImpl()
1195 { 1172 {
1196 } 1173 }
1197 1174
1175 // NOTE: This list contains only not native Command Line API methods. For full l ist: V8InjectedScriptHost.
dgozman 2016/04/25 20:55:08 V8InjectedScriptHost -> V8Console
kozy 2016/04/25 21:33:58 Done.
1176 // NOTE: Argument names of these methods will be printed in the console, so use pretty names!
1177 /**
1178 * @type {!Array.<string>}
1179 * @const
1180 */
1181 CommandLineAPIImpl.members_ = [
dgozman 2016/04/25 20:55:08 nit: inline this, but keep the comment.
kozy 2016/04/25 21:33:58 Done.
1182 "$", "$$", "$x", "monitorEvents", "unmonitorEvents", "inspect", "copy", "get EventListeners"
1183 ];
1184
1198 CommandLineAPIImpl.prototype = { 1185 CommandLineAPIImpl.prototype = {
1199 /** 1186 /**
1200 * @param {string} selector 1187 * @param {string} selector
1201 * @param {!Node=} opt_startNode 1188 * @param {!Node=} opt_startNode
1202 * @return {*} 1189 * @return {*}
1203 */ 1190 */
1204 $: function (selector, opt_startNode) 1191 $: function (selector, opt_startNode)
1205 { 1192 {
1206 if (this._canQuerySelectorOnNode(opt_startNode)) 1193 if (this._canQuerySelectorOnNode(opt_startNode))
1207 return opt_startNode.querySelector(selector); 1194 return opt_startNode.querySelector(selector);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 default: 1236 default:
1250 var nodes = []; 1237 var nodes = [];
1251 var node; 1238 var node;
1252 while (node = result.iterateNext()) 1239 while (node = result.iterateNext())
1253 push(nodes, node); 1240 push(nodes, node);
1254 return nodes; 1241 return nodes;
1255 } 1242 }
1256 }, 1243 },
1257 1244
1258 /** 1245 /**
1259 * @return {*}
1260 */
1261 dir: function(var_args)
1262 {
1263 return InjectedScriptHost.callFunction(inspectedGlobalObject.console.dir , inspectedGlobalObject.console, slice(arguments));
1264 },
1265
1266 /**
1267 * @return {*}
1268 */
1269 dirxml: function(var_args)
1270 {
1271 return InjectedScriptHost.callFunction(inspectedGlobalObject.console.dir xml, inspectedGlobalObject.console, slice(arguments));
1272 },
1273
1274 /**
1275 * @return {!Array.<string>}
1276 */
1277 keys: function(object)
1278 {
1279 return Object.keys(object);
1280 },
1281
1282 /**
1283 * @return {!Array.<*>}
1284 */
1285 values: function(object)
1286 {
1287 var result = [];
1288 for (var key in object)
1289 push(result, object[key]);
1290 return result;
1291 },
1292
1293 /**
1294 * @return {*}
1295 */
1296 profile: function(opt_title)
1297 {
1298 return InjectedScriptHost.callFunction(inspectedGlobalObject.console.pro file, inspectedGlobalObject.console, slice(arguments));
1299 },
1300
1301 /**
1302 * @return {*}
1303 */
1304 profileEnd: function(opt_title)
1305 {
1306 return InjectedScriptHost.callFunction(inspectedGlobalObject.console.pro fileEnd, inspectedGlobalObject.console, slice(arguments));
1307 },
1308
1309 /**
1310 * @param {!Object} object 1246 * @param {!Object} object
1311 * @param {!Array.<string>|string=} opt_types 1247 * @param {!Array.<string>|string=} opt_types
1312 */ 1248 */
1313 monitorEvents: function(object, opt_types) 1249 monitorEvents: function(object, opt_types)
1314 { 1250 {
1315 if (!object || !object.addEventListener || !object.removeEventListener) 1251 if (!object || !object.addEventListener || !object.removeEventListener)
1316 return; 1252 return;
1317 var types = this._normalizeEventTypes(opt_types); 1253 var types = this._normalizeEventTypes(opt_types);
1318 for (var i = 0; i < types.length; ++i) { 1254 for (var i = 0; i < types.length; ++i) {
1319 object.removeEventListener(types[i], this._logEvent, false); 1255 object.removeEventListener(types[i], this._logEvent, false);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 } catch (e) { 1292 } catch (e) {
1357 string = toString(object); 1293 string = toString(object);
1358 } 1294 }
1359 } 1295 }
1360 1296
1361 var hints = { copyToClipboard: true, __proto__: null }; 1297 var hints = { copyToClipboard: true, __proto__: null };
1362 var remoteObject = injectedScript._wrapObject(string, "") 1298 var remoteObject = injectedScript._wrapObject(string, "")
1363 InjectedScriptHost.inspect(remoteObject, hints); 1299 InjectedScriptHost.inspect(remoteObject, hints);
1364 }, 1300 },
1365 1301
1366 clear: function()
1367 {
1368 InjectedScriptHost.clearConsoleMessages();
1369 },
1370
1371 /** 1302 /**
1372 * @param {!Node} node 1303 * @param {!Node} node
1373 * @return {!Object|undefined} 1304 * @return {!Object|undefined}
1374 */ 1305 */
1375 getEventListeners: function(node) 1306 getEventListeners: function(node)
1376 { 1307 {
1377 var result = nullifyObjectProto(InjectedScriptHost.getEventListeners(nod e)); 1308 var result = nullifyObjectProto(InjectedScriptHost.getEventListeners(nod e));
1378 if (!result) 1309 if (!result)
1379 return; 1310 return;
1380 1311
(...skipping 28 matching lines...) Expand all
1409 for (var type in result) { 1340 for (var type in result) {
1410 var listeners = result[type]; 1341 var listeners = result[type];
1411 for (var i = 0, listener; listener = listeners[i]; ++i) { 1342 for (var i = 0, listener; listener = listeners[i]; ++i) {
1412 listener["type"] = type; 1343 listener["type"] = type;
1413 listener["remove"] = removeFunc; 1344 listener["remove"] = removeFunc;
1414 } 1345 }
1415 } 1346 }
1416 return result; 1347 return result;
1417 }, 1348 },
1418 1349
1419 debug: function(fn)
1420 {
1421 InjectedScriptHost.debugFunction(fn);
1422 },
1423
1424 undebug: function(fn)
1425 {
1426 InjectedScriptHost.undebugFunction(fn);
1427 },
1428
1429 monitor: function(fn)
1430 {
1431 InjectedScriptHost.monitorFunction(fn);
1432 },
1433
1434 unmonitor: function(fn)
1435 {
1436 InjectedScriptHost.unmonitorFunction(fn);
1437 },
1438
1439 table: function(data, opt_columns)
1440 {
1441 InjectedScriptHost.callFunction(inspectedGlobalObject.console.table, ins pectedGlobalObject.console, slice(arguments));
1442 },
1443
1444 /** 1350 /**
1445 * @param {number} num 1351 * @param {number} num
1446 */ 1352 */
1447 _inspectedObject: function(num) 1353 _inspectedObject: function(num)
1448 { 1354 {
1449 return InjectedScriptHost.inspectedObject(num); 1355 return InjectedScriptHost.inspectedObject(num);
1450 }, 1356 },
1451 1357
1452 /** 1358 /**
1453 * @param {!Array.<string>|string=} types 1359 * @param {!Array.<string>|string=} types
(...skipping 29 matching lines...) Expand all
1483 */ 1389 */
1484 _logEvent: function(event) 1390 _logEvent: function(event)
1485 { 1391 {
1486 inspectedGlobalObject.console.log(event.type, event); 1392 inspectedGlobalObject.console.log(event.type, event);
1487 } 1393 }
1488 } 1394 }
1489 1395
1490 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); 1396 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl();
1491 return injectedScript; 1397 return injectedScript;
1492 }) 1398 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698