stdout.js (7643B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 // The functions in the class use standard functions called from tracer.js but we want to keep the 8 // arguments intact. 9 /* eslint "no-unused-vars": ["error", {args: "none"} ]*/ 10 11 class StdoutTracingListener { 12 constructor({ targetActor, traceValues, traceActor }) { 13 this.targetActor = targetActor; 14 this.traceValues = traceValues; 15 this.sourcesManager = targetActor.sourcesManager; 16 this.traceActor = traceActor; 17 } 18 19 /** 20 * Called when the tracer stops recording JS executions. 21 */ 22 stop() { 23 // The stdout output is simple enough to not need to do any cleanup. 24 } 25 26 /** 27 * Be notified by the underlying JavaScriptTracer class 28 * in case it stops by itself, instead of being stopped when the Actor's stopTracing 29 * method is called by the user. 30 * 31 * @param {boolean} enabled 32 * True if the tracer starts tracing, false it it stops. 33 * @return {boolean} 34 * Return true, if the JavaScriptTracer should log a message to stdout. 35 */ 36 onTracingToggled(enabled) { 37 if (!enabled) { 38 this.traceActor.stopTracing(); 39 } 40 // Delegate to JavaScriptTracer to log to stdout 41 return true; 42 } 43 44 /** 45 * Called when "trace on next user interaction" is enabled, to notify the user 46 * that the tracer is initialized but waiting for the user first input. 47 */ 48 onTracingPending() { 49 // Delegate to JavaScriptTracer to log to stdout 50 return true; 51 } 52 53 /** 54 * Called by JavaScriptTracer class when a new mutation happened on any DOM Element. 55 * 56 * @param {object} options 57 * @param {number} options.depth 58 * Represents the depth of the frame in the call stack. 59 * @param {string} options.prefix 60 * A string to be displayed as a prefix of any logged frame. 61 * @param {nsIStackFrame} options.caller 62 * The JS Callsite which caused this mutation. 63 * @param {string} options.type 64 * Type of DOM Mutation: 65 * - "add": Node being added, 66 * - "attributes": Node whose attributes changed, 67 * - "remove": Node being removed, 68 * @param {DOMNode} options.element 69 * The DOM Node related to the current mutation. 70 * @return {boolean} 71 * Return true, if the JavaScriptTracer should log a message to stdout. 72 */ 73 onTracingDOMMutation({ depth, prefix, type, caller, element }) { 74 // Delegate to JavaScriptTracer to log to stdout 75 return true; 76 } 77 78 /** 79 * Called by JavaScriptTracer class on each step of a function call. 80 * 81 * @param {object} options 82 * @param {Debugger.Frame} options.frame 83 * A descriptor object for the JavaScript frame. 84 * @param {number} options.depth 85 * Represents the depth of the frame in the call stack. 86 * @param {string} options.prefix 87 * A string to be displayed as a prefix of any logged frame. 88 * @return {boolean} 89 * Return true, if the JavaScriptTracer should log the step to stdout. 90 */ 91 onTracingFrameStep({ frame, depth, prefix }) { 92 const { script } = frame; 93 const { lineNumber, columnNumber } = script.getOffsetMetadata(frame.offset); 94 const url = script.source.url; 95 96 // NOTE: Debugger.Script.prototype.getOffsetMetadata returns 97 // columnNumber in 1-based. 98 // Convert to 0-based, while keeping the wasm's column (1) as is. 99 // (bug 1863878) 100 const columnBase = script.format === "wasm" ? 0 : 1; 101 const column = columnNumber - columnBase; 102 103 // Ignore blackboxed sources 104 if (this.sourcesManager.isBlackBoxed(url, lineNumber, column)) { 105 return false; 106 } 107 108 // By returning true, we let JavaScriptTracer class log the message to stdout. 109 return true; 110 } 111 112 /** 113 * Called by JavaScriptTracer class when a new JavaScript frame is executed. 114 * 115 * @param {Debugger.Frame} frame 116 * A descriptor object for the JavaScript frame. 117 * @param {number} depth 118 * Represents the depth of the frame in the call stack. 119 * @param {string} formatedDisplayName 120 * A human readable name for the current frame. 121 * @param {string} prefix 122 * A string to be displayed as a prefix of any logged frame. 123 * @param {string} currentDOMEvent 124 * If this is a top level frame (depth==0), and we are currently processing 125 * a DOM Event, this will refer to the name of that DOM Event. 126 * Note that it may also refer to setTimeout and setTimeout callback calls. 127 * @return {boolean} 128 * Return true, if the JavaScriptTracer should log the frame to stdout. 129 */ 130 onTracingFrame({ 131 frame, 132 depth, 133 formatedDisplayName, 134 prefix, 135 currentDOMEvent, 136 }) { 137 const { script } = frame; 138 const { lineNumber, columnNumber } = script.getOffsetMetadata(frame.offset); 139 const url = script.source.url; 140 141 // NOTE: Debugger.Script.prototype.getOffsetMetadata returns 142 // columnNumber in 1-based. 143 // Convert to 0-based, while keeping the wasm's column (1) as is. 144 // (bug 1863878) 145 const columnBase = script.format === "wasm" ? 0 : 1; 146 const column = columnNumber - columnBase; 147 148 // Ignore blackboxed sources 149 if (this.sourcesManager.isBlackBoxed(url, lineNumber, column)) { 150 return false; 151 } 152 153 // By returning true, we let JavaScriptTracer class log the message to stdout. 154 return true; 155 } 156 157 /** 158 * Called by JavaScriptTracer class when a JavaScript frame exits (i.e. a function returns or throw). 159 * 160 * @param {object} options 161 * @param {number} options.frameId 162 * Unique identifier for the current frame. 163 * This should match a frame notified via onTracingFrame. 164 * @param {Debugger.Frame} options.frame 165 * A descriptor object for the JavaScript frame. 166 * @param {number} options.depth 167 * Represents the depth of the frame in the call stack. 168 * @param {string} options.formatedDisplayName 169 * A human readable name for the current frame. 170 * @param {string} options.prefix 171 * A string to be displayed as a prefix of any logged frame. 172 * @param {string} options.why 173 * A string to explain why the function stopped. 174 * See tracer.sys.mjs's FRAME_EXIT_REASONS. 175 * @param {Debugger.Object|primitive} options.rv 176 * The returned value. It can be the returned value, or the thrown exception. 177 * It is either a primitive object, otherwise it is a Debugger.Object for any other JS Object type. 178 * @return {boolean} 179 * Return true, if the JavaScriptTracer should log the frame to stdout. 180 */ 181 onTracingFrameExit({ 182 frameId, 183 frame, 184 depth, 185 formatedDisplayName, 186 prefix, 187 why, 188 rv, 189 }) { 190 const { script } = frame; 191 const { lineNumber, columnNumber } = script.getOffsetMetadata(frame.offset); 192 const url = script.source.url; 193 194 // NOTE: Debugger.Script.prototype.getOffsetMetadata returns 195 // columnNumber in 1-based. 196 // Convert to 0-based, while keeping the wasm's column (1) as is. 197 // (bug 1863878) 198 const columnBase = script.format === "wasm" ? 0 : 1; 199 const column = columnNumber - columnBase; 200 201 // Ignore blackboxed sources 202 if (this.sourcesManager.isBlackBoxed(url, lineNumber, column)) { 203 return false; 204 } 205 206 // By returning true, we let JavaScriptTracer class log the message to stdout. 207 return true; 208 } 209 } 210 211 exports.StdoutTracingListener = StdoutTracingListener;