public
Rubygem
Description: Johnson wraps JavaScript in a loving Ruby embrace.
Homepage: http://github.com/jbarnette/johnson/wikis
Clone URL: git://github.com/jbarnette/johnson.git
Search Repo:
making sure to raise on compile errors!
aaronp (author)
Wed Jun 18 19:39:15 -0700 2008
commit  23c2473ca9b8a737d32031fe032a9c6fdfb7f6d0
tree    b60dcb4f9b9bc9e2a3f53f0e0c0d9076d3676a3d
parent  7edecccae03b3aaccbe6bcdf5622b2fb7b433eb5
...
62
63
64
 
65
66
67
...
71
72
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
76
77
...
62
63
64
65
66
67
68
...
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
0
@@ -62,6 +62,7 @@ static VALUE native_compile(VALUE self, VALUE script, VALUE filename, VALUE line
0
   Data_Get_Struct(self, JohnsonRuntime, runtime);
0
 
0
   JSContext * context = johnson_get_current_context(runtime);
0
+ JohnsonContext * johnson_context = OUR_CONTEXT(context);
0
 
0
   JSScript * compiled_js = JS_CompileScript(
0
       context,
0
@@ -71,7 +72,22 @@ static VALUE native_compile(VALUE self, VALUE script, VALUE filename, VALUE line
0
       StringValueCStr(filename),
0
       (unsigned)NUM2INT(linenum)
0
   );
0
+ if(compiled_js == NULL) {
0
+ if (JS_IsExceptionPending(context))
0
+ {
0
+ // If there's an exception pending here, it's a syntax error.
0
+ JS_GetPendingException(context, &johnson_context->ex);
0
+ JS_ClearPendingException(context);
0
+ }
0
+
0
+ if (johnson_context->ex) {
0
+ RAISE_JS_ERROR(self, johnson_context->ex);
0
+ return Qnil;
0
+ }
0
+ }
0
+
0
   JSObject * script_object = JS_NewScriptObject(context, compiled_js);
0
+
0
   PREPARE_RUBY_JROOTS(context, 1);
0
   JROOT(script_object);
0
   JRETURN_RUBY(make_ruby_land_proxy(runtime, OBJECT_TO_JSVAL(script_object)));
...
26
27
28
29
 
 
30
31
32
...
26
27
28
 
29
30
31
32
33
0
@@ -26,7 +26,8 @@ module Johnson #:nodoc:
0
       ###
0
       # Evaluate +script+ with +filename+ and +linenum+
0
       def evaluate(script, filename = nil, linenum = nil)
0
- evaluate_compiled_script(compile(script, filename, linenum))
0
+ compiled_script = compile(script, filename, linenum)
0
+ evaluate_compiled_script(compiled_script)
0
       end
0
 
0
       ###
...
14
15
16
 
 
 
 
 
 
 
 
 
17
18
19
...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
0
@@ -14,6 +14,15 @@ module Johnson
0
       assert_equal(1, @runtime.evaluate('eval("1");'))
0
     end
0
 
0
+ def test_js_throws_compile_errors
0
+ assert_raises(Johnson::Error) {
0
+ @runtime.evaluate("var js_lambda = function(x) { return x ** 2; }")
0
+ }
0
+ assert_raises(Johnson::Error) {
0
+ @runtime.compile("var js_lambda = function(x) { return x ** 2; }")
0
+ }
0
+ end
0
+
0
     def test_breakpoint_gets_called
0
       break_times = 0
0
       @runtime['some_number'] = 0

Comments

    No one has commented yet.