Permalink
Browse files

Use JS_SetOperationCallback if available

Newer SpiderMonkey drops support for JS_SetBranchCallback.
  • Loading branch information...
1 parent 31b6558 commit 4e2b6e0bfced5a373845fa5e863618045e2c403a @matthewd committed May 14, 2010
Showing with 18 additions and 0 deletions.
  1. +4 −0 extconf.rb
  2. +14 −0 spidermonkey.c
View
@@ -23,6 +23,10 @@ def find_smjs(mozjs)
%w(xulrunner-js thunderbird-js mozilla-js).any? do |package|
PKGConfig.have_package(package)
end
+
+ have_func("JS_SetOperationCallback")
+ have_func("JS_SetBranchCallback")
+
create_makefile("spidermonkey")
else
exit 1
View
@@ -135,8 +135,12 @@ typedef VALUE(* RBSMJS_Convert)( JSContext* cx, jsval val );
static VALUE RBSMContext_FROM_JsContext( JSContext* cx );
#ifdef BRANCH_GC
+#if defined HAVE_JS_SETOPERATIONCALLBACK
+static JSBool rbsm_operation_callback( JSContext* cx );
+#elif defined HAVE_JS_SETBRANCHCALLBACK
static JSBool rbsm_branch_callback( JSContext* cx, JSScript* script );
#endif
+#endif
static JSBool rbsm_class_get_property( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
static JSBool rbsm_class_get_temp_property( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
static JSBool rbsm_class_set_property( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
@@ -710,7 +714,13 @@ RBSMContext_TO_JsContext( VALUE context ){
#ifdef BRANCH_GC
static JSBool
+#if defined HAVE_JS_SETOPERATIONCALLBACK
+rbsm_operation_callback( JSContext* cx ){
+#elif defined HAVE_JS_SETBRANCHCALLBACK
rbsm_branch_callback( JSContext* cx, JSScript* script ){
+#else
+#error "BRANCH_GC is defined, but we don't have JS_SetOperationCallback OR JS_SetBranchCallback"
+#endif
if( ++gSMJS_counter % BRANCH_GC == 0 )
JS_MaybeGC( cx );
return JS_TRUE;
@@ -1915,8 +1925,12 @@ rb_smjs_context_initialize( int argc, VALUE* argv, VALUE self ){
rb_raise( eJSError, "Failed to create context" );
#ifdef BRANCH_GC
+#if defined HAVE_JS_SETOPERATIONCALLBACK
+ JS_SetOperationCallback( cs->cx, rbsm_operation_callback );
+#elif defined HAVE_JS_SETBRANCHCALLBACK
JS_SetBranchCallback( cs->cx, rbsm_branch_callback );
#endif
+#endif
JS_SetOptions( cs->cx, JS_GetOptions( cs->cx )
#ifdef JSOPTION_DONT_REPORT_UNCAUGHT

0 comments on commit 4e2b6e0

Please sign in to comment.