| 1 |
# Debugger.Object |
| 2 |
|
| 3 |
A `Debugger.Object` instance represents an object in the debuggee, |
| 4 |
providing reflection-oriented methods to inspect and modify its referent. |
| 5 |
The referent's properties do not appear directly as properties of the |
| 6 |
`Debugger.Object` instance; the debugger can access them only through |
| 7 |
methods like `Debugger.Object.prototype.getOwnPropertyDescriptor` and |
| 8 |
`Debugger.Object.prototype.defineProperty`, ensuring that the debugger will |
| 9 |
not inadvertently invoke the referent's getters and setters. |
| 10 |
|
| 11 |
SpiderMonkey creates exactly one `Debugger.Object` instance for each |
| 12 |
debuggee object it presents to a given [`Debugger`][debugger-object] |
| 13 |
instance: if the debugger encounters the same object through two different |
| 14 |
routes (perhaps two functions are called on the same object), SpiderMonkey |
| 15 |
presents the same `Debugger.Object` instance to the debugger each time. |
| 16 |
This means that the debugger can use the `==` operator to recognize when |
| 17 |
two `Debugger.Object` instances refer to the same debuggee object, and |
| 18 |
place its own properties on a `Debugger.Object` instance to store metadata |
| 19 |
about particular debuggee objects. |
| 20 |
|
| 21 |
JavaScript code in different compartments can have different views of the |
| 22 |
same object. For example, in Firefox, code in privileged compartments sees |
| 23 |
content DOM element objects without redefinitions or extensions made to |
| 24 |
that object's properties by content code. (In Firefox terminology, |
| 25 |
privileged code sees the element through an "xray wrapper".) To ensure that |
| 26 |
debugger code sees each object just as the debuggee would, each |
| 27 |
`Debugger.Object` instance presents its referent as it would be seen from a |
| 28 |
particular compartment. This "viewing compartment" is chosen to match the |
| 29 |
way the debugger came across the referent. As a consequence, a single |
| 30 |
[`Debugger`][debugger-object] instance may actually have several |
| 31 |
`Debugger.Object` instances: one for each compartment from which the |
| 32 |
referent is viewed. |
| 33 |
|
| 34 |
If more than one [`Debugger`][debugger-object] instance is debugging the |
| 35 |
same code, each [`Debugger`][debugger-object] gets a separate |
| 36 |
`Debugger.Object` instance for a given object. This allows the code using |
| 37 |
each [`Debugger`][debugger-object] instance to place whatever properties it |
| 38 |
likes on its own `Debugger.Object` instances, without worrying about |
| 39 |
interfering with other debuggers. |
| 40 |
|
| 41 |
While most `Debugger.Object` instances are created by SpiderMonkey in the |
| 42 |
process of exposing debuggee's behavior and state to the debugger, the |
| 43 |
debugger can use `Debugger.Object.prototype.makeDebuggeeValue` to create |
| 44 |
`Debugger.Object` instances for given debuggee objects, or use |
| 45 |
`Debugger.Object.prototype.copy` and `Debugger.Object.prototype.create` to |
| 46 |
create new objects in debuggee compartments, allocated as if by particular |
| 47 |
debuggee globals. |
| 48 |
|
| 49 |
`Debugger.Object` instances protect their referents from the garbage |
| 50 |
collector; as long as the `Debugger.Object` instance is live, the referent |
| 51 |
remains live. This means that garbage collection has no visible effect on |
| 52 |
`Debugger.Object` instances. |
| 53 |
|
| 54 |
|
| 55 |
## Accessor Properties of the Debugger.Object prototype |
| 56 |
|
| 57 |
A `Debugger.Object` instance inherits the following accessor properties |
| 58 |
from its prototype: |
| 59 |
|
| 60 |
### `proto` |
| 61 |
The referent's prototype (as a new `Debugger.Object` instance), or `null` if |
| 62 |
it has no prototype. This accessor may throw if the referent is a scripted |
| 63 |
proxy or some other sort of exotic object (an opaque wrapper, for example). |
| 64 |
|
| 65 |
### `class` |
| 66 |
A string naming the ECMAScript `[[Class]]` of the referent. |
| 67 |
|
| 68 |
### `callable` |
| 69 |
`true` if the referent is a callable object (such as a function or a |
| 70 |
function proxy); false otherwise. |
| 71 |
|
| 72 |
### `name` |
| 73 |
The name of the referent, if it is a named function. If the referent is |
| 74 |
an anonymous function, or not a function at all, this is `undefined`. |
| 75 |
|
| 76 |
This accessor returns whatever name appeared after the `function` |
| 77 |
keyword in the source code, regardless of whether the function is the |
| 78 |
result of instantiating a function declaration (which binds the |
| 79 |
function to its name in the enclosing scope) or evaluating a function |
| 80 |
expression (which binds the function to its name only within the |
| 81 |
function's body). |
| 82 |
|
| 83 |
### `displayName` |
| 84 |
The referent's display name, if the referent is a function with a |
| 85 |
display name. If the referent is not a function, or if it has no display |
| 86 |
name, this is `undefined`. |
| 87 |
|
| 88 |
If a function has a given name, its display name is the same as its |
| 89 |
given name. In this case, the `displayName` and `name` properties are |
| 90 |
equal. |
| 91 |
|
| 92 |
If a function has no name, SpiderMonkey attempts to infer an appropriate |
| 93 |
name for it given its context. For example: |
| 94 |
|
| 95 |
```js |
| 96 |
function f() {} // display name: f (the given name) |
| 97 |
var g = function () {}; // display name: g |
| 98 |
o.p = function () {}; // display name: o.p |
| 99 |
var q = { |
| 100 |
r: function () {} // display name: q.r |
| 101 |
}; |
| 102 |
``` |
| 103 |
|
| 104 |
Note that the display name may not be a proper JavaScript identifier, |
| 105 |
or even a proper expression: we attempt to find helpful names even when |
| 106 |
the function is not immediately assigned as the value of some variable |
| 107 |
or property. Thus, we use <code><i>a</i>/<i>b</i></code> to refer to |
| 108 |
the <i>b</i> defined within <i>a</i>, and <code><i>a</i><</code> to |
| 109 |
refer to a function that occurs somewhere within an expression that is |
| 110 |
assigned to <i>a</i>. For example: |
| 111 |
|
| 112 |
```js |
| 113 |
function h() { |
| 114 |
var i = function() {}; // display name: h/i |
| 115 |
f(function () {}); // display name: h/< |
| 116 |
} |
| 117 |
var s = f(function () {}); // display name: s< |
| 118 |
``` |
| 119 |
|
| 120 |
### `parameterNames` |
| 121 |
If the referent is a debuggee function, the names of its parameters, |
| 122 |
as an array of strings. If the referent is not a debuggee function, or |
| 123 |
not a function at all, this is `undefined`. |
| 124 |
|
| 125 |
If the referent is a host function for which parameter names are not |
| 126 |
available, return an array with one element per parameter, each of which |
| 127 |
is `undefined`. |
| 128 |
|
| 129 |
If the referent is a function proxy, return an empty array. |
| 130 |
|
| 131 |
If the function uses destructuring parameters, the corresponding array elements |
| 132 |
are `undefined`. For example, if the referent is a function declared in this |
| 133 |
way: |
| 134 |
|
| 135 |
```js |
| 136 |
function f(a, [b, c], {d, e:f}) { ... } |
| 137 |
``` |
| 138 |
|
| 139 |
then this `Debugger.Object` instance's `parameterNames` property would |
| 140 |
have the value: |
| 141 |
|
| 142 |
```js |
| 143 |
["a", undefined, undefined] |
| 144 |
``` |
| 145 |
|
| 146 |
### `script` |
| 147 |
If the referent is a function that is debuggee code, this is that |
| 148 |
function's script, as a [`Debugger.Script`][script] instance. If the |
| 149 |
referent is a function proxy or not debuggee code, this is `undefined`. |
| 150 |
|
| 151 |
### `environment` |
| 152 |
If the referent is a function that is debuggee code, a |
| 153 |
[`Debugger.Environment`][environment] instance representing the lexical |
| 154 |
environment enclosing the function when it was created. If the referent |
| 155 |
is a function proxy or not debuggee code, this is `undefined`. |
| 156 |
|
| 157 |
### `isError` |
| 158 |
`true` if the referent is any potentially wrapped Error; `false` otherwise. |
| 159 |
|
| 160 |
### `isMutedError` |
| 161 |
`true` if the referent is any potentially wrapped Error associated with a muted |
| 162 |
error report; `false` otherwise. |
| 163 |
|
| 164 |
### `errorMessageName` |
| 165 |
If the referent is an error created with an engine internal message template |
| 166 |
this is a string which is the name of the template; `undefined` otherwise. |
| 167 |
|
| 168 |
### `errorLineNumber` |
| 169 |
If the referent is an Error object, this is the 1-origin line number at which |
| 170 |
the referent was created; `undefined` otherwise. |
| 171 |
|
| 172 |
### `errorColumnNumber` |
| 173 |
If the referent is an Error object, this is the 1-origin column number in |
| 174 |
UTF-16 code units at which the referent was created; `undefined` otherwise. |
| 175 |
|
| 176 |
### `isBoundFunction` |
| 177 |
If the referent is a debuggee function, returns `true` if the referent is a |
| 178 |
bound function; `false` otherwise. If the referent is not a debuggee |
| 179 |
function, or not a function at all, returns `undefined` instead. |
| 180 |
|
| 181 |
### `isArrowFunction` |
| 182 |
If the referent is a debuggee function, returns `true` if the referent is an |
| 183 |
arrow function; `false` otherwise. If the referent is not a debuggee |
| 184 |
function, or not a function at all, returns `undefined` instead. |
| 185 |
|
| 186 |
### `isGeneratorFunction` |
| 187 |
If the referent is a debuggee function, returns `true` if the referent was |
| 188 |
created with a `function*` expression or statement, or false if it is some |
| 189 |
other sort of function. If the referent is not a debuggee function, or not a |
| 190 |
function at all, this is `undefined`. (This is always equal to |
| 191 |
`obj.script.isGeneratorFunction`, assuming `obj.script` is a |
| 192 |
`Debugger.Script`.) |
| 193 |
|
| 194 |
### `isAsyncFunction` |
| 195 |
If the referent is a debuggee function, returns `true` if the referent is an |
| 196 |
async function, defined with an `async function` expression or statement, or |
| 197 |
false if it is some other sort of function. If the referent is not a |
| 198 |
debuggee function, or not a function at all, this is `undefined`. (This is |
| 199 |
always equal to `obj.script.isAsyncFunction`, assuming `obj.script` is a |
| 200 |
`Debugger.Script`.) |
| 201 |
|
| 202 |
### `isClassConstructor` |
| 203 |
If the referent is a debuggee function, returns `true` if the referent is a class, |
| 204 |
or false if it is some other sort of function. If the referent is not a debuggee |
| 205 |
function, or not a function at all, this is `undefined`. (This is always equal to |
| 206 |
`obj.script.isClassConstructor`, assuming `obj.script` is a `Debugger.Script`.) |
| 207 |
|
| 208 |
### `isPromise` |
| 209 |
`true` if the referent is a Promise; `false` otherwise. |
| 210 |
|
| 211 |
### `boundTargetFunction` |
| 212 |
If the referent is a bound debuggee function, this is its target function— |
| 213 |
the function that was bound to a particular `this` object. If the referent |
| 214 |
is either not a bound function, not a debuggee function, or not a function |
| 215 |
at all, this is `undefined`. |
| 216 |
|
| 217 |
### `boundThis` |
| 218 |
If the referent is a bound debuggee function, this is the `this` value it |
| 219 |
was bound to. If the referent is either not a bound function, not a debuggee |
| 220 |
function, or not a function at all, this is `undefined`. |
| 221 |
|
| 222 |
### `boundArguments` |
| 223 |
If the referent is a bound debuggee function, this is an array (in the |
| 224 |
Debugger object's compartment) that contains the debuggee values of the |
| 225 |
`arguments` object it was bound to. If the referent is either not a bound |
| 226 |
function, not a debuggee function, or not a function at all, this is |
| 227 |
`undefined`. |
| 228 |
|
| 229 |
### `isProxy` |
| 230 |
If the referent is a (scripted) proxy, either revoked or not, return `true`. |
| 231 |
If the referent is not a (scripted) proxy, return `false`. |
| 232 |
|
| 233 |
### `proxyTarget` |
| 234 |
If the referent is a non-revoked (scripted) proxy, return a `Debugger.Object` |
| 235 |
instance referring to the ECMAScript `[[ProxyTarget]]` of the referent. |
| 236 |
If the referent is a revoked (scripted) proxy, return `null`. |
| 237 |
If the referent is not a (scripted) proxy, return `undefined`. |
| 238 |
|
| 239 |
### `proxyHandler` |
| 240 |
If the referent is a non-revoked (scripted) proxy, return a `Debugger.Object` |
| 241 |
instance referring to the ECMAScript `[[ProxyHandler]]` of the referent. |
| 242 |
If the referent is a revoked (scripted) proxy, return `null`. |
| 243 |
If the referent is not a (scripted) proxy, return `undefined`. |
| 244 |
|
| 245 |
### `promiseState` |
| 246 |
If the referent is a [`Promise`][promise], return a string indicating |
| 247 |
whether the [`Promise`][promise] is pending, or has been fulfilled or |
| 248 |
rejected. This string takes one of the following values: |
| 249 |
|
| 250 |
* `"pending"`, if the [`Promise`][promise] is pending. |
| 251 |
|
| 252 |
* `"fulfilled"`, if the [`Promise`][promise] has been fulfilled. |
| 253 |
|
| 254 |
* `"rejected"`, if the [`Promise`][promise] has been rejected. |
| 255 |
|
| 256 |
If the referent is not a [`Promise`][promise], throw a `TypeError`. |
| 257 |
|
| 258 |
### `promiseValue` |
| 259 |
Return a debuggee value representing the value the [`Promise`][promise] has |
| 260 |
been fulfilled with. |
| 261 |
|
| 262 |
If the referent is not a [`Promise`][promise], or the [`Promise`][promise] |
| 263 |
has not been fulfilled, throw a `TypeError`. |
| 264 |
|
| 265 |
### `promiseReason` |
| 266 |
Return a debuggee value representing the value the [`Promise`][promise] has |
| 267 |
been rejected with. |
| 268 |
|
| 269 |
If the referent is not a [`Promise`][promise], or the [`Promise`][promise] |
| 270 |
has not been rejected, throw a `TypeError`. |
| 271 |
|
| 272 |
### `promiseAllocationSite` |
| 273 |
If the referent is a [`Promise`][promise], this is the |
| 274 |
[JavaScript execution stack][saved-frame] captured at the time of the |
| 275 |
promise's allocation. This can return null if the promise was not |
| 276 |
created from script. If the referent is not a [`Promise`][promise], throw |
| 277 |
a `TypeError` exception. |
| 278 |
|
| 279 |
### `promiseResolutionSite` |
| 280 |
If the referent is a [`Promise`][promise], this is the |
| 281 |
[JavaScript execution stack][saved-frame] captured at the time of the |
| 282 |
promise's resolution. This can return null if the promise was not |
| 283 |
resolved by calling its `resolve` or `reject` resolving functions from |
| 284 |
script. If the referent is not a [`Promise`][promise], throw a `TypeError` |
| 285 |
exception. |
| 286 |
|
| 287 |
### `promiseID` |
| 288 |
If the referent is a [`Promise`][promise], this is a process-unique |
| 289 |
identifier for the [`Promise`][promise]. With e10s, the same id can |
| 290 |
potentially be assigned to multiple [`Promise`][promise] instances, if |
| 291 |
those instances were created in different processes. If the referent is |
| 292 |
not a [`Promise`][promise], throw a `TypeError` exception. |
| 293 |
|
| 294 |
### `promiseDependentPromises` |
| 295 |
If the referent is a [`Promise`][promise], this is an `Array` of |
| 296 |
`Debugger.Objects` referring to the promises directly depending on the |
| 297 |
referent [`Promise`][promise]. These are: |
| 298 |
|
| 299 |
1) Return values of `then()` calls on the promise. |
| 300 |
2) Return values of `Promise.all()` if the referent [`Promise`][promise] |
| 301 |
was passed in as one of the arguments. |
| 302 |
3) Return values of `Promise.race()` if the referent [`Promise`][promise] |
| 303 |
was passed in as one of the arguments. |
| 304 |
|
| 305 |
Once a [`Promise`][promise] is settled, it will generally notify its |
| 306 |
dependent promises and forget about them, so this is most useful on |
| 307 |
*pending* promises. |
| 308 |
|
| 309 |
Note that the `Array` only contains the promises that directly depend on |
| 310 |
the referent [`Promise`][promise]. It does not contain promises that depend |
| 311 |
on promises that depend on the referent [`Promise`][promise]. |
| 312 |
|
| 313 |
If the referent is not a [`Promise`][promise], throw a `TypeError` |
| 314 |
exception. |
| 315 |
|
| 316 |
### `promiseLifetime` |
| 317 |
If the referent is a [`Promise`][promise], this is the number of |
| 318 |
milliseconds elapsed since the [`Promise`][promise] was created. If the |
| 319 |
referent is not a [`Promise`][promise], throw a `TypeError` exception. |
| 320 |
|
| 321 |
### `promiseTimeToResolution` |
| 322 |
If the referent is a [`Promise`][promise], this is the number of |
| 323 |
milliseconds elapsed between when the [`Promise`][promise] was created and |
| 324 |
when it was resolved. If the referent hasn't been resolved or is not a |
| 325 |
[`Promise`][promise], throw a `TypeError` exception. |
| 326 |
|
| 327 |
### `allocationSite` |
| 328 |
If [object allocation site tracking][tracking-allocs] was enabled when this |
| 329 |
`Debugger.Object`'s referent was allocated, return the |
| 330 |
[JavaScript execution stack][saved-frame] captured at the time of the |
| 331 |
allocation. Otherwise, return `null`. |
| 332 |
|
| 333 |
|
| 334 |
## Function Properties of the Debugger.Object prototype |
| 335 |
|
| 336 |
The functions described below may only be called with a `this` value |
| 337 |
referring to a `Debugger.Object` instance; they may not be used as methods |
| 338 |
of other kinds of objects. The descriptions use "referent" to mean "the |
| 339 |
referent of this `Debugger.Object` instance". |
| 340 |
|
| 341 |
Unless otherwise specified, these methods are not |
| 342 |
[invocation functions][inv fr]; if a call would cause debuggee code to run |
| 343 |
(say, because it gets or sets an accessor property whose handler is |
| 344 |
debuggee code, or because the referent is a proxy whose traps are debuggee |
| 345 |
code), the call throws a [`Debugger.DebuggeeWouldRun`][wouldrun] exception. |
| 346 |
|
| 347 |
These methods may throw if the referent is not a native object. Even simple |
| 348 |
accessors like `isExtensible` may throw if the referent is a proxy or some sort |
| 349 |
of exotic object like an opaque wrapper. |
| 350 |
|
| 351 |
### `getProperty(key, [receiver])` |
| 352 |
Return a [completion value][cv] with "return" being the value of the |
| 353 |
referent's property named <i>key</i>, or `undefined` if it has no such |
| 354 |
property. <i>key</i> must be a string or symbol; <i>receiver</i> must be |
| 355 |
a debuggee value. If the property is a getter, it will be evaluated with |
| 356 |
<i>receiver</i> as the receiver, defaulting to the `Debugger.Object` |
| 357 |
if omitted. All extant handler methods, breakpoints, and so on remain |
| 358 |
active during the call. |
| 359 |
|
| 360 |
### `setProperty(key, value<, [receiver])` |
| 361 |
Store <i>value</i> as the value of the referent's property named |
| 362 |
<i>key</i>, creating the property if it does not exist. <i>key</i> |
| 363 |
must be a string or symbol; <i>value</i> and <i>receiver</i> must be |
| 364 |
debuggee values. If the property is a setter, it will be evaluated with |
| 365 |
<i>receiver</i> as the receiver, defaulting to the `Debugger.Object` |
| 366 |
if omitted. Return a [completion value][cv] with "return" being a |
| 367 |
success/failure boolean, or else "throw" being the exception thrown |
| 368 |
during property assignment. All extant handler methods, breakpoints, |
| 369 |
and so on remain active during the call. |
| 370 |
|
| 371 |
### `getOwnPropertyDescriptor(key)` |
| 372 |
Return a property descriptor for the property named <i>key</i> of the |
| 373 |
referent. If the referent has no such property, return `undefined`. |
| 374 |
(This function behaves like the standard |
| 375 |
`Object.getOwnPropertyDescriptor` function, except that the object being |
| 376 |
inspected is implicit; the property descriptor returned is allocated as |
| 377 |
if by code scoped to the debugger's global object (and is thus in the |
| 378 |
debugger's compartment); and its `value`, `get`, and `set` properties, |
| 379 |
if present, are debuggee values.) |
| 380 |
|
| 381 |
### `getOwnPropertyNames()` |
| 382 |
Return an array of strings naming all the referent's own properties, as |
| 383 |
if <code>Object.getOwnPropertyNames(<i>referent</i>)</code> had been |
| 384 |
called in the debuggee, and the result copied in the scope of the |
| 385 |
debugger's global object. |
| 386 |
|
| 387 |
### `getOwnPropertyNamesLength()` |
| 388 |
Return the number of the referent's own properties. |
| 389 |
|
| 390 |
### `getOwnPropertySymbols()` |
| 391 |
Return an array of strings naming all the referent's own symbols, as |
| 392 |
if <code>Object.getOwnPropertySymbols(<i>referent</i>)</code> had been |
| 393 |
called in the debuggee, and the result copied in the scope of the |
| 394 |
debugger's global object. |
| 395 |
|
| 396 |
### `defineProperty(key, attributes)` |
| 397 |
Define a property on the referent named <i>key</i>, as described by |
| 398 |
the property descriptor <i>descriptor</i>. Any `value`, `get`, and |
| 399 |
`set` properties of <i>attributes</i> must be debuggee values. (This |
| 400 |
function behaves like `Object.defineProperty`, except that the target |
| 401 |
object is implicit, and in a different compartment from the function |
| 402 |
and descriptor.) |
| 403 |
|
| 404 |
### `defineProperties(properties)` |
| 405 |
Add the properties given by <i>properties</i> to the referent. (This |
| 406 |
function behaves like `Object.defineProperties`, except that the target |
| 407 |
object is implicit, and in a different compartment from the |
| 408 |
<i>properties</i> argument.) |
| 409 |
|
| 410 |
### `deleteProperty(key)` |
| 411 |
Remove the referent's property named <i>key</i>. Return true if the |
| 412 |
property was successfully removed, or if the referent has no such |
| 413 |
property. Return false if the property is non-configurable. |
| 414 |
|
| 415 |
### `seal()` |
| 416 |
Prevent properties from being added to or deleted from the referent. |
| 417 |
Return this `Debugger.Object` instance. (This function behaves like the |
| 418 |
standard `Object.seal` function, except that the object to be sealed is |
| 419 |
implicit and in a different compartment from the caller.) |
| 420 |
|
| 421 |
### `freeze()` |
| 422 |
Prevent properties from being added to or deleted from the referent, and |
| 423 |
mark each property as non-writable. Return this `Debugger.Object` |
| 424 |
instance. (This function behaves like the standard `Object.freeze` |
| 425 |
function, except that the object to be sealed is implicit and in a |
| 426 |
different compartment from the caller.) |
| 427 |
|
| 428 |
### `preventExtensions()` |
| 429 |
Prevent properties from being added to the referent. (This function |
| 430 |
behaves like the standard `Object.preventExtensions` function, except |
| 431 |
that the object to operate on is implicit and in a different compartment |
| 432 |
from the caller.) |
| 433 |
|
| 434 |
### `isSealed()` |
| 435 |
Return true if the referent is sealed—that is, if it is not extensible, |
| 436 |
and all its properties have been marked as non-configurable. (This |
| 437 |
function behaves like the standard `Object.isSealed` function, except |
| 438 |
that the object inspected is implicit and in a different compartment |
| 439 |
from the caller.) |
| 440 |
|
| 441 |
### `isFrozen()` |
| 442 |
Return true if the referent is frozen—that is, if it is not extensible, |
| 443 |
and all its properties have been marked as non-configurable and |
| 444 |
read-only. (This function behaves like the standard `Object.isFrozen` |
| 445 |
function, except that the object inspected is implicit and in a |
| 446 |
different compartment from the caller.) |
| 447 |
|
| 448 |
### `isExtensible()` |
| 449 |
Return true if the referent is extensible—that is, if it can have new |
| 450 |
properties defined on it. (This function behaves like the standard |
| 451 |
`Object.isExtensible` function, except that the object inspected is |
| 452 |
implicit and in a different compartment from the caller.) |
| 453 |
|
| 454 |
### `makeDebuggeeValue(value)` |
| 455 |
Return the debuggee value that represents <i>value</i> in the debuggee. |
| 456 |
If <i>value</i> is a primitive, we return it unchanged; if <i>value</i> |
| 457 |
is an object, we return the `Debugger.Object` instance representing |
| 458 |
that object, wrapped appropriately for use in this `Debugger.Object`'s |
| 459 |
referent's compartment. |
| 460 |
|
| 461 |
Note that, if <i>value</i> is an object, it need not be one allocated |
| 462 |
in a debuggee global, nor even a debuggee compartment; it can be any |
| 463 |
object the debugger wishes to use as a debuggee value. |
| 464 |
|
| 465 |
As described above, each `Debugger.Object` instance presents its |
| 466 |
referent as viewed from a particular compartment. Given a |
| 467 |
`Debugger.Object` instance <i>d</i> and an object <i>o</i>, the call |
| 468 |
<code><i>d</i>.makeDebuggeeValue(<i>o</i>)</code> returns a |
| 469 |
`Debugger.Object` instance that presents <i>o</i> as it would be seen |
| 470 |
by code in <i>d</i>'s compartment. |
| 471 |
|
| 472 |
### `isSameNative(value)` |
| 473 |
If <i>value</i> is a native function in the debugger's compartment, return |
| 474 |
whether the referent is a native function for the same C++ native. |
| 475 |
|
| 476 |
### `isSameNativeWithJitInfo(value)` |
| 477 |
If <i>value</i> is a native function in the debugger's compartment, return |
| 478 |
whether the referent is a native function for the same C++ native with the |
| 479 |
same JSJitInfo pointer value. |
| 480 |
|
| 481 |
This can be used to distinguish functions with shared native function |
| 482 |
implementation with different JSJitInfo pointer to define the underlying |
| 483 |
functionality. |
| 484 |
|
| 485 |
### `isNativeGetterWithJitInfo()` |
| 486 |
Return whether the referent is a native getter function with JSJitInfo. |
| 487 |
|
| 488 |
### `decompile([pretty])` |
| 489 |
If the referent is a function that is debuggee code, return the |
| 490 |
JavaScript source code for a function definition equivalent to the |
| 491 |
referent function in its effect and result, as a string. If |
| 492 |
<i>pretty</i> is present and `true`, produce indented code with line |
| 493 |
breaks. If the referent is not a function that is debuggee code, return |
| 494 |
`undefined`. |
| 495 |
|
| 496 |
### `call(this, argument, ...)` |
| 497 |
If the referent is callable, call it with the given <i>this</i> value |
| 498 |
and <i>argument</i> values, and return a [completion value][cv] |
| 499 |
describing how the call completed. <i>This</i> should be a debuggee |
| 500 |
value, or `{ asConstructor: true }` to invoke the referent as a |
| 501 |
constructor, in which case SpiderMonkey provides an appropriate `this` |
| 502 |
value itself. Each <i>argument</i> must be a debuggee value. All extant |
| 503 |
handler methods, breakpoints, and so on remain active |
| 504 |
during the call. If the referent is not callable, throw a `TypeError`. |
| 505 |
This function follows the [invocation function conventions][inv fr]. |
| 506 |
|
| 507 |
Note: If this method is called on an object whose owner |
| 508 |
[Debugger object][debugger-object] has an onNativeCall handler, only hooks |
| 509 |
on objects associated with that debugger will be called during the evaluation. |
| 510 |
|
| 511 |
### `apply(this, arguments)` |
| 512 |
If the referent is callable, call it with the given <i>this</i> value |
| 513 |
and the argument values in <i>arguments</i>, and return a |
| 514 |
[completion value][cv] describing how the call completed. <i>This</i> |
| 515 |
should be a debuggee value, or `{ asConstructor: true }` to invoke |
| 516 |
<i>function</i> as a constructor, in which case SpiderMonkey provides |
| 517 |
an appropriate `this` value itself. <i>Arguments</i> must either be an |
| 518 |
array (in the debugger) of debuggee values, or `null` or `undefined`, |
| 519 |
which are treated as an empty array. All extant handler methods, |
| 520 |
breakpoints, and so on remain active during the call. If |
| 521 |
the referent is not callable, throw a `TypeError`. This function |
| 522 |
follows the [invocation function conventions][inv fr]. |
| 523 |
|
| 524 |
Note: If this method is called on an object whose owner |
| 525 |
[Debugger object][debugger-object] has an onNativeCall handler, only hooks |
| 526 |
on objects associated with that debugger will be called during the evaluation. |
| 527 |
|
| 528 |
### `executeInGlobal(code, [options])` |
| 529 |
If the referent is a global object, evaluate <i>code</i> in that global |
| 530 |
environment, and return a [completion value][cv] describing how it completed. |
| 531 |
<i>Code</i> is a string. All extant handler methods, breakpoints, |
| 532 |
and so on remain active during the call (pending note below). This function |
| 533 |
follows the [invocation function conventions][inv fr]. |
| 534 |
If the referent is not a global object, throw a `TypeError` exception. |
| 535 |
|
| 536 |
<i>Code</i> is interpreted as strict mode code when it contains a Use |
| 537 |
Strict Directive. |
| 538 |
|
| 539 |
This evaluation is semantically equivalent to executing statements at the |
| 540 |
global level, not an indirect eval. Regardless of <i>code</i> being strict |
| 541 |
mode code, variable declarations in <i>code</i> affect the referent global |
| 542 |
object. |
| 543 |
|
| 544 |
The <i>options</i> argument is as for [`Debugger.Frame.prototype.eval`][fr eval]. |
| 545 |
|
| 546 |
Note: If this method is called on an object whose owner |
| 547 |
[Debugger object][debugger-object] has an onNativeCall handler, only hooks |
| 548 |
on objects associated with that debugger will be called during the evaluation. |
| 549 |
|
| 550 |
### `executeInGlobalWithBindings(code, bindings, [options])` |
| 551 |
Like `executeInGlobal`, but evaluate <i>code</i> using the referent as the |
| 552 |
variable object, but with a lexical environment extended with bindings |
| 553 |
from the object <i>bindings</i>. |
| 554 |
|
| 555 |
An extra environment is created with bindings specified by <i>bindings</i>. |
| 556 |
The environment contains bindings corresponding to each own enumerable property |
| 557 |
of <i>bindings</i>, where the property name <i>name</i> as binding name, |
| 558 |
and the property value <i>value</i> as binding's initial value. |
| 559 |
|
| 560 |
If `options.useInnerBindings` is not specified or is specified as `false`, |
| 561 |
it emulates where the bindings environment is placed outside of global, |
| 562 |
which means, if the binding conflicts with any global variable declared in |
| 563 |
the <i>code</i>, or any existing global variable, the binding is ignored. |
| 564 |
|
| 565 |
If `options.useInnerBindings` is speified as `true`, it directly performs as |
| 566 |
the bindings environment is placed inside the global, and the provided bindings |
| 567 |
shadow the global variables. |
| 568 |
|
| 569 |
Each <i>value</i> must be a debuggee value. |
| 570 |
|
| 571 |
This is not like a `with` statement: <i>code</i> may access, assign to, and |
| 572 |
delete the introduced bindings without having any effect on the passed |
| 573 |
<i>bindings</i> object, because the properties are copied to a new object for |
| 574 |
each invocation. |
| 575 |
|
| 576 |
This method allows debugger code to introduce temporary bindings that |
| 577 |
are visible to the given debuggee code and which refer to debugger-held |
| 578 |
debuggee values, and do so without mutating any existing debuggee |
| 579 |
environment. |
| 580 |
|
| 581 |
Note that, like `executeInGlobal`, any declarations it contains affect the |
| 582 |
referent global object, even as <i>code</i> is evaluated in an environment |
| 583 |
extended according to <i>bindings</i>. (In the terms used by the ECMAScript |
| 584 |
specification, the `VariableEnvironment` of the execution context for |
| 585 |
<i>code</i> is the referent, and the <i>bindings</i> appear in a new |
| 586 |
declarative environment, which is the eval code's `LexicalEnvironment`.) |
| 587 |
|
| 588 |
The <i>options</i> argument is as for [`Debugger.Frame.prototype.eval`][fr eval]. |
| 589 |
|
| 590 |
Note: If this method is called on an object whose owner |
| 591 |
[Debugger object][debugger-object] has an onNativeCall handler, only hooks |
| 592 |
on objects associated with that debugger will be called during the evaluation. |
| 593 |
|
| 594 |
### `createSource(options)` |
| 595 |
If the referent is a global object, return a new JavaScript source in the |
| 596 |
global's realm which has its properties filled in according to the `options` |
| 597 |
object. If the referent is not a global object, throw a `TypeError` |
| 598 |
exception. The `options` object can have the following properties: |
| 599 |
* `text`: String contents of the JavaScript in the source. |
| 600 |
* `url`: URL the resulting source should be associated with. |
| 601 |
* `startLine`: Starting line of the source. |
| 602 |
* `startColumn`: Starting column of the source. |
| 603 |
* `sourceMapURL`: Optional URL specifying the source's source map URL. |
| 604 |
If not specified, the source map URL can be filled in if specified by |
| 605 |
the source's text. |
| 606 |
* `isScriptElement`: Optional boolean which will set the source's |
| 607 |
`introductionType` to `"inlineScript"` if specified. Otherwise, the |
| 608 |
source's `introductionType` will be `undefined`. |
| 609 |
* `forceEnableAsmJS`: Optional boolean to force enable the asm.js feature. |
| 610 |
Unless specified, asm.js is disabled by default in the debuggee global. |
| 611 |
This option can be used when the createSource is used for recompiling the |
| 612 |
top-level script, where the script contains asm.js functions and the asm.js |
| 613 |
was enabled at the first compilation, and the consumer doesn't want the |
| 614 |
asm.js functions being compiled as regular JS functions. |
| 615 |
|
| 616 |
### `asEnvironment()` |
| 617 |
If the referent is a global object, return the [`Debugger.Environment`][environment] |
| 618 |
instance representing the referent's global lexical scope. The global |
| 619 |
lexical scope's enclosing scope is the global object. If the referent is |
| 620 |
not a global object, throw a `TypeError`. |
| 621 |
|
| 622 |
### `unwrap()` |
| 623 |
If the referent is a wrapper that this `Debugger.Object`'s compartment |
| 624 |
is permitted to unwrap, return a `Debugger.Object` instance referring to |
| 625 |
the wrapped object. If we are not permitted to unwrap the referent, |
| 626 |
return `null`. If the referent is not a wrapper, return this |
| 627 |
`Debugger.Object` instance unchanged. |
| 628 |
|
| 629 |
### `unsafeDereference()` |
| 630 |
Return the referent of this `Debugger.Object` instance. |
| 631 |
|
| 632 |
If the referent is an inner object (say, an HTML5 `Window` object), |
| 633 |
return the corresponding outer object (say, the HTML5 `WindowProxy` |
| 634 |
object). This makes `unsafeDereference` more useful in producing values |
| 635 |
appropriate for direct use by debuggee code, without using [invocation functions][inv fr]. |
| 636 |
|
| 637 |
This method pierces the membrane of `Debugger.Object` instances meant to |
| 638 |
protect debugger code from debuggee code, and allows debugger code to |
| 639 |
access debuggee objects through the standard cross-compartment wrappers, |
| 640 |
rather than via `Debugger.Object`'s reflection-oriented interfaces. This |
| 641 |
method makes it easier to gradually adapt large code bases to this |
| 642 |
Debugger API: adapted portions of the code can use `Debugger.Object` |
| 643 |
instances, but use this method to pass direct object references to code |
| 644 |
that has not yet been updated. |
| 645 |
|
| 646 |
### `forceLexicalInitializationByName(binding)` |
| 647 |
If <i>binding</i> is in an uninitialized state initialize it to undefined |
| 648 |
and return true, otherwise do nothing and return false. |
| 649 |
|
| 650 |
### `getPromiseReactions` |
| 651 |
|
| 652 |
If the referent is a [`Promise`][promise] or a cross-compartment wrapper of one, |
| 653 |
this returns an array of objects describing the reaction records added to the |
| 654 |
promise. There are several different sorts of reaction records: |
| 655 |
|
| 656 |
- The array entry for a reaction record added with `then` or `catch` has the |
| 657 |
form `{ resolve: F, reject: F, result: P }`, where each `F` is a `Debugger.Object` |
| 658 |
referring to a function object, and `P` is the promise that will be resolved |
| 659 |
with the result of calling them. |
| 660 |
|
| 661 |
The `resolve` and `reject` properties may be absent in some cases. A call to |
| 662 |
`then` can omit the rejection handler, and a call to `catch` omits the |
| 663 |
resolution handler. Furthermore, various promise facilities create records |
| 664 |
like this as internal implementation details, creating handlers that are not |
| 665 |
representable as JavaScript functions. |
| 666 |
|
| 667 |
- When a promise `P1` is resolved to another promise `P2` (such that resolving |
| 668 |
`P2` resolves `P1` in the same way) that adds a reaction record to `P2`. The |
| 669 |
array entry for that reaction record is simply the `Debugger.Object` |
| 670 |
representing `P1`. |
| 671 |
|
| 672 |
Note that, if `P1` and `P2` are in different compartments, resolving `P1` to |
| 673 |
`P2` creates the same sort of reaction record as a call to `then` or |
| 674 |
`catch`, with `P1` stored only in a private slot of the `resolve` and |
| 675 |
`reject` functions, and not directly available from the reaction record. |
| 676 |
|
| 677 |
- An `await` expression calls `PromiseResolve` on its operand to obtain a |
| 678 |
promise `P`, and then adds a reaction record to `P` that resumes the |
| 679 |
suspended call appropriately. The array entry for that reaction record is a |
| 680 |
`Debugger.Frame` representing the suspended call. |
| 681 |
|
| 682 |
If the `await`'s operand `A` is a native promise with the standard |
| 683 |
constructor, then `PromiseResolve` simply returns `A` unchanged, and the |
| 684 |
reaction record for resuming the suspended call is added to `A`'s list. But |
| 685 |
if `A` is some other sort of 'thenable', then `PromiseResolve` creates a new |
| 686 |
promise and enqueues a job to call `A`'s `then` method; this may produce |
| 687 |
more indirect chains from awaitees to awaiters. |
| 688 |
|
| 689 |
- `JS::AddPromiseReactions` and |
| 690 |
`JS::AddPromiseReactionsIgnoringUnhandledRejection` create a reaction record |
| 691 |
whose promise field is `null`. |
| 692 |
|
| 693 |
[debugger-object]: Debugger.md |
| 694 |
[script]: Debugger.Script.md |
| 695 |
[environment]: Debugger.Environment.md |
| 696 |
[promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise |
| 697 |
[saved-frame]: ../SavedFrame/index |
| 698 |
|
| 699 |
[tracking-allocs]: Debugger.Memory.md#trackingallocationsites |
| 700 |
[inv fr]: Debugger.Frame.md#invocation-functions-and-debugger-frames |
| 701 |
[wouldrun]: Conventions.md#the-debugger-debuggeewouldrun-exception |
| 702 |
[cv]: Conventions.md#completion-values |
| 703 |
[fr eval]: Debugger.Frame.md#eval-code-options |