therubyrhino 1.72.1-jruby → 1.72.2-jruby

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,5 +1,9 @@
1
- === 1.72.1 2009-10-XX
2
- * N major enhancements:
1
+ === 1.72.2 2009-11-10
2
+ * 1 major enhancement:
3
+ * ability to limit the instruction count for a context
4
+
5
+ === 1.72.1 2009-11-09
6
+ * 4 major enhancements:
3
7
  * easily manipulate javascript objects from ruby (NativeObject)
4
8
  * make NativeObject Enumerable
5
9
  * to_h and to_json for NativeObject
data/lib/rhino.rb CHANGED
@@ -3,7 +3,7 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
 
4
4
 
5
5
  module Rhino
6
- VERSION = '1.72.1'
6
+ VERSION = '1.72.2'
7
7
  require 'rhino/java'
8
8
  require 'rhino/context'
9
9
  require 'rhino/wormhole'
data/lib/rhino/context.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Rhino
2
-
3
2
  def function(&impl)
4
3
  Function.new &impl
5
4
  end
@@ -8,7 +7,7 @@ module Rhino
8
7
 
9
8
  class << self
10
9
  def open
11
- J::ContextFactory.new.call do |native|
10
+ ContextFactory.new.call do |native|
12
11
  yield new(native)
13
12
  end
14
13
  end
@@ -45,6 +44,11 @@ module Rhino
45
44
  end
46
45
  end
47
46
 
47
+ def instruction_limit=(limit)
48
+ @native.setInstructionObserverThreshold(limit);
49
+ @native.factory.instruction_limit = limit
50
+ end
51
+
48
52
  def standard
49
53
  yield @native.initStandardObjects()
50
54
  end
@@ -65,6 +69,17 @@ module Rhino
65
69
  '"[Native Function]"'
66
70
  end
67
71
  end
72
+
73
+ class ContextFactory < J::ContextFactory
74
+
75
+ def observeInstructionCount(cxt, count)
76
+ raise RunawayScriptError, "script exceeded allowable instruction count" if count > @limit
77
+ end
78
+
79
+ def instruction_limit=(count)
80
+ @limit = count
81
+ end
82
+ end
68
83
 
69
84
 
70
85
  class RhinoError < StandardError
@@ -80,4 +95,6 @@ module Rhino
80
95
  @native.getScriptStackTrace()
81
96
  end
82
97
  end
98
+
99
+ class RunawayScriptError < StandardError; end
83
100
  end
@@ -20,7 +20,7 @@ describe Rhino::Context do
20
20
  Context.open do |cxt|
21
21
  cxt.init_standard_objects.tap do |scope|
22
22
  scope["foo"] = "Hello World"
23
- cxt.eval("foo", scope).should == "Hello World"
23
+ cxt.eval("foo", scope).unwrap.should == "Hello World"
24
24
  end
25
25
  end
26
26
  end
@@ -91,6 +91,17 @@ describe Rhino::Context do
91
91
  end
92
92
  end
93
93
  end
94
+
95
+ it "can limit the number of instructions that are executed in the context" do
96
+ lambda {
97
+ Context.open_std do |cxt, scope|
98
+ cxt.instruction_limit = 100 * 1000
99
+ timeout(1) do
100
+ cxt.eval('while (true);')
101
+ end
102
+ end
103
+ }.should raise_error(Rhino::RunawayScriptError)
104
+ end
94
105
 
95
106
  it "has a private constructor" do
96
107
  lambda {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: therubyrhino
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.72.1
4
+ version: 1.72.2
5
5
  platform: jruby
6
6
  authors:
7
7
  - Charles Lowell
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-09 00:00:00 -05:00
12
+ date: 2009-11-10 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency