1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* eval.c (proc_set_safe_level, proc_invoke, rb_mod_define_method): not

set $SAFE for methods defined from Proc.  [ruby-dev:23697]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2004-06-19 04:27:08 +00:00
parent 934064ba5a
commit 33b8591248
3 changed files with 42 additions and 3 deletions

View file

@ -91,4 +91,35 @@ class TestProc < Test::Unit::TestCase
assert_equal(10, Proc.new{|&b| b.call(10)}.call {|x| x})
assert_equal(12, Proc.new{|a,&b| b.call(a)}.call(12) {|x| x})
end
def test_safe
safe = $SAFE
c = Class.new
x = c.new
p = proc {
$SAFE += 1
proc {$SAFE}
}.call
assert_equal(safe, $SAFE)
assert_equal(safe + 1, p.call)
assert_equal(safe, $SAFE)
c.class_eval {define_method(:safe, p)}
assert_equal(safe, x.safe)
assert_equal(safe, x.method(:safe).call)
assert_equal(safe, x.method(:safe).to_proc.call)
p = proc {$SAFE += 1}
assert_equal(safe + 1, p.call)
assert_equal(safe, $SAFE)
c.class_eval {define_method(:inc, p)}
assert_equal(safe + 1, proc {x.inc; $SAFE}.call)
assert_equal(safe, $SAFE)
assert_equal(safe + 1, proc {x.method(:inc).call; $SAFE}.call)
assert_equal(safe, $SAFE)
assert_equal(safe + 1, proc {x.method(:inc).to_proc.call; $SAFE}.call)
assert_equal(safe, $SAFE)
end
end