From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../components/flight/tools/debug/debug.js | 157 +++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/flight/tools/debug/debug.js (limited to 'third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/flight/tools/debug') diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/flight/tools/debug/debug.js b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/flight/tools/debug/debug.js new file mode 100644 index 0000000000..b2e4fdfeff --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/flight/tools/debug/debug.js @@ -0,0 +1,157 @@ +"use strict"; + +define( + + [ + '../../lib/registry', + '../../lib/utils' + ], + + function(registry, utils) { + + var logFilter; + + //****************************************************************************************** + // Search object model + //****************************************************************************************** + + function traverse(util, searchTerm, options) { + var options = options || {}; + var obj = options.obj || window; + var path = options.path || ((obj==window) ? "window" : ""); + var props = Object.keys(obj); + props.forEach(function(prop) { + if ((tests[util] || util)(searchTerm, obj, prop)){ + console.log([path, ".", prop].join(""), "->",["(", typeof obj[prop], ")"].join(""), obj[prop]); + } + if(Object.prototype.toString.call(obj[prop])=="[object Object]" && (obj[prop] != obj) && path.split(".").indexOf(prop) == -1) { + traverse(util, searchTerm, {obj: obj[prop], path: [path,prop].join(".")}); + } + }); + } + + function search(util, expected, searchTerm, options) { + if (!expected || typeof searchTerm == expected) { + traverse(util, searchTerm, options); + } else { + console.error([searchTerm, 'must be', expected].join(' ')) + } + } + + var tests = { + 'name': function(searchTerm, obj, prop) {return searchTerm == prop}, + 'nameContains': function(searchTerm, obj, prop) {return prop.indexOf(searchTerm)>-1}, + 'type': function(searchTerm, obj, prop) {return obj[prop] instanceof searchTerm}, + 'value': function(searchTerm, obj, prop) {return obj[prop] === searchTerm}, + 'valueCoerced': function(searchTerm, obj, prop) {return obj[prop] == searchTerm} + } + + function byName(searchTerm, options) {search('name', 'string', searchTerm, options);}; + function byNameContains(searchTerm, options) {search('nameContains', 'string', searchTerm, options);}; + function byType(searchTerm, options) {search('type', 'function', searchTerm, options);}; + function byValue(searchTerm, options) {search('value', null, searchTerm, options);}; + function byValueCoerced(searchTerm, options) {search('valueCoerced', null, searchTerm, options);}; + function custom(fn, options) {traverse(fn, null, options);}; + + //****************************************************************************************** + // Event logging + //****************************************************************************************** + + var ALL = 'all'; //no filter + + //no logging by default + var defaultEventNamesFilter = []; + var defaultActionsFilter = []; + + var logFilter = retrieveLogFilter(); + + function filterEventLogsByAction(/*actions*/) { + var actions = [].slice.call(arguments); + + logFilter.eventNames.length || (logFilter.eventNames = ALL); + logFilter.actions = actions.length ? actions : ALL; + saveLogFilter(); + } + + function filterEventLogsByName(/*eventNames*/) { + var eventNames = [].slice.call(arguments); + + logFilter.actions.length || (logFilter.actions = ALL); + logFilter.eventNames = eventNames.length ? eventNames : ALL; + saveLogFilter(); + } + + function hideAllEventLogs() { + logFilter.actions = []; + logFilter.eventNames = []; + saveLogFilter(); + } + + function showAllEventLogs() { + logFilter.actions = ALL; + logFilter.eventNames = ALL; + saveLogFilter(); + } + + function saveLogFilter() { + if (window.localStorage) { + localStorage.setItem('logFilter_eventNames', logFilter.eventNames); + localStorage.setItem('logFilter_actions', logFilter.actions); + } + } + + function retrieveLogFilter() { + var result = { + eventNames: (window.localStorage && localStorage.getItem('logFilter_eventNames')) || defaultEventNamesFilter, + actions: (window.localStorage && localStorage.getItem('logFilter_actions')) || defaultActionsFilter + }; + //reconstitute arrays + Object.keys(result).forEach(function(k) { + var thisProp = result[k]; + if (typeof thisProp == 'string' && thisProp !== ALL) { + result[k] = thisProp.split(','); + } + }); + return result; + } + + return { + + enable: function(enable) { + this.enabled = !!enable; + + if (enable && window.console) { + console.info('Booting in DEBUG mode'); + console.info('You can configure event logging with DEBUG.events.logAll()/logNone()/logByName()/logByAction()'); + } + + window.DEBUG = this; + }, + + find: { + byName: byName, + byNameContains: byNameContains, + byType: byType, + byValue: byValue, + byValueCoerced: byValueCoerced, + custom: custom + }, + + events: { + logFilter: logFilter, + + // Accepts any number of action args + // e.g. DEBUG.events.logByAction("on", "off") + logByAction: filterEventLogsByAction, + + // Accepts any number of event name args (inc. regex or wildcards) + // e.g. DEBUG.events.logByName(/ui.*/, "*Thread*"); + logByName: filterEventLogsByName, + + logAll: showAllEventLogs, + logNone: hideAllEventLogs + } + }; + } +); + -- cgit v1.2.3