Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 function toStringDescription(obj) | 98 function toStringDescription(obj) |
| 99 { | 99 { |
| 100 if (typeof obj === "number" && obj === 0 && 1 / obj < 0) | 100 if (typeof obj === "number" && obj === 0 && 1 / obj < 0) |
| 101 return "-0"; // Negative zero. | 101 return "-0"; // Negative zero. |
| 102 return "" + obj; | 102 return "" + obj; |
| 103 } | 103 } |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * Please use this bind, not the one from Function.prototype | 106 * Please use this bind, not the one from Function.prototype |
| 107 * @param {function(...)} func | 107 * @param {function(...)} func |
| 108 * @param {Object} thisObject | 108 * @param {Object} thisObject |
|
aandrey
2014/06/05 19:08:24
why the check for nullability modificator does not
apavlov
2014/06/05 19:26:25
None of these fixed errors are currently checked f
| |
| 109 * @param {...} var_args | 109 * @param {...} var_args |
| 110 * @return {function(...)} | |
| 110 */ | 111 */ |
| 111 function bind(func, thisObject, var_args) | 112 function bind(func, thisObject, var_args) |
| 112 { | 113 { |
| 113 var args = slice(arguments, 2); | 114 var args = slice(arguments, 2); |
| 114 | 115 |
| 115 /** | 116 /** |
| 116 * @param {...} var_args | 117 * @param {...} var_args |
| 117 */ | 118 */ |
| 118 function bound(var_args) | 119 function bound(var_args) |
| 119 { | 120 { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 if ("symbol" in descriptor) | 404 if ("symbol" in descriptor) |
| 404 descriptor.symbol = this._wrapObject(descriptor.symbol, objectGr oupName); | 405 descriptor.symbol = this._wrapObject(descriptor.symbol, objectGr oupName); |
| 405 } | 406 } |
| 406 return descriptors; | 407 return descriptors; |
| 407 }, | 408 }, |
| 408 | 409 |
| 409 /** | 410 /** |
| 410 * @param {string} objectId | 411 * @param {string} objectId |
| 411 * @return {Array.<Object>|boolean} | 412 * @return {Array.<Object>|boolean} |
| 412 */ | 413 */ |
| 413 getInternalProperties: function(objectId, ownProperties) | 414 getInternalProperties: function(objectId) |
| 414 { | 415 { |
| 415 var parsedObjectId = this._parseObjectId(objectId); | 416 var parsedObjectId = this._parseObjectId(objectId); |
| 416 var object = this._objectForId(parsedObjectId); | 417 var object = this._objectForId(parsedObjectId); |
| 417 var objectGroupName = this._idToObjectGroupName[parsedObjectId.id]; | 418 var objectGroupName = this._idToObjectGroupName[parsedObjectId.id]; |
| 418 if (!this._isDefined(object)) | 419 if (!this._isDefined(object)) |
| 419 return false; | 420 return false; |
| 420 var descriptors = []; | 421 var descriptors = []; |
| 421 var internalProperties = InjectedScriptHost.getInternalProperties(object ); | 422 var internalProperties = InjectedScriptHost.getInternalProperties(object ); |
| 422 if (internalProperties) { | 423 if (internalProperties) { |
| 423 for (var i = 0; i < internalProperties.length; i++) { | 424 for (var i = 0; i < internalProperties.length; i++) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 * @return {*} | 565 * @return {*} |
| 565 */ | 566 */ |
| 566 evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByVa lue, generatePreview) | 567 evaluate: function(expression, objectGroup, injectCommandLineAPI, returnByVa lue, generatePreview) |
| 567 { | 568 { |
| 568 return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScript Host, expression, objectGroup, false, injectCommandLineAPI, returnByValue, gener atePreview); | 569 return this._evaluateAndWrap(InjectedScriptHost.evaluate, InjectedScript Host, expression, objectGroup, false, injectCommandLineAPI, returnByValue, gener atePreview); |
| 569 }, | 570 }, |
| 570 | 571 |
| 571 /** | 572 /** |
| 572 * @param {string} objectId | 573 * @param {string} objectId |
| 573 * @param {string} expression | 574 * @param {string} expression |
| 575 * @param {string} args | |
| 574 * @param {boolean} returnByValue | 576 * @param {boolean} returnByValue |
| 575 * @return {!Object|string} | 577 * @return {!Object|string} |
| 576 */ | 578 */ |
| 577 callFunctionOn: function(objectId, expression, args, returnByValue) | 579 callFunctionOn: function(objectId, expression, args, returnByValue) |
| 578 { | 580 { |
| 579 var parsedObjectId = this._parseObjectId(objectId); | 581 var parsedObjectId = this._parseObjectId(objectId); |
| 580 var object = this._objectForId(parsedObjectId); | 582 var object = this._objectForId(parsedObjectId); |
| 581 if (!this._isDefined(object)) | 583 if (!this._isDefined(object)) |
| 582 return "Could not find object with given id"; | 584 return "Could not find object with given id"; |
| 583 | 585 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 if (callArgumentJson.type === "number" && typeof value !== "number") | 634 if (callArgumentJson.type === "number" && typeof value !== "number") |
| 633 value = Number(value); | 635 value = Number(value); |
| 634 return value; | 636 return value; |
| 635 } | 637 } |
| 636 return undefined; | 638 return undefined; |
| 637 }, | 639 }, |
| 638 | 640 |
| 639 /** | 641 /** |
| 640 * @param {Function} evalFunction | 642 * @param {Function} evalFunction |
| 641 * @param {Object} object | 643 * @param {Object} object |
| 644 * @param {string} expression | |
| 642 * @param {string} objectGroup | 645 * @param {string} objectGroup |
| 643 * @param {boolean} isEvalOnCallFrame | 646 * @param {boolean} isEvalOnCallFrame |
| 644 * @param {boolean} injectCommandLineAPI | 647 * @param {boolean} injectCommandLineAPI |
| 645 * @param {boolean} returnByValue | 648 * @param {boolean} returnByValue |
| 646 * @param {boolean} generatePreview | 649 * @param {boolean} generatePreview |
| 647 * @param {!Array.<!Object>=} scopeChain | 650 * @param {!Array.<!Object>=} scopeChain |
| 648 * @return {!Object} | 651 * @return {!Object} |
| 649 */ | 652 */ |
| 650 _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, is EvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview, scopeChai n) | 653 _evaluateAndWrap: function(evalFunction, object, expression, objectGroup, is EvalOnCallFrame, injectCommandLineAPI, returnByValue, generatePreview, scopeChai n) |
| 651 { | 654 { |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1398 * @constructor | 1401 * @constructor |
| 1399 */ | 1402 */ |
| 1400 function CommandLineAPIImpl() | 1403 function CommandLineAPIImpl() |
| 1401 { | 1404 { |
| 1402 } | 1405 } |
| 1403 | 1406 |
| 1404 CommandLineAPIImpl.prototype = { | 1407 CommandLineAPIImpl.prototype = { |
| 1405 /** | 1408 /** |
| 1406 * @param {string} selector | 1409 * @param {string} selector |
| 1407 * @param {Node=} opt_startNode | 1410 * @param {Node=} opt_startNode |
| 1411 * @return {*} | |
| 1408 */ | 1412 */ |
| 1409 $: function (selector, opt_startNode) | 1413 $: function (selector, opt_startNode) |
| 1410 { | 1414 { |
| 1411 if (this._canQuerySelectorOnNode(opt_startNode)) | 1415 if (this._canQuerySelectorOnNode(opt_startNode)) |
| 1412 return opt_startNode.querySelector(selector); | 1416 return opt_startNode.querySelector(selector); |
| 1413 | 1417 |
| 1414 return inspectedWindow.document.querySelector(selector); | 1418 return inspectedWindow.document.querySelector(selector); |
| 1415 }, | 1419 }, |
| 1416 | 1420 |
| 1417 /** | 1421 /** |
| 1418 * @param {string} selector | 1422 * @param {string} selector |
| 1419 * @param {Node=} opt_startNode | 1423 * @param {Node=} opt_startNode |
| 1424 * @return {*} | |
| 1420 */ | 1425 */ |
| 1421 $$: function (selector, opt_startNode) | 1426 $$: function (selector, opt_startNode) |
| 1422 { | 1427 { |
| 1423 if (this._canQuerySelectorOnNode(opt_startNode)) | 1428 if (this._canQuerySelectorOnNode(opt_startNode)) |
| 1424 return opt_startNode.querySelectorAll(selector); | 1429 return opt_startNode.querySelectorAll(selector); |
| 1425 return inspectedWindow.document.querySelectorAll(selector); | 1430 return inspectedWindow.document.querySelectorAll(selector); |
| 1426 }, | 1431 }, |
| 1427 | 1432 |
| 1428 /** | 1433 /** |
| 1429 * @param {Node=} node | 1434 * @param {Node=} node |
| 1430 * @return {boolean} | 1435 * @return {boolean} |
| 1431 */ | 1436 */ |
| 1432 _canQuerySelectorOnNode: function(node) | 1437 _canQuerySelectorOnNode: function(node) |
| 1433 { | 1438 { |
| 1434 return !!node && InjectedScriptHost.type(node) === "node" && (node.nodeT ype === Node.ELEMENT_NODE || node.nodeType === Node.DOCUMENT_NODE || node.nodeTy pe === Node.DOCUMENT_FRAGMENT_NODE); | 1439 return !!node && InjectedScriptHost.type(node) === "node" && (node.nodeT ype === Node.ELEMENT_NODE || node.nodeType === Node.DOCUMENT_NODE || node.nodeTy pe === Node.DOCUMENT_FRAGMENT_NODE); |
| 1435 }, | 1440 }, |
| 1436 | 1441 |
| 1437 /** | 1442 /** |
| 1438 * @param {string} xpath | 1443 * @param {string} xpath |
| 1439 * @param {Node=} opt_startNode | 1444 * @param {Node=} opt_startNode |
| 1445 * @return {*} | |
| 1440 */ | 1446 */ |
| 1441 $x: function(xpath, opt_startNode) | 1447 $x: function(xpath, opt_startNode) |
| 1442 { | 1448 { |
| 1443 var doc = (opt_startNode && opt_startNode.ownerDocument) || inspectedWin dow.document; | 1449 var doc = (opt_startNode && opt_startNode.ownerDocument) || inspectedWin dow.document; |
| 1444 var result = doc.evaluate(xpath, opt_startNode || doc, null, XPathResult .ANY_TYPE, null); | 1450 var result = doc.evaluate(xpath, opt_startNode || doc, null, XPathResult .ANY_TYPE, null); |
| 1445 switch (result.resultType) { | 1451 switch (result.resultType) { |
| 1446 case XPathResult.NUMBER_TYPE: | 1452 case XPathResult.NUMBER_TYPE: |
| 1447 return result.numberValue; | 1453 return result.numberValue; |
| 1448 case XPathResult.STRING_TYPE: | 1454 case XPathResult.STRING_TYPE: |
| 1449 return result.stringValue; | 1455 return result.stringValue; |
| 1450 case XPathResult.BOOLEAN_TYPE: | 1456 case XPathResult.BOOLEAN_TYPE: |
| 1451 return result.booleanValue; | 1457 return result.booleanValue; |
| 1452 default: | 1458 default: |
| 1453 var nodes = []; | 1459 var nodes = []; |
| 1454 var node; | 1460 var node; |
| 1455 while (node = result.iterateNext()) | 1461 while (node = result.iterateNext()) |
| 1456 push(nodes, node); | 1462 push(nodes, node); |
| 1457 return nodes; | 1463 return nodes; |
| 1458 } | 1464 } |
| 1459 }, | 1465 }, |
| 1460 | 1466 |
| 1467 /** | |
| 1468 * @return {*} | |
| 1469 */ | |
| 1461 dir: function(var_args) | 1470 dir: function(var_args) |
| 1462 { | 1471 { |
| 1463 return inspectedWindow.console.dir.apply(inspectedWindow.console, argume nts) | 1472 return inspectedWindow.console.dir.apply(inspectedWindow.console, argume nts) |
| 1464 }, | 1473 }, |
| 1465 | 1474 |
| 1475 /** | |
| 1476 * @return {*} | |
| 1477 */ | |
| 1466 dirxml: function(var_args) | 1478 dirxml: function(var_args) |
| 1467 { | 1479 { |
| 1468 return inspectedWindow.console.dirxml.apply(inspectedWindow.console, arg uments) | 1480 return inspectedWindow.console.dirxml.apply(inspectedWindow.console, arg uments) |
| 1469 }, | 1481 }, |
| 1470 | 1482 |
| 1483 /** | |
| 1484 * @return {!Array.<string>} | |
| 1485 */ | |
| 1471 keys: function(object) | 1486 keys: function(object) |
| 1472 { | 1487 { |
| 1473 return Object.keys(object); | 1488 return Object.keys(object); |
| 1474 }, | 1489 }, |
| 1475 | 1490 |
| 1491 /** | |
| 1492 * @return {!Array.<*>} | |
| 1493 */ | |
| 1476 values: function(object) | 1494 values: function(object) |
| 1477 { | 1495 { |
| 1478 var result = []; | 1496 var result = []; |
| 1479 for (var key in object) | 1497 for (var key in object) |
| 1480 push(result, object[key]); | 1498 push(result, object[key]); |
| 1481 return result; | 1499 return result; |
| 1482 }, | 1500 }, |
| 1483 | 1501 |
| 1502 /** | |
| 1503 * @return {*} | |
| 1504 */ | |
| 1484 profile: function(opt_title) | 1505 profile: function(opt_title) |
| 1485 { | 1506 { |
| 1486 return inspectedWindow.console.profile.apply(inspectedWindow.console, ar guments) | 1507 return inspectedWindow.console.profile.apply(inspectedWindow.console, ar guments) |
| 1487 }, | 1508 }, |
| 1488 | 1509 |
| 1510 /** | |
| 1511 * @return {*} | |
| 1512 */ | |
| 1489 profileEnd: function(opt_title) | 1513 profileEnd: function(opt_title) |
| 1490 { | 1514 { |
| 1491 return inspectedWindow.console.profileEnd.apply(inspectedWindow.console, arguments) | 1515 return inspectedWindow.console.profileEnd.apply(inspectedWindow.console, arguments) |
| 1492 }, | 1516 }, |
| 1493 | 1517 |
| 1494 /** | 1518 /** |
| 1495 * @param {Object} object | 1519 * @param {Object} object |
| 1496 * @param {Array.<string>|string=} opt_types | 1520 * @param {Array.<string>|string=} opt_types |
| 1497 */ | 1521 */ |
| 1498 monitorEvents: function(object, opt_types) | 1522 monitorEvents: function(object, opt_types) |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1642 */ | 1666 */ |
| 1643 _logEvent: function(event) | 1667 _logEvent: function(event) |
| 1644 { | 1668 { |
| 1645 inspectedWindow.console.log(event.type, event); | 1669 inspectedWindow.console.log(event.type, event); |
| 1646 } | 1670 } |
| 1647 } | 1671 } |
| 1648 | 1672 |
| 1649 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1673 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
| 1650 return injectedScript; | 1674 return injectedScript; |
| 1651 }) | 1675 }) |
| OLD | NEW |