Navigation Menu

Skip to content

Commit

Permalink
Fix defined?(::Object) logic in JIT. Partial fix for #2090.
Browse files Browse the repository at this point in the history
The current IR for this logic uses the runtime helper call
isDefinedConstantOrMethod, which can trigger exceptions on its own
(if e.g. the method lookup triggers an error?). Because of that
handler, this bug in the JIT was caught and swallowed, resulting
in the defined? returning nil. That is not correct behavior; only
the exceptions we would expect to be raised by these lookups
should be caught.

In addition, I don't believe the :: form can be used to call
methods (::foo doesn't parse), so the use of exception handling
and isDefinedConstOrMethod may be inappropriate here.
  • Loading branch information
headius committed Nov 4, 2014
1 parent 0e4c83c commit c3b80aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Expand Up @@ -1573,10 +1573,9 @@ public void RuntimeHelperCall(RuntimeHelperCall runtimehelpercall) {
break;
case IS_DEFINED_CONSTANT_OR_METHOD:
jvmMethod().loadContext();
jvmMethod().loadSelf();
visit(runtimehelpercall.getArgs()[0]);
jvmAdapter().ldc(((StringLiteral)runtimehelpercall.getArgs()[1]).getString());
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "isDefinedConstantOrMethod", sig(IRubyObject.class, ThreadContext.class, IRubyObject.class, IRubyObject.class, String.class));
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "isDefinedConstantOrMethod", sig(IRubyObject.class, ThreadContext.class, IRubyObject.class, String.class));
jvmStoreLocal(runtimehelpercall.getResult());
break;
case IS_DEFINED_NTH_REF:
Expand Down
6 changes: 6 additions & 0 deletions spec/compiler/general_spec.rb
Expand Up @@ -866,4 +866,10 @@ class JRUBY4925
expect(x).to eq Object
end
end

it "retrieves toplevel constants with ::Const form" do
run '::Object' do |x|
expect(x).to eq Object
end
end
end

0 comments on commit c3b80aa

Please sign in to comment.