[前][次][番号順一覧][スレッド一覧]

ruby-changes:60035

From: Koichi <ko1@a...>
Date: Thu, 13 Feb 2020 15:23:07 +0900 (JST)
Subject: [ruby-changes:60035] 580edc25aa (ruby_2_7): script_compiled event on compile error.

https://git.ruby-lang.org/ruby.git/commit/?id=580edc25aa

From 580edc25aa00930bdb71b244d70a2007905f5fec Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Mon, 6 Jan 2020 11:36:51 +0900
Subject: script_compiled event on compile error.

script_compiled event for TracePoint should not be invoked on
compile error (SyntaxError) because it is not "compiled".
[Bug #16459]

diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index 316e14e..ada7b75 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -2188,10 +2188,19 @@ class TestSetTraceFunc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L2188
                   [__FILE__+"/instance_eval", eval_script],
                   [__FILE__+"/class_eval", eval_script],
                  ], events
+
     events.clear
+    tp.enable{
+      begin
+        eval('a=')
+      rescue SyntaxError
+      end
+    }
+    assert_equal [], events, 'script_compiled event should not be invoked on compile error'
 
     skip "TODO: test for requires"
 
+    events.clear
     tp.enable{
       require ''
       require_relative ''
diff --git a/vm_eval.c b/vm_eval.c
index 24d8dcf..76e56fa 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1552,7 +1552,7 @@ eval_make_iseq(VALUE src, VALUE fname, int line, const rb_binding_t *bind, https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1552
     const VALUE parser = rb_parser_new();
     const rb_iseq_t *const parent = vm_block_iseq(base_block);
     VALUE realpath = Qnil;
-    rb_iseq_t *iseq = 0;
+    rb_iseq_t *iseq = NULL;
     rb_ast_t *ast;
 
     if (!fname) {
@@ -1583,12 +1583,14 @@ eval_make_iseq(VALUE src, VALUE fname, int line, const rb_binding_t *bind, https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1583
     }
     rb_ast_dispose(ast);
 
-    if (0 && iseq) {		/* for debug */
-	VALUE disasm = rb_iseq_disasm(iseq);
-	printf("%s\n", StringValuePtr(disasm));
-    }
+    if (iseq != NULL) {
+        if (0 && iseq) {		/* for debug */
+            VALUE disasm = rb_iseq_disasm(iseq);
+            printf("%s\n", StringValuePtr(disasm));
+        }
 
-    rb_exec_event_hook_script_compiled(GET_EC(), iseq, src);
+        rb_exec_event_hook_script_compiled(GET_EC(), iseq, src);
+    }
 
     return iseq;
 }
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]