56
56
#define GJS_MODULE_PROP_FLAGS (JSPROP_PERMANENT | JSPROP_ENUMERATE)
58
/* priv_from_js_with_typecheck checks that the object is in fact an
59
* instance of the specified class before accessing its private data.
60
* Keep in mind that the function can return JS_TRUE and still fill the
61
* out parameter with NULL if the object is the prototype for a class
62
* without the JSCLASS_CONSTRUCT_PROTOTYPE flag or if it the class simply
63
* does not have any private data.
59
* Helper methods to access private data:
61
* do_base_typecheck: checks that object has the right JSClass, and possibly
62
* throw a TypeError exception if the check fails
63
* priv_from_js: accesses the object private field; as a debug measure,
64
* it also checks that the object is of a compatible
65
* JSClass, but it doesn't raise an exception (it
66
* wouldn't be of much use, if subsequent code crashes on
68
* priv_from_js_with_typecheck: a convenience function to call
69
* do_base_typecheck and priv_from_js
65
#define GJS_DEFINE_PRIV_FROM_JS(type, class) \
66
__attribute__((unused)) static JSBool \
67
priv_from_js_with_typecheck(JSContext *context, \
73
if (!JS_InstanceOf(context, object, &class, NULL)) \
75
*out = JS_GetInstancePrivate(context, object, &class, NULL); \
79
priv_from_js(JSContext *context, \
82
return JS_GetInstancePrivate(context, object, &class, NULL); \
71
#define GJS_DEFINE_PRIV_FROM_JS(type, class) \
72
__attribute__((unused)) static inline JSBool \
73
do_base_typecheck(JSContext *context, \
77
return gjs_typecheck_static_instance(context, object, &class, throw); \
80
priv_from_js(JSContext *context, \
83
return JS_GetInstancePrivate(context, object, &class, NULL); \
85
__attribute__((unused)) static JSBool \
86
priv_from_js_with_typecheck(JSContext *context, \
90
if (!do_base_typecheck(context, object, JS_FALSE)) \
92
*out = priv_from_js(context, object); \
86
#define GJS_DEFINE_DYNAMIC_PRIV_FROM_JS(type, class) \
87
__attribute__((unused)) static JSBool\
88
priv_from_js_with_typecheck(JSContext *context, \
95
result = gjs_get_instance_private_dynamic_with_typecheck(context, object, &class, NULL); \
102
priv_from_js(JSContext *context, \
105
return gjs_get_instance_private_dynamic(context, object, &class, NULL); \
96
#define GJS_DEFINE_DYNAMIC_PRIV_FROM_JS(type, class) \
97
__attribute__((unused)) static inline JSBool \
98
do_base_typecheck(JSContext *context, \
102
return gjs_typecheck_dynamic_instance(context, object, &class, throw); \
104
static inline type* \
105
priv_from_js(JSContext *context, \
108
return JS_GetPrivate(context, object); \
110
__attribute__((unused)) static JSBool \
111
priv_from_js_with_typecheck(JSContext *context, \
115
if (!do_base_typecheck(context, object, JS_FALSE)) \
117
*out = priv_from_js(context, object); \