class RKelly::JS::Function
Attributes
arguments[R]
body[R]
Public Class Methods
create(*args)
click to toggle source
# File lib/rkelly/js/function.rb, line 5 def create(*args) if args.length > 0 parser = RKelly::Parser.new body = args.pop tree = parser.parse("function x(#{args.join(',')}) { #{body} }") func = tree.value.first self.new(func.function_body, func.arguments) else self.new end end
new(body = nil, arguments = [])
click to toggle source
Calls superclass method
RKelly::JS::Base.new
# File lib/rkelly/js/function.rb, line 19 def initialize(body = nil, arguments = []) super() @body = body @arguments = arguments self['prototype'] = JS::FunctionPrototype.new(self) self['toString'] = :undefined self['length'] = arguments.length end
Public Instance Methods
js_call(scope_chain, *params)
click to toggle source
# File lib/rkelly/js/function.rb, line 28 def js_call(scope_chain, *params) arguments.each_with_index { |name, i| scope_chain[name.value] = params[i] || RKelly::Runtime::UNDEFINED } function_visitor = RKelly::Visitors::FunctionVisitor.new(scope_chain) eval_visitor = RKelly::Visitors::EvaluationVisitor.new(scope_chain) body.accept(function_visitor) if body body.accept(eval_visitor) if body end