From ecf4502bfc2d23c2ddc758af91e30a0b2480ff89 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Wed, 10 Feb 2021 08:48:54 +0000 Subject: [PATCH] Extend dumpInspectorHighlightJSON to accept a replacer for JSON.stringify Based on the discussion in https://chromium-review.googlesource.com/c/chromium/src/+/2683860/2/third_party/blink/web_tests/http/tests/devtools/elements/highlight/highlight-css-flex-item.js#28 Bug: 1173995 Change-Id: I0365be80158b7b4a1b4d39244f0bbc9d8ad15317 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2687055 Reviewed-by: Mathias Bynens Reviewed-by: Patrick Brosset Commit-Queue: Alex Rudenko --- .../elements_test_runner/ElementsTestRunner.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/front_end/elements_test_runner/ElementsTestRunner.js b/front_end/elements_test_runner/ElementsTestRunner.js index 566ac0d2fe..e13fd7ccd5 100644 --- a/front_end/elements_test_runner/ElementsTestRunner.js +++ b/front_end/elements_test_runner/ElementsTestRunner.js @@ -1213,12 +1213,24 @@ function onBlankSection(selector, callback) { ElementsTestRunner.waitForSelectorCommitted(callback.bind(null, section)); } -ElementsTestRunner.dumpInspectorHighlightJSON = function(idValue, callback) { +/** + * The function accepts 2 or 3 arguments. Callback is the last one and the second argument is optional. + * + * To dump all highlight properties: dumpInspectorHighlightJSON(idValue, callback). + * To pick which properties to dump: dumpInspectorHighlightJSON(idValue, ['prop'], callback). + * + * @param {string} idValue + * @param {!Function|!Array} replacerOrCallback + * @param {?Function=} maybeCallback + */ +ElementsTestRunner.dumpInspectorHighlightJSON = function(idValue, replacerOrCallback, maybeCallback) { + const callback = arguments.length === 3 ? maybeCallback : replacerOrCallback; + const replacer = arguments.length === 3 ? replacerOrCallback : null; ElementsTestRunner.nodeWithId(idValue, nodeResolved); async function nodeResolved(node) { const result = await TestRunner.OverlayAgent.getHighlightObjectForTest(node.id); - TestRunner.addResult(idValue + JSON.stringify(result, null, 2)); + TestRunner.addResult(idValue + JSON.stringify(result, replacer, 2)); callback(); } };