JSClass.flags 编辑

The 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:

FlagMeaning

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 JS_GetPrivate and JS_SetPrivate.

MXR ID Search for 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.

MXR ID Search for JSCLASS_PRIVATE_IS_NSISUPPORTS

JSCLASS_IS_DOMJSCLASS

Added in SpiderMonkey 17 Objects are DOM.

MXR ID Search for JSCLASS_IS_DOMJSCLASS

JSCLASS_EMULATES_UNDEFINED

Added in SpiderMonkey 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.

MXR ID Search for 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 [0..255]. The slots initially contain unspecified valid jsval values. They can be accessed using JS_GetReservedSlot and JS_SetReservedSlot.

(The JSClass.reserveSlots hook also allocates reserved slots to objects.)

MXR ID Search for 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 scope chain, which can be different objects at different times. This is actually quite subtle. JS_ExecuteScript and similar APIs set the global object for the code they execute. 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).

MXR ID Search for 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_BARRIERSObsolete since JSAPI 43 Correctly implements GC read and write barriers.

JSCLASS_NEW_ENUMERATE

Obsolete since JSAPI 37 This class's enumerate hook is actually a JSNewEnumerateOp, not a JSEnumerateOp.

JSCLASS_NEW_RESOLVE

Obsolete since JSAPI 36 This class's resolve hook is actually a JSNewResolveOp, not a JSResolveOp.

JSCLASS_SHARE_ALL_PROPERTIES

Obsolete since JavaScript 1.8.5 Instructs SpiderMonkey to automatically give all properties of objects of this class the JSPROP_SHARED attribute.

JSCLASS_NEW_RESOLVE_GETS_START

Obsolete since JSAPI 16 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 since JSAPI 11 Instructs JS_InitClass to invoke the constructor when creating the class prototype.

JSCLASS_IS_EXTENDED

Obsolete since JSAPI 17Indicates that this JSClass is really a JSExtendedClass.

JSCLASS_MARK_IS_TRACE

Obsolete since JSAPI 5 Indicates that the mark hook implements the new JSTraceOp signature instead of the old 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:135 次

字数:12254

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文