code or the serialized text of a block of WebAssembly code. The two cases are
distinguished by the latter having its
introductionType property always
"wasm" and the former having its
introductionType property never
Debugger instance has a separate collection of
Debugger.Source instances representing the source code that has been
presented to the system.
A debugger may place its own properties on
to store metadata about particular pieces of source code.
code, its properties provide the source code itself as a string, and describe
where it came from. Each
Debugger.Script instance refers to the
Debugger.Source instance holding the source code from which it was produced.
If a single piece of source code contains both top-level code and
function definitions, perhaps with nested functions, then the
Debugger.Script instances for those all refer to the same
Debugger.Source instance. Each script indicates the substring of the
overall source to which it corresponds.
Debugger.Source instance may represent only a portion of a larger
<script> elements and event handler content attributes.
In this case, there may be either a single
for the entire HTML document, with each
Debugger.Script referring to
its substring of the document; or there may be a separate
Debugger.Source instance for each
<script> element and
attribute. The choice is left up to the implementation.
implementation more than once, with the same origin metadata, the
instance to represent each presentation, or it may use a single
Debugger.Source instance to represent them all.
Debugger.Source for WebAssembly¶
Debugger.Source instance representing the serialized text of a block
of WebAssembly code, its properties provide the serialized text as a string.
Currently only entire modules evaluated via
new WebAssembly.Module are
represented. SpiderMonkey constructs exactly one
Debugger.Source for each
underlying WebAssembly module per
Please note at the time of this writing, support for WebAssembly is very preliminary. Many properties below return placeholder values.
Accessor Properties of the Debugger.Source Prototype Object¶
Debugger.Source instance inherits the following accessor properties
from its prototype:
code, as a string. The value satisfies the
FunctionExpression productions in the
If the instance refers to WebAssembly code, the
"[wasm]" value will
If the instance refers to WebAssembly code, a Uint8Array that contains the WebAssembly bytecode.
which this script’s code was loaded. For scripts created by
eval or the
Function constructor, this may be a synthesized filename, starting with a
valid URL and followed by information tracking how the code was introduced
into the system; the entire string is not a valid URL. For
Function.prototype’s script, this is
null. Source may be loaded from a
URL in the following ways:
The URL may appear as the
srcattribute of a
<script>element in markup text.
The URL may be passed to the
Workerweb worker constructor, or the web worker
(Note that code passed to
Function constructor, or a
similar function is not considered to be loaded from a URL; the
url accessor on
Debugger.Source instances for such sources should
If the instance refers to WebAssembly code, the URL of the script that
new WebAssembly.Module with the string
"> wasm" appended.
source within the file or URL it was loaded from. This is normally
may have another value if the source is part of an HTML document.
produced by a minimizer or translated from some other language, and we
know the URL of a source map document relating the source positions
in this source to the corresponding source positions in the original
source, then this property’s value is that URL. Otherwise, this is
This property is writable, so you can change the source map URL by setting it. All Debugger.Source objects referencing the same source will see the change. Setting an empty string has no effect and will not change existing value.
If the instance refers to WebAssembly code,
null. Attempts to write
to this property throw a
If the script had a special
//# sourceURL comment, as described in
the source maps specification, then this property’s value holds
the string that was given. Otherwise, this is
Debugger.Object instance referring to the DOM element to which
this source code belongs, if any, or
undefined if it belongs to no DOM
element. Source belongs to a DOM element in the following cases:
Source belongs to a
<script>element if it is the element’s text content (that is, it is written out as the body of the
<script>element in the markup text), or is the source document referenced by its
Source belongs to a DOM element if it is an event handler content attribute (that is, if it is written out in the markup text as an attribute value).
Source belongs to a DOM element if it was assigned to one of the element’s event handler IDL attributes as a string. (Note that one may assign both strings and functions to DOM elements’ event handler IDL attributes. If one assigns a function, that function’s script’s source does not belong to the DOM element; the function’s definition must appear elsewhere.)
(If the sources attached to a DOM element change, the
instances representing superseded code still refer to the DOM element;
this accessor only reflects origins, not current relationships.)
If this source belongs to a DOM element because it is an event handler
content attribute or an event handler IDL attribute, this is the name of
that attribute, a string. Otherwise, this is
"eval", for code passed to
"debugger eval", for code evaluated by debugger.
"Function", for code passed to the
"GeneratorFunction", for code passed to the generator constructor.
"AsyncFunction", for code passed to the async function constructor.
"AsyncGenerator", for code passed to the async generator constructor.
"Worklet", for code loaded by worklet.
"importScripts", for code by calling
importScriptsin a web worker.
"eventHandler", for code assigned to DOM elements’ event handler IDL attributes as a string.
"srcScript", for code belonging to
"inlineScript", for code belonging to
"injectedScript", for code belonging to scripts that would be
"inlineScript"except that they were not part of the initial file itself.
For example, scripts created via:
var s = document.createElement("script"); s.text = "code";
"importedModule", for code that was loaded indirectly by being imported by another script using ESM static or dynamic imports.
"domTimer", for code passed to
setIntervalas a string.
"self-hosted", for internal self-hosted JS code.
undefined, if the implementation doesn’t know how the code was introduced.
If the instance refers to WebAssembly code,
introduced by calling a function from debuggee code, then
introductionScript is the
Debugger.Script instance referring
to the script containing that call, and
introductionOffset is the call’s
bytecode offset within that script. Otherwise, these are both
Taken together, these properties indicate the location of the introducing
For the purposes of these accessors, assignments to accessor properties are
treated as function calls. Thus, setting a DOM element’s event handler IDL
introductionOffset refer to the
<script> element parsed from a web page’s original HTML was not
introduced by any scripted call, its source’s
introductionOffset accessors both return
<script> element was dynamically inserted into a document, then these
accessors refer to the call that actually caused the script to run—usually
the call that made the element part of the document. Thus, they do
not refer to the call that created the element; stored the source as
the element’s text child; made the element a child of some uninserted parent
node that was later inserted; or the like.
Although the main script of a worker thread is introduced by a call to
SharedWorker, these accessors always return
such script’s sources. A worker’s main script source and the call that
created the worker are always in separate threads, but
Debugger is an inherently single-threaded facility: its
debuggees must all run in the same thread. Since the global that created the
worker is in a different thread, it is guaranteed not to be a debuggee of
Debugger instance that owns this source; and thus
the creating call is never “in debuggee code”. Relating a worker to its
creator, and other multi-threaded debugging concerns, are out of scope for
If the instance refers to WebAssembly code,
Debugger.Script instance referring to the same underlying
Function Properties of the Debugger.Source Prototype Object¶
The functions described below may only be called with a
referring to a
Debugger.Source instance; they may not be used as
methods of other kinds of objects.
available, return a
Debugger.Script instance referring to a new script
created by reparsing this source’s text. Debugger
onNewScript hooks will
not be invoked for the new script. Otherwise, throw an