| jsapi-util.h | | jsapi-util.h | |
| | | | |
| skipping to change at line 58 | | skipping to change at line 58 | |
| | | | |
| /* Flags that should be set on properties exported from native code modules
. | | /* Flags that should be set on properties exported from native code modules
. | |
| * Basically set these on API, but do NOT set them on data. | | * Basically set these on API, but do NOT set them on data. | |
| * | | * | |
| * READONLY: forbid setting prop to another value | | * READONLY: forbid setting prop to another value | |
| * PERMANENT: forbid deleting the prop | | * PERMANENT: forbid deleting the prop | |
| * ENUMERATE: allows copyProperties to work among other reasons to have it | | * ENUMERATE: allows copyProperties to work among other reasons to have it | |
| */ | | */ | |
| #define GJS_MODULE_PROP_FLAGS (JSPROP_PERMANENT | JSPROP_ENUMERATE) | | #define GJS_MODULE_PROP_FLAGS (JSPROP_PERMANENT | JSPROP_ENUMERATE) | |
| | | | |
|
| /* priv_from_js_with_typecheck checks that the object is in fact an | | /* | |
| * instance of the specified class before accessing its private data. | | * Helper methods to access private data: | |
| * Keep in mind that the function can return JS_TRUE and still fill the | | * | |
| * out parameter with NULL if the object is the prototype for a class | | * do_base_typecheck: checks that object has the right JSClass, and possibl | |
| * without the JSCLASS_CONSTRUCT_PROTOTYPE flag or if it the class simply | | y | |
| * does not have any private data. | | * throw a TypeError exception if the check fails | |
| | | * priv_from_js: accesses the object private field; as a debug measure, | |
| | | * it also checks that the object is of a compatible | |
| | | * JSClass, but it doesn't raise an exception (it | |
| | | * wouldn't be of much use, if subsequent code crashes on | |
| | | * NULL) | |
| | | * priv_from_js_with_typecheck: a convenience function to call | |
| | | * do_base_typecheck and priv_from_js | |
| */ | | */ | |
|
| #define GJS_DEFINE_PRIV_FROM_JS(type, class) \ | | #define GJS_DEFINE_PRIV_FROM_JS(type, class) \ | |
| __attribute__((unused)) static JSBool \ | | __attribute__((unused)) static inline JSBool \ | |
| priv_from_js_with_typecheck(JSContext *context, \ | | do_base_typecheck(JSContext *context, \ | |
| JSObject *object, \ | | JSObject *object, \ | |
| type **out) \ | | JSBool throw) \ | |
| {\ | | { \ | |
| if (!out) \ | | return gjs_typecheck_static_instance(context, object, &class, throw | |
| return JS_FALSE; \ | | ); \ | |
| if (!JS_InstanceOf(context, object, &class, NULL)) \ | | } \ | |
| return JS_FALSE; \ | | static inline type* \ | |
| *out = JS_GetInstancePrivate(context, object, &class, NULL); \ | | priv_from_js(JSContext *context, \ | |
| return JS_TRUE; \ | | JSObject *object) \ | |
| }\ | | { \ | |
| static type*\ | | return JS_GetInstancePrivate(context, object, &class, NULL); \ | |
| priv_from_js(JSContext *context, \ | | } \ | |
| JSObject *object) \ | | __attribute__((unused)) static JSBool \ | |
| {\ | | priv_from_js_with_typecheck(JSContext *context, \ | |
| return JS_GetInstancePrivate(context, object, &class, NULL); \ | | JSObject *object, \ | |
| | | type **out) \ | |
| | | { \ | |
| | | if (!do_base_typecheck(context, object, JS_FALSE)) \ | |
| | | return JS_FALSE; \ | |
| | | *out = priv_from_js(context, object); \ | |
| | | return JS_TRUE; \ | |
| } | | } | |
| | | | |
|
| #define GJS_DEFINE_DYNAMIC_PRIV_FROM_JS(type, class) \ | | #define GJS_DEFINE_DYNAMIC_PRIV_FROM_JS(type, class) \ | |
| __attribute__((unused)) static JSBool\ | | __attribute__((unused)) static inline JSBool \ | |
| priv_from_js_with_typecheck(JSContext *context, \ | | do_base_typecheck(JSContext *context, \ | |
| JSObject *object, \ | | JSObject *object, \ | |
| type **out) \ | | JSBool throw) \ | |
| {\ | | { \ | |
| type *result; \ | | return gjs_typecheck_dynamic_instance(context, object, &class, thro | |
| if (!out) \ | | w); \ | |
| return JS_FALSE; \ | | } \ | |
| result = gjs_get_instance_private_dynamic_with_typecheck(context, o | | static inline type* \ | |
| bject, &class, NULL); \ | | priv_from_js(JSContext *context, \ | |
| if (result == NULL) \ | | JSObject *object) \ | |
| return JS_FALSE; \ | | { \ | |
| *out = result; \ | | return JS_GetPrivate(context, object); \ | |
| return JS_TRUE; \ | | } \ | |
| }\ | | __attribute__((unused)) static JSBool \ | |
| static type*\ | | priv_from_js_with_typecheck(JSContext *context, \ | |
| priv_from_js(JSContext *context, \ | | JSObject *object, \ | |
| JSObject *object) \ | | type **out) \ | |
| {\ | | { \ | |
| return gjs_get_instance_private_dynamic(context, object, &class, NU | | if (!do_base_typecheck(context, object, JS_FALSE)) \ | |
| LL); \ | | return JS_FALSE; \ | |
| | | *out = priv_from_js(context, object); \ | |
| | | return JS_TRUE; \ | |
| } | | } | |
| | | | |
| /** | | /** | |
| * GJS_DEFINE_PROTO: | | * GJS_DEFINE_PROTO: | |
| * @tn: The name of the prototype, as a string | | * @tn: The name of the prototype, as a string | |
| * @cn: The name of the prototype, separated by _ | | * @cn: The name of the prototype, separated by _ | |
| * | | * | |
| * A convenience macro for prototype implementations. | | * A convenience macro for prototype implementations. | |
| */ | | */ | |
| #define GJS_DEFINE_PROTO(tn, cn) \ | | #define GJS_DEFINE_PROTO(tn, cn) \ | |
| | | | |
| skipping to change at line 229 | | skipping to change at line 243 | |
| const char *class_name, | | const char *class_name, | |
| JSClass *clasp, | | JSClass *clasp, | |
| JSNative constructor, | | JSNative constructor, | |
| uintN nargs, | | uintN nargs, | |
| JSPropertySpec *ps, | | JSPropertySpec *ps, | |
| JSFunctionSpec *fs, | | JSFunctionSpec *fs, | |
| JSPropertySpec *static_ps, | | JSPropertySpec *static_ps, | |
| JSFunctionSpec *static_fs); | | JSFunctionSpec *static_fs); | |
| void gjs_throw_constructor_error (JSContext *context); | | void gjs_throw_constructor_error (JSContext *context); | |
| | | | |
|
| void* gjs_get_instance_private_dynamic (JSContext *context, | | JSBool gjs_typecheck_static_instance (JSContext *context, | |
| JSObject *obj, | | JSObject *obj, | |
| JSClass *static_c | | JSClass *static_clasp, | |
| lasp, | | JSBool _throw); | |
| jsval *argv); | | JSBool gjs_typecheck_dynamic_instance (JSContext *context, | |
| void* gjs_get_instance_private_dynamic_with_typecheck (JSContext *context, | | JSObject *obj, | |
| JSObject *obj, | | JSClass *static_clasp, | |
| JSClass *static_c | | JSBool _throw); | |
| lasp, | | | |
| jsval *argv); | | | |
| | | | |
| JSObject* gjs_construct_object_dynamic (JSContext *context, | | JSObject* gjs_construct_object_dynamic (JSContext *context, | |
| JSObject *proto, | | JSObject *proto, | |
| uintN argc, | | uintN argc, | |
| jsval *argv); | | jsval *argv); | |
| JSObject* gjs_define_string_array (JSContext *context, | | JSObject* gjs_define_string_array (JSContext *context, | |
| JSObject *obj, | | JSObject *obj, | |
| const char *array_name, | | const char *array_name, | |
| gssize array_length
, | | gssize array_length
, | |
| const char **array_values
, | | const char **array_values
, | |
| uintN attrs); | | uintN attrs); | |
| void gjs_throw (JSContext *context, | | void gjs_throw (JSContext *context, | |
| const char *format, | | const char *format, | |
| ...) G_GNUC_PRINTF (2, 3); | | ...) G_GNUC_PRINTF (2, 3); | |
|
| | | void gjs_throw_custom (JSContext *context, | |
| | | const char *error_class, | |
| | | const char *format, | |
| | | ...) G_GNUC_PRINTF (3, 4); | |
| void gjs_throw_literal (JSContext *context, | | void gjs_throw_literal (JSContext *context, | |
| const char *string); | | const char *string); | |
| void gjs_throw_g_error (JSContext *context, | | void gjs_throw_g_error (JSContext *context, | |
| GError *error); | | GError *error); | |
| JSBool gjs_log_exception (JSContext *context, | | JSBool gjs_log_exception (JSContext *context, | |
| char **message_p); | | char **message_p); | |
| JSBool gjs_log_and_keep_exception (JSContext *context, | | JSBool gjs_log_and_keep_exception (JSContext *context, | |
| char **message_p); | | char **message_p); | |
| JSBool gjs_move_exception (JSContext *src_context, | | JSBool gjs_move_exception (JSContext *src_context, | |
| JSContext *dest_context
); | | JSContext *dest_context
); | |
| | | | |
End of changes. 5 change blocks. |
| 56 lines changed or deleted | | 73 lines changed or added | |
|