abstract out GC root manipulation for js values

This commit is contained in:
Vincent Sanders 2012-12-04 18:15:14 +00:00
parent 897acff532
commit 0718d80918
2 changed files with 11 additions and 2 deletions

View File

@ -315,14 +315,14 @@ js_dom_event_add_listener(jscontext *ctx,
JSLOG("adding %p to listener", private);
JS_AddValueRoot(cx, &private->funcval);
JSAPI_ADD_VALUE_ROOT(cx, &private->funcval);
exc = dom_event_target_add_event_listener(private->node,
private->type,
private->listener,
true);
if (exc != DOM_NO_ERR) {
JSLOG("failed to add listener");
JS_RemoveValueRoot(cx, &private->funcval);
JSAPI_REMOVE_VALUE_ROOT(cx, &private->funcval);
}
return true;

View File

@ -150,6 +150,9 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
#define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddRoot(cx, obj)
#define JSAPI_REMOVE_OBJECT_ROOT(cx, obj) JS_RemoveRoot(cx, obj)
#define JSAPI_ADD_VALUE_ROOT(cx, obj) JS_AddRoot(cx, obj)
#define JSAPI_REMOVE_VALUE_ROOT(cx, obj) JS_RemoveRoot(cx, obj)
#elif JS_VERSION == 180
/************************** Spidermonkey 1.8.0 **************************/
@ -263,6 +266,9 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
#define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddRoot(cx, obj)
#define JSAPI_REMOVE_OBJECT_ROOT(cx, obj) JS_RemoveRoot(cx, obj)
#define JSAPI_ADD_VALUE_ROOT(cx, obj) JS_AddRoot(cx, obj)
#define JSAPI_REMOVE_VALUE_ROOT(cx, obj) JS_RemoveRoot(cx, obj)
#else /* #if JS_VERSION == 180 */
@ -365,6 +371,9 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
#define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddObjectRoot(cx, obj)
#define JSAPI_REMOVE_OBJECT_ROOT(cx, obj) JS_RemoveObjectRoot(cx, obj)
#define JSAPI_ADD_VALUE_ROOT(cx, val) JS_AddValueRoot(cx, val)
#define JSAPI_REMOVE_VALUE_ROOT(cx, val) JS_RemoveValueRoot(cx, val)
#endif
#define JSLOG(args...) LOG((args))