Show
Ignore:
Timestamp:
01/08/08 19:26:12 (5 years ago)
Author:
nshuyo
Message:

lang/javascript/jsruby: enabled to pass function objects from javascript and to use 'new'

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

Legend:

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

    r4197 r4221  
    299299RubyEngine.RubyObject.JSObject.prototype.toValue = function(){ return this.obj; } 
    300300RubyEngine.RubyObject.JSObject.methods = { 
    301  "method_missing": function(self, args, block) { 
     301  "new": function(self, args, block) { 
     302    var jsargs = []; 
     303    if(args) for (var i=1;i<args.length;i++) jsargs.push( this.run(args[i]).toValue() ); 
     304    return RubyEngine.RubyObject.js2r(new self.obj()); 
     305  }, 
     306  "method_missing": function(self, args, block) { 
    302307    var name = this.run(args[0]).str; 
    303308    if (args.length==1) { 
    304309      return RubyEngine.RubyObject.js2r(self.obj[name]); 
    305310    } else if (name[name.length-1] == "=") { 
    306       self.obj[name.slice(0, name.length-1)] = this.run(args[1]).toValue(); 
     311      var v=this.run(args[1]) 
     312      self.obj[name.slice(0, name.length-1)] = v.toValue(); 
     313      return v; 
    307314    } else { 
    308315      if (name in self.obj) { 
  • lang/javascript/jsruby/trunk/src/interpreter.js

    r4193 r4221  
    4646  if (typeof(ref) == "function") { 
    4747    return ref.apply(this, [args, block]); 
     48  } else if (RubyEngine.RubyObject.JSObject.prototype.isPrototypeOf(ref)) { 
     49    return RubyEngine.RubyObject.js2r(ref.obj.apply(ref.obj, args)); 
    4850  } else if (RubyEngine.Node.Block.prototype.isPrototypeOf(ref)) { 
    4951    var block = ref; 
     
    193195 
    194196RubyEngine.Interpreter.prototype.kernelMethod = function(node){ 
    195   var method = RubyEngine.Interpreter.KernelMethod[node.name]; 
     197  //var method = RubyEngine.Interpreter.KernelMethod[node.name]; 
     198  var method = this.scope.reference(node.name); 
    196199  if (typeof(method)=="function") { 
    197200    return method.apply(this, [node.args, node.block]);