lib/rhino/context.rb in therubyrhino-1.72.8 vs lib/rhino/context.rb in therubyrhino-1.73.0
- old
+ new
@@ -3,27 +3,27 @@
module Rhino
# ==Overview
# All Javascript must be executed in a context which represents the execution environment in
# which scripts will run. The environment consists of the standard javascript objects
-# and functions like Object, String, Array, etc... as well as any objects or functions which
+# and functions like Object, String, Array, etc... as well as any objects or functions which
# have been defined in it. e.g.
-#
+#
# Context.open do |cxt|
# cxt['num'] = 5
# cxt.eval('num + 5') #=> 10
# end
-#
+#
# == Multiple Contexts.
-# The same object may appear in any number of contexts, but only one context may be executing javascript code
+# The same object may appear in any number of contexts, but only one context may be executing javascript code
# in any given thread. If a new context is opened in a thread in which a context is already opened, the second
# context will "mask" the old context e.g.
#
# six = 6
# Context.open do |cxt|
# cxt['num'] = 5
-# cxt.eval('num') # => 5
+# cxt.eval('num') # => 5
# Context.open do |cxt|
# cxt['num'] = 10
# cxt.eval('num') # => 10
# cxt.eval('++num') # => 11
# end
@@ -42,15 +42,15 @@
# initalize a new context with a fresh set of standard objects. All operations on the context
# should be performed in the block that is passed.
def open(options = {}, &block)
new(options).open(&block)
end
-
+
def eval(javascript)
new.eval(javascript)
end
-
+
end
# Create a new javascript environment for executing javascript and ruby code.
# * <tt>:sealed</tt> - if this is true, then the standard objects such as Object, Function, Array will not be able to be modified
# * <tt>:with</tt> - use this ruby object as the root scope for all javascript that is evaluated
@@ -76,12 +76,12 @@
# Read a value from the global scope of this context
def [](k)
@scope[k]
end
- # Set a value in the global scope of this context. This value will be visible to all the
- # javascript that is executed in this context.
+ # Set a value in the global scope of this context. This value will be visible to all the
+ # javascript that is executed in this context.
def []=(k, v)
@scope[k] = v
end
# Evaluate a string of javascript in this context:
@@ -101,11 +101,11 @@
rescue J::RhinoException => e
raise Rhino::JavascriptError, e
end
end
end
-
+
def evaluate(*args) # :nodoc:
self.eval(*args)
end
# Read the contents of <tt>filename</tt> and evaluate it as javascript. Returns the result of evaluating the
@@ -184,11 +184,11 @@
@limit = count
end
end
class ContextError < StandardError # :nodoc:
-
+
end
class JavascriptError < StandardError # :nodoc:
def initialize(native)
@native = native
@@ -200,9 +200,11 @@
def javascript_backtrace
@native.getScriptStackTrace()
end
end
+
+ JSError = JavascriptError
class RunawayScriptError < StandardError # :nodoc:
end
end