public
Description: Johnson wraps JavaScript in a loving Ruby embrace.
Homepage: http://github.com/jbarnette/johnson/wikis
Clone URL: git://github.com/jbarnette/johnson.git
Root both gcthings and global.
matthewd (author)
Sat May 31 19:51:22 -0700 2008
commit  dc9c9cb4769a1acb15be6c089dd324e24fa75584
tree    855e38e6665d51257e846be7ce697d4f045ab9b5
parent  947c557bb8b54f75e236c09209492dce5d650b36
...
155
156
157
 
158
159
160
...
166
167
168
 
169
170
 
171
172
173
 
 
174
175
176
...
155
156
157
158
159
160
161
...
167
168
169
170
171
 
172
173
174
175
176
177
178
179
180
0
@@ -155,6 +155,7 @@ initialize_native(VALUE self, VALUE UNUSED(options))
0
   JohnsonRuntime* runtime;
0
   Data_Get_Struct(self, JohnsonRuntime, runtime);
0
   
0
+  bool global_rooted_p = false;
0
   bool gcthings_rooted_p = false;
0
 
0
   if ((runtime->js = JS_NewRuntime(0x100000))
0
@@ -166,11 +167,14 @@ initialize_native(VALUE self, VALUE UNUSED(options))
0
     JSContext* context = johnson_get_current_context(runtime);
0
     if(
0
         (runtime->gcthings = JS_NewObject(context, NULL, 0, 0))
0
+        &&(gcthings_rooted_p = JS_AddNamedRoot(context, &(runtime->gcthings), "runtime->gcthings"))
0
         &&(runtime->global = JS_GetGlobalObject(context))
0
-        &&(gcthings_rooted_p = JS_AddNamedRoot(context, &(runtime->global), "runtime->global"))
0
+        &&(global_rooted_p = JS_AddNamedRoot(context, &(runtime->global), "runtime->global"))
0
     ) {
0
       return self;
0
     }
0
+    if (global_rooted_p)
0
+      JS_RemoveRoot(context, &(runtime->global));
0
     if (gcthings_rooted_p)
0
       JS_RemoveRoot(context, &(runtime->gcthings));
0
   }

Comments