From ad55116193bcaef9f8da0f58ca2a30db9dd0d4f6 Mon Sep 17 00:00:00 2001 From: olabini Date: Wed, 26 Mar 2008 20:26:50 +0000 Subject: [PATCH] Partial fix for JRUBY-2328 git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@6346 961051c9-f516-0410-bf72-c9f7e237a7b7 --- src/org/jruby/Ruby.java | 4 ++-- src/org/jruby/runtime/ThreadContext.java | 8 ++++++++ test/test_load.rb | 24 +++++++++++++++++++++++- test/test_loading_behavior.rb | 1 + 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 test/test_loading_behavior.rb diff --git a/src/org/jruby/Ruby.java b/src/org/jruby/Ruby.java index c2119f7f4..d7cb921b4 100644 --- a/src/org/jruby/Ruby.java +++ b/src/org/jruby/Ruby.java @@ -1849,7 +1849,7 @@ public final class Ruby { try { secure(4); /* should alter global state */ - context.preNodeEval(objectClass, self); + context.preNodeEval(objectClass, self, scriptName); Node node = parseFile(in, scriptName, null); ASTInterpreter.eval(this, context, node, self, Block.NULL_BLOCK); @@ -1872,7 +1872,7 @@ public final class Ruby { try { secure(4); /* should alter global state */ - context.preNodeEval(objectClass, self); + context.preNodeEval(objectClass, self, filename); Node scriptNode = parseFile(in, filename, null); diff --git a/src/org/jruby/runtime/ThreadContext.java b/src/org/jruby/runtime/ThreadContext.java index fad252f18..775b5507d 100644 --- a/src/org/jruby/runtime/ThreadContext.java +++ b/src/org/jruby/runtime/ThreadContext.java @@ -739,6 +739,14 @@ public final class ThreadContext { getCurrentScope().getStaticScope().setModule(objectClass); } + public void preNodeEval(RubyModule rubyClass, IRubyObject self, String name) { + setFile(name); + pushRubyClass(rubyClass); + pushCallFrame(null, name, self, Block.NULL_BLOCK, null); + // set visibility to private, since toplevel of scripts always started out private + setCurrentVisibility(Visibility.PRIVATE); + } + public void preNodeEval(RubyModule rubyClass, IRubyObject self) { pushRubyClass(rubyClass); pushCallFrame(null, null, self, Block.NULL_BLOCK, null); diff --git a/test/test_load.rb b/test/test_load.rb index 1df29a581..13cdc862e 100644 --- a/test/test_load.rb +++ b/test/test_load.rb @@ -1,5 +1,9 @@ require 'test/unit' +def load_behavior_block(&block) + eval("__FILE__", block.binding) +end + class TestLoad < Test::Unit::TestCase def test_require # Allow us to run MRI against non-Java dependent tests @@ -41,4 +45,22 @@ class TestLoad < Test::Unit::TestCase require 'hello_from_jar' assert "hi", $hello end -end \ No newline at end of file + + def test_overriding_require_shouldnt_cause_problems + eval(<