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:
parent
6adef0bfb6
commit
fd6f42879c
2 changed files with 16 additions and 2 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue