therubyracer 0.10.2 → 0.11.0beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of therubyracer might be problematic. Click here for more details.

Files changed (159) hide show
  1. data/.gitignore +21 -11
  2. data/.travis.yml +2 -1
  3. data/Changelog.md +46 -0
  4. data/Gemfile +16 -1
  5. data/README.md +31 -13
  6. data/Rakefile +42 -23
  7. data/benchmarks.rb +217 -0
  8. data/ext/v8/accessor.cc +181 -0
  9. data/ext/v8/array.cc +26 -0
  10. data/ext/v8/backref.cc +56 -0
  11. data/ext/v8/build.rb +51 -0
  12. data/ext/v8/constants.cc +34 -0
  13. data/ext/v8/constraints.cc +52 -0
  14. data/ext/v8/context.cc +130 -0
  15. data/ext/v8/date.cc +18 -0
  16. data/ext/v8/exception.cc +38 -0
  17. data/ext/v8/extconf.rb +14 -18
  18. data/ext/v8/external.cc +43 -0
  19. data/ext/v8/function.cc +58 -0
  20. data/ext/v8/gc.cc +43 -0
  21. data/ext/v8/handles.cc +34 -0
  22. data/ext/v8/heap.cc +31 -0
  23. data/ext/v8/init.cc +39 -0
  24. data/ext/v8/invocation.cc +86 -0
  25. data/ext/v8/locker.cc +77 -0
  26. data/ext/v8/message.cc +51 -0
  27. data/ext/v8/object.cc +334 -0
  28. data/ext/v8/primitive.cc +8 -0
  29. data/ext/v8/rr.cc +83 -0
  30. data/ext/v8/rr.h +878 -36
  31. data/ext/v8/script.cc +80 -0
  32. data/ext/v8/signature.cc +18 -0
  33. data/ext/v8/stack.cc +75 -0
  34. data/ext/v8/string.cc +47 -0
  35. data/ext/v8/template.cc +175 -0
  36. data/ext/v8/trycatch.cc +86 -0
  37. data/ext/v8/v8.cc +87 -0
  38. data/ext/v8/value.cc +239 -0
  39. data/lib/v8.rb +30 -22
  40. data/lib/v8/access.rb +5 -87
  41. data/lib/v8/access/indices.rb +40 -0
  42. data/lib/v8/access/invocation.rb +47 -0
  43. data/lib/v8/access/names.rb +65 -0
  44. data/lib/v8/array.rb +19 -10
  45. data/lib/v8/context.rb +85 -78
  46. data/lib/v8/conversion.rb +35 -0
  47. data/lib/v8/conversion/array.rb +11 -0
  48. data/lib/v8/conversion/class.rb +120 -0
  49. data/lib/v8/conversion/code.rb +38 -0
  50. data/lib/v8/conversion/fundamental.rb +11 -0
  51. data/lib/v8/conversion/hash.rb +11 -0
  52. data/lib/v8/conversion/indentity.rb +31 -0
  53. data/lib/v8/conversion/method.rb +26 -0
  54. data/lib/v8/conversion/object.rb +28 -0
  55. data/lib/v8/conversion/primitive.rb +7 -0
  56. data/lib/v8/conversion/proc.rb +5 -0
  57. data/lib/v8/conversion/reference.rb +16 -0
  58. data/lib/v8/conversion/string.rb +12 -0
  59. data/lib/v8/conversion/symbol.rb +7 -0
  60. data/lib/v8/conversion/time.rb +13 -0
  61. data/lib/v8/error.rb +18 -123
  62. data/lib/v8/error/protect.rb +20 -0
  63. data/lib/v8/error/try.rb +15 -0
  64. data/lib/v8/function.rb +18 -34
  65. data/lib/v8/object.rb +48 -52
  66. data/lib/v8/util/weakcell.rb +29 -0
  67. data/lib/v8/version.rb +2 -2
  68. data/spec/c/array_spec.rb +17 -0
  69. data/spec/c/constants_spec.rb +20 -0
  70. data/spec/c/exception_spec.rb +26 -0
  71. data/spec/c/external_spec.rb +9 -0
  72. data/spec/c/function_spec.rb +46 -0
  73. data/spec/c/handles_spec.rb +35 -0
  74. data/spec/c/locker_spec.rb +38 -0
  75. data/spec/c/object_spec.rb +46 -0
  76. data/spec/c/script_spec.rb +28 -0
  77. data/spec/c/string_spec.rb +16 -0
  78. data/spec/c/template_spec.rb +30 -0
  79. data/spec/c/trycatch_spec.rb +51 -0
  80. data/spec/mem/blunt_spec.rb +42 -0
  81. data/spec/redjs_spec.rb +10 -0
  82. data/spec/spec_helper.rb +40 -4
  83. data/spec/threading_spec.rb +52 -0
  84. data/spec/v8/context_spec.rb +19 -0
  85. data/spec/v8/conversion_spec.rb +9 -0
  86. data/spec/v8/error_spec.rb +15 -125
  87. data/spec/v8/function_spec.rb +9 -0
  88. data/therubyracer.gemspec +15 -24
  89. metadata +102 -135
  90. data/.gitmodules +0 -3
  91. data/.rspec +0 -1
  92. data/.yardopts +0 -1
  93. data/bin/therubyracer +0 -11
  94. data/ext/v8/rr.cpp +0 -189
  95. data/ext/v8/v8.cpp +0 -48
  96. data/ext/v8/v8_array.cpp +0 -48
  97. data/ext/v8/v8_array.h +0 -8
  98. data/ext/v8/v8_callbacks.cpp +0 -81
  99. data/ext/v8/v8_callbacks.h +0 -8
  100. data/ext/v8/v8_context.cpp +0 -92
  101. data/ext/v8/v8_context.h +0 -6
  102. data/ext/v8/v8_date.cpp +0 -34
  103. data/ext/v8/v8_date.h +0 -6
  104. data/ext/v8/v8_debug.cpp +0 -17
  105. data/ext/v8/v8_debug.h +0 -6
  106. data/ext/v8/v8_exception.cpp +0 -133
  107. data/ext/v8/v8_exception.h +0 -11
  108. data/ext/v8/v8_external.cpp +0 -70
  109. data/ext/v8/v8_external.h +0 -8
  110. data/ext/v8/v8_function.cpp +0 -69
  111. data/ext/v8/v8_function.h +0 -11
  112. data/ext/v8/v8_handle.cpp +0 -186
  113. data/ext/v8/v8_handle.h +0 -48
  114. data/ext/v8/v8_locker.cpp +0 -139
  115. data/ext/v8/v8_locker.h +0 -6
  116. data/ext/v8/v8_message.cpp +0 -67
  117. data/ext/v8/v8_message.h +0 -10
  118. data/ext/v8/v8_object.cpp +0 -122
  119. data/ext/v8/v8_object.h +0 -10
  120. data/ext/v8/v8_script.cpp +0 -36
  121. data/ext/v8/v8_script.h +0 -8
  122. data/ext/v8/v8_string.cpp +0 -52
  123. data/ext/v8/v8_string.h +0 -9
  124. data/ext/v8/v8_template.cpp +0 -344
  125. data/ext/v8/v8_template.h +0 -8
  126. data/ext/v8/v8_try_catch.cpp +0 -70
  127. data/ext/v8/v8_try_catch.h +0 -5
  128. data/ext/v8/v8_v8.cpp +0 -35
  129. data/ext/v8/v8_v8.h +0 -6
  130. data/ext/v8/v8_value.cpp +0 -175
  131. data/ext/v8/v8_value.h +0 -10
  132. data/ext/v8/v8_weakref.cpp +0 -61
  133. data/ext/v8/v8_weakref.h +0 -29
  134. data/lib/v8/c/locker.rb +0 -18
  135. data/lib/v8/cli.rb +0 -133
  136. data/lib/v8/portal.rb +0 -86
  137. data/lib/v8/portal/caller.rb +0 -37
  138. data/lib/v8/portal/constructor.rb +0 -98
  139. data/lib/v8/portal/function.rb +0 -63
  140. data/lib/v8/portal/interceptors.rb +0 -152
  141. data/lib/v8/portal/proxies.rb +0 -151
  142. data/lib/v8/portal/templates.rb +0 -73
  143. data/lib/v8/stack.rb +0 -66
  144. data/lib/v8/tap.rb +0 -9
  145. data/spec/ext/array_spec.rb +0 -15
  146. data/spec/ext/cxt_spec.rb +0 -57
  147. data/spec/ext/ext_spec_helper.rb +0 -27
  148. data/spec/ext/func_spec.rb +0 -64
  149. data/spec/ext/object_spec.rb +0 -10
  150. data/spec/ext/string_spec.rb +0 -11
  151. data/spec/ext/try_catch_spec.rb +0 -60
  152. data/spec/redjs_helper.rb +0 -3
  153. data/spec/v8/portal/proxies_spec.rb +0 -106
  154. data/specmem/handle_memspec.rb +0 -41
  155. data/specmem/object_memspec.rb +0 -14
  156. data/specmem/proxies_memspec.rb +0 -49
  157. data/specmem/spec_helper.rb +0 -24
  158. data/specthread/spec_helper.rb +0 -2
  159. data/specthread/threading_spec.rb +0 -13
data/.gitignore CHANGED
@@ -1,13 +1,23 @@
1
- .bundle
2
- .rvmrc
3
- Gemfile.lock
4
- v8.bundle
5
- v8.so
6
- *.o
7
1
  *.gem
8
2
  *.rbc
9
- *.log
10
- *~
11
- pkg/
12
- tmp/
13
- .yardoc/
3
+ .rbx/
4
+ .rvmrc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ .project
9
+ .cproject
10
+ Gemfile.lock
11
+ InstalledFiles
12
+ _yardoc
13
+ coverage
14
+ doc/
15
+ lib/bundler/man
16
+ lib/v8/*.bundle
17
+ lib/v8/*.so
18
+ pkg
19
+ rdoc
20
+ spec/reports
21
+ test/tmp
22
+ test/version_tmp
23
+ tmp
data/.travis.yml CHANGED
@@ -2,8 +2,9 @@ rvm:
2
2
  - 1.9.2
3
3
  - 1.9.3
4
4
  - 1.8.7
5
+ - rbx-18mode
6
+ - rbx-19mode
5
7
  notifications:
6
8
  recipients:
7
9
  - cowboyd@thefrontside.net
8
10
  script: bundle exec rake compile spec
9
- before_install: git submodule update --init
data/Changelog.md CHANGED
@@ -1,5 +1,51 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11
4
+
5
+ * upgrade V8 version to 3.11.8
6
+ * remove dependency on libv8. enable compilation against system v8
7
+ * complete re-write of low-level C layer for dramatically increased stability and performance
8
+ * more faithful and complete coverage of the low-level C API
9
+ * ease the building of binary gems
10
+ * official support for Rubinius
11
+ * ability to query V8 for memory usage and set resource constraints
12
+ * extensible conversion framework for thunking Ruby values to V8 and vice-versa
13
+ * extensible invocation framework for calling Ruby code (Proc, Method, etc...) from JavaScript
14
+ * extensible access framework for interacting with Ruby properties from JavaScript
15
+ * provide explicit context teardown for distributed cycles of garbage.
16
+
17
+
18
+ ## 0.10.1 2012/04/05
19
+
20
+ * [bugfix] V8::Object#respond_to? did not call super
21
+
22
+ ## 0.10.0 2012/03/28
23
+
24
+ * [incompatible] embedded lambdas now take JS `this` object as first object
25
+ * add sponsorship image to the README
26
+ * enable Travis CI
27
+
28
+ ## 0.9.9 2012/11/08
29
+
30
+ * remove GCC specific C++ extension to fix llvm build.
31
+
32
+ ## 0.9.8 2012/11/07
33
+
34
+ * let Rake version float again.
35
+
36
+ ## 0.9.7 2012/10/06
37
+ * build fixes
38
+ * fix rake dependency at 0.8.7 while the Rake team sorts some shit out.
39
+
40
+ ## 0.9.6 2012/10/06
41
+
42
+ * make build compatible with Gentoo
43
+
44
+ ## 0.9.5 - 2012/10/05
45
+
46
+ * remove GCC specific code to enable build on BSD
47
+ * let Rake dependency float
48
+
3
49
  ## 0.9.4 - 2011/08/22
4
50
 
5
51
  * Fix an issue with the compilation include paths which allowed compilation against conflicting libv8's
data/Gemfile CHANGED
@@ -1 +1,16 @@
1
- source :rubygems;gemspec
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'redjs', :git => 'https://github.com/cowboyd/redjs.git'
6
+ gem "rake"
7
+ gem "rspec", "~> 2.0"
8
+ gem "rake-compiler"
9
+ gem 'gem-compiler' unless Object.const_defined?(:RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
10
+
11
+ group :libv8 do
12
+ gem 'libv8', "~> 3.11.8"
13
+ end
14
+
15
+
16
+
data/README.md CHANGED
@@ -19,12 +19,13 @@ Embed the V8 Javascript interpreter into Ruby.
19
19
 
20
20
  ## SYNOPSIS
21
21
 
22
- gem install therubyracer ;: stable
23
- gem install therubyracer --pre ;: bleeding edge
22
+ gem install therubyracer
24
23
 
25
24
  then in your ruby code
26
25
 
27
26
  require 'v8'
27
+ # or if using bundler (as with Rails), add the following to your Gemfile
28
+ gem "therubyracer", :require => 'v8'
28
29
 
29
30
  evaluate some simple javascript
30
31
 
@@ -38,7 +39,7 @@ embed values into the scope of your context
38
39
 
39
40
  embed ruby code into your scope and call it from javascript
40
41
 
41
- cxt["say"] = lambda {|word, times| word * times}
42
+ cxt["say"] = lambda {|this, word, times| word * times}
42
43
  cxt.eval("say('Hello', 3)") #=> HelloHelloHello
43
44
 
44
45
  embed a ruby object into your scope and access its properties/methods from javascript
@@ -119,22 +120,36 @@ to allow whatever behavior you'd like
119
120
 
120
121
  More documentation can be found on the [github wiki](https://github.com/cowboyd/therubyracer/wiki)
121
122
 
122
- ## REQUIREMENTS:
123
+ ## PREREQUISITES
123
124
 
124
- * python >= 2.5 (required to compile v8)
125
- * C++ compiler
125
+ For platforms for which there is a binary version of therubyracer gem available, there are no
126
+ dependencies other than ruby and rubygems.
126
127
 
127
- ## Rails/Bundler
128
+ If there is not a binary version for your system, then you will need to compile it from source.
129
+ To do this, you must have v8 >= 3.11.8 installed somewhere on your system. There are several
130
+ ways of doing this. For both you will need a C++ compiler.
128
131
 
129
- To use the ruby racer in rails, or any application using Bundler to manage gems, add the following to your Gemfile
132
+ The first method involves using a version of the v8 source which is maintained
133
+ [as a rubygem called libv8][1]. To use it, all you have to do is
134
+ add the following to your Gemfile:
135
+
136
+ gem 'libv8', '~> 3.11.8'
137
+
138
+ This will download and build v8 from source for you as part of the gem installation
139
+ process. When therubyracer is installed, it will find this gem if it is present and
140
+ link against the v8 binaries contained therein.
141
+
142
+ If you cannot, or do not wish to use the libv8 rubygem, then you can either install
143
+ libv8 with you operating system's packaging system or you can [build it from source][2].
144
+ If you build from source, be sure to set the library=shared option. Also, if you install
145
+ this shared library into a place that is not on your standard lib and include paths, then
146
+ you can pass your non-standard locations to therubyracer using the
147
+ `--with-v8-include` and `--with-v8-lib` configuration options.
130
148
 
131
- gem "therubyracer", :require => 'v8'
132
- gem "therubyracer", "~> 0.8.2.pre" #bleeding edge.
133
149
 
134
150
  ## DEVELOP
135
151
  git clone git://github.com/cowboyd/therubyracer.git
136
152
  cd therubyracer
137
- git submodule update --init
138
153
  bundle install
139
154
  rake compile
140
155
 
@@ -145,7 +160,7 @@ To use the ruby racer in rails, or any application using Bundler to manage gems,
145
160
 
146
161
  (The MIT License)
147
162
 
148
- Copyright (c) 2009,2010,2011 Charles Lowell
163
+ Copyright (c) 2009,2010,2011,2012 Charles Lowell
149
164
 
150
165
  Permission is hereby granted, free of charge, to any person obtaining
151
166
  a copy of this software and associated documentation files (the
@@ -164,4 +179,7 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
164
179
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
165
180
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
166
181
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
167
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
182
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
183
+
184
+ [1]: https://github.com/cowboyd/libv8
185
+ [2]: http://code.google.com/p/v8/wiki/BuildingWithGYP
data/Rakefile CHANGED
@@ -1,23 +1,42 @@
1
- require 'bundler'
2
- require 'bundler/setup'
3
- require "rake/extensiontask"
4
- require "rspec/core/rake_task"
5
- Bundler::GemHelper.install_tasks
6
-
7
- task :default => :spec
8
-
9
- desc "remove all generated artifacts except built v8 objects"
10
- task :clean do
11
- sh "rm -rf pkg"
12
- sh "rm -rf ext/v8/*.bundle ext/v8/*.so"
13
- sh "rm -rf lib/v8/*.bundle lib/v8/*.so"
14
- end
15
-
16
- Rake::ExtensionTask.new("v8", eval(File.read("therubyracer.gemspec"))) do |ext|
17
- ext.lib_dir = "lib/v8"
18
- ext.source_pattern = "*.{cpp,h}"
19
- end
20
-
21
- RSpec::Core::RakeTask.new(:spec)
22
-
23
-
1
+ #!/usr/bin/env rake
2
+ require 'bundler/setup'
3
+ require "bundler/gem_tasks"
4
+
5
+ task :clean do
6
+ sh "rm -rf lib/v8/init.bundle lib/v8/init.so"
7
+ sh "rm -rf pkg"
8
+ end
9
+
10
+ require "rake/extensiontask"
11
+ Rake::ExtensionTask.new("init", eval(File.read("therubyracer.gemspec"))) do |ext|
12
+ ext.ext_dir = "ext/v8"
13
+ ext.lib_dir = "lib/v8"
14
+ ext.source_pattern = "*.{cc,h}"
15
+ end
16
+
17
+ require 'rspec/core/rake_task'
18
+ RSpec::Core::RakeTask.new(:spec) do |task|
19
+ task.rspec_opts = '--tag ~memory --tag ~threads'
20
+ end
21
+
22
+ task :sanity => [:clean, :compile] do
23
+ sh %q{ruby -Ilib -e "require 'v8'"}
24
+ end
25
+
26
+ NativeGem = "pkg/therubyracer-#{V8::VERSION}-#{Gem::Platform.new(RUBY_PLATFORM)}.gem"
27
+ file NativeGem => :build do
28
+ require "rubygems/compiler"
29
+ compiler = Gem::Compiler.new("pkg/therubyracer-#{V8::VERSION}.gem", 'pkg')
30
+ compiler.compile
31
+ end
32
+
33
+ desc "Build #{NativeGem} into the pkg directory"
34
+ task "build:native" => NativeGem
35
+
36
+ desc "Build and install #{File.basename NativeGem} into system gems"
37
+ task "install:native" => "build:native" do
38
+ sh "gem install #{NativeGem}"
39
+ end
40
+
41
+ task :default => :spec
42
+
data/benchmarks.rb ADDED
@@ -0,0 +1,217 @@
1
+ require 'bundler/setup'
2
+ require 'v8'
3
+ require 'benchmark'
4
+ require 'optparse'
5
+
6
+ OPTIONS = {
7
+ :times => 5,
8
+ :mode => :object,
9
+ :objects => 500
10
+ }
11
+
12
+ parser = OptionParser.new do |opts|
13
+ opts.on("-t", "--times [T]", Integer, "run benchmark N times") do |t|
14
+ OPTIONS[:times] = t
15
+ end
16
+
17
+ opts.on("-m", "--mode [MODE]", [:object, :function, :eval], "select the type of object access to stress test") do |mode|
18
+ mode = mode.to_sym
19
+ raise "unsupported mode #{mode}" unless [:object,:function,:eval].include?(mode)
20
+ OPTIONS[:mode] = mode
21
+ end
22
+
23
+ opts.on("-o", "--objects [N]", Integer, "create N objects for each iteration") do |n|
24
+ OPTIONS[:objects] = n
25
+ end
26
+ opts
27
+ end
28
+
29
+ parser.parse! ARGV
30
+
31
+ MODE = OPTIONS[:mode]
32
+ TIMES = OPTIONS[:times]
33
+ OBJECTS = OPTIONS[:objects]
34
+
35
+ puts "using #{OPTIONS[:mode]}"
36
+ if MODE==:object
37
+ def get(i)
38
+ @cxt["test"]["objects"][i]
39
+ end
40
+ elsif MODE==:function
41
+ def get(i)
42
+ @cxt["test"].getObject(i)
43
+ end
44
+ elsif MODE==:eval
45
+ def get(i)
46
+ @cxt.eval "test.getObject(#{i})"
47
+ end
48
+ end
49
+
50
+ js= <<JS
51
+
52
+ function createTest()
53
+ {
54
+ var test = {};
55
+ test.objects = [];
56
+ test.seed = 49734321;
57
+ test.summ;
58
+
59
+ test.random = function()
60
+ {
61
+ // Robert Jenkins' 32 bit integer hash function.
62
+ test.seed = ((test.seed + 0x7ed55d16) + (test.seed << 12)) & 0xffffffff;
63
+ test.seed = ((test.seed ^ 0xc761c23c) ^ (test.seed >>> 19)) & 0xffffffff;
64
+ test.seed = ((test.seed + 0x165667b1) + (test.seed << 5)) & 0xffffffff;
65
+ test.seed = ((test.seed + 0xd3a2646c) ^ (test.seed << 9)) & 0xffffffff;
66
+ test.seed = ((test.seed + 0xfd7046c5) + (test.seed << 3)) & 0xffffffff;
67
+ test.seed = ((test.seed ^ 0xb55a4f09) ^ (test.seed >>> 16)) & 0xffffffff;
68
+ return (test.seed & 0xfffffff) / 0x10000000;
69
+ };
70
+
71
+ test.init = function()
72
+ {
73
+ test.objects = [];
74
+ for(var i=0; i<#{OBJECTS}; i++)
75
+ {
76
+ var hash = {};
77
+ for(var j=0; j<10; j++)
78
+ {
79
+ var isString = test.random();
80
+ var key = "str" + test.random();
81
+ var value;
82
+ if(isString < 0.5)
83
+ value = "str" + test.random();
84
+ else
85
+ value = test.random();
86
+ hash[key] = value;
87
+ }
88
+ test.objects[i] = hash;
89
+ }
90
+ return test.objects.length;
91
+ }
92
+
93
+ test.findSum = function()
94
+ {
95
+ test.summ = 0;
96
+ var length = test.objects.length;
97
+ for(var i=0; i<length; i++)
98
+ {
99
+ var hash = test.objects[i];
100
+ for (var k in hash)
101
+ {
102
+ if (hash.hasOwnProperty(k) && (typeof(hash[k]) == "number"))
103
+ {
104
+ test.summ += hash[k];
105
+ }
106
+ }
107
+ }
108
+ return test.summ;
109
+ };
110
+
111
+ test.finalCheck = function()
112
+ {
113
+ var summ = 0;
114
+ var length = test.objects.length;
115
+ for(var i=0; i<length; i++)
116
+ {
117
+ var hash = test.objects[i];
118
+ for (var k in hash)
119
+ {
120
+ if (hash.hasOwnProperty(k) && (typeof(hash[k]) == "number"))
121
+ {
122
+ summ += hash[k];
123
+ }
124
+ }
125
+ }
126
+ return summ ;
127
+ };
128
+
129
+ test.getObject = function(index)
130
+ {
131
+ if(!test.objects[index]) return {};
132
+ return test.objects[index];
133
+ }
134
+
135
+ test.setObject = function(index, object)
136
+ {
137
+ test.objects[index] = object;
138
+ }
139
+
140
+ return test;
141
+ }
142
+
143
+ JS
144
+
145
+
146
+
147
+
148
+
149
+ def profile
150
+ Benchmark.realtime do
151
+ yield
152
+ end
153
+ end
154
+
155
+ def get_res result
156
+ result.to_f
157
+ end
158
+
159
+
160
+
161
+
162
+
163
+ puts "init js context..."
164
+ cxt = V8::Context.new
165
+ @cxt=cxt
166
+ cxt.eval(js)
167
+
168
+ cxt.eval('var test = createTest()')
169
+
170
+ puts "run init test"
171
+ result =profile do
172
+ TIMES.times do
173
+ cxt['test'].init()
174
+ end
175
+ end
176
+
177
+ puts "init time: #{get_res(result) / TIMES} sec."
178
+ sum1=sum2=0
179
+ puts "run findSum test"
180
+
181
+ result =profile do
182
+ TIMES.times do
183
+ sum1= cxt['test'].findSum
184
+ end
185
+ end
186
+
187
+ puts "findSum time: #{get_res(result) / TIMES} sec."
188
+
189
+
190
+ puts "run Objects inversion in ruby test"
191
+ result =profile do
192
+ TIMES.times do |j|
193
+ puts j
194
+ for i in 0..(OBJECTS-1) do
195
+ obj = get(i)
196
+ obj.each do |key, value|
197
+ if value.instance_of? Float
198
+ obj[key] = value * (-1)
199
+ end
200
+ end
201
+ end
202
+ end
203
+ end
204
+
205
+ puts "Objects time: #{get_res(result) / TIMES} sec."
206
+
207
+ puts "run finalCheck test"
208
+
209
+
210
+ result =profile do
211
+ TIMES.times do
212
+ sum2= cxt['test'].findSum
213
+ end
214
+ end
215
+
216
+ puts "final check time: #{get_res(result) / TIMES} sec."
217
+ puts "#{sum1==sum2*(TIMES%2==0?1:-1) ? 'TEST PASS': 'TEST FAIL'}: Sum before inversions: #{sum1} / Sum after inversions: #{sum2}"