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

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, 7 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 /**
617 * @param {string} name The name of the method for which a toString meth od should be generated.
618 * @return {function():string}
619 */
620 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.
621 {
622 return function()
623 {
624 var funcArgsSyntax = "";
625 try {
626 var funcSyntax = "" + commandLineAPIImpl[name];
627 funcSyntax = funcSyntax.replace(/\n/g, " ");
628 funcSyntax = funcSyntax.replace(/^function[^\(]*\(([^\)]*)\) .*$/, "$1");
629 funcSyntax = funcSyntax.replace(/\s*,\s*/g, ", ");
630 funcSyntax = funcSyntax.replace(/\bopt_(\w+)\b/g, "[$1]");
631 funcArgsSyntax = funcSyntax.trim();
632 } catch (e) {
633 }
634 return "function " + name + "(" + funcArgsSyntax + ") { [Command Line API] }";
635 };
636 }
637
638 for (var i = 0; i < CommandLineAPIImpl.members_.length; ++i) {
639 var member = CommandLineAPIImpl.members_[i];
640 nativeCommandLineAPI[member] = bind(commandLineAPIImpl[member], comm andLineAPIImpl);
641 nativeCommandLineAPI[member].toString = customToStringMethod(member) ;
642 }
643
644 for (var i = 0; i < 5; ++i) {
645 var member = "$" + i;
646 nativeCommandLineAPI[member] = bind(commandLineAPIImpl._inspectedObj ect, commandLineAPIImpl, i);
647 }
648 return nativeCommandLineAPI;
615 }, 649 },
616 650
617 /** 651 /**
618 * @param {string} objectGroup 652 * @param {string} objectGroup
619 * @return {!Object} 653 * @return {!Object}
620 */ 654 */
621 remoteObjectAPI: function(objectGroup) 655 remoteObjectAPI: function(objectGroup)
622 { 656 {
623 /** 657 /**
624 * @suppressReceiverCheck 658 * @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); 1163 return string.substr(0, leftHalf) + "\u2026" + string.substr(string. length - rightHalf, rightHalf);
1130 } 1164 }
1131 return string.substr(0, maxLength) + "\u2026"; 1165 return string.substr(0, maxLength) + "\u2026";
1132 }, 1166 },
1133 1167
1134 __proto__: null 1168 __proto__: null
1135 } 1169 }
1136 1170
1137 /** 1171 /**
1138 * @constructor 1172 * @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 */ 1173 */
1194 function CommandLineAPIImpl() 1174 function CommandLineAPIImpl()
1195 { 1175 {
1196 } 1176 }
1197 1177
1178 // NOTE: This list contains only not native Command Line API methods. For full l ist: V8InjectedScriptHost.
1179 // NOTE: Argument names of these methods will be printed in the console, so use pretty names!
1180 /**
1181 * @type {!Array.<string>}
1182 * @const
1183 */
1184 CommandLineAPIImpl.members_ = [
1185 "$", "$$", "$x", "monitorEvents", "unmonitorEvents", "inspect", "copy", "get EventListeners"
1186 ];
1187
1198 CommandLineAPIImpl.prototype = { 1188 CommandLineAPIImpl.prototype = {
1199 /** 1189 /**
1200 * @param {string} selector 1190 * @param {string} selector
1201 * @param {!Node=} opt_startNode 1191 * @param {!Node=} opt_startNode
1202 * @return {*} 1192 * @return {*}
1203 */ 1193 */
1204 $: function (selector, opt_startNode) 1194 $: function (selector, opt_startNode)
1205 { 1195 {
1206 if (this._canQuerySelectorOnNode(opt_startNode)) 1196 if (this._canQuerySelectorOnNode(opt_startNode))
1207 return opt_startNode.querySelector(selector); 1197 return opt_startNode.querySelector(selector);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 default: 1239 default:
1250 var nodes = []; 1240 var nodes = [];
1251 var node; 1241 var node;
1252 while (node = result.iterateNext()) 1242 while (node = result.iterateNext())
1253 push(nodes, node); 1243 push(nodes, node);
1254 return nodes; 1244 return nodes;
1255 } 1245 }
1256 }, 1246 },
1257 1247
1258 /** 1248 /**
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 1249 * @param {!Object} object
1311 * @param {!Array.<string>|string=} opt_types 1250 * @param {!Array.<string>|string=} opt_types
1312 */ 1251 */
1313 monitorEvents: function(object, opt_types) 1252 monitorEvents: function(object, opt_types)
1314 { 1253 {
1315 if (!object || !object.addEventListener || !object.removeEventListener) 1254 if (!object || !object.addEventListener || !object.removeEventListener)
1316 return; 1255 return;
1317 var types = this._normalizeEventTypes(opt_types); 1256 var types = this._normalizeEventTypes(opt_types);
1318 for (var i = 0; i < types.length; ++i) { 1257 for (var i = 0; i < types.length; ++i) {
1319 object.removeEventListener(types[i], this._logEvent, false); 1258 object.removeEventListener(types[i], this._logEvent, false);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 } catch (e) { 1295 } catch (e) {
1357 string = toString(object); 1296 string = toString(object);
1358 } 1297 }
1359 } 1298 }
1360 1299
1361 var hints = { copyToClipboard: true, __proto__: null }; 1300 var hints = { copyToClipboard: true, __proto__: null };
1362 var remoteObject = injectedScript._wrapObject(string, "") 1301 var remoteObject = injectedScript._wrapObject(string, "")
1363 InjectedScriptHost.inspect(remoteObject, hints); 1302 InjectedScriptHost.inspect(remoteObject, hints);
1364 }, 1303 },
1365 1304
1366 clear: function()
1367 {
1368 InjectedScriptHost.clearConsoleMessages();
1369 },
1370
1371 /** 1305 /**
1372 * @param {!Node} node 1306 * @param {!Node} node
1373 * @return {!Object|undefined} 1307 * @return {!Object|undefined}
1374 */ 1308 */
1375 getEventListeners: function(node) 1309 getEventListeners: function(node)
1376 { 1310 {
1377 var result = nullifyObjectProto(InjectedScriptHost.getEventListeners(nod e)); 1311 var result = nullifyObjectProto(InjectedScriptHost.getEventListeners(nod e));
1378 if (!result) 1312 if (!result)
1379 return; 1313 return;
1380 1314
(...skipping 28 matching lines...) Expand all
1409 for (var type in result) { 1343 for (var type in result) {
1410 var listeners = result[type]; 1344 var listeners = result[type];
1411 for (var i = 0, listener; listener = listeners[i]; ++i) { 1345 for (var i = 0, listener; listener = listeners[i]; ++i) {
1412 listener["type"] = type; 1346 listener["type"] = type;
1413 listener["remove"] = removeFunc; 1347 listener["remove"] = removeFunc;
1414 } 1348 }
1415 } 1349 }
1416 return result; 1350 return result;
1417 }, 1351 },
1418 1352
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 /** 1353 /**
1445 * @param {number} num 1354 * @param {number} num
1446 */ 1355 */
1447 _inspectedObject: function(num) 1356 _inspectedObject: function(num)
1448 { 1357 {
1449 return InjectedScriptHost.inspectedObject(num); 1358 return InjectedScriptHost.inspectedObject(num);
1450 }, 1359 },
1451 1360
1452 /** 1361 /**
1453 * @param {!Array.<string>|string=} types 1362 * @param {!Array.<string>|string=} types
(...skipping 29 matching lines...) Expand all
1483 */ 1392 */
1484 _logEvent: function(event) 1393 _logEvent: function(event)
1485 { 1394 {
1486 inspectedGlobalObject.console.log(event.type, event); 1395 inspectedGlobalObject.console.log(event.type, event);
1487 } 1396 }
1488 } 1397 }
1489 1398
1490 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); 1399 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl();
1491 return injectedScript; 1400 return injectedScript;
1492 }) 1401 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698