execjs 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/execjs/module.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "rbconfig"
2
2
 
3
3
  module ExecJS
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.2"
5
5
 
6
6
  class Error < ::StandardError; end
7
7
  class RuntimeError < Error; end
@@ -4,8 +4,10 @@ module ExecJS
4
4
  def initialize(source = "")
5
5
  source = source.encode('UTF-8') if source.respond_to?(:encode)
6
6
 
7
- @v8_context = ::V8::Context.new
8
- @v8_context.eval(source)
7
+ lock do
8
+ @v8_context = ::V8::Context.new
9
+ @v8_context.eval(source)
10
+ end
9
11
  end
10
12
 
11
13
  def exec(source, options = {})
@@ -20,7 +22,9 @@ module ExecJS
20
22
  source = source.encode('UTF-8') if source.respond_to?(:encode)
21
23
 
22
24
  if /\S/ =~ source
23
- unbox @v8_context.eval("(#{source})")
25
+ lock do
26
+ unbox @v8_context.eval("(#{source})")
27
+ end
24
28
  end
25
29
  rescue ::V8::JSError => e
26
30
  if e.value["name"] == "SyntaxError"
@@ -31,7 +35,9 @@ module ExecJS
31
35
  end
32
36
 
33
37
  def call(properties, *args)
34
- unbox @v8_context.eval(properties).call(*args)
38
+ lock do
39
+ unbox @v8_context.eval(properties).call(*args)
40
+ end
35
41
  rescue ::V8::JSError => e
36
42
  if e.value["name"] == "SyntaxError"
37
43
  raise RuntimeError, e.message
@@ -59,6 +65,24 @@ module ExecJS
59
65
  value
60
66
  end
61
67
  end
68
+
69
+ private
70
+ def lock
71
+ result, exception = nil, nil
72
+ V8::C::Locker() do
73
+ begin
74
+ result = yield
75
+ rescue Exception => e
76
+ exception = e
77
+ end
78
+ end
79
+
80
+ if exception
81
+ raise exception
82
+ else
83
+ result
84
+ end
85
+ end
62
86
  end
63
87
 
64
88
  def name
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execjs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 1
10
- version: 1.1.1
9
+ - 2
10
+ version: 1.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Stephenson
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-06-07 00:00:00 -05:00
19
+ date: 2011-06-08 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency