diff options
author | John Hawthorn <john@hawthorn.email> | 2022-09-14 13:15:55 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-14 16:15:55 -0400 |
commit | f98d6d3f389e8e46775c5895ddc1a3eec4544533 (patch) | |
tree | 1267208755ae53ad583c71a81826772ed31ebcdd /bootstraptest | |
parent | d5cdc2edd02eb6990d045c932aaedb60213143e1 (diff) | |
download | ruby-f98d6d3f389e8e46775c5895ddc1a3eec4544533.tar.gz |
YJIT: Implement specialized respond_to? (#6363)
* Add rb_callable_method_entry_or_negative
* YJIT: Implement specialized respond_to?
This implements a specialized respond_to? in YJIT.
* Update yjit/src/codegen.rs
Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Diffstat (limited to 'bootstraptest')
-rw-r--r-- | bootstraptest/test_yjit.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index 364ed7094b..2dff7d591a 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -3255,3 +3255,57 @@ assert_equal '[1, 2]', %q{ foo foo } + +# respond_to? with changing symbol +assert_equal 'false', %q{ + def foo(name) + :sym.respond_to?(name) + end + foo(:to_s) + foo(:to_s) + foo(:not_exist) +} + +# respond_to? with method being defined +assert_equal 'true', %q{ + def foo + :sym.respond_to?(:not_yet_defined) + end + foo + foo + module Kernel + def not_yet_defined = true + end + foo +} + +# respond_to? with undef method +assert_equal 'false', %q{ + module Kernel + def to_be_removed = true + end + def foo + :sym.respond_to?(:to_be_removed) + end + foo + foo + class Object + undef_method :to_be_removed + end + foo +} + +# respond_to? with respond_to_missing? +assert_equal 'true', %q{ + class Foo + end + def foo(x) + x.respond_to?(:bar) + end + foo(Foo.new) + foo(Foo.new) + class Foo + def respond_to_missing?(*) = true + end + foo(Foo.new) +} |