Debugger.Environment - Firefox Developer Tools 编辑
A /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instance represents a lexical environment, associating names with variables. Each /wiki/en-US/docs/Tools/Debugger-API/Debugger.Frame
instance representing a debuggee frame has an associated environment object describing the variables in scope in that frame; and each /wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance representing a debuggee function has an environment object representing the environment the function has closed over.
ECMAScript environments form a tree, in which each local environment is parented by its enclosing environment (in ECMAScript terms, its ‘outer’ environment). We say an environmentbinds an identifier if that environment itself associates the identifier with a variable, independently of its outer environments. We say an identifier isin scope in an environment if the identifier is bound in that environment or any enclosing environment.
SpiderMonkey creates /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instances as needed as the debugger inspects stack frames and function objects; calling /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
as a function or constructor raises a TypeError
exception.
SpiderMonkey creates exactly one /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instance for each environment it presents via a given /wiki/en-US/docs/Tools/Debugger-API/Debugger
instance: if the debugger encounters the same environment through two different routes (perhaps two functions have closed over the same environment), SpiderMonkey presents the same /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instance to the debugger each time. This means that the debugger can use the ==
operator to recognize when two /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instances refer to the same environment in the debuggee, and place its own properties on a /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instance to store metadata about particular environments.
(If more than one /wiki/en-US/docs/Tools/Debugger-API/Debugger
instance is debugging the same code, each /wiki/en-US/docs/Tools/Debugger-API/Debugger
gets a separate /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instance for a given environment. This allows the code using each /wiki/en-US/docs/Tools/Debugger-API/Debugger
instance to place whatever properties it likes on its own /wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instances, without worrying about interfering with other debuggers.)
If a /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instance’s referent is not a debuggee environment, then attempting to access its properties (other than inspectable
) or call any its methods throws an instance of Error
.
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instances protect their referents from the garbage collector; as long as the /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instance is live, the referent remains live. Garbage collection has no visible effect on /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instances.
Accessor Properties of the /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment Prototype Object
A /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instance inherits the following accessor properties from its prototype:
inspectable
- True if this environment is a debuggee environment, and can therefore be inspected. False otherwise. All other properties and methods of
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instances throw if applied to a non-inspectable environment. type
The type of this environment object, one of the following values:
“declarative”, indicating that the environment is a declarative environment record. Function calls, calls to
eval
,let
blocks,catch
blocks, and the like create declarative environment records.“object”, indicating that the environment’s bindings are the properties of an object. The global object and DOM elements appear in the chain of environments via object environments. (Note that
with
statements have their own environment type.)“with”, indicating that the environment was introduced by a
with
statement.
parent
- The environment that encloses this one (the “outer” environment, in ECMAScript terminology), or
null
if this is the outermost environment. object
- A
/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance referring to the object whose properties this environment reflects. If this is a declarative environment record, this accessor throws aTypeError
(since declarative environment records have no such object). Both"object"
and"with"
environments haveobject
properties that provide the object whose properties they reflect as variable bindings. callee
- If this environment represents the variable environment (the top-level environment within the function, which receives
var
definitions) for a call to a functionf, then this property’s value is a/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance referring tof. Otherwise, this property’s value isnull
. optimizedOut
- True if this environment is optimized out. False otherwise. For example, functions whose locals are never aliased may present optimized-out environments. When true,
getVariable
returns an ordinary JavaScript object whoseoptimizedOut
property is true on all bindings, andsetVariable
throws aReferenceError
.
Function Properties of the /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment Prototype Object
The methods described below may only be called with a this
value referring to a /wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment
instance; they may not be used as methods of other kinds of objects.
names()
- Return an array of strings giving the names of the identifiers bound by this environment. The result does not include the names of identifiers bound by enclosing environments.
getVariable(name)
Return the value of the variable bound toname in this environment, or
undefined
if this environment does not bindname.Name must be a string that is a valid ECMAScript identifier name. The result is a debuggee value.JavaScript engines often omit variables from environments, to save space and reduce execution time. If the given variable should be in scope, but
getVariable
is unable to produce its value, it returns an ordinary JavaScript object (not a/wiki/en-US/docs/Tools/Debugger-API/Debugger.Object
instance) whoseoptimizedOut
property istrue
.This is not an invocation function; if this call would cause debuggee code to run (say, because the environment is a
"with"
environment, andname refers to an accessor property of thewith
statement’s operand), this call throws a/wiki/en-US/docs/Tools/Debugger-API/Debugger.DebuggeeWouldRun
exception.setVariable(name,value)
Storevalue as the value of the variable bound toname in this environment.Name must be a string that is a valid ECMAScript identifier name;value must be a debuggee value.
If this environment binds no variable namedname, throw a
ReferenceError
.This is not an invocation function; if this call would cause debuggee code to run, this call throws a
/wiki/en-US/docs/Tools/Debugger-API/Debugger.DebuggeeWouldRun
exception.find(name)
- Return a reference to the innermost environment, starting with this environment, that bindsname. Ifname is not in scope in this environment, return
null
.Name must be a string whose value is a valid ECMAScript identifier name.
Source Metadata
- Generated from file:
- js/src/doc//wiki/en-US/docs/Tools/Debugger-API/Debugger//wiki/en-US/docs/Tools/Debugger-API/Debugger.Environment.md
- Watermark:
- sha256:3d6f67939e351803d5d7fe201ed38c4aaf766caf032f255e168df1f1c6fe73cb
- Changeset:
- 7ae377917236
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论