Changeset 2991

Show
Ignore:
Timestamp:
12/10/07 17:59:32 (6 years ago)
Author:
nshuyo
Message:

lang/javascript/jsruby: added class method (i.e. Array.new) support

Location:
lang/javascript/jsruby/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/jsruby/trunk/src/interpreter.js

    r2989 r2991  
    22 
    33RubyEngine.Scope = function(){ this.clear(); } 
    4 RubyEngine.Scope.copy = function(scope, src) { 
    5   for(var i in src) scope[i] = src[i]; 
    6   return scope; 
    7 } 
    84 
    95RubyEngine.Scope.prototype.clear = function(){ 
    106  this.level = [{}] 
    117  this.stack = [] 
    12   this.global = RubyEngine.Scope.copy({}, RubyEngine.Interpreter.KernelMethod) 
     8  this.global = {} 
     9  for(var i in RubyEngine.Interpreter.KernelMethod) { 
     10    if (i.match(/^[a-z_]/)) this.global[i] = RubyEngine.Interpreter.KernelMethod[i]; 
     11  } 
     12  for(var i in RubyEngine.RubyObject) { 
     13    if (i.match(/^[A-Z\$]/)) this.global[i] = RubyEngine.RubyObject[i]; 
     14  } 
    1315} 
    1416RubyEngine.Scope.prototype.substitute = function(name, value){ 
     
    5153 
    5254RubyEngine.Interpreter.prototype.run = function(node){ 
    53 //console.log(args[idx].toSource());console.trace();if(!confirm("continue?")) exit(); 
     55//console.log(node.toSource());console.trace();if(!confirm("continue?")) exit(); 
    5456        var ret = null; 
    5557        if (Array.prototype.isPrototypeOf(node)) { 
     
    146148} 
    147149RubyEngine.Interpreter.prototype.objectMethod = function(node){ 
    148 //console.log(node.toSource());console.trace();if(!confirm("continue?")) exit(); 
    149   var obj = this.run(node.target); 
     150//console.log(node.toSource());console.dir(node);console.trace();if(!confirm("continue?")) exit(); 
     151  var obj; 
     152  if (RubyEngine.Node.Ref.prototype.isPrototypeOf(node.target)) { 
     153    obj = this.scope.reference(node.target.name); 
     154  } else { 
     155    obj = this.run(node.target); 
     156  } 
    150157  var method = obj.clz.methods[node.name]; 
    151158  if (method) { 
  • lang/javascript/jsruby/trunk/tests/array.html

    r2474 r2991  
    2525} 
    2626 
     27function testArrayNew() { 
     28        assertArrayEquals("array new 1", ruby.exec(" Array.new() "), []); 
     29        assertArrayEquals("array new 2", ruby.exec(" Array.new(1) "), [1]); 
     30        assertArrayEquals("array new 3", ruby.exec(" Array.new(1, 2, 3) "), [1, 2, 3]); 
     31        assertArrayEquals("array new 4", ruby.exec(" Array.new([1, 2], Array.new(3, 4)) "), [[1, 2], [3, 4]]); 
     32        assertArrayEquals("array new 5", ruby.exec(" Array.new(1, '2', 3) "), [1, '2', 3]); 
     33} 
     34 
    2735function testBrackett() { 
    2836        ruby.exec(' a=["x", "y", "z"] ')