diff options
| author | NARUSE, Yui <nurse@users.noreply.github.com> | 2024-03-21 10:45:01 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-21 01:45:01 +0000 |
| commit | a63e979853783601a60228b45741f8b3776e5507 (patch) | |
| tree | 8396278af85906d600486360bfb7e466aaef6161 /spec/ruby/core/binding | |
| parent | a406c516685f1950269c4e43d13cc748f0bfbc06 (diff) | |
merge revision(s) d19d683a354530a27b4cbb049223f8dc70c75849,de1a586ecc2ee7f465f0c0a69291054136a3a819: [Backport #20250] (#10308)
rb_obj_setup: do not copy RUBY_FL_SEEN_OBJ_ID
[Bug #20250]
We're seting up a new instance, so it never had an associated
object_id.
proc.c: get rid of `CLONESETUP`
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[Bug #20253]
All the way down to Ruby 1.9, `Proc`, `Method`, `UnboundMethod`
and `Binding` always had their own specific clone and dup routine.
This caused various discrepancies with how other objects behave
on `dup` and `clone. [Bug #20250], [Bug #20253].
This commit get rid of `CLONESETUP` and use the the same codepath
as all other types, so ensure consistency.
NB: It's still not accepting the `freeze` keyword argument on `clone`.
Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
Diffstat (limited to 'spec/ruby/core/binding')
| -rw-r--r-- | spec/ruby/core/binding/clone_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/core/binding/dup_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/core/binding/shared/clone.rb | 22 |
3 files changed, 34 insertions, 0 deletions
diff --git a/spec/ruby/core/binding/clone_spec.rb b/spec/ruby/core/binding/clone_spec.rb index ebd40f5377..f1769ac6de 100644 --- a/spec/ruby/core/binding/clone_spec.rb +++ b/spec/ruby/core/binding/clone_spec.rb @@ -4,4 +4,10 @@ require_relative 'shared/clone' describe "Binding#clone" do it_behaves_like :binding_clone, :clone + + it "preserves frozen status" do + bind = binding.freeze + bind.frozen?.should == true + bind.clone.frozen?.should == true + end end diff --git a/spec/ruby/core/binding/dup_spec.rb b/spec/ruby/core/binding/dup_spec.rb index 43968213c8..55fac6e333 100644 --- a/spec/ruby/core/binding/dup_spec.rb +++ b/spec/ruby/core/binding/dup_spec.rb @@ -4,4 +4,10 @@ require_relative 'shared/clone' describe "Binding#dup" do it_behaves_like :binding_clone, :dup + + it "resets frozen status" do + bind = binding.freeze + bind.frozen?.should == true + bind.dup.frozen?.should == false + end end diff --git a/spec/ruby/core/binding/shared/clone.rb b/spec/ruby/core/binding/shared/clone.rb index 0e934ac1b5..1224b8ec7d 100644 --- a/spec/ruby/core/binding/shared/clone.rb +++ b/spec/ruby/core/binding/shared/clone.rb @@ -31,4 +31,26 @@ describe :binding_clone, shared: true do b2.local_variable_defined?(:x).should == false end end + + ruby_version_is "3.4" do + it "copies instance variables" do + @b1.instance_variable_set(:@ivar, 1) + cl = @b1.send(@method) + cl.instance_variables.should == [:@ivar] + end + + it "copies the finalizer" do + code = <<-RUBY + obj = binding + + ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized\n" }) + + obj.clone + + exit 0 + RUBY + + ruby_exe(code).lines.sort.should == ["finalized\n", "finalized\n"] + end + end end |
