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

Add utility methods to do quick and dirty eval

This commit is contained in:
Charles Lowell 2010-01-13 17:37:51 +02:00
parent 6adef0bfb6
commit fd6f42879c
2 changed files with 16 additions and 2 deletions

View file

@ -20,6 +20,10 @@ Embed the V8 Javascript interpreter into Ruby.
# evaluate some simple javascript
V8.eval("7 * 6") #=> 42
# embed values into the scope of your context
V8::Context.open do |cxt|
cxt['foo'] = "bar"
cxt.eval('foo') # => "bar"

View file

@ -1,3 +1,5 @@
require 'stringio'
module V8
class Context
def initialize(opts = {})
@ -47,6 +49,14 @@ module V8
def self.open(opts = {}, &block)
new(opts).open(&block)
end
def self.eval(source)
new.eval(source)
end
def V8.eval(*args)
V8::Context.eval(*args)
end
end
class ContextError < StandardError