Search completed in 1.29 seconds.
JSObject - Archive of obsolete content
Summary The public final class netscape.javascript.
JSObject extends Object. java.lang.Object | +----netscape.javascript.
JSObject Description JavaScript objects are wrapped in an instance of the class netscape.javascript.
JSObject and passed to Java.
JSObject allows Java to manipulate JavaScript objects. When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type
JSObject; when a
JSObject is sent from Java to JavaScript, the runtime engine unwraps it to its original JavaScript object type. The
JSObject class provides a way to invoke JavaScript methods and examine JavaScript properties. Any JavaScript data brought into Java is converted to Java data types. ...
...When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type
JSObject; when a
JSObject is sent from Java to JavaScript, the runtime engine unwraps it to its original JavaScript object type. The
JSObject class provides a way to invoke JavaScript methods and examine JavaScript properties. Any JavaScript data brought into Java is converted to Java data types. When the
JSObject is passed back to JavaScript, the object is unwrapped and can be used by JavaScript code. See the Core JavaScript 1.5 Guide for more information about data type conversions. Method Summary The netscape.javascript.
JSObject class has the following methods: call Calls a JavaScript method. equals Determines if two
JSObject objects refer to the same instance. (What's the problem with == ?
...cript expression. getMember Retrieves the value of a property of a JavaScript object. getSlot Retrieves the value of an array element of a JavaScript object. removeMember Removes a property of a JavaScript object. setMember Sets the value of a property of a JavaScript object. setSlot Sets the value of an array element of a JavaScript object. ...
...And 6 more matches
JSObjectOps.dropProperty
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. Warning! ...
...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. 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,...
...lback 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 JSProperty * The property to release. That is, the value that
JSObjectOps.lookupProperty hook stored in the *propp out parameter. Description The following contract governs
JSObjectOps callers and implementations: Whenever
JSObjectOps.lookupProperty returns a JSProperty pointer, the property is locked. While...
...And 4 more matches
JSObjectOps.newObjectMap
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. Warning! ...
...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. Warning! ...
...ged since 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.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 ...
...And 4 more matches
wrappedJSObject
wrapped
JSObject is a property sometimes available on XPConnect wrappers. When available, it lets you access the JavaScript object hidden by the wrapper. There are two kinds of XPConnect wrappers that support the wrapped
JSObject property: XPCNativeWrappers which are used to protect the chrome code working with content objects. See XPCNativeWrapper for detailed documentation. Regular XPConnect wrappers which you can encounter, for example, when using XPCOM components implemented in JS. This article focuses on the latter kind of wrappers, which hide any properties or methods on the component that are not part of the supported interfaces as declared in xpidl. The rest of this article demonstrates what XPConnect wrappers do and how wrapped
JSObject can be used to bypass them. Example co...
...r, for example, when using XPCOM components implemented in JS. This article focuses on the latter kind of wrappers, which hide any properties or methods on the component that are not part of the supported interfaces as declared in xpidl. The rest of this article demonstrates what XPConnect wrappers do and how wrapped
JSObject can be used to bypass them. Example component To see how the wrapped
JSObject property works, we need an example XPCOM component implemented in JS. See How to Build an XPCOM Component in Javascript for details on creating one. For simplicity we omit the component registration code. Suppose we register the component below with the @myself.com/my-component;1 contract. // constructor function HelloWorld() { }; HelloWorld.prototype = { hello: function() { return "Hell...
...Assuming the nsIHelloWorld interface defines the hello method, we can now call it: > comp.hello() Hello World! While this behavior is nice for production code as it forces you to clearly define the interfaces that should be used to access the component, it's inconvenient to write the interfaces (and recompile each time you change them) when working on a prototype of the component. Meet wrapped
JSObject XPConnect lets you bypass its wrappers and access the underlying JS object directly using the wrapper.wrapped
JSObject property if the wrapped object allows this. More specifically, as XPConnect source comments say, you can get comp.wrapped
JSObject if three conditions are met: comp really is an XPConnect wrapper around a JS object. Wrappers around non-JS objects don't have this property. The...
...And 3 more matches
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.
JSObjectOp is the type of several JSAPI callbacks that map an object to another object, or NULL if an error or exception occurred. ...
... 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.
JSObjectOp is the type of several JSAPI callbacks that map an object to another object, or NULL if an error or exception occurred. ...
... 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.
JSObjectOp is the type of several JSAPI callbacks that map an object to another object, or NULL if an error or exception occurred. ...
...And 2 more matches
JSObjectOps.lookupProperty
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. Warning! ...
....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. Warning! ...
...ved at any time. Try to avoid using it. Warning! ...
...And 2 more matches
JSObjectOps.setProto
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. Warning! ...
....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. Warning! ...
...PI 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. ...
...cks 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.setProto callback, and JSSLOT_PARENT for the
JSObjectOps.setParent callback. pobj
JSObject * The new prototype or parent object. Description These hooks must check for cycles without deadlocking, and otherwise take sp...
JSObjectOps.defaultValue
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. 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 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 JSObjec...
...bject *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. Description The
JSObjectOps.defaultValue callback corresponds to the [[DefaultValue]] method defined in ECMA 262-3 ?8.6.2.6. Many expressions in the ECMAScript language, such as a+b, involve implicit conversion of the operands using [[DefaultValue]]. The default [[DefaultValue]] behavior for ordinary objects is as described in ES5 ?8.12.8. It calls the JavaScript methods obj.valueOf() and/or obj.toString(). Provide a cu...
...efaultValue callback corresponds to the [[DefaultValue]] method defined in ECMA 262-3 ?8.6.2.6. Many expressions in the ECMAScript language, such as a+b, involve implicit conversion of the operands using [[DefaultValue]]. The default [[DefaultValue]] behavior for ordinary objects is as described in ES5 ?8.12.8. It calls the JavaScript methods obj.valueOf() and/or obj.toString(). Provide a custom
JSObjectOps.defaultValue callback to implement customized [[DefaultValue]] behavior. The JSClass.convert callback should convert obj to the given type, returning JS_TRUE with the resulting value in *vp on success, and returning JS_FALSE on error or exception. On success, *vp must be a primitive value: per ES5 ?8.12.8, every object "must ensure that its [[DefaultValue]] internal method can return only pri...
JSObjectOps.defineProperty
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. Warning! ...
....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. 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. ...
... id jsid The name or index of the property to define. value jsval The initial value for the new property. ...
JSObjectOps.getAttributes
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. 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. ...
... id jsid The name or index of the property whose attributes are being accessed. prop JSProperty * The property whose attributes are being accessed. This may be NULL. attrsp unsigned int * In/out parameter. See the Description section below. ...
...perty * The property whose attributes are being accessed. This may be NULL. attrsp unsigned int * In/out parameter. See the Description section below. Description Get or set attributes of the property obj[id]. Returns JS_FALSE on error or exception, else JS_TRUE with current attributes in *attrsp. If prop is non-null, it must come from the *propp out parameter of a prior
JSObjectOps.defineProperty or
JSObjectOps.lookupProperty call. For more information on property attributes, see JS_GetPropertyAttributes. ...
JSObjectOps.getRequiredSlot
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. Warning! ...
....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. Warning! ...
...rted 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 jsval The ...
JSObject
Objects are made up of the following parts: Most objects have a prototype. See JS_GetPrototype. An object inherits properties, including methods, from its prototype (which is another object). Most objects have a parent. See JS_GetParent. An object's parent is another object, usually either the global object or an object that represents an activation record. The JavaScript engine sometimes uses this relationship to implement lexical scoping. Security-sensitive applications can use this relationship to make every object a member of some security domain. Almost every object can have any number of its own properties. The term own property refers to a property of an object that is not inherited from its prototype. ...
...e every object a member of some security domain. Almost every object can have any number of its own properties. The term own property refers to a property of an object that is not inherited from its prototype. Each property has a name, a getter, a setter, and property attributes. Most properties also have a stored value. See JS_DefineProperty. Every object is associated with a JSClass and a
JSObjectOps. These are C/C++ hooks and metadata that govern various aspects of the object's behavior and describe its layout in memory. Depending on the JSClass, an object may have a private data pointer and any number of reserved slots. ...
JSObjectOps.getProperty
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. 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.
JSObjectOps.getProperty, setProperty, and deleteProperty are high-level callbacks that implement object property accesses. Each of these callbacks is responsible for everything involved with an individual property access operation, including: any locking necessary for thread safety; security checks; finding the property, including walking the prototype chain if needed; callin...
...he 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. Description Get, set, ...
JSObjectPrincipalsFinder
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.
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 watch...
...d to watch the currently executing script. Another example: when the Function constructor is called, the JavaScript engine calls the object principals finder callback to obtain principals for the local scope object, to check that the caller has access to that object. The two debugger functions JS_StackFramePrincipals and JS_EvalFramePrincipals also use this callback. Since it is very common for
JSObjectOps.checkAccess or JSClass.checkAccess hooks to call these functions, the object principals finder callback is a key security feature. The callback returns a pointer to the principals associated with obj, possibly via the immutable parent chain leading from obj to a top-level container (such as a window object in the DOM). If there are no principals associated with obj, return NULL. Therefore NUL...
JSObjectOps.destroyObjectMap
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. 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.enumerate
The type of the callback is JSNewEnumerateOp. For native objects, the enumerate callback first checks the JSCLASS_NEW_ENUMERATE flag of the object's class. If the flag is present, enumerate simply delegates the call to JSClass.enumerate. Otherwise, it invokes the JSClass.enumerate hook as an old-style JSEnumerateOp to give the object an opportunity to define any remaining lazy properties. ...
nsIXPConnect
2.1) To access the XPConnect 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(); nsIXPConnect
JSObjectHolder 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); vo...
... void flagSystemFilenamePrefix(in string aFilenamePrefix, in PRBool aWantNativeWrappers); void Garba...
...cals, 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 nsIXPConnect
JSObjectHolder sandbox, in PRBool returnStringOnly); Native code only! ...
...And 53 more matches
Index
e creates a JS::Value that represents the JavaScript value null. 56 JS::NumberValue JSAPI Reference, Reference, Reference(2), SpiderMonkey JS::NumberValue converts a C integer or floating-point value to JS::Value, the type of JavaScript values. 57 JS::ObjectOrNullValue JSAPI Reference, Reference, Reference(2), SpiderMonkey JS::ObjectValue converts a given
JSObject to JS::Value. If the pointer is null, it returns JavaScript null. The conversion always succeeds. 58 JS::ObjectValue JSAPI Reference, Reference, Reference(2), SpiderMonkey JS::ObjectValue converts a given
JSObject to JS::Value. The conversion always succeeds. 59 JS::OrdinaryToPrimitive JSAPI Reference, Reference, Reference(2), SpiderMonkey JS::OrdinaryToP...
... Reference, SpiderMonkey JSFunctionSpec defines the attributes for a single JS function to associate with an object. An application typically has an array of JSFunctionSpec to define all the functions for an object and calls JS_DefineFunctions or JS_InitClass to create the functions and assign them to an object. ...
... assign them to an object. 111 JSGetObjectOps JSAPI Reference, Obsolete, SpiderMonkey
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 and host objects have a
JSObjectMap at obj->map, which may be shared among a number of objects, and which contains the
JSObjectOps *ops pointer used to dispatch object operations from API calls. 112 JSHasInstanceOp JSAPI Reference, Reference, Reference(2), SpiderMonkey JSHasInstanceOp is called to check whether v is an instance of obj. Return false on error or exception, true on success with true in *bp if v...
...And 22 more matches
nsIXPCScriptable
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. ...
.... 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. ...
...ct/idl/nsIXPCScriptable.idlNot scriptable Please add a summary to this article. ...
...And 22 more matches
GC Rooting Guide
. Since SpiderMonkey has a moving GC, it is very important that it knows about each and every pointer to a GC thing in the system. SpiderMonkey's rooting API tries to make this task as simple as possible. What is a GC thing pointer? "GC thing" is the term used to refer to memory allocated and managed by the SpiderMonkey garbage collector. The main types of GC thing pointer are: JS::Value
JSObject* JSString* JSScript* jsid Note that JS::Value and jsid can contain pointers internally even though they are not a normal pointer type, hence their inclusion in this list. If you use these types directly, or create classes, structs or arrays that contain them, you must follow the rules set out in this guide. If you do not your program will not work correctly - if it works at all. GC things...
...re the underlying pointer. JS::Rooted must be constructed with a JSContext*, and optionally an initial value. There are typedefs available for the main types. ...
... JS::Handle<T> All G...
...And 18 more matches
LiveConnect Overview - Archive of obsolete content
pper is an object of the target language data type that encloses an object of the source language. When programming in JavaScript, you can use a wrapper object to access methods and fields of the Java object; calling a method or accessing a property on the wrapper results in a call on the Java object. On the Java side, JavaScript objects are wrapped in an instance of the class netscape.javascript.
JSObject and passed to Java. When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type
JSObject; when a
JSObject is sent from Java to JavaScript, the runtime engine unwraps it to its original JavaScript object type. The
JSObject class provides an interface for invoking JavaScript methods and examining JavaScript properties. JavaScript to Java Communication When you refer ...
... instanceof java.io.FileNotFound) { // handling for FileNotFound } else { throw e; } } See Exception Handling Statements for more information about JavaScript exceptions. Java to JavaScript Communication If you want to use JavaScript objects in Java, you must import the netscape.javascript package into your Java file. This package defines the following classes: netscape.javascript.
JSObject allows Java code to access JavaScript methods and properties. netscape.javascript.JSException allows Java code to handle JavaScript errors. See the JavaScript Reference for more information about these classes. Locating the LiveConnect classes In older versions of the Netscape browser, these classes were distributed along with the browser. Starting with JavaScript 1.2, these classes are deliver...
...n about CLASSPATH. Note: Because Java is a strongly typed language and JavaScript is weakly typed, the JavaScript runtime engine converts argument values into the appropriate data types for the other language when you use LiveConnect. See Data Type Conversions for complete information. Using the LiveConnect Classes All JavaScript objects appear within Java code as instances of netscape.javascript.
JSObject. When you call a method in your Java code, you can pass it a JavaScript object as one of its argument. To do so, you must define the corresponding formal parameter of the method to be of type
JSObject. Also, any time you use JavaScript objects in your Java code, you should put the call to the JavaScript object inside a try...catch statement which handles exceptions of type netscape.javascript.JSE...
...And 11 more matches
WebIDL bindings
ouble double double double float float float float interface: non-nullable Foo& already_addRefed<Foo> Foo* OwningNonNull<Foo> interface: nullable Foo* already_addRefed<Foo> Foo* RefPtr<Foo> long int32_t int32_t int32_t long long int64_t int64_t int64_t object JS::Handle<
JSObject*> JS::MutableHandle<
JSObject*>
JSObject* octet uint8_t uint8_t uint8_t sequence const Sequence<T>& nsTArray<T>& (outparam) short int16_t int16_t int16_t unrestricted double double double double unrestricted float float float float unsigned long uint32_t uint32_t uint32_t uns...
... sequences, dictionaries, owning unions, and variadic arguments becomes nsCString. Nullable ByteString are represented by the same types as non-nullable ones, but the string will return true for IsVoid(). Returning null as a string value can be done using SetIsVoid() on the out param. object object is represented in three different ways, depending on use: object arguments become JS::Handle<
JSObject*>. They will be in the compartment of the passed-in JSContext. object return values become a JS::MutableHandle<
JSObject*> out param appended to the argument list. This comes after all IDL arguments, but before the ErrorResult&, if any, for the method. The return value is allowed to be in any compartment; bindings will wrap it into the context compartment as needed. object dictionary members a...
...The dictionary members and sequence elements are guaranteed to be marked by whoever puts the sequence or dictionary on the stack, using SequenceRooter and DictionaryRooter. Methods using object always get a JSContext* argument. ...
...And 11 more matches
JS_NewObject
Requires request. ...
...Requires request. ...
...Requires request. ...
...And 7 more matches
JSAPI reference
_GetExternalStringFinalizer Added in SpiderMonkey 17 JS_AddExternalStringFinalizer Obsolete since JSAPI 13 JS_RemoveExternalStringFinalizer Obsolete since JSAPI 13 JS_GetExternalStringGCType Obsolete since JSAPI 13 JS_NewExternalStringWithClosure Added in SpiderMonkey 6 Obsolete since JSAPI 13 JS_GetExternalStringClosure Added in SpiderMonkey 6 Obsolete since JSAPI 13 Objects typedef
JSObject JS_DefineObject JS_NewObject JS_NewPlainObject Added in SpiderMonkey 38 JS_NewObjectForConstructor Added in SpiderMonkey 1.8.5 JS_NewGlobalObject Added in SpiderMonkey 1.8 JS_NewObjectWithGivenProto JS_New Added in SpiderMonkey 1.8 JS_IsGlobalObject Added in JSAPI 24 JS_ConstructObject Obsolete since JSAPI 16 JS_ConstructObjectWithArguments Obsolete since JSAPI 16 JS_GetClass ...
... struct JSFunctionSpec struct JSPropertySpec JS_InitClass JS_LinkConstructorAndPrototype Added in SpiderMonkey 17 JS::PropertySpecNameIsSymbol Added in SpiderMonkey 38 JS::PropertySpecNameEqualsId Added in SpiderMonkey 38 JS::PropertySpecNameToPermanentId Added in SpiderMonkey 38 JS_GetReservedSlot JS_SetReservedSlot struct JSExtendedClass Obsolete since JavaScript 1.8.5 struct
JSObjectOps Obsolete since JavaScript 1.8.5 struct JSXMLObjectOps Obsolete since JavaScript 1.8.5 struct JSProperty Obsolete since JSAPI 16 Adding native properties and methods to classes: JSNative struct JSFunctionSpec JS_FS Added in SpiderMonkey 1.8 JS_FN Added in SpiderMonkey 1.8 JS_SYM_FN Added in SpiderMonkey 38 JS_FNINFO Added in SpiderMonkey 17 JS_SELF_HOSTED_FN Added in SpiderMonkey 3...
... SpiderMonkey 1.9.3 JS_ConvertStub Obsolete since JSAPI 37 JS_DeletePropertyStub Obsolete since JSAPI 37 JS_EnumerateStub Obsolete since JSAPI 37 JS_FinalizeStub Obsolete since JSAPI 15 JS_ResolveStub Obsolete since JSAPI 37 JSExtendedClass method types: In JS 1.8.5, JSExtendedClass has made private. ...
...And 7 more matches
platform/xpcom - Archive of obsolete content
f Unknown called HelloWorld that implements a function called hello. By creating a Factory and passing it the contract ID for the HelloWorld component and the HelloWorld constructor, we enable XPCOM clients to access the HelloWorld component, given its contract ID. ...
...ript only, so we use the technique documented under the "Using wrapped
JSObject" section of How to Build an XPCOM Component in JavaScript. ...
...If you don't specify a class ID, then the factory will generate one. Either way, it will be accessible as the value of the factory's id property. ...
...And 5 more matches
nsIJSON
stance, use: var nativeJSON = Components.classes["@mozilla.org/dom/json;1"] .createInstance(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. ...
...d 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. ...
... 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. ...
...And 5 more matches
JSAPI User Guide
ppear to be in use, and a JS::Value by itself does not protect its referent from the garbage collector. See Garbage collection below for crucial information on how to use JS::Values safely. JS::Value includes member functions to test the JavaScript data type. These are isObject(), isNumber(), isInt32(), isDouble(), isString(), isBoolean(), isNull(), and isUndefined(). ...
... Garbage collection As it runs, JavaScript code implicitly allocates memory for objects, strings, variables, and so on. ...
... can cast it to its underlying data type using the toObject(), toDouble(), and toString() member functions, respectively. This is useful in some cases where your application or a JSAPI function requires a variable or argument of a specific data type, rather than a JS::Value. Similarly, you can create a JS::Value wrapping a
JSObject, double, or JSString pointer to a JS::Value using JS::ObjectValue(
JSObject&), JS::DoubleValue(double), or JS::StringValue(JSString*). Garbage collection As it runs, JavaScript code implicitly allocates memory for objects, strings, variables, and so on. Garbage collection is the process by which the JavaScript engine detects when those pieces of memory are no longer reachable--that is, they could not possibly ever be used again--and reclaims the memory. Garbage colle...
...And 4 more matches
JavaScript-DOM Prototypes in Mozilla
Prototype setup on an XPConnect wrapped DOM node in Mozilla When a DOM node is accessed from JavaScript in Mozilla, the native C++ DOM node is wrapped using XPConnect and the wrapper is exposed to JavaScript as the JavaScript representation of the DOM node. When XPConnect wraps a C++ object it will create a
JSObject that is unique to this C++ object. ...
...XPConnect wrapped DOM node in Mozilla When a DOM node is accessed from JavaScript in Mozilla, the native C++ DOM node is wrapped using XPConnect and the wrapper is exposed to JavaScript as the JavaScript representation of the DOM node. When XPConnect wraps a C++ object it will create a
JSObject that is unique to this C++ object. In the case where the C++ object has class info (nsIClassInfo), the
JSObject is a more or less empty
JSObject which is not really that special. All the methods that are supposed to show up on this
JSObject are actually not properties of the object itself, but rather properties of the prototype of the
JSObject for the wrapper (unless the C++ object's class info has the flag nsIXPCScriptable::DONT_SHARE_PROTOTYPE set, but lets assume that's not the case here). As an exampl...
...object itself, but rather properties of the prototype of the
JSObject for the wrapper (unless the C++ object's class info has the flag nsIXPCScriptable::DONT_SHARE_PROTOTYPE set, but lets assume that's not the case here). As an example of this let's look at an HTML image element in a document. var obj = document.images[0]; Here, obj will not really have any properties (except for the standard
JSObject properties such as constructor, and the non-standard __parent__, __proto__, etc.), all the DOM functionality of obj comes from obj's prototype (obj.__proto__) that XPConnect sets up when exposing the first image in document to JavaScript. Here are a few of the properties of obj's prototype: obj.__proto__ parentNode (getter Function) src (getter and setter Functions) getElementsByTagName (F...
...And 3 more matches
JS::Value
The different representations are visible using the separate int32/double methods but do not affect observable semantic...
...The different representations are visible using the separate int32/double methods but do not affect observable semantics (ignoring performance). The number m...
...The different representations are visible using the separate int32/double methods but do not affect observable semantics (ignoring performance). The number mutators attempt to use int32_t representation ...
...And 3 more matches
GCIntegration - SpiderMonkey Redirect 1
of changes that happen in the future. Avoid having C++ objects that point to JS objects (unless it's just to their own wrapper--that's okay). It's safe for JS objects to point to other JS objects or to C++ objects. If there is a choice between storing a GC thing inside a C++ object or its JS corresponding representation, prefer to store it in the JS representation. Never store GC things in a
JSObject's private pointer (i.e., via JS_SetPrivate()). It's better to store them in reserved slots, since those will automatically be traced if the object is native. As much as possible, avoid trace hooks. If objects are structured as described above, there should be no need for them. This should be obvious by now, but never ever allow a GC thing point to a GC thing in a different compartment unless it...
...ries, then it probably requires a write barrier. Before the pointer is modified (except initializing writes, which don't need a barrier), you should call IncrementalReferenceBarrier() or IncrementalValueBarrier(), passing it the value the pointer held before the write. There are several examples of this usage in XPConnect. The js::ObjectPtr class is intended to serve as a drop-in replacement for
JSObject *. It has an assignment operator that automatically invokes a write barrier. So far, though, there hasn't been much use for this class--there aren't many places outside of SpiderMonkey where a write barrier is required. Read barriers "Weak pointers" are a major complication to the scheme described above. For the purposes of this article, a weak pointer is one that is not traced during GC. At th...
... some code has read the weak pointer to C and then created a regular (strong) reference from B to C. Now C is reachable, but it won't be marked because B was already fully marked. No write barrier is invoked when creating the pointer from B to C because no pointer is being destroyed. As a concrete example of this, imagine that we call GetWrapper() on an nsWrapperCache instance. This will return a
JSObject *. Then this pointer is installed as a property on another
JSObject that was already marked. The solution to this problem is to require a read barrier on every weak reference. Whenever the weak pointer is read during incremental marking, we mark the object that it points to. In the example above, C would be marked when reading it out of A. A very simple way to identify weak pointers is to look ...
...And 2 more matches
JS::ObjectOrNullValue
If the pointer is null, it returns JavaScript null. The conversion always succeeds. ...
...If the pointer is null, it returns JavaScript null. The conversion always succeeds. ...
...If the pointer is null, it returns JavaScript null. The conversion always succeeds. ...
...And 2 more matches
JS::ObjectValue
The conversion always succeeds. ...
...The conversion always succeeds. ...
...The conversion always succeeds. ...
...And 2 more matches
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 a...
...e 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 and host objects have a
JSObjectMap at obj->map, which may be shared among a number of objects, and which contains the
JSObjectOps *ops pointer used to dispatch object operations from API calls. ...
...tions 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 and host objects have a
JSObjectMap at obj->map, which may be shared among a number of objects, and which contains the
JSObjectOps *ops pointer used to dispatch object operations from API calls. Thus JSClass (which pre-dates
JSObjectOps in the API) provides a low-level interface to class-specific code and data, while
JSObjectOps allows for a higher level of operation, which does not use the object's class except to find the class's
JSObjectOps struct, by calling clasp->getObjectOps, and to finalize the object. If this seems backwards, that's because it is! API compatibility requires a JSClass *clasp parameter to JS_NewObject,...
...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. ...
...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. ...
...script for execution. ...
...And 2 more matches
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. ...
...s discouraged since it could be removed at any time. Try to avoid using it. Retrieve the attributes, getter, and setter of a specified property. ...
...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. ...
...And 2 more matches
JS_GetReservedSlot
index uint32_t Index of the reserved slot to access. v JS::Value (in JS_SetReservedSlot) The value to store. ...
... index uint32_t Index of the reserved slot to access. v JS::Value (in JS_SetReservedSlot) The value to store. ...
... index uint32_t Index of the reserved slot to access. v JS::Value (in JS_SetReservedSlot) The value to store. ...
...And 2 more matches
How to build an XPCOM component in JavaScript
If not // provided, the ...
...rofile directory. Restart application. For Firefox: Copy HelloWorld.js, and HelloWorld.xpt (only if you defined and compiled the IDL) to the {objdir}/dist/bin/components directory, if running from the source. Delete compreg.dat and xpti.dat from the components directory. Delete compreg.dat and xpti.dat from your profile directory. Restart application. ...
... running from the source. Delete compreg.dat and xpti.dat from the components directory. Delete compreg.dat and xpti.dat from your profile directory. Restart application. Using Your Component Using wrapped
JSObject If you only intend to access your component from JavaScript, i.e. ...
...And 2 more matches
Interfacing with the XPCOM cycle collector
rough those fields. The main macro for Traverse is NS_IMPL_CYCLE_COLLECTION_TRAVERSE: NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSomeMember) Unlink works similarly: NS_IMPL_CYCLE_COLLECTION_UNLINK(mSomeMember) These macros should handle a variety of cases, such as reference counted pointers to cycle collected nsISupports or non-nsISupports objects, as well as arrays of these pointers. Handling
JSObjects fields If your class needs to store a pointer to a
JSObject then you need to tell the cycle collector about it. The approach you should take is as follows. Firstly it must be held in a JS::Heap<
JSObject *> field. For example, suppose your class nsFoo has field mSomeObj: private: ... JS::Heap<
JSObject*> mSomeObj; ... When you have something in the JS object pointer you need to use mozi...
... In the Unlink method (or destructor) you need to set the object pointer to NULL: NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsFoo) ... NS_IMPL_CYCLE_COLLECTION_UNLINK(mSomeMember) ... ...
... In the Unlink method (or destructor) you need to set the object pointer to NULL: NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsFoo) ... NS_IMPL_CYCLE_COLLECTION_UNLINK(mSomeMember) ... ...
...And 2 more matches
JSAPI Cookbook
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. But in a JSNative the correct way to do this is: /* JSAPI */ bool myNative(JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
JSObject *global = JS_GetGlobalForObject(cx, &args.callee()); ... } Defining a function // JavaScript function justForFun() { return null; } /* JSAPI */ bool justForFun(JSContext *cx, unsigned argc, JS::Value *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); args.rval().setNull(); return true; } ... /* * Add this to your JSContext setup code. * This makes your C functio...
... properties to the line of JavaScript code currently at the top of the stack. This is usually the line of code that called your native function, so it's usually what you want. ...
...tate savedState(cx); if (!JS_CallFunctionName(cx, global, "cleanup", 0, NULL, &r)) { /* The new error replaces the previous one, so discard the saved exception state. */ savedState.drop(); return false; } return success; Object properties Getting a property // JavaScript var x = y.myprop; The JSAPI function that does this is JS_GetProperty. It requires a
JSObject * argument. Since JavaScript values are usually stored in JS::Value variables, a cast or conversion is usually needed. In cases where it is certain that y is an object (that is, not a boolean, number, string, null, or undefined), this is fairly straightforward. Use JSVAL_TO_OBJECT to cast y to type
JSObject *. /* JSAPI */ JS::RootedValue x(cx); assert(y.isObject()); JS::RootedObject yobj(cx, &...
...ENUMERATE)) { return false; } Working with the prototype chain Defining a native read-only property on the String.prototype // JavaScript Object.defineProperty(String.prototype, "md5sum", {get: GetMD5Func, enumerable: true}); The following trick couldn't work if someone has replaced the global String object with something. /* JSAPI */
JSObject *string;
JSObject *string_prototype; JS::Value val; // Get the String constructor from the global object. if (!JS_GetProperty(cx, global, "String", &val)) return false; if (JSVAL_IS_PRIMITIVE(val)) return ThrowError(cx, global, "String is not an object", __FILE__, __LINE__); string = JSVAL_TO_OBJECT(val); // Get String.prototype. if (!JS_GetProperty(cx, string, "prototype", &val)) r...
JS::Add*Root
erMonkey 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. ...
...Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. rt JSRuntime * T...
...ontext in which to add the new root. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. rt JSRuntime * The runtime in which to add the new root. vp JS::Heap<JS::Value> The address of the JS::Value variable to root. rp JS::Heap<JSString *> The address of the JSString * variable to root. rp JS::Heap<
JSObject *> The address of the
JSObject * variable to root. rp JS::Heap<JSScript *> The address of the JSScript * variable to root. name const char * The name of the new root, or NULL. Description The JS::Add*Root and functions add a C/C++ variable to the garbage collector's root set, the set of variables used as starting points each time the collector checks to se...
...lector's root set, the set of variables used as starting points each time the collector checks to see what memory is reachable. The garbage collector aggressively collects and recycles memory that it deems unreachable, so roots are often necessary to protect data from being prematurely collected. vp/rp is the address of a C/C++ variable (or field, or array element) of type JS::Value, JSString *,
JSObject *, or JSScript *. This variable must already be initialized. (For example, it must not be an uninitialized local variable. That could cause sporadic crashes during garbage collection, which can be hard to debug.) The variable must remain in memory until the balancing call to JS::Remove*Root. Note that this means that if the root is meant to live past the end of a function, the address of a local ...
JS::CompileOptions
scripts and passed back in JSErrorReports. const char *filename() const Returns filename of the source code. const char *introducerFilename() const Returns filename of the file which introduces the file. const char16_t *sourceMapURL() const Returns the URL of the source map. Methods of JS::OwningCompileOptions Method Description
JSObject *element() const Returns the DOM element to which this source code belongs, if any, or NULL if it belongs to no DOM element. Source belongs to a DOM element in the following cases: Source belongs to a <script> element if it is the element's text content (that is, it is written out as the body of the <script> element in the markup text), or is the source document referenced by i...
...ull-terminated string s for sourceMapURL. Returns false if it failed to duplicate. bool setIntroducerFilename(JSContext *cx, const char *s) Duplicate null-terminated string s for introducerFilename. Returns false if it failed to duplicate. OwningCompileOptions &setLine(unsigned l) Sets each property and returns the instance itself. ...
...introducerFn, const char *intro, unsigned line, JSScript *script, uint32_t offset) Duplicate null-terminated string introducerFn for introducerFilename and set introductionType, introductionLineno, introductionScriptRoot, introductionOffset, and hasIntroductionInfo properties. Returns false if it failed to duplicate. Methods of JS::CompileOptions Method Description
JSObject *element() const Same as JS::OwningCompileOptions. JSString *elementAttributeName() const JSScript *introductionScript() const CompileOptions &setFile(const char *f) Sets each property and returns the instance itself. CompileOptions &setLine(unsigned l) CompileOptions &setFileAndLine(const char *f, unsigned l) CompileOptions &setSourceMa...
... JSString *elementAttributeName() const JSScript *introductionScript() const CompileOptions &setFile(const char *f) Sets each property and returns the instance itself. ...
JS_Add*Root
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. ...
...Requires request. ...
...xt * The context in which to add the new root. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. vp jsval * (In JS_AddValueRoot and JS_AddNamedValueRoot) The address of the jsval variable to root spp JSString ** (In JS_AddStringRoot and JS_AddNamedStringRoot) The address of the JSString* variable to root opp
JSObject ** (In JS_AddObjectRoot and JS_AddNamedObjectRoot) The address of the
JSObject* variable to root rp void ** (In JS_AddGCThingRoot and JS_AddNamedGCThingRoot) The address of the JSString* or
JSObject* (not jsval) variable to root name const char * (in JS_AddNamedRoot and JS_AddNamedRootRT) The name of the new root, or NULL. Description The JS_Add*Root and f...
...collector's root set, the set of variables used as starting points each time the collector checks to see what memory is reachable. The garbage collector aggressively collects and recycles memory that it deems unreachable, so roots are often necessary to protect data from being prematurely collected. vp/spp/opp/rp is the address of a C/C++ variable (or field, or array element) of type JSString *,
JSObject *, or jsval. This variable must already be initialized. (For example, it must not be an uninitialized local variable. That could cause sporadic crashes during garbage collection, which can be hard to debug.) The variable must remain in memory until the balancing call to JS_RemoveRoot. Note that this means that if the root is meant to live past the end of a function, the address of a local (stack-...
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...
... 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 request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. 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. namelen size_t (in JS_AlreadyHasOwnUCProperty only) The length of name, in characters; or the special value (size_t) -1 to indicate that name is null...
...-terminated. index uint32_t (in JS_AlreadyHasOwnElement only) The index of the element to search for. foundp bool * Out parameter. *foundp receives true if the property is found or false if it is not found. If an error occurs, the value left in *foundp is undefined. Description These functions attempt to determine whether a property already exists on a specific
JSObject without modifying the object. By design, this search may not find a property that other property lookup functions, such as JS_LookupProperty, would find. For native objects--objects whose properties are stored in the default data structure provided by SpiderMonkey--these functions simply check that data structure to see if the specified field is present. They do not search anywhere else for the p...
...s is the only API that can directly detect that a lazily resolved property has not yet been resolved.) Shared, permanent, delegated properties are not found. (Such properties are an implementation detail of SpiderMonkey. They are meant to be a transparent optimization; this is the only API that breaks the abstraction.) For non-native objects, this falls back on a complete search. This calls the
JSObjectOps.lookupProperty hook. *foundp is set to true only if lookupProperty reports that the property was found on obj itself and not on some other object (even the corresponding outer object, if any). If the property is found on obj, this sets *foundp to true and returns true. If the property is not found on obj, this sets *foundp to false and returns true (to indicate that no error occurred). If the ...
JS_DefineFunction
Create a native function and assign it as a property to a specified JS object. ...
... Create a native function and assign it as a property to a specified JS object. ...
...t *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. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
... 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. Added in SpiderMonkey 17 call JSNative The native C/C++ function to be wrapped by the new function. ...
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. ...
... its use is discouraged since it could be removed at any time. Try to avoid using it. Compile and execute a security-enabled script. ...
...t *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); ...
...This parameter is documented in detail at JS_ExecuteScript. principals JSPrincipals * Pointer to the structure holding the security information for this script. src / bytes / chars const char * or const jschar String containing the script to compile and execute. ...
JS_GetClass
The JS_GET_CLASS(cx, obj) macro abstracted away this detail. Newer versions have removed the context argument, so that the same signature is used regardless whether or not the build is thread-safe. ...
... The JS_GET_CLASS(cx, obj) macro abstracted away this detail. Newer versions have removed the context argument, so that the same signature is used regardless whether or not the build is thread-safe. ...
... The JS_GET_CLASS(cx, obj) macro abstracted away this detail. Newer versions have removed the context argument, so that the same signature is used regardless whether or not the build is thread-safe. ...
... The JS_GET_CLASS(cx, obj) macro abstracted away this detail. Newer versions have removed the context argument, so that the same signature is used regardless whether or not the build is thread-safe. Description JS_GetClass returns a pointer to the JSClass associated with a specified JS object, obj. The application must treat the JSClass as read-only. If obj has no JSClass, this returns NULL. ...
JS_NewRegExpObject
Requires request. ...
...Requires request. ...
...Requires request. ...
...Requires request. ...
Mozilla DOM Hacking Guide
nfo are twofold: Interface flattening, and implementing behaviors that are not possible with IDL alone. A brief introduction to JavaScript and XPConnect. Before we begin the explanation of Class Info, I'd like to introduce quickly the JavaScript engine and XPConnect. In JavaScript, there is no knowledge of types, like there is in C++. A function for example can be represented by a JSFunction, a
JSObject, a jsval, ... This means that when we use the DOM from JavaScript, we pass arguments that have no type. However, since the DOM is coded in C++, we expect to receive an argument of the correct type for our function. This is one of the jobs of XPConnect. XPConnect will "wrap" the argument in a wrapper that will be of the type expected by our C++ function. Similarly, then return type of the C++ func...
... 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 sIsInitialized to true, to remember that the initialization has been performed. The implementation i...
...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) { ... }: help ...
Garbage collection
paction. Much of the GC work is performed on helper threads. Principal data structures Cell A Cell is the unit of memory that is allocated and collected by the GC, as used externally. In other words, from the point of view of the rest of the engine, the job of the GC is to allocate cells and automatically collect them. Cell is the base class for all classes that are allocated by the GC, e.g.,
JSObject. Allocation Kind Cells are classified by allocation kind. The allocation kind determines the size of the object and the finalization behavior. Allocation kind is defined by enum AllocKind. Arenas always hold objects of the same allocation kind. Thus, an arena holds objects all of the same size and finalization behavior. Compartments The JS heap is partitioned into compartments. Some key prop...
...he weak ref will be marked. Implementation details Write barriers have a runtime cost, so SpiderMonkey tries to skip them when an incremental GC cycle is not active. Each Zone has a flag needsIncrementalBarrier() that indicates whether barriers are required. For each type T such that fields of type T* need a write barrier, there is a functionT::writeBarrierPre(old). For example, fields of type
JSObject* need a write barrier, so there is a function
JSObject::writeBarrierPre(
JSObject* old). If zone->needsIncrementalBarrier(), then writeBarrierPre() marks old. That's it. The class Heap<T> is provided to make it easy to invoke write barriers. A Heap<T> encapsulates a T* and invokes the write barrier whenever assigned to. Thus, object fields of GC-pointer type should normally be defined as type Hea...
... of GC-pointer type should normally be defined as type Heap<T>. The class HeapValue does the same thing for Value. HeapSlot (and the related class HeapSlotArray) is the same, but for object slots. HeapId is the same, but for jsid. Object private fields must be handled specially. The private field itself is opaque to the engine, but it may point to things that need to be marked, e.g., an array of
JSObject pointers. In this example, if the private field is overwritten, the
JSObject pointers could be 'lost', so a write barrier must be invoked to mark them. js::NativeObject::privateWriteBarrierPre takes care of this by invoking the
JSObject's class trace hook before the private field is set. Another detail is that write barriers can be skipped when initializing fields of newly allocated objects, bec...
Invariants
or, "The Zen of SpiderMonkey". A native object must never become non-native. (One reason for this is that the object may have watchpoints set; the watchpoint machinery assumes that all objects with watched properties are native. There may be other reasons that cover more cases, but nobody can remember one.) All
JSObjects and heap-allocated JSStrings must be 8-byte-aligned. (The jsval encoding depends on this.) The JSStackFrame::down chain never forms a cycle. (It's a stack. But note that a stack frame is not necessarily newer than the next stack frame down, thanks to generators!) An object's scope chain (found by chasing
JSObject::fslots[JSSLOT_PARENT]) never forms a cycle. (We can probably loop forever if that happens. JS_SetParent can violate this, if the application is really that dumb...
...ment == script->compartment. But this is true only so long as we are actually in the interpreter or JIT code. A JSNative or other callback may move cx to another compartment, as long as it returns cx to the script's compartment before returning. A given trace-jit 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_ValidContex...
...s). No JSNative or other object-related callback ever runs at the same time as a finalizer for that object. Property locks Each thread may have a lock on at most one property at a time. (Nesting them would risk deadlock. JS_SetWatchPoint violates this rule.) Whether a property is locked, and which one, is static information for almost every line of code. The locking scheme is described under
JSObjectOps.dropProperty. (Note that the locking scheme applies to all objects and talks about properties being locked. As implemented for native objects, the locking is not really that fine-grained, but that is a transparent optimization as long as we follow the rules.) A thread holding a property lock never leaves or suspends the current request. With a few exceptions (known to brendan and probably js...
Property cache
he case of SHARED PERMANENT properties, this differs from the notion of "own property" seen by scripts via Object.prototype.hasOwnProperty. Shape Native objects have a shape, a 24-bit unsigned integer such that: Basic layout guarantee -- If at time t0 the object x has shape s and at time t1 the object y has shape s, and no shape-regenerating GC occurred, then y at t1 has the same JSClass,
JSObjectOps, prototype, and property specs as x had at t0. To be more precise regarding property specs, y's properties have the same names, getters, setters, property attributes, and slot offsets, and they are in the same order, as x's properties at t0. Furthermore, y at t1 has the same number of fixed slots that x had at t0, and either both have a slot array or neither does. (Informally: objects with the...
...t's parent; obj->freeslot, which can be different for same-shaped objects if they have a JSClass.reserveSlots hook (bug 535416); anything about the values of the object's own properties, beyond what the method guarantee and the branded object guarantee say about functions. In particular shape does not cover the types of property values; typically {a: "x"} and {a: 12} have the same shape. Both
JSObject::objShape and JSShape::shape are shape-ids.
JSObject::objShape tells an object's shape. The JSShape::shape field is there so that when a property is added to or removed from an object, the JS engine can change that object's shape to match other objects with the same properties. Shapes and GC. Occasionally, during garbage collection, all shape ids are regenerated (in order to recycle unused shape...
...cts with the same properties. Shapes and GC. Occasionally, during garbage collection, all shape ids are regenerated (in order to recycle unused shape ids so that we don't run out; see calls to js_RegenerateShapeForGC. This could end up changing the shape of every object, so the property cache and JIT cache are emptied when this happens. Unique shapes. An object may be given a unique shape using
JSObject::generateOwnShape. This is usually done in order to bump the shape of one object without affecting other objects that happen to have the same properties. For example, when sealing an object, we must somehow preserve the extensibility guarantee. We do this by giving the sealed object a unique shape. Branded objects. An object may be branded. The interpreter and JIT brand an object whenever they f...
JS::IsCallable
Description JS::IsCallable returns whether the given function object is callable. ...
... Description JS::IsCallable returns whether the given function object is callable. ...
... Description JS::IsCallable returns whether the given function object is callable. ...
JS::Remove*Root
tures 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. ...
...Requires request. ...
...JS::Heap<JS::Value> Address of the JS::Value variable to remove from the root set. This must have been passed to one of JS::AddValueRoot, JS::AddNamedValueRoot or JS::AddNamedValueRootRT. rp JS::Heap<JSString *> Address of the JSString * variable to remove from the root set. This must have been passed to either JS::AddStringRoot or JS::AddNamedStringRoot. rp JS::Heap<
JSObject *> Address of the
JSObject * variable to remove from the root set. This must have been passed to either JS::AddObjectRoot or JS::AddNamedObjectRoot. rp JS::Heap<JSScript *> Address of the JSScript * variable to remove from the root set. This must have been passed to JS::AddNamedScriptRoot. Description JS::Remove*Root removes the variable that rp points to from the garbag...
JSExtendedClass
ince it could be removed at any time. Try to avoid using it. JSExtendedClass is an extended version of JSClass with additional hooks. A C/C++ program can use a JSExtendedClass with the JS_InitClass and JS_NewObject APIs to create objects that have custom methods and properties implemented in C/C++. Syntax struct JSExtendedClass { JSClass base; JSEqualityOp equality;
JSObjectOp outerObject;
JSObjectOp innerObject; JSIteratorOp iteratorObject;// Added in SpiderMonkey 1.8
JSObjectOp wrappedObject; // Added in SpiderMonkey 1.8 ...and additional reserved fields. }; Name Type Description base JSClass The basic class information and callbacks for this class. This contains some required fields. ...
...derMonkey 1.8
JSObjectOp wrappedObject; // Added in SpiderMonkey 1.8 ...and additional reserved fields. }; Name Type Description base JSClass The basic class information and callbacks for this class. This contains some required fields. equality JSEqualityOp Optional. Overrides the JavaScript == and != operators. outerObject
JSObjectOp Optional. Return the current outer object. This is used to implement split objects. innerObject
JSObjectOp Optional. Return the current inner object. This is used to implement split objects. iteratorObject JSIteratorOp Added in SpiderMonkey 1.8 Optional. Creates and returns a new iterator. ...
...If non-null, an object of this class may serve as a wrapper for another object. Wrappers sometimes transparently behave like the object they wrap. For example, an object and its wrappers are all equal under ===. ...
JSFinalizeOp
Description The JSFinalizeOp is analogous to Java finalizers or C++ destructors. The garbage collector calls this callback for each object it collects. ...
... Description The JSFinalizeOp is analogous to Java finalizers or C++ destructors. The garbage collector calls this callback for each object it collects. ...
...arbage collection. Any JSAPI call that would allocate memory from the GC heap will fail if called from a finalizer. For other ways to interact with garbage collection (e.g. implementing weak references), see JS_SetGCCallback. JSClass hooks JSClass offers the following hook: The JSClass.finalize callback is a hook for destructor code. The garbage collector calls the finalize hook of each
JSObject it collects. See Also MXR ID Search for JSFinalizeOp JSClass JS_SetGCCallback ...
JSVAL_TO_OBJECT
As a precondition, JSVAL_IS_OBJECT(v) must be true. That is, v must be either a reference to an object or JSVAL_NULL. ...
...As a precondition, JSVAL_IS_OBJECT(v) must be true. That is, v must be either a reference to an object or JSVAL_NULL. ...
...As a precondition, JSVAL_IS_OBJECT(v) must be true. That is, v must be either a reference to an object or JSVAL_NULL. ...
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. ...
...d 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 JSContext. ...
...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 JSContext. obj
JSObject * Object with which the function is to be associated. principals JSPrincipals * Pointer to the structure holding the security information for this function. 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 argumen...
JS_GetFunctionObject
Retrieves the object for a specified function. Syntax
JSObject * JS_GetFunctionObject(JSFunction *fun); Name Type Description fun JSFunction * Pointer to a JS function. fun should be a native function or JSAPI-compiled function. See below. Description JS_GetFunctionObject returns the JavaScript Function object for a specified function pointer, fun. fun must be either a function implemented by a JSNative (or JSFastNative) or the result of a call to JS_CompileFunction or similar functions. In other cases, the object returned by JS_GetFunctionObject is not necessarily safe to call and should not be exposed to script. In the JavaScript language, functions are objects. ...
...nction pointer, fun. fun must be either a function implemented by a JSNative (or JSFastNative) or the result of a call to JS_CompileFunction or similar functions. In other cases, the object returned by JS_GetFunctionObject is not necessarily safe to call and should not be exposed to script. In the JavaScript language, functions are objects. But in the JSAPI there are two separate concepts: a
JSObject is what is exposed to scripts and has properties and can be stored in variables; and the corresponding JSFunction contains the code of a function. For certain functions, the two have a strictly one-to-one relationship, and for those functions it is safe to call JS_GetFunctionObject to move from the JSFunction to the
JSObject. However, for other functions, and particularly for JavaScript closures...
...t is exposed to scripts and has properties and can be stored in variables; and the corresponding JSFunction contains the code of a function. For certain functions, the two have a strictly one-to-one relationship, and for those functions it is safe to call JS_GetFunctionObject to move from the JSFunction to the
JSObject. However, for other functions, and particularly for JavaScript closures, many
JSObjects may share the same JSFunction. In these cases, this function should not be called. Calling the
JSObject returned by it could cause a crash or worse. JS_GetFunctionObject always returns a pointer to an object. See Also MXR ID Search for JS_GetFunctionObject JS_CompileFunction ...
JS_GetParent
Description JS_GetParent retrieves the parent object of obj, or NULL if obj does not have a parent. Warning: The result may be an internal-use-only object. ...
... Description JS_GetParent retrieves the parent object of obj, or NULL if obj does not have a parent. Warning: The result may be an internal-use-only object. ...
... Description JS_GetParent retrieves the parent object of obj, or NULL if obj does not have a parent. Warning: The result may be an internal-use-only object. ...
JS_IsConstructing_PossiblyWithGivenThisObject
ll 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. ...
...ntax 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 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. JSBool foo_native(JSContext *cx, unsigned int arg...
...scription 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_IsNative
Description JS_IsNative returns true if the object is a native object. ...
... Description JS_IsNative returns true if the object is a native object. ...
... Description JS_IsNative returns true if the object is a native object. ...
JS_New
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
...Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
...Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
JS_NewFunction
Requires request. In a JS_THREADSAFE build, the caller mus...
...Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. call JSNative Native C/C++ implementation of this function. nargs unsigned Number of arguments t...
...ion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. call JSNative Native C/C++ implementation of this function. nargs unsigned Number of arguments the function expects. flags unsigned Pass JSFUN_CONSTRUCTOR to make a native that can be called as a constructor, otherwise 0. parent JS::Handle<
JSObject*> Pointer to the parent object for this function. If this is NULL, a default parent object is used. Obsolete since JSAPI 39 name const char * Name to assign to the new function. If this is NULL, the new function has no name. id JS::Handle<jsid> A pointer to jsid of the name to assign to the new function. Added in SpiderMonkey 17 Description JS_New...
JS_NewObjectForConstructor
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
...Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
...Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
Mozilla
ies can be found here. JavaScript Tips JavaScript-DOM Prototypes in Mozilla When a DOM node is accessed from JavaScript in Mozilla, the native C++ DOM node is wrapped using XPConnect and the wrapper is exposed to JavaScript as the JavaScript representation of the DOM node. ...
... When a DOM node is accessed from JavaScript in Mozilla, the native C++ DOM node is wrapped using XPConnect and the wrapper is exposed to JavaScript as the JavaScript representation of the DOM node. When XPConnect wraps a C++ object it will create a
JSObject that is unique to this C++ object. In the case where the C++ object has class info (nsIClassInfo), the
JSObject is a more or less empty
JSObject which is not really that special. ...
...he wrapper is exposed to JavaScript as the JavaScript representation of the DOM node. When XPConnect wraps a C++ object it will create a
JSObject that is unique to this C++ object. In the case where the C++ object has class info (nsIClassInfo), the
JSObject is a more or less empty
JSObject which is not really that special. All the methods that are supposed to show up on this
JSObject are actually not properties of the object itself, but rather properties of the prototype of the
JSObject for the wrapper (unless the C++ object's class info has the flag nsIXPCScriptable::DONT_SHARE_PROTOTYPE set, but lets assume that's not the case here). js-ctypes js-ctypes allows application and extension code to call back and forth to nati...
/loader - Archive of obsolete content
pecific loader. The SDK builds a higher level API on top of this for handling unloads and performing cleanup: let unloadSubject = require('@loader/unload'); let observerService = Cc['@mozilla.org/observer-service;1']. ...
...= Cc['@mozilla.org/observer-service;1']. getService(Ci.nsIObserverService); let observer = { observe: function onunload(subject, topic, reason) { // If this module is unloaded then `subject.wrapped
JSObject` will be // `unloadSubject`. `topic` will be `'sdk:loader:destroy'`, and // `reason` will be a string describing the reason (e.g. `'disable'`). if (subject.wrapped
JSObject === unloadSubject) console.log("I am about to unload, reason is " + reason); }}; observerService.addObserver(observer, 'sdk:loader:destroy', false); Unload The loader module exposes an unload() function that can be used to unload specific loader instance and undo changes made by modules loaded into it. unload takes loader as a first argument and optionally a reason string identifying the r...
Exact Stack Rooting
g a new property on the object. Class FooClass = { "FooPrototype", /* name */ JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(1), /* flags */ JS_PropertyStub, /* addProperty */ JS_PropertyStub, /* delProperty */ ... etc ... }; RootedObject obj(cx, NewObject(cx, &FooClass, NullPtr(), NullPtr(), &obj)); RootedValue v(cx, OBJECT_TO_VALUE(otherGCThing));
JSObject::SetReservedSlot(obj, 0, v); Storing a GCPointer on the CHeap TODO: Tracing and HeapPtr Storing a GCPointer on the CStack GCPointers stored on the CStack are special. Unlike other GCPointers, they are not traced as part of the GC. Instead, every pointer on the CStack should be considered part of the RootSet. To that end, we have a special "Rooting" mechanism for stack pointers that is very e...
...ions with MOZ_STACK_CLASS. Returning a js::HandleT from a function. If you do this, a handle may outlive its root. Definitions GC - Acronym for Garbage Collection: specifically SpiderMonkey's method of automatically managing JavaScript program memory. GCThing - Storage allocated by SpiderMonkey's allocator. GCPointer - A raw pointer type or tagged pointer type that may refer to a GCThing (
JSObject *, JSString *, Value, jsid, etc.) GCHeap - The graph of GCThings allocated by SpiderMonkey's allocator. The goal of SpiderMonkey's GC is to partition this heap into regions reachable from the RootSet and not. Root - A GCPointer held live because it is a member of the RootSet. RootSet - This is a set of GCPointers that are de-facto alive, regardless of the GCThing's reachability. GCPointers mus...
JS::CallArgs
Returns the i-th zero-indexed argument. JS::HandleValue get(unsigned i) const Returns the i-th zero-indexed argument, or undefined if there's no such argument. bool hasDefined(unsigned i) const Returns true if the i-th zero-indexed argument is present and is not undefined. Methods inherited from JS::detail::CallReceiverBase Method Description
JSObject &callee() const Returns the function being called, as an object. Must not be called after rval() has been used! JS::HandleValue calleev() const Returns the function 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...
...ol 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's always fine to access thisv(). HandleValue thisv = rec.thisv(); args.rval().set(JS::NumberValue(args.length() * args[0].toNumber())); // callee() and calleev() will now assert. return true; } See Also MXR ID Search for JS::CallArgs MXR ID Search for JS::CallArgsFromVp JS::Call bug 770586 ...
JS::CloneFunctionObject
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. funobj JS::HandleObject The Function to clone. ...
...Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. funobj JS::HandleObject The Function to clone. ...
JSClass
cess 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. ...
...c 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); return false; } JS_SetPrivate(cx, obj, p); args.rval().setObject(*obj); ...
JSFunction
ype in the JSAPI. The APIs JS_NewFunction, JS_DefineFunction, JS_CompileFunction, and their Unicode equivalents return values of type JSFunction *. For native functions and JSAPI-compiled functions - that is, functions returned by the APIs listed above-there is a simple one-to-one relationship between the JSFunction and the corresponding JavaScript Function object. To get a JSFunction * given the
JSObject * of a Function object, use JS_ValueToFunction. To get the
JSObject * given the JSFunction *, use JS_GetFunctionObject. For other function objects - that is, functions created by running JavaScript code containing function declarations or function-expressions-the relationship between the JSFunction * and the
JSObject * is not well-defined. Different closures (Function objects) generated from the ...
...Instead of using JS_CallFunction, for example, it must call JS_CallFunctionValue. Function objects created by calling JS_NewFunction have two reserved slots for the application's use. See JS_NewFunction for details. ...
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 reques...
...RT Check for permission to import the property. JSACC_WATCH Check for permission to place a watchpoint on the property. JSACC_READ Check for permission to get the property's value. JSACC_WRITE When bitwise-ORed with one of the above values, check for permission to write the property, not read it. The access check proceeds as follows. If obj has custom
JSObjectOps, the access check is delegated to the
JSObjectOps.checkAccess callback. Otherwise, if obj's class has a non-null JSClass.checkAccess callback, then it is called to perform the check. Otherwise, if a runtime-wide check-object-access callback has been installed by calling JS_SetCheckObjectAccessCallback, then that is called to perform the check. Otherwise, access is granted. On success, JS_Chec...
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 re...
... 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_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. ...
...Object *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 jschar * length size_t filename const char * lineno unsigned int version JSVersion Description Please provide a description. See A...
JS_ConstructObject
r the class, then to call it using 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, ...
...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 on this JSContext. 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. parent
JSObject * The object to serve as the new object's parent, or NULL. argc unsigned int (only in JS_ConstructObjectWithArguments) The number of arguments to pass to the constructor. argv jsval * (only in JS_ConstructObjectWithArguments) The array of arguments to pass to the construct...
JS_ConvertArguments
This conversion is dangerous and almost entirely useless, because the resulting JSFunction is not a real function object and therefore cannot be safely passed to any other JSAPI function. That includes JS_CallFunction() and JS_GetFunctionObject(). A JSFunct...
...argument is missing from argv, JS_ConvertArguments neither assigns anything to any variable nor reports an error. This function also takes in consideration any additional custom types defined on cx using JS_AddArgumentFormatter. For example, if format is "bIob", then JS_ConvertArguments converts the first JS value in argv into a bool, the second value into a double, the third value into a
JSObject *, and the last value into a bool. To skip a given argument, pass an asterisk in the corresponding position in format. If argc is less than the number of arguments required by format, JS_ConvertArgument reports an error and returns false. If argc is greater than the number of arguments described in format, the extraneous arguments are ignored. On success, JS_ConvertArgument returns true. If an...
JS_DeepFreezeObject
Description JS_DeepFreezeObject freezes obj, and all objects it refers to, recursively. ...
... Description JS_DeepFreezeObject freezes obj, and all objects it refers to, recursively. ...
JS_DefineElement
x, uint32_t value, unsigned attrs, JSNative getter = nullptr, JSNative setter = nullptr); bool JS_DefineElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double value, unsigned attrs, JSNative getter = nullptr, JSNative setter = nullptr); /* Obsolete since JSAPI 32 */ JS_DefineElement(JSContext *cx,
JSObject *obj, uint32_t index, jsval value, JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs); Name Type Description cx JSContext * The context in which to create the new property. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::HandleObject or
JSObject * The object on which ...
...od for retrieving the current property value. setter JSNative or JSStrictPropertyOp setProperty method for specifying a new property value. flags unsigned Property attributes. Obsolete since JSAPI 32 Description JS_DefineElement defines a numeric property for a specified object, obj. index is the index of the element being defined. value is one of JS::Value,
JSObject, JSString, int32_t, uint32_t, or double that defines the property's initial value. getter and setter identify the getProperty and setProperty methods for the property, respectively. If you pass NULL values for these entries, JS_DefineElement assigns the default getProperty and setProperty methods to this element. Obsolete since JSAPI 32 flags contains the property attributes to set for the new ...
JS_DefineFunctions
fs const JSFunctionSpec * A NULL-terminated array of function specifications. ...
...ionSpec *fs, PropertyDefinitionBehavior behavior = DefineAllProperties); In SpiderMonkey versions prior to SpiderMonkey 24, fs was not const. Name Type Description cx JSContext * The context in which to define functions. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<
JSObject*> The object on which functions are to be defined. fs const JSFunctionSpec * A NULL-terminated array of function specifications. Each element of the array defines an individual function. behavior PropertyDefinitionBehavior See below. Added in SpiderMonkey 38 enum PropertyDefinitionBehavior { DefineAllProperties, OnlyDefineLateProperties, Dont...
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 i...
... 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_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. ...
...his 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 execute the script. This paramet...
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...
...Instead: The scope chain is initialized to contain obj, followed by its parent, then its parent's parent, etc. until NULL is reached. Variable initialization is performed. If the JSOPTION_VAROBJFIX option is in effect (recommended), then the last object in the scope chain is used as the variable object. Otherwise obj is used. The this value is obj. script
JSObject * The compiled script to execute. rval jsval * Out parameter. On success, *rval receives the value from the last executed expression statement processed in the script. version JSVersion Version for the script. Description JS_ExecuteScript executes a previously-compiled script, script. If the script executes successfully, *rval receives the value from the ...
JS_ForgetLocalRoot
nnermost 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 this topic. In case a native hook allocates many objects or other GC-things, but the native protects some of those GC-things by storing them as property values in an object that is itself protected, the hook can call...
...on this topic. In case a native hook allocates many objects or other GC-things, but the native protects some of those GC-things by storing them as property values in an object that is itself protected, the hook can call JS_ForgetLocalRoot to free the local root automatically pushed for the now-protected GC-thing. (Here the term GC-thing refers to any value that is subject to garbage collection: a
JSObject, JSString, JSFunction, or jsdouble.) JS_ForgetLocalRoot works on any GC-thing allocated in the current local root scope, but it's more time-efficient when called on references to more recently created GC-things. Calling it successively on other than the most recently allocated GC-thing will tend to average the time inefficiency, and may risk O(n2) growth rate, but in any event, you shouldn't allo...
JS_FreezeObject
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. ...
... 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_GetArrayLength
lengthp uint32_t * Out parameter. On success, *lengthp receives the length of the array. ...
... 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_GetClassObject
If successful, receive the class constructor. Description JS_GetClassObject gets the builtin class costructor for the specified prototype key. ...
...If successful, receive the class constructor. Description JS_GetClassObject gets the builtin class costructor for the specified prototype key. ...
JS_GetClassPrototype
If successful, receive the class prototype object. Description JS_GetClassPrototype gets the builtin class costructor for the specified prototype key. ...
...If successful, receive the class prototype object. Description JS_GetClassPrototype gets the builtin class costructor for the specified prototype key. ...
JS_GetConstructor
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. To get an object's parent, use JS_GetParent. ...
... 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. To get an object's parent, use JS_GetParent. ...
JS_GetProperty
undefined. Then the JSClass.getProperty hook of obj's class is called with the arguments (cx, obj, id, vp). For many objects, including objects of standard classes such as Object and Array, this hook does nothing and returns true, so the property get succeeds and undefined is left in *vp. If the property is found on a non-native object, get handler of Proxy (only if the object is a Proxy) or its
JSObjectOps.getProperty method is called. Otherwise the property is found on a native object. If the property has a JavaScript getter, it is called. Otherwise *vp is set to the property's stored value, or undefined if the property does not have a stored value, and then the property's getter is called with the arguments (cx, obj, id, vp). For many properties, the getter does nothing and returns true, so t...
...rty's stored value, or undefined if the property does not have a stored value, and then the property's getter is called with the arguments (cx, obj, id, vp). For many properties, the getter does nothing and returns true, so the property get succeeds and the property's stored value is left in *vp. Internally, property retrieval, including all the behavior described above, is implemented by obj's
JSObjectOps.getProperty callback. On success, these functions set *vp to the current value of the property, or undefined if obj has no such property, and return true. On an error or exception, these functions return false, and the value left in *vp is undefined. See Also MXR ID Search for JS_GetProperty MXR ID Search for JS_GetUCProperty MXR ID Search for JS_GetPropertyById Example in the JSAPI Ph...
JS_GetScopeChain
use is discouraged since it 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 ob...
...n that object will be the last object in the current scope chain. If the context is currently executing a script, and not in any function, it's running in a scope that was passed to JS_ExecuteScript or a similar function by the application. This scope chain may or may not contain cx's current global object. If any code is currently executing in cx, JS_GetScopeChain returns a pointer to the first
JSObject on the current scope chain. Otherwise, if cx has a global object, JS_GetScopeChain returns that. Otherwise, an error is reported and JS_GetScopeChain returns NULL. To walk the scope chain, use JS_GetParent. See Also MXR ID Search for JS_GetScopeChain JS_GetGlobalForScopeChain bug 632064 ...
JS_HasInstance
v JS::Handle<JS::Value> The value to test. bp bool * Out parameter. On success, *bp receives the result of the test. ...
... v JS::Handle<JS::Value> The value to test. bp bool * Out parameter. On success, *bp receives the result of the test. Description JS_HasInstance determines if a specified JS value, v, is an instance of JS object, obj. ...
JS_InitClass
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
...JSFunctionSpec * Either NULL or a pointer to the first element of an array of JSFunctionSpecs, terminated by JS_FS_END. These functions, if any, are added to the new class's constructor. (This is the JavaScript equivalent of public static methods in C++ or Java.) Description JS_InitClass initializes a JSClass and (optionally) makes it visible to JavaScript code. This is one way to create
JSObjects whose properties and methods are implemented in native C/C++. If you need a native function but you don't need to support instances or inheritance, JS_InitClass might be overkill. JS_DefineFunction is simpler. A JSAPI class consists of a JSClass structure, a constructor, a prototype object, and properties and functions. The JSClass is an internal data structure that is not exposed outside the Ja...
JS_InitStandardClasses
This object must be of a JSClass that has the JSCLASS_GLOBAL_FLAGS bits set. ...
...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_IsNativeFunction
call JSNative The native function to compare. ...
... call JSNative The native function to compare. ...
JS_NewDateObject
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. year int The year to set the new object to. mon int The month to set the new object to. ...
...e 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. min int The minute to set the new object's time to. sec int The second to set the new object's time to. Description Creates and returns a new
JSObject representing a JavaScript Date object, which is pre-configured using the specified values. See also MXR ID Search for JS_NewDateObject JS_NewDateObjectMsec JS_ObjectIsDate bug 625870 ...
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 giv...
...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 given JSScript. Every JSScript object has an associated
JSObject script object. As long as the script object is reachable, the JSScript and its components are protected from garbage collection; when the script object is collected, the JSScript and its contents are freed. Once you have created a script, you should immediately ensure that its script object is reachable (perhaps by using JS_AddRoot or JS_EnterLocalRootScope). A script object has no properties, a...
JS_PushArguments
If successful, JS_PushArguments would return...
...If successful, JS_PushArguments would return a pointer to the first element of an array of four jsvals: a boolean, a number, an object (or null), and a boolean. ...
JS_Remove*Root
e 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 of the jsval variable to remove from the root set. This must have been passed to either JS_AddValueRoot or JS_AddNamedValueRoot...
...aller must be in a request on this JSContext. vp jsval * Address of the jsval variable to remove from the root set. This must have been passed to either JS_AddValueRoot or JS_AddNamedValueRoot. spp JSString * Address of the JSString* variable to remove from the root set. This must have been passed to either JS_AddStringRoot or JS_AddNamedStringRoot. opp
JSObject * Address of the
JSObject* variable to remove from the root set. This must have been passed to either JS_AddObjectRoot or JS_AddNamedObjectRoot. rp void ** Address of the pointer variable to remove from the root set. This must have been passed to either JS_AddGCThingRoot or JS_AddNamedGCThingRoot. Description JS_RemoveRoot removes the variable that rp points to from the ...
JS_SetArrayLength
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. ...
... 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. ...
Xray vision
r example, if you need to see expandos on DOM objects. In cases like this you can waive Xray protection, but then you can no longer rely on any properties or functions being, or doing, what you expect. Any of them, even setters and getters, could have been redefined by untrusted code. ...
...usted code. To waive Xray vision for an object you can use Components.utils.waiveXrays(object), or use the object's wrapped
JSObject property: // chrome code var waivedWindow = Components.utils.waiveXrays(gBrowser.contentWindow); var transfer = waivedWindow.confirm("Transfer all my money?"); // calls the redefined implementation // chrome code var waivedWindow = gBrowser.contentWindow.wrapped
JSObject; var transfer = waivedWindow.confirm("Transfer all my money?"); // calls the redefined implementation Waivers are transitive: so if you waive Xray vision for an object, then you automatically waive it for all the object's properties. For example, window.wrapped
JSObject.document gets you the waived version of document. To undo the waiver again, call Components.utils.unwaiveXrays(waivedObject): ...
Working with windows in chrome code
tcher for passing an arbritrary JavaScript object It is still possible to pass any JavaScript object using nsIWindowWatcher, it just takes a little more effort. In this example a single object is passed, though it is possible to pass multiple objects and primitives using a combination of this and the example above. // In the calling code var args = { param1: true, param2: 42 }; args.wrapped
JSObject = args; var watcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] .getService(Components.interfaces.nsIWindowWatcher); watcher.openWindow(null, url, windowName, features, args); // In the window code var args = window.arguments[0].wrapped
JSObject; This uses the wrapped
JSObject trick. By passing args to openWindow xpconnect will automatically wrap...
... Advanced data sharing The above code is useful when you need to pass data from one window to another or to a set of windows, but sometimes you just want to share a JavaScript variable in common between different windows. ...
JavaScript Debugger Service - Archive of obsolete content
You can use insertFilter (jsdIFilter filter, jsdIFilter after) to insert the filter after a particular filter; you can pass null for jsdIFilter after to insert at the head of the list. You can also use swapFilters (jsdIFilter filter_a, jsdIFilter filter_b) to swap filters, a...
Appendix D: Loading Scripts - Archive of obsolete content
urrent content page. The globals of the current content window will be available in the scripts global scope. In stack traces, the script will appear to have been loaded from the file "zz-9://plural/zed/alpha", line 42. // Use the current content window as the execution context. // To make properties defined by scripts executing on the page // available to your sandbox script, use content.wrapped
JSObject // instead. let context = content; // Create the Sandbox let sandbox = Components.utils.Sandbox(context, { // Make properties of the context object available via the // script's global scope sandboxPrototype: context, // Wrap objects retrieved from the sandbox in XPCNativeWrappers. // This is the default action. wantXrays: true }); // The script that will be executed: le...
Connecting to Remote Content - Archive of obsolete content
we need to parse the following data: {"shops": [{"name": "Apple", "code": "A001"}, {"name": "Orange"}], "total": 100} When the onload callback function is called, the response text is converted into a JS object using the parse method. You can then use this object like any other JavaScript objects in your code. request.onload = function(aEvent) { let text = aEvent.target.responseText; let
jsObject = JSON.parse(text); window.alert(
jsObject.shops[1].name); // => "Orange" window.alert(
jsObject.total); // => 2; }; The JavaScript object can also be serialized back with the stringify method. let string = JSON.stringify(
jsObject); XML content XML is possibly the most popular data interchange format. Let's assume that the XML returned from remote server is this: <?xml version="...
Index - Archive of obsolete content
nect technology to let Java and JavaScript code communicate with each other. The chapter assumes you are familiar with Java programming. 2191 LiveConnect Reference This section documents the Java classes used for LiveConnect, along with their constructors and methods. 2192 JSException The public class JSException extends RuntimeException 2193
JSObject The public final class netscape.javascript.
JSObject extends Object. 2194 MSX Emulator (jsMSX) Canvas_examples, Examples, HTML:Canvas No summary! 2195 Old Proxy API Obsolete Proxies are objects for which the programmer has to define the semantics in JavaScript. The default object semantics are implemented in the JavaScript engine, often written ...
Index of archived content - Archive of obsolete content
4X Tutorial Accessing XML children Descendants and Filters Introduction Namespaces The global XML object Iterator LiveConnect LiveConnect Overview LiveConnect Reference JSException
JSObject MSX Emulator (jsMSX) Old Proxy API ParallelArray Properly Using CSS and JavaScript in XHTML Documents Examples Reference Server-Side JavaScript Back to the Server: Server-Side JavaScript On The ...
SpiderMonkey coding conventions - Archive of obsolete content
have unprefixed, mixed-case names: GetChar. But static native methods of JS objects have lowercase, underscore-separated or intercaps names, e.g., str_indexOf. And library-private and static data use underscores, not intercaps (but library-private data do use a js_ prefix). Scalar type names are lowercase and js-prefixed: jsdouble. Aggregate type names are JS-prefixed and mixed-case:
JSObject. Macros are generally ALL_CAPS and underscored, to call out potential side effects, multiple uses of a formal argument, etc. Linkage DLL entry points have their return type expanded within a JS_PUBLIC_API() macro call, to get the right Windows secret type qualifiers in the right places for all build variants. DLL entry points that are not public APIs use JS_FRIEND_API() instead. ...
browser - Archive of obsolete content
ument object in the browser. contentViewerEdit Type: nsIContentViewerEdit This read-only property contains the nsIContentViewerEdit which handles clipboard operations on the document. contentViewerFile Type: nsIContentViewerFile Reference to the nsIContentViewerFile interface for the document. contentWindow Type: TODO Use the contentWindow.wrapped
JSObject to obtain a DOM(html) window object currentURI Type: nsIURI This read-only property contains the currently loaded URL. To change the URL, use the loadURI method. docShell Type: nsIDocShell This read-only property contains the nsIDocShell object for the document. documentCharsetInfo Obsolete since Gecko 12.0 Type: nsIDocumentCharsetI...
editor - Archive of obsolete content
leType Type: integer A value indicating the type of accessibility object for the element. commandManager Type: nsICommandManager The command manager handles operations on the editor. contentDocument Type: document This read-only property contains the document object in the element. contentWindow Type: TODO Use the contentWindow.wrapped
JSObject to obtain a DOM(html) window object docShell Type: nsIDocShell This read-only property contains the nsIDocShell object for the document. editingSession Type: nsIEditingSession The editing session for the editor which is used to initialize the editor. You would not normally need to use this. editortype Type: one of the values below ...
iframe - Archive of obsolete content
statustext, style, template, tooltip, tooltiptext, top, uri, wait-cursor, width Properties accessibleType Type: integer A value indicating the type of accessibility object for the element. contentDocument Type: document This read-only property contains the document object in the element. contentWindow Type: TODO Use the contentWindow.wrapped
JSObject to obtain a DOM(html) window object docShell Type: nsIDocShell This read-only property contains the nsIDocShell object for the document. webNavigation Type: nsIWebNavigation This read-only property contains the nsIWebNavigation object for the document. Most of its methods are callable directly on the element itself, such as goBack and goForward. It al...
tabbrowser - Archive of obsolete content
document object in the browser. contentViewerEdit Type: nsIContentViewerEdit This read-only property contains the nsIContentViewerEdit which handles clipboard operations on the document. contentViewerFile Type: nsIContentViewerFile Reference to the nsIContentViewerFile interface for the document. contentWindow Type: TODO Use the contentWindow.wrapped
JSObject to obtain a DOM(html) window object currentURI Type: nsIURI This read-only property contains the currently loaded URL. To change the URL, use the loadURI method. docShell Type: nsIDocShell This read-only property contains the nsIDocShell object for the document. documentCharsetInfo Obsolete since Gecko 12.0 Type: nsIDocumentCharsetInfo...
LiveConnect Reference - Archive of obsolete content
This section documents the Java classes used for LiveConnect, along with their constructors and methods. JavaScript-to-Java These classes allow a Java object to access JavaScript code. JSException The public class JSException extends RuntimeException, and is thrown when JavaScript returns an error.
JSObject The public class
JSObject extends Object. JavaScript objects are wrapped in an instance of the class
JSObject and passed to Java, allowing Java to manipulate JavaScript objects. Java-to-JavaScript Global objects java Packages netscape sun JavaArray JavaClass JavaObject JavaPackage ...
JavaClass - Archive of obsolete content
A reference to the class name used with the Packages object: Packages.JavaClass JavaClassis the fully-specified name of the object's Java class. The LiveConnect java, sun, and netscape objects provide shortcuts for commonly used Java packages and also create JavaClass objects. Description A JavaClass object is a reference to one of the classes in a Java package, such as netscape.javascript.
JSObject. A JavaPackage object is a reference to a Java package, such as netscape.javascript. In JavaScript, the JavaPackage and JavaClass hierarchy reflect the Java package and class hierarchy. You can pass a JavaClass object to a Java method which requires an argument of type java.lang.Class. Backward compatibility JavaScript 1.3 and earlier You must create a wrapper around an instance of java.lang.
JavaPackage - Archive of obsolete content
ges keyword: Packages.JavaPackage JavaPackageis the name of the object's Java package. If the package is in the java, netscape, or sun packages, the Packages keyword is optional. Description In Java, a package is a collection of Java classes or other Java packages. For example, the netscape package contains the package netscape.javascript; the netscape.javascript package contains the classes
JSObject and JSException. In JavaScript, a JavaPackage is a reference to a Java package. For example, a reference to netscape is a JavaPackage. netscape.javascript is both a JavaPackage and a property of the netscape JavaPackage. A JavaClass object is a reference to one of the classes in a package, such as netscape.javascript.
JSObject. The JavaPackage and JavaClass hierarchy reflect the Java package and...
Chrome registration
vewrappers=no until Firefox 4. Note: Support for this flag has been removed in Gecko 2.0. You can no longer disable XPCNativeWrappers. To update your add-on to work without this flag: If your add-on depends upon XBL bindings attached to content objects (that is, it needs to be able to call functions or get and set properties created by the XBL binding), you'll need to use the object's wrapped
JSObject property to obtain a wrapped object. If you need to call functions or access properties defined by the content -- for example, if your add-on wants to add a button to the page that calls a JavaScript function defined by the page. The xpcnativewrappers flag applies only to content packages; it is not recognized for locale or skin registration. Example chrome manifest content necko ...
Error codes returned by Mozilla APIs
NT_CONVERT_OBJECT_TO_ARRAY (0x80570023) NS_ERROR_XPC_NOT_ENOUGH_ELEMENTS_IN_ARRAY (0x80570024) NS_ERROR_XPC_CANT_GET_ARRAY_INFO (0x80570025) NS_ERROR_XPC_NOT_ENOUGH_CHARS_IN_STRING (0x80570026) NS_ERROR_XPC_SECURITY_MANAGER_VETO (0x80570027) NS_ERROR_XPC_INTERFACE_NOT_SCRIPTABLE (0x80570028) NS_ERROR_XPC_INTERFACE_NOT_FROM_NSISUPPORTS (0x80570029) NS_ERROR_XPC_CANT_GET_
JSOBJECT_OF_DOM_OBJECT (0x8057002A) NS_ERROR_XPC_CANT_SET_READ_ONLY_CONSTANT (0x8057002B) NS_ERROR_XPC_CANT_SET_READ_ONLY_ATTRIBUTE (0x8057002C) NS_ERROR_XPC_CANT_SET_READ_ONLY_METHOD (0x8057002D) NS_ERROR_XPC_CANT_ADD_PROP_TO_WRAPPED_NATIVE (0x8057002E) NS_ERROR_XPC_CALL_TO_SCRIPTABLE_FAILED (0x8057002F) NS_ERROR_XPC_
JSOBJECT_HAS_NO_FUNCTION_NAMED (0x80570030) NS_ERROR_XPC_BAD...
JS::PerfMeasurement
e the results available to JavaScript, 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. ...
Hacking Tips
ignore OOM For example if you are performing a speculative optimisation you might abandon it and continue anyway. But in this case you may have to call cx->recoverFromOutOfMemory() if something further down the stack has already reported the failure. Debugging GC marking/rooting The js::debug namespace contains some functions that are useful for watching mark bits for an individual
JSObject* (or any Cell*). js/src/gc/Heap.h contains a comment describing an example usage. Reproduced here: // Sample usage from gdb: // // (gdb) p $word = js::debug::GetMarkWordAddress(obj) // $1 = (uintptr_t *) 0x7fa56d5fe360 // (gdb) p/x $mask = js::debug::GetMarkMask(obj, js::gc::GRAY) // $2 = 0x200000000 // (gdb) watch *$word // Hardware watchpoint 7: *$word // (gdb) cond 7 *$word & $m...
How to embed the JavaScript engine
2); JS::AutoValueArray<2> argv(cx); argv[0].setInt32(1); argv[1].setInt32(2); then call the function: // [SpiderMonkey 24] Pass arguments length and the 'jsval *' pointer. // JS_CallFunctionName(cx, global, "func", 2, argv.begin(), rval.address()); JS_CallFunctionName(cx, global, "func", argv, &rval); Example Say the click event is for the top-most or focused UI element at position (x, y):
JSObject *target, *event; JS::AutoValueArray<1> argv(cx); /* * Find event target and make event object to represent this click. * Pass cx to NewEventObject so JS_NewObject can be called. */ target = FindEventTargetAt(cx, global, x, y); event = NewEventObject(cx, "click", x, y); argv[0].setObjectOrNull(event); /* To emulate the DOM, you might want to try "onclick" too. */ ok = JS_CallFunctionName(cx, ...
Functions
(But note that objects of other classes can be callable and can even have typeof obj == "function".) Script functions Functions written in JavaScript and compiled to bytecode. There are four variations that affect how NameExpressions are evaluated. (NameExpressions are basic expressions like String and x that would eat up a huge amount of run time if the engine weren't smart enough to avoid symbol table lookups.) General closures are the base case. When the function object is created, its parent is set to the first object on the scope chain. ...
JS::AutoVectorRooter
st T &back() const Returns the last element. Description JS::AutoVectorRooter<T> holds a variable-size rooted array of type T. ...
JS::CurrentGlobalOrNull
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. 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::Handle
nerated, which is quicker and easier to fix than when relying on a separate rooting analysis. If you want to add additional methods to JS::Handle for a specific specialization, define a js::HandleBase<T> specialization containing them. ...
JS::IdentifyStandardInstance
This article covers features introduced in SpiderMonkey 31 Determine if the given object is an instance/prototype/constructor for a standard class. Syntax JSProtoKey JS::IdentifyStandardInstance(
JSObject *obj); JSProtoKey JS::IdentifyStandardPrototype(
JSObject *obj); JSProtoKey JS::IdentifyStandardInstanceOrPrototype(
JSObject *obj); JSProtoKey JS::IdentifyStandardConstructor(
JSObject *obj); // Added in SpiderMonkey 38 Name Type Description obj
JSObject * Pointer to the instance/prototype/constructor object to determine. Description JS::IdentifyStandardInstance determines if the given object is an instance for a standard class. If so, return the associated JSProtoKey. If not, return JSProto_Null. JS::IdentifyStandardPrototype determines if the...
JS::MutableHandle
T> by using |JS::Rooted<T>::operator&()|. If you want to add additional methods to JS::MutableHandle for a specific specialization, define a js::MutableHandleBase<T> specialization containing them. ...
JS::PersistentRooted
nkey 38, PersistentRooted<T> itself cannot be a global variable, but from SpiderMonkey38, it can be declared as a global variable, and initialized later with init() method (bug 1107639). ...
JS::Rooted
ed<T> may be automatically coerced to a JS::Handle<T>. JS::Rooted<T> should be used whenever a local variable's value may be held live across a call which can trigger a GC. If you want to add additional methods to Rooted for a specific specialization, define a js::RootedBase<T> specialization containing them. ...
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 c...
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. ...
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
Native methods must not call JS_CALLEE after calling JS_SET_RVAL. (The return value and the callee are stored in the same stack slot.) JS_THIS(cx, vp) Returns the this argument as a jsval, or JSVAL_NULL on error. Native methods must not call JS_THIS after calling JS_SET_RVAL. (JS_THIS may call JS_CALLEE.) JS_THIS_OBJECT(cx, vp) Returns the this argument as a
JSObject *, or NULL on error. Native methods must not call JS_THIS_OBJECT after calling JS_SET_RVAL. (JS_THIS_OBJECT may call JS_CALLEE.) JS_ARGV(cx, vp) Returns the argv pointer. This points to element 0 of an array of argc jsvals, the arguments supplied by the caller. JS_RVAL(cx, vp) Returns the jsval that is currently in the return-value slot. JS_SET_RVAL(cx, vp...
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 ob...
JSMarkOp
rs, 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 reachable from obj. ...
JSPRINCIPALS_HOLD
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. Application code that stores a pointer to a JSPrincipals object must call JSPRINCIPALS_HOLD(cx, principals) before storing it and JSPRINCIPALS_DROP(cx, principals) when done with it. JSPRINCIPALS_HOLD(cx, principals) increments the reference count of principals by 1. JSPRINCIPALS_DROP(cx, principals) decrements the reference count of principals...
JSProperty
Internal use only. The type of JavaScript object properties, used by the
JSObjectOps layer. Syntax struct JSProperty { jsid id; }; Description JSProperty is the abstract base class of all object properties. It is used internally in
JSObjectOps.lookupProperty, getAttributes, setAttributes, and dropProperty. See Also bug 483473 ...
JSReserveSlotsOp
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. JSReserveSlotsOp is the type of the JSClass.reserveSlots. Syntax typedef uint32 (* JSReserveSlotsOp)(JSContext *cx,
JSObject *obj); Name Type Description cx JSContext * The JS context in which the new object is being created. obj
JSObject * The new object. Description Warning: JSAPI applications should not use this hook. A class cannot freely use a reserveSlots hook to reserve a different number of slots for each object. Rather, within a JSRuntime, every call to the same reserveSlots hook must return the same value (excepting a few internal classes su...
JSTraceOp
Description JSTraceOp is the function type for trace operation of the class called to enumerate all traceable things reachable from obj's private data structure. For each such thing, a trace implementation must call one of the JS_Call*Tracer variants on the thing. JSTraceOp implementation can assume that no other threads mutates object state. It must not change state of the object or corresponding native structures. ...
JSVAL_IS_OBJECT
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 a given jsval is an object or null. Syntax JSBool JSVAL_IS_OBJECT(jsval v); Description JSVAL_IS_OBJECT(v) returns true if v is either an object or JSVAL_NULL. This indicates that it is safe to call JSVAL_TO_OBJECT(v) to convert v to type
JSObject *. If v is a string, number, boolean, or undefined, the result is false. This function is obsolete and has been removed. Instead use !JSVAL_IS_PRIMITIVE(v) to detect objects and JSVAL_IS_NULL(v) to detect null. See Also bug 952650 ...
JSXDRObjectOp
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. JSXDRObjectOp is the type for JSClass.xdrObject. Syntax typedef JSBool (* JSXDRObjectOp)(JSXDRState *xdr,
JSObject **objp); Name Type Description xdr JSXDRState * The XDR reader or writer. objp
JSObject ** The object to be serialized or deserialized. Description Serialize or deserialize an object, given an XDR state record representing external data. See jsxdrapi.h. JSClass hooks JSClass offers the following hook: JSXDR calls the JSClass.xdrObject callback to serialize and deserialize objects. See Also JSClass bug 726944 ...
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 in...
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_AliasPro...
JS_BindCallable
This article covers features introduced in SpiderMonkey 17 Bind the given callable to use the given object as this. Syntax
JSObject* JS_BindCallable(JSContext *cx, JS::Handle<
JSObject*> callable, JS::Handle<
JSObject*> newThis); 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. 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. If callable is not callable, wi...
JS_BufferIsCompilableUnit
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. 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_CallFunction
l 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, jsval *argv, jsval *rval); bool JS_CallFunctionValue(JSContext *cx,
JSObject *obj, jsval fval, unsigned argc, jsval *argv, jsval *rval); Name Type Description cx...
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 operat...
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 sing...
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 a...
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_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 ...
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. filen...
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
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 JSType The hint to pass to ...
JS_DefineConstDoubles
nstDoubleSpec *cds); bool JS_DefineConstIntegers(JSContext *cx, JS::HandleObject obj, const JSConstIntegerSpec *cis); // Added in SpiderMonkey 38 Name Type Description cx JSContext * The context in which to define the new properties. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. 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. cis JSConstIntegerSpec * Pointer to an array of JSConstIntegerSpec records containing property names and values to create. The last array eleme...
JS_DefineObject
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. 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_DefineProperties
Define multiple properties for a single object. Syntax bool JS_DefineProperties(JSContext *cx, JS::HandleObject obj, const JSPropertySpec *ps); Name Type Description cx JSContext * The context in which to define the properties. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. 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. In SpiderMonkey versions prior to SpiderMonkey 24, the last argument to JS_DefinePropeties was not const. Description JS_DefineProp...
JS_DefineProperty
HasProperty, and Property_attributes, can detect or examine a property without calling its getter.) If getter (or setter) is NULL, the new property will use the JSClass.getProperty (or JSClass.setProperty) callback from obj's class. If attrs contains the JSPROP_GETTER (or JSPROP_SETTER) flag, then getter (or setter) must point to a JavaScript Function, not a C/C++ function. That is, it must be a
JSObject * that points to a JavaScript Function, cast to type JSPropertyOp. For more about JavaScript getters and setters, see Defining Getters and Setters. On success, JS_DefineProperty returns true. On error or exception, it returns false. See Also MXR ID Search for JS_DefineProperty MXR ID Search for JS_DefineUCProperty MXR ID Search for JS_DefinePropertyById JS_DefineElement bug 461163 bug 1...
JS_DeleteProperty
not configurable, an error is raised. Otherwise, the property is removed. These functions return true on success, regardless of whether a property was actually deleted, and false on error or exception. (In JavaScript 1.2 and earlier, attempting to delete a permanent property caused an error. There is no longer any way to get this behavior.) Internally, property deletion is implemented by the
JSObjectOps.deleteProperty callback. To remove all properties from an object, call JS_ClearScope. See Also MXR ID Search for JS_DeleteProperty MXR ID Search for JS_DeletePropertyById JS_DeleteProperty2 JS_DeletePropertyById2 bug 461163 bug 1113369 -- added result parameter and JS_DeleteUCProperty ...
JS_DeleteProperty2
ch may change *succeeded). If the hook returns false, the error is propagated. Otherwise, if obj is not configurable, an error is raised. Otherwise, *succeeded receives true and the property is removed. These functions return true on success, regardless of whether a property was actually deleted. On error or exception, the return value is false, and the value left in *succeeded is unspecified.
JSObjectOps.deleteProperty implements this behavior. (In JavaScript 1.2 and earlier, attempting to delete a permanent property caused an error. There is no longer any way to get this behavior.) To remove all properties from an object, call JS_ClearScope. See Also MXR ID Search for JS_DeleteProperty2 MXR ID Search for JS_DeleteUCProperty2 MXR ID Search for JS_DeletePropertyById2 bug 461163 bug 11...
JS_DumpNamedRoots
d by the application. When JS_DumpNamedRoots calls it, it passes three arguments: Argument Type Description name const char * The name of the named root. rp void * A pointer to the rooted variable, array element, or field. This is the pointer that the application passed to JS_AddNamedRoot. It points to a variable, array element, or field of type jsval,
JSObject *, JSString *, or jsdouble *. data void * The data argument that the application passed to JS_DumpNamedRoots. Example static void dumpRoot(const char *name, void *addr, void *data) { /* The application may use `data` for anything. In this example, we use it to pass the desired output file. */ FILE *f = (FILE *) data; fprintf(f, "There is a root named '%s'...
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 ...
JS_EnterCrossCompartmentCall
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 different compartm...
JS_EnterLocalRootScope
y 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, obj, id, vp); // When we leave the local root scope, this protec...
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_ExecuteScript
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::HandleObject The scope in which to execute th...
JS_ExecuteScriptPart
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. 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_ExecuteScript. ...
JS_GET_CLASS
moved 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. Newer versions have removed the context argument, so that the same signature is used regar...
JS_GetArrayPrototype
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. forObj JS::HandleObject An object from the global whose Array.prototype is being retrieved. ...
JS_GetErrorPrototype
Other contexts in the same runtime can have their own error reporting functions. ...
JS_GetFunctionPrototype
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. forObj JS::HandleObject An object from the global whose Function.prototype is being retrieved. ...
JS_GetGlobalForCompartmentOrNull
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. 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_GetGlobalForObject
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. For example, if the function refers to a global variable foo, then foo is a property of the object returned by JS_GetGlobalForObject. ...
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 ...
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 NU...
JS_GetInstancePrivate
Retrieve the private data associated with an object, if that object is an instance of a specified class. Syntax void * JS_GetInstancePrivate(JSContext *cx, JS::Handle<
JSObject*> obj, const JSClass *clasp, JS::CallArgs *args); // Added in JSAPI 32 void * JS_GetInstancePrivate(JSContext *cx, JS::Handle<
JSObject*> obj, const JSClass *clasp, jsval *argv); // Obsolete since JSAPI 32 Name Type Description cx JSContext * A context. 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. Added in SpiderMonkey 32 argv jsval * ...
JS_GetObjectPrototype
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. forObj JS::HandleObject An object from the global whose Object.prototype is being retrieved. ...
JS_GetObjectRuntime
This article covers features introduced in SpiderMonkey 17 Retrieve a pointer to the JSRuntime of a specified object. Syntax JSRuntime * JS_GetObjectRuntime(
JSObject *obj); Name Type Description obj
JSObject * The object to query. Description JS_GetObjectRuntime retrieves a pointer to the JSRuntime for a specified
JSObject. See Also MXR ID Search for JS_GetObjectRuntime bug 723286 ...
JS_GetPrivate
Access the private data field of an object. Syntax void * JS_GetPrivate(
JSObject *obj); Name Type Description obj
JSObject * An object whose JSClass has the JSCLASS_HAS_PRIVATE flag. Description JS_GetPrivate accesses an object's private data field. obj must be an instance of a class that has the JSCLASS_HAS_PRIVATE flag. New objects' private data fields are initially NULL. If obj is a Function object, as reported by JS_ObjectIsFunction, the private data is a pointer to a JSFunction. (But consider using JS_ValueToFunction instead to access it.) Warning: It is dangerous to call JS_GetPrivate on a
JSObject * unless the object's JSClass is known. If the object is not of the expected JSClass, the result of JS_GetPrivate would probably be NULL or a pointer ...
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_GetSecurityCallbacks
s for the runtime. Callback Structure struct JSSecurityCallbacks { JSCSPEvalChecker contentSecurityPolicyAllows; // Added in SpiderMonkey 1.8.5 JSSubsumesOp subsumes; // Added in SpiderMonkey 31 JSCheckAccessOp checkObjectAccess; // Obsolete since JSAPI 29 JSPrincipalsTranscoder principalsTranscoder; // Obsolete since JSAPI 13
JSObjectPrincipalsFinder findObjectPrincipals; // Obsolete since JSAPI 13 }; Name Type Description contentSecurityPolicyAllows JSCSPEvalChecker A pointer to the function which checks if a CSP instance wants to disable eval() and friends. Use NULL is not needed. subsumes JSSubsumesOp A pointe to the function which returns whether the first principal subsumes...
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 proper...
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_InstanceOf
Determine if an object is an instance of a specified JSClass. Syntax bool JS_InstanceOf(JSContext *cx, JS::Handle<
JSObject*> obj, const JSClass *clasp, JS::CallArgs *args); // Added in SpiderMonkey 38 bool JS_InstanceOf(JSContext *cx, JS::Handle<
JSObject*> obj, const JSClass *clasp, jsval *argv); // Obsolete since JSAPI 32 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::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...
JS_IsGlobalObject
This article covers features introduced in SpiderMonkey 24 Determine if given object is a global object. Syntax bool JS_IsGlobalObject(
JSObject *obj); Name Type Description obj
JSObject * The object to examine. Description JS_IsGlobalObject returns true if obj is a global object, false otherwise. See also MXR ID Search for JS_IsGlobalObject JS_NewGlobalObject bug 797821 ...
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 funct...
JS_LockGCThing
t. 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_LockGCThing is a deprecated function that protects a specified item, thing, associated with an executable script context, cx, from garbage collection. thing is a pointer to a jsdouble, JSString, or
JSObject. JS_UnlockGCThing removes a lock from a specified item, thing, allowing it to be garbage collected when the JavaScript engine determines it is unreachable. JS_LockGCThing and JS_UnlockGCThing are available only for backward compatibility with existing applications. Use JS_AddRoot and JS_RemoveRoot instead. See Also bug 734250 - removed *RT functions bug 706885 ...
JS_LookupProperty
king at the currently executing bytecode. Notes JS_LookupProperty does not distinguish between a property with a value of undefined and a property that does not exist. Use JS_GetPropertyAttributes to distinguish these cases. JS_LookupProperty differs from JS_GetProperty in that JS_LookupProperty does not invoke the get handler for the property. Internally, property lookups are implemented by the
JSObjectOps.lookupProperty callback. See Also bug 547140 -- removed *WithFlags bug 1094176 ...
JS_NewArrayObject
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. contents JS::HandleValueArray& Reference to the initial values for the array's elements. Added in SpiderMonkey 31 length size_t or int The length of the new array. ...
JS_NewCompartmentAndGlobalObject
since JSAPI 16This 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.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...
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_NewGlobalObject
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
JS_NewPlainObject
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. Description JS_NewPlainObject creates a new plain object, like new Object(), with Object.prototype as [[Prototype]]. On success, JS_NewPlainObject returns a pointer to the new object. ...
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 ...
JS_ObjectIsDate
ced in SpiderMonkey 1.8.5 Determines if a specified object is a Date object. Syntax bool JS_ObjectIsDate(JSContext *cx, JS::HandleObject obj); Name Type Description cx JSContext * Pointer to a JavaScript 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 *
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). This function returns true if the object is a Date. See also MXR ID Search for JS_ObjectIsDate JS_NewDateObject JS_NewDateObjectMsec bug 625870 ...
JS_ObjectIsFunction
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_ParseJSON
5 and return the corresponding value. Syntax JSBool JS_ParseJSON(JSContext *cx, const jschar *chars, uint32 len, jsval *vp); JSBool JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32 len, jsval reviver, jsval *vp); Name Type Description cx JSContext * Pointer to a JS context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. 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. *vp receives the value after parsing (and optionally, processing by the reviver). If an error occurs, the value left in *v...
JS_PropertyStub
Rather, they are convenient stand-ins anywhere the JSAPI requires callbacks of certain types. Examples at JSClass illustrate how stub functions can be used. JS_PropertyStub is of type JSPropertyOp, the type of getter callback. It can be used in JSClass.addProperty, a...
JS_SealObject
f 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, or set the val...
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 ...
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_SetObjectPrincipalsFinder
Set the runtime-wide object-principals-finder callback. This function is deprecated. In SpiderMonkey 1.8.1 or later, use JS_SetRuntimeSecurityCallbacks instead. Syntax
JSObjectPrincipalsFinder JS_SetObjectPrincipalsFinder(JSRuntime *rt,
JSObjectPrincipalsFinder fop); Name Type Description rt JSRuntime * The runtime to configure. fop
JSObjectPrincipalsFinder The new object-principals-finder callback. Description JS_SetObjectPrincipalsFinder allows the application to set a callback that the JavaScript engine uses to obtain an object's principals. This callback is described in
JSObjectPrincipalsFinder. JS_SetObjectPrincipalsFinder returns the previous object-principals-finder callback. MXR ID Search for JS_SetObjectPrincipalsFinder ...
JS_SetPrivate
data void * Private data for the object. This pointer must be aligned to a 2-byte boundary. Description If a JSClass has the JSCLASS_HAS_PRIVATE flag, each object of that class has a private field of type void * which the application may use for any purpose. It is especially useful for storing C/C++ data that should not be directly visible to scripts. For example, a Socket class might use the private data field to store the socket handle. JS_SetPrivate sets an object's private data field. ...
JS_SetProperty
the property has a stored value, then the value left in v becomes the stored value of the property. On success, JS_SetProperty returns true, and the value in v is left unchanged unless a hook or setter modified it. On error or exception, it returns false, and the value left in v is unspecified. Internally, property assignment, including all the behavior described above, is implemented by obj's
JSObjectOps.setProperty callback. See Also MXR ID Search for JS_SetProperty MXR ID Search for JS_SetUCProperty MXR ID Search for JS_SetPropertyById bug 461163 ...
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. n...
JS_ValueToFunction
to JSTYPE_FUNCTION safely. If v is a Function object, this returns the associated JSFunction. If v is null, undefined, a boolean, a number, or a string, a TypeError is reported and JS_ValueToFunction returns NULL. Otherwise, v is an object. The JavaScript engine attempts to convert it to a function. (Implementation note: The actual conversion is performed by the object itself. The object's
JSObjectOps.defaultValue method is called with hint=JSTYPE_FUNCTION.) JS_ValueToFunction returns a pointer to the converted function. If conversion fails with an error or exception, JS_ValueToFunction returns NULL. See Also MXR ID Search for JS_ValueToFunction MXR ID Search for JS_ValueToConstructor ...
JS_ValueToNumber
specified in ECMA 262-3 ?9.3.1. JS_ValueToNumber always succeeds in this case, returning JS_TRUE. If the string is not a numeric string, *dp is set to NaN. Otherwise v is an object. JS_ValueToNumber carries out the following steps to convert it to a number. If at any step an error or exception occurs, or conversion succeeds, the rest of the steps are skipped. (This behavior is implemented by v's
JSObjectOps.defaultValue hook, so host objects can override it all.) First, the object's JSClass.convert callback is called. For objects of standard classes, this is JS_ConvertStub, which simply calls v.valueOf() if present. If the convert callback produces a primitive value, the value is converted to a number as described above and conversion succeeds. Otherwise, the resulting object's toString ...
JS_ValueToObject
VOID, the result is NULL. If v is a boolean value, a number, or a string, the result is a new wrapper object of type Boolean, Number, or String. Otherwise v is an object, and the result depends on the object. If v is a native JavaScript Object, this calls the object's valueOf method, if any. In any case, the result is not guaranteed to be the same object as v. (Implementation note: the object's
JSObjectOps.defaultValue method is called with hint=JSTYPE_OBJECT.) The resulting object is subject to garbage collection unless the variable *objp is protected by a local root scope, an object property, or the JS_AddRoot function. Note that a local root scope is not sufficient to protect the resulting object in some cases involving the valueOf method! See Also MXR ID Search for JS_ValueToObject JS_Co...
JS_ValueToString
A 262-3 ?9.8.1. This might be "NaN", "Infinity", or "-Infinity". Otherwise the result is a decimal representation of the number, possibly using exponential notation. Otherwise v is an object. JS_ValueToString uses the steps below to convert it to a string. If at any point an error or exception occurs, or conversion succeeds, the rest of the steps are skipped. (This behavior is implemented by v's
JSObjectOps.defaultValue method, so host objects can override it all.) If v.toString() is a function, it is called. If that method returns a primitive value, the value is converted to a string as described above and conversion succeeds. Otherwise, the resulting object's JSClass.convert callback is called. For standard classes, this is JS_ConvertStub, which simply calls v.valueOf() if present. If...
OBJECT_TO_JSVAL
Obsolete since JSAPI 42This 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. Casts a specified JS object to a JS value. Please use JS::ObjectValue/JS::ObjectOrNullValue instead in SpiderMonkey 45 or later. Syntax jsval OBJECT_TO_JSVAL(
JSObject *obj); Name Type Description obj
JSObject * A pointer to a JavaScript object to convert to a jsval. Description OBJECT_TO_JSVAL casts obj from type
JSObject * to jsval. If obj is NULL, the result is JSVAL_NULL. See Also MXR ID Search for OBJECT_TO_JSVAL JS_ValueToObject JS::ObjectValue JS::ObjectOrNullValue bug 1177892 -- removed ...
Stored value
tter, if any, is called. JS_DefineProperty allows the application to specify a property's initial stored value. JS_LookupProperty fetches a property's stored value without triggering its getter. Properties with the JSPROP_SHARED attribute do not have a stored value. ES5 accessor properties, as in {get length() { return 0; }, automatically have JSPROP_SHARED. Properties of objects that have custom
JSObjectOps do not have a stored value. Stored values are strong references for the purpose of garbage collection. As long as an object is reachable, the stored values of its properties are reachable and will not be collected. ...
SpiderMonkey 1.8.5
piler might optimize away important stack/register roots (such as when we access the jschars in a JSString). A C analogue, JS_AnchorPtr, was introduced with bug 630209. bug 630209 also removed the need for JS_NewScriptObject, by modifying the script compilation interfaces to handle the creation and management of the object wrapper directly; similarly, the script execution interfaces now accept a
JSObject pointer than a pointer to JSScript. Affected interfaces are: JS_CompileScript JS_CompileScriptForPrincipals JS_CompileScriptForPrincipalsVersion JS_CompileUCScript JS_CompileUCScriptForPrincipals JS_CompileUCScriptForPrincipalsVersion JS_CompileFile JS_CompileFileHandle JS_CompileFileHandleForPrincipals JS_CompileFileHandleForPrincipalsVersion JS_CompileFunction JS_CompileFunctionFor...
SpiderMonkey 1.8.7
iler might optimize away important stack/register roots (such as when we access the jschars in a JSString). A C analogue, JS_AnchorPtr, was introduced with bug 630209. Bug 630209 also removed the need for JS_NewScriptObject, by modifying the script compilation interfaces to handle the creation and management of the object wrapper directly; similarly, the script execution interfaces now accept a
JSObject pointer than a pointer to JSScript. Affected interfaces are: JS_CompileScript JS_CompileScriptForPrincipals JS_CompileScriptForPrincipalsVersion JS_CompileUCScript JS_CompileUCScriptForPrincipals JS_CompileUCScriptForPrincipalsVersion JS_CompileFile JS_CompileFileHandle JS_CompileFileHandleForPrincipals JS_CompileFileHandleForPrincipalsVersion JS_CompileFunction JS_CompileFunctionFor...
SpiderMonkey 1.8.8
pe has changed A number of optional members have 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... Futur...
SpiderMonkey 17
pe has changed A number of optional members have 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 argu...
Split object
Each half of a split object always has a pointer to the other half. Inner objects implement the JSExtendedClass.outerObject hook, which returns a pointer to the corresponding outer object. Outer objects implement the JSExtendedClass.innerObject hook. But the association is not fixed. An outer object may be associated with different inner objects at different times. This feature is complicated. Programs other than Mozilla that embed SpiderMonkey should avoid using split objects. The window object Split objects were introduced to resolve a problem posed by the window object. ...
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: You need to che...
XPCOM changes in Gecko 2.0
ger supported. This was always intended to be a short-term workaround to allow extensions to continue to work while their authors updated their code to use XPCNativeWrappers. If your add-on depends upon XBL bindings attached to content objects--for example, the ability to call functions or get and set properties created by the XBL binding--you will need to use the XPCNativeWrapper property wrapped
JSObject to access wrapped objects. If you need to be able to call functions or access properties defined by web content, you'll need to do this as well. This may be the case if, for example, you've written an extension that adds a delete button to a web mail service, and the service defines a window.delete() function that you need to call. If, on the other hand, all you're doing with content is accessing...
Index
uide. 1272 already_AddRefed XPCOM, XPCOM API Reference, nsCOMPtr already_AddRefed in association with nsCOMPtr allows you to assign in a pointer without AddRefing it. 1273 nsCOMPtr versus RefPtr Gecko code uses both nsCOMPtr and RefPtr as smart pointers. This guide provides some explanation and advice on how to choose between them. 1274 wrapped
JSObject XPCOM:Language Bindings, XPConnect wrapped
JSObject is a property sometimes available on XPConnect wrappers. When available, it lets you access the JavaScript object hidden by the wrapper. 1275 xptcall FAQ XPCOM, XPCOM:Language Bindings, XPConnect xptcall is a small low level XPCOM method call library. It is implemented using platform specific C/C++ and assembly lang...
Components.classes
To access a service (a singleton component, only single instance of which exists at any time), you should use getService instead of createInstance: var os = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); The first time anyone accesses a service, the corresponding component is created under the hood.
Components.utils.Sandbox
page sees a "vanilla" view of the other. The protection is bidirectional: the caller sees the bonafide DOM objects without being confused by sneakily-redefined properties, and the target receives appropriate privacy from having its expandos inspected by untrusted callers. In situations where only unidirectional protection is needed, callers have the option to waive the X-ray behavior using wrapped
JSObject or XPCNativeWrapper.unwrap(). In general, when accessing same-origin content, script gets a Transparent wrapper rather than an Xray wrapper. However, sandboxes are often used when chrome wants to run script as another origin, possibly to interact with the page. In this case, same-origin Xrays are desirable, and wantXrays should be set to true. See Safely accessing content DOM from chrome for ...
Components.utils.exportFunction
the original object. For the full details refer to the documentation for Xray vision, but for example: functions are not visible in the Xrays of JavaScript Object types. ...
Components.utils.waiveXrays
at object (and their properties, and so on). If you waive Xray vision, you can no longer trust that any of the object's properties are what you expect: any of them, including prototypes and accessors, could have been redefined by the less-privileged code. To undo waiveXrays and get Xray vision back, call Components.utils.unwaiveXrays on the object. The result of waiveXrays is just like the wrapped
JSObject property for Xrayed objects, but it's more useful because you can call it on primitives or objects that aren't Xrays, in which case it just returns the argument you passed in. This means you don't have to care whether the initial object is an Xray or not. Syntax waived = Components.utils.waiveXrays(obj); Parameters obj The object for which we wish to waive Xrays. Returns If the argumen...
nsIHttpServer
} if (callback) { this.registerPrefixHandler("/", callback); } let host = "localhost"; if (typeof port === "string" && port.indexOf(':') != -1){ [host, port] = port.split(':'); port = parseInt(port); server.identity.add('http', host, port); } server.wrapped
JSObject._start(port, host); return true; }, registerFile: function(path, filePath) { var file = Components.classes['@mozilla.org/file/local;1'] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filePath); return server.registerFile(path, file); }, registerDirectory : function...
nsIMessageWakeupService
interface to instantiate the component as (e.g. "nsIMyInterface"). The method to call to instantiate the component (either "getService" or "createInstance"). A comma-separated list of messages for which your component should be instantiated. Alternatively, it is possible to register a wakeup entry programmatically via the nsICategoryManager interface. Currently, services must expose a wrapped
JSObject in order to support this; however, once bug 593407 is fixed, the service to be woken up must implement nsIFrameMessageListener. ...
XPCOM
not keep that object alive. If the referent object is destroyed before the weak reference, the pointer inside the weak reference is set to nsnull.Working with Multiple Versions of InterfacesIn this short note we illustrate how one can update an XPCOM module in order for it to work in both Firefox 2 and Firefox 3, even if the interfaces have changed in the interim.Working with out parameterswrapped
JSObjectwrapped
JSObject is a property sometimes available on XPConnect wrappers. When available, it lets you access the JavaScript object hidden by the wrapper.XPCOM ABIXPCOM ABI is the binary interface of XPCOM components. While XPCOM components written in a scripting language (such as JavaScript) can be moved across platforms (such as Windows and OS X) without adaptation, those written in a compiled lan...
Tutorial: Show Allocations Per Call Path - Firefox Developer Tools
er; // This makes hacking on the demo *much* more // pleasant. dbg.uncaughtExceptionHook = handleUncaughtException; // Find the current tab's main content window. var w = gBrowser.selectedBrowser.contentWindow; console.log("Tracking allocations in page: " + w.location.href); // Make that window a debuggee of our Debugger. dbg.addDebuggee(w.wrapped
JSObject); // Enable allocation tracking in dbg's debuggees. dbg.memory.trackingAllocationSites = true; } window.demoPlotAllocations = function() { // Grab the allocation log. var log = dbg.memory.drainAllocationsLog(); // Neutralize the Debugger, and drop it on the floor // for the GC to collect. console.log("Stopping allocation tracking."); dbg.removeAllDebuggees()...
Document.documentURIObject - Web APIs
erty returns an nsIURI object representing the URI of the document. This only works for privileged (UniversalXPConnect) scripts, including extension code. For web content this property doesn't have any special meaning and can be used just like any other custom property. Privileged code must be careful not to try getting or setting this property on a non-wrapped content object (e.g., on a wrapped
JSObject of an XPCNativeWrapper). See bug 324464's comments for details. Syntax var uri = document.documentURIObject; Example // Check that the URI scheme of the current tab in Firefox is 'http', // assuming this code runs in context of browser.xul let uriObj = content.document.documentURIObject; let uriPort = uriObj.port; if (uriObj.schemeIs('http')) { ... } Specifications Not part of any spec...
Document.open() - Web APIs
this method is subject to the same same-origin policy as other properties, and does not work if doing so would change the document's origin. Starting with Gecko 1.9.2, document.open() uses the principal of the document whose URI it uses, instead of fetching the principal off the stack. As a result, you can no longer call document.write() into an untrusted document from chrome, even using wrapped
JSObject. See Security check basics for more about principals. Three-argument document.open() There is a lesser-known and little-used three-argument version of document.open() , which is an alias of Window.open() (see its page for full details). This call, for example opens github.com in a new window, with its opener set to null: document.open('https://www.github.com','', 'noopener=true') Two-argumen...
How to check the security state of an XMLHTTPRequest over SSL - Web APIs
really hard to // do on b2g18. On mozilla-central we want a proper TCPError that ideally // sub-classes DOMError. Bug 867872 has been filed to implement this and // contains a documented TCPError.webidl that maps all the error codes we use in // this file to slightly more readable explanations. ...