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
using the runtime for exception raising
tenderlove (author)
Sat May 31 14:00:24 -0700 2008
commit  3ba6b82bee91202cd1d7011bee1b6f1af0996297
tree    027e6e91454b60f6b1d511a2346b5821c4a3e168
parent  59807b0f2fbcd193aeec31f8676bffad951fc772
...
241
242
243
 
244
245
 
246
247
248
...
241
242
243
244
245
 
246
247
248
249
0
@@ -241,8 +241,9 @@ NORETURN(void) raise_js_error_in_ruby(JohnsonRuntime* runtime)
0
   }
0
 
0
   VALUE ruby_context = (VALUE)JS_GetContextPrivate(context);
0
+  VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(runtime->js);
0
   if (johnson_context->ex)
0
-    rb_funcall(ruby_context, rb_intern("handle_js_exception"),
0
+    rb_funcall(ruby_runtime, rb_intern("handle_js_exception"),
0
       1, convert_to_ruby(runtime, johnson_context->ex));
0
 
0
   if (!johnson_context->msg)
...
616
617
618
619
620
621
622
 
 
 
 
623
624
625
626
627
 
 
628
629
630
 
631
632
633
...
616
617
618
 
 
 
 
619
620
621
622
623
 
 
 
 
624
625
626
627
 
628
629
630
631
0
@@ -616,18 +616,16 @@ print = function(txt) { Ruby.puts(txt); };
0
             handleResponse();
0
           }
0
         } else { 
0
-          connection = Ruby.Net.HTTP.start(url.host, url.port, function(http) {
0
-            var out_headers = new Ruby.Hash;
0
-            for (var header in self.headers)
0
-              out_headers[header] = self.headers[header];
0
+          var http = Ruby.Net.HTTP.new(url.host, url.port);
0
+          var request = new Ruby.Net.HTTP.Get(url.path);
0
+          for (var header in self.headers)
0
+            request.add_field(header, self.headers[header]);
0
 
0
-            http.send_request( self.method, url.path, nil, out_headers );            
0
-          });
0
-          
0
-          connection.instance_variable_get("@header").each(function(k, v) {
0
+          var connection = http.request(request);
0
+          connection.each_header(function(k,v) {
0
             self.responseHeaders[k] = v;
0
           });
0
-                    
0
+
0
           handleResponse();
0
         }
0
         
...
202
203
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
206
207
...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
0
@@ -202,6 +202,24 @@ module Johnson
0
         asplode = lambda { raise err }
0
         assert_js_equal(err, "x = null; try { foo(); } catch(ex) { x = ex; }; x", :foo => asplode)
0
       end
0
+
0
+      # FIXME: If you uncomment this test, we get this error:
0
+      #
0
+      # JS API usage error: the address passed to JS_AddNamedRoot currently holds an
0
+      # invalid jsval.  This is usually caused by a missing call to JS_RemoveRoot.
0
+      # The root's name is "ruby_land_proxy.c[210]:native_call: proxy_value".
0
+      # Assertion failure: root_points_to_gcArenaList, at jsgc.c:2618
0
+      # 
0
+      # WTF?
0
+      #
0
+      # -Aaron
0
+      #
0
+      #def test_throwing_in_js_goes_to_ruby
0
+      #  func = @runtime.evaluate('function () { throw "foo"; }')
0
+      #  assert_raise(Johnson::Error) {
0
+      #    func.call
0
+      #  }
0
+      #end
0
     end
0
   end
0
 end

Comments