JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-4339

Kernel.load with wrap=true does not protect the global namespace of calling program

    Details

    • Number of attachments :
      2

      Description

      The rubydoc for Kernel#load explicitly states about the wrap parameter:

      "If the optional wrap parameter is true, the loaded script will be executed under an anonymous module, protecting the calling program's global namespace."

      But JRuby doesn't provide such protection at the moment.

      This caused one rubyspec failure:

      1)
      Kernel#load allows wrapping the code in the file in an anonymous module FAILED
      Expected "constant"
       to equal nil
      
      /opt/work/rubyspec.git/core/kernel/load_spec.rb:233
      /opt/work/rubyspec.git/core/kernel/load_spec.rb:31
      /opt/work/rubyspec.git/core/kernel/load_spec.rb:55:in `load'
      /opt/work/mspec.git/bin/mspec-run:8
      
      Finished in 0.461000 seconds
      

      Attached also a standalone example that exhibits the problem. Run load_test.rb and you'll see:

      Z:\work\samples>ruby load_test.rb
      "main – 31095610"
      "MAIN: main – 31128780"
      nil
      nil

      Z:\work\samples>jruby load_test.rb
      "main – 18788761"
      "MAIN: main – 9102426"
      "constant"
      "constant"

      1. load_t.rb
        0.1 kB
        Vladimir Sizikov
      2. load_test.rb
        0.1 kB
        Vladimir Sizikov

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        commit 36dd3a0424ec9789a402a60d6262fff7c7a59c75
        Author: Charles Oliver Nutter <headius@headius.com>
        Date: Sun Jul 10 01:45:11 2011 -0500

        Fix JRUBY-4339: Kernel.load with wrap=true does not protect the global namespace of calling program

        • We were not wrapping the script's scope with an anonymous module.
        Show
        Charles Oliver Nutter added a comment - commit 36dd3a0424ec9789a402a60d6262fff7c7a59c75 Author: Charles Oliver Nutter <headius@headius.com> Date: Sun Jul 10 01:45:11 2011 -0500 Fix JRUBY-4339 : Kernel.load with wrap=true does not protect the global namespace of calling program We were not wrapping the script's scope with an anonymous module.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Vladimir Sizikov
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: