Files
metasploit-gs/lib/rkelly/runtime/scope_chain.rb
T
James Lee 7458abc8b3 add rkelly, a javascript parsing library. this version fixes several bugs in the abandoned gem, see https://github.com/tenderlove/rkelly/pull/6
git-svn-id: file:///home/svn/framework3/trunk@12815 4d416f70-5f16-0410-b530-b9f4589650da
2011-06-02 06:31:34 +00:00

58 lines
1021 B
Ruby

module RKelly
class Runtime
class ScopeChain
include RKelly::JS
def initialize(scope = Scope.new)
@chain = [GlobalObject.new]
end
def <<(scope)
@chain << scope
end
def has_property?(name)
scope = @chain.reverse.find { |x|
x.has_property?(name)
}
scope ? scope[name] : nil
end
def [](name)
property = has_property?(name)
return property if property
@chain.last.properties[name]
end
def []=(name, value)
@chain.last.properties[name] = value
end
def pop
@chain.pop
end
def this
@chain.last
end
def new_scope(&block)
@chain << Scope.new
result = yield(self)
@chain.pop
result
end
def return=(value)
@chain.last.return = value
end
def return; @chain.last.return; end
def returned?
@chain.last.returned?
end
end
end
end