--- title: JSClass.flags slug: JSAPI_Reference/JSClass.flags translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSClass.flags ---
The {{jsapixref("JSClass", "JSClass.flags")}} field allows an application to enable optional JSClass
features on a per-class basis.
The flags
field is of type uint32_t
. Its value is the logical OR of zero or more of the following constants:
Flag | Meaning |
---|---|
|
This class uses private data. If this flag is set, each instance of the class has a field for private data. The field can be accessed using {{jsapixref("JS_GetPrivate")}} and {{jsapixref("JS_SetPrivate")}}. {{ LXRSearch("ident", "i", "JSCLASS_HAS_PRIVATE") }} |
|
Mozilla extension. The private field of each object of this class points to an XPCOM object (see {{ LXRSearch("ident", "i", "JSCLASS_PRIVATE_IS_NSISUPPORTS") }} |
|
{{ Jsapi_minversion_inline("17") }} Objects are DOM. {{ LXRSearch("ident", "i", "JSCLASS_IS_DOMJSCLASS") }} |
JSCLASS_EMULATES_UNDEFINED |
{{ Jsapi_minversion_inline("24") }} Causes objects which have this class to emulate
{{ LXRSearch("ident", "i", "JSCLASS_EMULATES_UNDEFINED") }} |
|
Indicates that instances of this class have (The {{jsapixref("JSClass.reserveSlots")}} hook also allocates reserved slots to objects.) {{ LXRSearch("ident", "i", "JSCLASS_HAS_RESERVED_SLOTS") }} |
|
This flag is only relevant for the class of an object that is used as a global object. (ECMAScript specifies a single global object, but in SpiderMonkey the global object is the last object in the {{jsapixref("JS_GetScopeChain", "scope chain", "", 1)}}, which can be different objects at different times. This is actually quite subtle. {{jsapixref("JS_ExecuteScript")}} and similar APIs set the global object for the code they execute. {{jsapixref("JS_SetGlobalObject")}} sets an object which is sometimes used as the global object, as a last resort.) Enable standard ECMAScript behavior for setting the prototype of certain objects, such as Objects that can end up with the wrong prototype object, if this flag is not present, include: {{ LXRSearch("ident", "i", "JSCLASS_GLOBAL_FLAGS") }} |
JSCLASS_FOREGROUND_FINALIZE |
Objects of this class must be finalized on the main thread. If this class has a finalizer that makes use of state shared with the main thread then this option must be specified. It is always safe to specify this option. One of |
JSCLASS_BACKGROUND_FINALIZE |
It is safe to finalize objects of this class on a background thread. If this class has a finalizer that can be safely run concurrently with the main thread then this option can be specified. It results in finalization work being offloaded to another thread which improves performance. One of |
JSCLASS_IMPLEMENTS_BARRIERS |
{{ obsolete_inline("jsapi43") }} Correctly implements GC read and write barriers. |
|
{{ obsolete_inline("jsapi37") }} This class's enumerate hook is actually a {{jsapixref("JSClass.enumerate", "JSNewEnumerateOp")}}, not a {{jsapixref("JSEnumerateOp")}}. |
|
{{ obsolete_inline("jsapi36") }} This class's resolve hook is actually a {{jsapixref("JSNewResolveOp")}}, not a {{jsapixref("JSClass.resolve", "JSResolveOp")}}. |
|
{{ obsolete_inline("js1.8.5") }} Instructs SpiderMonkey to automatically give all properties of objects of this class the {{jsapixref("JS_GetPropertyAttributes", "JSPROP_SHARED")}} attribute. |
|
{{ obsolete_inline("jsapi16") }} The resolve hook expects to receive the starting object in the prototype chain passed in via the *objp in/out parameter. (This is meaningful only if the JSCLASS_NEW_RESOLVE flag is also set.) |
|
{{ obsolete_inline("jsapi11") }} Instructs {{jsapixref("JS_InitClass")}} to invoke the constructor when creating the class prototype. |
|
{{ obsolete_inline("jsapi17") }}Indicates that this JSClass is really a {{jsapixref("JSExtendedClass")}}. |
|
{{ obsolete_inline("jsapi5") }} Indicates that the {{jsapixref("JSClass.mark", "mark")}} hook implements the new {{jsapixref("JSTraceOp")}} signature instead of the old {{jsapixref("JSClass.mark", "JSMarkOp")}} signature. This is recommended for all new code that needs custom marking. |
SpiderMonkey reserves a few other flags for its internal use. They are JSCLASS_IS_ANONYMOUS
, JSCLASS_IS_GLOBAL
, JSCLASS_IS_PROXY
, and JSCLASS_HAS_CACHED_PROTO
. JSAPI applications should not use these flags.
JSCLASS_SHARE_ALL_PROPERTIES
JSCLASS_IS_EXTENDED
JSCLASS_MARK_IS_TRACE
JSCLASS_IMPLEMENTS_BARRIERS
JSCLASS_CONSTRUCT_PROTOTYPE
JSCLASS_NEW_RESOLVE_GETS_START
JSCLASS_IS_DOMJSCLASS
JSCLASS_EMULATES_UNDEFINED
JSCLASS_NEW_RESOLVE
JSCLASS_NEW_ENUMERATE