js/src/doc/Debugger/Debugger.md

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 # The Debugger Object
     3 When called as a constructor, the `Debugger` object creates a new
     4 `Debugger` instance.
     6 <code>new Debugger([<i>global</i>, ...])</code>
     7 :   Create a debugger object, and apply its [`addDebuggee`][add] method to
     8     each of the given <i>global</i> objects to add them as the initial
     9     debuggees.
    11 ## Accessor Properties of the Debugger Prototype Object
    13 A `Debugger` instance inherits the following accessor properties from
    14 its prototype:
    16 `enabled`
    17 :   A boolean value indicating whether this `Debugger` instance's handlers,
    18     breakpoints, watchpoints, and the like are currently enabled. It is an
    19     accessor property with a getter and setter: assigning to it enables or
    20     disables this `Debugger` instance; reading it produces true if the
    21     instance is enabled, or false otherwise. This property is initially
    22     `true` in a freshly created `Debugger` instance.
    24     This property gives debugger code a single point of control for
    25     disentangling itself from the debuggee, regardless of what sort of
    26     events or handlers or "points" we add to the interface.
    28 `uncaughtExceptionHook`
    29 :   Either `null` or a function that SpiderMonkey calls when a call to a
    30     debug event handler, breakpoint handler, watchpoint handler, or similar
    31     function throws some exception, which we refer to as
    32     <i>debugger-exception</i> here. Exceptions thrown in the debugger are
    33     not propagated to debuggee code; instead, SpiderMonkey calls this
    34     function, passing <i>debugger-exception</i> as its sole argument and
    35     the `Debugger` instance as the `this` value. This function should
    36     return a [resumption value][rv], which determines how the debuggee
    37     should continue.
    39     If the uncaught exception hook itself throws an exception,
    40     <i>uncaught-hook-exception</i>, SpiderMonkey throws a new error object,
    41     <i>confess-to-debuggee-exception</i>, to the debuggee whose message
    42     blames the debugger, and includes textual descriptions of
    43     <i>uncaught-hook-exception</i> and the original
    44     <i>debugger-exception</i>.
    46     If `uncaughtExceptionHook`'s value is `null`, SpiderMonkey throws an
    47     exception to the debuggee whose message blames the debugger, and
    48     includes a textual description of <i>debugger-exception</i>.
    50     Assigning anything other than a callable value or `null` to this
    51     property throws a `TypeError` exception.
    53     (This is not an ideal way to handle debugger bugs, but the hope here is
    54     that some sort of backstop, even if imperfect, will make life easier for
    55     debugger developers. For example, an uncaught exception hook may have
    56     access to browser-level features like the `alert` function, which this
    57     API's implementation does not, making it possible to present debugger
    58     errors to the developer in a way suited to the context.)
    61 ## Debugger Handler Functions
    63 Each `Debugger` instance inherits accessor properties with which you can
    64 store handler functions for SpiderMonkey to call when given events occur
    65 in debuggee code.
    67 When one of the events described below occurs in debuggee code, the engine
    68 pauses the debuggee and calls the corresponding debugging handler on each
    69 `Debugger` instance that is observing the debuggee. The handler functions
    70 receive the `Debugger` instance as their `this` value. Most handler
    71 functions can return a [resumption value][rv] indicating how the debuggee's
    72 execution should proceed.
    74 On a new `Debugger` instance, each of these properties is initially
    75 `undefined`. Any value assigned to a debugging handler must be either a
    76 function or `undefined`; otherwise a `TypeError` is thrown.
    78 Handler functions run in the same thread in which the event occurred.
    79 They run in the compartment to which they belong, not in a debuggee
    80 compartment.
    82 <code>onNewScript(<i>script</i>, <i>global</i>)</code>
    83 :   New code, represented by the [`Debugger.Script`][script] instance
    84     <i>script</i>, has been loaded in the scope of the debuggee global
    85     object <i>global</i>. <i>global</i> is a [`Debugger.Object`][object]
    86     instance whose referent is the global object.
    88     This method's return value is ignored.
    90 <code>onDebuggerStatement(<i>frame</i>)</code>
    91 :   Debuggee code has executed a <i>debugger</i> statement in <i>frame</i>.
    92     This method should return a [resumption value][rv] specifying how the
    93     debuggee's execution should proceed.
    95 <code>onEnterFrame(<i>frame</i>)</code>
    96 :   The stack frame <i>frame</i> is about to begin executing code.
    97     (Naturally, <i>frame</i> is currently the youngest
    98     [visible frame][vf].) This method should return
    99     a [resumption value][rv] specifying how the debuggee's execution should
   100     proceed.
   102     SpiderMonkey only calls `onEnterFrame` to report
   103     [visible][vf], non-`"debugger"` frames.
   105 <code>onThrow(<i>frame</i>, <i>value</i>) <i>(future plan)</i></code>
   106 :   The exception <i>value</i> is being thrown by <i>frame</i>, which is
   107     running debuggee code. This method should return a
   108     [resumption value][rv] specifying how the debuggee's execution should
   109     proceed. If it returns `undefined`, the exception is thrown as normal.
   111     A call to the `onThrow` handler is typically followed by one or more
   112     calls to the `onExceptionUnwind` handler.
   114     *(pending discussion)* If the debuggee executes
   115     `try { throw 0; } finally { f(); }` and `f()` executes without error,
   116     the `onThrow` handler is called only once. The debugger is not notified
   117     when the exception is set aside in order to execute the `finally` block,
   118     nor when it is restored after the `finally` block completes normally.
   120     *(An alternative design here would be: onException(status, frame, value)
   121     where status is one of the strings "throw", "unwind", "catch",
   122     "finally", "rethrow". JS\_SaveExceptionState would trigger a "finally"
   123     event, JS\_RestoreExceptionState would trigger a "rethrow",
   124     JS\_ClearPendingException would trigger a "catch"; not sure what
   125     JS\_DropExceptionState or a return/throw from a finally block should
   126     do.)*
   128 <code>onExceptionUnwind(<i>frame</i>, <i>value</i>)</code>
   129 :   The exception <i>value</i> has been thrown, and has propagated to
   130     <i>frame</i>; <i>frame</i> is the youngest remaining stack frame, and is a
   131     debuggee frame. This method should return a [resumption value][rv]
   132     specifying how the debuggee's execution should proceed. If it returns
   133     `undefined`, the exception continues to propagate as normal: if control in
   134     `frame` is in a `try` block, control jumps to the corresponding `catch` or
   135     `finally` block; otherwise, <i>frame</i> is popped, and the exception
   136     propagates to <i>frame</i>'s caller.
   138     When an exception's propagation causes control to enter a `finally`
   139     block, the exception is temporarily set aside. If the `finally` block
   140     finishes normally, the exception resumes propagation, and the debugger's
   141     `onExceptionUnwind` handler is called again, in the same frame. (The
   142     other possibility is for the `finally` block to exit due to a `return`,
   143     `continue`, or `break` statement, or a new exception. In those cases the
   144     old exception does not continue to propagate; it is discarded.)
   146 <code>sourceHandler(<i>ASuffusionOfYellow</i>)</code>
   147 :   This method is never called. If it is ever called, a contradiction has
   148     been proven, and the debugger is free to assume that everything is true.
   150 <code>onError(<i>frame</i>, <i>report</i>)</code>
   151 :   SpiderMonkey is about to report an error in <i>frame</i>. <i>Report</i>
   152     is an object describing the error, with the following properties:
   154     `message`
   155     :   The fully formatted error message.
   157     `file`
   158     :   If present, the source file name, URL, etc. (If this property is
   159         present, the <i>line</i> property will be too, and vice versa.)
   161     `line`
   162     :   If present, the source line number at which the error occurred.
   164     `lineText`
   165     :   If present, this is the source code of the offending line.
   167     `offset`
   168     :   The index of the character within lineText at which the error occurred.
   170     `warning`
   171     :   Present and true if this is a warning; absent otherwise.
   173     `strict`
   174     :   Present and true if this error or warning is due to the strict option
   175         (not to be confused with ES strict mode)
   177     `exception`
   178     :   Present and true if an exception will be thrown; absent otherwise.
   180     `arguments`
   181     :   An array of strings, representing the arguments substituted into the
   182         error message.
   184     This method's return value is ignored.
   186 `onNewGlobalObject(global)`
   187 :   A new global object, <i>global</i>, has been created. The application
   188     embedding the JavaScript implementation may provide details about what
   189     kind of global it is via <code><i>global</i>.hostAnnotations</code>.
   191     This handler method should return a [resumption value][rv] specifying how
   192     the debuggee's execution should proceed. However, note that a <code>{ return:
   193     <i>value</i> }</code> resumption value is treated like `undefined` ("continue
   194     normally"); <i>value</i> is ignored. (Allowing the handler to substitute
   195     its own value for the new global object doesn't seem useful.)
   197     This handler method is only available to debuggers running in privileged
   198     code ("chrome", in Firefox). Most functions provided by this `Debugger`
   199     API observe activity in only those globals that are reachable by the
   200     API's user, thus imposing capability-based restrictions on a
   201     `Debugger`'s reach. However, the `onNewGlobalObject` method allows the
   202     API user to monitor all global object creation that occurs anywhere
   203     within the JavaScript system (the "JSRuntime", in SpiderMonkey terms),
   204     thereby escaping the capability-based limits. For this reason,
   205     `onNewGlobalObject` is only available to privileged code.
   209 ## Function Properties of the Debugger Prototype Object
   211 The functions described below may only be called with a `this` value
   212 referring to a `Debugger` instance; they may not be used as methods of
   213 other kinds of objects.
   215 <code id="addDebuggee">addDebuggee(<i>global</i>)</code>
   216 :   Add the global object designated by <i>global</i> to the set of global
   217     objects this `Debugger` instance is debugging. If the designated global
   218     is already a debuggee, this has no effect. Return this `Debugger`'s
   219     [`Debugger.Object`][object] instance referring to the designated global.
   221     The value <i>global</i> may be any of the following:
   223     * A global object.
   225     * An HTML5 `WindowProxy` object (an "outer window", in Firefox
   226       terminology), which is treated as if the `Window` object of the
   227       browsing context's active document (the "inner window") were passed.
   229     * A cross-compartment wrapper of an object; we apply the prior rules to
   230       the wrapped object.
   232     * A [`Debugger.Object`][object] instance belonging to this `Debugger` instance;
   233       we apply the prior rules to the referent.
   235     * Any other sort of value is treated as a `TypeError`. (Note that each
   236       rule is only applied once in the process of resolving a given
   237       <i>global</i> argument. Thus, for example, a [`Debugger.Object`][object]
   238       referring to a second [`Debugger.Object`][object] which refers to a global does
   239       not designate that global for the purposes of this function.)
   241     The global designated by <i>global</i> must be in a different
   242     compartment than this `Debugger` instance itself. If adding the
   243     designated global's compartment would create a cycle of debugger and
   244     debuggee compartments, this method throws an error.
   246     This method returns the [`Debugger.Object`][object] instance whose referent is
   247     the designated global object.
   249     The `Debugger` instance does not hold a strong reference to its
   250     debuggee globals: if a debuggee global is not otherwise reachable, then
   251     it is dropped from the `Debugger`'s set of debuggees. (Naturally, the
   252     [`Debugger.Object`][object] instance this method returns does hold a strong
   253     reference to the added global.)
   255 <code>removeDebuggee(<i>global</i>)</code>
   256 :   Remove the global object designated by <i>global</i> from this
   257     `Debugger` instance's set of debuggees. Return `undefined`.
   259     This method interprets <i>global</i> using the same rules that
   260     [`addDebuggee`][add] does.
   262 <code>hasDebuggee(<i>global</i>)</code>
   263 :   Return `true` if the global object designated by <i>global</i> is a
   264     debuggee of this `Debugger` instance.
   266     This method interprets <i>global</i> using the same rules that
   267     [`addDebuggee`][add] does.
   269 `getDebuggees()`
   270 :   Return an array of distinct [`Debugger.Object`][object] instances whose referents
   271     are all the global objects this `Debugger` instance is debugging.
   273     Since `Debugger` instances don't hold strong references to their
   274     debuggee globals, if a debuggee global is otherwise unreachable, it may
   275     be dropped at any moment from the array this method returns.
   277 `getNewestFrame()`
   278 :   Return a [`Debugger.Frame`][frame] instance referring to the youngest
   279     [visible frame][vf] currently on the calling thread's stack, or `null`
   280     if there are no visible frames on the stack.
   282 <code>findSources([<i>query</i>]) <i>(not yet implemented)</i></code>
   283 :   Return an array of all [`Debugger.Source`][source] instances matching
   284     <i>query</i>. Each source appears only once in the array. <i>Query</i>
   285     is an object whose properties restrict which sources are returned; a
   286     source must meet all the criteria given by <i>query</i> to be returned.
   287     If <i>query</i> is omitted, we return all sources of all debuggee
   288     scripts.
   290     <i>Query</i> may have the following properties:
   292     `url`
   293     :   The source's `url` property must be equal to this value.
   295     `global`
   296     :   The source must have been evaluated in the scope of the given global
   297         object. If this property's value is a [`Debugger.Object`][object] instance
   298         belonging to this `Debugger` instance, then its referent is used. If the
   299         object is not a global object, then the global in whose scope it was
   300         allocated is used.
   302     Note that the result may include sources that can no longer ever be
   303     used by the debuggee: say, eval code that has finished running, or
   304     source for unreachable functions. Whether such sources appear can be
   305     affected by the garbage collector's behavior, so this function's result
   306     is not entirely deterministic.
   308 <code>findScripts([<i>query</i>])</code>
   309 :   Return an array of [`Debugger.Script`][script] instances for all debuggee scripts
   310     matching <i>query</i>. Each instance appears only once in the array.
   311     <i>Query</i> is an object whose properties restrict which scripts are
   312     returned; a script must meet all the criteria given by <i>query</i> to
   313     be returned. If <i>query</i> is omitted, we return the [`Debugger.Script`][script]
   314     instances for all debuggee scripts.
   316     <i>Query</i> may have the following properties:
   318     `url`
   319     :   The script's `url` property must be equal to this value.
   321     `source` <i>(not yet implemented)</i>
   322     :   The script's `source` property must be equal to this value.
   324     `line`
   325     :   The script must at least partially cover the given source line. If this
   326         property is present, the `url` property must be present as well.
   328     `column`
   329     :   The script must include given column on the line given by the `line`
   330         property. If this property is present, the `url` and `line` properties
   331         must both be present as well.
   333     `innermost`
   334     :   If this property is present and true, the script must be the innermost
   335         script covering the given source location; scripts of enclosing code are
   336         omitted.
   338     `global`
   339     :   The script must be in the scope of the given global object. If this
   340         property's value is a [`Debugger.Object`][object] instance belonging to this
   341         `Debugger` instance, then its referent is used. If the object is not a
   342         global object, then the global in whose scope it was allocated is used.
   344     All properties of <i>query</i> are optional. Passing an empty object
   345     returns all debuggee code scripts.
   347     Note that the result may include [`Debugger.Script`][script] instances for
   348     scripts that can no longer ever be used by the debuggee, say, those for
   349     eval code that has finished running, or unreachable functions. Whether
   350     such scripts appear can be affected by the garbage collector's
   351     behavior, so this function's behavior is not entirely deterministic.
   353 <code>clearBreakpoint(<i>handler</i>)</code>
   354 :   Remove all breakpoints set in this `Debugger` instance that use
   355     <i>handler</i> as their handler. Note that, if breakpoints using other
   356     handler objects are set at the same location(s) as <i>handler</i>, they
   357     remain in place.
   359 `clearAllBreakpoints()`
   360 :   Remove all breakpoints set using this `Debugger` instance.
   362 `clearAllWatchpoints()` <i>(future plan)</i>
   363 :   Clear all watchpoints owned by this `Debugger` instance.
   365 `findAllGlobals()`
   366 :   Return an array of [`Debugger.Object`][object] instances referring to all the
   367     global objects present in this JavaScript instance. The application may
   368     provide details about what kind of globals they are via the
   369     [`Debugger.Object`][object] instances' `hostAnnotations` accessors.
   371     The results of this call can be affected in non-deterministic ways by
   372     the details of the JavaScript implementation. The array may include
   373     [`Debugger.Object`][object] instances referring to global objects that are not
   374     actually reachable by the debuggee or any other code in the system.
   375     (Naturally, once the function has returned, the array's
   376     [`Debugger.Object`][object] instances strongly reference the globals they refer
   377     to.)
   379     This handler method is only available to debuggers running in privileged
   380     code ("chrome", in Firefox). Most functions provided by this `Debugger`
   381     API observe activity in only those globals that are reachable by the
   382     API's user, thus imposing capability-based restrictions on a
   383     `Debugger`'s reach. However, `findAllGlobals` allows the API user to
   384     find all global objects anywhere within the JavaScript system (the
   385     "JSRuntime", in SpiderMonkey terms), thereby escaping the
   386     capability-based limits. For this reason, `findAllGlobals` is only
   387     available to privileged code.
   389 <code>makeGlobalObjectReference(<i>global</i>)</code>
   390 :   Return the [`Debugger.Object`][object] whose referent is the global object
   391     designated by <i>global</i>, without adding the designated global as a
   392     debuggee. If <i>global</i> does not designate a global object, throw a
   393     `TypeError`. Determine which global is designated by <i>global</i>
   394     using the same rules as [`Debugger.prototype.addDebuggee`][add].

mercurial