-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Inline Class#new. #13080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline Class#new. #13080
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,20 @@ | |
require 'objspace' | ||
|
||
describe "ObjectSpace.trace_object_allocations" do | ||
def has_class_frame? | ||
Class.new { | ||
attr_reader :c | ||
|
||
def initialize | ||
@c = caller_locations.first.label =~ /new/ | ||
end | ||
}.new.c | ||
end | ||
|
||
def obj_class_path | ||
has_class_frame? ? "Class" : nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Notably the spec no longer works on TruffleRuby because of the changed expectations due to this commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if CRuby would return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eregon We could probably do that, but to be honest I think we should delete these tests (or update them not to run inside anonymous blocks). As you noted, returning For example: require "objspace"
class Foo
def test
ObjectSpace.trace_object_allocations do
o = Object.new
p ObjectSpace.allocation_class_path(o)
p ObjectSpace.allocation_method_id(o)
end
end
end
Foo.new.test
1.times do
ObjectSpace.trace_object_allocations do
o = Object.new
p ObjectSpace.allocation_class_path(o)
p ObjectSpace.allocation_method_id(o)
end
end Output is this:
The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, we'll refactor those specs to move the |
||
end | ||
|
||
it "runs a block" do | ||
ScratchPad.clear | ||
ObjectSpace.trace_object_allocations do | ||
|
@@ -13,7 +27,7 @@ | |
it "records info for allocation_class_path" do | ||
ObjectSpace.trace_object_allocations do | ||
o = Object.new | ||
ObjectSpace.allocation_class_path(o).should == "Class" | ||
ObjectSpace.allocation_class_path(o).should == obj_class_path | ||
a = [1, 2, 3] | ||
ObjectSpace.allocation_class_path(a).should == nil | ||
end | ||
|
@@ -31,7 +45,7 @@ | |
it "records info for allocation_method_id" do | ||
ObjectSpace.trace_object_allocations do | ||
o = Object.new | ||
ObjectSpace.allocation_method_id(o).should == :new | ||
ObjectSpace.allocation_method_id(o).should == (has_class_frame? ? :new : nil) | ||
a = [1, 2, 3] | ||
ObjectSpace.allocation_method_id(a).should == nil | ||
end | ||
|
@@ -58,7 +72,7 @@ | |
it "can be cleared using trace_object_allocations_clear" do | ||
ObjectSpace.trace_object_allocations do | ||
o = Object.new | ||
ObjectSpace.allocation_class_path(o).should == "Class" | ||
ObjectSpace.allocation_class_path(o).should == obj_class_path | ||
ObjectSpace.trace_object_allocations_clear | ||
ObjectSpace.allocation_class_path(o).should be_nil | ||
end | ||
|
@@ -69,14 +83,14 @@ | |
ObjectSpace.trace_object_allocations do | ||
o = Object.new | ||
end | ||
ObjectSpace.allocation_class_path(o).should == "Class" | ||
ObjectSpace.allocation_class_path(o).should == obj_class_path | ||
end | ||
|
||
it "can be used without a block using trace_object_allocations_start and _stop" do | ||
ObjectSpace.trace_object_allocations_start | ||
begin | ||
o = Object.new | ||
ObjectSpace.allocation_class_path(o).should == "Class" | ||
ObjectSpace.allocation_class_path(o).should == obj_class_path | ||
a = [1, 2, 3] | ||
ObjectSpace.allocation_class_path(a).should == nil | ||
ensure | ||
|
@@ -91,14 +105,14 @@ | |
ensure | ||
ObjectSpace.trace_object_allocations_stop | ||
end | ||
ObjectSpace.allocation_class_path(o).should == "Class" | ||
ObjectSpace.allocation_class_path(o).should == obj_class_path | ||
end | ||
|
||
it "can be nested" do | ||
ObjectSpace.trace_object_allocations do | ||
ObjectSpace.trace_object_allocations do | ||
o = Object.new | ||
ObjectSpace.allocation_class_path(o).should == "Class" | ||
ObjectSpace.allocation_class_path(o).should == obj_class_path | ||
end | ||
end | ||
end | ||
|
@@ -109,7 +123,7 @@ | |
ObjectSpace.trace_object_allocations_start | ||
begin | ||
o = Object.new | ||
ObjectSpace.allocation_class_path(o).should == "Class" | ||
ObjectSpace.allocation_class_path(o).should == obj_class_path | ||
ensure | ||
ObjectSpace.trace_object_allocations_stop | ||
end | ||
|
@@ -122,7 +136,7 @@ | |
ObjectSpace.trace_object_allocations_start | ||
begin | ||
o = Object.new | ||
ObjectSpace.allocation_class_path(o).should == "Class" | ||
ObjectSpace.allocation_class_path(o).should == obj_class_path | ||
ObjectSpace.trace_object_allocations_stop | ||
ensure | ||
ObjectSpace.trace_object_allocations_stop | ||
|
Uh oh!
There was an error while loading. Please reload this page.