js/src/doc/Debugger/Debugger.Environment.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 # Debugger.Environment
     3 A `Debugger.Environment` instance represents a lexical environment,
     4 associating names with variables. Each [`Debugger.Frame`][frame] instance
     5 representing a debuggee frame has an associated environment object
     6 describing the variables in scope in that frame; and each
     7 [`Debugger.Object`][object] instance representing a debuggee function has an
     8 environment object representing the environment the function has closed
     9 over.
    11 ECMAScript environments form a tree, in which each local environment is
    12 parented by its enclosing environment (in ECMAScript terms, its 'outer'
    13 environment). We say an environment <i>binds</i> an identifier if that
    14 environment itself associates the identifier with a variable, independently
    15 of its outer environments. We say an identifier is <i>in scope</i> in an
    16 environment if the identifier is bound in that environment or any enclosing
    17 environment.
    19 SpiderMonkey creates `Debugger.Environment` instances as needed as the
    20 debugger inspects stack frames and function objects; calling
    21 `Debugger.Environment` as a function or constructor raises a `TypeError`
    22 exception.
    24 SpiderMonkey creates exactly one `Debugger.Environment` instance for each
    25 environment it presents via a given [`Debugger`][debugger-object] instance:
    26 if the debugger encounters the same environment through two different
    27 routes (perhaps two functions have closed over the same environment),
    28 SpiderMonkey presents the same `Debugger.Environment` instance to the
    29 debugger each time. This means that the debugger can use the `==` operator
    30 to recognize when two `Debugger.Environment` instances refer to the same
    31 environment in the debuggee, and place its own properties on a
    32 `Debugger.Environment` instance to store metadata about particular
    33 environments.
    35 (If more than one [`Debugger`][debugger-object] instance is debugging the
    36 same code, each [`Debugger`][debugger-object] gets a separate
    37 `Debugger.Environment` instance for a given environment. This allows the
    38 code using each [`Debugger`][debugger-object] instance to place whatever
    39 properties it likes on its own [`Debugger.Object`][object] instances,
    40 without worrying about interfering with other debuggers.)
    42 If a `Debugger.Environment` instance's referent is not a debuggee
    43 environment, then attempting to access its properties (other than
    44 `inspectable`) or call any its methods throws an instance of `Error`.
    46 `Debugger.Environment` instances protect their referents from the
    47 garbage collector; as long as the `Debugger.Environment` instance is
    48 live, the referent remains live. Garbage collection has no visible
    49 effect on `Debugger.Environment` instances.
    52 ## Accessor Properties of the Debugger.Environment Prototype Object
    54 A `Debugger.Environment` instance inherits the following accessor
    55 properties from its prototype:
    57 `inspectable`
    58 :   True if this environment is a debuggee environment, and can therefore
    59     be inspected. False otherwise. All other properties and methods of
    60     `Debugger.Environment` instances throw if applied to a non-inspectable
    61     environment.
    63 `type`
    64 :   The type of this environment object, one of the following values:
    66     * "declarative", indicating that the environment is a declarative
    67       environment record. Function calls, calls to `eval`, `let` blocks,
    68       `catch` blocks, and the like create declarative environment records.
    70     * "object", indicating that the environment's bindings are the
    71       properties of an object. The global object and DOM elements appear in
    72       the chain of environments via object environments. (Note that `with`
    73       statements have their own environment type.)
    75     * "with", indicating that the environment was introduced by a `with`
    76       statement.
    78 `parent`
    79 :   The environment that encloses this one (the "outer" environment, in
    80     ECMAScript terminology), or `null` if this is the outermost environment.
    82 `object`
    83 :   A [`Debugger.Object`][object] instance referring to the object whose
    84     properties this environment reflects. If this is a declarative
    85     environment record, this accessor throws a `TypeError` (since
    86     declarative environment records have no such object). Both `"object"`
    87     and `"with"` environments have `object` properties that provide the
    88     object whose properties they reflect as variable bindings.
    90 `callee`
    91 :   If this environment represents the variable environment (the top-level
    92     environment within the function, which receives `var` definitions) for
    93     a call to a function <i>f</i>, then this property's value is a
    94     [`Debugger.Object`][object] instance referring to <i>f</i>. Otherwise,
    95     this property's value is `null`.
    99 ## Function Properties of the Debugger.Environment Prototype Object
   101 The methods described below may only be called with a `this` value
   102 referring to a `Debugger.Environment` instance; they may not be used as
   103 methods of other kinds of objects.
   105 `names()`
   106 :   Return an array of strings giving the names of the identifiers bound by
   107     this environment. The result does not include the names of identifiers
   108     bound by enclosing environments.
   110 <code>getVariable(<i>name</i>)</code>
   111 :   Return the value of the variable bound to <i>name</i> in this
   112     environment, or `undefined` if this environment does not bind
   113     <i>name</i>. <i>Name</i> must be a string that is a valid ECMAScript
   114     identifier name. The result is a debuggee value.
   116     JavaScript engines often omit variables from environments, to save space
   117     and reduce execution time. If the given variable should be in scope, but
   118     `getVariable` is unable to produce its value, it returns an ordinary
   119     JavaScript object (not a [`Debugger.Object`][object] instance) whose
   120     `optimizedOut` property is `true`.
   122     This is not an [invocation function][inv fr];
   123     if this call would cause debuggee code to run (say, because the
   124     environment is a `"with"` environment, and <i>name</i> refers to an
   125     accessor property of the `with` statement's operand), this call throws a
   126     [`Debugger.DebuggeeWouldRun`][wouldrun]
   127     exception.
   129 <code>setVariable(<i>name</i>, <i>value</i>)</code>
   130 :   Store <i>value</i> as the value of the variable bound to <i>name</i> in
   131     this environment. <i>Name</i> must be a string that is a valid
   132     ECMAScript identifier name; <i>value</i> must be a debuggee value.
   134     If this environment binds no variable named <i>name</i>, throw a
   135     `ReferenceError`.
   137     This is not an [invocation function][inv fr];
   138     if this call would cause debuggee code to run, this call throws a
   139     [`Debugger.DebuggeeWouldRun`][wouldrun]
   140     exception.
   142 <code>getVariableDescriptor(<i>name</i>)</code>
   143 :   Return an property descriptor describing the variable bound to
   144     <i>name</i> in this environment, of the sort returned by
   145     `Debugger.Object.prototype.getOwnPropertyDescriptor`. <i>Name</i> must
   146     be a string whose value is a valid ECMAScript identifier name.
   148     If this is an `"object"` or `"with"` environment record, this simply
   149     returns the descriptor for the given property of the environment's
   150     object. If this is a declarative environment record, this returns a
   151     descriptor reflecting the binding's mutability as the descriptor's
   152     `writable` property, and its deletability as the descriptor's
   153     `configurable` property. All declarative environment record bindings are
   154     marked as `enumerable`. <i>(This isn't great; the semantics of variables
   155     in declarative enviroments don't really match those of properties, so
   156     writing code that operates properly on descriptors for either kind may
   157     be difficult.)</i>
   159     If this environment binds no variable named <i>name</i>, throw a
   160     `ReferenceError`.
   162 <code>defineVariable(<i>name</i>, <i>descriptor</i>)</code>
   163 :   Create or reconfigure the variable bound to <i>name</i> in this
   164     environment according to <i>descriptor</i>. <i>Descriptor</i> is the
   165     sort of value returned by `getVariableDescriptor`. On success, return
   166     `undefined`; on failure, throw an appropriate exception. <i>Name</i>
   167     must be a string whose value is a valid ECMAScript identifier name.
   169     If implementation restrictions prevent SpiderMonkey from creating or
   170     reconfiguring the variable as requested, this call throws an `Error`
   171     exception.
   173 <code>deleteVariable(<i>name</i>)</code>
   174 :   Delete this environment's binding for <i>name</i>.
   176     If this environment binds no variable named <i>name</i>, throw a
   177     `ReferenceError`.
   179     If implementation restrictions prevent SpiderMonkey from deleting the
   180     variable as requested, this call throws an `Error` exception.
   182 <code>find(<i>name</i>)</code>
   183 :   Return a reference to the innermost environment, starting with this
   184     environment, that binds <i>name</i>. If <i>name</i> is not in scope in
   185     this environment, return `null`. <i>Name</i> must be a string whose
   186     value is a valid ECMAScript identifier name.
   188 <code>eval(<i>code</i>)</code> <i>(future plan)</i>
   189 :   Evaluate <i>code</i> in this environment, and return a
   190     [completion value][cv] describing how it completed. <i>Code</i> is a
   191     string. All extant handler methods, breakpoints, watchpoints, and so on
   192     remain active during the call. This function follows the
   193     [invocation function conventions][inv fr].
   195     <i>Code</i> is interpreted as strict mode code when it contains a Use
   196     Strict Directive.
   198     If <i>code</i> is not strict mode code, then variable declarations in
   199     <i>code</i> affect this environment. (In the terms used by the
   200     ECMAScript specification, the `VariableEnvironment` of the execution
   201     context for the eval code is the `VariableEnvironment` this
   202     `Debugger.Environment` instance represents.) If implementation
   203     restrictions prevent SpiderMonkey from extending this environment as
   204     requested, this call throws an `Error` exception.
   206 <code>evalWithBindings(<i>code</i>, <i>bindings</i>)</code> <i>(future plan)</i>
   207 :   Like `eval`, but evaluate <i>code</i> in this environment, extended with
   208     bindings from the object <i>bindings</i>. For each own enumerable
   209     property of <i>bindings</i> named <i>name</i> whose value is
   210     <i>value</i>, include a variable in the environment in which <i>code</i>
   211     is evaluated named <i>name</i>, whose value is <i>value</i>. Each
   212     <i>value</i> must be a debuggee value. (This is not like a `with`
   213     statement: <i>code</i> may access, assign to, and delete the introduced
   214     bindings without having any effect on the <i>bindings</i> object.)
   216     This method allows debugger code to introduce temporary bindings that
   217     are visible to the given debuggee code and which refer to debugger-held
   218     debuggee values, and do so without mutating any existing debuggee
   219     environment.
   221     Note that, like `eval`, declarations in the <i>code</i> passed to
   222     `evalWithBindings` affect this environment, even as <i>code</i> is
   223     evaluated with <i>bindings</i> visible. (In the terms used by the
   224     ECMAScript specification, the `VariableEnvironment` of the execution
   225     context for the eval code is the `VariableEnvironment` this environment
   226     represents, and the <i>bindings</i> appear in a new declarative
   227     environment, which is the eval code's `LexicalEnvironment`.) If
   228     implementation restrictions prevent SpiderMonkey from extending this
   229     environment as requested, this call throws an `Error` exception.

mercurial