| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 * @param {number} a | 167 * @param {number} a |
| 168 * @param {number} b | 168 * @param {number} b |
| 169 * @return {number} | 169 * @return {number} |
| 170 */ | 170 */ |
| 171 function max(a, b) | 171 function max(a, b) |
| 172 { | 172 { |
| 173 return a > b ? a : b; | 173 return a > b ? a : b; |
| 174 } | 174 } |
| 175 | 175 |
| 176 /** | 176 /** |
| 177 * FIXME: Remove once ES6 is supported natively by JS compiler. |
| 178 * @param {*} obj |
| 179 * @return {boolean} |
| 180 */ |
| 181 function isSymbol(obj) |
| 182 { |
| 183 var type = typeof obj; |
| 184 return (type === "symbol"); |
| 185 } |
| 186 |
| 187 /** |
| 177 * @constructor | 188 * @constructor |
| 178 */ | 189 */ |
| 179 var InjectedScript = function() | 190 var InjectedScript = function() |
| 180 { | 191 { |
| 181 /** @type {number} */ | 192 /** @type {number} */ |
| 182 this._lastBoundObjectId = 1; | 193 this._lastBoundObjectId = 1; |
| 183 /** @type {!Object.<number, !Object>} */ | 194 /** @type {!Object.<number, (!Object|symbol)>} */ |
| 184 this._idToWrappedObject = { __proto__: null }; | 195 this._idToWrappedObject = { __proto__: null }; |
| 185 /** @type {!Object.<number, string>} */ | 196 /** @type {!Object.<number, string>} */ |
| 186 this._idToObjectGroupName = { __proto__: null }; | 197 this._idToObjectGroupName = { __proto__: null }; |
| 187 /** @type {!Object.<string, !Array.<number>>} */ | 198 /** @type {!Object.<string, !Array.<number>>} */ |
| 188 this._objectGroups = { __proto__: null }; | 199 this._objectGroups = { __proto__: null }; |
| 189 /** @type {!Object.<string, !Object>} */ | 200 /** @type {!Object.<string, !Object>} */ |
| 190 this._modules = { __proto__: null }; | 201 this._modules = { __proto__: null }; |
| 191 } | 202 } |
| 192 | 203 |
| 193 /** | 204 /** |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 try { | 317 try { |
| 307 var description = injectedScript._describe(e); | 318 var description = injectedScript._describe(e); |
| 308 } catch (ex) { | 319 } catch (ex) { |
| 309 var description = "<failed to convert exception to string>"; | 320 var description = "<failed to convert exception to string>"; |
| 310 } | 321 } |
| 311 return new InjectedScript.RemoteObject(description); | 322 return new InjectedScript.RemoteObject(description); |
| 312 } | 323 } |
| 313 }, | 324 }, |
| 314 | 325 |
| 315 /** | 326 /** |
| 316 * @param {!Object} object | 327 * @param {!Object|symbol} object |
| 317 * @param {string=} objectGroupName | 328 * @param {string=} objectGroupName |
| 318 * @return {string} | 329 * @return {string} |
| 319 */ | 330 */ |
| 320 _bind: function(object, objectGroupName) | 331 _bind: function(object, objectGroupName) |
| 321 { | 332 { |
| 322 var id = this._lastBoundObjectId++; | 333 var id = this._lastBoundObjectId++; |
| 323 this._idToWrappedObject[id] = object; | 334 this._idToWrappedObject[id] = object; |
| 324 var objectId = "{\"injectedScriptId\":" + injectedScriptId + ",\"id\":"
+ id + "}"; | 335 var objectId = "{\"injectedScriptId\":" + injectedScriptId + ",\"id\":"
+ id + "}"; |
| 325 if (objectGroupName) { | 336 if (objectGroupName) { |
| 326 var group = this._objectGroups[objectGroupName]; | 337 var group = this._objectGroups[objectGroupName]; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 * @param {boolean} ownProperties | 388 * @param {boolean} ownProperties |
| 378 * @param {boolean} accessorPropertiesOnly | 389 * @param {boolean} accessorPropertiesOnly |
| 379 * @return {!Array.<!RuntimeAgent.PropertyDescriptor>|boolean} | 390 * @return {!Array.<!RuntimeAgent.PropertyDescriptor>|boolean} |
| 380 */ | 391 */ |
| 381 getProperties: function(objectId, ownProperties, accessorPropertiesOnly) | 392 getProperties: function(objectId, ownProperties, accessorPropertiesOnly) |
| 382 { | 393 { |
| 383 var parsedObjectId = this._parseObjectId(objectId); | 394 var parsedObjectId = this._parseObjectId(objectId); |
| 384 var object = this._objectForId(parsedObjectId); | 395 var object = this._objectForId(parsedObjectId); |
| 385 var objectGroupName = this._idToObjectGroupName[parsedObjectId.id]; | 396 var objectGroupName = this._idToObjectGroupName[parsedObjectId.id]; |
| 386 | 397 |
| 387 if (!this._isDefined(object)) | 398 if (!this._isDefined(object) || isSymbol(object)) |
| 388 return false; | 399 return false; |
| 400 object = /** @type {!Object} */ (object); |
| 389 var descriptors = this._propertyDescriptors(object, ownProperties, acces
sorPropertiesOnly); | 401 var descriptors = this._propertyDescriptors(object, ownProperties, acces
sorPropertiesOnly); |
| 390 | 402 |
| 391 // Go over properties, wrap object values. | 403 // Go over properties, wrap object values. |
| 392 for (var i = 0; i < descriptors.length; ++i) { | 404 for (var i = 0; i < descriptors.length; ++i) { |
| 393 var descriptor = descriptors[i]; | 405 var descriptor = descriptors[i]; |
| 394 if ("get" in descriptor) | 406 if ("get" in descriptor) |
| 395 descriptor.get = this._wrapObject(descriptor.get, objectGroupNam
e); | 407 descriptor.get = this._wrapObject(descriptor.get, objectGroupNam
e); |
| 396 if ("set" in descriptor) | 408 if ("set" in descriptor) |
| 397 descriptor.set = this._wrapObject(descriptor.set, objectGroupNam
e); | 409 descriptor.set = this._wrapObject(descriptor.set, objectGroupNam
e); |
| 398 if ("value" in descriptor) | 410 if ("value" in descriptor) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 409 | 421 |
| 410 /** | 422 /** |
| 411 * @param {string} objectId | 423 * @param {string} objectId |
| 412 * @return {!Array.<!Object>|boolean} | 424 * @return {!Array.<!Object>|boolean} |
| 413 */ | 425 */ |
| 414 getInternalProperties: function(objectId) | 426 getInternalProperties: function(objectId) |
| 415 { | 427 { |
| 416 var parsedObjectId = this._parseObjectId(objectId); | 428 var parsedObjectId = this._parseObjectId(objectId); |
| 417 var object = this._objectForId(parsedObjectId); | 429 var object = this._objectForId(parsedObjectId); |
| 418 var objectGroupName = this._idToObjectGroupName[parsedObjectId.id]; | 430 var objectGroupName = this._idToObjectGroupName[parsedObjectId.id]; |
| 419 if (!this._isDefined(object)) | 431 if (!this._isDefined(object) || isSymbol(object)) |
| 420 return false; | 432 return false; |
| 433 object = /** @type {!Object} */ (object); |
| 421 var descriptors = []; | 434 var descriptors = []; |
| 422 var internalProperties = InjectedScriptHost.getInternalProperties(object
); | 435 var internalProperties = InjectedScriptHost.getInternalProperties(object
); |
| 423 if (internalProperties) { | 436 if (internalProperties) { |
| 424 for (var i = 0; i < internalProperties.length; i++) { | 437 for (var i = 0; i < internalProperties.length; i++) { |
| 425 var property = internalProperties[i]; | 438 var property = internalProperties[i]; |
| 426 var descriptor = { | 439 var descriptor = { |
| 427 name: property.name, | 440 name: property.name, |
| 428 value: this._wrapObject(property.value, objectGroupName), | 441 value: this._wrapObject(property.value, objectGroupName), |
| 429 __proto__: null | 442 __proto__: null |
| 430 }; | 443 }; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 * @param {!Array.<string|symbol>} properties | 504 * @param {!Array.<string|symbol>} properties |
| 492 */ | 505 */ |
| 493 function process(o, properties) | 506 function process(o, properties) |
| 494 { | 507 { |
| 495 for (var i = 0; i < properties.length; ++i) { | 508 for (var i = 0; i < properties.length; ++i) { |
| 496 var property = properties[i]; | 509 var property = properties[i]; |
| 497 if (propertyProcessed[property]) | 510 if (propertyProcessed[property]) |
| 498 continue; | 511 continue; |
| 499 | 512 |
| 500 var name = property; | 513 var name = property; |
| 501 var type = typeof property; | 514 if (isSymbol(property)) |
| 502 if (type === "symbol") | |
| 503 name = injectedScript._describe(property); | 515 name = injectedScript._describe(property); |
| 504 | 516 |
| 505 try { | 517 try { |
| 506 propertyProcessed[property] = true; | 518 propertyProcessed[property] = true; |
| 507 var descriptor = nullifyObjectProto(InjectedScriptHost.suppr
essWarningsAndCall(Object, Object.getOwnPropertyDescriptor, o, property)); | 519 var descriptor = nullifyObjectProto(InjectedScriptHost.suppr
essWarningsAndCall(Object, Object.getOwnPropertyDescriptor, o, property)); |
| 508 if (descriptor) { | 520 if (descriptor) { |
| 509 if (accessorPropertiesOnly && !("get" in descriptor || "
set" in descriptor)) | 521 if (accessorPropertiesOnly && !("get" in descriptor || "
set" in descriptor)) |
| 510 continue; | 522 continue; |
| 511 } else { | 523 } else { |
| 512 // Not all bindings provide proper descriptors. Fall bac
k to the writable, configurable property. | 524 // Not all bindings provide proper descriptors. Fall bac
k to the writable, configurable property. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 526 if (accessorPropertiesOnly) | 538 if (accessorPropertiesOnly) |
| 527 continue; | 539 continue; |
| 528 var descriptor = { __proto__: null }; | 540 var descriptor = { __proto__: null }; |
| 529 descriptor.value = e; | 541 descriptor.value = e; |
| 530 descriptor.wasThrown = true; | 542 descriptor.wasThrown = true; |
| 531 } | 543 } |
| 532 | 544 |
| 533 descriptor.name = name; | 545 descriptor.name = name; |
| 534 if (o === object) | 546 if (o === object) |
| 535 descriptor.isOwn = true; | 547 descriptor.isOwn = true; |
| 536 if (type === "symbol") | 548 if (isSymbol(property)) |
| 537 descriptor.symbol = property; | 549 descriptor.symbol = property; |
| 538 push(descriptors, descriptor); | 550 push(descriptors, descriptor); |
| 539 } | 551 } |
| 540 } | 552 } |
| 541 | 553 |
| 542 for (var o = object; this._isDefined(o); o = o.__proto__) { | 554 for (var o = object; this._isDefined(o); o = o.__proto__) { |
| 543 // First call Object.keys() to enforce ordering of the property desc
riptors. | 555 // First call Object.keys() to enforce ordering of the property desc
riptors. |
| 544 process(o, Object.keys(/** @type {!Object} */ (o))); | 556 process(o, Object.keys(/** @type {!Object} */ (o))); |
| 545 process(o, Object.getOwnPropertyNames(/** @type {!Object} */ (o))); | 557 process(o, Object.getOwnPropertyNames(/** @type {!Object} */ (o))); |
| 546 if (Object.getOwnPropertySymbols) | 558 if (Object.getOwnPropertySymbols) |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 topCallFrame = asyncCallStacks[asyncOrdinal - 1]; | 882 topCallFrame = asyncCallStacks[asyncOrdinal - 1]; |
| 871 var ordinal = parsedCallFrameId["ordinal"]; | 883 var ordinal = parsedCallFrameId["ordinal"]; |
| 872 var callFrame = topCallFrame; | 884 var callFrame = topCallFrame; |
| 873 while (--ordinal >= 0 && callFrame) | 885 while (--ordinal >= 0 && callFrame) |
| 874 callFrame = callFrame.caller; | 886 callFrame = callFrame.caller; |
| 875 return callFrame; | 887 return callFrame; |
| 876 }, | 888 }, |
| 877 | 889 |
| 878 /** | 890 /** |
| 879 * @param {!Object} objectId | 891 * @param {!Object} objectId |
| 880 * @return {!Object} | 892 * @return {!Object|symbol} |
| 881 */ | 893 */ |
| 882 _objectForId: function(objectId) | 894 _objectForId: function(objectId) |
| 883 { | 895 { |
| 884 return this._idToWrappedObject[objectId.id]; | 896 return this._idToWrappedObject[objectId.id]; |
| 885 }, | 897 }, |
| 886 | 898 |
| 887 /** | 899 /** |
| 888 * @param {string} objectId | 900 * @param {string} objectId |
| 889 * @return {!Object} | 901 * @return {!Object|symbol} |
| 890 */ | 902 */ |
| 891 findObjectById: function(objectId) | 903 findObjectById: function(objectId) |
| 892 { | 904 { |
| 893 var parsedObjectId = this._parseObjectId(objectId); | 905 var parsedObjectId = this._parseObjectId(objectId); |
| 894 return this._objectForId(parsedObjectId); | 906 return this._objectForId(parsedObjectId); |
| 895 }, | 907 }, |
| 896 | 908 |
| 897 /** | 909 /** |
| 898 * @param {string} objectId | 910 * @param {string} objectId |
| 899 * @return {?Node} | 911 * @return {?Node} |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 | 992 |
| 981 /** | 993 /** |
| 982 * @param {*} obj | 994 * @param {*} obj |
| 983 * @return {?string} | 995 * @return {?string} |
| 984 */ | 996 */ |
| 985 _describe: function(obj) | 997 _describe: function(obj) |
| 986 { | 998 { |
| 987 if (this.isPrimitiveValue(obj)) | 999 if (this.isPrimitiveValue(obj)) |
| 988 return null; | 1000 return null; |
| 989 | 1001 |
| 990 var type = typeof obj; | |
| 991 var subtype = this._subtype(obj); | 1002 var subtype = this._subtype(obj); |
| 992 | 1003 |
| 993 if (subtype === "regexp") | 1004 if (subtype === "regexp") |
| 994 return toString(obj); | 1005 return toString(obj); |
| 995 | 1006 |
| 996 if (subtype === "date") | 1007 if (subtype === "date") |
| 997 return toString(obj); | 1008 return toString(obj); |
| 998 | 1009 |
| 999 if (subtype === "node") { | 1010 if (subtype === "node") { |
| 1000 var description = obj.nodeName.toLowerCase(); | 1011 var description = obj.nodeName.toLowerCase(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1012 } | 1023 } |
| 1013 | 1024 |
| 1014 var className = InjectedScriptHost.internalConstructorName(obj); | 1025 var className = InjectedScriptHost.internalConstructorName(obj); |
| 1015 if (subtype === "array") { | 1026 if (subtype === "array") { |
| 1016 if (typeof obj.length === "number") | 1027 if (typeof obj.length === "number") |
| 1017 className += "[" + obj.length + "]"; | 1028 className += "[" + obj.length + "]"; |
| 1018 return className; | 1029 return className; |
| 1019 } | 1030 } |
| 1020 | 1031 |
| 1021 // NodeList in JSC is a function, check for array prior to this. | 1032 // NodeList in JSC is a function, check for array prior to this. |
| 1022 if (type === "function") | 1033 if (typeof obj === "function") |
| 1023 return toString(obj); | 1034 return toString(obj); |
| 1024 | 1035 |
| 1025 if (type === "symbol") { | 1036 if (isSymbol(obj)) { |
| 1026 try { | 1037 try { |
| 1027 return Symbol.prototype.toString.call(obj) || "Symbol"; | 1038 return Symbol.prototype.toString.call(obj) || "Symbol"; |
| 1028 } catch (e) { | 1039 } catch (e) { |
| 1029 return "Symbol"; | 1040 return "Symbol"; |
| 1030 } | 1041 } |
| 1031 } | 1042 } |
| 1032 | 1043 |
| 1033 if (className === "Object") { | 1044 if (className === "Object") { |
| 1034 // In Chromium DOM wrapper prototypes will have Object as their cons
tructor name, | 1045 // In Chromium DOM wrapper prototypes will have Object as their cons
tructor name, |
| 1035 // get the real DOM wrapper name from the constructor property. | 1046 // get the real DOM wrapper name from the constructor property. |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1666 */ | 1677 */ |
| 1667 _logEvent: function(event) | 1678 _logEvent: function(event) |
| 1668 { | 1679 { |
| 1669 inspectedWindow.console.log(event.type, event); | 1680 inspectedWindow.console.log(event.type, event); |
| 1670 } | 1681 } |
| 1671 } | 1682 } |
| 1672 | 1683 |
| 1673 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1684 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
| 1674 return injectedScript; | 1685 return injectedScript; |
| 1675 }) | 1686 }) |
| OLD | NEW |