From c7c19c86a735f99b5051e11d6b63fe70c31468f7 Mon Sep 17 00:00:00 2001 From: luoe Date: Wed, 7 Dec 2016 14:33:56 -0800 Subject: [PATCH] Show functions in object previews Due to the isOwn check, functions inherited through prototype will not be included in a preview. BUG=645053 Review-Url: https://codereview.chromium.org/2554623003 Cr-Commit-Position: refs/heads/master@{#41566} --- src/inspector/injected-script-source.js | 4 -- ...valuate-with-generate-preview-expected.txt | 55 +++++++++++++++++-- .../runtime/evaluate-with-generate-preview.js | 38 ++++++++++--- 3 files changed, 80 insertions(+), 17 deletions(-) diff --git a/src/inspector/injected-script-source.js b/src/inspector/injected-script-source.js index 044eb736c0..84e7262213 100644 --- a/src/inspector/injected-script-source.js +++ b/src/inspector/injected-script-source.js @@ -946,10 +946,6 @@ InjectedScript.RemoteObject.prototype = { var value = descriptor.value; var type = typeof value; - // Never render functions in object preview. - if (type === "function" && (this.subtype !== "array" || !isUInt32(name))) - continue; - // Special-case HTMLAll. if (type === "undefined" && injectedScript._isHTMLAllCollection(value)) type = "object"; diff --git a/test/inspector/runtime/evaluate-with-generate-preview-expected.txt b/test/inspector/runtime/evaluate-with-generate-preview-expected.txt index bef284bf39..c0d686efce 100644 --- a/test/inspector/runtime/evaluate-with-generate-preview-expected.txt +++ b/test/inspector/runtime/evaluate-with-generate-preview-expected.txt @@ -17,10 +17,15 @@ Running test: testObjectPropertiesPreview } [2] : { name : p3 - type : accessor + type : function + value : } [3] : { - name : p5 + name : p4 + type : accessor + } + [4] : { + name : p6 type : accessor } ] @@ -29,7 +34,7 @@ Running test: testObjectPropertiesPreview Running test: testArrayPropertiesPreview { - description : Array(7) + description : Array(8) overflow : false properties : [ [0] : { @@ -45,13 +50,53 @@ Running test: testArrayPropertiesPreview } [2] : { name : 4 - type : accessor + type : function + value : } [3] : { - name : 6 + name : nonEntryFunction + type : function + value : + } + [4] : { + name : 5 + type : accessor + } + [5] : { + name : 7 type : accessor } ] subtype : array type : object } + +Running test: testInheritingObjectPropertiesPreview +{ + description : Object + overflow : false + properties : [ + [0] : { + name : prototype + type : object + value : Object + } + ] + type : object +} + +Running test: testInheritingArrayPropertiesPreview +{ + description : Array(0) + overflow : false + properties : [ + [0] : { + name : prototype + subtype : array + type : object + value : Array(8) + } + ] + subtype : array + type : object +} diff --git a/test/inspector/runtime/evaluate-with-generate-preview.js b/test/inspector/runtime/evaluate-with-generate-preview.js index 5e747d5ab9..5e8f34a283 100644 --- a/test/inspector/runtime/evaluate-with-generate-preview.js +++ b/test/inspector/runtime/evaluate-with-generate-preview.js @@ -6,35 +6,43 @@ print("Tests that Runtime.evaluate will generate correct previews."); InspectorTest.addScript( ` +var f1 = function(){}; + Object.prototype[0] = 'default-first'; -var obj = {p1: {a:1}, p2: {b:'foo'}}; +var obj = {p1: {a:1}, p2: {b:'foo'}, p3: f1}; Object.defineProperties(obj, { - p3: { + p4: { get() { return 2 } }, - p4: { + p5: { set(x) { return x } }, - p5: { + p6: { get() { return 2 }, set(x) { return x } } }); Array.prototype[0] = 'default-first'; -var arr = [,, 1, [2]]; +var arr = [,, 1, [2], f1]; Object.defineProperties(arr, { - 4: { + 5: { get() { return 2 } }, - 5: { + 6: { set(x) { return x } }, - 6: { + 7: { get() { return 2 }, set(x) { return x } } }); +arr.nonEntryFunction = f1; + +var inheritingObj = {}; +var inheritingArr = []; +inheritingObj.prototype = obj; +inheritingArr.prototype = arr; `); InspectorTest.runTestSuite([ @@ -50,5 +58,19 @@ InspectorTest.runTestSuite([ Protocol.Runtime.evaluate({ "expression": "arr", "generatePreview": true }) .then(result => InspectorTest.logMessage(result.result.result.preview)) .then(next); + }, + + function testInheritingObjectPropertiesPreview(next) + { + Protocol.Runtime.evaluate({ "expression": "inheritingObj", "generatePreview": true }) + .then(result => InspectorTest.logMessage(result.result.result.preview)) + .then(next); + }, + + function testInheritingArrayPropertiesPreview(next) + { + Protocol.Runtime.evaluate({ "expression": "inheritingArr", "generatePreview": true }) + .then(result => InspectorTest.logMessage(result.result.result.preview)) + .then(next); } ]);