mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Exit when the object is frozen
Exit when the object is frozen, also add tests
This commit is contained in:
parent
376f5ec1a1
commit
640b162b51
3 changed files with 41 additions and 0 deletions
|
@ -1,3 +1,25 @@
|
|||
# Check that frozen objects are respected
|
||||
assert_equal 'great', %q{
|
||||
class Foo
|
||||
attr_accessor :bar
|
||||
def initialize
|
||||
@bar = 1
|
||||
freeze
|
||||
end
|
||||
end
|
||||
|
||||
foo = Foo.new
|
||||
|
||||
5.times do
|
||||
begin
|
||||
foo.bar = 2
|
||||
rescue FrozenError
|
||||
end
|
||||
end
|
||||
|
||||
foo.bar == 1 ? "great" : "NG"
|
||||
}
|
||||
|
||||
# Check that global variable set works
|
||||
assert_equal 'string', %q{
|
||||
def foo
|
||||
|
|
|
@ -75,6 +75,20 @@ class TestYJIT < Test::Unit::TestCase
|
|||
assert_no_exits('"i am a string #{true}"')
|
||||
end
|
||||
|
||||
def test_compile_attr_set
|
||||
assert_no_exits(<<~EORB)
|
||||
class Foo
|
||||
attr_accessor :bar
|
||||
end
|
||||
|
||||
foo = Foo.new
|
||||
foo.bar = 3
|
||||
foo.bar = 3
|
||||
foo.bar = 3
|
||||
foo.bar = 3
|
||||
EORB
|
||||
end
|
||||
|
||||
def test_compile_regexp
|
||||
assert_no_exits('/#{true}/')
|
||||
end
|
||||
|
|
|
@ -1447,6 +1447,11 @@ gen_set_ivar(jitstate_t *jit, ctx_t *ctx, const int max_chain_depth, VALUE compt
|
|||
VALUE comptime_val_klass = CLASS_OF(comptime_receiver);
|
||||
const ctx_t starting_context = *ctx; // make a copy for use with jit_chain_guard
|
||||
|
||||
ADD_COMMENT(cb, "guard self is not frozen");
|
||||
x86opnd_t flags_opnd = member_opnd(REG0, struct RBasic, flags);
|
||||
test(cb, flags_opnd, imm_opnd(RUBY_FL_FREEZE));
|
||||
jnz_ptr(cb, COUNTED_EXIT(side_exit, setivar_frozen));
|
||||
|
||||
// If the class uses the default allocator, instances should all be T_OBJECT
|
||||
// NOTE: This assumes nobody changes the allocator of the class after allocation.
|
||||
// Eventually, we can encode whether an object is T_OBJECT or not
|
||||
|
|
Loading…
Reference in a new issue