# File lib/rkelly/runtime.rb, line 8 def initialize @parser = Parser.new @scope = ScopeChain.new end
# File lib/rkelly/runtime.rb, line 23 def call_function(function_name, *args) function = @scope[function_name].value @scope.new_scope { |chain| function.js_call(chain, *(args.map { |x| RKelly::JS::Property.new(:param, x) })) }.value end
# File lib/rkelly/runtime.rb, line 32 def define_function(function, &block) @scope[function.to_s].function = block end
Execute js
# File lib/rkelly/runtime.rb, line 14 def execute(js) function_visitor = Visitors::FunctionVisitor.new(@scope) eval_visitor = Visitors::EvaluationVisitor.new(@scope) tree = @parser.parse(js) function_visitor.accept(tree) eval_visitor.accept(tree) @scope end