diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2019-10-17 13:30:09 -0700 |
---|---|---|
committer | Aaron Patterson <tenderlove@ruby-lang.org> | 2019-10-17 13:30:09 -0700 |
commit | 9026e12f93bb0f3f63d7449cdb5eabb2e660088f (patch) | |
tree | 290fad182af2cafdfd2952e052548007acbe48c5 /test/json | |
parent | ee821e90741ebedc6c7a3bb0e8b67e59f3a44022 (diff) |
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 'test/json')
-rw-r--r-- | test/json/json_generator_test.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/json/json_generator_test.rb b/test/json/json_generator_test.rb index d7f9ebeb68..3d9ab7a364 100644 --- a/test/json/json_generator_test.rb +++ b/test/json/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)) |