Skip to content

Commit

Permalink
Throw a runtime error if #binding is called from a
Browse files Browse the repository at this point in the history
C ext module (non-ruby frame)

Co-authored-by: Randy Stauner <[email protected]>
  • Loading branch information
manefz and rwstauner committed Feb 2, 2024
1 parent 90bfaa0 commit 0c3f184
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/truffleruby/core/kernel/KernelNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ RubyBinding binding(Frame callerFrame, Object self, Object[] rubyArgs, RootCallT
@Cached(
value = "getAdoptedNode(this).getEncapsulatingSourceSection()",
allowUncached = true, neverDefault = false) SourceSection sourceSection) {
final InternalMethod method = RubyArguments.tryGetMethod(callerFrame);
if (method == null || method.getDeclaringModule().toString().equals("Truffle::CExt")) {
throw new RaiseException(getContext(),
coreExceptions().runtimeError("You cannot call Kernel#Binding from a non-ruby frame", this));

}
needCallerFrame(callerFrame, target);
return BindingNodes.createBinding(getContext(), getLanguage(), callerFrame.materialize(), sourceSection);
}
Expand Down

0 comments on commit 0c3f184

Please sign in to comment.