Skip to content

Commit

Permalink
Frame name for module/class bodies should be null
Browse files Browse the repository at this point in the history
There's no super and __method__ should return nil inside module
and class bodies, so we pass null to indicate this.
  • Loading branch information
headius committed Mar 28, 2024
1 parent f7dbc18 commit 4302ab9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private IRubyObject INTERPRET_CLASS(InterpreterContext ic, ThreadContext context
private IRubyObject interpretWithBacktrace(InterpreterContext ic, ThreadContext context, IRubyObject self, String name, Block block) {
try {
ThreadContext.pushBacktrace(context, name, ic.getFileName(), ic.getLine());
return ic.getEngine().interpret(context, null, self, ic, getImplementationClass().getMethodLocation(), name, block);
return ic.getEngine().interpret(context, null, self, ic, getImplementationClass().getMethodLocation(), null, block);
} finally {
ThreadContext.popBacktrace(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private IRubyObject INTERPRET_CLASS(ThreadContext context, RubyModule clazz) {

try {
ThreadContext.pushBacktrace(context, id, ic.getFileName(), ic.getLine());
return ic.getEngine().interpret(context, null, clazz, ic, clazz.getMethodLocation(), id, Block.NULL_BLOCK);
return ic.getEngine().interpret(context, null, clazz, ic, clazz.getMethodLocation(), null, Block.NULL_BLOCK);
} finally {
body.cleanupAfterExecution();
if (!hasExplicitCallProtocol) post(ic, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private IRubyObject INTERPRET_MODULE(ThreadContext context, RubyModule clazz) {

try {
ThreadContext.pushBacktrace(context, id, ic.getFileName(), ic.getLine());
return ic.getEngine().interpret(context, null, clazz, ic, clazz.getMethodLocation(), id, Block.NULL_BLOCK);
return ic.getEngine().interpret(context, null, clazz, ic, clazz.getMethodLocation(), null, Block.NULL_BLOCK);
} finally {
body.cleanupAfterExecution();
if (!hasExplicitCallProtocol) post(ic, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public IRubyObject getFrameName(ThreadContext context, IRubyObject self, String
return frameNameSite.call(context, self, self);
}

if (compositeName == null) return context.nil;

return callee ?
RubySymbol.newCalleeSymbolFromCompound(context.runtime, compositeName):
RubySymbol.newMethodSymbolFromCompound(context.runtime, compositeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@ public static void defCompiledInstanceMethod(ThreadContext context, MethodHandle
public static IRubyObject invokeModuleBody(ThreadContext context, DynamicMethod method) {
RubyModule implClass = method.getImplementationClass();

return method.call(context, implClass, implClass, "", Block.NULL_BLOCK);
return method.call(context, implClass, implClass, null, Block.NULL_BLOCK);
}

@JIT
Expand Down
11 changes: 8 additions & 3 deletions core/src/main/java/org/jruby/ir/targets/indy/FrameNameSite.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jruby.ir.targets.indy;

import com.headius.invokebinder.Binder;
import org.jruby.RubyNil;
import org.jruby.RubySymbol;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -58,7 +59,7 @@ public IRubyObject frameNameFallback(String name, ThreadContext context, IRubyOb
if (entry.method.isBuiltin()) {
target = Binder.from(type())
.permute(2)
.append(context.runtime.getSymbolTable())
.append(context.runtime.getSymbolTable(), context.nil)
.prepend(this)
.invokeVirtualQuiet(methodName);
} else {
Expand All @@ -72,14 +73,18 @@ public IRubyObject frameNameFallback(String name, ThreadContext context, IRubyOb
return (IRubyObject) target.invokeExact(context, self, frameName);
}

public IRubyObject __callee__(String frameName, RubySymbol.SymbolTable symbolTable) {
public IRubyObject __callee__(String frameName, RubySymbol.SymbolTable symbolTable, RubyNil nil) {
if (frameName == null) return nil;

if (frameName.charAt(0) != '\0') {
return getSimpleName(frameName, symbolTable);
}
return symbolTable.getCalleeSymbolFromCompound(frameName);
}

public IRubyObject __method__(String frameName, RubySymbol.SymbolTable symbolTable) {
public IRubyObject __method__(String frameName, RubySymbol.SymbolTable symbolTable, RubyNil nil) {
if (frameName == null) return nil;

if (frameName.charAt(0) != '\0') {
return getSimpleName(frameName, symbolTable);
}
Expand Down

0 comments on commit 4302ab9

Please sign in to comment.