diff --git a/src/main/java/org/truffleruby/core/kernel/KernelNodes.java b/src/main/java/org/truffleruby/core/kernel/KernelNodes.java index b1da3d150421..7f1f4c655c70 100644 --- a/src/main/java/org/truffleruby/core/kernel/KernelNodes.java +++ b/src/main/java/org/truffleruby/core/kernel/KernelNodes.java @@ -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); }