Skip to content

Commit

Permalink
Use JS_SetOperationCallback if available
Browse files Browse the repository at this point in the history
Newer SpiderMonkey drops support for JS_SetBranchCallback.
  • Loading branch information
matthewd committed May 14, 2010
1 parent 31b6558 commit 4e2b6e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions spidermonkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1915,7 +1925,11 @@ 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 )
Expand Down

0 comments on commit 4e2b6e0

Please sign in to comment.