Class: Rhino::Context

Inherits:
Object show all
Defined in:
lib/rhino/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(native, options) ⇒ Context

:nodoc:



20
21
22
23
24
25
26
27
28
# File 'lib/rhino/context.rb', line 20

def initialize(native, options) #:nodoc:
  @native = native
  @scope = NativeObject.new(@native.initStandardObjects(nil, options[:sealed] == true))
  unless options[:java]
    for package in ["Packages", "java", "org", "com"]
      @scope.j.delete(package)
    end
  end      
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



8
9
10
# File 'lib/rhino/context.rb', line 8

def scope
  @scope
end

Class Method Details

.open(options = {}) ⇒ Object



11
12
13
14
15
# File 'lib/rhino/context.rb', line 11

def open(options = {})
  ContextFactory.new.call do |native|
    yield new(native, options)
  end
end

Instance Method Details

#[](k) ⇒ Object



30
31
32
# File 'lib/rhino/context.rb', line 30

def [](k)
  @scope[k]
end

#[]=(k, v) ⇒ Object



34
35
36
# File 'lib/rhino/context.rb', line 34

def []=(k,v)
  @scope[k] = v
end

#eval(str) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/rhino/context.rb', line 38

def eval(str)
  str = str.to_s
  begin
    To.ruby @native.evaluateString(@scope.j, str, "<eval>", 1, nil)
  rescue J::RhinoException => e
    raise Rhino::RhinoError, e
  end
end

#instruction_limit=(limit) ⇒ Object



47
48
49
50
# File 'lib/rhino/context.rb', line 47

def instruction_limit=(limit)
  @native.setInstructionObserverThreshold(limit);
  @native.factory.instruction_limit = limit
end