Search completed in 1.44 seconds.
nsIXPConnect
service, use code like this: nsresult rv; nsCOMPtr<nsIXPConnect> xpconnect = do_GetService(nsIXPConnect::GetCID(), &rv); if (NS_SUCCEEDED(rv)) { /* use the object */ } Method overview void addJSHolder(in voidPtr aHolder, in nsScriptObjectTracerPtr aTracer); Native code only! void clearAllWrappedNativeSecurityPolicies(); nsIXPConnectJSObjectHolder createSandbox(in
JSContextPtr cx, in nsIPrincipal principal); Native code only! nsIStackFrame createStackFrameLocation(in PRUint32 aLanguage, in string aFilename, in string aFunctionName, in PRInt32 aLineNumber, in nsIStackFrame aCaller); void debugDump(in short depth); void debugDumpEvalInJSStackFrame(in PRUint32 aFrameNumber, in string aSourceText); void debugDumpJSStack(in PRBool sho...
... void flagSystemFilenamePrefix(in string aFilenamePrefix, in PRBool aWantNativeWrappers); ...
...RBool showArgs, in PRBool showLocals, in PRBool showThisProps); void debugDumpObject(in nsISupports aCOMObj, in short depth); [noscript,notxpcom] PRBool defineDOMQuickStubs(in
JSContextPtr cx, in JSObjectPtr proto, in PRUint32 flags, in PRUint32 interfaceCount, [array, size_is(interfaceCount)] in nsIIDPtr interfaceArray); jsval evalInSandboxObject(in AString source, in
JSContextPtr cx, in nsIXPConnectJSObjectHolder sandbox, in PRBool returnStringOnly); Native code only! ...
...And 82 more matches
WebIDL bindings
reflections of WebIDL operations (methods) A WebIDL operation is turned into a method call on the underlying C++ object. The return type and argument types are determined as described below. In addition to those, all methods that are allowed to throw will get an ErrorResult& argument appended to their argument list. Non-static methods that use certain WebIDL types like any or object will get a
JSContext* argument prepended to the argument list. Static methods will be passed a const GlobalObject& for the relevant global and can get a
JSContext* by calling Context() on it. The name of the C++ method is simply the name of the WebIDL operation with the first letter converted to uppercase. WebIDL overloads are turned into C++ overloads: they simply call C++ methods with the same name and different ...
...A readonly attribute only has a getter and no setter. The getter's name is the name o...
...te's type. C++ reflections of WebIDL constructors A WebIDL constructor is turned into a static class method named Constructor. The arguments of this method will be the arguments of the WebIDL constructor, with a const GlobalObject& for the relevant global prepended. For the non-worker case, the global is typically the inner window for the DOM Window the constructor function is attached to. If a
JSContext* is also needed due to some of the argument types, it will come after the global. The return value of the constructor for MyInterface is exactly the same as that of a method returning an instance of MyInterface. Constructors are always allowed to throw. For example, this IDL: [Constructor, Constructor(unsigned long someNumber)] interface MyInterface { }; will require the following declaratio...
...And 21 more matches
nsIXPCScriptable
urn a boolean to PR_TRUE before making the call. Implementations may skip writing to *_retval unless they want to return PR_FALSE. js/src/xpconnect/idl/nsIXPCScriptable.idlNot scriptable Please add a summary to this article. ...
...LSE. js/src/xpconnect/idl/nsIXPCScriptable.idlNot scriptable Please add a summary to this article. ...
...cle. ...
...And 20 more matches
JSAPI User Guide
s a prebuilt package. Build it from source instead. Your program will be easier to debug. C++ code accesses SpiderMonkey via the JSAPI, by including the header "jsapi.h". An overview of JSAPI functionality follows. For more details, see the JSAPI Reference. The SpiderMonkey universe In order to run any JavaScript code in SpiderMonkey, an application must have three key elements: a JSRuntime, a
JSContext, and a global object. This section describes what these things are. The next section explains how to set them up, using JSAPI functions. Runtimes. A JSRuntime, or runtime, is the space in which the JavaScript variables, objects, scripts, and contexts used by your application are allocated. Every
JSContext and every object in an application lives within a JSRuntime. They cannot travel to other ru...
... JSAPI functions. Runtimes. A JSRuntime, or runtime, is the space in which the JavaScript variables, objects, scripts, and contexts used by your application are allocated. Every
JSContext and every object in an application lives within a JSRuntime. They cannot travel to other runtimes or be shared across runtimes. You will need at least one JSRuntime per thread that uses the JSAPI. Contexts. A
JSContext, or context, is like a little machine that can do many things involving JavaScript code and objects. It can compile and execute scripts, get and set object properties, call JavaScript functions, convert JavaScript data from one type to another, create objects, and so on. Almost all JSAPI functions require a
JSContext * as the first argument, just like most <stdio.h> functions require a FILE *. G...
...amespace JS; // The class of the global object. static JSClass globalClass = { "global", JSCLASS_GLOBAL_FLAGS, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, nullptr, nullptr, nullptr, nullptr, JS_GlobalObjectTraceHook }; // The error reporter callback. void reportError(
JSContext *cx, const char *message, JSErrorReport *report) { fprintf(stderr, "%s:%u:%s\n", report->filename ? report->filename : "[no filename]", (unsigned int) report->lineno, message); } int run(
JSContext *cx) { // Enter a request before running anything in the context. JSAutoRequest ar(cx); // Create the global object and a new compartment. R...
...And 13 more matches
JS_DefineProperty
Create a new property on an object. ...
... Create a new property on an object. ...
...HandleObject obj, const char *name, JS::HandleValue value, unsigned attrs, JSNative getter = nullptr, JSNative setter = nullptr); bool JS_DefineProperty(
JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleObject value, unsigned attrs, JSNative getter = nullptr, JSNative setter = nullptr); bool JS_DefineProperty(
JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleString value, unsigned attrs, JSNative getter = nullptr, JSNative setter = nullptr); bool JS_DefineProperty(
JSContext *cx, JS::HandleObject obj, const char *name, int32_t value, unsigned attrs, JSNative getter = nullptr, JSNative setter = nullptr); bool JS_DefinePropert...
...And 10 more matches
Index
23 JS::AutoIdArray JSAPI Reference, Reference, Reference(2), SpiderMonkey JS::AutoIdArray takes the ownership of JSIdArray, and frees it in destructor by calling JS_DestroyIdArray. 24 JS::AutoSaveExceptionState JSAPI Reference, Reference, Reference(2), SpiderMonkey JS::AutoSaveExceptionState saves and later restores the current exception state of a given
JSContext. 25 JS::AutoValueArray JSAPI Reference, Reference, Reference(2), SpiderMonkey JS::AutoValueArray<N> holds a rooted array of JS::Value. This is typically used for local variables being passed to function which requires JS::HandleValueArray or a pointer to JS::Value array. 26 JS::AutoVectorRooter JSAPI Reference, Reference, Reference(2), SpiderMonkey JS::Au...
...age collector calls this callback for each object it collects. The finalizer's job is to clean up any resources allocated by the instance which wouldn't normally be cleaned up by the garbage collector (private data stored in the object by the application, file handles, etc.) 108 JSFreeOp JSAPI Reference, Reference, Reference(2), SpiderMonkey Various finalization API takes not
JSContext * but rather either JSFreeOp structure or its library-private counterpart FreeOp. These structures wrap parameters that are passed to the finalizers removing most of explicit dependencies on
JSContext in the finalization code. 109 JSFunction API, Guide, JSAPI, NeedsContent, SpiderMonkey JSFunction is a type in the JSAPI. The APIs JS_NewFunction, JS_DefineFunction, JS_CompileF...
...whether a running script may access a given object property. 197 JS_CheckForInterrupt JSAPI_Reference, Reference, Reference(2), SpiderMonkey JS_CheckForInterrupt checks for the interrupt, and handle it if it's pending. JS_CheckForInterrupt returns false if interrupt callback returns false. 198 JS_ClearContextThread JSAPI Reference, SpiderMonkey Transfer a
JSContext from one thread to another. 199 JS_ClearDateCaches Date, JSAPI Reference, JavaScript, Reference, Reference(2), SpiderMonkey JS_ClearDateCaches clears the cache of calculated local time from each Date object. Call to propagate a system timezone change. 200 JS_ClearNewbornRoots JSAPI Reference, SpiderMonkey The last GC thing of each type (object, string, do...
...And 8 more matches
GC Rooting Guide
on the stack JS::Rooted<T> All GC thing pointers stored on the stack (i.e., local variables and parameters to functions) must use the JS::Rooted<T> class. This is a template class where the template parameter is the type of the GC thing it contains. From the user perspective, a JS::Rooted<T> instance behaves exactly as if it were the underlying pointer. JS::Rooted must be constructed with a
JSContext*, and optionally an initial value. There are typedefs available for the main types. Within SpiderMonkey, it is suggested that these are used in preference to the template class (Gecko uses the template versions): Template class Typedef JS::Rooted<JS::Value> JS::RootedValue JS::Rooted<JSObject*> JS::RootedObject JS::Rooted<JSString*> JS::Rooted...
...:HandleValue JS::Handle<JSObject*> JS::HandleObject JS::Handle<JSString*> JS::HandleString JS::Handle<JSScript*> JS::HandleScript JS::Handle<jsid> JS::HandleId You should use JS::Handle<T> for all function parameters taking GC thing pointers (except out-parameters, which are described below). For example, instead of: JSObject * someFunction(
JSContext *cx, JSObject* obj) { // ... } You should write: JSObject * someFunction(
JSContext *cx, JS::HandleObject obj) { // ... } JS::MutableHandle<T> All GC thing pointers that are used as out-parameters must be wrapped in a JS::MutableHandle<T>. A JS::MutableHandle<T> is a reference to a JS::Rooted<T> that, unlike a normal handle, may modify the underlying JS::Rooted<T>. All JS::MutableHan...
... if (!wasError) valueOut.set(resultValue); return wa...
...And 4 more matches
JS_GetContextPrivate
They are especially useful for storing data needed by callbacks. ...
...They are especially useful for storing data needed by callbacks. ...
...They are especially useful for storing data needed by callbacks. ...
...And 4 more matches
How to embed the JavaScript engine
l object. */ static JSClass global_class = { "global", JSCLASS_GLOBAL_FLAGS, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, }; int main(int argc, const char *argv[]) { JSRuntime *rt = JS_NewRuntime(8L * 1024 * 1024, JS_USE_HELPER_THREADS); if (!rt) return 1;
JSContext *cx = JS_NewContext(rt, 8192); if (!cx) return 1; { // Scope for our various stack objects (JSAutoRequest, RootedObject), so they all go // out of scope before we JS_DestroyContext. JSAutoRequest ar(cx); // In practice, you would want to exit this any // time you're spinning the event loop JS::RootedObject global(cx, JS_NewGlobalObj...
... JSAutoRequest ar(cx); // In practice, you would want to exit this any // time you're spinning the event loop JS::RootedObject global(cx, JS_NewGlobalObj...
...t. */ static JSClass global_class = { "global", JSCLASS_GLOBAL_FLAGS, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, JS_GlobalObjectTraceHook }; int main(int argc, const char *argv[]) { JS_Init(); JSRuntime *rt = JS_NewRuntime(8L * 1024 * 1024); if (!rt) return 1;
JSContext *cx = JS_NewContext(rt, 8192); if (!cx) return 1; { // Scope for our various stack objects (JSAutoRequest, RootedObject), so they all go // out of scope before we JS_DestroyContext. JSAutoRequest ar(cx); // In practice, you would want to exit this any // time you're spinning the event loop JS::RootedObject global(cx, JS_NewGlobalObj...
...And 3 more matches
JS::Add*Root
n some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 31 Register a variable as a member of the garbage collector's root set, to protect anything the root points at from garbage collection. These functions are obsoleted, use JS::PersistentRooted instead. ...
... at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 31 Register a variable as a member of the garbage collector's root set, to protect anything the root points at from garbage collection. These functions are obsoleted, use JS::PersistentRooted instead. ...
...tures introduced in SpiderMonkey 31 Register a variable as a member of the garbage collector's root set, to protect anything the root points at from garbage collection. These functions are obsoleted, use JS::PersistentRooted instead. ...
...And 3 more matches
JS::Compile
This article covers features introduced in SpiderMonkey 17 Compile a script for execution. ...
... This article covers features introduced in SpiderMonkey 17 Compile a script for execution. ...
... execution. ...
...And 3 more matches
JS::CompileOptions
This article covers features introduced in SpiderMonkey 17 Compile options classes. Constructor JS::ReadOnlyCompileOptions(); // Added in SpiderMonkey 31 JS::OwningCompileOptions(
JSContext *cx); // Added in SpiderMonkey 31 JS::CompileOptions(
JSContext *cx, JSVersion version = JSVERSION_UNKNOWN); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. version JSVersion JavaScript version used to compile the script. Methods Some methods of JS::OwningCompileOptions and JS::CompileOptions return the instance itself to allow method chain. Methods of JS::ReadOnlyCompileOptions ...
...sewhere.) JSString *elementAttributeName() const If this source belongs to a DOM element because it is an event handler content attribute or an event handler IDL attribute, this returns the name of that attribute, a string. Otherwise, this returns NULL. JSScript *introductionScript() const Returns a pointer to JSScript which introduces the file. ...
...event handler IDL attribute, this returns the name of that attribute, a string. Otherwise, this returns NULL. JSScript *introductionScript() const Returns a pointer to JSScript which introduces the file. bool copy(
JSContext *cx, const ReadOnlyCompileOptions &rhs) Copy compile options from rhs. Returns false if it failed to duplicate owning properties. bool setFile(
JSContext *cx, const char *f) Duplicate null-terminated string f for filename(). Returns false if it failed to duplicate. ...
...And 3 more matches
JS::Evaluate
This article covers features introduced in SpiderMonkey 17 Compile and execute a script. ...
... This article covers features introduced in SpiderMonkey 17 Compile and execute a script. ...
...cript. ...
...And 3 more matches
JS::Remove*Root
gh it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 31 Unregister a pointer to a GC thing so that it is no longer a member of the garbage collector's root set. This enables any pointed-at GC thing to be garbage collected as needed. ...
...nce it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 31 Unregister a pointer to a GC thing so that it is no longer a member of the garbage collector's root set. This enables any pointed-at GC thing to be garbage collected as needed. ...
... This article covers features introduced in SpiderMonkey 31 Unregister a pointer to a GC thing so that it is no longer a member of the garbage collector's root set. This enables any pointed-at GC thing to be garbage collected as needed. ...
...And 3 more matches
JS_Add*Root
e JSAPI 31This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Register a variable as a member of the garbage collector's root set, to protect anything the root points at from garbage collection. These functions are obsoleted, use JS::PersistentRooted instead. ...
... still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Register a variable as a member of the garbage collector's root set, to protect anything the root points at from garbage collection. These functions are obsoleted, use JS::PersistentRooted instead. ...
...ce it could be removed at any time. Try to avoid using it. Register a variable as a member of the garbage collector's root set, to protect anything the root points at from garbage collection. These functions are obsoleted, use JS::PersistentRooted instead. ...
...And 3 more matches
JS_ContextIterator
On input, *iterp must be NULL or point to a context in rt. ...
...On input, *iterp must be NULL or point to a context in rt. ...
...On input, *iterp must be NULL or point to a context in rt. ...
...And 3 more matches
JS_DefineElement
Creates a numeric property on a specified object. ...
... Creates a numeric property on a specified object. ...
... uint32_t index, JS::HandleValue value, unsigned attrs, JSNative getter = nullptr, JSNative setter = nullptr); bool JS_DefineElement(
JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject value, unsigned attrs, JSNative getter = nullptr, JSNative setter = nullptr); bool JS_DefineElement(
JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString value, unsigned attrs, JSNative getter = nullptr, JSNative setter = nullptr); bool JS_DefineElement(
JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t value, unsigned attrs, JSNative getter = nullptr, JSNative setter = nullptr...
...And 3 more matches
JS_ExecuteScript
Execute a compiled script. ...
... Execute a compiled script. ...
... Execute a compiled script. ...
...And 3 more matches
JS_LookupProperty
Obsolete since JSAPI 37This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Determine if a specified property exists. ...
... Obsolete since JSAPI 37This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Determine if a specified property exists. ...
...ime. Try to avoid using it. Determine if a specified property exists. ...
...And 3 more matches
JS_ReportErrorNumber
Report an error with an application-defined error code. ...
... Report an error with an application-defined error code. ...
... Report an error with an application-defined error code. ...
...And 3 more matches
JS_SetElement
Assign a value to a numeric property of an object. ...
... Assign a value to a numeric property of an object. ...
... Assign a value to a numeric property of an object. ...
...And 3 more matches
nsIJSON
nce(Components.interfaces.nsIJSON); Method overview Note: The IDL file has portions of the IDL commented out because they represent things that can't actually be properly described by IDL; however, for the purposes of this article, we'll pretend they can be and ignore that issue. ...
...end they can be and ignore that issue. ...
... Note: This method is more flexible than it should be, and accepts some not-correctly-structured JSON. ...
...And 3 more matches
Hacking Tips
t/bin/js ./foo.js [...] SpiderMonkey unwinder is disabled by default, to enable it type: enable unwinder .* SpiderMonkey (gdb) b js::math_cos (gdb) run [...] #0 js::math_cos (cx=0x14f2640, argc=1, vp=0x7fffffff6a88) at js/src/jsmath.cpp:338 338 CallArgs args = CallArgsFromVp(argc, vp); (gdb) enable unwinder .* SpiderMonkey (gdb) backtrace 10 #0 0x0000000000f89979 in js::math_cos(
JSContext*, unsigned int, JS::Value*) (cx=0x14f2640, argc=1, vp=0x7fffffff6a88) at js/src/jsmath.cpp:338 #1 0x0000000000ca9c6e in js::CallJSNative(
JSContext*, bool (*)(
JSContext*, unsigned int, JS::Value*), JS::CallArgs const&) (cx=0x14f2640, native=0xf89960 , args=...) at js/src/jscntxtinlines.h:235 #2 0x0000000000c87625 in js::Invoke(
JSContext*, JS::CallArgs const&, js::MaybeConstruct) (cx=0x14f2640, a...
...n js::CallJSNative(
JSContext*, bool (*)(
JSContext*, unsigned int, JS::Value*), JS::CallArgs const&) (cx=0x14f2640, native=0xf89960 , args=...) at js/src/jscntxtinlines.h:235 #2 0x0000000000c87625 in js::Invoke(
JSContext*, JS::CallArgs const&, js::MaybeConstruct) (cx=0x14f2640, args=..., construct=js::NO_CONSTRUCT) at js/src/vm/Interpreter.cpp:476 #3 0x000000000069bdcf in js::jit::DoCallFallback(
JSContext*, js::jit::BaselineFrame*, js::jit::ICCall_Fallback*, uint32_t, JS::Value*, JS::MutableHandleValue) (cx=0x14f2640, frame=0x7fffffff6ad8, stub_=0x1798838, argc=1, vp=0x7fffffff6a88, res=JSVAL_VOID) at js/src/jit/BaselineIC.cpp:6113 #4 0x00007ffff7f41395 in <<JitFrame_Exit>> () #5 0x00007ffff7f42223 in <<JitFrame_BaselineStub>> () #6 0x00007ffff7f4423d in <<JitFrame_BaselineJS>> () #7 0x00007ff...
...Therefore, the JIT frames do not appear until you settle on the next breakpoint. To work-around this issue you can use the recording feature of gdb, to step one instruction, and settle back to where you came fr...
...And 2 more matches
JSAPI Cookbook
; v.setBoolean(false); // or: v = JS::BooleanValue(false); Finding the global object Many of these recipes require finding the current global object first. // JavaScript var global = this; There is a function, JS_GetGlobalForScopeChain(cx), that makes a best guess, and sometimes that is the best that can be done. ...
... * This makes your C function visible as a global function in JavaScript. ...
... * This makes your C function visible as a global function in JavaScript. ...
...And 2 more matches
JS::AutoSaveExceptionState
This is useful for implementing behavior in C++ that's like try/catch or try/finally in JS. ...
... This is useful for implementing behavior in C++ that's like try/catch or try/finally in JS. ...
... This is useful for implementing behavior in C++ that's like try/catch or try/finally in JS. ...
...And 2 more matches
JS::Call
This article covers features introduced in SpiderMonkey 17 Call a specified JS function. ...
... This article covers features introduced in SpiderMonkey 17 Call a specified JS function. ...
...ers features introduced in SpiderMonkey 17 Call a specified JS function. ...
...And 2 more matches
JS::CompileFunction
This article covers features introduced in SpiderMonkey 17 Create a JavaScript function from a text string. ...
...7 Create a JavaScript function from a text string. ...
...Requires requ...
...And 2 more matches
JS::PersistentRooted
ble, assignable global GC root type with arbitrary lifetime, an infallible constructor, and automatic unrooting on destruction. ...
...ype Description cx
JSContext * The context to get the runtime in which to add the root rt JSRuntime * The runtime in which to add the root. initial T An initial value for the persistent rooted variable. Methods Here, ptr represents the private member of JS::PersistentRooted<T>, typed with T. Method Description void init(
JSContext* cx) Initialize with optional initial value (if not provided, it will be initialized with the initial value of the type). Added in SpiderMonkey 38 void init(
JSContext* cx, T initial) void init(JSRuntime* rt) void init(JSRuntime* rt, T initial) void reset() Reset the value to initial value of the type. Added in SpiderMonkey 38 T& get() Returns ...
... JS::PersistentRooted<T> declares a variable of type T whose value is always rooted. This is typically used for global variables. JS::PersistentRooted<T> is a copyable, assignable global GC root type with arbitrary lifetime, an infallible constructor, and automatic unrooting on destruction. These roots can be used in heap-allocated data structures, so they are not associated with any particular
JSContext or stack. They are registered with the JSRuntime itself, without locking, so they require a full
JSContext to be initialized, not one of its more restricted superclasses. Initialization may take place on construction, or in two phases if the no-argument constructor is called followed by init(). Note that you must not use an PersistentRooted in an object owned by a JS object: Whenever one object...
...And 2 more matches
JS_CompileScript
Compiles a script for execution. ...
... Compiles a script for execution. ...
... const char *ascii, size_t length, const JS::CompileOptions &options, JS::MutableHandleScript script); bool JS_CompileUCScript(
JSContext *cx, const char16_t *chars, size_t length, const JS::CompileOptions &options, JS::MutableHandleScript script); // Obsolete since JSAPI 39 bool JS_CompileScript(
JSContext *cx, JS::HandleObject obj, const char *ascii, size_t length, const JS::CompileOptions &options, JS::MutableHandleScript script); bool JS_CompileUCScript(
JSContext *cx, JS::HandleObject obj, const char16_t *chars, size_t length, const JS::CompileOptions &options, JS::MutableHandleScript scr...
...And 2 more matches
JS_CompileScriptForPrincipals
Obsolete since JSAPI 28This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Compile a security-enabled script for execution. ...
...still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Compile a security-enabled script for execution. ...
...mpileScriptForPrincipals(
JSContext *cx, JSObject *obj, JSPrincipals *principals, const char *src, size_t length, const char *filename, unsigned int lineno); JSScript * JS_CompileUCScriptForPrincipals(
JSContext *cx, JSObject *obj, JSPrincipals *principals, const jschar *src, size_t length, const char *filename, unsigned int lineno); JSObject * JS_CompileScriptForPrincipalsVersion(
JSContext *cx, JSObject *obj, JSPrincipals *principals, const char *src, size_t length, const char *filename, unsigned int lineno, JSVersion version); // Obsoleted since JSAPI 19 JSObject * JS_CompileUCScriptForPrincipalsVersion(
JSContext *cx, JSObject *obj, JSPrincipals *principals, const jschar *src, size_t length, const char *filename, unsigned int lineno, JSVersion version); // Obsolet...
...And 2 more matches
JS_DeleteProperty
Removes a specified property from an object. ...
... Removes a specified property from an object. ...
... Removes a specified property from an object. ...
...And 2 more matches
JS_EvaluateScriptForPrincipals
Obsolete since JSAPI 30This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Compile and execute a security-enabled script. ...
... some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Compile and execute a security-enabled script. ...
...xt *cx, JSObject *obj, JSPrincipals *principals, const char *src, unsigned int length, const char *filename, unsigned int lineno, jsval *rval); JSBool JS_EvaluateScriptUCForPrincipals(
JSContext *cx, JSObject *obj, JSPrincipals *principals, const jschar *src, unsigned int length, const char *filename, unsigned int lineno, jsval *rval); JSBool JS_EvaluateScriptForPrincipalsVersion(
JSContext *cx, JSObject *obj, JSPrincipals *principals, const char *bytes, unsigned int length, const char *filename, unsigned int lineno, jsval *rval, JSVersion version); JSBool JS_EvaluateUCScriptForPrincipalsVersion(
JSContext *cx, JSObject *obj, JSPrincipals *principals, const jschar *chars, unsigned int length, const char *filename, unsigned int lineno, jsval *rval, JSVersion version);...
...And 2 more matches
JS_HasProperty
obj JS::HandleObject Object to search on for the property. ...
... obj JS::HandleObject Object to search on for the property. ...
... obj JS::HandleObject Object to search on for the property. ...
...And 2 more matches
JS_NewArrayObject
contents JS::HandleValueArray& Reference to the initial values for the array's elements. ...
... contents JS::HandleValueArray& Reference to the initial values for the array's elements. ...
... contents JS::HandleValueArray& Reference to the initial values for the array's elements. ...
...And 2 more matches
JS_PropertyStub
Default implementations of the required callbacks in JSClass. ...
... Default implementations of the required callbacks in JSClass. ...
... implementations of the required callbacks in JSClass. ...
...And 2 more matches
JS_THREADSAFE
n a JS_THREADSAFE build, the application must separate code that uses the JSAPI from code that performs blocking I/O or time-consuming calculations. A request is a region of code that uses the JSAPI. Requests must be bracketed with calls to JS_BeginRequest() and JS_EndRequest(). JS_BeginRequest(cx); /* ... do JSAPI stuff ... */ JS_EndRequest(cx); A request is always associated with a specific
JSContext and runs from start to finish on a single thread. Most JSAPI functions require the caller to be in a request. In this reference, these JSAPI functions are marked with the words "Requires request", like this: Name Type Description cx
JSContext * The context to use. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. ...
...Provides request. In JS_THREADSAFE builds, the JavaScript engine calls this callback only from within an active request on cx. The callback does not need to call JS_BeginRequest()). In particular, JSNative callbacks provide a request. ...
...es request. In JS_THREADSAFE builds, the JavaScript engine calls this callback only from within an active request on cx. The callback does not need to call JS_BeginRequest()). In particular, JSNative callbacks provide a request. This means that any potentially long-running operation in a native must be bracketed with calls to JS_SuspendRequest() and JS_ResumeRequest(). JSBool socket_recv(
JSContext *cx, unsigned int argc, jsval *vp) { ... rc = JS_SuspendRequest(cx); read_size = recv(socket, buf, size, flags); JS_ResumeRequest(cx, rc); ... } Garbage collection Requests help make garbage collection safe when multiple threads are using the JSAPI. For each thread that is in a request: Almost any call into the JSAPI may trigger garbage collection; but Garbage collectio...
...And 2 more matches
XPIDL
ar();' becomes 'nsresult Foo()' in native code (note that capitalization is still applied). However, the capitalization is not applied when using binaryname with attributes; i.e., [binaryname(foo)] readonly attribute Quux bar; becomes Getfoo(Quux**) in native code. Attributes named 'IID' and methods named 'GetIID' are forbidden, although this is checked before binaryname conversion. The implicit_
jscontext and optional_argc parameters are properties which help native code implementations determine how the call was made from script. If implicit_
jscontext is present on a method, then an additional
JSContext *cx parameter is added just after the regular list which receives the context of the caller. If optional_argc is present, then an additional uint8_t _argc method is added at the end which receives...
... Another native-only property is nostdcall. ...
... Another native-only property is nostdcall. Normally, declarations are made in the stdcall ABI on Windows to be ABI-compatible with COM interfaces. ...
...And 2 more matches
Mozilla DOM Hacking Guide
responding to the Data passed in. The implementation is detailed in Section 1.6. static void ShutDown(): Releases the interface pointers. static nsIClassInfo* doCreate(nsDOMClassInfoData* aData): Inline function that returns a nsIClassInfo pointer to a new instance of the nsDOMClassInfo class. static nsresult WrapNative(...): XPConnect fu, not our problem. static nsresult ThrowJSException(
JSContext *cx, nsresult aResult);: help me! static nsresult InitDOMJSClass(
JSContext *cx, JSObject *obj);: help me! static JSClass sDOMJSClass;: help me! Protected section: const nsDOMClassInfoData* mData;: help me! static nsresult Init(): Called only once, it is used to initialize the remaining members of the nsDOMClassInfoData structure, as mentioned above. Once called, Init() sets sIsIniti...
..., as mentioned above. Once called, Init() sets sIsInitialized to true, to remember that the initialization has been performed. The implementation is described in Section 1.5. static nsresult RegisterClassName(PRInt32 aDOMClassInfoID): help me! static nsresult RegisterClassProtos(PRInt32 aDOMClassInfoID): help me! static nsresult RegisterExternalClasses();: help me! nsresult ResolveConstructor(
JSContext *cx, JSObject *obj, JSObject **objp);: help me! static PRInt32 GetArrayIndexFromId(
JSContext *cx, jsval id, PRBool *aIsNumber = nsnull): If the JS value is an integer, then *aIsNumber is true, and the integer is returned. Else, *aIsNumber is false and -1 is returned. static inline PRBool IsReadonlyReplaceable(jsval id) { ... }: help me! static inline PRBool IsWritableReplaceable(jsval id) ...
...OMConstructorProtoClass: XPConnect fu to expose the DOM objects constructors to JavaScript. static JSFunctionSpec sDOMJSClass_methods[];: help me! (bug 91557) static nsIXPConnect *sXPConnect: Used to call nsIXPConnect methods that we need. Initialized in Init(). static nsIScriptSecurityManager *sSecMan: Used by the DOM security engine. Initialized in Init(). static nsresult DefineStaticJSVals(
JSContext *cx);: Used to define all the static JSString data members of nsDOMClassInfo. static PRBool sIsInitialized: Keeps track of wether Class Info was already initialized, because Init() shouldn't be called twice. static jsval *sX_id: strings used in the global resolve methods for comparison with the passed in arguments. They represent special words for the DOM. Initialized by DefineStaticJSVals().
...oData array, initialize the sXPConnect and sSecMan data members, create a new JavaScript Context, define the JSString data members, and register class names and class prototypes. Finally it sets sIsInitialized to true. The actions that concern the DOM are described below. First, the call to CallGetService() initializes sXPConnect. Then the Script Security Manager (sSecMan) is initialized. GetSafe
JSContext() grabs us a cool JS context to run our JavaScript code in. The part about ComponentRegistrar is designed to allow external modules (in this case XPath) to be included in DOMClassInfo and as such benefit from the JavaScript benefits it provides. After that, we fill the blanks in the sClassInfoData array. If you remember the discussion in the introduction to Class Info, there is the main array, s...
JS::CloneFunctionObject
funobj JS::HandleObject The Function to clone. ...
... funobj JS::HandleObject The Function to clone. ...
... funobj JS::HandleObject The Function to clone. ...
... funobj JS::HandleObject The Function to clone. scopeChain JS::AutoObjectVector The new function's scope chain. Description JS::CloneFunctionObject creates a new function object from funobj. The new object has the same code and argument list as funobj. If scopeChain is supplied, it uses scopeChain as its enclosing scope. ...
JS_CallFunction
Calls a specified JS function. ...
... Calls a specified JS function. ...
...* Added in SpiderMonkey 31 */ bool JS_CallFunction(
JSContext *cx, JS::HandleObject obj, JS::HandleFunction fun, const JS::HandleValueArray& args, JS::MutableHandleValue rval); bool JS_CallFunctionName(
JSContext *cx, JS::HandleObject obj, const char *name, const JS::HandleValueArray& args, JS::MutableHandleValue rval); bool JS_CallFunctionValue(
JSContext *cx, JS::HandleObject obj, JS::HandleValue fval, const JS::HandleValueArray& args, JS::MutableHandleValue rval); /* Obsolete since JSAPI 30 */ bool JS_CallFunction(
JSContext *cx, JSObject *obj, JSFunction *fun, unsigned argc, jsval *argv, jsval *rval); bool JS_CallFunctionName(
JSContext *cx, JSObject *obj, const char *name, unsigned argc, ...
... const JS::HandleValueArray& args, JS::MutableHandleValue rval); /* Obsolete since JSAPI 30 */ bool JS_CallFunction(
JSContext *cx, JSObject *obj, JSFunction *fun, unsigned argc, jsval *argv, jsval *rval); bool JS_CallFunctionName(
JSContext *cx, JSObject *obj, const char *name, unsigned argc, jsval *argv, jsval *rval); bool JS_CallFunctionValue(
JSContext *cx, JSObject *obj, jsval fval, unsigned argc, jsval *argv, jsval *rval); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleObject The "current" object on which the func...
JS_ClearContextThread
Obsolete since JSAPI 8This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Transfer a
JSContext from one thread to another. Syntax jsword JS_ClearContextThread(
JSContext *cx); jsword JS_SetContextThread(
JSContext *cx); Name Type Description cx
JSContext * The context to transfer from one thread to another. There must not be any active or suspended requests using this context. ...
.... Transfer a
JSContext from one thread to another. Syntax jsword JS_ClearContextThread(
JSContext *cx); jsword JS_SetContextThread(
JSContext *cx); Name Type Description cx
JSContext * The context to transfer from one thread to another. There must not be any active or suspended requests using this context. Description An application that creates or uses a
JSContext in one thread, then uses or destroys it in another thread, must use JS_ClearContextThread and JS_SetContextThread to transfer the
JSContext safely from one thread to the other. The rules for using
JSContexts in multiple threads are: Each
JSContext may only be used by one thread at a time. Each request runs from start to finish on a single thread. ...
...es or uses a
JSContext in one thread, then uses or destroys it in another thread, must use JS_ClearContextThread and JS_SetContextThread to transfer the
JSContext safely from one thread to the other. The rules for using
JSContexts in multiple threads are: Each
JSContext may only be used by one thread at a time. Each request runs from start to finish on a single thread. Before transferring a
JSContext from thread A to thread B, thread A must call JS_ClearContextThread. This is the last thing thread A does with the context. Before thread B uses the
JSContext, it must call JS_SetContextThread. This is the first thing thread B does with the context, before beginning a request. ...
...h request runs from start to finish on a single thread. Before transferring a
JSContext from thread A to thread B, thread A must call JS_ClearContextThread. This is the last thing thread A does with the context. Before thread B uses the
JSContext, it must call JS_SetContextThread. This is the first thing thread B does with the context, before beginning a request. So the usual code for using a
JSContext on a thread other than the one where it was created looks like this: void myThread(
JSContext *cx) { JS_SetContextThread(cx); /* Note: outside the request */ JS_BeginRequest(cx); ... JS_EndRequest(cx); JS_ClearContextThread(cx); /* Note: outside the request */ } JS_SetContextThread ties cx to the current thread for exclusive use. No other thread may use cx until the curren...
JS_DefineConstDoubles
obj JSObject * Object for which to create new properties. ...
... obj JSObject * Object for which to create new properties. ...
... obj JSObject * Object for which to create new properties. ...
... obj JSObject * Object for which to create new properties. cds JSConstDoubleSpec * Pointer to an array of JSConstDoubleSpec records containing property names and values to create. The last array element must contain zero-valued members. ...
JS_DeleteElement
obj JS::HandleObject Object from which to delete an element. index uint32_t Index number of the element to delete. ...
... obj JS::HandleObject Object from which to delete an element. index uint32_t Index number of the element to delete. ...
... obj JS::HandleObject Object from which to delete an element. index uint32_t Index number of the element to delete. ...
... obj JS::HandleObject Object from which to delete an element. index uint32_t Index number of the element to delete. result JS::ObjectOpResult & (out parameter) Receives the result of the operation. ...
JS_EnterLocalRootScope
Description Scoped local root management allows native functions, getter/setters, etc. ...
... Description Scoped local root management allows native functions, getter/setters, etc. ...
... Description Scoped local root management allows native functions, getter/setters, etc. to avoid calling JS_AddRoot and JS_RemoveRoot to manage global roots temporarily. ...
...er the variable points to at any given moment is protected from GC. By contrast, local root scopes protect newly-created objects, doubles, and strings. There is no need to tell the JS engine about each variable that may point to such a value. Calling JS_EnterLocalRootScope and JS_LeaveLocalRootScope around the body of the native hook protects each object, double, and string created using the same
JSContext from GC. For example: JSBool my_GetProperty(
JSContext *cx, JSObject *obj, jsval id, jsval *vp) { JSBool ok; if (!JS_EnterLocalRootScope(cx)) return JS_FALSE; // This function doesn't need to bother rooting any new objects, // strings, or doubles it creates using cx. Even if JS_GC is // called, these new values will not be collected. ok = my_GetPropertyBody(cx, o...
JS_GetPositiveInfinityValue
Description JS_GetPositiveInfinityValue returns a JS::Value that represents an IEEE floating-point positive infinity. JS_GetNegativeInfinityValue returns the corresponding negative infinity. ...
... Description JS_GetPositiveInfinityValue returns a JS::Value that represents an IEEE floating-point positive infinity. JS_GetNegativeInfinityValue returns the corresponding negative infinity. ...
... Description JS_GetPositiveInfinityValue returns a JS::Value that represents an IEEE floating-point positive infinity. JS_GetNegativeInfinityValue returns the corresponding negative infinity. ...
... Description JS_GetPositiveInfinityValue returns a JS::Value that represents an IEEE floating-point positive infinity. JS_GetNegativeInfinityValue returns the corresponding negative infinity. ...
JS_HasOwnProperty
obj JS::HandleObject Object to search on for the property. ...
... obj JS::HandleObject Object to search on for the property. ...
... obj JS::HandleObject Object to search on for the property. ...
... obj JS::HandleObject Object to search on for the property. name or id const char * or JS::HandleId Name of the property to look up. foundp bool * Non-null pointer to a variable of type bool. ...
JS_InstanceOf
obj JS::Handle<JSObject*> Object to test. ...
... obj JS::Handle<JSObject*> Object to test. ...
... obj JS::Handle<JSObject*> Object to test. clasp JSClass * Class against which to test the object. ...
... obj JS::Handle<JSObject*> Object to test. clasp JSClass * Class against which to test the object. args JS::CallArgs * Optional pointer to arguments. If non-null, report an error if obj is not of type clasp. Added in SpiderMonkey 38 argv jsval * Optional argument vector. ...
JS_NewFunction
Create a new JavaScript function that is implemented in C/C++ as a JSNative. ...
... Create a new JavaScript function that is implemented in C/C++ as a JSNative. ...
... as a JSNative. ...
... const char *name); // Obsolete since JSAPI 44 JSFunction * JS_NewFunctionById(
JSContext *cx, JSNative call, unsigned nargs, unsigned flags, JS::Handle<jsid> id); // Obsolete since JSAPI 39 JSFunction * JS_NewFunction(
JSContext *cx, JSNative call, unsigned nargs, unsigned flags, JS::Handle<JSObject*> parent, const char *name); JSFunction * JS_NewFunctionById(
JSContext *cx, JSNative call, unsigned nargs, unsigned flags, JS::Handle<JSObject*> parent, JS::Handle<jsid> id); // Added in SpiderMonkey 17 Name Type Description cx
JSContext * The context in which to create the new function. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. call JSNative Native...
JS_NewStringCopyZ
s const char * or const char16_t * Pointer to the character array containing the text for the JS string to create; or NULL. ...
... s const char * or const char16_t * Pointer to the character array containing the text for the JS string to create; or NULL. ...
... s const char * or const char16_t * Pointer to the character array containing the text for the JS string to create; or NULL. ...
... s const char * or const char16_t * Pointer to the character array containing the text for the JS string to create; or NULL. ...
JS_ParseJSON
ch JSObject * The object to be searched. ...
... ch JSObject * The object to be searched. ...
... ch JSObject * The object to be searched. ...
... ch JSObject * The object to be searched. chars const jschar * The characters of the string. len uint32 The length of the string. index jsint (in JS_ParseJSONWithReviver only) A reviver function to apply to the created value after parsing; see JSON.parse. vp jsval * Out parameter. ...
JS_PreventExtensions
obj JS::HandleObject Object to be made non-extensible. result JS::ObjectOpResult & (out parameter) Receives the result of the operation. ...
... obj JS::HandleObject Object to be made non-extensible. result JS::ObjectOpResult & (out parameter) Receives the result of the operation. ...
... obj JS::HandleObject Object to be made non-extensible. result JS::ObjectOpResult & (out parameter) Receives the result of the operation. ...
... obj JS::HandleObject Object to be made non-extensible. result JS::ObjectOpResult & (out parameter) Receives the result of the operation. Added in SpiderMonkey 45 succeeded bool * Outparam indicating, on JSAPI success, whether the object is now non-extensible. ...
JS_SetContextCallback
Specifies a callback function that is automatically called whenever a
JSContext is created or destroyed. Syntax void JS_SetContextCallback(JSRuntime *rt,
JSContextCallback cxCallback, void *data); Name Type Description rt JSRuntime * Pointer to a JS runtime. cxCallback
JSContextCallback Pointer to the callback function, described below. data void * Any data passed as 3rd argument to the callback function. Added in SpiderMonkey 31 Callback syntax typedef bool (*
JSContextCallback)(
JSContext *cx, unsigned contextOp, void *data); Name Type Description cx
JSContext * Pointer to a
JSContext which the callback may use to call into JSAPI functions. This is the context which was just created, or is about to...
...ata); Name Type Description cx
JSContext * Pointer to a
JSContext which the callback may use to call into JSAPI functions. This is the context which was just created, or is about to be destroyed. For example, the callback my call JS_GetContextPrivate(cx) in order to free up resources previously allocated by JS_SetContextPrivate. contextOp unsigned See
JSContextOp. For future compatibility the callback must do nothing and return true if any other value is passed. data void * data specified in JS_SetContextCallback. ...
.... For example, the callback my call JS_GetContextPrivate(cx) in order to free up resources previously allocated by JS_SetContextPrivate. contextOp unsigned See
JSContextOp. For future compatibility the callback must do nothing and return true if any other value is passed. data void * data specified in JS_SetContextCallback. Added in SpiderMonkey 31 typedef enum
JSContextOp {
JSCONTEXT_NEW,
JSCONTEXT_DESTROY }
JSContextOp; Enumeration Meaning
JSCONTEXT_NEW JS_NewContext successfully created a new
JSContext instance. The callback can initialize the instance as required. If the callback returns JS_FALSE, the instance will be destroyed and JS_NewContext returns NULL. In this case the callback is not called again.
JSCONTEXT_DE...
... called again.
JSCONTEXT_DESTROY One of JS_DestroyContext, JS_DestroyContextNoGC, or JS_DestroyContextMaybeGC was called. The callback may perform its own cleanup and must always return true. In a DEBUG build, if the callback returns false, the JS engine will halt with an assertion. Description JS_SetContextCallback specifies a callback function that is automatically called when
JSContexts are created or destroyed. Only one callback function may be specified per JS runtime. This function returns the previous context callback, if any, else NULL. See Also MXR ID Search for JS_SetContextCallback JS_NewContext JS_DestroyContext JS_DestroyContextNoGC JS_DestroyContextMaybeGC JS_GetContextPrivate JS_SetContextPrivate bug 845545 ...
JS_SetGCCallback
The GC callback of the associated JSRuntime is set. rt JSRuntime * The JSRuntime for which to set the GC callback. ...
...The GC callback of the associated JSRuntime is set. rt JSRuntime * The JSRuntime for which to set the GC callback. ...
...The GC callback of the associated JSRuntime is set. rt JSRuntime * The JSRuntime for which to set the GC callback. cb JSGCCallback Pointer to the new callback function to use. ...
...k. cb JSGCCallback Pointer to the new callback function to use. Callback syntax typedef enum JSGCStatus { JSGC_BEGIN, JSGC_END, JSGC_MARK_END, // Obsolete since JSAPI 13 JSGC_FINALIZE_END // Obsolete since JSAPI 13 } JSGCStatus; typedef void (* JSGCCallback)(JSRuntime *rt, JSGCStatus status, void *data); Name Type Description cx
JSContext * The context in which garbage collection is happening. status JSGCStatus One of the JSGCStatus constants, described below, indicating the stage of GC. Description JS_SetGCCallback sets a callback function which the garbage collector calls at several points during garbage collection. rt is the runtime in which you specify the callback. cb is a pointer to the new callback f...
JS_SetOperationCallback
ed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.5 Set a callback function that is automatically called periodically while JavaScript code runs. These methods/types are renamed to JS_SetInterruptCallback, JS_GetInterruptCallback, JS_RequestInterruptCallback and JSInterruptCallback in SpiderMonkey 30. Syntax void JS_SetOperationCallback(
JSContext *cx, JSOperationCallback callback); JSOperationCallback JS_GetOperationCallback(
JSContext *cx); void JS_TriggerOperationCallback(JSRuntime *rt); Name Type Description cx
JSContext * A context. rt JSRuntime * The runtime. callback JSOperationCallback (only in JS_SetOperationCallback) The callback function to install. Callback s...
... The callback may use this context to call JSAPI functions, but it should first use JS_SetOperationCallback to set the context's operation callback to NULL. ...
... The callback may use this context to call JSAPI functions, but it should first use JS_SetOperationCallback to set the context's operation callback to NULL. Otherwise the engine may call the operation callback again, reentering it. ...
... The callback may use this context to call JSAPI functions, but it should first use JS_SetOperationCallback to set the context's operation callback to NULL. Otherwise the engine may call the operation callback again, reentering it. Provides request. ...
JS_SetOptions
options uint32 The new set of options. This is the logical OR of zero or more flags described below. ...
... options uint32 The new set of options. This is the logical OR of zero or more flags described below. ...
... options uint32 The new set of options. This is the logical OR of zero or more flags described below. ...
...on, the application promises to the compiler that a null rval out-param will be passed to each call to JS_ExecuteScript. MXR ID Search for JSOPTION_NO_SCRIPT_RVAL JSOPTION_UNROOTED_GLOBAL Added in SpiderMonkey 1.8.1 Instructs the garbage collector not to consider the context's global object a root. The application must ensure that the global object survives as long as the
JSContext. MXR ID Search for JSOPTION_UNROOTED_GLOBAL See Also MXR ID Search for JS_SetOptions JS_GetOptions JS_ToggleOptions bug 880330 ...
nsIAppShellService
void hideSplashScreen(); Obsolete since Gecko 1.8 void initialize(in nsICmdLineService aCmdLineService, in nsISupports nativeAppSupportOrSplashScreen); Obsolete since Gecko 1.8 void quit(in PRUint32 aFerocity); Obsolete since Gecko 1.8 void registerTopLevelWindow(in nsIXULWindow aWi...
...ervice aCmdLineService, in boolean canInteract); Obsolete since Gecko 1.8 void ensure1Window(in nsICmdLineService aCmdLineService); Obsolete since Gecko 1.8 void enterLastWindowClosingSurvivalArea(); Obsolete since Gecko 1.8 void exitLastWindowClosingSurvivalArea(); Obsolete since Gecko 1.8 void getHiddenWindowAnd
JSContext(out nsIDOMWindow aHiddenDOMWindow, out
JSContext a
JSContext); Native code only! void hideSplashScreen(); Obsolete since Gecko 1.8 void initialize(in nsICmdLineService aCmdLineService, in nsISupports nativeAppSupportOrSplashScreen); Obsolete since Gecko 1.8 void quit(in PRUint32 aFerocity); Obsolete since Gecko 1.8 void registerTopLevelWindow(in nsIXULWindow aWindow); void run(); Obsolete since Gecko ...
... platforms that do not normally quit when the last window has closed, call Enter once, but not Exit) void enterLastWindowClosingSurvivalArea(); Parameters None. exitLastWindowClosingSurvivalArea() Obsolete since Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0) void exitLastWindowClosingSurvivalArea(); Parameters None. Native code only!getHiddenWindowAnd
JSContext Return the (singleton) application hidden window as an nsIDOMWindow, and, the corresponding JavaScript context pointer. This is useful if you'd like to subsequently call OpenDialog on the hidden window. void getHiddenWindowAnd
JSContext( out nsIDOMWindow aHiddenDOMWindow, out
JSContext a
JSContext ); Parameters aHiddenDOMWindow The hidden window QueryInterface'd to type nsIDOMWindow. a...
... Return the (singleton) application hidden window as an nsIDOMWindow, and, the corresponding JavaScript context pointer. This is useful if you'd like to subsequently call OpenDialog on the hidden window. void getHiddenWindowAnd
JSContext( out nsIDOMWindow aHiddenDOMWindow, out
JSContext a
JSContext ); Parameters aHiddenDOMWindow The hidden window QueryInterface'd to type nsIDOMWindow. a
JSContext The corresponding JavaScript context. hideSplashScreen() Obsolete since Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0) Remove the splash screen (if visible). This need be called only once per application session. void hideSplashScreen(); Parameters None. initialize() Obsolete since Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey ...
JS::CallArgs
function call. Syntax JS::CallArgs JS::CallArgsFromVp(unsigned argc, JS::Value *vp); Name Type Description args unsigned Number of argument. (2nd argument of JSNative) vp JS::Value * A pointer to the argument value array. (3nd argument of JSNative) Methods Methods of JS::CallArgs Method Description bool requireAtLeast(
JSContext *cx, const char *fnname, unsigned required) Returns true if there are at least required arguments passed in. If false, it reports an error message on the context. Methods inherited from JS::CallArgsBase Method Description unsigned length() const Returns the number of arguments.. JS::MutableHandleValue operator[](unsigned i) const Returns the i-th zer...
...n being called, as a value. Must not be called after rval() has been used! JS::HandleValue thisv() const Returns the this value passed to the function. This method must not be called when the function is being called as a constructor via new. The value may or may not be an object: it is the individual function's responsibility to box the value if needed. JS::Value computeThis(
JSContext *cx) const Returns the this value if this is an object, otherwise calls JS_ComputeThis and returns it. bool isConstructing() const Returns true if the function is called via new. MutableHandleValue rval() const Returns the currently-set return value. The initial contents of this value are unspecified. Once this method has been called, callee() and calleev() can no ...
...ts will require changing methods' signatures but won't require invasive changes to the methods' implementations, potentially under time pressure. JS::CallArgs encapsulates access to the callee, this, the function call's arguments, and eventual return value for a function call. The principal way to create a CallArgs is like so, using JS::CallArgsFromVp: static bool FunctionReturningArgcTimesArg0(
JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); // Guard against no arguments or a non-numeric arg0. if (args.length() == 0 || !args[0].isNumber()) { args.rval().setInt32(0); return true; } // Access to the callee must occur before accessing/setting // the return value. JSObject &callee = rec.callee(); // It...
JS::Construct
fun JS::HandleValue Pointer to the function to call. Should be a native function or JSAPI-compiled function.. ...
... fun JS::HandleValue Pointer to the function to call. Should be a native function or JSAPI-compiled function.. ...
... fun JS::HandleValue Pointer to the function to call. Should be a native function or JSAPI-compiled function.. args JS::HandleValueArray & Arguments you are passing to the function. rval JS::MutableHandleValue Out parameter. ...
JS::CurrentGlobalOrNull
Description JS::CurrentGlobalOrNull() returns the global object for whatever function is currently running on the context. In other words, it returns the global object on the current scope chain. ...
... Description JS::CurrentGlobalOrNull() returns the global object for whatever function is currently running on the context. In other words, it returns the global object on the current scope chain. ...
... Description JS::CurrentGlobalOrNull() returns the global object for whatever function is currently running on the context. In other words, it returns the global object on the current scope chain. ...
JS::GetSelfHostedFunction
selfHostedName const char* Function name in the self-hosted JavaScript. ...
... selfHostedName const char* Function name in the self-hosted JavaScript. ...
... selfHostedName const char* Function name in the self-hosted JavaScript. id JS::Handle<jsid> A pointer to jsid of the name to assign to the new function. nargs unsigned Number of arguments the function expects. ...
JS::OrdinaryToPrimitive
obj JS::HandleObject The object to convert. type JSType The type of converted value. vp JS::MutableHandleValue Out parameter. ...
... obj JS::HandleObject The object to convert. type JSType The type of converted value. vp JS::MutableHandleValue Out parameter. ...
... obj JS::HandleObject The object to convert. type JSType The type of converted value. vp JS::MutableHandleValue Out parameter. On success, *vp receives the converted value. ...
JS::PropertySpecNameToPermanentId
name const char * JSPropertySpec::name or JSFunctionSpec::name. idp jsid * Out parameter. Receives the created id. ...
... name const char * JSPropertySpec::name or JSFunctionSpec::name. idp jsid * Out parameter. Receives the created id. ...
... name const char * JSPropertySpec::name or JSFunctionSpec::name. idp jsid * Out parameter. Receives the created id. ...
JS::ProtoKeyToId
key JSProtoKey The prototype key to convert. vp JS::MutableHandleId Out parameter. *idp receives the converted id. Description JS::ProtoKeyToId converts a specified JS prototype key key, to a JS ID. ...
... key JSProtoKey The prototype key to convert. vp JS::MutableHandleId Out parameter. *idp receives the converted id. Description JS::ProtoKeyToId converts a specified JS prototype key key, to a JS ID. ...
... key JSProtoKey The prototype key to convert. vp JS::MutableHandleId Out parameter. *idp receives the converted id. Description JS::ProtoKeyToId converts a specified JS prototype key key, to a JS ID. ...
JS::ToInt32
v JS::HandleValue The value to convert. out int32_t * Out parameter. On success, *out receives the converted floating-point value. Description JS::ToInt32 converts a JavaScript value to a signed 32bit integer. ...
... v JS::HandleValue The value to convert. out int32_t * Out parameter. On success, *out receives the converted floating-point value. Description JS::ToInt32 converts a JavaScript value to a signed 32bit integer. ...
... v JS::HandleValue The value to convert. out int32_t * Out parameter. On success, *out receives the converted floating-point value. Description JS::ToInt32 converts a JavaScript value to a signed 32bit integer. ...
JS::ToInt64
v JS::HandleValue The value to convert. out int64_t * Out parameter. On success, *out receives the converted floating-point value. Description JS::ToInt64 converts a JavaScript value to a signed 64bit integer. ...
... v JS::HandleValue The value to convert. out int64_t * Out parameter. On success, *out receives the converted floating-point value. Description JS::ToInt64 converts a JavaScript value to a signed 64bit integer. ...
... v JS::HandleValue The value to convert. out int64_t * Out parameter. On success, *out receives the converted floating-point value. Description JS::ToInt64 converts a JavaScript value to a signed 64bit integer. ...
JS::ToNumber
v JS::HandleValue The value to convert. out double * Out parameter. On success, *out receives the converted floating-point value. Description JS::ToNumber converts a JavaScript value to a number. ...
... v JS::HandleValue The value to convert. out double * Out parameter. On success, *out receives the converted floating-point value. Description JS::ToNumber converts a JavaScript value to a number. ...
... v JS::HandleValue The value to convert. out double * Out parameter. On success, *out receives the converted floating-point value. Description JS::ToNumber converts a JavaScript value to a number. ...
JS::ToPrimitive
obj JS::HandleObject The object to convert. ...
... obj JS::HandleObject The object to convert. ...
... obj JS::HandleObject The object to convert. hint JSType The hint to pass to the ToPrimitive and @@toPrimitive method when converting the object. hint must be JSTYPE_STRING or JSTYPE_NUMBER to pass the corresponding type as a hint, or JSTYPE_VOID to pass no hint. ...
JS::ToString
v JS::HandleValue The value to convert. ...
... v JS::HandleValue The value to convert. ...
... v JS::HandleValue The value to convert. Description JS::ToString returns a string representation of a JavaScript value. If v.isString() is true, it calls v.toString(). ...
JS::ToUint16
v JS::HandleValue The value to convert. out uint16_t * Out parameter. On success, *out receives the converted floating-point value. ...
... v JS::HandleValue The value to convert. out uint16_t * Out parameter. On success, *out receives the converted floating-point value. ...
... v JS::HandleValue The value to convert. out uint16_t * Out parameter. On success, *out receives the converted floating-point value. ...
JS::ToUint32
v JS::HandleValue The value to convert. out int32_t * Out parameter. On success, *out receives the converted floating-point value. ...
... v JS::HandleValue The value to convert. out int32_t * Out parameter. On success, *out receives the converted floating-point value. ...
... v JS::HandleValue The value to convert. out int32_t * Out parameter. On success, *out receives the converted floating-point value. ...
JS::ToUint64
v JS::HandleValue The value to convert. out uint64_t * Out parameter. On success, *out receives the converted floating-point value. ...
... v JS::HandleValue The value to convert. out uint64_t * Out parameter. On success, *out receives the converted floating-point value. ...
... v JS::HandleValue The value to convert. out uint64_t * Out parameter. On success, *out receives the converted floating-point value. ...
JSID_IS_STRING
id jsid The property identifier to test or convert. ...
... id jsid The property identifier to test or convert. ...
... id jsid The property identifier to test or convert. str JSString * An interned string to convert to an id. Description JSID_IS_STRING tests whether a specified JS ID, id, is a string, and returns true if it's a string. JSID_TO_STRING converts a specified JS ID, id to a JSString *. ...
JSResolveOp
obj JS::HandleObject Pointer to the object whose properties are being accessed. id JS::HandleId The name or index of the property being resolved. resolvedp bool * Out parameter. ...
... obj JS::HandleObject Pointer to the object whose properties are being accessed. id JS::HandleId The name or index of the property being resolved. resolvedp bool * Out parameter. ...
... obj JS::HandleObject Pointer to the object whose properties are being accessed. id JS::HandleId The name or index of the property being resolved. resolvedp bool * Out parameter. ...
JS_BindCallable
callable JS::Handle<JSObject*> Pointer to the function object to bind new this. ...
... callable JS::Handle<JSObject*> Pointer to the function object to bind new this. ...
... callable JS::Handle<JSObject*> Pointer to the function object to bind new this. newThis JS::Handle<JSObject*> Pointer to the new this value for callable. Description JS_BindCallable binds the given callable to use the given object as this. ...
JS_BufferIsCompilableUnit
obj JS::HandleObject The global object, or NULL. utf8 const char * String containing the script to compile. length size_t The length of utf8 in characters. ...
... obj JS::HandleObject The global object, or NULL. utf8 const char * String containing the script to compile. length size_t The length of utf8 in characters. ...
... obj JS::HandleObject The global object, or NULL. utf8 const char * String containing the script to compile. length size_t The length of utf8 in characters. ...
JS_ClearDateCaches
Description JS_ClearDateCaches clears the cache of calculated local time from each Date object. Call to propagate a system timezone change. ...
... Description JS_ClearDateCaches clears the cache of calculated local time from each Date object. Call to propagate a system timezone change. ...
... Description JS_ClearDateCaches clears the cache of calculated local time from each Date object. Call to propagate a system timezone change. ...
JS_DecompileFunction
fun JS::Handle<JSFunction*> Function to decompile. Description JS_DecompileFunction generates the complete source code of a function declaration from a function's compiled form, fun. ...
... fun JS::Handle<JSFunction*> Function to decompile. Description JS_DecompileFunction generates the complete source code of a function declaration from a function's compiled form, fun. ...
... fun JS::Handle<JSFunction*> Function to decompile. Description JS_DecompileFunction generates the complete source code of a function declaration from a function's compiled form, fun. ...
JS_DecompileFunctionBody
fun JS::Handle<JSFunction*> The function to decompile. ...
... fun JS::Handle<JSFunction*> The function to decompile. ...
... fun JS::Handle<JSFunction*> The function to decompile. indent unsigned If it's not JS_DONT_PRETTY_PRINT, JS_DecompileFunction returns pretty printed source code of the function. ...
JS_DefineFunctions
obj JS::Handle<JSObject*> The object on which functions are to be defined. fs const JSFunctionSpec * A NULL-terminated array of function specifications. ...
... obj JS::Handle<JSObject*> The object on which functions are to be defined. fs const JSFunctionSpec * A NULL-terminated array of function specifications. ...
... obj JS::Handle<JSObject*> The object on which functions are to be defined. ...
JS_DefineObject
obj JS::HandleObject Object to which this new object belongs as a property. name const char * Name of the property being defined in obj to hold the new object. clasp const JSClass * Class to use for the new object. ...
... obj JS::HandleObject Object to which this new object belongs as a property. name const char * Name of the property being defined in obj to hold the new object. clasp const JSClass * Class to use for the new object. ...
... obj JS::HandleObject Object to which this new object belongs as a property. name const char * Name of the property being defined in obj to hold the new object. clasp const JSClass * Class to use for the new object. ...
JS_DeleteProperty2
Obsolete since JSAPI 39This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Removes a specified property from an object. Renamed to JS_DeleteProperty from JSAPI 39. ...
...eature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Removes a specified property from an object. Renamed to JS_DeleteProperty from JSAPI 39. Syntax bool JS_DeleteProperty2(
JSContext *cx, JS::HandleObject obj, const char *name, bool *succeeded); bool JS_DeleteUCProperty2(
JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen, bool *succeeded); bool JS_DeletePropertyById2(
JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *succeeded); // Added in SpiderMonkey 1.8.1 Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requi...
... obj JS::HandleObject Object from which to delete a property. name or id const char * or const char16_t or JS::HandleId Name of the property to delete. namelen size_t (only in JS_DeleteUCProperty2) The length of name in characters; or -1 to indicate that name is null-terminated. ...
JS_DropExceptionState
state JSExceptionState * Pointer to the JSExceptionState object to destroy. ...
... state JSExceptionState * Pointer to the JSExceptionState object to destroy. ...
... state JSExceptionState * Pointer to the JSExceptionState object to destroy. ...
JS_EncodeString
str JSString * / JS::HandleString A string to encode. Description JS_EncodeString and JS_EncodeStringToUTF8 convert the specified JavaScript str to a C string (an array of 8-bit chars). ...
... str JSString * / JS::HandleString A string to encode. Description JS_EncodeString and JS_EncodeStringToUTF8 convert the specified JavaScript str to a C string (an array of 8-bit chars). ...
... str JSString * / JS::HandleString A string to encode. Description JS_EncodeString and JS_EncodeStringToUTF8 convert the specified JavaScript str to a C string (an array of 8-bit chars). ...
JS_EncodeStringToBuffer
str JSString * A string to encode. buffer char * A character buffer to receive encoded string. length size_t The size of buffer in bytes. ...
... str JSString * A string to encode. buffer char * A character buffer to receive encoded string. length size_t The size of buffer in bytes. ...
... str JSString * A string to encode. buffer char * A character buffer to receive encoded string. length size_t The size of buffer in bytes. ...
JS_FlattenString
str JSString * The string to flatten. Description JS_FlattenString flattens a string str and returns a pointer to JSFlatString. ...
... str JSString * The string to flatten. Description JS_FlattenString flattens a string str and returns a pointer to JSFlatString. ...
... str JSString * The string to flatten. Description JS_FlattenString flattens a string str and returns a pointer to JSFlatString. ...
JS_GetArrayPrototype
forObj JS::HandleObject An object from the global whose Array.prototype is being retrieved. ...
... forObj JS::HandleObject An object from the global whose Array.prototype is being retrieved. ...
... forObj JS::HandleObject An object from the global whose Array.prototype is being retrieved. Description JS_GetArrayPrototype() retrieves the original Array.prototype of a specified object, obj. If an error occurs, it returns NULL. ...
JS_GetElement
obj JS::HandleObject The object to search for the element. index uint32_t Index of the element to look up. vp JS::MutableHandleValue Out parameter. ...
... obj JS::HandleObject The object to search for the element. index uint32_t Index of the element to look up. vp JS::MutableHandleValue Out parameter. ...
... obj JS::HandleObject The object to search for the element. index uint32_t Index of the element to look up. vp JS::MutableHandleValue Out parameter. On success, *vp receives the current value of the element, if it exists, and undefined otherwise. ...
JS_GetFunctionPrototype
forObj JS::HandleObject An object from the global whose Function.prototype is being retrieved. ...
... forObj JS::HandleObject An object from the global whose Function.prototype is being retrieved. ...
... forObj JS::HandleObject An object from the global whose Function.prototype is being retrieved. Description JS_GetFunctionPrototype() retrieves the original Function.prototype of a specified object, obj. If an error occurs, it returns NULL. ...
JS_GetFunctionScript
fun JS::HandleFunction Pointer to a JS function. ...
... fun JS::HandleFunction Pointer to a JS function. ...
... fun JS::HandleFunction Pointer to a JS function. ...
JS_GetGlobalForCompartmentOrNull
c JSCompartment * The compartment for which to return the global object. ...
... c JSCompartment * The compartment for which to return the global object. ...
... c JSCompartment * The compartment for which to return the global object. Description JS_GetGlobalForCompartmentOrNull() returns the global object for the context and the compartment. ...
JS_GetInstancePrivate
obj JS::Handle<JSObject*> The object for which to retrieve private data. ...
... obj JS::Handle<JSObject*> The object for which to retrieve private data. ...
... obj JS::Handle<JSObject*> The object for which to retrieve private data. clasp JSClass * Class against which to test the object. args JS::CallArgs * Optional argument, used for error reporting. ...
JS_GetLocaleCallbacks
Get and set locale specific string conversion and error message callbacks. Syntax JSLocaleCallbacks * JS_GetLocaleCallbacks(JSRuntime *rt); void JS_SetLocaleCallbacks(JSRuntime *rt, JSLocaleCallbacks *callbacks); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. callbacks JSLocaleCallbacks * Pointer to a JSLocaleCallbacks struct. Callback functions struct JSLocaleCallbacks { JSLocaleToUpperCase localeToUpperCase; JSLocaleToLowerCase localeToLowerCase; JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API JSLocaleToUnicode localeToUnicode; };...
...Context. callbacks JSLocaleCallbacks * Pointer to a JSLocaleCallbacks struct. ...
...ck functions struct JSLocaleCallbacks { JSLocaleToUpperCase localeToUpperCase; JSLocaleToLowerCase localeToLowerCase; JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API JSLocaleToUnicode localeToUnicode; }; typedef bool (* JSLocaleToUpperCase)(
JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool (* JSLocaleToLowerCase)(
JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval); typedef bool (* JSLocaleCompare)(
JSContext *cx, JS::HandleString src1, JS::HandleString src2, JS::MutableHandleValue rval); typedef bool (* JSLocaleToUnicode)(
JSContext *cx, const char *src, JS::MutableHandleValue rval); Type Description JSLocaleToUpperCase Implementation of String.prototype.to...
JS_GetObjectPrototype
forObj JS::HandleObject An object from the global whose Object.prototype is being retrieved. ...
... forObj JS::HandleObject An object from the global whose Object.prototype is being retrieved. ...
... forObj JS::HandleObject An object from the global whose Object.prototype is being retrieved. Description JS_GetObjectPrototype() retrieves the original Object.prototype of a specified object, obj. If an error occurs, it returns NULL. ...
JS_GetOptions
Description JS_GetOptions retrieves the option flags of a given JS context cx. ...
... Description JS_GetOptions retrieves the option flags of a given JS context cx. ...
... Description JS_GetOptions retrieves the option flags of a given JS context cx. ...
JS_GetPropertyAttrsGetterAndSetter
Obsolete since JSAPI 26This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Retrieve the attributes, getter, and setter of a specified property. ...
...sers, its use is discouraged since it could be removed at any time. Try to avoid using it. Retrieve the attributes, getter, and setter of a specified property. ...
...ter(
JSContext *cx, JSObject *obj, const char *name, unsigned int *attrsp, JSBool *foundp, JSPropertyOp *getterp, JSPropertyOp *setterp); JSBool JS_GetUCPropertyAttrsGetterAndSetter(
JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, unsigned int *attrsp, JSBool *foundp, JSPropertyOp *getterp, JSPropertyOp *setterp); JSBool JS_GetPropertyAttrsGetterAndSetterById(
JSContext *cx, JSObject *obj, jsid id, unsigned int *attrsp, JSBool *foundp, JSPropertyOp *getterp, JSPropertyOp *setterp); // Added in SpiderMonkey 1.8.1 Name Type Description cx
JSContext * The context in which to perform the property lookup. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * ...
JS_GetStringCharAt
str JSString * or JSFlatString * The string to get character. index size_t An integer between 0 and 1-less-than the length of the string. ...
... str JSString * or JSFlatString * The string to get character. index size_t An integer between 0 and 1-less-than the length of the string. ...
... str JSString * or JSFlatString * The string to get character. index size_t An integer between 0 and 1-less-than the length of the string. res char16_t * (JS_GetStringCharAt only) Out parameter. On successful, receives the character code. ...
JS_GetStringEncodingLength
str JSString * A string to encode. Description JS_GetStringEncodingLength returns the length of the specified string in bytes, regardless of its encoding. ...
... str JSString * A string to encode. Description JS_GetStringEncodingLength returns the length of the specified string in bytes, regardless of its encoding. ...
... str JSString * A string to encode. Description JS_GetStringEncodingLength returns the length of the specified string in bytes, regardless of its encoding. ...
JS_GetVersion
The result is one of the JSVersion constants. When a context is created, its version is initially JSVERSION_DEFAULT. Scripts are compiled using the latest version of the JavaScript language. ...
...The result is one of the JSVersion constants. When a context is created, its version is initially JSVERSION_DEFAULT. Scripts are compiled using the latest version of the JavaScript language. ...
...The result is one of the JSVersion constants. When a context is created, its version is initially JSVERSION_DEFAULT. Scripts are compiled using the latest version of the JavaScript language. ...
JS_HasInstance
obj JS::Handle<JSObject*> Constructor/prototype to test. v JS::Handle<JS::Value> The value to test. bp bool * Out parameter. On success, *bp receives the result of the test. ...
... obj JS::Handle<JSObject*> Constructor/prototype to test. v JS::Handle<JS::Value> The value to test. bp bool * Out parameter. On success, *bp receives the result of the test. ...
... obj JS::Handle<JSObject*> Constructor/prototype to test. v JS::Handle<JS::Value> The value to test. bp bool * Out parameter. On success, *bp receives the result of the test. ...
JS_IdToProtoKey
id JS::HandleId The property identifier to convert. Description JS_IdToProtoKey converts a specified JS ID, id, to a prototype key. ...
... id JS::HandleId The property identifier to convert. Description JS_IdToProtoKey converts a specified JS ID, id, to a prototype key. ...
... id JS::HandleId The property identifier to convert. Description JS_IdToProtoKey converts a specified JS ID, id, to a prototype key. ...
JS_InitStandardClasses
obj JS::Handle<JSObject*> The global object to initialize. This object must be of a JSClass that has the JSCLASS_GLOBAL_FLAGS bits set. ...
... obj JS::Handle<JSObject*> The global object to initialize. This object must be of a JSClass that has the JSCLASS_GLOBAL_FLAGS bits set. ...
... obj JS::Handle<JSObject*> The global object to initialize. This object must be of a JSClass that has the JSCLASS_GLOBAL_FLAGS bits set. Description JS_InitStandardClasses initializes the built-in JavaScript global properties. ...
JS_InternJSString
str JS::HandleString A string to be interned. ...
... str JS::HandleString A string to be interned. ...
... str JS::HandleString A string to be interned. ...
JS_IsArrayObject
value JS::HandleValue The value to examine. obj JS::HandleObject The object to examine. isArray bool Whether the value/object is an array. Description JS_IsArrayObject determines if a specified object, obj or value, is an Array object. ...
... value JS::HandleValue The value to examine. obj JS::HandleObject The object to examine. isArray bool Whether the value/object is an array. Description JS_IsArrayObject determines if a specified object, obj or value, is an Array object. ...
... value JS::HandleValue The value to examine. obj JS::HandleObject The object to examine. isArray bool Whether the value/object is an array. Description JS_IsArrayObject determines if a specified object, obj or value, is an Array object. ...
JS_IsExtensible
obj JS::HandleObject The object to examine. extensible bool * Out parameter. Receives true if extensible, false otherwise. Description JS_IsExtensible queries [[Extensible]] property of the specified object, obj. ...
... obj JS::HandleObject The object to examine. extensible bool * Out parameter. Receives true if extensible, false otherwise. Description JS_IsExtensible queries [[Extensible]] property of the specified object, obj. ...
... obj JS::HandleObject The object to examine. extensible bool * Out parameter. Receives true if extensible, false otherwise. Description JS_IsExtensible queries [[Extensible]] property of the specified object, obj. ...
JS_IsIdentifier
str JS::HandleString The string to test. ...
... str JS::HandleString The string to test. ...
... str JS::HandleString The string to test. chars const char16_t * The pointer of the string to test. length size_t The length of chars. isIdentifier bool * Out parameter. On success, *isIdentifier receives whether str is an identifier or not. ...
JS_LooselyEqual
v1, v2 JS::Handle<JS::Value> The value to compare. equal bool * Out parameter. ...
... v1, v2 JS::Handle<JS::Value> The value to compare. equal bool * Out parameter. ...
... v1, v2 JS::Handle<JS::Value> The value to compare. equal bool * Out parameter. Receives the comparison result. Description JS_LooselyEqual determines if v1 is loosely equal to v2 under the JavaScript == operator, as specified in ECMA 262-3 ?11.9.3. ...
JS_MakeStringImmutable
s JSString * The string to operate on. s must not be null. ...
... s JSString * The string to operate on. s must not be null. ...
... s JSString * The string to operate on. s must not be null. ...
JS_NewContext
Create a new
JSContext. Syntax
JSContext * JS_NewContext(JSRuntime *rt, size_t stackChunkSize); Name Type Description rt JSRuntime * Parent runtime for the new context. JavaScript objects, functions, strings, and numbers may be shared among the contexts in a JSRuntime, but they cannot be shared across JSRuntimes. stackchunksize size_t The size, in bytes, of each "stack chunk". This is a memory management tuning parameter which most users should not adjust. 8192 is a good default value. Description JS_NewContext creates a new
JSContext in the runtime rt. On success, it returns a pointer to the new context. Otherwise it returns NULL. For more details about contexts, see
JSContext. ...
... The stackchunksize parameter does not control the JavaScript stack size. ...
...t control the JavaScript stack size. (The JSAPI does not provide a way to adjust the stack depth limit.) Passing a large number for stackchunksize is a mistake. In a DEBUG build, large chunk sizes can degrade performance dramatically. The usual value of 8192 is recommended. The application must call JS_DestroyContext when it is done using the context. Before a JSRuntime may be destroyed, all the
JSContexts associated with it must be destroyed. The new
JSContext initially has no global object. The new
JSContext is associated with the calling thread. No other thread may use it or destroy it. See Also MXR ID Search for JS_NewContext JS_DestroyContext JS_ContextIterator JS_SetContextCallback ...
JS_NewDateObject
year int The year to set the new object to. mon int The month to set the new object to. ...
... year int The year to set the new object to. mon int The month to set the new object to. ...
... year int The year to set the new object to. mon int The month to set the new object to. mday int The day of the month to set the new object to. hour int The hour to set the new object to. ...
JS_NewDependentString
str JS::HandleString The string containing the characters for the new string. start size_t The start index of the substring. length size_t Length of the substring, in characters. ...
... str JS::HandleString The string containing the characters for the new string. start size_t The start index of the substring. length size_t Length of the substring, in characters. ...
... str JS::HandleString The string containing the characters for the new string. start size_t The start index of the substring. length size_t Length of the substring, in characters. ...
JS_NewPlainObject
Description JS_NewPlainObject creates a new plain object, like new Object(), with Object.prototype as [[Prototype]]. ...
... Description JS_NewPlainObject creates a new plain object, like new Object(), with Object.prototype as [[Prototype]]. ...
... Description JS_NewPlainObject creates a new plain object, like new Object(), with Object.prototype as [[Prototype]]. ...
JS_NewStringCopyN
s const char* or const char16_t * Pointer to the array of characters containing the text for the JS string to create. n size_t Number of characters to copy from s into the new string. ...
... s const char* or const char16_t * Pointer to the array of characters containing the text for the JS string to create. n size_t Number of characters to copy from s into the new string. ...
... s const char* or const char16_t * Pointer to the array of characters containing the text for the JS string to create. n size_t Number of characters to copy from s into the new string. ...
JS_ObjectIsDate
obj JSObject * JSObject that should be checked. ...
... obj JSObject * JSObject that should be checked. ...
... obj JSObject * JSObject that should be checked. Description JS_ObjectIsDate() can be used to check if you are dealing with a Date object, or a Date object used across compartments (or windows or sites, in the browser embedding). ...
JS_PutEscapedString
buffer char * A pointer to char buffer to write into. size size_t The size of buffer in bytes. ...
... buffer char * A pointer to char buffer to write into. size size_t The size of buffer in bytes. ...
... buffer char * A pointer to char buffer to write into. size size_t The size of buffer in bytes. str JSString * or JSFlatString * A string to write into the file. quote char One of 0, single quote, and double quote. ...
JS_RestoreExceptionState
state JSExceptionState * Pointer to the JSExceptionState object to restore exception state from. ...
... state JSExceptionState * Pointer to the JSExceptionState object to restore exception state from. ...
... state JSExceptionState * Pointer to the JSExceptionState object to restore exception state from. ...
JS_SetFunctionCallback
f code, and is particularly useful for JavaScript tracers and profilers since it works across all run modes (interpreter, method JIT, trace JIT). Using this function may have a significant performance impact. See Function tracing for an example. Note: This method is only available if MOZ_TRACE_JSCALLS was defined at compile time using --enable-trace-jscalls. Syntax void JS_SetFunctionCallback(
JSContext *cx, JSFunctionCallback fcb); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. fcb JSFunctionCallback The callback to execute when JavaScript functions are invoked and exited. Specify NULL to stop callin...
... entering int true if the callback is being called because the specified function is bein...
...ate stack traces, and set breakpoints.) Callback syntax typedef void (* JSFunctionCallback)(const JSFunction *fun,const JSScript *scr, const
JSContext *cx, int entering); Name Type Description fun const JSFunction * The JavaScript function being invoked or exited. scr const JSScript * The script being executed. cx
JSContext * The JavaScript context in which the script is being run. entering int true if the callback is being called because the specified function is being invoked or false if the function is exiting. See Also MXR ID Search for JS_SetFunctionCallback Function tracing JS_GetFunctionCallback bug 1103269 ...
JS_SetVersion
version JSVersion Version of JavaScript to set context to. ...
... version JSVersion Version of JavaScript to set context to. ...
... version JSVersion Version of JavaScript to set context to. ...
JS_StringEqualsAscii
str JSFlatString * String to compare. asciiBytes const char * ASCII string to compare with. match bool * (JS_StringEqualsAscii only) Out parameter. ...
... str JSFlatString * String to compare. asciiBytes const char * ASCII string to compare with. match bool * (JS_StringEqualsAscii only) Out parameter. ...
... str JSFlatString * String to compare. asciiBytes const char * ASCII string to compare with. match bool * (JS_StringEqualsAscii only) Out parameter. Received the comparison result. ...
JS_ToggleOptions
options uint32 The set of options to toggle. This is the logical OR of zero or more flags described at JS_SetOptions. ...
... options uint32 The set of options to toggle. This is the logical OR of zero or more flags described at JS_SetOptions. ...
... options uint32 The set of options to toggle. This is the logical OR of zero or more flags described at JS_SetOptions. ...
JS_ValueToFunction
v JS::HandleValue The value to convert. Description JS_ValueToFunction converts a specified JavaScript value, v, to a function. JS_ValueToConstructor is the exactly same function as JS_ValueToFunction. ...
... v JS::HandleValue The value to convert. Description JS_ValueToFunction converts a specified JavaScript value, v, to a function. JS_ValueToConstructor is the exactly same function as JS_ValueToFunction. ...
... v JS::HandleValue The value to convert. Description JS_ValueToFunction converts a specified JavaScript value, v, to a function. JS_ValueToConstructor is the exactly same function as JS_ValueToFunction. ...
JS_ValueToString
v jsval The value to convert. ...
... v jsval The value to convert. ...
... v jsval The value to convert. Description JS_ValueToString converts a specified JavaScript value, v, to a string. It implements the ToString operator specified in ECMA 262-3 ?9.8. ...
JSAPI reference
ease with the old scheme, where the JSAPI has the version 1.8.5. ...
...ded in SpiderMonkey 31 JS_ShutDown struct JSRuntime JS_NewRuntimeObsolete since JSAPI 52 JS_DestroyRuntime JS_GetRuntimePrivate JS_SetRuntimePrivate JS_SetNativeStackQuota Added in SpiderMonkey 17 JS_ContextIteratorObsolete since JSAPI 52 JS_Finish Obsolete since JSAPI 19 struct
JSContext JS_NewContext JS_DestroyContext JS_DestroyContextNoGC JS_SetContextCallback enum
JSContextOp JS_GetRuntime JS_GetParentRuntime Added in SpiderMonkey 31 JS_GetObjectRuntime Added in SpiderMonkey 17 JS_GetContextPrivate JS_SetContextPrivate JS_GetSecondContextPrivate Added in SpiderMonkey 17 JS_SetSecondContextPrivate Added in SpiderMonkey 17 JS_SetInterruptCallback Added in SpiderMonkey 31 JS_GetInterruptCallback Added in SpiderMonkey 31 JS_RequestInterruptCallba...
...allback types: JS::LargeAllocationFailureCallback - used by JS::SetLargeAllocationFailureCallback Added in SpiderMonkey 31 JS::OffThreadCompileCallback - used by JS::CompileOffThread Added in SpiderMonkey 26 JS::SetOutOfMemoryCallback - used by JS::OutOfMemoryCallback Added in SpiderMonkey 31 JSCompartmentNameCallback - used by JS_SetCompartmentNameCallback Added in SpiderMonkey 17
JSContextCallback - used by JS_SetContextCallback JSDestroyCompartmentCallback - used by JS_SetDestroyCompartmentCallback Added in SpiderMonkey 17 JSEnumerateDiagnosticMemoryCallback - used by JS_EnumerateDiagnosticMemoryRegions Added in SpiderMonkey 17 JSErrorCallback - used by JS_ReportErrorNumber and friends JSErrorReporter - used by JS_SetErrorReporter JSGCCallback - used by JS_SetGCCa...
NPN_SetValue - Archive of obsolete content
Returns If successful, the function should return NPERR_NO_ERROR. If unsuccessful, the function should return the most relev...
...ansparentBool (Windows and Unix) specifies that a plugin is either opaque or transparent. To specify an opaque mode, the plugin calls NPN_SetValue with NPPVpluginTransparentBool for the variable parameter and FALSE for the value parameter. To specify a transparent mode, the value parameter should be set to TRUE. NPPVjavascriptPushCallerBool sets whether you are pushing or popping the appropriate
JSContext off the stack (see the two-way scriptability article on the Mozilla Plugins project page for more details). NPPVpluginKeepLibraryInMemory specifies that the plugin does not want to be unloaded from memory after the page which initiated it has gone. Normally, when the browser navigates away from the page containing the plugin, all plugin instances get an NPP_Destroy call, and if there are no more...
Exact Stack Rooting
o solve this, we use the standard "handle" approach. A js::HandleT is a pointer to a js::RootedT. A js::RootedT will automatically convert to a js::HandleT. By using js::HandleT in the interface instead of direct GCPointers, we ensure that the GCThing is already rooted on some previous stack frame, freeing us from having to worry about rooting the GCThing for the duration of the call. bool Hello(
JSContext *cx, HandleObject foo) { return Hello(cx, foo); } ..... void OtherFunction(
JSContext *cx) { ... RootedObject obj(cx, ...); Hello(cx, obj); ... } A secondary benefit: since all JS functions take js::HandleTs, code that does not root CStack GCPointers correctly will be much less likely to compile. Warning: js::HandleT does not root objects itself! That is the job of js::Roo...
...s js::HandleT and js::RootedT behave the same, allowing us to seamlessly weave js::HandleTs into the JS API. The problem is that this requires us to overload operator->. If we have a method taking Handle<Value>*, then out->setObject(foo) will not work as expected. To solve these problems we have the js::MutableHandleT class. js::MutableHandleT is a js::HandleT with a set method. bool ReturnFoo(
JSContext *cx, MutableHandleString out) { out.set(JS_NewStringCopyZ(cx, "Foo")); return bool(out); } size_t GetLengthFoo(
JSContext *cx) { RootedString s(cx); if (ReturnFoo(cx, &s)) return JS_GetStringLength(s); return size_t(-1); } All methods in the JS-API that return GCPointers have been changed to this out-param style. This prevents an entire class of bugs where return val...
Invariants
trace stays within a single compartment (indeed, a single global object) end-to-end. Lifetime invariants In some places, pointers to JSObjects and JSStrings must refer to live heap objects, but this is not a hard fast rule, especially for strings. Some JSStrings are allocated on the stack for quick operations. Some commonly used strings are allocated statically; see JSString::isStatic(). Most
JSContext pointers must point to live contexts, but JSTitle::ownercx may point to one that has been destroyed! So code must check js_ValidContextPointer(ownercx) before dereferencing it. Shape invariants The shape guarantees hold whenever the property cache is enabled. Also, we never change the shape of the global object on trace. (Here "the global object" refers to the object at the end of the scope c...
...extPointer(ownercx) before dereferencing it. Shape invariants The shape guarantees hold whenever the property cache is enabled. Also, we never change the shape of the global object on trace. (Here "the global object" refers to the object at the end of the scope chain of the Function object we're executing.) Requests Many functions require a request. That is, they take a parameter cx of type
JSContext *, and require that cx is in a request on the current thread. See JS_THREADSAFE. "Are we in a request on cx?", where cx is any variable of type
JSContext *, is a static yes for most lines of code where such a variable exists. Occasionally it's a static no; other times we don't care. Almost all JSAPI callbacks provide a request; that is, when we call a callback with a cx argument, we know stat...
SpiderMonkey Internals: Thread Safety
m typically has only one JSRuntime, even if it has many threads. Each runtime has one or more JSCompartments. The JSCompartment is the universe in which JS objects live. They can't travel to other JSCompartments. Crucially, any given compartment may only be accessed by one thread at a time. This means that objects cannot be shared across compartments. All JS code and most JSAPI calls run within a
JSContext. The
JSContext can be thought of as a machine that knows how to run JavaScript code, or as an abstraction of the notion of a thread. Exception handling, for example, is per-
JSContext. Each
JSContext must be used by only one thread at a time. A single
JSContext can run work with code and objects in multiple compartments as long as no other thread is accessing those compartments. Objects may be sha...
...There's no fixed association between an object and a context. Thread-safety in SpiderMonkey is turned on by compiling with -DJS_THREADSAFE. ...
SpiderMonkey Internals
tand in the way. So optimizations such as dense arrays and the property cache are, alas, not transparently tucked away in the jsarray.* and jsobj.* files. Both guest-star in jsinterp.cpp (to thunderous applause from Firefox users). All state associated with an interpreter instance is passed through formal parameters to the interpreter entry point; most implicit state is collected in a type named
JSContext. Therefore, almost all functions in SpiderMonkey, API or not, take a
JSContext pointer as their first argument. Compiler The compiler consumes JavaScript source code and produces a script which contains bytecode, source annotations, and a pool of string, number, and identifier literals. The script also contains objects, including any functions defined in the source code, each of which has its o...
... (JSAtomMap) methods. jsarena.cpp, jsarena.h Last-In-First-Out allocation macros that amortize malloc costs and allow for en-masse freeing. See the paper mentioned in jsarena.h's major comment. jsgc.cpp, jsgc.h The garbage collector and tracing routines. jsinterp.*, jscntxt.*, jsinvoke.cpp The bytecode interpreter, and related functions such as Call and AllocStack, live in jsinterp.cpp. The
JSContext constructor and destructor are factored out into jscntxt.cpp for minimal linking when the compiler part of JS is split from the interpreter part into a separate program. jsinvoke.cpp is a build hack used on some platforms to build js_Interpret under different compiler options from the rest of jsinterp.cpp. jsemit.*, jsopcode.tbl, jsopcode.*, jsparse.*, jsscan.*, jsscript.* Compiler and decompi...
JS::AutoIdArray
ida JSIdArray * A pointer to JSIdArray to take the ownership. Methods Method Description bool operator!() const Return true if this has no owned array. jsid operator[](size_t i) const Return a jsid in specified index of the owned array. ...
... ida JSIdArray * A pointer to JSIdArray to take the ownership. Methods Method Description bool operator!() const Return true if this has no owned array. jsid operator[](size_t i) const Return a jsid in specified index of the owned array. ...
JS::AutoValueArray
This article covers features introduced in SpiderMonkey 31 Root an internal fixed-size array of JS::Values. Syntax JS::AutoValueArray<N> vp(cx); Name Type Description cx
JSContext * The context in which to add the root. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. N size_t Size of a JS::Value array. Description JS::AutoValueArray<N> holds a rooted array of JS::Value. This is typically used for local variables being passed to function which requires JS::HandleValueArray or a pointer to JS::Value array. Examples Pass to function as a pointer to JS::Value. bool someFunction1(
JSContext *cx, unsigned argc, const JS::Value *argv) { /* ... */ } JS::AutoValueArray<2> args(cx); /* ... I...
...*/ } JS::AutoValueArray<2> args(cx); /* ... ...
JS::CompileOffThread
This article covers features introduced in SpiderMonkey 31 Compile a script off thread for execution. Syntax bool JS::CanCompileOffThread(
JSContext *cx, const JS::ReadOnlyCompileOptions &options, size_t length); bool JS::CompileOffThread(
JSContext *cx, const JS::ReadOnlyCompileOptions &options, const char16_t *chars, size_t length, JS::OffThreadCompileCallback callback, void *callbackData); JSScript * JS::FinishOffThreadScript(
JSContext *maybecx, JSRuntime *rt, void *token); typedef void (*JS::OffThreadCompileCallback)(void *token, void *callbackData); Name Type Description cx / maybe
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_...
... rt JSRuntime * Pointer to a JS runtime. options JS::ReadOnlyCompileOptions & Compile options. chars const char16_t * String containing the script to compile. length size_t The length of chars or bytes, in characters. ...
JS::CreateError
This article covers features introduced in SpiderMonkey 38 Create an Error object. Syntax // Added in SpiderMonkey 45 bool JS::CreateError(
JSContext *cx, JSExnType type, HandleObject stack, HandleString fileName, uint32_t lineNumber, uint32_t columnNumber, JSErrorReport *report, HandleString message, MutableHandleValue rval); // Obsolete since JSAPI 39 bool JS::CreateError(
JSContext *cx, JSExnType type, HandleString stack, HandleString fileName, uint32_t lineNumber, uint32_t columnNumber, JSErrorReport *report, HandleString message, MutableHandleValue rval); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THRE...
... type JSExnType The exception's type. stack JS::HandleString or JS::HandleObject The value of Error.prototype.stack. ...
JS::GetFirstArgumentAsTypeHint
fs CallArgs The arguments of the function call. behavior JSType * Receives the result of conversion. See below. Description JS::GetFirstArgumentAsTypeHint converts first argument of @@toPrimitive method to JSType. ...
... fs CallArgs The arguments of the function call. behavior JSType * Receives the result of conversion. See below. Description JS::GetFirstArgumentAsTypeHint converts first argument of @@toPrimitive method to JSType. ...
JS::NewFunctionFromSpec
fs const JSFunctionSpec * A pointer to function specification. behavior HandleId The result of a successful call to PropertySpecNameToPermanentId(cx, fs->name, &id). Description JS::NewFunctionFromSpec creates a new function based on the given JSFunctionSpec, *fs. ...
... fs const JSFunctionSpec * A pointer to function specification. behavior HandleId The result of a successful call to PropertySpecNameToPermanentId(cx, fs->name, &id). Description JS::NewFunctionFromSpec creates a new function based on the given JSFunctionSpec, *fs. ...
JS::Rooted
rt JSRuntime * The runtime in which to add the root. ...
... rt JSRuntime * The runtime in which to add the root. initial T An initial value for the rooted variable. ...
JSAutoByteString
This article covers features introduced in SpiderMonkey 17 Take ownership of a string and free it later. Syntax JSAutoByteString str; JSAutoByteString(
JSContext *cx, JSString *str); Name Type Description cx
JSContext * The context in which to add the root. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. str JSString * A pointer to JSString to get initial content by calling JS_EncodeString(cx, str). Methods Method Description void initBytes(char *bytes) Take ownership of the given byte array. char *encodeLatin1(
JSContext *cx, JSString *str) Call JS_EncodeString and take ownership of the returned string, and return the string. char *encodeLati...
... *cx, JSString *str) Call JS_EncodeString and take ownership of the returned string, and return the string. char *encodeLatin1(js::ExclusiveContext *cx, JSString *str) Call JS::LossyTwoByteCharsToNewLatin1CharsZ, or allocate string and copy the content of JSLinearString::latin1Chars, and take the ownership of the string. This may fail if str is not linear. char *encodeUtf8(
JSContext *cx, JS::HandleString str) Call JS_EncodeStringToUTF8 and take ownership of the returned string, and return the string. void clear() Free the owned string. You should call this before calling encode* methods or initBytes method if a string is already owned, otherwise the string will never be freed. char *ptr() const Return a pointer to the owned string. This could be NU...
JSAutoCompartment
This article covers features introduced in SpiderMonkey 24 RAII helper to enter a different compartment on the given context and automatically leave it once the JSAutoCompartment instance gets out of scope. Syntax JSAutoCompartment(
JSContext *cx, JSObject *target); JSAutoCompartment(
JSContext *cx, JSScript *target); Name Type Description cx
JSContext * The context on which a cross-compartment call is needed. target JSObject * / JSScript * The object in a different compartment to be accessed. This implicitly identifies the compartment to be entered. Description Every
JSContext has a current compartment. Only objects in the current compartment can be accessed, so to access an object in a different compartment, this co...
...tion Every
JSContext has a current compartment. Only objects in the current compartment can be accessed, so to access an object in a different compartment, this containing compartment has to be entered first. Compartments have to be entered and left in LIFO order. ...
JSClass
r method can access the private data using JS_GetInstancePrivate. When initializing the class, pass the JSNative constructor function to JS_InitClass. (This example uses the C++ new and delete keywords, but the application can allocate the memory for private data however it likes. ...
...LL, NULL, NULL, NULL, NULL, NULL, NULL, printer_finalize }; /* SpiderMonkey 31 or older * static JSClass printer_class = { * "Printer", * JSCLASS_HAS_PRIVATE, * JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, * JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, printer_finalize, * JSCLASS_NO_OPTIONAL_MEMBERS * }; */ bool printer_construct(
JSContext *cx, unsigned argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JSObject *obj = JS_NewObjectForConstructor(cx, &printer_class, args); /* SpiderMonkey 31 or older * JSObject *obj = JS_NewObjectForConstructor(cx, &printer_class, vp); */ if (!obj) return false; MyPrinter *p = new MyPrinter; if (p == NULL) { JS_ReportOutOfMemory(cx...
JSDeletePropertyOp
Provides request. In JS_THREADSAFE builds, the JavaScript engine calls this callback only from within an active request on cx. The callback does not need to call JS_BeginRequest()). obj JS::HandleObject The object whose properties are being deleted. ...
...Provides request. In JS_THREADSAFE builds, the JavaScript engine calls this callback only from within an active request on cx. The callback does not need to call JS_BeginRequest()). obj JS::HandleObject The object whose properties are being deleted. ...
JSPrincipals
Define security information for an object or script. Properties Name Type Description refcount mozilla::Atomic<int32_t> Reference count. Use JS_HoldPrincipals and JS_DropPrincipals. codebase char * Pointer to the codebase for the principal. ...
...lla::Atomic<int32_t> Reference count. Use JS_HoldPrincipals and JS_DropPrincipals. codebase char * Pointer to the codebase for the principal. Obsolete since JSAPI 13 getPrincipalArray void * (*)(
JSContext *, JSPrincipals *) Pointer to the function that returns an array of principal definitions. Obsolete since JSAPI 12 globalPrivilegesEnabled JSBool (*)(
JSContext *, JSPrincipals *) Flag indicating whether principals are enabled globally. Obsolete since JSAPI 12 destroy void (*)(
JSContext *, JSPrincipals *) Pointer to the function that decrements the reference count and possibly frees the principals if they are no longer in use. Obsolete since JSAPI 13 Methods Name Description void dump() This is not define...
JSReserveSlotsOp
obj JSObject * The new object. ...
... obj JSObject * The new object. ...
JSRuntime
In the JSAPI, JSRuntime is the top-level object that represents an instance of the JavaScript engine. A program typically has only one JSRuntime, even if it has many threads. The JSRuntime is the universe in which JavaScript objects live; they can't travel to other JSRuntimes. All JavaScript code and most JSAPI calls run within a
JSContext. The
JSContext is a child of the JSRuntime. A context can run scripts. It contains the global object and the execution stack. Exception handling, error reporting, and some language options are per-
JSContext. Once created, a context can be used any number of times for different scripts or JSAPI queries. For example, a browser might create a separate context for each HTML page; every script in the page could use the same context. Objects may be shared among JSCo...
...n be used any number of times for different scripts or JSAPI queries. For example, a browser might create a separate context for each HTML page; every script in the page could use the same context. Objects may be shared among
JSContexts within a JSRuntime. There's no fixed association between an object and the context in which it is created. Sample code to set up and tear down a JSRuntime and a
JSContext is at JSAPI User Guide. Threads Only one thread may use a
JSContext or JSRuntime. Earlier versions allowed using JS_ClearContextThread and other functions to move a
JSContext from one thread to another. This feature has since been removed. See Also JS_NewRuntime JS_DestroyRuntime JS_NewContext JS_DestroyContext ...
JS_AddArgumentFormatter
Obsolete since JSAPI 18This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Add or remove a format string handler for JS_ConvertArguments, JS_PushArguments, JS_ConvertArgumentsVA, and JS_PushArgumentsVA. Syntax JSBool JS_AddArgumentFormatter(
JSContext *cx, const char *format, JSArgumentFormatter formatter); void JS_RemoveArgumentFormatter(
JSContext *cx, const char *format); Name Type Description cx
JSContext * The context in which to install the formatter. format const char * The format string prefix that should be handled by formatter, or whose handler should be removed. formatter JSArgumentFormatter The fu...
...egistration.) JS_AddArgumentFormatter does not copy format, it points at the string storage allocated by the caller, which is typically a string constant. If format is in dynamic storage, the caller must keep the string alive until JS_RemoveArgumentFormatter is called. JS_RemoveArgumentFormatter removes any conversion functions associated with format. Callback Syntax JSBool (*JSArgumentFormatter)(
JSContext *cx, const char *format, JSBool fromJS, jsval **vpp, va_list *app); Name Type Description cx
JSContext * The context in which the conversion is being performed. format const char * The tail of the format string whose prefix is associated with this formatting function. fromJS JSBool JS_TRUE if the conversion functi...
JS_AlreadyHasOwnProperty
This article covers features introduced in SpiderMonkey 1.8 Determine whether a property is already physically present on a JSObject. Syntax boo JS_AlreadyHasOwnProperty(
JSContext *cx, JS::HandleObject obj, const char *name, bool *foundp); boo JS_AlreadyHasOwnUCProperty(
JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen, bool *foundp); boo JS_AlreadyHasOwnPropertyById(
JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool *foundp); // Added in SpiderMonkey 1.8.1 boo JS_AlreadyHasOwnElement(
JSContext *cx, JS::HandleObject obj, uint32_t index, bool *foundp); Name Type Description cx
JSContext * Pointer to a JS context. Requires ...
... obj JSObject * The object to be searched. name or id const char * or const char16_t *or JS::HandleId (in JS_AlreadyHasOwnProperty, AlreadyHasOwnUCProperty, and JS_AlreadyHasOwnPropertyById) The name of the property to search for. ...
JS_BeginRequest
Indicates to the JS engine that the calling thread is entering a region of code that may call into the JSAPI but does not block. Syntax void JS_BeginRequest(
JSContext *cx); void JS_EndRequest(
JSContext *cx); Name Type Description cx
JSContext * The context in which the calling thread intends to call JSAPI functions. Description When your multithreaded application wants to use a
JSContext, it must use JS_BeginRequest and JS_EndRequest to bracket maximal non-blocking hunks of native code that call the JSAPI. This "request model" is necessary to interlock with the global garbage collector. In a JS_THREADSAFE build, many JSAPI functions must only be called from within a request. In this reference, the cx parameter of such functions is documented with ...
...al non-blocking hunks of native code that call the JSAPI. This "request model" is necessary to interlock with the global garbage collector. In a JS_THREADSAFE build, many JSAPI functions must only be called from within a request. In this reference, the cx parameter of such functions is documented with the phrase "Requires request", like this: Name Type Description cx
JSContext * The context to use. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. In a DEBUG build, this is enforced with assertions. Requests constrain garbage collection. If any thread is in a requests, garbage collection can happen only when that thread calls into the JSAPI. If one thread needs garbage collection, it blocks until each other thread...
JS_CheckForInterrupt
Description JS_CheckForInterrupt checks for the interrupt, and handle it if it's pending. JS_CheckForInterrupt returns false if interrupt callback returns false. ...
... Description JS_CheckForInterrupt checks for the interrupt, and handle it if it's pending. JS_CheckForInterrupt returns false if interrupt callback returns false. ...
JS_ClearRegExpStatics
obj JS::HandleObject A pointer to a global object. Description JS_ClearRegExpStatics clears the pending input string and flags of the built-in RegExp object. On successful, JS_ClearRegExpStatics returns true, otherwise returns false. ...
... obj JS::HandleObject A pointer to a global object. Description JS_ClearRegExpStatics clears the pending input string and flags of the built-in RegExp object. On successful, JS_ClearRegExpStatics returns true, otherwise returns false. ...
JS_CompileFunction
Obsolete since JSAPI 36This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Creates a JavaScript function from a text string. Syntax JSFunction * JS_CompileFunction(
JSContext *cx, JSObject *obj, const char *name, unsigned int nargs, const char **argnames, const char *body, size_t length, const char *filename, unsigned int lineno); JSFunction * JS_CompileUCFunction(
JSContext *cx, JSObject *obj, const char *name, unsigned int nargs, const char **argnames, const jschar *body, size_t length, const char *filename, unsigned int lineno); Name Type Description cx
JSContext * The context in which to compile the function. Requires req...
... obj JSObject * Object with which the function is associated. name const char * Name to assign the newly compiled function. nargs unsigned int Number of arguments to pass to the function. argnames const char ** Names to assign to the arguments passed to the function. ...
JS_CompileFunctionForPrincipals
Obsolete since JSAPI 28This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Create a security-enabled JS function from a text string. ...
...y time. Try to avoid using it. Create a security-enabled JS function from a text string. Syntax JSFunction * JS_CompileFunctionForPrincipals(
JSContext *cx, JSObject *obj, JSPrincipals *principals, const char *name, unsigned int nargs, const char **argnames, const char *body, size_t length, const char *filename, unsigned int lineno); JSFunction * JS_CompileUCFunctionForPrincipals(
JSContext *cx, JSObject *obj, JSPrincipals *principals, const char *name, unsigned int nargs, const char **argnames, const jschar *body, size_t length, const char *filename, unsigned int lineno); Name Type Description cx
JSContext * The context in which to compile the function. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JS...
JS_ConstructObject
sing JS_New. A less-preferred short-term solution might be to use this reimplementation of the method, but note that this reimplementation is not guaranteed to continue working across SpiderMonkey releases. Create a new object of the specified class, with the specified prototype and parent, then invokes a constructor function to initialize the new object. Syntax JSObject * JS_ConstructObject(
JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent); JSObject * JS_ConstructObjectWithArguments(
JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent, unsigned int argc, jsval *argv); Name Type Description cx
JSContext * The context in which to create the new object. Requires request. In a JS_THREADSAFE build, the caller must be in a request...
... clasp JSClass * Pointer to the class to use for the new object. If this is NULL, an ordinary JavaScript Object is created. proto JSObject * The object to serve as the new object's prototype, or NULL. ...
JS_ConvertArguments
Obsolete since JSAPI 38This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Converts a series of JS values, passed in an argument array, to their corresponding JS types. Syntax bool JS_ConvertArguments(
JSContext *cx, const JS::CallArgs &args, const char *format, ...); // Added in SpiderMonkey 31 bool JS_ConvertArguments(
JSContext *cx, unsigned argc, jsval *argv, const char *format, ...); // Obsolete since JSAPI 30 Name Type Description cx
JSContext * The context in which to perform any necessary conversions. cx also affects the interpretation of format, if JS_AddArgumentFormatter has been called. Requi...
... args const JS::CallArgs & Reference to the arguments to convert. Added in SpiderMonkey 31 argc unsigned The number of arguments to convert. ...
JS_DecompileScript
script JS::Handle<JSScript*> Script or function to decompile. Description JS_DecompileScript returns the source code of script. If script is a function, it calls JS_DecompileFunction. Otherwise, it returns the original source code of the script. ...
... script JS::Handle<JSScript*> Script or function to decompile. Description JS_DecompileScript returns the source code of script. If script is a function, it calls JS_DecompileFunction. Otherwise, it returns the original source code of the script. ...
JS_DeepFreezeObject
obj JS::Handle<JSObject*> An object to freeze. Description JS_DeepFreezeObject freezes obj, and all objects it refers to, recursively. ...
... obj JS::Handle<JSObject*> An object to freeze. Description JS_DeepFreezeObject freezes obj, and all objects it refers to, recursively. ...
JS_DefineFunction
Create a native function and assign it as a property to a specified JS object. Syntax JSFunction * JS_DefineFunction(
JSContext *cx, JS::Handle<JSObject*> obj, const char *name, JSNative call, unsigned nargs, unsigned attrs); JSFunction * JS_DefineUCFunction(
JSContext *cx, JS::Handle<JSObject*> obj, const char16_t *name, size_t namelen, JSNative call, unsigned nargs, unsigned attrs); JSFunction * JS_DefineFunctionById(
JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JSNative call, unsigned nargs, unsigned attrs); // Added in SpiderMonkey 17 Name Type Description cx
JSContext * The context in which to define the function. ...
... obj JS::Handle<JSObject*> Object for which to define a function as a property (method). name const char * or const char16_t * Name to assign to the function. id JS::Handle<jsid> A pointer to jsid for name to assign to the function. ...
JS_DefineProperties
obj JSObject * The object on which to define new properties. ps const JSPropertySpec * Pointer to the first element of an array containing names, ids, flags, and getProperty and setProperty method for the properties to create. The last array element must contain 0-valued members. ...
... obj JSObject * The object on which to define new properties. ps const JSPropertySpec * Pointer to the first element of an array containing names, ids, flags, and getProperty and setProperty method for the properties to create. The last array element must contain 0-valued members. ...
JS_DefinePropertyWithTinyId
Obsolete since JSAPI 30This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Create a new object property with a tiny id. Syntax JSBool JS_DefinePropertyWithTinyId(
JSContext *cx, JSObject *obj, const char *name, int8 tinyid, jsval value, JSPropertyOp getter, JSPropertyOp setter, unsigned int attrs); JSBool JS_DefineUCPropertyWithTinyId(
JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, int8 tinyid, jsval value, JSPropertyOp getter, JSPropertyOp setter, unsigned int attrs); Name Type Description cx
JSContext * The context in which to define the property. Requires request. In a JS_THREADSAFE build, the caller must be in...
... obj JSObject * Object for which to create the new property. name const char * or const jschar * Name for the property to create. namelen size_t (only in JS_DefineUCPropertyWithTinyId) The length of name in characters; or (size_t) -1 to indicate that name is null-terminated. ...
JS_EncodeCharacters
src const jschar * The pointer to 16-bit values of JSString. ...
... src const jschar * The pointer to 16-bit values of JSString. This can be obtained with JS_GetStringChars. ...
JS_Enumerate
obj JS::HandleObject The object whose properties are to be enumerated. Description JS_Enumerate gets the ids of all own properties of the specified object, obj, that have the JSPROP_ENUMERATE attribute. ...
... obj JS::HandleObject The object whose properties are to be enumerated. Description JS_Enumerate gets the ids of all own properties of the specified object, obj, that have the JSPROP_ENUMERATE attribute. ...
JS_EnumerateStandardClasses
obj JS::HandleObject An object to enumerate standard classes. Description The global object's class's enumerate op should call JS_EnumerateStandardClasses(cx, obj), to define eagerly during for...in loops any classes not yet resolved lazily. ...
... obj JS::HandleObject An object to enumerate standard classes. Description The global object's class's enumerate op should call JS_EnumerateStandardClasses(cx, obj), to define eagerly during for...in loops any classes not yet resolved lazily. ...
JS_FreezeObject
obj JS::Handle<JSObject*> An object to freeze. Description Freezes an object. This means that other code cannot delete, add or change any properties on the object. See ES5's Object.freeze method. ...
... obj JS::Handle<JSObject*> An object to freeze. Description Freezes an object. This means that other code cannot delete, add or change any properties on the object. See ES5's Object.freeze method. ...
JS_GC
Added in SpiderMonkey 52 rt JSRuntime * The runtime to for which to perform garbage collection. Obsolete since JSAPI 50 Description JS_GC performs garbage collection of JS objects, strings and other internal data structures that are no longer reachable in the specified context or runtime. ...
...ny objects, you may want to call JS_GC directly in your code, particularly when a script terminates or when the application has idle time. To perform garbage collection only if needed, call JS_MaybeGC instead. Use JS_SetGCCallback to add hooks that are called during garbage collection. See Also MXR ID Search for JS_GC JS_MaybeGC bug 737364 -- Changed to JSRuntime bug 1283855 -- Changed to
JSContext ...
JS_GetArrayLength
obj JS::Handle<JSObject*> The object to examine. lengthp uint32_t * Out parameter. On success, *lengthp receives the length of the array. Description JS_GetArrayLength gets the .length property of obj as though by calling JS_GetProperty and converts it to a 32-bit unsigned integer. ...
... obj JS::Handle<JSObject*> The object to examine. lengthp uint32_t * Out parameter. On success, *lengthp receives the length of the array. Description JS_GetArrayLength gets the .length property of obj as though by calling JS_GetProperty and converts it to a 32-bit unsigned integer. ...
JS_GetClass
The JS_GET_CLASS(cx, obj) macro abstracted away this detail. ...
... The JS_GET_CLASS(cx, obj) macro abstracted away this detail. ...
JS_GetClassObject
key JSProtoKey The key of the prototype. objp JS::MutableHandle<JSObject*> Out parameter. If successful, receive the class constructor. Description JS_GetClassObject gets the builtin class costructor for the specified prototype key. ...
... key JSProtoKey The key of the prototype. objp JS::MutableHandle<JSObject*> Out parameter. If successful, receive the class constructor. Description JS_GetClassObject gets the builtin class costructor for the specified prototype key. ...
JS_GetClassPrototype
key JSProtoKey The key of the prototype. objp JS::MutableHandle<JSObject*> Out parameter. If successful, receive the class prototype object. Description JS_GetClassPrototype gets the builtin class costructor for the specified prototype key. ...
... key JSProtoKey The key of the prototype. objp JS::MutableHandle<JSObject*> Out parameter. If successful, receive the class prototype object. Description JS_GetClassPrototype gets the builtin class costructor for the specified prototype key. ...
JS_GetErrorPrototype
Other contexts in the same runtime can have their own error reporting functions. ...
...Other contexts in the same runtime can have their own error reporting functions. ...
JS_GetGlobalForObject
obj JSObject * A non-NULL JSObject. Description JS_GetGlobalForObject returns the last non-null object on the parent chain of the input object. For function object inputs, the result is "the global object" as referred to in the ECMAScript specification. ...
... obj JSObject * A non-NULL JSObject. Description JS_GetGlobalForObject returns the last non-null object on the parent chain of the input object. For function object inputs, the result is "the global object" as referred to in the ECMAScript specification. ...
JS_GetPrototype
obj JS::HandleObject Object for which to retrieve the prototype. protop JS::MutableHandleObject Out parameter. If successful, Receives prototype object of obj. Description JS_GetPrototype retrieves the prototype of a specified object, obj. A prototype object provides properties inherited by similar JS objects. ...
... obj JS::HandleObject Object for which to retrieve the prototype. protop JS::MutableHandleObject Out parameter. If successful, Receives prototype object of obj. Description JS_GetPrototype retrieves the prototype of a specified object, obj. A prototype object provides properties inherited by similar JS objects. ...
JS_GetRegExpFlags
obj JS::HandleObject The object to get the flags. Description JS_GetRegExpFlags returns flags of the specified object, obj. ...
... obj JS::HandleObject The object to get the flags. Description JS_GetRegExpFlags returns flags of the specified object, obj. ...
JS_GetRegExpSource
obj JS::HandleObject The object to get the source string. Description JS_GetRegExpSource returns a source string of the specified object, obj. ...
... obj JS::HandleObject The object to get the source string. Description JS_GetRegExpSource returns a source string of the specified object, obj. ...
JS_GetRuntime
Each context is associated with a particular JSRuntime when it is created (see JS_NewContext); JS_GetRuntime provides a convenient, programmatic way to look up the association. ...
...Each context is associated with a particular JSRuntime when it is created (see JS_NewContext); JS_GetRuntime provides a convenient, programmatic way to look up the association. ...
JS_HasElement
obj JS::HandleObject The object to search for the element. index uint32_t Index of the element to look up. foundp bool * Out parameter. On success, it stores true to *foundp, false otherwise. ...
... obj JS::HandleObject The object to search for the element. index uint32_t Index of the element to look up. foundp bool * Out parameter. On success, it stores true to *foundp, false otherwise. ...
JS_IdArrayGet
ida JSIdArray * The JSIdArray to get the length. index unsigned The index of the id in the JSIdArray. ...
... ida JSIdArray * The JSIdArray to get the length. index unsigned The index of the id in the JSIdArray. ...
JS_IdArrayLength
ida JSIdArray * The JSIdArray to get the length of. ...
... ida JSIdArray * The JSIdArray to get the length of. ...
JS_IsConstructing_PossiblyWithGivenThisObject
Obsolete since JSAPI 17This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.5 Determine if a special this object was supplied to the constructor. Syntax static JSBool JS_IsConstructing_PossiblyWithGivenThisObject(
JSContext *cx, const jsval *vp, JSObject **maybeThis); Name Type Description cx
JSContext * The context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. vp const jsval * maybeThis JSObject ** Description In the case of a constructor called fr...
... maybeThis JSObject ** Description In the case of a constructor called from JS_ConstructObject and JS_InitClass where the class has the JSCLASS_CONSTRUCT_PROTOTYPE flag set, SpiderMonkey passes the constructor a non-standard this object. In such cases, the following example would provide the additional information of whether a special this was supplied. ...
JS_LeaveLocalRootScopeWithResult
Obsolete since JavaScript 1.8.5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Leave a local root scope, transferring the result value to the next enclosing root scope. Syntax void JS_LeaveLocalRootScopeWithResult(
JSContext *cx, jsval rval); Name Type Description cx
JSContext * Pointer to the context. This must be the same context that was passed to JS_EnterLocalRootScope. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. rval jsval The result value that should remain protected from garbage collection. Description See JS_EnterLocalRootScope for an explanation of local root scopes. The protect...
...This slot is rooted, but the value will eventually be overwritten by some other operation, and it is very difficult to figure out exactly when this will happen--or more to the point, guarantee that it won't happen in the time it takes some specific chunk of code to run. ...
JS_NewNumberValue
d jsdouble The numeric value to convert. rval jsval * Out parameter. On success, *rval receives a JavaScript number with the value d. Description JS_NewNumberValue converts a C floating-point number of type jsdouble to jsval, the type of JavaScript values. ...
... d jsdouble The numeric value to convert. rval jsval * Out parameter. On success, *rval receives a JavaScript number with the value d. Description JS_NewNumberValue converts a C floating-point number of type jsdouble to jsval, the type of JavaScript values. ...
JS_NewRegExpObject
Create a new RegExp object. Syntax JSObject * JS_NewRegExpObject(
JSContext *cx, JS::HandleObject obj, const char *bytes, size_t length, unsigned flags); JSObject * JS_NewUCRegExpObject(
JSContext *cx, JS::HandleObject obj, const char16_t *chars, size_t length, unsigned flags); JSObject * JS_NewRegExpObjectNoStatics(
JSContext *cx, char *bytes, size_t length, unsigned flags); JSObject * JS_NewUCRegExpObjectNoStatics(
JSContext *cx, char16_t *chars, size_t length, unsigned flags); Name Type Description cx
JSContext * The context in which to create the new object. Requires request. In a JS_THREADSAFE build, the caller must b...
... obj JS::HandleObject A pointer to a global object. bytes or chars const char * or const char16_t * A pointer to the string that contains a regular expression. length size_t The length of bytes or chars, in characters. ...
JS_ObjectIsRegExp
obj JS::HandleObject The object to examine. Description JS_ObjectIsRegExp determines if a specified object, obj, is a RegExp object. If so, JS_ObjectIsRegExp returns true. ...
... obj JS::HandleObject The object to examine. Description JS_ObjectIsRegExp determines if a specified object, obj, is a RegExp object. If so, JS_ObjectIsRegExp returns true. ...
JS_ResolveStandardClass
obj JS::HandleObject An object to resolve id to a standard class. id JS::HandleId An id of a standard class name, which must contain either a string or an int. resolved bool * Out parameter. ...
... obj JS::HandleObject An object to resolve id to a standard class. id JS::HandleId An id of a standard class name, which must contain either a string or an int. resolved bool * Out parameter. If the id is resolved, true is stored into *resolved if success. false otherwise. ...
JS_SetBranchCallback
re is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Specifies a callback function that is automatically called when a script branches backward during execution, when a function returns, and at the end of the script. Replaced with JS_SetOperationCallback. ...
...t could be removed at any time. Try to avoid using it. Specifies a callback function that is automatically called when a script branches backward during execution, when a function returns, and at the end of the script. Replaced with JS_SetOperationCallback. Syntax JSBranchCallback JS_SetBranchCallback(
JSContext *cx, JSBranchCallback cb); Name Type Description cx
JSContext * The context to hook. cb JSBranchCallback Pointer to the callback function. Callback syntax JSBool (*JSBranchCallback)(
JSContext *cx, JSScript *script); Name Type Description cx
JSContext * Pointer to a
JSContext which the callback may use to call into JSAPI functions. For example, the callback my call JS_MaybeGC(cx). This is the context ...
JS_SetErrorReporter
t); JSErrorReporter JS_SetErrorReporter(JSRuntime *rt, JSErrorReporter er); Name Type Description cx JSRuntime * Pointer to a JS runtime whose errors should be reported via your function. er JSErrorReporter The user-defined error reporting function to use in your application, described below. Callback Syntax typedef void (* JSErrorReporter)(
JSContext *cx, const char *message, JSErrorReport *report); Name Type Description cx
JSContext * The context in which the error happened. message const char * An error message. report JSErrorReport * An error report record containing additional details about the error. Description JS_SetErrorReporter enables you to define and use your ow...
.... ...
JS_SetGCZeal
The GC zeal level of the associated JSRuntime is set. zeal uint8_t The desired level of garbage collection. frequency uint32_t With some zeal levels, a GC is triggered every frequency allocations. ...
...The GC zeal level of the associated JSRuntime is set. zeal uint8_t The desired level of garbage collection. frequency uint32_t With some zeal levels, a GC is triggered every frequency allocations. ...
JS_SetPendingException
Sets the current exception being thrown within a context. Syntax void JS_SetPendingException(
JSContext *cx, JS::HandleValue v); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. v JS::HandleValue Value to throw as an exception. Description JS_SetPendingException sets the current exception being thrown within a context. If an exception is already being thrown, it is replaced with the new one given. v is the new value to throw as an exception. ...
... JS::HandleValue Value to throw as an exception. Description JS_SetPendingException sets the current exception being thrown within a context. If an exception is already being thrown, it is replaced with the new one given. v is the new value to throw as an exception. A native function or hook using this to throw an exception must also return false to ensure the exception is thrown. Each
JSContext's pending-exception field is a GC root. That is, garbage collection never collects a pending exception. See examples in the JSAPI Phrasebook. See Also MXR ID Search for JS_SetPendingException JS_IsExceptionPending JS_GetPendingException JS_ClearPendingException JS_ReportPendingException ...
JS_SetPrototype
obj JS::HandleObject The object to modify. proto JS::HandleObject The object to set as the new prototype of obj. Description JS_SetPrototype sets the prototype object for a specified object. A prototype object provides properties that are shared by similar JS object instances. ...
... obj JS::HandleObject The object to modify. proto JS::HandleObject The object to set as the new prototype of obj. Description JS_SetPrototype sets the prototype object for a specified object. A prototype object provides properties that are shared by similar JS object instances. ...
JS_SetRegExpInput
obj JS::HandleObject A pointer to a global object. input JS::HandleString A pointer to the input string. multiline bool true if input is multiline. Description JS_SetRegExpInput sets the pending input string of the built-in RegExp object to the specified input string. ...
... obj JS::HandleObject A pointer to a global object. input JS::HandleString A pointer to the input string. multiline bool true if input is multiline. Description JS_SetRegExpInput sets the pending input string of the built-in RegExp object to the specified input string. ...
JS_SetScriptStackQuota
quota size_t The desired stack quota setting, in bytes. Description Set the quota on the number of bytes that stack-like data structures can use when the runtime compiles and executes scripts. These structures also consume heap space, so JS_SetThreadStackLimit does not bound their size. The default quota is 32MB which is quite generous. ...
...ota on the number of bytes that stack-like data structures can use when the runtime compiles and executes scripts. These structures also consume heap space, so JS_SetThreadStackLimit does not bound their size. The default quota is 32MB which is quite generous. The function must be called before any script compilation or execution API calls, i.e. either immediately after JS_NewContext or from the
JSCONTEXT_NEW context callback. See Also MXR ID Search for JS_SetScriptStackQuota bug 644241 ...
JS_SetThreadStackLimit
Obsolete since JSAPI 13This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Enable or disable checks to avoid overflowing the C stack. This is deprecated, Use JS_SetNativeStackQuota instead. Syntax void JS_SetThreadStackLimit(
JSContext *cx, jsuword limitAddr) Name Type Description cx
JSContext * The context to configure. limitAddr jsuword An address near the top of the C stack. This should be a safely writeable address well short of the actual top of the stack. Description JS_SetThreadStackLimit sets the maximum (if stack grows upward) or minimum (downward) legal stack byte address in limitAddr for the thread or process stack used b...
...ess near the top of the C stack. This should be a safely writeable address well short of the actual top of the stack. Description JS_SetThreadStackLimit sets the maximum (if stack grows upward) or minimum (downward) legal stack byte address in limitAddr for the thread or process stack used by cx. To disable stack size checking, pass 0 for limitAddr. In a JS_THREADSAFE build, after passing a
JSContext from one thread to another, call JS_SetThreadStackLimit(cx, 0) after calling JS_SetContextThread. (See also JS_SetContextThread and JS_ClearContextThread.) See Also MXR ID Search for JS_SetThreadStackLimit JS_SetNativeStackQuota bug 723021 ...
JS_TypeOfValue
v JS::Handle<JS::Value> The value to examine. Description JS_TypeOfValue examines a specified JS value, v, and returns its JS data type. The return value is always one of JSTYPE_VOID, JSTYPE_OBJECT, JSTYPE_FUNCTION, JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_BOOLEAN. ...
... v JS::Handle<JS::Value> The value to examine. Description JS_TypeOfValue examines a specified JS value, v, and returns its JS data type. The return value is always one of JSTYPE_VOID, JSTYPE_OBJECT, JSTYPE_FUNCTION, JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_BOOLEAN. ...
JS_ValueToObject
v JS::HandleValue The value to convert. objp JS::MutableHandleObject Out parameter. On success, *objp receives NULL or a pointer to the resulting object. Description JS_ValueToObject converts a specified JavaScript value, v, to an object. ...
... v JS::HandleValue The value to convert. objp JS::MutableHandleObject Out parameter. On success, *objp receives NULL or a pointer to the resulting object. Description JS_ValueToObject converts a specified JavaScript value, v, to an object. ...
JS_ValueToSource
v JS::Handle<JS::Value> The value to convert. Description JS_ValueToSource converts a specified JavaScript value, v, to a JavaScript source. On success, JS_ValueToSource returns a pointer to a string. On error or exception, it returns NULL. ...
... v JS::Handle<JS::Value> The value to convert. Description JS_ValueToSource converts a specified JavaScript value, v, to a JavaScript source. On success, JS_ValueToSource returns a pointer to a string. On error or exception, it returns NULL. ...
JS_malloc
If allocation fails, an error is reported in this context. p void * (JS_realloc and JS_free only) Pointer to a previously allocated region of memory to resize or deallocate. nbytes size_t (JS_malloc and JS_realloc only) Amount of space, in bytes, to allocate. ...
...If allocation fails, an error is reported in this context. p void * (JS_realloc and JS_free only) Pointer to a previously allocated region of memory to resize or deallocate. nbytes size_t (JS_malloc and JS_realloc only) Amount of space, in bytes, to allocate. ...
Using RAII classes in Mozilla
that will cause a class to assert when it is instantiated at a temporary. They cause no extra complexity for users of the class, but they do slightly complicate the implementation of the class. These macros are provided in GuardObjects.h. In the common case, using these macros involves these three additions to a class: class MOZ_RAII nsAutoScriptBlocker { public: explicit nsAutoScriptBlocker(
JSContext *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) { // Note: No ',' before macro MOZ_GUARD_OBJECT_NOTIFIER_INIT; nsContentUtils::AddScriptBlocker(cx); } ~nsAutoScriptBlocker() { nsContentUtils::RemoveScriptBlocker(); } private: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; MOZ_GUARD_OBJECT_NOTIFIER_PARAM is added to the end of the constructor's parameter list. MOZ_GUARD_OBJECT_NOTIFIER_INIT is ...
...r(); } ~nsAutoScriptBlocker() { nsContentUtils::RemoveScriptBlocker(); } private: MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER }; Second, if the constructor is not inline, it needs the parameter added in its implementation as well. ...
nsIDispatchSupport
c/xpconnect/idl/nsIDispatchSupport.idlNot scriptable Please add a summary to this article. Inherits from: nsISupports Last changed in Gecko 1.7 Method overview void COMVariant2JSVal(in COMVARIANTPtr comvar, out jsval val); unsigned long getHostingFlags(in string aContext); boolean isClassMarkedSafeForScripting(in nsCIDRef cid, out boolean classExists); boolean isClassSafeToHost(in
JSContextPtr cx, in nsCIDRef cid, in boolean capsCheck, out boolean classExists); boolean isObjectSafeForScripting(in voidPtr theObject, in nsIIDRef id); void JSVal2COMVariant(in jsval var, out COMVARIANT comvar); Methods COMVariant2JSVal() Converts a COM Variant to a jsval. void COMVariant2JSVal( in COMVARIANTPtr comvar, out jsval val ); Parameters comvar The COM Variant to be converted. val ...
...afeForScripting() Test if the specified class is marked safe for scripting. boolean isClassMarkedSafeForScripting( in nsCIDRef cid, out boolean classExists ); Parameters cid The nsID representation of the CLSID to test. classExists Returns containing PR_FALSE if the class is not registered. Return value isClassSafeToHost() Test if the class is safe to host. boolean isClassSafeToHost( in
JSContextPtr cx, in nsCIDRef cid, in boolean capsCheck, out boolean classExists ); Parameters cx cid capsCheck classExists Returns containing PR_FALSE if the class is not registered. Return value isObjectSafeForScripting() Test if the instantiated object is safe for scripting on the specified interface. boolean isObjectSafeForScripting( in voidPtr theObject, in nsIIDRef id ); Parameters ...
nsIPrincipal
apability(in string capability); Native code only! void checkMayLoad(in nsIURI uri, in boolean report); void disableCapability(in string capability, inout voidPtr annotation); Native code only! void enableCapability(in string capability, inout voidPtr annotation); Native code only! boolean equals(in nsIPrincipal other); JSPrincipals getJSPrincipals(in
JSContext cx); Native code only! void getPreferences(out string prefBranch, out string id, out string subjectName, out string grantedList, out string deniedList, out boolean isTrusted); boolean isCapabilityEnabled(in string capability, in voidPtr annotation); Native code only! void revertCapability(in string capability, inout voidPtr annotation); Native code only! void s...
...if they are the same principal, they have the same origin, or have the same certificate fingerprint ID. boolean equals( in nsIPrincipal other ); Parameters other The other principal to compare against. Return value true if the two principals are equivalent; otherwise false. Native code only!getJSPrincipals Returns the JS equivalent of the principal. JSPrincipals getJSPrincipals( in
JSContext cx ); Parameters cx Missing Description Return value Missing Description getPreferences() Returns the security preferences associated with this principal. void getPreferences( out string prefBranch, out string id, out string subjectName, out string grantedList, out string deniedList, out boolean isTrusted ); Parameters prefBranch On return, contains the preferen...
nsISmsService
Introduced Gecko 13.0 Inherits from: nsISupports Last changed in Gecko 15.0 (Firefox 15.0 / Thunderbird 15.0 / SeaMonkey 2.12) Implemented by: @mozilla.org/sms/smsservice;1. ...
... delivery A DOMString which can either be "received" or "sent" and is representing the way the SMS was delivered. sender A DOMString with the na...
nsIXPCException
tions when implementing xpcom interfaces in JavaScript. Inherits from: nsIException Last changed in Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0) Method overview void initialize(in string aMessage, in nsresult aResult, in string aName, in nsIStackFrame aLocation, in nsISupports aData, in nsIException aInner); xpcexJSVal stealJSVal(); Native code only! void stowJSVal(in xpcex
JSContextPtr cx, in xpcexJSVal val); Native code only! Methods initialize() void initialize( in string aMessage, in nsresult aResult, in string aName, in nsIStackFrame aLocation, in nsISupports aData, in nsIException aInner ); Parameters aMessage aResult aName aLocation aData aInner Native code only!stealJSVal xpcexJSVal stealJSVal(); Parameters None. Return value Native code on...
...only! Methods initialize() void initialize( in string aMessage, in nsresult aResult, in string aName, in nsIStackFrame aLocation, in nsISupports aData, in nsIException aInner ); Parameters aMessage aResult aName aLocation aData aInner Native code only!stealJSVal xpcexJSVal stealJSVal(); Parameters None. Return value Native code only!stowJSVal void stowJSVal( in xpcex
JSContextPtr cx, in xpcexJSVal val ); Parameters cx val Remarks Components.Exception is a JavaScript constructor to create nsIXPCException objects. The call signature of the constructor is: Components.Exception(message, result, stack, data, inner) all parameters are optional and the appropriate placeholder is 'unknown'. message - A custom message set by the thrower (defaults to 'exception') result...
Adding a new event
in the constructor of the most descendant class because each constructor creates dummy internal event instance at calling constructors of its super class. Therefore, super classes always set it false. Don't override methods of its super classes as far as possible since overriding the method may cause harder to maintain. When you need to check if the caller content or chrome, you can use implicit
JSContext attribute in dom/bindings/Bindings.conf. Then, the method can have a pointer of
JSContext in its argument. Create DOM event factory method If your DOM event implementation is generatable, you can skip this section. In nsIDOMEvent.idl, you need to define NS_NewDOMFooEvent(). It's last argument should be the most subclass. Then, the implementation of the DOM event can access internal event cl...
JS::PerfMeasurement
you can declare a bare jsval argument in your .idl file and have JavaScript pass a PerfMeasurement object that it created in that argument slot. The jsval you receive points to a JavaScript wrapper object. To extract the C++-level PerfMeasurement object, call this function. It will return NULL if JavaScript passed in something with the wrong dynamic type. JSObject* JS::RegisterPerfMeasurement(
JSContext* cx, JSObject* global) You shouldn't need to use this function, but we mention it for completeness. It initializes the JavaScript wrapper interface for this API and pokes the constructor function into the global object you provide. ...
Functions
ull closures with upvars. A nested function is algol-like if it is only ever defined and called, and it isn't accessed in any other way (and it is not a generator-function). Such a function is guaranteed never to be called again after the enclosing function exits. An algol-like function may read the local variables and arguments of its immediate enclosing function from the stack, as if by magic. (
JSContext::display caches the enclosing function's stack frame.) If that function is also algol-like, its child can read locals and variables from the next enclosing function, and so on. The compiler detects these cases and makes such functions null closures too. Flat closures. Suppose a function reads some variables from enclosing functions but is not algol-like. If the function does not assign to any clo...
Tracing JIT
d and fixed when the build is configured. The architecture-specific methods found in these files are the only functions within nanojit or TraceMonkey that emit raw bytes of machine-code into memory. SpiderMonkey-specific high level component: jstracer.* The files jstracer.cpp and jstracer.h contain a the mechanisms of monitoring and recording the activity of the interpreter. Each SpiderMonkey
JSContext holds a trace monitor of type JSTraceMonitor. The trace monitor maintains some book-keeping information, as well as the collection of recorded Fragments, held in a hashtable keyed by the interpreter's program counter and global object shape at the time of recording. At any moment, the trace monitor is in one of three major states: monitoring, recording, or executing. The transitions between the...
JS::AutoVectorRooter
bool empty() const Determines if the array is empty (length is zero). bool append(const T &v) Appends an element v to the array. bool append(const T *ptr, size_t len) Appends a sequence of T specified with a pointer ptr and length len to the array. ...
JS::Handle
} Methods Here, ptr represents the private member of JS::Handle<T>, typed with T. Method Description const T *address() const Returns a pointer to ptr. const T &get() const Returns ptr. ...
JS::MutableHandle
} Methods Here, ptr represents the private member of JS::MutableHandle<T>, typed with T *. Method Description const T &get() const Returns *ptr. operator const T&() const T operator->() const T *address() Returns ptr. void set(T v) Sets the value of *ptr to v. ...
JS::SetOutOfMemoryCallback
k cb, void *data); Name Type Description rt JSRuntime * The JSRuntime for which to set the GC callback. cb JS::OutOfMemoryCallback Pointer to the new callback function to use. data void * data parameter which will be passed to JS::OutOfMemoryCallback. Added in SpiderMonkey 38 Callback syntax typedef void (* OutOfMemoryCallback)(
JSContext *cx, void *data); Name Type Description data void * data parameter passed to JS::SetOutOfMemoryCallback. Added in SpiderMonkey 38 Description Unlike the error reporter, which is only called if the exception for an OOM bubbles up and is not caught, the JS::OutOfMemoryCallback is called immediately at the OOM site to allow the embedding to capture the current...
JSCheckAccessOp
Obsolete since JSAPI 29This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. JSCheckAccessOp is the type for JSClass.checkAccess. (It is also the type of the callback set by JS_SetCheckObjectAccessCallback.) Syntax typedef JSBool (* JSCheckAccessOp)(
JSContext *cx, JSObject *obj, jsval id, JSAccessMode mode, jsval *vp); Name Type Description cx
JSContext * The JS context in which the property access attempt is occurring. obj JSObject * The object whose properties are being accessed. id jsval The name or index of the property being accessed. mode JSAccessMode The type of access being checked. ...
JSConvertOp
obj JS::HandleObject The object to be converted. hint JSType The hint to pass to the [[DefaultValue]] hook when converting the object. hint will be JSTYPE_STRING or JSTYPE_NUMBER to pass the corresponding type as a hint, or JSTYPE_VOID to pass no hint. Other types may be passed as hints, but such behavior is deprecated. vp JS::MutableHandleValue Out parameter. ...
JSEnumerateOp
obj JS::HandleObject Pointer to the object to be enumerated. Description JSEnumerateOp is called just before an object is enumerated (via a for...in statement, an array comprehension, or a call to JS_Enumerate). It should define any remaining lazy properties that should be enumerable but are not yet defined in obj. ...
JSExtendedClass.outerObject
Obsolete since JavaScript 1.8.5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. JSExtendedClass.outerObject and .innerObject are callbacks for split objects. Callback syntax typedef JSObject * (*JSObjectOp)(
JSContext *cx, JSObject *obj); Name Type Description cx
JSContext * A context. obj JSObject * The object being queried. Description See split objects. ...
JSExtendedClass.wrappedObject
Obsolete since JavaScript 1.8.5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8 Callback for objects that wrap other objects. Syntax typedef JSObject * (*JSObjectOp)(
JSContext *cx, JSObject *obj); Name Type Description cx
JSContext * The context in which the object is being unwrapped. obj JSObject * The object to unwrap. Description If a class has the JSCLASS_IS_EXTENDED bit set in its JSClass.flags and has a non-null JSExtendedClass.wrappedObject, then objects of that class may be wrappers. In a few cases the JavaScript engine will pretend the wrapper isn't there, ...
JSFastNative
tNative is the type of fast native functions in the JSAPI. APIs such as JS_InitClass and JS_DefineFunctions can create custom methods that are implemented as C/C++ functions of this type, instead of JSNative. The term "native" here refers to C/C++ code as opposed to JavaScript code. Added in SpiderMonkey 1.8.1 JSFastNative has been renamed to JSNative. Syntax typedef JSBool (*JSFastNative)(
JSContext *cx, unsigned int argc, jsval *vp); Name Type Description cx
JSContext * The context in which the fast native is being called. Provides request. In JS_THREADSAFE builds, the JavaScript engine calls this callback only from within an active request on cx. The callback does not need to call JS_BeginRequest()). argc unsigned int The number of arguments ...
JSFinalizeOp
obj JSObject * The object being destroyed. Description The JSFinalizeOp is analogous to Java finalizers or C++ destructors. The garbage collector calls this callback for each object it collects. ...
JSFreeOp
This article covers features introduced in SpiderMonkey 17 Structure used during finalization instead of
JSContext. Syntax JSFreeOp(JSRuntime *rt); Name Type Description rt JSRuntime * A runtime to store in this structure. Methods Method Description JSRuntime *runtime() const Returns a pointer to JSRuntime passed to constructor. Description Various finalization API takes not
JSContext * but rather either JSFreeOp structure or its library-private counterpart FreeOp. These structures wrap parameters that are passed to the finalizers removing most of explicit dependencies on
JSContext in the finalization code. See Also MXR ID Search for JSFreeOp JS_freeop JS_GetDefaultFreeOp JSFinalizeCallback JSDestroyCompartm...
JSGetObjectOps
Obsolete since JSAPI 17This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. JSGetObjectOps is the type for JSClass.getObjectOps Callback Syntax typedef JSObjectOps * (* JSGetObjectOps)(
JSContext *cx, JSClass *clasp); Name Type Description cx
JSContext * The JS context in which the new object is being created. cls JSClass * The class of the new object. Description JSObjectOps is used by JS_NewObject's internals to discover the set of high-level object operations to use for new objects of the given class. All native objects have a JSClass, which is stored as a private (int-tagged) pointer in object slots. In contrast, all native an...
JSHasInstanceOp
obj JS::HandleObject The "type" in the type check. v JS::MutableHandleValue The value whose type is being checked. bp bool * Out parameter. On success, the callback stores the result of the type check in *bp. Description JSHasInstanceOp is called to check whether v is an instance of obj. ...
JSIteratorOp
Obsolete since JSAPI 26This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8 Callback for creating iterators. Syntax typedef JSObject * (*JSIteratorOp)(
JSContext *cx, JSObject *obj, JSBool keysonly); Name Type Description cx
JSContext * Pointer to the JS context in which the iterator creation should take place. obj JSObject * Pointer to the object to iterate over. keysonly JSBool If true, the iterator should yield keys only, not [key, value] pairs. Description The JavaScript engine calls the JSExtendedClass.iteratorObject callback to create an iterator obj...
JSMarkOp
in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. JSMarkOp is the type of the JSClass.mark callback in SpiderMonkey 1.7 and earlier. In SpiderMonkey 1.8, JSMarkOp will be deprecated. All new code using SpiderMonkey 1.8 or later should use a JSTraceOp instead to ensure that the tracing APIs work properly. Syntax typedef uint32 (* JSMarkOp)(
JSContext *cx, JSObject *obj, void *arg); Name Type Description cx
JSContext * The JS context in which the mark phase of garbage collection is occurring. obj JSObject * The object to be marked. arg void * Opaque data which the mark hook must pass through to JS_MarkGCThing. Description Call JS_MarkGCThing for each GC thing directly reacha...
JSNative
JSNative is the type of many JSAPI callbacks. In particular, APIs such as JS_InitClass and JS_DefineFunctions create custom methods on JavaScript objects that are implemented as JSNative callbacks provided by the application, written in C/C++ code. The term "native" here refers to C/C++ code as opposed to JavaScript code. Syntax typedef bool (* JSNative)(
JSContext *cx, unsigned argc, JS::Value *vp); Name Type Description cx
JSContext * The context in which the native function is being called. Provides request. In JS_THREADSAFE builds, the JavaScript engine calls this callback only from within an active request on cx. The callback does not need to call JS_BeginRequest()). argc unsigned The number of arguments supplied to the function by the calle...
JSNewEnumerateOp
The type of ObjectOps::enumerate. This callback overrides a portion of SpiderMonkey's default [[Enumerate]] internal method. Syntax typedef bool (* JSNewEnumerateOp)(
JSContext *cx, JS::HandleObject obj, JS::AutoIdVector &properties); // Added in SpiderMonkeySidebar 38 typedef bool (* JSNewEnumerateOp)(
JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op, JS::MutableHandleValue statep, JS::MutableHandleId idp); // Obsolete since JSAPI 37 Name Type Description cx
JSContext * The context in which the enumeration is taking place. obj JS::HandleObject The object to be enumerated. properties JS::AutoIdVector & Out parameter. Id array to populate with all property keys. enum_op ...
JSNewResolveOp
Obsolete since JSAPI 36This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. JSNewResolveOp is the type of the JSClass.resolve callback when the JSCLASS_NEW_RESOLVE bit is set in the JSClass.flags field. Syntax typedef bool (* JSNewResolveOp)(
JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleObject objp); Name Type Description cx
JSContext * Pointer to the JS context in which the property access is taking place. obj JS::HandleObject Pointer to the object whose properties are being accessed. id JS::HandleId Name or index of the property being accessed. flags uint32_t Obs...
JSObjectOp
Obsolete since JavaScript 1.8.5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. ...
JSObjectOps.defaultValue
ing! JSObjectOps is not a supported API. Details of the API may change from one release to the next. This documentation should be considered SpiderMonkey internals documentation, not API documentation. See bug 408416 for details. The JavaScript engine calls the JSObjectOps.defaultValue and JSClass.convert callbacks to convert objects to primitive values. Syntax typedef JSBool (*JSConvertOp)(
JSContext *cx, JSObject *obj, JSType type, jsval *vp); Name Type Description cx
JSContext * Pointer to the JS context in which the conversion is needed. obj JSObject * The object to be converted. type JSType The target type. vp jsval * Out parameter. On success, the callback must store the converted value here. Descript...
JSObjectOps.defineProperty
it. Warning! JSObjectOps is not a supported API. Details of the API may change from one release to the next. This documentation should be considered SpiderMonkey internals documentation, not API documentation. See bug 408416 for details. The JSObjectOps.defineProperty callback is called whenever an object property is defined. It implements JS_DefineProperty. Syntax JSBool (*JSDefinePropOp)(
JSContext *cx, JSObject *obj, jsid id, jsval value, JSPropertyOp getter, JSPropertyOp setter, unsigned int attrs); Name Type Description cx
JSContext * Pointer to the JS context in which the property is being defined. obj JSObject * The object on which the property is being defined. id jsid The name or index of the property to define. ...
JSObjectOps.destroyObjectMap
g it. Warning! JSObjectOps is not a supported API. Details of the API may change from one release to the next. This documentation should be considered SpiderMonkey internals documentation, not API documentation. See bug 408416 for details. The JSObjectOps.destroyObjectMap callback is called to destroy a JSObjectMap when its reference count goes to zero. Syntax typedef void (*JSObjectMapOp)(
JSContext *cx, JSObjectMap *map); Name Type Description cx
JSContext * Pointer to the JS context in which garbage collection is happening. map JSObjectMap * The map to destroy. ...
JSObjectOps.dropProperty
e it could be removed at any time. Try to avoid using it. Warning! JSObjectOps is not a supported API. Details of the API may change from one release to the next. This documentation should be considered SpiderMonkey internals documentation, not API documentation. See bug 408416 for details. The JSObjectOps.dropProperty callback releases a JSProperty. Syntax typedef void (*JSPropertyRefOp)(
JSContext *cx, JSObject *obj, JSProperty *prop); Name Type Description cx
JSContext * A context that was the cx argument to an earlier call to JSObjectOps.lookupProperty that found a property. obj JSObject * The object of which prop is an own property. That is, the value that the JSObjectOps.lookupProperty hook stored in the *objp out parameter. prop...
JSObjectOps.getAttributes
sing it. Warning! JSObjectOps is not a supported API. Details of the API may change from one release to the next. This documentation should be considered SpiderMonkey internals documentation, not API documentation. See bug 408416 for details. The JSObjectOps.getAttributes and setAttributes callbacks are called to access the attributes of a property. Syntax typedef JSBool (*JSAttributesOp)(
JSContext *cx, JSObject *obj, jsid id, JSProperty *prop, unsigned int *attrsp); Name Type Description cx
JSContext * Pointer to the JS context in which the property access is happening. obj JSObject * The object whose property attributes are being accessed. id jsid The name or index of the property whose attributes are being accessed. ...
JSObjectOps.getProperty
uding walking the prototype chain if needed; calling the lower-level JSClass hooks; calling getters or setters; and actually getting, setting, or deleting the property once it is found. Contrast JSClass.getProperty, JSClass.setProperty, and JSClass.delProperty, which are hooks called during property accesses and don't have to implement any of that. Syntax typedef JSBool (*JSPropertyIdOp)(
JSContext *cx, JSObject *obj, jsid id, jsval *vp); Name Type Description cx
JSContext * Pointer to the JS context in which the property access is happening. obj JSObject * The object to be accessed. id jsid The name or index of the property to access. vp jsval * In/out parameter. See the Description section below. Descripti...
JSObjectOps.getRequiredSlot
is not a supported API. Details of the API may change from one release to the next. This documentation should be considered SpiderMonkey internals documentation, not API documentation. See bug 408416 for details. The JSObjectOps.getRequiredSlot and setRequiredSlot callbacks get and set a required slot--one that should already have been allocated. Syntax typedef jsval (*JSGetRequiredSlotOp)(
JSContext *cx, JSObject *obj, uint32 slot); typedef JSBool (*JSSetRequiredSlotOp)(
JSContext *cx, JSObject *obj, uint32 slot, jsval v); Name Type Description cx
JSContext * The JS context in which we access the slot. obj JSObject * The object whose slot we access. slot uint32 The index of the slot to access. See note below. v ...
JSObjectOps.lookupProperty
lease to the next. This documentation should be considered SpiderMonkey internals documentation, not API documentation. See bug 408416 for details. The JSObjectOps.lookupProperty callback is called for every property access (except when a higher-level callback, such as JSObjectOps.getProperty, is overloaded in a way that does not call lookupProperty). Syntax typedef JSBool (*JSLookupPropOp)(
JSContext *cx, JSObject *obj, jsid id, JSObject **objp, JSProperty **propp); Name Type Description cx
JSContext * Pointer to the JS context in which the property lookup is happening. obj JSObject * The object whose properties are being searched. id jsid The name or index of the property to look up. objp JSObject ** Out paramet...
JSObjectOps.newObjectMap
ails of the API may change from one release to the next. This documentation should be considered SpiderMonkey internals documentation, not API documentation. See bug 408416 for details. The JSObjectOps.newObjectMap callback is called whenever a new object is created. It creates a JSObjectMap that completely controls the new object's behavior. Syntax typedef JSObjectMap * (*JSNewObjectMapOp)(
JSContext *cx, jsrefcount nrefs, JSObjectOps *ops, JSClass *clasp, JSObject *obj); Name Type Description cx
JSContext * Pointer to the JS context in which the new object is being created. nrefs jsrefcount The initial reference count for the new JSObjectMap. ops JSObjectOps * The ops for the new JSObjectMap. clasp JSClass * The...
JSObjectOps.setProto
etails of the API may change from one release to the next. This documentation should be considered SpiderMonkey internals documentation, not API documentation. See bug 408416 for details. The JSObjectOps.setProto and setParent callbacks implement the JS_SetPrototype and JS_SetParent functions. These callbacks share the same type, JSSetObjectSlotOp. Syntax typedef JSBool (*JSSetObjectSlotOp)(
JSContext *cx, JSObject *obj, uint32 slot, JSObject *pobj); Name Type Description cx
JSContext * Pointer to the JS context in which the object's prototype or parent is being modified. obj JSObject * The object whose prototype or parent is being modified. slot uint32 The index of the slot being modified: JSSLOT_PROTO for the JSObjectOps.setPr...
JSObjectPrincipalsFinder
ough it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. JSObjectPrincipalsFinder is the type of a security callback that can be configured using JS_SetObjectPrincipalsFinderJSAPI 1.8 and earlier or JS_SetRuntimeSecurityCallbacksAdded in SpiderMonkey 1.8.1. Callback syntax typedef JSPrincipals * (* JSObjectPrincipalsFinder)(
JSContext *cx, JSObject *obj); Name Type Description cx
JSContext * The context in which to find principals. obj JSObject * The object whose principals are needed. Description The JavaScript engine calls this callback to obtain principals for a JSPrincipals.subsume check. For example, when a watchpoint triggers, the engine calls the callback, passing ...
JSPRINCIPALS_HOLD
Obsolete since JSAPI 13This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Increment or decrement the reference count of a JSPrincipals object. Syntax JSPRINCIPALS_HOLD(cx, principals) JSPRINCIPALS_DROP(cx, principals) Name Type Description cx
JSContext * A context. principals JSPrincipals * Pointer to the JSPrincipals object to hold or drop. This argument must not be NULL. Description JSPRINCIPALS_HOLD and JSPRINCIPALS_DROP are used to manage memory for JSPrincipals objects. Principals are used by the SpiderMonkey security system. JSPrincipals objects are not JSObjects. They are reference counted, not garbage collected. Applicat...
JSPropertyOp
JSPropertyOp and JSStrictPropertyOp are the type of property getter and setter callbacks in the JSAPI. They are also the types of the JSClass.addProperty, getProperty, and setProperty callbacks, which are called during object property accesses. Syntax typedef bool (* JSPropertyOp)(
JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); typedef bool (* JSStrictPropertyOp)(
JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp); // Added in SpiderMonkey 1.9.3 Name Type Description cx
JSContext * The context in which the property access is taking place. Provides request. In JS_THREADSAFE builds, the JavaScript engine calls this callback only from with...
JSSecurityCallbacks.contentSecurityPolicyAllows
The JSSecurityCallbacks.contentSecurityPolicyAllows callback is called when a script attempts to access an object property. The callback can deny the script access to the property. JSCheckAccessOp is the type of the callback. (It is also the type of the callback set by JS_SetCheckObjectAccessCallback.) Syntax typedef JSBool (*JSCSPEvalChecker)(
JSContext *cx); Name Type Description cx
JSContext * The JS context in which the property access attempt is occurring. Description Check whether runtime code generation is allowed for the current global. JSSecurityCallbacks.contentSecurityPolicyAllows is invoked once per global object upon the first attempt to evaluate JS code from a string (either through eval or the Function constructo...
JS_AddExternalStringFinalizer
manager. Syntax int JS_AddExternalStringFinalizer(JSStringFinalizeOp finalizer); Name Type Description finalizer JSStringFinalizeOp Pointer to a callback function, described below. The JS engine will automatically call this function each time a string created by JS_NewExternalString is garbage-collected. Callback syntax typedef void (*JSStringFinalizeOp)(
JSContext *cx, JSString *str); Name Type Description cx
JSContext * Pointer to a
JSContext which the finalizer may use for certain very limited operations (not documented). Since the JSStringFinalizeOp callback is called during garbage collection, it must avoid most JSAPI functions. (Is cx guaranteed to be non-NULL?) str JSString * The string being finalized. ...
JS_AliasElement
Obsolete since JSAPI 8This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Create an aliased index entry for an existing numeric property of a native object. Syntax JSBool JS_AliasElement(
JSContext *cx, JSObject *obj, const char *name, jsint alias); Name Type Description cx
JSContext * The context in which to create the alias. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * The object for which to create the alias. name const char * Name of the element for which to create an alias. This name corresponds to a string representation of the element's current ind...
JS_AliasProperty
Obsolete since JSAPI 8This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Create an alias for a native property. Syntax JSBool JS_AliasProperty(
JSContext *cx, JSObject *obj, const char *name, const char *alias); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * Object for which to create the alias. name const char * Name of the property for which to create an alias. alias const char * Alias name to assign to the property. Description JS_AliasProp...
JS_CheckAccess
Obsolete since JSAPI 29This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Check whether a running script may access a given object property. Syntax JSBool JS_CheckAccess(
JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, jsval *vp, unsigned int *attrsp); Name Type Description cx
JSContext * The context in which to perform the access check. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * The object that has the property being accessed. id jsid The name or index of the property being accessed. mode JSAccessMode The type of access request...
JS_ClearNewbornRoots
Obsolete since JSAPI 5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Clear a context's newborn roots, which temporarily protect newly allocated values from garbage collection. Syntax void JS_ClearNewbornRoots(
JSContext *cx); Name Type Description cx
JSContext * The context to clear. Description The last GC thing of each type (object, string, double, external string types) created on a given context is kept alive until another thing of the same type is created, using a newborn root in the context. These newborn roots help native code protect newly-created GC-things from GC invocations activated before those things can be rooted using local or global r...
JS_ClearNonGlobalObject
Obsolete since JSAPI 34This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 24 Remove all properties associated with an object. Syntax void JS_ClearNonGlobalObject(
JSContext *cx, JSObject *obj); Name Type Description cx
JSContext * The context in which to clear the object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * Object from which to delete all properties. Description JS_ClearNonGlobalObject removes all of obj's own properties, except the special __proto__ and __parent__ properties, in a single operati...
JS_ClearPendingException
Description JS_ClearPendingException cancels the currently pending exception in cx, if any. (There is a pending exception if the most recently thrown exception in cx has not yet been caught or cleared.) When any JSAPI call fails with an exception, the caller must either use JS_ClearPendingException to catch the exception; or return false to allow the exception to propagate to the caller. ...
JS_ClearScope
Obsolete since JSAPI 18This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Remove all properties associated with an object. Syntax void JS_ClearScope(
JSContext *cx, JSObject *obj); Name Type Description cx
JSContext * The context in which to clear the object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * Object from which to delete all properties. Description JS_ClearScope removes all of obj's own properties, except the special __proto__ and __parent__ properties, in a single operation. Properties belonging to objects on obj's prototype chain are not affected. To remove a singl...
JS_CloneFunctionObject
Obsolete since JSAPI 36This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Create a new Function object from an existing JSFunction. Syntax JSObject * JS_CloneFunctionObject(
JSContext *cx, JSObject *funobj, JSObject *parent); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. funobj JSObject * The Function to clone. parent JSObject * The new function's parent. Description JS_CloneFunctionObject creates a new function object from funobj. The new object has the same code an...
JS_CompareStrings
str1 JSString * First string to compare. str2 JSString * Second string to compare. result int32_t * The out parameter. See description for value of *result. Description JS_CompareStrings compares two JS strings, str1 and str2. If the strings are identical in content and length, JS_CompareStrings stores 0 in *result. If str1 is less than str2, *result is less than 0. If str1 is greater than str2, *result is greater than 0. ...
JS_CompileFileHandleForPrincipals
This article covers features introduced in SpiderMonkey 1.8.5 Please provide a description of this function. Syntax JSObject * JS_CompileFileHandleForPrincipals(
JSContext *cx, JSObject *obj, const char *filename, FILE *fh, JSPrincipals *principals); Name Type Description cx
JSContext * The context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * filename const char fh FILE * principals JSPrincipals * Description Please provide a description. See Also JS_CompileFileHandleForPrincipalsVersion ...
JS_CompileFileHandleForPrincipalsVersion
This article covers features introduced in SpiderMonkey 1.8.5 Please provide a description for this function. Syntax JSObject * JS_CompileFileHandleForPrincipalsVersion(
JSContext *cx, JSObject *obj, const char *filename, FILE *fh, JSPrincipals *principals, JSVersion version); Name Type Description cx
JSContext * The context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * filename const char fh FILE * principals JSPrincipals * version JSVersion Description Please provide a description. See also JS_CompileFileHandleForPrincipals ...
JS_CompileUCFunctionForPrincipalsVersion
This article covers features introduced in SpiderMonkey 1.8.5 Please provide a description for this function. Syntax JSFunction * JS_CompileUCFunctionForPrincipalsVersion(
JSContext *cx, JSObject *obj, JSPrincipals *principals, const char *name, unsigned int nargs, const char **argnames, const jschar *chars, size_t length, const char *filename, unsigned int lineno, JSVersion version); Name Type Description cx
JSContext * The context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * principals JSPrincipals * name const char * nargs unsigned int argnames const char ** chars const jscha...
JS_CompileUTF8File
Obsolete since JSAPI 19This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Compile a script, reading the source code from a file. Syntax JSObject * JS_CompileUTF8File(
JSContext *cx, JSObject *obj, const char *filename); Name Type Description cx
JSContext * The context in which to compile the script. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * Object with which the script is associated. filename const char * Name of file containing the script to compile. Description JS_CompileUTF8File compiles the text of script in an external file location for execution b...
JS_CompileUTF8FileHandle
Obsolete since JSAPI 19This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Compile a script, reading the source code from a stdio FILE. Syntax JSObject * JS_CompileUTF8FileHandle(
JSContext *cx, JSObject *obj, const char *filename, FILE *file); JSObject * JS_CompileUTF8FileHandleForPrincipals(
JSContext *cx, JSObject *obj, const char *filename, FILE *file, JSPrincipals *principals); Name Type Description cx
JSContext * The context in which to compile the script. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * Object with which the script is associated. filena...
JS_ConcatStrings
left JS::HandleString First string to concatenate. right JS::HandleString Second string to concatenate. Description JS_ConcatStrings concatenates two JS strings, str1 and str2, and returns the result. The result could be the same as one of the input strings, if the other string is zero length. ...
JS_ConvertArgumentsVA
Obsolete since JSAPI 38This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Converts a series of JS values, passed in a va_list, to their corresponding JSAPI types. Syntax bool JS_ConvertArgumentsVA(
JSContext *cx, const JS::CallArgs &args, const char *format, va_list ap); bool JS_ConvertArgumentsVA(
JSContext *cx, unsigned argc, jsval *argv, const char *format, va_list ap); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. args const JS::CallArgs &am...
JS_ConvertValue
Obsolete since JSAPI 38This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Converts a JavaScript value to a value of a specific JavaScript type. Syntax bool JS_ConvertValue(
JSContext *cx, JS::HandleValue v, JSType type, JS::MutableHandleValue vp); Name Type Description cx
JSContext * The context in which to perform the conversion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. v JS::HandleValue The value to convert. type JSType The type to which the value is to be converted. type must be one of JSTYPE_VOID, JSTYPE_OBJECT, JSTYPE_FUNCTION, JSTYPE_STRING, JSTYPE_NUMBER, or J...
JS_DecompileScriptObject
This article covers features introduced in SpiderMonkey 1.8.5 FIXME: Please provide a description for this function. Syntax JSString * JS_DecompileScriptObject(
JSContext *cx, JSObject *scriptObj, const char *name, unsigned int indent); Name Type Description cx
JSContext * The context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. scriptObj JSObject * name const char * indent unsigned int Description FIXME: Please provide a description. See also FIXME: ...
JS_DefaultValue
ete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.6 Converts a JavaScript object to a primitive value, using the semantics of that object's internal [[DefaultValue]] hook. Renamed to JS::ToPrimitive from JSAPI 44. Syntax bool JS_DefaultValue(
JSContext *cx, JS::Handle<JSObject*> obj, JSType hint, JS::MutableHandle<JS::Value> vp); Name Type Description cx
JSContext * The context in which to perform the conversion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::Handle<JSObject*> The object to convert. hint JSTyp...
JS_DefineOwnProperty
Obsolete since JSAPI 33This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.5 Please provide a description for this function. Syntax bool JS_DefineOwnProperty(
JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue descriptor, bool *bp); Name Type Description cx
JSContext * The context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleObject Object on which the property should be defined own. id JS::HandleId The jsid of the property that should be defined. descripto...
JS_DeleteElement2
Obsolete since JSAPI 39This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Removes a specified element or numeric property from an object. Renamed to JS_DeleteElement in JSAPI 39 Syntax bool JS_DeleteElement2(
JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleObject Object from which to delete an element. index uint32_t Index number of the element to delete. succeeded ...
JS_DestroyContext
Description These functions destroy a context, cx. JS_DestroyContext additionally performs garbage collection to reclaim any memory that was being used by cx's global object. JS_DestroyContextNoGC does not perform garbage collection. JS_DestroyContextMaybeGC may or may not perform garbage collection; the engine makes an educated guess as to whether enough memory would be reclaimed to justify the work. ...
JS_DestroyIdArray
ida JSIdArray * The JSIdArray to free. Description JS_DestroyIdArray frees the ID array pointed to by ida. ID arrays are primarily the result of JS_Enumerate. ...
JS_DestroyScript
script JSScript * The script to destroy. Description JS_DestroyScript destroys the given compiled script, freeing the memory allocated to it. The script must not be currently executing (in any context, at any level of the stack) and must not be used again afterwards. At present, this function has no effect; the JSScript lives for as long as its script object lives. ...
JS_DumpHeap
it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8 DEBUG only. Dump the object graph of heap-allocated things. Syntax bool JS_DumpHeap(JSRuntime *rt, FILE *fp, void* startThing, JSGCTraceKind kind, void *thingToFind, size_t maxDepth, void *thingToIgnore); Name Type Description cx
JSContext * Pointer to a JS context. Every
JSContext is permanently associated with a JSRuntime; each JSRuntime contains a GC heap. fp FILE * File for the dump output. startThing void * NULL or a pointer to a GC thing (use JS::Value::toGCThing() to obtain a pointer to pass here). When null, dump all things reachable from the runtime roots. When non-null, dump only things re...
JS_EnterCompartment
This article covers features introduced in SpiderMonkey 24 Note: the preferred way of changing a context's current compartment is using JSAutoCompartment. Enter a different compartment on the given context, so that objects in that compartment can be accessed. Syntax JSCompartment * JS_EnterCompartment(
JSContext *cx, JSObject *target); Name Type Description cx
JSContext * The context on which a cross-compartment call is needed. target JSObject * The object in a different compartment to be accessed. This implicitly identifies the compartment to be entered. Description Every
JSContext has a current compartment. Any access to an object in a different compartment must be bracketed by calling JS_EnterCompartment and J...
JS_EnterCrossCompartmentCall
since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.1 JS_EnterCrossCompartmentCall has been removed in bug 786068. Use JS_EnterCompartment instead. Enter a different compartment on the given context, so that objects in that compartment can be accessed. Syntax JSCrossCompartmentCall * JS_EnterCrossCompartmentCall(
JSContext *cx, JSObject *target); Name Type Description cx
JSContext * The context on which a cross-compartment call is needed. target JSObject * The object in a different compartment to be accessed. This implicitly identifies the compartment to be entered. Description Every
JSContext has a current compartment. Any access to an object in a diff...
JS_EnumerateResolvedStandardClasses
Obsolete since JSAPI 24This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Enumerate any already-resolved standard class ids. Syntax JSIdArray * JS_EnumerateResolvedStandardClasses(
JSContext *cx, JSObject *obj, JSIdArray *ida); Name Type Description Description JS_EnumerateResolvedStandardClasses enumerates any already-resolved standard class ids into ida, or into a new JSIdArray if ida is NULL. Return the augmented array on success, NULL on failure with ida (if it was non-null on entry) destroyed. See Also JS_EnumerateResolvedStandardClasses bug 884410 ...
JS_ErrorFromException
Other contexts in the same runtime can have their own error reporting functions. obj JS::HandleObject An exception object. Description If obj is an exception object, the exception will have (or be able to lazily create) an error report struct, and JS_ErrorFromException will return the address of that struct. Otherwise, it returns nullptr. ...
JS_EvaluateScript
Obsolete since JSAPI 36This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Compile and execute a script. Syntax JSBool JS_EvaluateScript(
JSContext *cx, JSObject *obj, const char *src, unsigned int length, const char *filename, unsigned int lineno, jsval *rval); JSBool JS_EvaluateUCScript(
JSContext *cx, JSObject *obj, const jschar *src, unsigned int length, const char *filename, unsigned int lineno, jsval *rval); Name Type Description cx
JSContext * The context in which to run the script. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * The scope in which to...
JS_ExecuteRegExp
Execute a new RegExp object to given input string. Syntax bool JS_ExecuteRegExp(
JSContext *cx, JS::HandleObject obj, JS::HandleObject reobj, char16_t *chars, size_t length, size_t *indexp, bool test, JS::MutableHandleValue rval); bool JS_ExecuteRegExpNoStatics(
JSContext *cx, JS::HandleObject reobj, char16_t *chars, size_t length, size_t *indexp, bool test, JS::MutableHandleValue rval); Name Type Description cx
JSContext * The context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleObject A pointer to a global object. reobj JS::HandleObject A po...
JS_ExecuteScriptPart
ipt 1.9.3This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. JS_ExecuteScriptPart has been removed in bug 555104. Use JS_ExecuteScript instead. Executes a part of a compiled script. Syntax typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart; JSBool JS_ExecuteScriptPart(
JSContext *cx, JSObject *obj, JSScript *script, JSExecPart part, jsval *rval); Name Type Description cx
JSContext * The context in which to execute the script. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * The scope in which to execute the script. This parameter is documented in detail at JS_Ex...
JS_ExecuteScriptVersion
Obsolete since JSAPI 36This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.5 Execute a compiled script with specified version. Syntax JSBool JS_ExecuteScriptVersion(
JSContext *cx, JSObject *obj, JSObject *scriptObj, jsval *rval, JSVersion version); Name Type Description cx
JSContext * The context in which to execute the script. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * The scope in which to execute the script. In the simplest cases, this should just be the embedding's global object. obj ...
JS_FlushCaches
obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.5 Flushes the code cache for the current thread. The operation might be delayed if the cache cannot be flushed currently because native code is currently executing. Syntax void JS_FlushCaches(
JSContext *cx); Name Type Description cx
JSContext * The context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. Description . See also bug 737364 ...
JS_ForgetLocalRoot
Obsolete since JavaScript 1.8.5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Remove a value from the innermost current local root scope. Syntax void JS_ForgetLocalRoot(
JSContext *cx, void *thing); Name Type Description cx
JSContext * Pointer to the context in which the caller is running. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. thing void * Pointer to the value to be unrooted. This must point to a JSObject, JSString, JSFunction, or jsdouble. It must not be NULL. Description This function is used to interact with scoped local root management. See JS_EnterLocalRootScope for more on t...
JS_ForwardGetPropertyTo
This article covers features introduced in SpiderMonkey 17 Find a specified property and retrieve its value. Syntax bool JS_ForwardGetPropertyTo(
JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject onBehalfOf, JS::MutableHandleValue vp); bool JS_ForwardGetElementTo(
JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject onBehalfOf, JS::MutableHandleValue vp); Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleObject Object to search on for the property. id or index JS::HandleId or uint32_t Name or index of the property to look up. onB...
JS_GET_CLASS
. Try to avoid using it. Retrieves the class associated with an object. This macro was removed in SpiderMonkey 1.8.8 when the signature of JS_GetClass() was changed to take only an object pointer. Syntax #ifdef JS_THREADSAFE #define JS_GET_CLASS(cx,obj) JS_GetClass(cx, obj) #else #define JS_GET_CLASS(cx,obj) JS_GetClass(obj) #endif Parameter Type Description cx
JSContext * Any context associated with the runtime in which obj exists. obj JSObject * Object to get the class from. Note: In SpiderMonkey versions prior to SpiderMonkey 1.8.8, JS_GetClass took both a
JSContext* and a JSObject* as arguments in thread-safe builds, and in non-thread-safe builds it took only a JSObject*. The JS_GET_CLASS(cx, obj) macro abstracted away this detail. ...
JS_GetConstructor
obj JS::Handle<JSObject*> The object whose constructor is to be returned. Description JS_GetConstructor retrieves the constructor property of a given object, obj. If the result is a Function object, JS_GetConstructor returns a pointer to that object. Otherwise, it reports an error and returns NULL. To get an object's prototype, use JS_GetPrototype. ...
JS_GetContextThread
Obsolete since JSAPI 8This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Returns the ID of the associated thread for a context. Syntax int JS_GetContextThread(
JSContext *cx); Name Type Description cx
JSContext * The context to examine. Description JS_GetContextThread returns the ID of the thread currently associated with this context. If the context is not currently associated with any thread, the return value is 0. See JS_SetContextThread. JS_GetContextThread is available only if the engine is built with JS_THREADSAFE. MXR ID Search for JS_GetContextThread ...
JS_GetEmptyStringValue
Get the empty string as a value of type JS::Value. Syntax // Added in SpiderMonkey 42 JS::Value JS_GetEmptyStringValue(
JSContext *cx); // Obsolete since SpiderMonkey 42 jsval JS_GetEmptyStringValue(
JSContext *cx); Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. Description JS_GetEmptyStringValue returns the empty string as a JS::Value. See Also MXR ID Search for JS_GetEmptyStringValue bug 1184564 -- Changed jsval to JS::Value ...
JS_GetExternalStringClosure
Obsolete since JSAPI 13This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 6 Returns the string closure stored in a JSString created by calling JS_NewExternalStringWithClosure. Syntax void * JS_GetExternalStringClosure(
JSContext *cx, JSString *str); Name Type Description cx
JSContext * The context from which to retrieve the closure for a string. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. str JSString * The string for which to return the closure. The result is NULL if the external string was created without one (that is, by calling JS_...
JS_GetFunctionCallback
ouraged since it could be removed at any time. Try to avoid using it. Returns the callback currently configured to be called when JavaScript functions are invoked or exited, as established by a prior call to JS_SetFunctionCallback. Note: This method is only available if MOZ_TRACE_JSCALLS was defined at compile time using --enable-trace-jscalls. Syntax JSFunctionCallback JS_GetFunctionCallback(
JSContext *cx); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. Description JS_GetFunctionCallback returns the current function invocation callback, or NULL if there isn't one set up. See Also MXR ID Search for JS_G...
JS_GetGCParameter
Adjust performance parameters related to garbage collection. Syntax uint32_t JS_GetGCParameter(JSRuntime *rt, JSGCParamKey key); void JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value); uint32_t JS_GetGCParameterForThread(
JSContext *cx, JSGCParamKey key); // Added in SpiderMonkeySidebar 17 void JS_SetGCParameterForThread(
JSContext *cx, JSGCParamKey key, uint32_t value); // Added in SpiderMonkeySidebar 17 Name Type Description rt JSRuntime * The runtime to configure. cx
JSContext * The context to configure. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. key JSGCParamKey Specifies which garbage collection parameter to get or set. value uint32_t (JS_SetGC...
JS_GetGlobalForScopeChain
Obsolete since JSAPI 25This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.5 Returns the global object for the active function on the context. Renamed to JS::CurrentGlobalOrNull. Syntax JSObject * JS_GetGlobalForScopeChain(
JSContext *cx); Name Type Description cx
JSContext * The context for which to return the global object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. Description JS_GetGlobalForScopeChain() returns the global object for whatever function is currently running on the context. In other words, it returns the global object on ...
JS_GetGlobalObject
Obsolete since JSAPI 24This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Retrieves a context's global object. (In JavaScript, global variables are stored as properties of the global object.) Syntax JSObject * JS_GetGlobalObject(
JSContext *cx); Name Type Description cx
JSContext * The context from which to retrieve the global object. Description This function is obsolete: use JS_GetGlobalForObject or JS_GetGlobalForScopeChain instead. The concept of a global object belonging to a context will likely be phased out in future versions of SpiderMonkey. JS_GetGlobalObject retrieves the global object for a specified
JSContext *, cx. This returns NUL...
JS_GetLatin1FlatStringChars
tures introduced in SpiderMonkey 38 Get the chars of a flat string. Syntax const JS::Latin1Char * JS_GetLatin1FlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); const char16_t * JS_GetTwoByteFlatStringChars(const JS::AutoCheckCannotGC &nogc, JSFlatString *str); Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext.. nogc JS::AutoCheckCannotGC & A reference to JS::AutoCheckCannotGC. str JSFlatString * A string to get characters. Description JS_GetLatin1FlatStringChars and JS_GetTwoByteFlatStringChars return a pointer to the string. See Also MXR ID Search...
JS_GetLatin1InternedStringChars
ced in SpiderMonkey 38 Get the chars of an interned string. Syntax const JS::Latin1Char * JS_GetLatin1InternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); const char16_t * JS_GetTwoByteInternedStringChars(const JS::AutoCheckCannotGC &nogc, JSString *str); Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext.. nogc JS::AutoCheckCannotGC & A reference to JS::AutoCheckCannotGC. str JSString * A string to get characters. Description JS_GetLatin1InternedStringChars and JS_GetTwoByteInternedStringChars gets the characters of the string, str. If successful...
JS_GetLatin1StringCharsAndLength
This article covers features introduced in SpiderMonkey 38 Get the chars and the length of a string. Syntax const JS::Latin1Char * JS_GetLatin1StringCharsAndLength(
JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, size_t *length); const char16_t * JS_GetTwoByteStringCharsAndLength(
JSContext *cx, const JS::AutoCheckCannotGC &nogc, JSString *str, size_t *length); Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext.. nogc JS::AutoCheckCannotGC & A reference to JS::AutoCheckCannotGC. str JSString * A string to get characters. length size_t * ...
JS_GetNaNValue
Description JS_GetNaNValue returns a value of type JS::Value that represents an IEEE floating-point quiet Not-a-Number (NaN). NaN is typically used in JavaScript as the return value of a numeric operation when an argument is invalid or conversion fails. For example, 0/0 and Math.sqrt(-1) both return NaN. ...
JS_GetOwnPropertyDescriptor
Get a detailed description of that property. Syntax bool JS_GetOwnPropertyDescriptor(
JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle<JSPropertyDescriptor> desc); bool JS_GetOwnPropertyDescriptorById(
JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle<JSPropertyDescriptor> desc); bool JS_GetOwnUCPropertyDescriptor(
JSContext *cx, JS::HandleObject obj, const char16_t *name, JS::MutableHandle desc); // Added in SpiderMonkey 45 Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleObject The object to search for the...
JS_GetParentRuntime
This article covers features introduced in SpiderMonkey 31 Retrieve a pointer to the parent JSRuntime. Syntax JSRuntime * JS_GetParentRuntime(
JSContext *cx); Name Type Description cx
JSContext * The context to query. Description JS_GetParentRuntime retrieves a pointer to the parent JSRuntime of the runtime for a specified
JSContext. If the cx's runtime has no parent runtime, JS_GetParentRuntime returns cx's runtime itself. See Also MXR ID Search for JS_GetParentRuntime JS_GetRuntime bug 964059 ...
JS_GetPendingException
vp JS::MutableHandleValue Out parameter. On success, *vp receives the current pending exception. Description If an exception has been thrown in the context cx, and it has not yet been caught or cleared, JS_GetPendingException stores the exception object in *vp and returns true. Otherwise, it returns false, and the value left in *vp is undefined. ...
JS_GetProperty
Find a specified property and retrieve its value. Syntax bool JS_GetProperty(
JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandleValue vp); bool JS_GetUCProperty(
JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen, JS::MutableHandleValue vp); bool JS_GetPropertyById(
JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); // Added in SpiderMonkey 1.8.1 Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleObject Object to search on for the property. name or id const char * or const char16_t * or JS::...
JS_GetPropertyAttributes
Obsolete since JSAPI 26This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Get the attributes of a specified property. Syntax JSBool JS_GetPropertyAttributes(
JSContext *cx, JSObject *obj, const char *name, unsigned int *attrsp, JSBool *foundp); JSBool JS_GetUCPropertyAttributes(
JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, unsigned int *attrsp, JSBool *foundp); Name Type Description cx
JSContext * The context in which to look up property attributes. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * The object that has the property to be queried. ...
JS_GetPropertyDefault
Obsolete since JSAPI 26This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.5 Finds a specified property and retrieves its value or provided default value. Syntax bool JS_GetPropertyDefault(
JSContext *cx, JSObject *obj, const char *name, jsval def, JS::MutableHandle<JS::Value> vp); bool JS_GetPropertyByIdDefault(
JSContext *cx, JSObject *obj, jsid id, jsval def, JS::MutableHandle<JS::Value> vp); Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. ...
JS_GetPropertyDescriptor
Finds a specified property of an object and gets a detailed description of that property. Syntax bool JS_GetPropertyDescriptor(
JSContext *cx, JS::HandleObject obj, const char *name, JS::MutableHandle<JSPropertyDescriptor> desc); // Added in SpiderMonkey 31 bool JS_GetPropertyDescriptorById(
JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandle<JSPropertyDescriptor> desc); Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleObject The object to search for the property. id const char * or JS::HandleId The name of the property to look up. desc ...
JS_GetScopeChain
could be removed at any time. Try to avoid using it. Retrieves the scope chain for the JavaScript code currently running in a given context. JS_GetScopeChain has been removed in SpiderMonkey 1.8.7 with no identical replacement. When you only used this function to retrieve the scope chain's global, then you can use the function JS_GetGlobalForScopeChain. Syntax JSObject * JS_GetScopeChain(
JSContext *cx); Name Type Description cx
JSContext * The context to query. Description JS_GetScopeChain returns the first JSObject on the scope chain for the JavaScript code currently running in the given context, cx. The ECMAScript standard, ECMA 262-3 ?10, describes execution contexts and scope chains. A scope chain is a sequence of objects whose properties are se...
JS_GetSecurityCallbacks
This article covers features introduced in SpiderMonkey 1.8.1 Configure SpiderMonkey security hooks. Syntax /* Added in SpiderMonkey 17 */ void JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks); const JSSecurityCallbacks * JS_GetSecurityCallbacks(JSRuntime *rt); /* Obsolete since JSAPI 13 */ JSSecurityCallbacks * JS_SetContextSecurityCallbacks(
JSContext *cx, JSSecurityCallbacks *callbacks); JSSecurityCallbacks * JS_GetRuntimeSecurityCallbacks(JSRuntime *rt); JSSecurityCallbacks * JS_SetRuntimeSecurityCallbacks(JSRuntime *rt, JSSecurityCallbacks *callbacks); Name Type Description rt JSRuntime * A runtime to get/set the security callbacks. callbacks const JSSecurityCallbacks * A pointer to the new callba...
JS_GetStringBytes
Obsolete since JSAPI 1.8.5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Convert a JavaScript string to a C string. Syntax char * JS_GetStringBytes(JSString *str); const char * JS_GetStringBytesZ(
JSContext *cx, JSString *str); // Added in JSAPI 1.8.2 Name Type Description cx
JSContext * (JS_GetStringBytesZ and JS_EncodeString only) A context. str JSString * String to retrieve bytes from. Description JS_GetStringBytes and JS_GetStringBytesZ convert the specified JavaScript string, str, to a C string (an array of 8-bit chars). If JS_CStringsAreUTF8 is true, then the returned string is UTF-8, and the conversion is lossless. Otherwise the...
JS_GetStringChars
Obsolete since JSAPI 33This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Retrieve a pointer to the 16-bit values that make up a given string. Syntax jschar * JS_GetStringChars(JSString *str); // Obsolete since JSAPI 1.8.5 const jschar * JS_GetStringCharsZ(
JSContext *cx, JSString *str); // Added in SpiderMonkey 1.8.2, Obsolete since JSAPI 33 Name Type Description cx
JSContext * (in JS_GetStringCharsZ only) A context. str JSString * The string to obtain characters from. Description JS_GetStringChars Obsolete since JavaScript 1.8.5 returns a pointer to the first element of an array of jschars. Warnings: The array is not necessa...
JS_GetStringCharsAndLength
Obsolete since JSAPI 33This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.5 Get the characters and the length of a string. Syntax const jschar * JS_GetStringCharsAndLength(
JSContext *cx, JSString *str, size_t *length); Name Type Description cx
JSContext * The context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. str JSString * A string to get characters. length size_t * Out parameter. Receives the length of the string. Description JS_GetStringCharsAndLength gets the characters and the length of the string, st...
JS_GetTypeName
Obsolete since JSAPI 34This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Returns a pointer to the string literal description of a specified JS data type. Syntax const char * JS_GetTypeName(
JSContext *cx, JSType type); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. type JSType One of JSTYPE_VOID, JSTYPE_OBJECT, JSTYPE_FUNCTION, JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_BOOLEAN. Description JS_GetTypeName returns a pointer to a string literal description of a specified JS data type, type. The following table lists JSTypes and the string literals reported by JS_GetTypeName: Type ...
JS_HasArrayLength
Obsolete since JSAPI 8This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Determines if an object has an array length property. Syntax JSBool JS_HasArrayLength(
JSContext *cx, JSObject *obj, jsuint *lengthp); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * Array object to get the length of. lengthp jsuint * Out parameter. On success, *lengthp receives the length of the array. Description JS_HasArrayLength determines if an object, obj, has a length propert...
JS_IdToValue
id jsid The property identifier to convert. vp JS::MutableHandle<JS::Value> Out parameter. On success, *vp receives the converted value. Description JS_IdToValue converts a specified JS ID, id, to a JS value. On success, JS_IdToValue stores the converted value in *vp and returns true. Otherwise it returns false. ...
JS_InitCTypesClass
This article covers features introduced in SpiderMonkey 1.8.5 Initialize the ctypes object on a global object. The ctypes object will be frozen. Syntax JSBool JS_InitCTypesClass(
JSContext *cx, JSObject *global); Name Type Description cx
JSContext * The context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. global JSObject * The global object. Description ctypes capability is disabled in a build by default. See also ...
JS_InitClass
Make a JSClass accessible to JavaScript code by creating its prototype, constructor, properties, and functions. Syntax JSObject * JS_InitClass(
JSContext *cx, JS::HandleObject obj, JS::HandleObject parent_proto, const JSClass *clasp, JSNative constructor, unsigned nargs, const JSPropertySpec *ps, const JSFunctionSpec *fs, const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleObject Pointer to the "globals" object to use for initializing the class. This must not be NULL. Once JS_InitClass crea...
JS_InternString
Get an interned string - a JSString that is protected from GC and automatically shared with other code that needs a JSString with the same value. Syntax JSString * JS_InternString(
JSContext *cx, const char *s); JSString * JS_InternStringN(
JSContext *cx, const char *s, size_t length); JSString * JS_InternUCString(
JSContext *cx, const char16_t *s); JSString * JS_InternUCStringN(
JSContext *cx, const char16_t *s, size_t length); Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. s const char * or const char16_t * Pointer to a character array containing the data for the string. In JS_InternString and JS_InternUCString, the string must be null-terminated. ...
JS_IsAssigning
Obsolete since JavaScript 1.8.5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Determine whether script is executing assignment operation. Syntax JSBool JS_IsAssigning(
JSContext *cx); Name Type Description Description JS_IsAssigning returns true if a script is executing and its current bytecode is a set (assignment) operation, even if there are native (no script) stack frames between the script and the caller to JS_IsAssigning. See Also bug 458421 ...
JS_IsConstructing
I 26This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Determine whether the currently executing JSNative was called as a constructor. JS_IsConstructing has been removed in bug 918462. Use CallArgs::isConstructing or CallReceiver::isConstructing instead. Syntax JSBool JS_IsConstructing(
JSContext *cx, jsval *vp); Name Type Description cx
JSContext * The cx parameter passed to the JSNative. vp jsval * The vp parameter passed to the JSNative. Description JS_IsConstructing must be called only from a JSNative called from the engine. cx and vp must be the arguments that the engine passed to that JSNative. JS_IsConstructing returns JS_TRUE if ...
JS_IsExceptionPending
Description JS_IsExceptionPending returns true if an exception has been thrown in the context cx and the exception has not yet been caught or cleared. Otherwise, it returns false This can be used from JSNative functions which call JS code to determine if the called JS code threw an exception or not. Example /* JSAPI */ bool pending; JS::RootedValue exception(cx); /* If an exception is pending, save and clear it. ...
JS_IsRunning
Indicates whether or not a script or function is currently executing in a given context. Syntax bool JS_IsRunning(
JSContext *cx); Name Type Description cx
JSContext * The context to query. Description JS_IsRunning determines if a script or function is currently executing in a specified
JSContext, cx. If a script is executing, JS_IsRunning returns true. Otherwise it returns false. See Also MXR ID Search for JS_IsRunning ...
JS_LeaveCompartment
This article covers features introduced in SpiderMonkey 24 Note: the preferred way of changing a context's current compartment is using JSAutoCompartment. Leave a the compartment, returning to the compartment active before the corresponding JS_EnterCompartment. Syntax void JS_LeaveCompartment(
JSContext *cx, JSCompartment *oldCompartment); Name Type Description cx
JSContext * The context in which to leave the compartment. oldCompartment JSCompartment * Value returned by previous call to JS_EnterCompartment. Description Every
JSContext has a current compartment. Any access to an object in a different compartment must be bracketed by calls to JS_EnterCompartment and JS_LeaveCompartment. See Also MXR ID Search for JS_Lea...
JS_LeaveCrossCompartmentCall
Use JS_LeaveCompartment instead. Leave a the compartment, returning to the compartment active before the corresponding JS_EnterCrossCompartmentCall. Syntax void JS_LeaveCrossCompartmentCall(JSCrossCompartmentCall *call); Name Type Description call JSCrossCompartmentCall * Value returned by previous call to JS_EnterCrossCompartmentCall. Description Every
JSContext has a current compartment. Any access to an object in a different compartment must be bracketed by call JS_EnterCrossCompartmentCall and JS_LeaveCrossCompartmentCall. See Also JS_EnterCrossCompartmentCall JS_EnterCompartment JS_LeaveCompartment bug 786068 bug 563099 ...
JS_LeaveLocalRootScope
Obsolete since JavaScript 1.8.5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Leave a local root scope. Syntax void JS_LeaveLocalRootScope(
JSContext *cx); Name Type Description cx
JSContext * Pointer to the context. This must be the same context passed to JS_EnterLocalRootScope(). Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. Description See JS_EnterLocalRootScope for an explanation of local root scopes. Leaving a nested local root scope causes all objects created since the matching JS_EnterLocalRootScope call to become subject to garbage collection. That is, they are not transferred to the enclosing l...
JS_LinkConstructorAndPrototype
This article covers features introduced in SpiderMonkey 17 Set up ctor.prototype = proto and proto.constructor = ctor with the right property flags. Syntax bool JS_LinkConstructorAndPrototype(
JSContext *cx, JS::Handle<JSObject*> ctor, JS::Handle<JSObject*> proto); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. ctor JS::Handle<JSObject*> Pointer to the constructor object. proto JS::Handle<JSObject*> Pointer to the prototype object. Description JS_LinkConstructorAndPrototype sets the prototype property of class constructor functi...
JS_LockGCThing
Obsolete since JSAPI 22This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Protect a specified JS item from garbage collection. Syntax JSBool JS_LockGCThing(
JSContext *cx, void *thing); // Obsolete since JSAPI 21 JSBool JS_UnlockGCThing(
JSContext *cx, void *thing); // Obsolete since JSAPI 21 JSBool JS_LockGCThingRT(JSRuntime *rt, void *thing); JSBool JS_UnlockGCThingRT(JSRuntime *rt, void *thing); Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. rt JSRuntime * A runtime. thing void * Pointer to the item to protect. Description JS_...
JS_LookupElement
Obsolete since JSAPI 37This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Determine if a specified numeric property exists. Syntax bool JS_LookupElement(
JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp); Name Type Description cx
JSContext * The context in which to look up the property. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleObject The object to search. index uint32_t The numeric id of the property to look up. vp JS::MutableHandleValue Out parameter. On success, *vp receives the stored value of obj...
JS_MaybeGC
Description JS_MaybeGC tries to determine whether garbage collection in cx's runtime would free up enough memory to be worth the amount of time it would take. If so, it performs some garbage collection. Calling JS_MaybeGC when the application is idle can help prevent garbage collection from happening at less convenient times. ...
JS_New
This article covers features introduced in SpiderMonkey 1.8 Create an object as though by using the new keyword and a JavaScript function. Syntax JSObject * JS_New(
JSContext *cx, JS::HandleObject ctor, const JS::HandleValueArray& args); // Added in JSAPI 32 JSObject * JS_New(
JSContext *cx, JSObject *ctor, unsigned argc, jsval *argv); // Obsolete since JSAPI 32 Name Type Description cx
JSContext * The context in which to create the new object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. ctor JS::HandleObject The constructor function object. args JS::HandleValueArray & An array of argument values to pass to the constructor. Added in SpiderMonkey 38 argc unsigne...
JS_NewCompartmentAndGlobalObject
hough it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.1 JS_NewCompartmentAndGlobalObject has been removed in bug 755186. Use JS_NewGlobalObject instead. Create a new global object in a new compartment. Syntax JSObject * JS_NewCompartmentAndGlobalObject(
JSContext *cx, JSClass *clasp, JSPrincipals *principals); Name Type Description cx
JSContext * The context in which to create the new global object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. clasp JSClass * The class to use for the new global object. clasp->flags must...
JS_NewDateObjectMsec
This article covers features introduced in SpiderMonkey 1.8.5 Creates a new Date object instance, configured to represent the date and time indicated by the specified time in milliseconds since the Unix epoch. Syntax JSObject * JS_NewDateObjectMsec(
JSContext *cx, double msec); Name Type Description cx
JSContext * The context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. msec double Time since Unix epoch in milliseconds. Description The returned JSObject is a standard JavaScript Date. See also MXR ID Search for JS_NewDateObjectMsec JS_NewDateObject JS_ObjectIsDate bug 625870 ...
JS_NewDouble
Obsolete since JSAPI 17This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Use JS_NewNumberValue instead. Allocates a copy of jsdouble on the GC heap. Syntax jsdouble * JS_NewDouble(
JSContext *cx, jsdouble d); Name Type Description cx
JSContext * The context in which to create the new number. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. d jsdouble The number to copy. Description JS_NewDouble allocates a copy of the number d on the JavaScript garbage collection heap. This function is not very useful. To convert a jsdouble to a jsval, use JS_NewNumberValue instead. Warning: The argument...
JS_NewDoubleValue
Obsolete since JSAPI 17This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Use JS_NumberValue instead. Create a floating-point jsval Syntax JSBool JS_NewDoubleValue(
JSContext *cx, jsdouble d, jsval *rval); Name Type Description cx
JSContext * The context in which to create the new number. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. d jsdouble The numeric value to convert. This must not be a value that could fit in an integer jsval (see INT_FITS_IN_JSVAL). rval jsval * Out parameter. On success, *rval receives a JavaScript number with the value d. Description JS_N...
JS_NewExternalString
Create a new JSString whose characters are stored in external memory. Syntax JSString * JS_NewExternalString(
JSContext *cx, const char16_t *chars, size_t length, const JSStringFinalizer *fin); JSString * JS_NewExternalStringWithClosure(
JSContext *cx, jschar *chars, size_t length, int type, void *closure); // Obsolete since JSAPI 13 Name Type Description cx
JSContext * The context in which to create the new string. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. chars const char16_t * or const jschar * Pointer to the first element of an array of char16_ts. This array is used as the character buffer of the JSString to be created. The array must be p...
JS_NewGlobalObject
This article covers features introduced in SpiderMonkey 17 Create a new JavaScript object for use as a global object. Syntax JSObject * JS_NewGlobalObject(
JSContext *cx, const JSClass *clasp, JSPrincipals *principals, JS::OnNewGlobalHookOption hookOption, const JS::CompartmentOptions &options = JS::CompartmentOptions()); Name Type Description cx
JSContext * The context in which to create the new global object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. clasp Jsclass * The class to use for the new global object. clasp->flags must have the JSCLASS_GLOBAL_FLAGS bits set. The caller must ensure that the JSClass remains alive through...
JS_NewObject
Creates a new JavaScript object. Syntax // Added in SpiderMonkey 45 JSObject * JS_NewObject(
JSContext *cx, const JSClass *clasp); bool JS_NewObjectWithGivenProto(
JSContext *cx, const JSClass *clasp, JS::Handle<JSObject*> proto); // Obsolete since SpiderMonkey 38 JSObject * JS_NewObject(
JSContext *cx, const JSClass *clasp, JS::Handle<JSObject*> proto, JS::Handle<JSObject*> parent); JSObject * JS_NewObjectWithGivenProto(
JSContext *cx, const JSClass *clasp, JS::Handle<JSObject*> proto, JS::Handle<JSObject*> parent); // Added in SpiderMonkey 1.8 Name Type Description cx
JSContext * The context in which to create the new object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. ...
JS_NewObjectForConstructor
Convenience function to create a new object exactly as a constructor function would. Syntax JSObject * JS_NewObjectForConstructor(
JSContext *cx, const JSClass *clasp, const JS::CallArgs& args); // Added in JSAPI 32 JSObject * JS_NewObjectForConstructor(
JSContext *cx, JSClass *clasp, const jsval *vp); // Added in JSAPI 14, Obsolete since JSAPI 32 JSObject * JS_NewObjectForConstructor(
JSContext *cx, const jsval *vp); // Obsolete since JSAPI 14 Name Type Description cx
JSContext * The context in which to create the new object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. clasp const JSClass * The class of the object to create. Added in SpiderMonkey 17 vp jsval * Pointer to a constructor...
JS_NewPropertyIterator
Obsolete since JSAPI 36This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Crate an iterator object for use with JS_NextProperty. Syntax JSObject * JS_NewPropertyIterator(
JSContext *cx, JS::Handle<JSObject*> obj); Name Type Description cx
JSContext * The JS context in which to enumerate properties. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::Handle<JSObject*> The object whose properties are to be enumerated. Description Create an object to iterate over the enumerable own properties of obj, in arbitrary order. (This differs from longstanding for..in loop order, which uses the o...
JS_NewScriptObject
Obsolete since JSAPI 8This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Return the JavaScript script object that wraps a compiled script. The compiled script and its parts live until the script object is garbage collected. Syntax JSObject * JS_NewScriptObject(
JSContext *cx, JSScript *script); Name Type Description cx
JSContext * The context in which to create the new script object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. script JSScript * The compiled script for which to create a new script object. Description JS_NewScriptObject returns the script object associated with the give...
JS_NewUCString
Note: JS_NewString() was removed in SpiderMonkey 1.8.5. Use JS_NewStringCopyN and JS_NewUCStringCopyN instead. Syntax JSString * JS_NewUCString(
JSContext *cx, char16_t *chars, size_t length); JSString * JS_NewString(
JSContext *cx, char *buf, size_t length); // Obsolete since JSAPI 1.8.5 Name Type Description cx
JSContext * The context in which to create the new string. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. buf char * or char16_t * Pointer to a character array, allocated with JS_malloc, containing the characters for the JS string to create. The JavaScript engine adopts the buffer. length size_t Number of characters in the text string. Description JS_NewString crea...
JS_NextProperty
Obsolete since JSAPI 36This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Get the next property id from an iterator object produced by JS_NewPropertyIterator. Syntax bool JS_NextProperty(
JSContext *cx, JS::HandleObject iterobj, JS::MutableHandleId idp); Name Type Description cx
JSContext * The JS context in which to enumerate properties. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. iterobj JS::HandleObject The opaque iterator object returned by a previous call to JS_NewPropertyIterator. idp JS::MutableHandleId Out parameter. On success, *idp receives the name or index of the next p...
JS_ObjectIsFunction
obj JSObject * The object to test. This must not be NULL. Description JS_ObjectIsFunction tests 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). JS_ObjectIsFunction returns true if obj is a Function and false otherwise. ...
JS_PopArguments
Obsolete since JavaScript 1.8.5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Frees the stack entry allocated by JS_PushArguments. Syntax void JS_PopArguments(
JSContext *cx, void *mark); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. mark void * Pointer to a void * which holds the stack frame pointer previously supplied by JS_PushArguments. Description JS_PopArguments frees the stack frame pointer previously allocated by JS_PushArguments and unroots the jsvals which have been associated ...
JS_PushArguments
Obsolete since JavaScript 1.8.5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Convert any number of arguments to jsvals and store the resulting jsvals in an array. Syntax jsval * JS_PushArguments(
JSContext *cx, void **markp, const char *format, ...); jsval * JS_PushArgumentsVA(
JSContext *cx, void **markp, const char *format, va_list ap); Name Type Description cx
JSContext * The context in which to perform any necessary conversions. cx also affects the interpretation of format, if JS_AddArgumentFormatter has been called. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. markp void ** Out p...
JS_Remove*Root
Obsolete since JSAPI 31This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Unregisters a pointer to a GC thing so that it is no longer a member of the garbage collector's root set. This enables any pointed-at GC thing to be garbage collected as needed. Syntax JSBool JS_RemoveValueRoot(
JSContext *cx, jsval *vp); JSBool JS_RemoveStringRoot(
JSContext *cx, JSString **spp); JSBool JS_RemoveObjectRoot(
JSContext *cx, JSObject **opp); JSBool JS_RemoveGCThingRoot(
JSContext *cx, void **rp); Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. vp jsval * Address o...
JS_ReportError
Create a formatted error or warning message to pass to a user-defined error reporting function. This function can also raise a JavaScript exception which a currently executing script can catch. Syntax void JS_ReportError(
JSContext *cx, const char *format, ...); bool JS_ReportWarning(
JSContext *cx, const char *format, ...); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. format const char * Format string to convert into an error message using JS_vsmprintf. ... ... Error message variables to insert into the format string. Description JS_ReportError is the simplest JSAPI function for ...
JS_ReportOutOfMemory
Description Call JS_ReportOutOfMemory to report that an operation failed because the system is out of memory. When the JavaScript engine tries to allocate memory and allocation fails, it reports an error as though by calling this function. Call JS_ReportAllocationOverflow if an operation fails because it tries to use more memory (or more of some other resource) than the application is designed to handle. ...
JS_ReportPendingException
Description If an exception is pending in the context cx, JS_ReportPendingException converts the exception to a string and reports it to the current error reporter. On success, it clears the exception as though by calling JS_ClearPendingException and returns true. If no exception is pending, or if a second error occurs while trying to report the first one, it returns false. ...
JS_SameValue
lue slightly differs from strict equality (===) in that +0 and -0 are not the same and in that NaN is the same as NaN. The SameValue algorithm is equivalent to the following JavaScript: function SameValue(v1, v2) { if (v1 === 0 && v2 === 0) return 1 / v1 === 1 / v2; if (v1 !== v1 && v2 !== v2) return true; return v1 === v2; } Syntax // Added in SpiderMonkey 45 bool JS_SameValue(
JSContext *cx, JS::Handle<JS::Value> v1, JS::Handle<JS::Value> v2, bool *same); // Obsolete since JSAPI 39 bool JS_SameValue(
JSContext *cx, jsval v1, jsval v2, bool *same); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JS...
JS_SaveExceptionState
Description Saves the current exception state (that is, any pending exception, or a cleared exception state) associated with the specified context cx, and returns a JSExceptionState object holding this state. That object may then be used to restore again the context using JS_RestoreExceptionState, or discarded using JS_DropExceptionState. ...
JS_SaveFrameChain
Description These two functions are used to set aside cx's call stack while that stack is inactive. After a call to JS_SaveFrameChain, it looks as if there is no code running on cx. Before calling JS_RestoreFrameChain, cx's call stack must be balanced and all nested calls to JS_SaveFrameChain must have had matching JS_RestoreFrameChain calls. JS_SaveFrameChain deals with cx not having any code running on it. ...
JS_ScheduleGC
The GC zeal level of the associated JSRuntime is set. frequency uint32_t The value of nextScheduled parameter of GC. Description JS_ScheduleGC sets the nextScheduled parameter of GC. At every allocation nextScheduled is decremented. When it reaches zero, we do either a full or a compartmental GC. ...
JS_SealObject
(namely, that of Object.seal) which is quite different from that of JS_SealObject. Moreover, JS_SealObject's exact semantics are subtly incompatible with ECMAScript. JS_FreezeObject and JS_DeepFreezeObject are near-substitutes compatible with ECMAScript semantics, implementing semantics compatible with those of Object.freeze. Prevent modification of object fields. Syntax JSBool JS_SealObject(
JSContext *cx, JSObject *obj, JSBool deep); Name Type Description cx
JSContext * A context. obj JSObject * The object to seal. deep JSBool If true, seal all objects directly or indirectly reachable from obj's slots. Description JS_SealObject prevents all write access to the object, either to add a new property, delete an existing property, ...
JS_SetAllNonReservedSlotsToUndefined
This article covers features introduced in SpiderMonkey 24 Assign undefined to all of the object's non-reserved slots. Note: This is done for all slots, regardless of the associated property descriptor. Syntax void JS_SetAllNonReservedSlotsToUndefined(
JSContext *cx, JSObject *objArg); Name Type Description cx
JSContext * The context in which to clear the object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * Object from which to delete all properties. Description JS_SetAllNonReservedSlotsToUndefined assignes undefined to all of obj's own properties, except the special __proto__ and __parent__ properties, in a single operation. Properties belonging to objects on o...
JS_SetArrayLength
obj JS::Handle<JSObject*> The array to modify. length uint32_t Number of array elements to set. Description JS_SetArrayLength sets the .length property of an object obj. length indicates the number of elements. JS_SetArrayLength(cx, obj, n) is exactly the same as setting the length property of obj to n using JS_SetProperty. ...
JS_SetCallReturnValue2
Obsolete since JavaScript 1.8.5This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Causes a native to return a Reference value (as allowed by ECMA 262-3 ?11.2.3). Syntax void JS_SetCallReturnValue2(
JSContext *cx, jsval v); Name Type Description cx
JSContext * The context in which the native function is running. v jsval The ID of the property of the Reference value to be returned from the native. Description ...
JS_SetGlobalObject
Obsolete since JSAPI 25This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Set a context's global object. Syntax void JS_SetGlobalObject(
JSContext *cx, JSObject *obj); Name Type Description cx
JSContext * The context to configure. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * Pointer to the object to set as the global object, or NULL. Description This function is obsolete; see also JS_GetGlobalObject. JS_SetGlobalObject sets the global object of the context cx to obj. If obj is NULL, the context is set to have no global object. Each context's global object is in the ...
JS_SetInterruptCallback
lback JS_SetInterruptCallback(JSRuntime *rt, JSInterruptCallback callback); JSInterruptCallback JS_GetInterruptCallback(JSRuntime *rt); void JS_RequestInterruptCallback(JSRuntime *rt); Name Type Description rt JSRuntime * The runtime. callback JSInterruptCallback The callback function to install. Callback syntax bool (* JSInterruptCallback)(
JSContext *cx); Name Type Description cx
JSContext * Pointer to a
JSContext in which this callback was installed. The callback may use this context to call JSAPI functions, but it should first use JS_SetInterruptCallback to set the context's interrupt callback to NULL. Otherwise the engine may call the interrupt callback again, reentering it. Provides request. In J...
JS_SetParent
Obsolete since JSAPI 39This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Sets the parent for an object. Syntax bool JS_SetParent(
JSContext *cx, JS::HandleObject obj, JS::HandleObject parent); Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleObject Pointer to the object for which to set the parent. This must be an object that has not yet been exposed to script. See the Description for details. parent JS::HandleObject Pointer to the parent object to use. Descri...
JS_SetProperty
Assign a value to a property of an object. Syntax bool JS_SetProperty(
JSContext *cx, JS::HandleObject obj, const char *name, JS::HandleValue v); bool JS_SetUCProperty(
JSContext *cx, JS::HandleObject obj, const char16_t *name, size_t namelen, JS::HandleValue v); bool JS_SetPropertyById(
JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v); // Added in SpiderMonkey 1.8.1 Name Type Description cx
JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JS::HandleValue Object to which the property to set belongs. name or id const char...
JS_SetPropertyAttributes
Obsolete since JSAPI 26This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Set the attributes for a specified property. Syntax JSBool JS_SetPropertyAttributes(
JSContext *cx, JSObject *obj, const char *name, unsigned int attrs, JSBool *foundp); JSBool JS_SetUCPropertyAttributes(
JSContext *cx, JSObject *obj, const jschar *name, size_t namelen, unsigned int attrs, JSBool *foundp); Name Type Description cx
JSContext * The context in which to set the property attributes. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. obj JSObject * Object for which to set property attributes. na...
JS_ShutDown
Free all resources used by the JS engine, not associated with specific runtimes. Syntax void JS_ShutDown(void); Description Destroys all free-standing resources allocated by SpiderMonkey, not associated with any JSRuntime,
JSContext, or other structure. This method should be called after all other JSAPI data has been properly cleaned up: every JSRuntime created with JS_NewRuntime must have been destroyed with JS_DestroyRuntime, every
JSContext created with JS_NewContext must have been destroyed with JS_DestroyContext, and so on. Calling this method before all other resources have been destroyed has undefined behavior. Failure to call this method, at present, has no adverse effects other than leaking memory. This may not always be the case; it's recommended that all embedders call this method wh...
JS_StrictlyEqual
This article covers features introduced in SpiderMonkey 1.8.1 Determine whether two JavaScript values are equal in the sense of the === operator. Syntax // Added in SpiderMonkey 45 bool JS_StrictlyEqual(
JSContext *cx, JS::Handle<JS::Value> v1, JS::Handle<JS::Value> v2, bool *equal); // Obsolete since JSAPI 39 bool JS_StrictlyEqual(
JSContext *cx, jsval v1, jsval v2, bool *equal); Name Type Description cx
JSContext * The context in which to perform the conversion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. v1, v2 JS::Handle<JS::Value> / jsval The value to compare. equal bool * Out parameter. Receives the comparison result. Description JS_Stri...
JS_StringHasBeenInterned
This article covers features introduced in SpiderMonkey 17 Determine if string is interned. Syntax bool JS_StringHasBeenInterned(
JSContext *cx, JSString *str); Name Type Description str JSString * A string to examine. Description JS_StringHasBeenInterned returns true if the string str is interned. See Also MXR ID Search for JS_StringHasBeenInterned bug 724810 ...
JS_SuspendRequest
iscouraged since it could be removed at any time. Try to avoid using it. Removed from SpiderMonkey at or prior to version 45. Since then, a JSRuntime is tied to the thread that created it; it may not be accessed by any other thread. Suspends the calling thread's current request, if any, to allow the thread to block or perform time-consuming calculations. Syntax jsrefcount JS_SuspendRequest(
JSContext *cx); void JS_ResumeRequest(
JSContext *cx, jsrefcount saveDepth); Name Type Description cx
JSContext * The context whose current request is to be suspended or resumed. saveDepth jsrefcount (only in JS_ResumeRequest) The valued returned by the matching JS_SuspendRequest call. Description In JS_THREADSAFE builds, when a multi-threaded applicat...
JS_ThrowStopIteration
Description JS_ThrowStopIteration throws the appropriate StopIteration object for the function currently executing in cx. In for...in and for each...in loops, the JavaScript engine can create an iterator object and call its .next method repeatedly, as described in New in JavaScript 1.7: Iterators. ...
JS_TracerInit
is article covers features introduced in SpiderMonkey 1.8 Note: in JSAPI 12, the macro JS_TRACER_INIT has been replaced by the function JS_TracerInit Initialize a JSTracer for object graph tracing. Syntax void JS_TracerInit(JSTracer *trc, JSRuntime *rt, JSTraceCallback callback); Name Type Description trc JSTracer * The tracer to be initialized. cx
JSContext * The context in which to perform tracing. callback JSTraceCallback A callback, described below, which the tracing APIs will call each time a pointer is found from one GC thing to another. Callback syntax typedef void (*JSTraceCallback)(JSTracer *trc, void *thing, uint32 kind); Name Type Description trc JSTracer * The tracer visiting obj. ...
JS_ValueToBoolean
Obsolete since JSAPI 28This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Replaced by JS::ToBoolean Convert any JavaScript value to a boolean value. Syntax JSBool JS_ValueToBoolean(
JSContext *cx, jsval v, JSBool *bp); Name Type Description cx
JSContext * The context in which to perform the conversion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. v jsval The value to convert. bp JSBool * Out parameter. On success, *bp receives the converted boolean value. Description JS_ValueToBoolean converts a specified JavaScript value, v, to a boolean value. It implements the ToBo...
JS_ValueToECMAInt32
Obsolete since JSAPI 28This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Convert a JavaScript value to an integer type as specified by the ECMAScript standard. Syntax JSBool JS_ValueToECMAInt32(
JSContext *cx, jsval v, int32 *ip); JSBool JS_ValueToECMAUint32(
JSContext *cx, jsval v, uint32 *ip); JSBool JS_ValueToUint16(
JSContext *cx, jsval v, uint16 *ip); Name Type Description cx
JSContext * The context in which to perform the conversion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. v jsval The JavaScript value to convert. ip int32 * or uint32 * or int16 * Out parameter. On su...
JS_ValueToId
Convert a JS::Value to type jsid. Syntax bool JS_ValueToId(
JSContext *cx, JS::HandleValue v, JS::MutableHandleId idp); bool JS_StringToId(
JSContext *cx, JS::HandleString s, JS::MutableHandleId idp); // Added in SpiderMonkey 38 bool JS_IndexToId(
JSContext *cx, uint32_t index, JS::MutableHandleId idp); // Added in SpiderMonkey 17 bool JS_CharsToId(
JSContext* cx, JS::TwoByteChars chars, JS::MutableHandleId idp); // Added in SpiderMonkey 24 void JS::ProtoKeyToId(
JSContext *cx, JSProtoKey key, JS::MutableHandleId idp); // Added in SpiderMonkey 38 Name Type Description cx
JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. v JS::HandleValue The JS value to convert. s JS::H...
JS_ValueToInt32
Obsolete since JSAPI 28This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Convert a JavaScript value to a 32-bit signed integer. Syntax JSBool JS_ValueToInt32(
JSContext *cx, jsval v, int32 *ip); Name Type Description cx
JSContext * The context in which to perform the conversion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. v jsval The value to convert. ip int32 * Out parameter. On success, *ip receives the converted integer value. Description JS_ValueToInt32 converts a specified JS value, v, to a 32-bit signed integer (-2147483648 to 2147483647). First it converts v to ...
JS_ValueToNumber
Obsolete since JSAPI 24This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Replaced by JS::ToNumber. Convert any JavaScript value to a floating-point number of type jsdouble. Syntax JSBool JS_ValueToNumber(
JSContext *cx, jsval v, jsdouble *dp); Name Type Description cx
JSContext * The context in which to perform the conversion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. v jsval The value to convert. dp jsdouble * Out parameter. On success, *dp receives the converted floating-point value. Description JS_ValueToNumber converts a JavaScript value to a number. It implem...
JS_YieldRequest
Obsolete since JSAPI 18This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. Momentarily suspend the current JSAPI request, allowing garbage collection to run if another thread has requested it. Syntax void JS_YieldRequest(
JSContext *cx); Name Type Description cx
JSContext * The
JSContext that is currently in a request on the calling thread. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this
JSContext. Description For more information about thread safety and requests, see JS_THREADSAFE. JS_YieldRequest momentarily suspends the current request. A program can call this function periodically to ensure that a long-r...
JS_updateMallocCounter
nbytes size_t Number of bytes to decrement from malloc counter. Description JS_updateMallocCounter decrements malloc counter of GC and the zone of the context. Malloc counter measures memory pressure for GC scheduling. It runs from maxMallocBytes down to zero. ...
SpiderMonkey 1.8.8
been removed from the JSCLass Prototype. JSClass Callback changes Many of the JSClass callbacks such as JSResolveOP, JSEnumerateOp and JSPropertyOp, have a type change on their arguments to JSHandleObject, JSHandleId, JSHandleMutableObject etc. Atleast for the C API this wraps an extra pointer around these objects, so you would cast the argument to JSObject**, in the callback function. Removal of
JSContext* parameters to many methods The JS_GetClass method now takes only a JSObject*, where previously it also required a
JSContext* in threadsafe builds. (The JS_GET_CLASS macro abstracting away this difference has accordingly been removed.) JavaScript shell changes Detail added/removed methods here... Known Issues Detail any known issues here... Future Direction INCLUDE-FOLLOWUP-ON-EXPERIMENTAL-LIBRA...
SpiderMonkey 17
been removed from the JSCLass Prototype. JSClass Callback changes Many of the JSClass callbacks such as JSResolveOP, JSEnumerateOp and JSPropertyOp, have a type change on their arguments to JSHandleObject, JSHandleId, JSHandleMutableObject etc. Atleast for the C API this wraps an extra pointer around these objects, so you would cast the argument to JSObject**, in the callback function. Removal of
JSContext* parameters to many methods The JS_GetClass method now takes only a JSObject*, where previously it also required a
JSContext* in threadsafe builds. (The JS_GET_CLASS macro abstracting away this difference has accordingly been removed.) Garbage Collection functions now take runtime argument Most garbage collection functions now take a runtime argument instead of a context. The one exception to th...
SpiderMonkey 45
plicit JS_AddWeakPointerCallback is replaced with JS_AddWeakPointerZoneGroupCallback and JS_AddWeakPointerCompartmentCallback JS_RemoveWeakPointerCallback is replaced with JS_RemoveWeakPointerZoneGroupCallback and JS_RemoveWeakPointerCompartmentCallback API changes JavaScript shell changes Detail added/removed methods here... Known Issues Detail any known issues here... Future Direction
JSContext and JSRuntime are merging. (
JSContext will be the only thing visible from within the API, there will be just one per runtime, and inheriting from JSRuntime.) SpiderMonkey embedders should be aware that Mozilla has no plans to keep the JSAPI stable for embedders. We have instead chosen to concentrate on overall performance and accuracy as our primary concerns. Release Notes Errata Feel free to ...
Split object
window.navigator, are intentionally parented to the outer window object using such APIs.) To enforce this rule: APIs that allow the caller to pass a scope object always check that object first and fail if any outer objects are on its scope chain. In the spirit of this rule, JS_GetScopeChain should always return an inner object. But there is a special case when JS_GetScopeChain is called on a
JSContext in which no code is currently running. By convention, the context's global object is returned in this case. For consistency with the rule, if that global object is an outer object, SpiderMonkey returns the inner object instead. Inner and outer objects are in certain other respects the same object: If Object.hasOwnProperty is called on an inner object, and the named property is found on an oute...
Secure Development Guidelines
newchars = (jschar *) JS_malloc(cx, (newlength + 1) * sizeof(jschar)); ... for (i = 0, ni = 0; i < length; i++) { if ((ch = chars[i]) < 128 && IS_OK(ch, mask)) { newchars[ni++] = ch; ... } ... } ... } Integer Overflows/Underflows: Prevention Difficult to fix: Y...
XPCOM hashtable guide
can put it all together. A few examples: A hashtable that maps UTF-8 origin names to a DOM Window - nsInterfaceHashtable<nsCStringHashKey, nsIDOMWindow> A hashtable that maps 32 bit integers to floats - nsDataHashtable<nsUint32HashKey, float> A hashtable that maps nsISupports pointers to reference counted CacheEntrys - nsRefPtrHashtable<nsISupportsHashKey, CacheEntry> A hashtable that maps
JSContext pointers to a ContextInfo struct - nsClassHashtable<nsPtrHashKey<
JSContext>, ContextInfo> A hashset of strings - nsTHashtable<nsStringHashKey> Hashtable API The hashtable classes all expose the same basic API. There are three key methods, Get, Put, and Remove, which retrieve entries from the hashtable, write entries into the hashtable, and remove entries from the hashtable respectively. The...
IJSDebugger
ctly use this service; instead, you should use the JavaScript code module that does this for you. The only time you should directly use this interface to create the Debugger object is if you need to debug chrome; due to bug 707237, the JavaScript code module doesn't work in that case. See the JavaScript Debugger API Guide for details on using the Debugger API. Method overview [implicit_
jscontext] void addClass(); Methods addClass() Defines the global Debugger constructor. On return, the Debugger object has been added to the global context. [implicit_
jscontext] void addClass(); Parameters None. See also JS Debugger API Reference JS Debugger API Guide ...
inIDOMUtils
Implemented by: @mozilla.org/inspector/dom-utils;1 as a service: var inIDOMUtils = Components.classes["@mozilla.org/inspector/dom-utils;1"] .getService(Components.interfaces.inIDOMUtils); Method overview void addPseudoClassLock(in nsIDOMElement aElement, in DOMString aPseudoClass); void clearPseudoClassLocks(in nsIDOMElement aElement); [implicit_
jscontext] jsval colorNameToRGB(in DOMString aColorName); nsIArray getBindingURLs(in nsIDOMElement aElement); nsIDOMNodeList getChildrenForNode(in nsIDOMNode aNode, in boolean aShowingAnonymousContent); unsigned long long getContentState(in nsIDOMElement aElement); void getCSSPropertyNames([optional] in unsigned long aFlags, [optional] out unsigned long aCount, [retval,...
nsIDOMHTMLAudioElement
s used to implement the HTML5 <audio> element. dom/interfaces/html/nsIDOMHTMLAudioElement.idlScriptable Please add a summary to this article. Last changed in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) Inherits from: nsIDOMHTMLMediaElement Method overview unsigned long long mozCurrentSampleOffset(); void mozSetup(in PRUint32 channels, in PRUint32 rate); [implicit_
jscontext] unsigned long mozWriteAudio(in jsval data); Methods mozCurrentSampleOffset() Non-standard This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future. Returns the current offset...
Debugger.Memory - Firefox Developer Tools
C_TRIGGER" "DESTROY_RUNTIME" "LAST_DITCH" "TOO_MUCH_MALLOC" "ALLOC_TRIGGER" "DEBUG_GC" "COMPARTMENT_REVIVED" "RESET" "OUT_OF_NURSERY" "EVICT_NURSERY" "FULL_STORE_BUFFER" "SHARED_MEMORY_LIMIT" "PERIODIC_FULL_GC" "INCREMENTAL_TOO_SLOW" "DOM_WINDOW_UTILS" "COMPONENT_UTILS" "MEM_PRESSURE" "CC_WAITING" "CC_FORCED" "LOAD_END" "PAGE_HIDE" "NS
JSCONTEXT_DESTROY" "SET_NEW_DOCUMENT" "SET_DOC_SHELL" "DOM_UTILS" "DOM_IPC" "DOM_WORKER" "INTER_SLICE_GC" "REFRESH_FRAME" "FULL_GC_TIMER" "SHUTDOWN_CC" "USER_INACTIVE" nonincrementalReason If SpiderMonkey's collector determined it could not incrementally collect garbage, and had to do a full GC all at once, this is a short string describing the reason it determine...