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