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 317 matching lines...) Loading... | |
328 getProperties: function(object, objectGroupName, ownProperties, accessorProp ertiesOnly, generatePreview) | 328 getProperties: function(object, objectGroupName, ownProperties, accessorProp ertiesOnly, generatePreview) |
329 { | 329 { |
330 var subtype = this._subtype(object); | 330 var subtype = this._subtype(object); |
331 if (subtype === "internal#scope") { | 331 if (subtype === "internal#scope") { |
332 // Internally, scope contains object with scope variables and additi onal information like type, | 332 // Internally, scope contains object with scope variables and additi onal information like type, |
333 // we use additional information for preview and would like to repor t variables as scope | 333 // we use additional information for preview and would like to repor t variables as scope |
334 // properties. | 334 // properties. |
335 object = object.object; | 335 object = object.object; |
336 } | 336 } |
337 | 337 |
338 var descriptors = []; | |
339 var iter = this._propertyDescriptors(object, ownProperties, accessorProp ertiesOnly, undefined); | |
340 // Go over properties, wrap object values. | 338 // Go over properties, wrap object values. |
341 for (var descriptor of iter) { | 339 var descriptors = this._propertyDescriptors(object, ownProperties, acces sorPropertiesOnly); |
342 if (subtype === "internal#scopeList" && descriptor.name === "length" ) | 340 for (var i = 0; i < descriptors.length; ++i) { |
343 continue; | 341 var descriptor = descriptors[i]; |
344 if ("get" in descriptor) | 342 if ("get" in descriptor) |
345 descriptor.get = this._wrapObject(descriptor.get, objectGroupNam e); | 343 descriptor.get = this._wrapObject(descriptor.get, objectGroupNam e); |
346 if ("set" in descriptor) | 344 if ("set" in descriptor) |
347 descriptor.set = this._wrapObject(descriptor.set, objectGroupNam e); | 345 descriptor.set = this._wrapObject(descriptor.set, objectGroupNam e); |
348 if ("value" in descriptor) | 346 if ("value" in descriptor) |
349 descriptor.value = this._wrapObject(descriptor.value, objectGrou pName, false, generatePreview); | 347 descriptor.value = this._wrapObject(descriptor.value, objectGrou pName, false, generatePreview); |
350 if (!("configurable" in descriptor)) | 348 if (!("configurable" in descriptor)) |
351 descriptor.configurable = false; | 349 descriptor.configurable = false; |
352 if (!("enumerable" in descriptor)) | 350 if (!("enumerable" in descriptor)) |
353 descriptor.enumerable = false; | 351 descriptor.enumerable = false; |
354 if ("symbol" in descriptor) | 352 if ("symbol" in descriptor) |
355 descriptor.symbol = this._wrapObject(descriptor.symbol, objectGr oupName); | 353 descriptor.symbol = this._wrapObject(descriptor.symbol, objectGr oupName); |
356 push(descriptors, descriptor); | |
357 } | 354 } |
358 return descriptors; | 355 return descriptors; |
359 }, | 356 }, |
360 | 357 |
361 /** | 358 /** |
362 * @param {!Object} object | 359 * @param {!Object} object |
363 * @return {?Object} | 360 * @return {?Object} |
364 */ | 361 */ |
365 _objectPrototype: function(object) | 362 _objectPrototype: function(object) |
366 { | 363 { |
367 if (InjectedScriptHost.subtype(object) === "proxy") | 364 if (InjectedScriptHost.subtype(object) === "proxy") |
368 return null; | 365 return null; |
369 try { | 366 try { |
370 return Object.getPrototypeOf(object); | 367 return Object.getPrototypeOf(object); |
371 } catch (e) { | 368 } catch (e) { |
372 return null; | 369 return null; |
373 } | 370 } |
374 }, | 371 }, |
375 | 372 |
376 /** | 373 /** |
377 * @param {!Object} object | 374 * @param {!Object} object |
378 * @param {boolean=} ownProperties | 375 * @param {boolean=} ownProperties |
379 * @param {boolean=} accessorPropertiesOnly | 376 * @param {boolean=} accessorPropertiesOnly |
380 * @param {?Array.<string>=} propertyNamesOnly | 377 * @param {?Array<string>=} propertyNamesOnly |
378 * @param {!function(!Array<!Object>, !Object)=} addPropertyIfNeeded | |
379 * @return {!Array<!Object>} | |
381 */ | 380 */ |
382 _propertyDescriptors: function*(object, ownProperties, accessorPropertiesOnl y, propertyNamesOnly) | 381 _propertyDescriptors: function(object, ownProperties, accessorPropertiesOnly , propertyNamesOnly, addPropertyIfNeeded) |
383 { | 382 { |
383 var descriptors = []; | |
384 descriptors.__proto__ = null; | |
385 addPropertyIfNeeded = addPropertyIfNeeded || function(descriptors, descr iptor) { push(descriptors, descriptor); return true; }; | |
kozy
2017/03/01 03:16:35
can we always pass this function and defined it ne
luoe
2017/03/01 21:47:18
Done.
| |
384 var propertyProcessed = { __proto__: null }; | 386 var propertyProcessed = { __proto__: null }; |
387 var subtype = InjectedScriptHost.subtype(object); | |
385 | 388 |
386 /** | 389 /** |
387 * @param {?Object} o | 390 * @param {!Object} o |
388 * @param {!Iterable<string|symbol|number>|!Array<string|number|symbol>} properties | 391 * @param {!Array<string|number|symbol>=} properties |
392 * @param {number=} objectLength | |
393 * @return {boolean} | |
389 */ | 394 */ |
390 function* process(o, properties) | 395 function process(o, properties, objectLength) |
391 { | 396 { |
392 for (var property of properties) { | 397 // When properties is not provided, iterate over the object's indice s. |
398 var length = properties ? properties.length : objectLength; | |
399 for (var i = 0; i < length; ++i) { | |
400 var property = properties ? properties[i] : ("" + i); | |
401 if (propertyProcessed[property]) | |
402 continue; | |
403 propertyProcessed[property] = true; | |
393 var name; | 404 var name; |
394 if (isSymbol(property)) | 405 if (isSymbol(property)) |
395 name = /** @type {string} */ (injectedScript._describe(prope rty)); | 406 name = /** @type {string} */ (injectedScript._describe(prope rty)); |
396 else | 407 else |
397 name = typeof property === "number" ? ("" + property) : /** @type {string} */(property); | 408 name = typeof property === "number" ? ("" + property) : /** @type {string} */(property); |
398 | 409 |
399 if (propertyProcessed[property]) | 410 if (subtype === "internal#scopeList" && name === "length") |
400 continue; | 411 continue; |
401 | 412 |
413 var descriptor; | |
402 try { | 414 try { |
403 propertyProcessed[property] = true; | 415 descriptor = Object.getOwnPropertyDescriptor(o, property); |
404 var descriptor = nullifyObjectProto(Object.getOwnPropertyDes criptor(o, property)); | 416 var isAccessorProperty = descriptor && ("get" in descriptor || "set" in descriptor); |
405 if (descriptor) { | 417 if (accessorPropertiesOnly && !isAccessorProperty) |
406 if (accessorPropertiesOnly && !("get" in descriptor || " set" in descriptor)) | |
407 continue; | |
408 if ("get" in descriptor && "set" in descriptor && name ! = "__proto__" && InjectedScriptHost.formatAccessorsAsProperties(object, descript or.get) && !doesAttributeHaveObservableSideEffectOnGet(object, name)) { | |
409 descriptor.value = object[property]; | |
410 descriptor.isOwn = true; | |
411 delete descriptor.get; | |
412 delete descriptor.set; | |
413 } | |
414 } else { | |
415 // Not all bindings provide proper descriptors. Fall bac k to the writable, configurable property. | |
416 if (accessorPropertiesOnly) | |
417 continue; | |
418 try { | |
419 descriptor = { name: name, value: o[property], writa ble: false, configurable: false, enumerable: false, __proto__: null }; | |
420 if (o === object) | |
421 descriptor.isOwn = true; | |
422 yield descriptor; | |
423 } catch (e) { | |
424 // Silent catch. | |
425 } | |
426 continue; | 418 continue; |
419 if (descriptor && "get" in descriptor && "set" in descriptor && name !== "__proto__" && | |
420 InjectedScriptHost.formatAccessorsAsProperties(objec t, descriptor.get) && | |
421 !doesAttributeHaveObservableSideEffectOnGet(object, name)) { | |
422 descriptor.value = object[property]; | |
423 descriptor.isOwn = true; | |
424 delete descriptor.get; | |
425 delete descriptor.set; | |
427 } | 426 } |
428 } catch (e) { | 427 } catch (e) { |
429 if (accessorPropertiesOnly) | 428 if (accessorPropertiesOnly) |
430 continue; | 429 continue; |
431 var descriptor = { __proto__: null }; | 430 descriptor = { value: e, wasThrown: true }; |
432 descriptor.value = e; | 431 } |
433 descriptor.wasThrown = true; | 432 |
433 // Not all bindings provide proper descriptors. Fall back to the non-configurable, non-enumerable, | |
434 // non-writable property. | |
435 if (!descriptor) { | |
436 try { | |
437 descriptor = { value: o[property], writable: false }; | |
438 } catch (e) { | |
439 // Silent catch. | |
440 continue; | |
441 } | |
434 } | 442 } |
435 | 443 |
436 descriptor.name = name; | 444 descriptor.name = name; |
437 if (o === object) | 445 if (o === object) |
438 descriptor.isOwn = true; | 446 descriptor.isOwn = true; |
439 if (isSymbol(property)) | 447 if (isSymbol(property)) |
440 descriptor.symbol = property; | 448 descriptor.symbol = property; |
441 yield descriptor; | 449 descriptor = nullifyObjectProto(descriptor); |
450 if (!addPropertyIfNeeded(descriptors, descriptor)) | |
451 return false; | |
442 } | 452 } |
453 return true; | |
443 } | 454 } |
444 | 455 |
445 if (propertyNamesOnly) { | 456 if (propertyNamesOnly) { |
446 for (var i = 0; i < propertyNamesOnly.length; ++i) { | 457 for (var i = 0; i < propertyNamesOnly.length; ++i) { |
447 var name = propertyNamesOnly[i]; | 458 var name = propertyNamesOnly[i]; |
448 for (var o = object; this._isDefined(o); o = this._objectPrototy pe(o)) { | 459 for (var o = object; this._isDefined(o); o = this._objectPrototy pe(/** @type {!Object} */ (o))) { |
460 o = /** @type {!Object} */ (o); | |
449 if (InjectedScriptHost.objectHasOwnProperty(o, name)) { | 461 if (InjectedScriptHost.objectHasOwnProperty(o, name)) { |
450 for (var descriptor of process(o, [name])) | 462 if (!process(o, [name])) |
451 yield descriptor; | 463 return descriptors; |
452 break; | 464 break; |
453 } | 465 } |
454 if (ownProperties) | 466 if (ownProperties) |
455 break; | 467 break; |
456 } | 468 } |
457 } | 469 } |
458 return; | 470 return descriptors; |
459 } | 471 } |
460 | 472 |
461 /** | 473 for (var o = object; this._isDefined(o); o = this._objectPrototype(/** @ type {!Object} */ (o))) { |
462 * @param {number} length | 474 o = /** @type {!Object} */ (o); |
463 */ | |
464 function* arrayIndexNames(length) | |
465 { | |
466 for (var i = 0; i < length; ++i) | |
467 yield "" + i; | |
468 } | |
469 | |
470 var skipGetOwnPropertyNames; | |
471 try { | |
472 skipGetOwnPropertyNames = InjectedScriptHost.subtype(object) === "ty pedarray" && object.length > 500000; | |
473 } catch (e) { | |
474 } | |
475 | |
476 for (var o = object; this._isDefined(o); o = this._objectPrototype(o)) { | |
477 if (InjectedScriptHost.subtype(o) === "proxy") | 475 if (InjectedScriptHost.subtype(o) === "proxy") |
478 continue; | 476 continue; |
479 if (skipGetOwnPropertyNames && o === object) { | 477 |
480 // Avoid OOM crashes from getting all own property names of a la rge TypedArray. | 478 try { |
481 for (var descriptor of process(o, arrayIndexNames(o.length))) | 479 var objectLength = o.length; |
482 yield descriptor; | 480 var skipGetOwnPropertyNames = subtype === "typedarray" && object Length > 500000; |
483 } else { | 481 if (skipGetOwnPropertyNames && o === object) { |
484 // First call Object.keys() to enforce ordering of the property descriptors. | 482 if (!process(o, undefined, objectLength)) |
485 for (var descriptor of process(o, Object.keys(/** @type {!Object } */ (o)))) | 483 return descriptors; |
486 yield descriptor; | 484 } else { |
487 for (var descriptor of process(o, Object.getOwnPropertyNames(/** @type {!Object} */ (o)))) | 485 // First call Object.keys() to enforce ordering of the prope rty descriptors. |
488 yield descriptor; | 486 if (!process(o, Object.keys(o))) |
487 return descriptors; | |
488 if (!process(o, Object.getOwnPropertyNames(o))) | |
489 return descriptors; | |
490 } | |
491 if (Object.getOwnPropertySymbols) { | |
492 if (!process(o, Object.getOwnPropertySymbols(o))) | |
493 return descriptors; | |
494 } | |
495 if (ownProperties) { | |
496 var proto = this._objectPrototype(o); | |
497 if (proto && !accessorPropertiesOnly) { | |
498 var descriptor = { name: "__proto__", value: proto, writ able: true, configurable: true, enumerable: false, isOwn: true, __proto__: null }; | |
499 if (!addPropertyIfNeeded(descriptors, descriptor)) | |
500 return descriptors; | |
501 } | |
502 } | |
503 } catch (e) { | |
489 } | 504 } |
490 if (Object.getOwnPropertySymbols) { | 505 |
491 for (var descriptor of process(o, Object.getOwnPropertySymbols(/ ** @type {!Object} */ (o)))) | 506 if (ownProperties) |
492 yield descriptor; | |
493 } | |
494 if (ownProperties) { | |
495 var proto = this._objectPrototype(o); | |
496 if (proto && !accessorPropertiesOnly) | |
497 yield { name: "__proto__", value: proto, writable: true, con figurable: true, enumerable: false, isOwn: true, __proto__: null }; | |
498 break; | 507 break; |
499 } | |
500 } | 508 } |
509 return descriptors; | |
501 }, | 510 }, |
502 | 511 |
503 /** | 512 /** |
504 * @param {string|undefined} objectGroupName | 513 * @param {string|undefined} objectGroupName |
505 * @param {*} jsonMLObject | 514 * @param {*} jsonMLObject |
506 * @throws {string} error message | 515 * @throws {string} error message |
507 */ | 516 */ |
508 _substituteObjectTagsInCustomPreview: function(objectGroupName, jsonMLObject ) | 517 _substituteObjectTagsInCustomPreview: function(objectGroupName, jsonMLObject ) |
509 { | 518 { |
510 var maxCustomPreviewRecursionDepth = 20; | 519 var maxCustomPreviewRecursionDepth = 20; |
(...skipping 345 matching lines...) Loading... | |
856 * @param {?Array.<string>=} firstLevelKeys | 865 * @param {?Array.<string>=} firstLevelKeys |
857 * @param {?Array.<string>=} secondLevelKeys | 866 * @param {?Array.<string>=} secondLevelKeys |
858 * @param {boolean=} isTable | 867 * @param {boolean=} isTable |
859 * @param {boolean=} skipEntriesPreview | 868 * @param {boolean=} skipEntriesPreview |
860 * @return {!RuntimeAgent.ObjectPreview} preview | 869 * @return {!RuntimeAgent.ObjectPreview} preview |
861 */ | 870 */ |
862 _generatePreview: function(object, firstLevelKeys, secondLevelKeys, isTable, skipEntriesPreview) | 871 _generatePreview: function(object, firstLevelKeys, secondLevelKeys, isTable, skipEntriesPreview) |
863 { | 872 { |
864 var preview = this._createEmptyPreview(); | 873 var preview = this._createEmptyPreview(); |
865 var firstLevelKeysCount = firstLevelKeys ? firstLevelKeys.length : 0; | 874 var firstLevelKeysCount = firstLevelKeys ? firstLevelKeys.length : 0; |
866 | |
867 var propertiesThreshold = { | 875 var propertiesThreshold = { |
868 properties: isTable ? 1000 : max(5, firstLevelKeysCount), | 876 properties: isTable ? 1000 : max(5, firstLevelKeysCount), |
869 indexes: isTable ? 1000 : max(100, firstLevelKeysCount), | 877 indexes: isTable ? 1000 : max(100, firstLevelKeysCount), |
870 __proto__: null | 878 __proto__: null |
871 }; | 879 }; |
880 var subtype = this.subtype; | |
872 | 881 |
873 try { | 882 try { |
874 var descriptors = injectedScript._propertyDescriptors(object, undefi ned, undefined, firstLevelKeys); | 883 var descriptors = injectedScript._propertyDescriptors(object, true, undefined /* accessorPropertiesOnly */, firstLevelKeys, addPropertyIfNeeded); |
875 | |
876 this._appendPropertyDescriptors(preview, descriptors, propertiesThre shold, secondLevelKeys, isTable); | |
877 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0) | |
878 return preview; | |
879 | 884 |
880 // Add internal properties to preview. | 885 // Add internal properties to preview. |
881 var rawInternalProperties = InjectedScriptHost.getInternalProperties (object) || []; | 886 var rawInternalProperties = InjectedScriptHost.getInternalProperties (object) || []; |
882 var internalProperties = []; | 887 var internalProperties = []; |
883 var entries = null; | 888 var entries = null; |
884 for (var i = 0; i < rawInternalProperties.length; i += 2) { | 889 for (var i = 0; i < rawInternalProperties.length; i += 2) { |
885 if (rawInternalProperties[i] === "[[Entries]]") { | 890 if (rawInternalProperties[i] === "[[Entries]]") { |
886 entries = /** @type {!Array<*>} */(rawInternalProperties[i + 1]); | 891 entries = /** @type {!Array<*>} */(rawInternalProperties[i + 1]); |
887 continue; | 892 continue; |
888 } | 893 } |
889 push(internalProperties, { | 894 var internalPropertyDescriptor = { |
890 name: rawInternalProperties[i], | 895 name: rawInternalProperties[i], |
891 value: rawInternalProperties[i + 1], | 896 value: rawInternalProperties[i + 1], |
892 isOwn: true, | 897 isOwn: true, |
893 enumerable: true, | 898 enumerable: true, |
894 __proto__: null | 899 __proto__: null |
895 }); | 900 }; |
901 if (!addPropertyIfNeeded(descriptors, internalPropertyDescriptor )) | |
902 break; | |
896 } | 903 } |
897 this._appendPropertyDescriptors(preview, internalProperties, propert iesThreshold, secondLevelKeys, isTable); | 904 this._appendPropertyPreviewDescriptors(preview, descriptors, secondL evelKeys, isTable); |
898 | 905 |
899 if (this.subtype === "map" || this.subtype === "set" || this.subtype === "iterator") | 906 if (subtype === "map" || subtype === "set" || subtype === "iterator" ) |
900 this._appendEntriesPreview(entries, preview, skipEntriesPreview) ; | 907 this._appendEntriesPreview(entries, preview, skipEntriesPreview) ; |
901 | 908 |
902 } catch (e) {} | 909 } catch (e) {} |
903 | 910 |
904 return preview; | 911 return preview; |
912 | |
913 /** | |
914 * @param {!Array<!Object>} descriptors | |
915 * @param {!Object} descriptor | |
916 * @return {boolean} | |
917 */ | |
918 function addPropertyIfNeeded(descriptors, descriptor) { | |
919 if (descriptor.wasThrown) | |
920 return true; | |
921 | |
922 // Ignore __proto__ property. | |
923 if (descriptor.name === "__proto__") | |
924 return true; | |
925 | |
926 // Ignore length property of array. | |
927 if ((subtype === "array" || subtype === "typedarray") && descriptor. name === "length") | |
928 return true; | |
929 | |
930 // Ignore size property of map, set. | |
931 if ((subtype === "map" || subtype === "set") && descriptor.name === "size") | |
932 return true; | |
933 | |
934 // Never preview prototype properties. | |
935 if (!descriptor.isOwn) | |
936 return true; | |
937 | |
938 // Ignore computed properties unless they have getters. | |
939 if (!("value" in descriptor) && !descriptor.get) | |
940 return true; | |
941 | |
942 if (toString(descriptor.name >>> 0) === descriptor.name) | |
943 propertiesThreshold.indexes--; | |
944 else | |
945 propertiesThreshold.properties--; | |
946 | |
947 var canContinue = propertiesThreshold.indexes >= 0 && propertiesThre shold.properties >= 0; | |
948 if (!canContinue) { | |
949 preview.overflow = true; | |
950 return false; | |
951 } | |
952 push(descriptors, descriptor); | |
953 return true; | |
954 } | |
905 }, | 955 }, |
906 | 956 |
907 /** | 957 /** |
908 * @param {!RuntimeAgent.ObjectPreview} preview | 958 * @param {!RuntimeAgent.ObjectPreview} preview |
909 * @param {!Array.<*>|!Iterable.<*>} descriptors | 959 * @param {!Array.<*>|!Iterable.<*>} descriptors |
910 * @param {!Object} propertiesThreshold | |
911 * @param {?Array.<string>=} secondLevelKeys | 960 * @param {?Array.<string>=} secondLevelKeys |
912 * @param {boolean=} isTable | 961 * @param {boolean=} isTable |
913 */ | 962 */ |
914 _appendPropertyDescriptors: function(preview, descriptors, propertiesThresho ld, secondLevelKeys, isTable) | 963 _appendPropertyPreviewDescriptors: function(preview, descriptors, secondLeve lKeys, isTable) |
915 { | 964 { |
916 for (var descriptor of descriptors) { | 965 for (var i = 0; i < descriptors.length; ++i) { |
917 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0) | 966 var descriptor = descriptors[i]; |
918 break; | |
919 if (!descriptor || descriptor.wasThrown) | |
920 continue; | |
921 | |
922 var name = descriptor.name; | 967 var name = descriptor.name; |
923 | |
924 // Ignore __proto__ property. | |
925 if (name === "__proto__") | |
926 continue; | |
927 | |
928 // Ignore length property of array. | |
929 if ((this.subtype === "array" || this.subtype === "typedarray") && n ame === "length") | |
930 continue; | |
931 | |
932 // Ignore size property of map, set. | |
933 if ((this.subtype === "map" || this.subtype === "set") && name === " size") | |
934 continue; | |
935 | |
936 // Never preview prototype properties. | |
937 if (!descriptor.isOwn) | |
938 continue; | |
939 | |
940 // Ignore computed properties unless they have getters. | |
941 if (!("value" in descriptor)) { | |
942 if (descriptor.get) | |
943 this._appendPropertyPreview(preview, { name: name, type: "ac cessor", __proto__: null }, propertiesThreshold); | |
944 continue; | |
945 } | |
946 | |
947 var value = descriptor.value; | 968 var value = descriptor.value; |
948 var type = typeof value; | 969 var type = typeof value; |
949 | 970 |
950 // Special-case HTMLAll. | 971 // Special-case HTMLAll. |
951 if (type === "undefined" && injectedScript._isHTMLAllCollection(valu e)) | 972 if (type === "undefined" && injectedScript._isHTMLAllCollection(valu e)) |
952 type = "object"; | 973 type = "object"; |
953 | 974 |
954 // Render own properties. | 975 // Ignore computed properties unless they have getters. |
955 if (value === null) { | 976 if (descriptor.get && !("value" in descriptor)) { |
956 this._appendPropertyPreview(preview, { name: name, type: "object ", subtype: "null", value: "null", __proto__: null }, propertiesThreshold); | 977 push(preview.properties, { name: name, type: "accessor", __proto __: null }); |
957 continue; | 978 continue; |
958 } | 979 } |
959 | 980 |
981 // Render own properties. | |
982 if (value === null) { | |
983 push(preview.properties, { name: name, type: "object", subtype: "null", value: "null", __proto__: null }); | |
984 continue; | |
985 } | |
986 | |
960 var maxLength = 100; | 987 var maxLength = 100; |
961 if (InjectedScript.primitiveTypes[type]) { | 988 if (InjectedScript.primitiveTypes[type]) { |
962 if (type === "string" && value.length > maxLength) | 989 if (type === "string" && value.length > maxLength) |
963 value = this._abbreviateString(value, maxLength, true); | 990 value = this._abbreviateString(value, maxLength, true); |
964 this._appendPropertyPreview(preview, { name: name, type: type, v alue: toStringDescription(value), __proto__: null }, propertiesThreshold); | 991 push(preview.properties, { name: name, type: type, value: toStri ngDescription(value), __proto__: null }); |
965 continue; | 992 continue; |
966 } | 993 } |
967 | 994 |
968 var property = { name: name, type: type, __proto__: null }; | 995 var property = { name: name, type: type, __proto__: null }; |
969 var subtype = injectedScript._subtype(value); | 996 var subtype = injectedScript._subtype(value); |
970 if (subtype) | 997 if (subtype) |
971 property.subtype = subtype; | 998 property.subtype = subtype; |
972 | 999 |
973 if (secondLevelKeys === null || secondLevelKeys) { | 1000 if (secondLevelKeys === null || secondLevelKeys) { |
974 var subPreview = this._generatePreview(value, secondLevelKeys || undefined, undefined, isTable); | 1001 var subPreview = this._generatePreview(value, secondLevelKeys || undefined, undefined, isTable); |
975 property.valuePreview = subPreview; | 1002 property.valuePreview = subPreview; |
976 if (subPreview.overflow) | 1003 if (subPreview.overflow) |
977 preview.overflow = true; | 1004 preview.overflow = true; |
978 } else { | 1005 } else { |
979 var description = ""; | 1006 var description = ""; |
980 if (type !== "function") | 1007 if (type !== "function") |
981 description = this._abbreviateString(/** @type {string} */ ( injectedScript._describe(value)), maxLength, subtype === "regexp"); | 1008 description = this._abbreviateString(/** @type {string} */ ( injectedScript._describe(value)), maxLength, subtype === "regexp"); |
982 property.value = description; | 1009 property.value = description; |
983 } | 1010 } |
984 this._appendPropertyPreview(preview, property, propertiesThreshold); | |
985 } | |
986 }, | |
987 | |
988 /** | |
989 * @param {!RuntimeAgent.ObjectPreview} preview | |
990 * @param {!Object} property | |
991 * @param {!Object} propertiesThreshold | |
992 */ | |
993 _appendPropertyPreview: function(preview, property, propertiesThreshold) | |
994 { | |
995 if (toString(property.name >>> 0) === property.name) | |
996 propertiesThreshold.indexes--; | |
997 else | |
998 propertiesThreshold.properties--; | |
999 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0) { | |
1000 preview.overflow = true; | |
1001 } else { | |
1002 push(preview.properties, property); | 1011 push(preview.properties, property); |
1003 } | 1012 } |
1004 }, | 1013 }, |
1005 | 1014 |
1006 /** | 1015 /** |
1007 * @param {?Array<*>} entries | 1016 * @param {?Array<*>} entries |
1008 * @param {!RuntimeAgent.ObjectPreview} preview | 1017 * @param {!RuntimeAgent.ObjectPreview} preview |
1009 * @param {boolean=} skipEntriesPreview | 1018 * @param {boolean=} skipEntriesPreview |
1010 */ | 1019 */ |
1011 _appendEntriesPreview: function(entries, preview, skipEntriesPreview) | 1020 _appendEntriesPreview: function(entries, preview, skipEntriesPreview) |
(...skipping 50 matching lines...) Loading... | |
1062 return string.substr(0, leftHalf) + "\u2026" + string.substr(string. length - rightHalf, rightHalf); | 1071 return string.substr(0, leftHalf) + "\u2026" + string.substr(string. length - rightHalf, rightHalf); |
1063 } | 1072 } |
1064 return string.substr(0, maxLength) + "\u2026"; | 1073 return string.substr(0, maxLength) + "\u2026"; |
1065 }, | 1074 }, |
1066 | 1075 |
1067 __proto__: null | 1076 __proto__: null |
1068 } | 1077 } |
1069 | 1078 |
1070 return injectedScript; | 1079 return injectedScript; |
1071 }) | 1080 }) |
OLD | NEW |