--- title: JSClass.flags slug: JSAPI_Reference/JSClass.flags translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSClass.flags ---
{{SpiderMonkeySidebar("JSAPI")}}

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

JSCLASS_HAS_PRIVATE

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") }}

JSCLASS_PRIVATE_IS_NSISUPPORTS

Mozilla extension. The private field of each object of this class points to an XPCOM object (see nsISupports). This is only meaningful if SpiderMonkey is built with XPConnect and the JSCLASS_HAS_PRIVATE flag is also set.

{{ LXRSearch("ident", "i", "JSCLASS_PRIVATE_IS_NSISUPPORTS") }}

JSCLASS_IS_DOMJSCLASS

{{ 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 undefined in certain circumstances.  An object obj that emulates undefined behaves like any other object, except in the following ways:

  • typeof obj === "undefined"
  • obj converts to false when obj is converted to a boolean when used in boolean contexts (if conditions, loop continuation/termination conditions [for/while/do { } while], the condition in a ternary ?: expression, and so on)
  • (obj == undefined) is true, and (obj != undefined) is false
  • (obj == null) is true, and (obj != null) is false

== and != comparisons to values other than null or undefined (including to an object that emulates undefined) are unaffected by this flag.  Strict equality (=== and !==) comparisons are also unaffected by this flag.

{{ LXRSearch("ident", "i", "JSCLASS_EMULATES_UNDEFINED") }}

JSCLASS_HAS_RESERVED_SLOTS(n)

Indicates that instances of this class have n reserved slots. n is an integer in the range {{ mediawiki.external('0..255') }}. The slots initially contain unspecified valid jsval values. They can be accessed using {{jsapixref("JS_GetReservedSlot")}} and {{jsapixref("JS_GetReservedSlot", "JS_SetReservedSlot")}}.

(The {{jsapixref("JSClass.reserveSlots")}} hook also allocates reserved slots to objects.)

{{ LXRSearch("ident", "i", "JSCLASS_HAS_RESERVED_SLOTS") }}

JSCLASS_GLOBAL_FLAGS

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 Function objects. If the global object does not have this flag, then scripts may cause nonstandard behavior by replacing standard constructors or prototypes (such as Function.prototype.)

Objects that can end up with the wrong prototype object, if this flag is not present, include: arguments objects (ECMA 262-3 §10.1.8 specifies "the original Object prototype"), Function objects (ECMA 262-3 §13.2 specifies "the original Function prototype"), and objects created by many standard constructors (ECMA 262-3 §15.4.2.1 and others).

{{ 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_FOREGROUND_FINALIZE and JSCLASS_BACKGROUND_FINALIZE must be specified.

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_FOREGROUND_FINALIZE and JSCLASS_BACKGROUND_FINALIZE must be specified.

JSCLASS_IMPLEMENTS_BARRIERS {{ obsolete_inline("jsapi43") }} Correctly implements GC read and write barriers.

JSCLASS_NEW_ENUMERATE

{{ obsolete_inline("jsapi37") }} This class's enumerate hook is actually a {{jsapixref("JSClass.enumerate", "JSNewEnumerateOp")}}, not a {{jsapixref("JSEnumerateOp")}}.

JSCLASS_NEW_RESOLVE

{{ obsolete_inline("jsapi36") }} This class's resolve hook is actually a {{jsapixref("JSNewResolveOp")}}, not a {{jsapixref("JSClass.resolve", "JSResolveOp")}}.

JSCLASS_SHARE_ALL_PROPERTIES

{{ obsolete_inline("js1.8.5") }} Instructs SpiderMonkey to automatically give all properties of objects of this class the {{jsapixref("JS_GetPropertyAttributes", "JSPROP_SHARED")}} attribute.

JSCLASS_NEW_RESOLVE_GETS_START

{{ 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.)

JSCLASS_CONSTRUCT_PROTOTYPE

{{ obsolete_inline("jsapi11") }} Instructs {{jsapixref("JS_InitClass")}} to invoke the constructor when creating the class prototype.

JSCLASS_IS_EXTENDED

{{ obsolete_inline("jsapi17") }}Indicates that this JSClass is really a {{jsapixref("JSExtendedClass")}}.

JSCLASS_MARK_IS_TRACE

{{ 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.

See Also