Forum: IronRuby Code Review: RubyScopes2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tomas M. (Guest)
on 2009-04-29 07:31
(Received via mailing list)
Attachment: RubyScopes2.diff (0 Bytes)
tfpt review "/shelveset:RubyScopes2;REDMOND\tomat"

DLR

  Deletes IDynamicObject and GlobalsDictionary types and Scope.GetKeys
method.
  Adds a default implementation for ScriptCode.Run that creates a new
scope and calls Run(scope).
  Adds assertions to ContractUtils.Invariant.

Ruby

  RubyScope fixes and refactoring.

  This change enables top-level hosted code to define instance methods
in DLR scope. It is no longer necessary to define them as singleton
methods.
  Ruby engine executes the hosted code as if it was executed using
instance_eval on a proc. The behavior is the same except for control
flow - break or retry on top-level throws an exception as it does in
MRI.

  This unit test illustrates the new behavior:

              // When executed without a scope top-level methods are
defined on Object (as in MRI):
              Engine.Execute("def foo; 1; end");
              Assert(Context.ObjectClass.GetMethod("foo") != null);

              // When executed against a scope top-level methods are
defined on main singleton (not on Object) and also stored in the scope:
              var scope = Engine.CreateScope();
              Engine.Execute("def bar; 1; end", scope);
              Assert(Context.ObjectClass.GetMethod("bar") == null);
              Assert(scope.GetVariable("bar") != null);

  Fixes bug in top-level scope compilation - variables from the scope
were not bound properly:

              var compiled =
Engine.CreateScriptSourceFromString("some_variable").Compile();
              scope = Engine.CreateScope();
              scope.SetVariable("some_variable", "foo");
              Assert(compiled.Execute<string>(scope) == "foo");

Tomas
This topic is locked and can not be replied to.