<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/johnson/error.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,7 +1,6 @@
 #include &quot;context.h&quot;
 #include &quot;conversions.h&quot;
 #include &quot;global.h&quot;
-#include &quot;error.h&quot;
 #include &quot;extensions.h&quot;
 #include &quot;idhash.h&quot;
 #include &quot;jsdbgapi.h&quot;</diff>
      <filename>ext/spidermonkey/context.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,6 @@
 #include &quot;conversions.h&quot;
 #include &quot;js_land_proxy.h&quot;
 #include &quot;ruby_land_proxy.h&quot;
-#include &quot;error.h&quot;
 
 DEFINE_RUBY_WRAPPER(convert_to_ruby, convert_to_ruby, ARGLIST2(runtime, js_value))
 
@@ -116,7 +115,7 @@ JSBool convert_to_js(JohnsonRuntime* runtime, VALUE ruby, jsval* retval)
       return make_js_land_proxy(runtime, ruby, retval);
     
     default:
-      Johnson_Error_raise(&quot;unknown ruby type in switch&quot;);
+      rb_raise(rb_eRuntimeError, &quot;unknown ruby type in switch&quot;);
   }
   
   *retval = JSVAL_NULL;
@@ -240,16 +239,17 @@ NORETURN(void) raise_js_error_in_ruby(JohnsonRuntime* runtime)
     JS_RemoveRoot(context, &amp;(johnson_context-&gt;ex));
   }
 
-  VALUE ruby_context = (VALUE)JS_GetContextPrivate(context);
   VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(runtime-&gt;js);
   if (johnson_context-&gt;ex)
-    rb_funcall(ruby_runtime, rb_intern(&quot;handle_js_exception&quot;),
-      1, convert_to_ruby(runtime, johnson_context-&gt;ex));
+    RAISE_JS_ERROR(ruby_runtime, johnson_context-&gt;ex);
 
+  // FIXME: I don't think this is needed, it should
+  // be done on the Ruby side.
   if (!johnson_context-&gt;msg)
-    Johnson_Error_raise(&quot;Unknown JavaScript Error&quot;);
+    rb_raise(rb_eRuntimeError, &quot;Unknown JavaScriptError&quot;);
 
-  Johnson_Error_raise(johnson_context-&gt;msg);
+  // FIXME: I don't think this can ever happen....
+  rb_raise(rb_eRuntimeError, johnson_context-&gt;msg);
 }
 
 #define TAG_RAISE 0x6</diff>
      <filename>ext/spidermonkey/conversions.c</filename>
    </modified>
    <modified>
      <diff>@@ -152,7 +152,7 @@
     char _jroot_msg[_JROOT_ERRSIZE]; \
     snprintf(_jroot_msg, _JROOT_ERRSIZE, (format) , ## args); \
     if (_jroot_ruby) \
-      Johnson_Error_raise(_jroot_msg); \
+      rb_raise(rb_eRuntimeError,  _jroot_msg); \
     else \
     { \
       JSString* _jroot_err_str = JS_NewStringCopyZ(_jroot_context, _jroot_msg); \</diff>
      <filename>ext/spidermonkey/jroot.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,5 @@
 #include &quot;ruby_land_proxy.h&quot;
 #include &quot;conversions.h&quot;
-#include &quot;error.h&quot;
 
 DECLARE_RUBY_WRAPPER(rb_call_super, int argc; const VALUE* argv)
 DEFINE_RUBY_WRAPPER(rb_call_super, rb_call_super, ARGLIST2(argc, argv))
@@ -193,8 +192,9 @@ respond_to_p(VALUE self, VALUE sym)
 static VALUE
 native_call(int argc, VALUE* argv, VALUE self)
 {
+  // FIXME: This should really call super#native_call.
   if (!function_p(self))
-    Johnson_Error_raise(&quot;This Johnson::SpiderMonkey::RubyLandProxy isn't a function.&quot;);
+    rb_raise(rb_eRuntimeError, &quot;This Johnson::SpiderMonkey::RubyLandProxy isn't a function.&quot;);
 
   if (argc &lt; 1)
     rb_raise(rb_eArgError, &quot;Target object required&quot;);</diff>
      <filename>ext/spidermonkey/ruby_land_proxy.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,4 @@
 #include &quot;runtime.h&quot;
-#include &quot;error.h&quot;
 #include &quot;global.h&quot;
 #include &quot;idhash.h&quot;
 #include &quot;conversions.h&quot;
@@ -57,40 +56,10 @@ static VALUE evaluate(int argc, VALUE* argv, VALUE self)
       JS_ClearPendingException(context);
     }
 
-    if (johnson_context-&gt;ex)
-    {
-      return rb_funcall(self, rb_intern(&quot;handle_js_exception&quot;),
-        1, convert_to_ruby(runtime, johnson_context-&gt;ex));
-      
-      // VALUE message, file, line, stack;
-      // 
-      // jsval js_message;
-      // assert(JS_GetProperty(context-&gt;js, JSVAL_TO_OBJECT(context-&gt;ex), &quot;message&quot;, &amp;js_message));
-      // message = convert_to_ruby(context, js_message);
-      // 
-      // jsval js_file;
-      // assert(JS_GetProperty(context-&gt;js, JSVAL_TO_OBJECT(context-&gt;ex), &quot;fileName&quot;, &amp;js_file));
-      // file = convert_to_ruby(context, js_file);
-      // 
-      // jsval js_line;
-      // assert(JS_GetProperty(context-&gt;js, JSVAL_TO_OBJECT(context-&gt;ex), &quot;lineNumber&quot;, &amp;js_line));
-      // line = convert_to_ruby(context, js_line);
-      // 
-      // jsval js_stack;
-      // assert(JS_GetProperty(context-&gt;js, JSVAL_TO_OBJECT(context-&gt;ex), &quot;stack&quot;, &amp;js_stack));
-      // stack = convert_to_ruby(context, js_stack);
-      // 
-      // return rb_funcall(self, rb_intern(&quot;handle_js_exception&quot;),
-      //   4, message, file, line, stack);
+    if (johnson_context-&gt;ex) {
+      RAISE_JS_ERROR(self, johnson_context-&gt;ex);
+      return Qnil;
     }
-    
-    char* msg = johnson_context-&gt;msg;
-
-    // toString() whatever the exception object is (if we have one)
-    if (johnson_context-&gt;ex)
-      msg = JS_GetStringBytes(JS_ValueToString(context, johnson_context-&gt;ex));
-
-    return Johnson_Error_raise(msg);
   }
 
   return convert_to_ruby(runtime, js);
@@ -189,7 +158,8 @@ initialize_native(VALUE self, VALUE UNUSED(options))
   if (runtime-&gt;js)
     JS_DestroyRuntime(runtime-&gt;js);
     
-  return Johnson_Error_raise(&quot;Couldn't initialize the runtime!&quot;);
+  rb_raise(rb_eRuntimeError, &quot;Couldn't initialize the runtime!&quot;);
+  return Qnil;
 }
 
 JSContext* johnson_get_current_context(JohnsonRuntime * runtime)</diff>
      <filename>ext/spidermonkey/runtime.c</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,14 @@
 
 #include &quot;spidermonkey.h&quot;
 
+#define RAISE_JS_ERROR(rb_runtime, ex) \
+  do {\
+    JohnsonRuntime * _rt = NULL;\
+    Data_Get_Struct(rb_runtime, JohnsonRuntime, _rt);\
+    rb_funcall(CLASS_OF(rb_runtime), rb_intern(&quot;raise_js_exception&quot;), 1,\
+      convert_to_ruby(_rt, ex)); \
+  } while(0)
+
 typedef struct {
   JSObject* global;
   JSRuntime* js;</diff>
      <filename>ext/spidermonkey/runtime.h</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,5 @@
 #include &quot;spidermonkey.h&quot;
 #include &quot;context.h&quot;
-#include &quot;error.h&quot;
 #include &quot;ruby_land_proxy.h&quot;
 #include &quot;debugger.h&quot;
 #include &quot;immutable_node.h&quot;
@@ -10,7 +9,6 @@ void Init_spidermonkey()
   VALUE johnson = rb_define_module(&quot;Johnson&quot;); // FIXME: this belongs outside the extension
   VALUE spidermonkey = rb_define_module_under(johnson, &quot;SpiderMonkey&quot;);
   
-  init_Johnson_Error(johnson); // FIXME: this belongs outside the extension
   init_Johnson_SpiderMonkey_Context(spidermonkey);
   init_Johnson_SpiderMonkey_Proxy(spidermonkey);
   init_Johnson_SpiderMonkey_Debugger(spidermonkey);</diff>
      <filename>ext/spidermonkey/spidermonkey.c</filename>
    </modified>
    <modified>
      <diff>@@ -68,7 +68,7 @@ Johnson.require = function(file) {
     }
   }
   
-  throw LoadError;
+  throw Ruby.LoadError;
 }
 
 null; // no need to marshal a result</diff>
      <filename>js/johnson/prelude.js</filename>
    </modified>
    <modified>
      <diff>@@ -24,6 +24,7 @@ require &quot;johnson/spidermonkey/debugger&quot;
 require &quot;johnson/spidermonkey/immutable_node&quot;
 
 # the 'public' interface
+require &quot;johnson/error&quot;
 require &quot;johnson/runtime&quot;
 require &quot;johnson/parser&quot;
 </diff>
      <filename>lib/johnson.rb</filename>
    </modified>
    <modified>
      <diff>@@ -19,23 +19,25 @@ module Johnson #:nodoc:
         global[key] = value
       end
 
-      protected
-      
-      def handle_js_exception(jsex)
-        raise jsex if Exception === jsex
-        raise Johnson::Error.new(jsex.to_s) unless Johnson::SpiderMonkey::RubyLandProxy === jsex
-        
-        # FIXME: sanitize stack traces
-        stack = jsex.stack rescue nil
-        
-        ex = Johnson::Error.new(jsex)
-        if stack
-          ex.set_backtrace(stack.split(&quot;\n&quot;) + caller)
-        else
-          ex.set_backtrace(caller)
+      class &lt;&lt; self
+        def raise_js_exception(jsex)
+          raise jsex if Exception === jsex
+          raise Johnson::Error.new(jsex.to_s) unless Johnson::SpiderMonkey::RubyLandProxy === jsex
+
+          stack = jsex.stack rescue nil
+
+          message = jsex['message'] || jsex.to_s
+          at = &quot;(#{jsex['fileName']}):#{jsex['lineNumber']}&quot;
+          ex = Johnson::Error.new(&quot;#{message} at #{at}&quot;)
+          if stack
+            js_caller = stack.split(&quot;\n&quot;).find_all { |x| x != '@:0' }
+            ex.set_backtrace(js_caller + caller)
+          else
+            ex.set_backtrace(caller)
+          end
+
+          raise ex
         end
-        
-        raise ex
       end
     end
   end</diff>
      <filename>lib/johnson/spidermonkey/runtime.rb</filename>
    </modified>
    <modified>
      <diff>@@ -57,7 +57,7 @@ module Johnson
       end
       
       def test_calling_non_functions_complains
-        assert_raise(Johnson::Error) { @runtime.evaluate(&quot;new Object()&quot;).call }
+        assert_raise(RuntimeError) { @runtime.evaluate(&quot;new Object()&quot;).call }
       end
       
       def test_functions_can_be_called</diff>
      <filename>test/johnson/spidermonkey/ruby_land_proxy_test.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>ext/spidermonkey/error.c</filename>
    </removed>
    <removed>
      <filename>ext/spidermonkey/error.h</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>ab1e446a5d21481038a96a04a88585eb34bcaa1e</id>
    </parent>
  </parents>
  <author>
    <name>Aaron Patterson</name>
    <email>aaron.patterson@gmail.com</email>
  </author>
  <url>http://github.com/jbarnette/johnson/commit/d4969c6bdba5740518c2b4ae625a9037287465cc</url>
  <id>d4969c6bdba5740518c2b4ae625a9037287465cc</id>
  <committed-date>2008-06-01T13:59:39-07:00</committed-date>
  <authored-date>2008-06-01T13:59:39-07:00</authored-date>
  <message>Making exceptions better.</message>
  <tree>7130ce198274333298a8d3714eee06ec9757e360</tree>
  <committer>
    <name>Aaron Patterson</name>
    <email>aaron.patterson@gmail.com</email>
  </committer>
</commit>
