Debugger - Firefox Developer Tools 编辑
The Debugger Object
When called as a constructor, the Debugger
object creates a new Debugger
instance.
new Debugger([global, …])
- Create a debugger object, and apply its
addDebuggee
method to each of the givenglobal objects to add them as the initial debuggees.
Accessor Properties of the Debugger Prototype Object
A Debugger
instance inherits the following accessor properties from its prototype:
enabled
A boolean value indicating whether this
Debugger
instance’s handlers, breakpoints, and the like are currently enabled. It is an accessor property with a getter and setter: assigning to it enables or disables thisDebugger
instance; reading it produces true if the instance is enabled, or false otherwise. This property is initiallytrue
in a freshly createdDebugger
instance.This property gives debugger code a single point of control for disentangling itself from the debuggee, regardless of what sort of events or handlers or “points” we add to the interface.
allowUnobservedAsmJS
A boolean value indicating whether asm.js code running inside this
Debugger
instance’s debuggee globals is invisible to Debugger API handlers and breakpoints. Setting this tofalse
inhibits the ahead-of-time asm.js compiler and forces asm.js code to run as normal JavaScript. This is an accessor property with a getter and setter. It is initiallyfalse
in a freshly createdDebugger
instance.Setting this flag to
true
is intended for uses of subsystems of the Debugger API (e.g,/wiki/en-US/docs/Tools/Debugger-API/Debugger.Source
) for purposes other than step debugging a target JavaScript program.allowWasmBinarySource
- A boolean value indicating whether WebAssembly sources will be available in binary form. The WebAssembly text generation will be disabled.
collectCoverageInfo
A boolean value indicating whether code coverage should be enabled inside each debuggee of this
Debugger
instance. Changing this flag value will recompile all JIT code to add or remove code coverage instrumentation. Changing this flag when any frame of the debuggee is currently active on the stack will produce an exception.Setting this to
true
enables code coverage instrumentation, which can be accessed via the/wiki/en-US/docs/Tools/Debugger-API/Debugger.Script
getOffsetsCoverage
function. In some cases, the code coverage might expose information which pre-date the modification of this flag. Code coverage reports are monotone, thus one can take a snapshot when the Debugger is enabled, and output the difference.Setting this to
false
prevents thisDebugger
instance from requiring any code coverage instrumentation, but it does not guarantee that the instrumentation is not present.uncaughtExceptionHook
Either
null
or a function that SpiderMonkey calls when a call to a debug event handler, breakpoint handler, or similar function throws some exception, which we refer to asdebugger-exception here. Exceptions thrown in the debugger are not propagated to debuggee code; instead, SpiderMonkey calls this function, passingdebugger-exception as its sole argument and theDebugger
instance as thethis
value. This function should return a resumption value, which determines how the debuggee should continue.If the uncaught exception hook itself throws an exception,uncaught-hook-exception, SpiderMonkey throws a new error object,confess-to-debuggee-exception, to the debuggee whose message blames the debugger, and includes textual descriptions ofuncaught-hook-exception and the originaldebugger-exception.
If
uncaughtExceptionHook
’s value isnull
, SpiderMonkey throws an exception to the debuggee whose message blames the debugger, and includes a textual description ofdebugger-exception.Assigning anything other than a callable value or
null
to this property throws aTypeError
exception.(This is not an ideal way to handle debugger bugs, but the hope here is that some sort of backstop, even if imperfect, will make life easier for debugger developers. For example, an uncaught exception hook may have access to browser-level features like the
alert
function, which this API’s implementation does not, making it possible to present debugger errors to the developer in a way suited to the context.)
Debugger Handler Functions
Each Debugger
instance inherits accessor properties with which you can store handler functions for SpiderMonkey to call when given events occur in debuggee code.
When one of the events described below occurs in debuggee code, the engine pauses the debuggee and calls the corresponding debugging handler on each Debugger
instance that is observing the debuggee. The handler functions receive the Debugger
instance as their this
value. Most handler functions can return a resumption value indicating how the debuggee’s execution should proceed.
On a new Debugger
instance, each of these properties is initially undefined
. Any value assigned to a debugging handler must be either a function or undefined
; otherwise a TypeError
is thrown.
Handler functions run in the same thread in which the event occurred. They run in the compartment to which they belong, not in a debuggee compartment.
onNewScript(script,global)
New code, represented by the
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Script
instancescript, has been loaded in the scope of the debuggees.This method’s return value is ignored.
onNewPromise(promise)
A new Promise object, referenced by the
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance promise, has been allocated in the scope of the debuggees. The Promise’s allocation stack can be obtained using the promiseAllocationStack accessor property of the/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance promise.This handler method should return a resumption value specifying how the debuggee’s execution should proceed. However, note that a
{ return:value }
resumption value is treated likeundefined
(“continue normally”);value is ignored.onPromiseSettled(promise)
A Promise object, referenced by the
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance promise that was allocated within a debuggee scope, has settled (either fulfilled or rejected). The Promise’s state, fulfillment or rejection value, and the allocation and resolution stacks can be obtained using the Promise-related accessor properties of the/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance promise.This handler method should return a resumption value specifying how the debuggee’s execution should proceed. However, note that a
{ return:value }
resumption value is treated likeundefined
(“continue normally”);value is ignored.onDebuggerStatement(frame)
- Debuggee code has executed adebugger statement inframe. This method should return a resumption value specifying how the debuggee’s execution should proceed.
onEnterFrame(frame)
The stack frameframe is about to begin executing code. (Naturally,frame is currently the youngest visible frame.) This method should return a resumption value specifying how the debuggee’s execution should proceed.
SpiderMonkey only calls
onEnterFrame
to report visible, non-"debugger"
frames.onExceptionUnwind(frame,value)
The exceptionvalue has been thrown, and has propagated toframe;frame is the youngest remaining stack frame, and is a debuggee frame. This method should return a resumption value specifying how the debuggee’s execution should proceed. If it returns
undefined
, the exception continues to propagate as normal: if control inframe
is in atry
block, control jumps to the correspondingcatch
orfinally
block; otherwise,frame is popped, and the exception propagates toframe’s caller.When an exception’s propagation causes control to enter a
finally
block, the exception is temporarily set aside. If thefinally
block finishes normally, the exception resumes propagation, and the debugger’sonExceptionUnwind
handler is called again, in the same frame. (The other possibility is for thefinally
block to exit due to areturn
,continue
, orbreak
statement, or a new exception. In those cases the old exception does not continue to propagate; it is discarded.)This handler is not called when unwinding a frame due to an over-recursion or out-of-memory exception.
sourceHandler(ASuffusionOfYellow)
- This method is never called. If it is ever called, a contradiction has been proven, and the debugger is free to assume that everything is true.
onError(frame,report)
SpiderMonkey is about to report an error inframe.Report is an object describing the error, with the following properties:
message
- The fully formatted error message.
file
- If present, the source file name, URL, etc. (If this property is present, theline property will be too, and vice versa.)
line
- If present, the source line number at which the error occurred.
lineText
- If present, this is the source code of the offending line.
offset
- The index of the character within lineText at which the error occurred.
warning
- Present and true if this is a warning; absent otherwise.
strict
- Present and true if this error or warning is due to the strict option (not to be confused with ES strict mode)
exception
- Present and true if an exception will be thrown; absent otherwise.
arguments
- An array of strings, representing the arguments substituted into the error message.
This method’s return value is ignored.
onNewGlobalObject(global)
A new global object,global, has been created.
This handler method should return a resumption value specifying how the debuggee’s execution should proceed. However, note that a
{ return:value }
resumption value is treated likeundefined
(“continue normally”);value is ignored. (Allowing the handler to substitute its own value for the new global object doesn’t seem useful.)This handler method is only available to debuggers running in privileged code (“chrome”, in Firefox). Most functions provided by this
Debugger
API observe activity in only those globals that are reachable by the API’s user, thus imposing capability-based restrictions on aDebugger
’s reach. However, theonNewGlobalObject
method allows the API user to monitor all global object creation that occurs anywhere within the JavaScript system (the “JSRuntime”, in SpiderMonkey terms), thereby escaping the capability-based limits. For this reason,onNewGlobalObject
is only available to privileged code.
Function Properties of the Debugger Prototype Object
The functions described below may only be called with a this
value referring to a Debugger
instance; they may not be used as methods of other kinds of objects.
addDebuggee(global)
Add the global object designated byglobal to the set of global objects this
Debugger
instance is debugging. If the designated global is already a debuggee, this has no effect. Return thisDebugger
’s/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance referring to the designated global.The valueglobal may be any of the following:
A global object.
An HTML5
WindowProxy
object (an “outer window”, in Firefox terminology), which is treated as if theWindow
object of the browsing context’s active document (the “inner window”) were passed.A cross-compartment wrapper of an object; we apply the prior rules to the wrapped object.
A
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance belonging to thisDebugger
instance; we apply the prior rules to the referent.Any other sort of value is treated as a
TypeError
. (Note that each rule is only applied once in the process of resolving a givenglobal argument. Thus, for example, a/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
referring to a second/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
which refers to a global does not designate that global for the purposes of this function.)
The global designated byglobal must be in a different compartment than this
Debugger
instance itself. If adding the designated global’s compartment would create a cycle of debugger and debuggee compartments, this method throws an error.This method returns the
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance whose referent is the designated global object.The
Debugger
instance does not hold a strong reference to its debuggee globals: if a debuggee global is not otherwise reachable, then it is dropped from theDebugger
’s set of debuggees. (Naturally, the/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance this method returns does hold a strong reference to the added global.)If this debugger is tracking allocation sites and cannot track allocation sites forglobal, this method throws an
Error
.addAllGlobalsAsDebuggees()
This method is like
addDebuggee
, but adds all the global objects from all compartments to thisDebugger
instance’s set of debuggees. Note that it skips this debugger’s compartment.If this debugger is tracking allocation sites and cannot track allocation sites for some global, this method throws an
Error
. Otherwise this method returnsundefined
.This method is only available to debuggers running in privileged code (“chrome”, in Firefox). Most functions provided by this
Debugger
API observe activity in only those globals that are reachable by the API’s user, thus imposing capability-based restrictions on aDebugger
’s reach. However, theaddAllGlobalsAsDebuggees
method allows the API user to monitor all global object creation that occurs anywhere within the JavaScript system (the “JSRuntime”, in SpiderMonkey terms), thereby escaping the capability-based limits. For this reason,addAllGlobalsAsDebuggees
is only available to privileged code.removeDebuggee(global)
Remove the global object designated byglobal from this
Debugger
instance’s set of debuggees. Returnundefined
.This method interpretsglobal using the same rules that
addDebuggee
does.Removing a global as a debuggee from this
Debugger
clears all breakpoints that belong to thatDebugger
in that global.removeAllDebuggees()
- Remove all the global objects from this
Debugger
instance’s set of debuggees. Returnundefined
. hasDebuggee(global)
Return
true
if the global object designated byglobal is a debuggee of thisDebugger
instance.This method interpretsglobal using the same rules that
addDebuggee
does.getDebuggees()
Return an array of distinct
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instances whose referents are all the global objects thisDebugger
instance is debugging.Since
Debugger
instances don’t hold strong references to their debuggee globals, if a debuggee global is otherwise unreachable, it may be dropped at any moment from the array this method returns.getNewestFrame()
- Return a
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Frame
instance referring to the youngest visible frame currently on the calling thread’s stack, ornull
if there are no visible frames on the stack. findSources([query])(not yet implemented)
Return an array of all
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Source
instances matchingquery. Each source appears only once in the array.Query is an object whose properties restrict which sources are returned; a source must meet all the criteria given byquery to be returned. Ifquery is omitted, we return all sources of all debuggee scripts.Querymay have the following properties:
url
- The source’s
url
property must be equal to this value. global
- The source must have been evaluated in the scope of the given global object. If this property’s value is a
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance belonging to thisDebugger
instance, then its referent is used. If the object is not a global object, then the global in whose scope it was allocated is used.
Note that the result may include sources that can no longer ever be used by the debuggee: say, eval code that has finished running, or source for unreachable functions. Whether such sources appear can be affected by the garbage collector’s behavior, so this function’s result is not entirely deterministic.
findScripts([query])
Return an array of
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Script
instances for all debuggee scripts matchingquery. Each instance appears only once in the array.Query is an object whose properties restrict which scripts are returned; a script must meet all the criteria given byquery to be returned. Ifquery is omitted, we return the/wiki/en-US/docs/Tools/Debugger-API/Debugger.Script
instances for all debuggee scripts.Querymay have the following properties:
url
- The script’s
url
property must be equal to this value. source
- The script’s
source
property must be equal to this value. line
- The script must at least partially cover the given source line. If this property is present, the
url
property must be present as well. column
- The script must include given column on the line given by the
line
property. If this property is present, theurl
andline
properties must both be present as well. innermost
- If this property is present and true, the script must be the innermost script covering the given source location; scripts of enclosing code are omitted.
global
- The script must be in the scope of the given global object. If this property’s value is a
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance belonging to thisDebugger
instance, then its referent is used. If the object is not a global object, then the global in whose scope it was allocated is used.
All properties ofquery are optional. Passing an empty object returns all debuggee code scripts.
Note that the result may include
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Script
instances for scripts that can no longer ever be used by the debuggee, say, those for eval code that has finished running, or unreachable functions. Whether such scripts appear can be affected by the garbage collector’s behavior, so this function’s behavior is not entirely deterministic.findObjects([query])
Return an array of
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instances referring to each live object allocated in the scope of the debuggee globals that matches query. Each instance appears only once in the array. Query is an object whose properties restrict which objects are returned; an object must meet all the criteria given by query to be returned. If query is omitted, we return the/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instances for all objects allocated in the scope of debuggee globals.The query object may have the following properties:
class
- If present, only return objects whose internal
[[Class]]
’s name matches the given string. Note that in some cases, the prototype object for a given constructor has the same[[Class]]
as the instances that refer to it, but cannot itself be used as a valid instance of the class. Code gathering objects by class name may need to examine them further before trying to use them.
All properties of query are optional. Passing an empty object returns all objects in debuggee globals.
Unlike
findScripts
, this function is deterministic and will never return/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
s referring to previously unreachable objects that had not been collected yet.clearBreakpoint(handler)
- Remove all breakpoints set in this
Debugger
instance that usehandler as their handler. Note that, if breakpoints using other handler objects are set at the same location(s) ashandler, they remain in place. clearAllBreakpoints()
- Remove all breakpoints set using this
Debugger
instance. findAllGlobals()
Return an array of
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instances referring to all the global objects present in this JavaScript instance.The results of this call can be affected in non-deterministic ways by the details of the JavaScript implementation. The array may include
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instances referring to global objects that are not actually reachable by the debuggee or any other code in the system. (Naturally, once the function has returned, the array’s/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instances strongly reference the globals they refer to.)This handler method is only available to debuggers running in privileged code (“chrome”, in Firefox). Most functions provided by this
Debugger
API observe activity in only those globals that are reachable by the API’s user, thus imposing capability-based restrictions on aDebugger
’s reach. However,findAllGlobals
allows the API user to find all global objects anywhere within the JavaScript system (the “JSRuntime”, in SpiderMonkey terms), thereby escaping the capability-based limits. For this reason,findAllGlobals
is only available to privileged code.makeGlobalObjectReference(global)
- Return the
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
whose referent is the global object designated byglobal, without adding the designated global as a debuggee. Ifglobal does not designate a global object, throw aTypeError
. Determine which global is designated byglobal using the same rules asDebugger.prototype.addDebuggee
. adoptDebuggeeValue(value)
Given a debuggee value
value
owned by an arbitraryDebugger
, return an equivalent debuggee value owned by thisDebugger
.If
value
is a primitive value, return it unchanged. Ifvalue
is a/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
owned by an arbitraryDebugger
, return an equivalent/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
owned by thisDebugger
. Otherwise, ifvalue
is some other kind of object, and hence not a proper debuggee value, throw a TypeError instead.
Static methods of the Debugger Object
The functions described below are not called with a this
value.
isCompilableUnit(source)
- Given a string of source code, designated bysource, return false if the string might become a valid JavaScript statement with the addition of more lines. Otherwise return true. The intent is to support interactive compilation - accumulate lines in a buffer until isCompilableUnit is true, then pass it to the compiler.
Source Metadata
- Generated from file:
- js/src/doc/Debugger/Debugger.md
- Watermark:
- sha256:03b36132885e046a5f213130ba22b1139b473770f7324b842483c09ab7665f7c
- Changeset:
- e91b2c85aacd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论