1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/lib/v8/context.rb

44 lines
850 B
Ruby
Raw Normal View History

2009-12-15 00:35:55 -05:00
module V8
class Context
def initialize
@native = C::Context.new
end
def open(&block)
@native.open do
block.call(self)
end if block_given?
end
def eval(javascript)
@native.eval(javascript).tap do |result|
raise JavascriptError.new(result) if result.kind_of?(C::Message)
return To.ruby(result)
end
end
def evaluate(*args)
self.eval(*args)
end
2009-12-18 02:48:06 -05:00
def []=(key, value)
value.tap do
@native.Global().tap do |scope|
scope.Set(key.to_s, value)
2009-12-18 02:48:06 -05:00
end
end
end
def self.open(&block)
new.open(&block)
2009-12-18 02:48:06 -05:00
end
end
class ContextError < StandardError
end
class JavascriptError < StandardError
def initialize(v8_message)
super(v8_message.Get())
end
2009-12-15 00:35:55 -05:00
end
end