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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 { | 80 { |
| 81 return func.apply(thisObject, args.concat(slice(arguments))); | 81 return func.apply(thisObject, args.concat(slice(arguments))); |
| 82 } | 82 } |
| 83 bound.toString = function() { | 83 bound.toString = function() { |
| 84 return "bound: " + func; | 84 return "bound: " + func; |
| 85 }; | 85 }; |
| 86 return bound; | 86 return bound; |
| 87 } | 87 } |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * @param {number} x | |
| 91 * @return {boolean} | |
| 92 */ | |
| 93 function isNegativeZero(x) | |
| 94 { | |
| 95 return x === 0 && 1 / x < 0; | |
| 96 } | |
| 97 | |
| 98 /** | |
| 90 * @constructor | 99 * @constructor |
| 91 */ | 100 */ |
| 92 var InjectedScript = function() | 101 var InjectedScript = function() |
| 93 { | 102 { |
| 94 /** @type {number} */ | 103 /** @type {number} */ |
| 95 this._lastBoundObjectId = 1; | 104 this._lastBoundObjectId = 1; |
| 96 /** @type {!Object.<number, Object>} */ | 105 /** @type {!Object.<number, Object>} */ |
| 97 this._idToWrappedObject = {}; | 106 this._idToWrappedObject = {}; |
| 98 /** @type {!Object.<number, string>} */ | 107 /** @type {!Object.<number, string>} */ |
| 99 this._idToObjectGroupName = {}; | 108 this._idToObjectGroupName = {}; |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 923 if (injectedScript.isPrimitiveValue(object) || object === null || forceValue Type) { | 932 if (injectedScript.isPrimitiveValue(object) || object === null || forceValue Type) { |
| 924 // We don't send undefined values over JSON. | 933 // We don't send undefined values over JSON. |
| 925 if (this.type !== "undefined") | 934 if (this.type !== "undefined") |
| 926 this.value = object; | 935 this.value = object; |
| 927 | 936 |
| 928 // Null object is object with 'null' subtype. | 937 // Null object is object with 'null' subtype. |
| 929 if (object === null) | 938 if (object === null) |
| 930 this.subtype = "null"; | 939 this.subtype = "null"; |
| 931 | 940 |
| 932 // Provide user-friendly number values. | 941 // Provide user-friendly number values. |
| 933 if (this.type === "number") | 942 if (this.type === "number") { |
| 934 this.description = toString(object); | 943 if (isNegativeZero(/** @type {number} */ (object))) |
| 944 this.description = "-0"; | |
| 945 else | |
| 946 this.description = toString(object); | |
| 947 } | |
| 935 return; | 948 return; |
| 936 } | 949 } |
| 937 | 950 |
| 938 object = /** @type {Object} */ (object); | 951 object = /** @type {Object} */ (object); |
| 939 | 952 |
| 940 this.objectId = injectedScript._bind(object, objectGroupName); | 953 this.objectId = injectedScript._bind(object, objectGroupName); |
| 941 var subtype = injectedScript._subtype(object); | 954 var subtype = injectedScript._subtype(object); |
| 942 if (subtype) | 955 if (subtype) |
| 943 this.subtype = subtype; | 956 this.subtype = subtype; |
| 944 this.className = InjectedScriptHost.internalConstructorName(object); | 957 this.className = InjectedScriptHost.internalConstructorName(object); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 const maxLength = 100; | 1035 const maxLength = 100; |
| 1023 var type = typeof value; | 1036 var type = typeof value; |
| 1024 if (!descriptor.enumerable && type === "function") | 1037 if (!descriptor.enumerable && type === "function") |
| 1025 continue; | 1038 continue; |
| 1026 | 1039 |
| 1027 if (InjectedScript.primitiveTypes[type]) { | 1040 if (InjectedScript.primitiveTypes[type]) { |
| 1028 if (type === "string" && value.length > maxLength) { | 1041 if (type === "string" && value.length > maxLength) { |
| 1029 value = this._abbreviateString(value, maxLength, true); | 1042 value = this._abbreviateString(value, maxLength, true); |
| 1030 preview.lossless = false; | 1043 preview.lossless = false; |
| 1031 } | 1044 } |
| 1032 this._appendPropertyPreview(preview, { name: name, type: typ e, value: toString(value) }, propertiesThreshold); | 1045 var description = (type === "number" && isNegativeZero(value )) ? "-0" : toString(value); |
|
yurys
2013/11/22 18:00:09
The code for the number serialization repeats twic
| |
| 1046 this._appendPropertyPreview(preview, { name: name, type: typ e, value: description }, propertiesThreshold); | |
| 1033 continue; | 1047 continue; |
| 1034 } | 1048 } |
| 1035 | 1049 |
| 1036 if (secondLevelKeys === null || secondLevelKeys) { | 1050 if (secondLevelKeys === null || secondLevelKeys) { |
| 1037 var subPreview = this._generatePreview(value, secondLevelKey s || undefined, undefined, false, isTable); | 1051 var subPreview = this._generatePreview(value, secondLevelKey s || undefined, undefined, false, isTable); |
| 1038 var property = { name: name, type: type, valuePreview: subPr eview }; | 1052 var property = { name: name, type: type, valuePreview: subPr eview }; |
| 1039 this._appendPropertyPreview(preview, property, propertiesThr eshold); | 1053 this._appendPropertyPreview(preview, property, propertiesThr eshold); |
| 1040 if (!subPreview.lossless) | 1054 if (!subPreview.lossless) |
| 1041 preview.lossless = false; | 1055 preview.lossless = false; |
| 1042 if (subPreview.overflow) | 1056 if (subPreview.overflow) |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1470 */ | 1484 */ |
| 1471 _logEvent: function(event) | 1485 _logEvent: function(event) |
| 1472 { | 1486 { |
| 1473 inspectedWindow.console.log(event.type, event); | 1487 inspectedWindow.console.log(event.type, event); |
| 1474 } | 1488 } |
| 1475 } | 1489 } |
| 1476 | 1490 |
| 1477 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1491 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
| 1478 return injectedScript; | 1492 return injectedScript; |
| 1479 }) | 1493 }) |
| OLD | NEW |