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

update redjs to conform with v8 version. quick and dirty eval()

This commit is contained in:
Charles Lowell 2010-01-18 13:06:38 +02:00
parent 53b0f3b911
commit b483beb493
4 changed files with 18 additions and 20 deletions

View file

@ -43,6 +43,10 @@ module Rhino
new(options).open(&block)
end
def eval(javascript)
new.eval(javascript)
end
end
# Create a new javascript environment for executing javascript and ruby code.
@ -83,17 +87,19 @@ module Rhino
# * <tt>source_name</tt> - associated name for this source code. Mainly useful for backtraces.
# * <tt>line_number</tt> - associate this number with the first line of executing source. Mainly useful for backtraces
def eval(source, source_name = "<eval>", line_number = 1)
begin
scope = To.javascript(@scope)
if IO === source || StringIO === source
result = @native.evaluateReader(scope, IOReader.new(source), source_name, line_number, nil)
else
result = @native.evaluateString(scope, source.to_s, source_name, line_number, nil)
self.open do
begin
scope = To.javascript(@scope)
if IO === source || StringIO === source
result = @native.evaluateReader(scope, IOReader.new(source), source_name, line_number, nil)
else
result = @native.evaluateString(scope, source.to_s, source_name, line_number, nil)
end
To.ruby result
rescue J::RhinoException => e
raise Rhino::RhinoError, e
end
To.ruby result
rescue J::RhinoException => e
raise Rhino::RhinoError, e
end if open?
end
end
def evaluate(*args) # :nodoc:
@ -132,13 +138,6 @@ module Rhino
end if block_given?
end
private
def open?
@native == J::Context.getCurrentContext() || (raise ContextError, "context must be open")
end
end
class IOReader < Java::JavaIo::Reader #:nodoc:

View file

@ -36,7 +36,6 @@ module Rhino
# end
def []=(k,v)
#@j.put(k.to_s,@j,To.javascript(v))
J::ScriptableObject.putProperty(@j, k.to_s, To.javascript(v))
end

@ -1 +1 @@
Subproject commit 540f43d897b928539bbb49243e899294dff9a0b5
Subproject commit 9e8d547fc7b217f9cab0192c04753499f47fdb38

View file

@ -1,5 +1,5 @@
require File.dirname(__FILE__) + '/../spec_helper.rb'
require File.dirname(__FILE__) + '/spec_helper.rb'
include Rhino