-
-
Notifications
You must be signed in to change notification settings - Fork 920
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
NoMethodError for ObjectSpace::WeakMap#values #6267
Comments
This is required to support rsim/oracle-enhanced#2027 |
Let me update that his issue needs to be addressed to support rails/rails#39121 . |
Should be easy enough to support. |
Ok, so I don't have a problem with adding the missing features from Weakmap, but officially it is not a public API. It has never been discussed (naming, behavior, etc) and I believe that needs to happen before it sees usage in third-party libraries. Unfortunately that would mean this should not be used until after Ruby 2.8/3.0, though JRuby would probably implement everything that CRuby provides in our 9.3 release. https://bugs.ruby-lang.org/issues/16959 I'd like to get some feedback on this before we proceed to implement the rest of Weakmap just because CRuby does it that way. |
FWIW I don't fault you for using the feature... it's sorely needed in Ruby, as I've pointed out in my ReferenceQueue issue (linked from the Ruby issue above), and now that there's specs it's hard to tell that it's not a public API. |
Thanks for the update. I with |
FWIW this can be implemented in Ruby using some JRuby internal APIs (non-public, but useful for cases like this): require 'jruby'
class org::jruby::RubyObjectSpace::WeakMap
field_reader :map
end
class ObjectSpace::WeakMap
def values
JRuby.ref(self).map.values.reject(&:nil?)
end
end
# Example usage follows...
wm = ObjectSpace::WeakMap.new
x = nil
# This is inside a block to avoid references leaking to the main scope
tap {
wm["foo"] = Object.new
wm["bar"] = x = Object.new
p wm.values # [#<Object:0x62e136d3>, #<Object:0x51b7e5df>]
}
5.times { JRuby.gc }
p wm.values # [#<Object:0x62e136d3>] The |
Refer jruby/jruby#6267 (comment) Co-authored-by: Charles Oliver Nutter <headius@headius.com>
Refer jruby/jruby#6267 (comment) Co-authored-by: Charles Oliver Nutter <headius@headius.com>
Environment Information
jruby -v
) and command line (flags, JRUBY_OPTS, etc)uname -a
)Expected Behavior
weakmap.values
should return empty Array as CRuby does.Actual Behavior
It raises
NoMethodError
The text was updated successfully, but these errors were encountered: