diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2019-10-17 13:30:09 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-10-31 10:39:47 +0900 |
commit | bd1c2748cbcb5f75c8a045ba3ca12ac1b710ebdd (patch) | |
tree | bfd28f3dada7358c79f0c6fbc3aab11addd523d8 /tests | |
parent | 8d8e1aa70297d55034e3f6a4ce2f32300294b2a4 (diff) | |
download | json-bd1c2748cbcb5f75c8a045ba3ca12ac1b710ebdd.tar.gz |
Look up constant instead of caching in a global
The global can go bad if the compactor runs, so we need to look up the
constant instead of caching it in a global.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/json_generator_test.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/json_generator_test.rb b/tests/json_generator_test.rb index 86be398..a85bd11 100644 --- a/tests/json_generator_test.rb +++ b/tests/json_generator_test.rb @@ -40,6 +40,43 @@ class JSONGeneratorTest < Test::Unit::TestCase EOT end + def silence + v = $VERBOSE + $VERBOSE = nil + yield + ensure + $VERBOSE = v + end + + def test_remove_const_segv + stress = GC.stress + const = JSON::SAFE_STATE_PROTOTYPE.dup + + bignum_too_long_to_embed_as_string = 1234567890123456789012345 + expect = bignum_too_long_to_embed_as_string.to_s + GC.stress = true + + 10.times do |i| + tmp = bignum_too_long_to_embed_as_string.to_json + raise "'\#{expect}' is expected, but '\#{tmp}'" unless tmp == expect + end + + silence do + JSON.const_set :SAFE_STATE_PROTOTYPE, nil + end + + 10.times do |i| + assert_raise TypeError do + bignum_too_long_to_embed_as_string.to_json + end + end + ensure + GC.stress = stress + silence do + JSON.const_set :SAFE_STATE_PROTOTYPE, const + end + end + def test_generate json = generate(@hash) assert_equal(parse(@json2), parse(json)) |