Class: RKelly::Runtime
- Inherits:
-
Object
- Object
- RKelly::Runtime
- Defined in:
- lib/rkelly/runtime.rb,
lib/rkelly/runtime/scope_chain.rb,
lib/rkelly/runtime/ruby_function.rb
Defined Under Namespace
Classes: RubyFunction, ScopeChain
Constant Summary collapse
Instance Method Summary collapse
- #call_function(function_name, *args) ⇒ Object
- #define_function(function, &block) ⇒ Object
-
#execute(js) ⇒ Object
Execute
js
. -
#initialize ⇒ Runtime
constructor
A new instance of Runtime.
Constructor Details
#initialize ⇒ Runtime
Returns a new instance of Runtime.
8 9 10 11 |
# File 'lib/rkelly/runtime.rb', line 8 def initialize @parser = Parser.new @scope = ScopeChain.new end |
Instance Method Details
#call_function(function_name, *args) ⇒ Object
23 24 25 26 27 28 29 30 |
# 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 |
#define_function(function, &block) ⇒ Object
32 33 34 |
# File 'lib/rkelly/runtime.rb', line 32 def define_function(function, &block) @scope[function.to_s].function = block end |
#execute(js) ⇒ Object
Execute js
14 15 16 17 18 19 20 21 |
# 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 |