diff options
author | Jean Boussier <[email protected]> | 2025-03-27 10:34:17 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-03-28 12:44:53 +0900 |
commit | 756b75f2421008a46ee68390c683ca2c1a0ddc31 (patch) | |
tree | babcd374b16cae7ab40c11be176e32661a693b5d /ext/json | |
parent | 96ecac1e245aaac4484f69a731d2af4328760a8e (diff) |
[ruby/json] Remove `Class#json_creatable?` monkey patch.
https://github.com/ruby/json/commit/1ca7efed1f
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13004
Diffstat (limited to 'ext/json')
-rw-r--r-- | ext/json/lib/json/common.rb | 11 | ||||
-rw-r--r-- | ext/json/parser/parser.c | 13 |
2 files changed, 11 insertions, 13 deletions
diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb index 30fdbe1db2..c47152e383 100644 --- a/ext/json/lib/json/common.rb +++ b/ext/json/lib/json/common.rb @@ -951,14 +951,3 @@ module ::Kernel JSON.generate(object, args.first) end end - -# Extends any Class to include _json_creatable?_ method. -class ::Class - # Returns true if this class can be used to create an instance - # from a serialised JSON string. The class has to implement a class - # method _json_create_ that expects a hash as first parameter. The hash - # should include the required data. - def json_creatable? - respond_to?(:json_create) - end -end diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c index d990612a2b..d2d0d38d84 100644 --- a/ext/json/parser/parser.c +++ b/ext/json/parser/parser.c @@ -790,6 +790,15 @@ static inline VALUE json_decode_array(JSON_ParserState *state, JSON_ParserConfig return array; } +static bool json_obj_creatable_p(VALUE klass) +{ + if (rb_respond_to(klass, i_json_creatable_p)) { + return RTEST(rb_funcall(klass, i_json_creatable_p, 0)); + } else { + return rb_respond_to(klass, i_json_create); + } +} + static inline VALUE json_decode_object(JSON_ParserState *state, JSON_ParserConfig *config, long count) { VALUE object; @@ -818,7 +827,7 @@ static inline VALUE json_decode_object(JSON_ParserState *state, JSON_ParserConfi } if (!NIL_P(klassname)) { VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname); - if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) { + if (json_obj_creatable_p(klass)) { if (config->deprecated_create_additions) { json_deprecated(deprecated_create_additions_warning); } @@ -837,7 +846,7 @@ static inline VALUE json_decode_object(JSON_ParserState *state, JSON_ParserConfi static int match_i(VALUE regexp, VALUE klass, VALUE memo) { if (regexp == Qundef) return ST_STOP; - if (RTEST(rb_funcall(klass, i_json_creatable_p, 0)) && + if (json_obj_creatable_p(klass) && RTEST(rb_funcall(regexp, i_match, 1, rb_ary_entry(memo, 0)))) { rb_ary_push(memo, klass); return ST_STOP; |