v8eval 0.1.4 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45e8f14514bbcd02b1dedd84d5d5dcc892dbfb65
4
- data.tar.gz: 51d0976a08a61c4141116745578b0c1d4b0e95d3
3
+ metadata.gz: 7517eee6ae6f2b484b2c929ae989c708ab0011de
4
+ data.tar.gz: f22920581af7c5b529a280c312b756539cd489ff
5
5
  SHA512:
6
- metadata.gz: 35c7d3dcbd97d956e2f36bbaa64eb4724e8ba59427917ccffbe690575f7e06a11ef093f5eadc63ae82a1c1705cdd60210d1d69035f5c764ad84ff13fba4129de
7
- data.tar.gz: 75f04cad230480da7a05e93f2f046c40e7cebab821e8f636aa5b2269836c2aa7c09dd6c735e445c295600784854d960b071031dcec431c87660588ff242ecb95
6
+ metadata.gz: 049d7fca83ede539ecadd2c0b2e6153c1d9ff2d6cb982ecd29f31a95deb6aeac12b47ad20556135cf763e1125ced49e57c87c9fd6689d83c550079922241a6c3
7
+ data.tar.gz: 92c06f57ca19b13072e12f6924818508fea1e0712aabe945c8aa8d885781ca027a4906c4821591036c62e491ba2bfb6fc5dd7727abb21b235f795532588a3cdc
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  Multi-language bindings to JavaScript engine V8.
9
9
 
10
- Currently v8eval provides Go, Python and Ruby bindings to the latest V8 4.7 and supports Linux and Mac OS X.
10
+ Currently v8eval provides Go, Python and Ruby bindings to the latest V8 4.9 and supports Linux and Mac OS X.
11
11
  v8eval uses SWIG and can be extended easily for other languages.
12
12
 
13
13
  ## Pre-installation
data/build.sh CHANGED
@@ -47,7 +47,7 @@ install_v8() {
47
47
  cd $V8EVAL_ROOT
48
48
  fetch v8
49
49
  cd v8
50
- git checkout 4.7.68
50
+ git checkout 4.9.135
51
51
  CFLAGS="-fPIC" CXXFLAGS="-fPIC" make x64.release V=1
52
52
  }
53
53
 
data/ruby/build.sh CHANGED
@@ -3,12 +3,14 @@
3
3
  V8EVAL_ROOT=`cd $(dirname $0)/.. && pwd`
4
4
 
5
5
  build() {
6
- cd $V8EVAL_ROOT/ruby && rake prepare_build
7
- cd $V8EVAL_ROOT && gem build v8eval.gemspec
6
+ cd $V8EVAL_ROOT/ruby
7
+ rake prepare_build
8
+ rake build_ext
8
9
  }
9
10
 
10
11
  install() {
11
12
  cd $V8EVAL_ROOT
13
+ gem build v8eval.gemspec
12
14
  gem install v8eval-*.gem
13
15
  }
14
16
 
@@ -27,7 +29,6 @@ test() {
27
29
  bundle install
28
30
 
29
31
  rspec --init
30
- rake build_ext
31
32
  rspec
32
33
  }
33
34
 
@@ -6,6 +6,7 @@ require_relative '../../lib/setup/extension_builder'
6
6
  # set path variables
7
7
  v8eval_root = File.expand_path('../../..', Dir.pwd)
8
8
  v8_dir = v8eval_root + '/v8'
9
+ uv_dir = v8eval_root + '/uv'
9
10
 
10
11
  # make instance of BuildTool class
11
12
  tool = BuildTool.new(v8eval_root)
@@ -22,6 +23,7 @@ INCLUDEDIR = RbConfig::CONFIG['includedir']
22
23
  header_dirs = [
23
24
  v8_dir,
24
25
  v8_dir + '/include',
26
+ uv_dir + '/include',
25
27
  INCLUDEDIR
26
28
  ]
27
29
 
@@ -39,10 +41,11 @@ elsif RUBY_PLATFORM =~ /linux/
39
41
  v8_dir + '/out/x64.release/obj.target/third_party/icu'
40
42
  ]
41
43
  end
44
+ lib_dirs += [uv_dir + '/.libs']
42
45
 
43
46
  dir_config('', header_dirs, lib_dirs)
44
47
 
45
- $LDFLAGS << ' -lv8eval -lv8_libplatform -lv8_base -lv8_libbase -lv8_nosnapshot -licui18n -licuuc -licudata'
48
+ $LDFLAGS << ' -lv8eval -lv8_libplatform -lv8_base -lv8_libbase -lv8_nosnapshot -licui18n -licuuc -licudata -luv'
46
49
  $CPPFLAGS << ' -g -O3 -std=c++11'
47
50
 
48
51
  create_makefile('v8eval/v8eval')
data/ruby/lib/v8eval.rb CHANGED
@@ -16,11 +16,12 @@ module V8Eval
16
16
  # Evaluates JavaScript code.
17
17
  # @param [String] src JavaScript code.
18
18
  # @return
19
- # The result of the JavaScript code. The result is marshalled/unmarshalled by using JSON.
19
+ # The result of the JavaScript code.
20
+ # The result is marshalled/unmarshalled by using JSON.
20
21
  # @raise [TypeError] If src is not a string.
21
22
  # @raise [V8Error] If some JavaScript exception happens.
22
23
  def eval(src)
23
- fail TypeError unless src.is_a?(String)
24
+ fail TypeError, 'source code not string' unless src.is_a?(String)
24
25
  res = @v8.eval(src)
25
26
  if res == 'undefined'
26
27
  return nil
@@ -37,12 +38,13 @@ module V8Eval
37
38
  # @param [String] func Name of a JavaScript function.
38
39
  # @param [Array] args Argument list to pass.
39
40
  # @return
40
- # The result of the JavaScript code. The result is marshalled/unmarshalled by using JSON.
41
+ # The result of the JavaScript code.
42
+ # The result is marshalled/unmarshalled by using JSON.
41
43
  # @raise [TypeError] If either func is not a string or args is not a array.
42
44
  # @raise [V8Error] If some JavaScript exception happens.
43
45
  def call(func, args)
44
- fail TypeError unless func.is_a?(String)
45
- fail TypeError unless args.is_a?(Array)
46
+ fail TypeError, 'function name not string' unless func.is_a?(String)
47
+ fail TypeError, 'arguments not array' unless args.is_a?(Array)
46
48
 
47
49
  args_str = JSON.dump(args)
48
50
  res = @v8.call(func, args_str)
@@ -56,6 +58,22 @@ module V8Eval
56
58
  end
57
59
  end
58
60
  end
61
+
62
+ # Starts a debug server associated with the V8 instance.
63
+ # @param [Integer] port TCP/IP port the server will listen, at localhost.
64
+ # @return nil.
65
+ # @raise [TypeError] If port is not an int.
66
+ # @raise [V8Error] If failing to start the debug server.
67
+ def enable_debugger(port)
68
+ fail TypeError, 'port not integer' unless port.is_a?(Integer)
69
+ fail V8Error, 'failed to start debug server' unless @v8.enable_debugger(port)
70
+ end
71
+
72
+ # Stops the debug server, if running.
73
+ # @return nil.
74
+ def disable_debugger
75
+ @v8.disable_debugger
76
+ end
59
77
  end
60
78
  end
61
79
 
@@ -55,3 +55,20 @@ RSpec.describe V8Eval, '#multithreading' do
55
55
  end
56
56
  end
57
57
  end
58
+
59
+ RSpec.describe V8Eval, '#test_debugger' do
60
+ context 'with debugging functionality' do
61
+ it 'should enable and disable debugger properly' do
62
+ v8 = V8Eval::V8.new
63
+ expect { v8.enable_debugger(0.1) }.to raise_exception(TypeError)
64
+ expect { v8.enable_debugger(-1) }.to raise_exception(V8Eval::V8Error)
65
+
66
+ port = 12_345
67
+ expect(v8.enable_debugger(port)).to be nil
68
+ expect { v8.enable_debugger(port) }.to raise_exception(V8Eval::V8Error)
69
+ expect(v8.disable_debugger).to be nil
70
+ expect(v8.enable_debugger(port)).to be nil
71
+ expect(v8.disable_debugger).to be nil
72
+ end
73
+ end
74
+ end
data/v8eval.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new 'v8eval', '1.0' do |s|
2
2
  s.name = 'v8eval'
3
- s.version = '0.1.4'
3
+ s.version = '0.2.1'
4
4
  s.licenses = ['MIT']
5
5
  s.description = 'Run JavaScript engine V8 in Ruby'
6
6
  s.summary = 'v8eval gem is ruby binding to the latest V8 4.7 and supports
metadata CHANGED
@@ -1,47 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: v8eval
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prateek Papriwal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '10.4'
20
- - - ">="
20
+ - - '>='
21
21
  - !ruby/object:Gem::Version
22
22
  version: 10.4.2
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '10.4'
30
- - - ">="
30
+ - - '>='
31
31
  - !ruby/object:Gem::Version
32
32
  version: 10.4.2
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ~>
38
38
  - !ruby/object:Gem::Version
39
39
  version: '3.0'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - "~>"
44
+ - - ~>
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.0'
47
47
  - !ruby/object:Gem::Dependency
@@ -71,13 +71,10 @@ files:
71
71
  - README.md
72
72
  - build.sh
73
73
  - ruby/Gemfile
74
- - ruby/Gemfile.lock
75
74
  - ruby/Rakefile
76
75
  - ruby/build.sh
77
76
  - ruby/example/js_add.rb
78
77
  - ruby/ext/v8eval/extconf.rb
79
- - ruby/ext/v8eval/v8eval.h
80
- - ruby/ext/v8eval/v8eval_wrap.cxx
81
78
  - ruby/lib/setup/extension_builder.rb
82
79
  - ruby/lib/v8eval.rb
83
80
  - ruby/spec/v8eval_spec.rb
@@ -98,17 +95,17 @@ require_paths:
98
95
  - ruby/ext
99
96
  required_ruby_version: !ruby/object:Gem::Requirement
100
97
  requirements:
101
- - - ">="
98
+ - - '>='
102
99
  - !ruby/object:Gem::Version
103
100
  version: 2.0.0
104
101
  required_rubygems_version: !ruby/object:Gem::Requirement
105
102
  requirements:
106
- - - ">="
103
+ - - '>='
107
104
  - !ruby/object:Gem::Version
108
105
  version: '0'
109
106
  requirements: []
110
107
  rubyforge_project:
111
- rubygems_version: 2.4.6
108
+ rubygems_version: 2.2.2
112
109
  signing_key:
113
110
  specification_version: 4
114
111
  summary: v8eval gem is ruby binding to the latest V8 4.7 and supports Linux and Mac
data/ruby/Gemfile.lock DELETED
@@ -1,30 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- diff-lcs (1.2.5)
5
- rake (10.4.2)
6
- rspec (3.3.0)
7
- rspec-core (~> 3.3.0)
8
- rspec-expectations (~> 3.3.0)
9
- rspec-mocks (~> 3.3.0)
10
- rspec-core (3.3.2)
11
- rspec-support (~> 3.3.0)
12
- rspec-expectations (3.3.1)
13
- diff-lcs (>= 1.2.0, < 2.0)
14
- rspec-support (~> 3.3.0)
15
- rspec-mocks (3.3.2)
16
- diff-lcs (>= 1.2.0, < 2.0)
17
- rspec-support (~> 3.3.0)
18
- rspec-support (3.3.0)
19
- yard (0.8.7.6)
20
-
21
- PLATFORMS
22
- ruby
23
-
24
- DEPENDENCIES
25
- rake (~> 10.4.2)
26
- rspec (~> 3.0)
27
- yard (~> 0.8.7.6)
28
-
29
- BUNDLED WITH
30
- 1.10.6
@@ -1,99 +0,0 @@
1
- #ifndef V8EVAL_H_
2
- #define V8EVAL_H_
3
-
4
- #include <string>
5
-
6
- #include "v8.h"
7
- #include "v8-debug.h"
8
-
9
- /// \file
10
- namespace v8eval {
11
-
12
- class DbgSrv;
13
-
14
- typedef void (*debugger_cb)(std::string&, void *opq);
15
-
16
- /// \brief Initialize the V8 runtime environment
17
- /// \return success or not as boolean
18
- ///
19
- /// This method initializes the V8 runtime environment. It must be called before creating any V8 instance.
20
- bool initialize();
21
-
22
- /// \brief Dispose the V8 runtime environment
23
- /// \return success or not as boolean
24
- ///
25
- /// This method disposes the V8 runtime environment.
26
- bool dispose();
27
-
28
- /// \class _V8
29
- ///
30
- /// _V8 instances can be used in multiple threads.
31
- /// But each _V8 instance can be used in only one thread at a time.
32
- class _V8 {
33
- public:
34
- _V8();
35
- virtual ~_V8();
36
-
37
- /// \brief Evaluate JavaScript code
38
- /// \param src JavaScript code
39
- /// \return JSON-encoded result or exception message
40
- ///
41
- /// This method evaluates the given JavaScript code 'src' and returns the result in JSON.
42
- /// If some JavaScript exception happens in runtime, the exception message is returned.
43
- std::string eval(const std::string& src);
44
-
45
- /// \brief Call a JavaScript function
46
- /// \param func Name of a JavaScript function
47
- /// \param args JSON-encoded argument array
48
- /// \return JSON-encoded result or exception message
49
- ///
50
- /// This method calls the JavaScript function specified by 'func'
51
- /// with the JSON-encoded argument array 'args'
52
- /// and returns the result in JSON.
53
- /// If some JavaScript exception happens in runtime, the exception message is returned.
54
- std::string call(const std::string& func, const std::string& args);
55
-
56
- /// \brief Start a debug server associated with the V8 instance
57
- /// \param port The TCP/IP port the debugger will listen, at localhost
58
- /// \return success or not as boolean
59
- ///
60
- /// After the debugger is successfully started, it will be possible to
61
- /// send commands and receive events at the specified port. When the
62
- /// debugger is started, the Javascript's "debugger" statement will
63
- /// cause the V8 instance to halt and wait for instructions through
64
- /// the debugger port.
65
- bool enable_debugger(int port);
66
-
67
- /// \brief Stop the debug server, if running.
68
- ///
69
- /// The debug server, if currently running, will be stopped, causing
70
- /// connections to remote debuggers to be dropped.
71
- void disable_debugger();
72
-
73
- private:
74
- static void debugger_message_handler(const v8::Debug::Message& message);
75
- v8::Local<v8::Context> new_context();
76
- v8::Local<v8::String> new_string(const char* str);
77
- v8::Local<v8::Value> json_parse(v8::Local<v8::Context> context, v8::Local<v8::String> str);
78
- v8::Local<v8::String> json_stringify(v8::Local<v8::Context> context, v8::Local<v8::Value> value);
79
-
80
- bool debugger_init(debugger_cb cb, void *cbopq);
81
- bool debugger_send(const std::string& cmd);
82
- void debugger_process();
83
- void debugger_stop();
84
-
85
- private:
86
- v8::Isolate* isolate_;
87
- v8::Persistent<v8::Context> context_;
88
-
89
- DbgSrv* dbg_server_;
90
- v8::Isolate* dbg_isolate_;
91
- debugger_cb callback_;
92
- void* callback_opq_;
93
-
94
- friend class DbgSrv;
95
- };
96
-
97
- } // namespace v8eval
98
-
99
- #endif // V8EVAL_H_