lib/johnson/spidermonkey/ruby_land_proxy.rb in johnson-1.1.2 vs lib/johnson/spidermonkey/ruby_land_proxy.rb in johnson-1.2.0

- old
+ new

@@ -1,54 +1,17 @@ module Johnson #:nodoc: module SpiderMonkey #:nodoc: - class RubyLandProxy # native - include Enumerable - - def initialize - raise Johnson::Error, "#{self.class.name} is an internal support class." + class RubyLandProxy < Johnson::RubyLandProxy # native + module Callable + def call_using(this, *args) + native_call(this, *args) + end end - - private :initialize - - # FIXME: need to revisit array vs non-array proxy, to_a/to_ary semantics, etc. - alias_method :size, :length - alias_method :to_ary, :to_a - - def to_proc - @proc ||= Proc.new { |*args| call(*args) } - end - - def call(*args) - call_using(runtime.global, *args) - end - - def call_using(this, *args) - native_call(this, *args) - end - - def inspect - toString - end - - def method_missing(sym, *args, &block) - args << block if block_given? - - name = sym.to_s - assignment = "=" == name[-1, 1] - - # default behavior if the slot's not there - return super unless assignment || respond_to?(sym) - - unless function_property?(name) - # for arity 0, treat it as a get - return self[name] if args.empty? - - # arity 1 and quacking like an assignment, treat it as a set - return self[name[0..-2]] = args[0] if assignment && 1 == args.size - end - - # okay, must really be a function - call_function_property(name, *args) + end + class RubyLandScript < Johnson::SpiderMonkey::RubyLandProxy # native + def break(linenum, &block) + runtime.set_trap(self, linenum, block) + runtime.traps << [self, linenum] end end end end