If IsIncrementalGCInProgress(cx), this call aborts the ongoing collection and
performs whatever work needs to be done to return the collector to its idle
state. This may take an arbitrarily long time. When this function returns,
IsIncrementalGCInProgress(cx) will always be false.
Advise the GC of external memory owned by a JSObject. This is used to
determine when to collect zones. Calls must be matched by calls to
RemoveAssociatedMemory() when the memory is deallocated or no longer owned by
the object.
Add and remove nursery collection callbacks for the given runtime. These will
be called at the start and end of every nursery collection.
Unforgeable, optimized version of the JS builtin Promise.prototype.then.
Unforgeable, optimized version of the JS builtin Promise.prototype.then.
Copy data from one array buffer to another.
Copy data from one array buffer to another.
Return true if the ArrayBuffer |obj| contains any data, i.e. it is not a
detached ArrayBuffer. (ArrayBuffer.prototype is not an ArrayBuffer.)
Asserts (in debug and release builds) that obj
belongs to the current
thread’s context.
Same as BigIntFits(), but checks if the value fits inside a JS Number value.
Return true if the given BigInt is negative.
Convert the given BigInt to a Number value as if calling the Number
constructor on it
(https://tc39.es/ecma262/#sec-number-constructor-number-value). The value
may be rounded if it doesn’t fit without loss of precision.
Convert the given BigInt to a String value as if toString() were called on
it.
Given a SavedFrame JSObject stack, stringify it in the same format as
Error.prototype.stack. The stringified stack out parameter is placed in the
cx’s compartment. Defaults to the empty string.
Calls the current compartment’s original Promise.reject on the original
Promise constructor, with resolutionValue
passed as an argument.
Calls the current compartment’s original Promise.resolve on the original
Promise constructor, with resolutionValue
passed as an argument.
Create a Promise with the given fulfill/reject handlers, that will be
fulfilled/rejected with the value/reason that the promise promise
is
fulfilled/rejected with.
Capture the current call stack as a chain of SavedFrame JSObjects, and set
|stackp| to the SavedFrame for the youngest stack frame, or nullptr if there
are no JS frames on the stack.
Check whether the given source is a valid regexp. If the regexp parses
successfully, returns true and sets |error| to undefined. If the regexp
has a syntax error, returns true, sets |error| to that error object, and
clears the exception. Returns false on OOM or over-recursion.
Clear kept alive objects in JS WeakRef.
https://tc39.es/proposal-weakrefs/#sec-clear-kept-objects
Clear the private value associated with a source text module record.
Compile the provided script using the given options. Return the script on
success, or return null on failure (usually with an error reported).
Compile the provided script using the given options. Return the script on
success, or return null on failure (usually with an error reported).
Compile a function with envChain plus the global as its scope chain.
envChain must contain objects in the current compartment of cx. The actual
scope chain used for the function will consist of With wrappers for those
objects, followed by the current global of the compartment cx is in. This
global must not be explicitly included in the scope chain.
Compile a function with envChain plus the global as its scope chain.
envChain must contain objects in the current compartment of cx. The actual
scope chain used for the function will consist of With wrappers for those
objects, followed by the current global of the compartment cx is in. This
global must not be explicitly included in the scope chain.
Identical to the CompileFunction overload above for UTF-8, but with
Rust-friendly ergonomics.
Parse the given source buffer as a JSON module in the scope of the current
global of cx and return a synthetic module record.
Parse the given source buffer as a module in the scope of the current global
of cx and return a source text module record.
Parse the given source buffer as a module in the scope of the current global
of cx and return a source text module record. An error is reported if a
UTF-8 encoding error is encountered.
Compile the UTF-8 contents of the given file into a script. It is an error
if the file contains invalid UTF-8. Return the script on success, or return
null on failure (usually with an error reported).
Compile the UTF-8 contents of the file at the given path into a script.
(The path itself is in the system encoding, not [necessarily] UTF-8.) It
is an error if the file’s contents are invalid UTF-8. Return the script on
success, or return null on failure (usually with an error reported).
Invoke a constructor. This is the C++ equivalent of
rval = Reflect.construct(fun, args, newTarget)
.
Invoke a constructor. This is the C++ equivalent of
rval = new fun(...args)
.
Returns true if there are any live SharedArrayBuffer objects, including those
for wasm memories, associated with the context. This is conservative,
because it does not run GC. Some dead objects may not have been collected
yet and thus will be thought live.
Given a SavedFrame object, convert it and its transitive parents to plain
objects. Because SavedFrame objects store their properties on the prototype,
they cannot be usefully stringified to JSON. Assigning their properties to
plain objects allow those objects to be stringified and the saved frame stack
can be encoded as a string.
Create a new ArrayBuffer, whose bytes are set to the values of the bytes in
the provided ArrayBuffer.
Create memory mapped ArrayBuffer contents.
Caller must take care of closing fd after calling this function.
Get the current realm’s global. Returns nullptr if no realm has been
entered.
Detect whether the internal date value is NaN.
Detach an ArrayBuffer, causing all associated views to no longer refer to
the ArrayBuffer’s original attached memory.
Incremental GC defaults to enabled, but may be disabled for testing or in
embeddings that have not yet implemented barriers on their native classes.
There is not currently a way to re-enable incremental GC once it has been
disabled on the runtime.
Attempt to disable Wasm’s usage of reserving a large virtual memory
allocation to avoid bounds checking overhead. This must be called before any
Wasm module or memory is created in this process, or else this function will
fail.
Encode a narrow multibyte character string to a UTF-8 string.
Encode a UTF-8 string to a narrow multibyte character string.
Encode a UTF-8 string to a wide string.
Encode a wide string to a UTF-8 string.
Enqueue |job| on the internal job queue.
NB: This API is infallible; a nullptr return value does not indicate error.
Evaluate the given source buffer in the scope of the current global of cx,
and return the completion value in |rval|.
As above, but providing an explicit scope chain. envChain must not include
the global object on it; that’s implicit. It needs to contain the other
objects that should end up on the script’s scope chain.
Evaluate the provided UTF-8 data in the scope of the current global of |cx|,
and return the completion value in |rval|. If the data contains invalid
UTF-8, an error is reported.
Evaluate the UTF-8 contents of the file at the given path, and return the
completion value in |rval|. (The path itself is UTF-8 encoded, too.) If
the contents contain any malformed UTF-8, an error is reported.
If the given object is an exception object (or an unwrappable
cross-compartment wrapper for one), return the stack for that exception, if
any. Will return null if the given object is not an exception object
(including if it’s null or a security wrapper that can’t be unwrapped) or if
the exception has no stack.
Execute a regexp on a given input, starting from |indexp|.
Returns false on OOM or over-recursion.
Execute a regexp on a given input, starting from |indexp|.
This is the same as ExecuteRegExp, except it does not update the RegExp
statics and can be called without a global object.
Get a statically allocated C string explaining the given GC reason.
This must be called after a dynamic import operation is complete.
If IsIncrementalGCInProgress(cx), this call finishes the ongoing collection
by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(cx),
this is equivalent to NonIncrementalGC. When this function returns,
IsIncrementalGCInProgress(cx) will always be false.
Set all of the uninitialized lexicals on an object to undefined. Return
true if any lexicals were initialized and false otherwise.
Returns the base size in bytes of the GC thing of kind |kind|.
Returns a static string equivalent of |kind|.
Get the metadata associated with an object.
Return the available byte length of an ArrayBuffer.
Return a pointer to the start of the data referenced by a typed array. The
data is still owned by the typed array, and should not be modified on
another thread. Furthermore, the pointer can become invalid on GC (if the
data is small and fits inside the array’s GC header), so callers must take
care not to hold on across anything that could GC.
Return a pointer to the start of the array buffer’s data, and indicate
whether the data is from a shared array buffer through an outparam.
Get the length, sharedness, and data from an ArrayBufferMaybeShared subtypes.
Store |*lengthp = ToLength(obj.length)| and return true on success, else
return false.
Determine the ECMAScript “class” – Date, String, RegExp, and all the other
builtin object types (described in ECMAScript in terms of an objecting having
“an [[ArrayBufferData]] internal slot” or similar language for other kinds of
object – of the provided object.
A JSErrorCallback suitable for passing to |JS_ReportErrorNumberASCII| and
similar functions in concert with one of the |JSErrNum| error numbers.
Get an error type name from a JSExnType constant.
Returns nullptr for invalid arguments and JSEXN_INTERNALERR
If args.get(0) is one of the strings “string”, “number”, or “default”, set
result to JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_UNDEFINED accordingly and
return true. Otherwise, return false with a TypeError pending.
Get the first SavedFrame object in this SavedFrame stack whose principals are
subsumed by the given |principals|. If there is no such frame, return
nullptr.
Get or set function’s reserved slot value.
fun
should be a function created with *WithReserved
API above.
Such functions have 2 reserved slots, and which
can be either 0 or 1.
This function only reports GC heap memory,
and not malloc allocated memory associated with GC things.
It reports the total of all memory for the whole Runtime.
This function reports memory used by a zone in bytes, this includes:
Get the HostImportModuleDynamically hook for the runtime.
Get the hook for populating the import.meta metadata object.
Get the HostResolveImportedModule hook for the runtime.
Get the global object associated with an object’s realm. The object must not
be a cross-compartment wrapper (because CCWs are shared by all realms in the
compartment).
Attempt to unwrap |obj| as an ArrayBuffer.
Returns a js::SavedFrame linked list of the stack that lead to the given
Promise’s allocation.
Returns the current compartment’s original Promise constructor.
Returns the given Promise’s process-unique ID.
Returns whether the given promise’s rejection is already handled or not.
Returns the current compartment’s original Promise.prototype.
Returns the given Promise’s state as a JS::PromiseState enum value.
Returns the given Promise’s activation behavior state flag per above as a
JS::PromiseUserInputEventHandlingState value. All promises are created with
the DontCare state by default.
Add some or all property keys of obj to the id vector *props.
Return the source text for a RegExp object (or a wrapper around one), or null
on failure.
Given a SavedFrame JSObject, get its asyncCause string. Defaults to nullptr.
Given a SavedFrame JSObject, get its asyncParent SavedFrame object or nullptr
if there is no asyncParent. The asyncParentp
out parameter is NOT
guaranteed to be in the cx’s compartment. Defaults to nullptr.
Given a SavedFrame JSObject, get its column property. Defaults to 0.
Given a SavedFrame JSObject, get its functionDisplayName string, or nullptr
if SpiderMonkey was unable to infer a name for the captured frame’s
function. Defaults to nullptr.
Given a SavedFrame JSObject, get its line property (1-origin).
Defaults to 0.
Given a SavedFrame JSObject, get its parent SavedFrame object or nullptr if
it is the oldest frame in the stack. The parentp
out parameter is NOT
guaranteed to be in the cx’s compartment. Defaults to nullptr.
Given a SavedFrame JSObject, get its source property. Defaults to the empty
string.
Given a SavedFrame JSObject, get an ID identifying its ScriptSource.
Defaults to 0.
Return the SymbolCode telling what sort of symbol symbol
is.
Get the [[Description]] attribute of the given symbol.
Symbol.for as specified in ES6.
Unforgeable version of the JS builtin Promise.all.
Get one of the well-known symbols defined by ES6. A single set of well-known
symbols is shared by all compartments in a JSRuntime.
Get one of the well-known symbols defined by ES6 as PropertyKey. This is
equivalent to calling JS::GetWellKnownSymbol and then creating a PropertyKey.
Informs the JS engine that the scripted caller should be hidden. This can be
used by the embedding to maintain an override of the scripted caller in its
calculations, by hiding the scripted caller in the JS engine and pushing data
onto a separate stack, which it inspects when DescribeScriptedCaller returns
null.
Return whether an incremental GC has work to do on the foreground thread and
would make progress if a slice was run now. If this returns false then the GC
is waiting for background threads to finish their work and a slice started
now would return immediately.
Perform a slice of an ongoing incremental collection. When this function
returns, the collection may not be complete. It must be called repeatedly
until !IsIncrementalGCInProgress(cx).
Return true if the GC reason is internal to the JS engine.
ES6 7.2.2.
Identical to IsArray above, but the nature of the object (if successfully
determined) is communicated via |*answer|. In particular this method
returns true and sets |*answer = IsArrayAnswer::RevokedProxy| when called on
a revoked proxy.
Check whether obj supports the JS::GetArrayBufferMaybeShared* APIs. Note
that this may return false if a security wrapper is encountered that denies
the unwrapping. If this test succeeds, then it is safe to call the various
predicate and accessor JSAPI calls defined below.
Return the isShared flag of a ArrayBufferView subtypes, which denotes whether
the underlying buffer is a SharedArrayBuffer.
Determine whether |value| is an Array object or a wrapper around one. (An
ES6 proxy whose target is an Array object, e.g.
|var target = [], handler = {}; Proxy.revocable(target, handler).proxy|, is
not considered to be an Array.)
Determine whether |obj| is an Array object or a wrapper around one. (An
ES6 proxy whose target is an Array object, e.g.
|var target = [], handler = {}; Proxy.revocable(target, handler).proxy|, is
not considered to be an Array.)
Returns true if capturing stack trace data to associate with an asynchronous
operation is currently enabled for the current context realm.
Return true if the given object is callable. In ES6 terms, an object is
callable if it has a [
Call] internal method.
Return true if the given object is a constructor. In ES6 terms, an object is
a constructor if it has a [
Construct] internal method. The expression
new obj()
throws a TypeError if obj is not a constructor.
Check whether the obj is a detached ArrayBufferObject. Note that this may
return false if a security wrapper is encountered that denies the
unwrapping.
Whether we are poisoning unused/released data for error detection. Governed
by the JS_GC_ALLOW_EXTRA_POISONING #ifdef as well as the
javascript.options.extra_gc_poisoning pref.
Returns true if any zone in the system has been scheduled for GC with one of
the functions above or by the JS engine.
Returns true if generational allocation and collection is currently enabled
on the given runtime.
Returns true if incremental GC is enabled. Simply having incremental GC
enabled is not sufficient to ensure incremental collections are happening.
See the comment “Incremental GC” above for reasons why incremental GC may be
suppressed. Inspection of the “nonincremental reason” field of the
GCDescription returned by GCSliceCallback may help narrow down the cause if
collections are not happening incrementally when expected.
Returns true while an incremental GC is ongoing, both when actively
collecting and between slices.
Returns true while an incremental GC is ongoing, both when actively
collecting and between slices.
Returns whether the passed array buffer is ‘large’: its byteLength >= 2 GB.
On success, returns true, setting |*isMap| to true if |obj| is a Map object
or a wrapper around one, or to false if not. Returns false on failure.
Check whether the obj is ArrayBufferObject and memory mapped. Note that this
may return false if a security wrapper is encountered that denies the
unwrapping.
Return true iff the given object is either a SavedFrame object or wrapper
around a SavedFrame object, and it is not the SavedFrame.prototype object.
Returns true if the given object is an unwrapped PromiseObject, false
otherwise.
Returns true if the given object is a ReadableStream object or an
unwrappable wrapper for one, false otherwise.
Returns true if the given object is a ReadableStreamDefaultReader object
or an unwrappable wrapper for one, false otherwise.
Returns true if the given object is a ReadableStreamDefaultReader or
ReadableStreamBYOBReader object or an unwrappable wrapper for one, false
otherwise.
Returns whether the passed array buffer is resizable or growable for shared
array buffers.
On success, returns true, setting |*isSet| to true if |obj| is a Set object
or a wrapper around one, or to false if not. Returns false on failure.
Check whether obj supports the JS::GetSharedArrayBuffer* APIs. Note that
this may return false if a security wrapper is encountered that denies the
unwrapping. If this test succeeds, then it is safe to call the various
accessor JSAPI calls defined below.
Return true iff the given object is a SavedFrame object and not the
SavedFrame.prototype object.
Returns true if the given text is valid JSON.
Returns true iff obj
has the WindowProxy Class (see SetWindowProxyClass).
Invoke cellCallback on every gray JSObject in the given zone.
This function calls |realmCallback| on every realm. Beware that there is no
guarantee that the realm will survive after the callback returns. Also,
barriers are disabled via the TraceSession.
Like IterateRealms, but only iterates realms in |compartment|.
Like IterateRealms, but only call the callback for realms using |principals|.
A JS context always has an “owner thread”. The owner thread is set when the
context is created (to the current thread) and practically all entry points
into the JS engine check that a context (or anything contained in the
context: runtime, compartment, object, etc) is only touched by its owner
thread. Embeddings may check this invariant outside the JS engine by calling
JS_AbortIfWrongThread (which will abort if not on the owner thread, even for
non-debug builds).
Register externally maintained GC roots.
Equivalent to Object.assign(target, src)
: Copies the properties from the
src
object (which must not be null) to target
(which also must not be
null).
Perform the method call rval = obj[name](args)
.
Call a function, passing a this-value and arguments. This is the C++
equivalent of rval = Reflect.apply(fun, obj, args)
.
Convert chars into a jsid.
Concatenate two strings, possibly resulting in a rope.
See above for thread safety comments.
Copies all own properties and private fields from |obj| to |target|. Both
|obj| and |target| must not be cross-compartment wrappers because we have to
enter their realms.
Copies the string’s characters to a null-terminated char16_t buffer.
For JS_DecodeBytes, set *dstlenp to the size of the destination buffer before
the call; on return, *dstlenp contains the number of characters actually
stored. To determine the necessary destination buffer size, make a sizing
call that passes nullptr for dst.
Freeze obj, and all objects it refers to, recursively. This will not recurse
through non-extensible objects, on the assumption that those are already
deep-frozen.
Other property-defining functions
Add various profiling-related functions as properties of the given object.
Defined in builtin/Profilers.cpp.
Define a property on obj.
Define a property on obj, throwing a TypeError if the attempt fails.
This is the C++ equivalent of Object.defineProperty(obj, id, desc)
.
Delete a property. This is the C++ equivalent of
result = Reflect.deleteProperty(obj, id)
.
Delete a property, ignoring strict failures. This is the C++ equivalent of
the JS delete obj[id]
in non-strict mode code.
DO NOT USE, only present for Rust bindings as a temporary hack
DEPRECATED
Encode string into a buffer. The function does not stores an additional
zero byte. The function returns (size_t) -1 if the string can not be
encoded into bytes with no error reported. Otherwise it returns the number
of bytes that are necessary to encode the string. If that exceeds the
length parameter, the string will be cut and only length bytes will be
written into the buffer.
DEPRECATED
DEPRECATED
Get an array of the non-symbol enumerable properties of obj.
This function is roughly equivalent to:
If the given object is an exception object, the exception will have (or be
able to lazily create) an error report struct, and this function will return
the address of that struct. Otherwise, it returns nullptr. The lifetime
of the error report struct that might be returned is the same as the
lifetime of the exception object.
Evaluate a script in the scope of the current global of cx.
As above, but providing an explicit scope chain. envChain must not include
the global object on it; that’s implicit. It needs to contain the other
objects that should end up on the script’s scope chain.
Get the value of the property obj[id]
, or undefined if no such property
exists. This is the C++ equivalent of vp = Reflect.get(obj, id, receiver)
.
Perform the same property assignment as Reflect.set(obj, id, v, receiver)
.
Freezes an object; see ES5’s Object.freeze(obj) method.
A variant of JS_ShutDown for process which used JS_FrontendOnlyInit instead
of JS_Init.
Return the ArrayBuffer or SharedArrayBuffer underlying an ArrayBufferView.
This may return a detached buffer. |obj| must be an object that would
return true for JS_IsArrayBufferViewObject().
More generic name for JS_GetTypedArrayByteLength to cover DataViews as well
More generic name for JS_GetTypedArrayByteOffset to cover DataViews as well
Same as above, but for any kind of ArrayBufferView. Prefer the type-specific
versions when possible.
Return a “fixed” pointer (one that will not move during a GC) to the
ArrayBufferView’s data. Note that this will not keep the object alive; the
holding object should be rooted or traced. If the view is storing the data
inline, this will copy the data to the provided buffer, returning nullptr if
bufSize is inadequate.
Return the ‘callbacks’ arg passed to JS_NewExternalStringLatin1,
JS_NewExternalUCString, JS_NewMaybeExternalStringLatin1,
or JS_NewMaybeExternalUCString.
Return a function’s display name as name
out-parameter.
Return the function’s identifier as a JSString, or null if fun is unnamed.
Almost same as JS_GetFunctionDisplayId.
Almost same as JS_GetFunctionId.
Get the value of the property obj[id]
, or undefined if no such property
exists. The result is stored in vp.
Get the prototype of |obj|, storing it in |proto|.
If |obj| (underneath any functionally-transparent wrapper proxies) has as
its [[GetPrototypeOf]] trap the ordinary [[GetPrototypeOf]] behavior defined
for ordinary objects, set |*isOrdinary = true| and store |obj|’s prototype
in |result|. Otherwise set |*isOrdinary = false|. In case of error, both
outparams have unspecified value.
Get number of bytes in the string encoding (without accounting for a
terminating zero bytes. The function returns (size_t) -1 if the string
can not be encoded into bytes and reports an error using cx accordingly.
Return the byte length of a typed array.
Return the byte offset from the start of an ArrayBuffer to the start of a
typed array view.
Return the number of elements in a typed array.
Return the isShared flag of a typed array, which denotes whether
the underlying buffer is a SharedArrayBuffer.
Spidermonkey does not have a good way of keeping track of what compartments
should be marked on their own. We can mark the roots unconditionally, but
marking GC things only relevant in live compartments is hard. To mitigate
this, we create a static trace hook, installed on each global object, from
which we can be sure the compartment is relevant, and mark it.
Determine whether obj has an own property with the key id
.
Compute the expression id in obj
.
Convert a uint32_t index into a jsid.
Defines a builtin constructor and prototype. Returns the prototype object.
Add ‘Reflect.parse’, a SpiderMonkey extension, to the Reflect object on the
given global.
Copy the own properties of src to dst in a fast way. src and dst must both
be native and must be in the compartment of cx. They must have the same
class, the same parent, and the same prototype. Class reserved slots will
NOT be copied.
Check whether obj supports JS_GetArrayBufferView* APIs. Note that this may
return false if a security wrapper is encountered that denies the
unwrapping. If this test or one of the more specific tests succeeds, then it
is safe to call the various ArrayBufferView accessor JSAPI calls defined
below.
True iff fun is the global eval function.
True iff fun is the Function constructor.
Return whether the given function is a valid constructor.
Determine whether the given object is backed by a DeadObjectProxy.
Determine whether obj is extensible. Extensible objects can have new
properties defined on them. Inextensible objects can’t, and their
[[Prototype]] slot is fixed as well.
Test if the given string is a valid ECMAScript identifier
Test whether the given chars + length are a valid ECMAScript identifier.
This version is infallible, so just returns whether the chars are an
identifier.
Check whether obj supports JS_GetTypedArray* APIs. Note that this may return
false if a security wrapper is encountered that denies the unwrapping. If
this test or one of the JS_Is*Array tests succeeds, then it is safe to call
the various accessor JSAPI calls defined below.
This function calls |compartmentCallback| on every compartment until either
all compartments have been iterated or CompartmentIterResult::Stop is
returned. Beware that there is no guarantee that the compartment will survive
after the callback returns. Also, barriers are disabled via the TraceSession.
This function calls |compartmentCallback| on every compartment in the given
zone until either all compartments have been iterated or
CompartmentIterResult::Stop is returned. Beware that there is no guarantee
that the compartment will survive after the callback returns. Also, barriers
are disabled via the TraceSession.
Set up ctor.prototype = proto and proto.constructor = ctor with the
right property flags.
Mark a jsid after entering a new compartment. Different zones separately
mark the ids in a runtime, and this must be used any time an id is obtained
from one compartment and then used in another compartment, unless the two
compartments are guaranteed to be in the same zone.
If value stores a jsid (an atomized string or symbol), mark that id as for
JS_MarkCrossZoneId.
If the bufSize passed to JS_GetArrayBufferViewFixedData is at least this
many bytes, then any copied data is guaranteed to fit into the provided
buffer.
Create a new DataView using the given buffer for storage. The given buffer
must be an ArrayBuffer or SharedArrayBuffer (or a cross-compartment wrapper
of either type), and the offset and length must fit within the bounds of the
buffer. Currently, nullptr will be returned and an exception will be thrown
if these conditions do not hold, but do not depend on that behavior.
Creates a new dead wrapper object in the given scope. To be used when
attempting to wrap objects from scopes which are already dead.
Create a dependent string, i.e., a string that owns no character storage,
but that refers to a slice of another string’s chars. Dependent strings
are mutable by definition, so the thread safety comments above apply.
Fill “properties” with a list of standard class names that have not yet been
resolved on “obj”. This can be used as (part of) a newEnumerate class hook
on a global. Already-resolved things are excluded because they might have
been deleted by script after being resolved and enumeration considers
already-defined properties anyway.
Fill “properties” with a list of standard class names. This can be used for
proxies that want to define behavior that looks like enumerating a global
without touching the global itself.
Create a new JSString whose chars member refers to external memory, i.e.,
memory requiring application-specific finalization.
Create a new JSString whose chars member may refer to external memory.
If a new external string is allocated, |*allocatedExternal| is set to true.
Otherwise the returned string is either not an external string or an
external string allocated by a previous call and |*allocatedExternal| is set
to false. If |*allocatedExternal| is false, |fin| won’t be called.
Similar to JS_NewMaybeExternalStringLatin1.
A constructor can request that the JS engine create a default new ‘this’
object of the given class, using the callee to determine parentage and
[[Prototype]].
Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default
proto. If proto is nullptr, the JS object will have null
as [[Prototype]].
Allocate an object in exactly the same way as JS_NewObjectWithGivenProto, but
without invoking the metadata callback on it. This allows creation of
internal bookkeeping objects that are guaranteed to not have metadata
attached to them.
Creates a new plain object, like new Object()
, with Object.prototype as
[[Prototype]].
Microseconds since the epoch, midnight, January 1, 1970 UTC.
Infallible predicate to test whether obj is a function object (faster than
comparing obj’s class name to “Function”, but equivalent unless someone has
overwritten the “Function” identifier with a different constructor and then
created instances using that constructor that might be passed in as obj).
Performs the JSON.parse operation as specified by ECMAScript.
Performs the JSON.parse operation as specified by ECMAScript.
Performs the JSON.parse operation as specified by ECMAScript.
Performs the JSON.parse operation as specified by ECMAScript, using the
given |reviver| argument as the corresponding optional argument to that
function.
Performs the JSON.parse operation as specified by ECMAScript, using the
given |reviver| argument as the corresponding optional argument to that
function.
Attempt to make |obj| non-extensible.
Implements StructuredDeserialize and StructuredDeserializeWithTransfer.
Undo a call to JS_AddExtraGCRootsTracer.
Complain when an allocation size overflows the maximum supported limit.
Report an exception represented by the sprintf-like conversion of format
and its arguments.
Complain when out of memory.
Resolve id, which must contain either a string or an int, to a standard
class name in obj if possible, defining the class’s constructor and/or
prototype and storing true in *resolved. If id does not name a standard
class or a top-level property induced by initializing a standard class,
store false in *resolved and just return true. Return false on error,
as usual for bool result-typed API entry points.
Assign ‘undefined’ to all of the object’s non-reserved slots. Note: this is
done for all slots, regardless of the associated property descriptor.
This function can be used to track memory used by ICU. If it is called, it
must be called before JS_Init. Don’t use it unless you know what you’re
doing!
Attempt to make the [[Prototype]] of |obj| immutable, such that any attempt
to modify it will fail. If an error occurs during the attempt, return false
(with a pending exception set, depending upon the nature of the error). If
no error occurs, return true with |*succeeded| set to indicate whether the
attempt successfully made the [[Prototype]] immutable.
Set the size of the native stack that should not be exceed. To disable
stack size checking pass 0.
Perform the assignment obj[id] = v
.
Change the prototype of obj.
Destroy free-standing resources allocated by SpiderMonkey, not associated
with any runtime, context, or other structure.
Performs the JSON.stringify operation, as specified by ECMAScript, except
writing stringified data by exactly one call of |callback|, passing |data| as
argument.
Given a buffer, return false if the buffer might become a valid JavaScript
script with the addition of more lines, or true if the validity of such a
script is conclusively known (because it’s the prefix of a valid script –
and possibly the entirety of such a script).
Implements StructuredSerialize, StructuredSerializeForStorage, and
StructuredSerializeWithTransfer.
A wrapper for |js_free(p)| that may delay |js_free(p)| invocation as a
performance optimization. |cx| may be nullptr.
Same as above, but for buffers that will be used with the BYOB
(Bring Your Own Buffer) JSString creation functions, such as
JS_NewLatin1String and JS_NewUCString
Inform the runtime that the job queue is empty and the embedding is going to
execute its last promise job. The runtime may now choose to skip creating
promise jobs for asynchronous execution and instead continue execution
synchronously. More specifically, this optimization is used to skip the
standard job queuing behavior for await
operations in async functions.
Inform the runtime that job queue is no longer empty. The runtime can now no
longer skip creating promise jobs for asynchronous execution, because
pending jobs in the job queue must be executed first to preserve the FIFO
(first in - first out) property of the queue. This effectively undoes
JobQueueIsEmpty and re-enables the standard job queuing behavior.
Store |v1 == v2| to |*equal| – loose equality, which may perform
user-modifiable conversions on |v1| or |v2|.
Get the script private value associated with an object, if any.
Check whether the nursery should be eagerly collected as per WantEagerMajorGC
above, and if so run a collection.
In memory reporting, we have concept of “sundries”, line items which are too
small to be worth reporting individually. Under some circumstances, a memory
reporter gets tossed into the sundries bucket if it’s smaller than
MemoryReportingSundriesThreshold() bytes.
Create a new ArrayBuffer with the given byte length.
Create a new ArrayBuffer with the given non-null |contents|.
Create an Array from the current realm with the given contents.
Create an Array from the current realm with the given length and allocate
memory for all its elements. (The elements nonetheless will not exist as
properties on the returned array until values have been assigned to them.)
Create a new Date object for a year/month/day-of-month/hour/minute/second.
Create a new ArrayBuffer with the given contents. The contents must not be
modified by any other code, internal or external.
Create a new function based on the given JSFunctionSpec, *fs.
id is the result of a successful call to
PropertySpecNameToId(cx, fs->name, &id)
or
PropertySpecNameToPermanentId(cx, fs->name, &id)
.
Same as above, but without an id arg, for callers who don’t have
the id already.
Create a new mapped ArrayBuffer with the given memory mapped contents. It
must be legal to free the contents pointer by unmapping it. On success,
ownership is transferred to the new mapped ArrayBuffer.
Returns a new instance of the Promise builtin class in the current
compartment, with the right slot layout.
Returns a new instance of the ReadableStream builtin class in the current
compartment, configured as a default stream.
If a |proto| is passed, that gets set as the instance’s [[Prototype]]
instead of the original value of |ReadableStream.prototype|.
Returns a new instance of the ReadableStream builtin class in the current
compartment.
Create a new RegExp for the given Latin-1-encoded bytes and flags.
Create a new SharedArrayBuffer with the given byte length. This
may only be called if
JS::RealmCreationOptionsRef(cx).getSharedMemoryAndAtomicsEnabled() is
true.
Create a new Symbol with the given description. This function never returns
a Symbol that is in the Runtime-wide symbol registry.
Create a new RegExp for the given source and flags.
Performs a non-incremental collection of all selected zones.
Hint that we expect a crash. Currently, the only thing that cares is the
breakpad injector, which (if loaded) will suppress minidump generation.
Create a BigInt from a floating-point value. If the number isn’t integral
(that is, if it’s NaN, an infinity, or contains a fractional component),
this function returns null and throws an exception.
On success, returns true, setting |*isDate| to true if |obj| is a Date
object or a wrapper around one, or to false if not. Returns false on
failure.
On success, returns true, setting |*isRegExp| to true if |obj| is a RegExp
object or a wrapper around one, or to false if not. Returns false on
failure.
ES6 draft 20141224, 7.1.1, second algorithm.
Performs the JSON.parse operation as specified by ECMAScript, and call
callbacks defined by the handler.
Schedule all zones to be collected in the next GC.
When performing an incremental GC, the zones that were selected for the
previous incremental slice must be selected in subsequent slices as well.
This function selects those slices automatically.
Schedule the given zone to be collected as part of the next GC.
Create a jsid that does not need to be marked for GC.
Cancels the given ReadableStream with the given reason and returns a
Promise resolved according to the result.
Close the given ReadableStream. This is equivalent to controller.close()
in JS.
Enqueues the given chunk in the given ReadableStream.
Errors the given ReadableStream, causing all future interactions to fail
with the given error value.
Retrieves the desired combined size of additional chunks to fill the given
ReadableStream’s queue. Stores the result in |value| and sets |hasValue| to
true on success, returns false on failure.
Returns the embedding-provided underlying source of the given |stream|.
Returns the stream’s ReadableStreamMode. If the mode is |Byte| or
|ExternalSource|, it’s possible to acquire a BYOB reader for more optimized
operations.
Creates a reader of the type specified by the mode option and locks the
stream to the new reader.
Returns true if the given ReadableStream is disturbed, false if not.
Returns true if the given ReadableStream is locked, false if not.
Returns true if the given ReadableStream is readable, false if not.
Returns true if the given ReadableStream reader is locked, false otherwise.
Break the cycle between this object and the
nsISupportsObject_alreadyAddreffed passed in
NewReadableExternalSourceStreamObject().
Releases the embedding-provided underlying source of the given |stream|,
returning the stream into an unlocked state.
Tees the given ReadableStream and stores the two resulting streams in
outparams. Returns false if the operation fails, e.g. because the stream is
locked.
Update the amount of data available at the underlying source of the given
|stream|.
Rejects the given promise
with the given rejectionValue
.
Release the allocated resource of mapped ArrayBuffer contents before the
object is created.
If a new object has been created by JS::NewMappedArrayBufferWithContents()
with this content, then JS::DetachArrayBuffer() should be used instead to
release the resource used by the object.
Advise the GC that external memory reported by JS::AddAssociatedMemory() is
no longer owned by a JSObject. Calls must match those to
AddAssociatedMemory().
Re-query the system to determine the current time zone adjustment from UTC,
including any component due to DST. If the time zone has changed, this will
cause all Date object non-UTC methods and formatting functions to produce
appropriately adjusted results.
Resolves the given Promise with the given resolutionValue
.
Instruct the runtime to restart draining the internal job queue after
stopping it with StopDrainingJobQueue.
Stores |SameValue(v1, v2)| to |*equal| – using the SameValue operation
defined in ECMAScript, initially exposed to script as |Object.is|. SameValue
behaves identically to strict equality, except that it equates two NaN values
and does not equate differently-signed zeroes. It performs no conversions on
|v1| or |v2| before comparing.
Specify a callback to invoke when creating each JS object in the current
compartment, which may return a metadata object to associate with the
object.
Perform |obj.length = length| as if in strict mode code, with a fast path for
the case where |obj| is an Array.
Transition the cx to a mode where failures that would normally cause a false
return value will instead crash with a diagnostic assertion.
Called when generating a GC slice budget. It allows the embedding to control
the duration of slices and potentially check an interrupt flag as well. For
internally triggered GCs, the given millis parameter is the JS engine’s
internal scheduling decision, which the embedding can choose to ignore.
(Otherwise, it will be the value that was passed to eg
JS::IncrementalGCSlice()).
The purge gray callback is called after any COMPARTMENT_REVIVED GC in which
the majority of compartments have been marked gray.
The GC slice callback is called at the beginning and end of each slice. This
callback may be used for GC notifications as well as to perform additional
marking.
Tell SpiderMonkey to use queue
to schedule promise reactions.
Set the HostImportModuleDynamically hook for the runtime to the given
function.
Set the hook for populating the import.meta metadata object to the given
function.
Set a private value associated with a source text module record.
Set the HostResolveImportedModule hook for the runtime to the given function.
Embedder hook to set the buildId-generating function.
Tell JS engine whether Profile Timeline Recording is enabled or not.
If Profile Timeline Recording is enabled, data shown there like stack won’t
be optimized out.
This is global state and not associated with specific runtime or context.
Sets the callback that’s invoked whenever a Promise is rejected without
a rejection handler, and when a Promise that was previously rejected
without a handler gets a handler attached.
Sets the given Promise’s activation behavior state flag per above as a
JS::PromiseUserInputEventHandlingState value.
Set a private value associated with a script. Note that this value is shared
by all nested scripts compiled from a single source file.
Set the script private finalize hook for the runtime to the given function.
Associates a WindowProxy with a Window (global object). windowProxy
must
have the Class set by SetWindowProxyClass.
Tell the JS engine which Class is used for WindowProxy objects. Used by the
functions below.
When a JSRuntime is destroyed it implicitly cancels all async tasks in
progress, releasing any roots held by the task. However, this is not soon
enough for cycle collection, which needs to have roots dropped earlier so
that the cycle collector can transitively remove roots for a future GC. For
these and other cases, the set of pending async tasks can be canceled
with this call earlier than JSRuntime destruction.
Create a BigInt by parsing a string consisting of an optional sign character
followed by one or more alphanumeric ASCII digits in the provided radix.
Undoes the effect of the Prepare methods above. The given zone will not be
collected in the next GC.
Begin an incremental collection and perform one slice worth of work. When
this function returns, the collection may not be complete.
IncrementalGCSlice() must be called repeatedly until
!IsIncrementalGCInProgress(cx).
Steal the contents of the given ArrayBuffer. The ArrayBuffer has its length
set to 0 and its contents array cleared. The caller takes ownership of the
return value and must free it or transfer ownership via
JS::NewArrayBufferWithContents when done using it.
Instruct the runtime to stop draining the internal job queue.
Store |v1 === v2| to |*equal| – strict equality, which performs no
conversions on |v1| or |v2| before comparing.
Overload of StringIsArrayIndex taking a (char16_t*,length) pair. Behaves
the same as the JSLinearString version.
Create a BigInt by parsing a string using the ECMAScript StringToBigInt
algorithm (https://tc39.es/ecma262/#sec-stringtobigint). Latin1 and two-byte
character ranges are supported. It may be convenient to use
JS::ConstLatin1Chars or JS::ConstTwoByteChars.
Convert a JS::Value to a BigInt using the ECMAScript ToBigInt algorithm
(https://tc39.es/ecma262/#sec-tobigint).
Convert the given BigInt, modulo 2**64, to a signed 64-bit integer.
Convert the given BigInt, modulo 2**64, to an unsigned 64-bit integer.
Generate getter/setter id for given id, by adding “get “ or “set “ prefix.
Performs the JSON.stringify operation, as specified by ECMAScript, except
writing stringified data by one call of |callback|, passing |data| as
argument.
An API akin to JS_Stringify but with the goal of not having observable
side-effects when the stringification is performed. This means it does not
allow a replacer or a custom space and has the following constraints on its
input:
Convert obj to a primitive value. On success, store the result in vp and
return true.
If obj
is a WindowProxy, get its associated Window (the compartment’s
global), else return obj
. This function is infallible and never returns
nullptr.
Unsets the gray bit for anything reachable from |thing|. |kind| should not be
JS::TraceKind::Shape. |thing| should be non-null. The return value indicates
if anything was unmarked.
Use the runtime’s internal handling of job queues for Promise jobs.
Check whether the nursery should be eagerly collected, this is before it is
full.
Report a warning represented by the sprintf-like conversion of ASCII format
filled from trailing ASCII arguments.
Report a warning represented by the sprintf-like conversion of Latin-1 format
filled from trailing Latin-1 arguments.
Report a warning represented by the sprintf-like conversion of UTF-8 format
filled from trailing UTF-8 arguments.
Returns true if the most recent GC ran incrementally.