mini_racer 0.6.4 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +64 -121
- data/README.md +115 -131
- data/ext/mini_racer_extension/mini_racer_extension.cc +3 -3
- data/lib/mini_racer/version.rb +2 -2
- data/lib/mini_racer_extension.so +0 -0
- data/lib/mini_racer_loader.so +0 -0
- metadata +10 -17
- data/.dockerignore +0 -12
- data/.github/workflows/ci.yml +0 -124
- data/.gitignore +0 -13
- data/Dockerfile +0 -21
- data/Gemfile +0 -4
- data/Rakefile +0 -108
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/mini_racer.gemspec +0 -39
data/README.md
CHANGED
@@ -1,22 +1,30 @@
|
|
1
1
|
# MiniRacer
|
2
2
|
|
3
|
-
[![Test](https://github.com/rubyjs/mini_racer/actions/workflows/ci.yml/badge.svg)](https://github.com/rubyjs/mini_racer/actions/workflows/ci.yml)
|
3
|
+
[![Test](https://github.com/rubyjs/mini_racer/actions/workflows/ci.yml/badge.svg)](https://github.com/rubyjs/mini_racer/actions/workflows/ci.yml) ![Gem](https://img.shields.io/gem/v/mini_racer)
|
4
4
|
|
5
5
|
Minimal, modern embedded V8 for Ruby.
|
6
6
|
|
7
7
|
MiniRacer provides a minimal two way bridge between the V8 JavaScript engine and Ruby.
|
8
8
|
|
9
|
-
It was created as an alternative to the excellent [therubyracer](https://github.com/cowboyd/therubyracer). Unlike therubyracer, mini_racer only implements a minimal bridge. This reduces the surface area making upgrading v8 much simpler and exhaustive testing simpler.
|
9
|
+
It was created as an alternative to the excellent [therubyracer](https://github.com/cowboyd/therubyracer), which is [no longer maintained](https://github.com/rubyjs/therubyracer/issues/462). Unlike therubyracer, mini_racer only implements a minimal bridge. This reduces the surface area making upgrading v8 much simpler and exhaustive testing simpler.
|
10
10
|
|
11
11
|
MiniRacer has an adapter for [execjs](https://github.com/rails/execjs) so it can be used directly with Rails projects to minify assets, run babel or compile CoffeeScript.
|
12
12
|
|
13
|
-
|
13
|
+
## Supported Ruby Versions & Troubleshooting
|
14
14
|
|
15
|
-
MiniRacer only supports non-EOL versions of Ruby. See [Ruby Maintenance Branches](https://www.ruby-lang.org/en/downloads/branches/) for the list of non-EOL Rubies.
|
15
|
+
MiniRacer only supports non-EOL versions of Ruby. See [Ruby Maintenance Branches](https://www.ruby-lang.org/en/downloads/branches/) for the list of non-EOL Rubies. If you require support for older versions of Ruby install an older version of the gem.
|
16
16
|
|
17
|
-
|
17
|
+
MiniRacer **does not support** [Ruby built on MinGW](https://github.com/rubyjs/mini_racer/issues/252#issuecomment-1201172236), "pure windows" no Cygwin, no WSL2 (see https://github.com/rubyjs/libv8-node/issues/9).
|
18
18
|
|
19
|
-
|
19
|
+
If you have a problem installing MiniRacer, please consider the following steps:
|
20
|
+
|
21
|
+
* make sure you try the latest released version of `mini_racer`
|
22
|
+
* make sure you have Rubygems >= 3.2.13 and bundler >= 2.2.13 installed: `gem update --system`
|
23
|
+
* if you are using bundler
|
24
|
+
* make sure it is actually using the latest bundler version: [`bundle update --bundler`](https://bundler.io/v2.4/man/bundle-update.1.html)
|
25
|
+
* make sure to have `PLATFORMS` set correctly in `Gemfile.lock` via [`bundle lock --add-platform`](https://bundler.io/v2.4/man/bundle-lock.1.html#SUPPORTING-OTHER-PLATFORMS)
|
26
|
+
* make sure to recompile/reinstall `mini_racer` and `libv8-node` after OS upgrades (for example via `gem uninstall --all mini_racer libv8-node`)
|
27
|
+
* make sure you are on the latest patch/teeny version of a supported Ruby branch
|
20
28
|
|
21
29
|
## Features
|
22
30
|
|
@@ -26,8 +34,8 @@ You can simply eval one or many JavaScript snippets in a shared context
|
|
26
34
|
|
27
35
|
```ruby
|
28
36
|
context = MiniRacer::Context.new
|
29
|
-
context.eval
|
30
|
-
puts context.eval
|
37
|
+
context.eval("var adder = (a,b)=>a+b;")
|
38
|
+
puts context.eval("adder(20,22)")
|
31
39
|
# => 42
|
32
40
|
```
|
33
41
|
|
@@ -38,20 +46,20 @@ You can attach one or many ruby proc that can be accessed via JavaScript
|
|
38
46
|
```ruby
|
39
47
|
context = MiniRacer::Context.new
|
40
48
|
context.attach("math.adder", proc{|a,b| a+b})
|
41
|
-
puts context.eval
|
49
|
+
puts context.eval("math.adder(20,22)")
|
42
50
|
# => 42
|
43
51
|
```
|
44
52
|
|
45
53
|
```ruby
|
46
54
|
context = MiniRacer::Context.new
|
47
55
|
context.attach("array_and_hash", proc{{a: 1, b: [1, {a: 1}]}})
|
48
|
-
puts context.eval
|
56
|
+
puts context.eval("array_and_hash()")
|
49
57
|
# => {"a" => 1, "b" => [1, {"a" => 1}]}
|
50
58
|
```
|
51
59
|
|
52
60
|
### GIL free JavaScript execution
|
53
61
|
|
54
|
-
The Ruby Global interpreter lock is released when scripts are executing
|
62
|
+
The Ruby Global interpreter lock is released when scripts are executing:
|
55
63
|
|
56
64
|
```ruby
|
57
65
|
context = MiniRacer::Context.new
|
@@ -59,35 +67,34 @@ Thread.new do
|
|
59
67
|
sleep 1
|
60
68
|
context.stop
|
61
69
|
end
|
62
|
-
context.eval
|
70
|
+
context.eval("while(true){}")
|
63
71
|
# => exception is raised
|
64
72
|
```
|
65
73
|
|
66
74
|
This allows you to execute multiple scripts in parallel.
|
67
75
|
|
68
|
-
### Timeout
|
76
|
+
### Timeout Support
|
69
77
|
|
70
78
|
Contexts can specify a default timeout for scripts
|
71
79
|
|
72
80
|
```ruby
|
73
|
-
# times out after 1 second (1000 ms)
|
74
81
|
context = MiniRacer::Context.new(timeout: 1000)
|
75
|
-
context.eval
|
76
|
-
# => exception is raised
|
82
|
+
context.eval("while(true){}")
|
83
|
+
# => exception is raised after 1 second (1000 ms)
|
77
84
|
```
|
78
85
|
|
79
|
-
### Memory softlimit
|
86
|
+
### Memory softlimit Support
|
80
87
|
|
81
88
|
Contexts can specify a memory softlimit for scripts
|
82
89
|
|
83
90
|
```ruby
|
84
91
|
# terminates script if heap usage exceeds 200mb after V8 garbage collection has run
|
85
|
-
context = MiniRacer::Context.new(max_memory:
|
86
|
-
context.eval
|
92
|
+
context = MiniRacer::Context.new(max_memory: 200_000_000)
|
93
|
+
context.eval("var a = new Array(10000); while(true) {a = a.concat(new Array(10000)) }")
|
87
94
|
# => V8OutOfMemoryError is raised
|
88
95
|
```
|
89
96
|
|
90
|
-
### Object marshal max
|
97
|
+
### Object marshal max Stack Ddepth Support
|
91
98
|
|
92
99
|
Contexts can specify a stack depth limit for object marshalling. Max depth is unbounded by default.
|
93
100
|
|
@@ -100,23 +107,24 @@ context.eval("let arr = []; arr.push(arr); a(arr)")
|
|
100
107
|
# => RuntimeError is raised
|
101
108
|
```
|
102
109
|
|
103
|
-
### Rich
|
110
|
+
### Rich Debugging with File Name in Stack Trace Support
|
104
111
|
|
105
|
-
|
112
|
+
You can provide `filename:` to `#eval` which will be used in stack traces produced by V8:
|
106
113
|
|
114
|
+
```ruby
|
107
115
|
context = MiniRacer::Context.new
|
108
|
-
context.eval(
|
109
|
-
context.eval(
|
110
|
-
|
111
|
-
# MiniRacer::RuntimeError is raised containing the filenames you specified for evals in backtrace
|
116
|
+
context.eval("var foo = function() {bar();}", filename: "a/foo.js")
|
117
|
+
context.eval("bar()", filename: "a/bar.js")
|
112
118
|
|
119
|
+
# JavaScript at a/bar.js:1:1: ReferenceError: bar is not defined (MiniRacer::RuntimeError)
|
120
|
+
# …
|
113
121
|
```
|
114
122
|
|
115
|
-
### Fork
|
123
|
+
### Fork Safety
|
116
124
|
|
117
125
|
Some Ruby web servers employ forking (for example unicorn or puma in clustered mode). V8 is not fork safe by default and sadly Ruby does not have support for fork notifications per [#5446](https://bugs.ruby-lang.org/issues/5446).
|
118
126
|
|
119
|
-
Since 0.6.1 mini_racer does support V8 single threaded platform mode which should remove most forking related issues. To enable run this before using `MiniRacer::Context
|
127
|
+
Since 0.6.1 mini_racer does support V8 single threaded platform mode which should remove most forking related issues. To enable run this before using `MiniRacer::Context`, for example in a Rails initializer:
|
120
128
|
|
121
129
|
```ruby
|
122
130
|
MiniRacer::Platform.set_flags!(:single_threaded)
|
@@ -124,16 +132,13 @@ MiniRacer::Platform.set_flags!(:single_threaded)
|
|
124
132
|
|
125
133
|
If you want to ensure your application does not leak memory after fork either:
|
126
134
|
|
127
|
-
1. Ensure no `MiniRacer::Context` objects are created in the master process
|
128
|
-
|
129
|
-
Or
|
130
|
-
|
135
|
+
1. Ensure no `MiniRacer::Context` objects are created in the master process; or
|
131
136
|
2. Dispose manually of all `MiniRacer::Context` objects prior to forking
|
132
137
|
|
133
138
|
```ruby
|
134
139
|
# before fork
|
135
140
|
|
136
|
-
require
|
141
|
+
require "objspace"
|
137
142
|
ObjectSpace.each_object(MiniRacer::Context){|c| c.dispose}
|
138
143
|
|
139
144
|
# fork here
|
@@ -144,9 +149,8 @@ ObjectSpace.each_object(MiniRacer::Context){|c| c.dispose}
|
|
144
149
|
Context usage is threadsafe
|
145
150
|
|
146
151
|
```ruby
|
147
|
-
|
148
152
|
context = MiniRacer::Context.new
|
149
|
-
context.eval(
|
153
|
+
context.eval("counter=0; plus=()=>counter++;")
|
150
154
|
|
151
155
|
(1..10).map do
|
152
156
|
Thread.new {
|
@@ -156,7 +160,6 @@ end.each(&:join)
|
|
156
160
|
|
157
161
|
puts context.eval("counter")
|
158
162
|
# => 10
|
159
|
-
|
160
163
|
```
|
161
164
|
|
162
165
|
### Snapshots
|
@@ -164,46 +167,40 @@ puts context.eval("counter")
|
|
164
167
|
Contexts can be created with pre-loaded snapshots:
|
165
168
|
|
166
169
|
```ruby
|
167
|
-
|
168
|
-
snapshot = MiniRacer::Snapshot.new('function hello() { return "world!"; }')
|
170
|
+
snapshot = MiniRacer::Snapshot.new("function hello() { return 'world!'; }")
|
169
171
|
|
170
172
|
context = MiniRacer::Context.new(snapshot: snapshot)
|
171
173
|
|
172
174
|
context.eval("hello()")
|
173
175
|
# => "world!"
|
174
|
-
|
175
|
-
```
|
176
|
-
|
177
|
-
Snapshots can come in handy for example if you want your contexts to be pre-loaded for effiency. It uses [V8 snapshots](http://v8project.blogspot.com/2015/09/custom-startup-snapshots.html) under the hood; see [this link](http://v8project.blogspot.com/2015/09/custom-startup-snapshots.html) for caveats using these, in particular:
|
178
|
-
|
179
176
|
```
|
180
|
-
There is an important limitation to snapshots: they can only capture V8’s
|
181
|
-
heap. Any interaction from V8 with the outside is off-limits when creating the
|
182
|
-
snapshot. Such interactions include:
|
183
177
|
|
184
|
-
|
185
|
-
* creating typed arrays, since the backing store may be allocated outside of V8
|
178
|
+
Snapshots can come in handy for example if you want your contexts to be pre-loaded for efficiency. It uses [V8 snapshots](http://v8project.blogspot.com/2015/09/custom-startup-snapshots.html) under the hood; see [this link](http://v8project.blogspot.com/2015/09/custom-startup-snapshots.html) for caveats using these, in particular:
|
186
179
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
180
|
+
> There is an important limitation to snapshots: they can only capture V8’s
|
181
|
+
> heap. Any interaction from V8 with the outside is off-limits when creating the
|
182
|
+
> snapshot. Such interactions include:
|
183
|
+
>
|
184
|
+
> * defining and calling API callbacks (i.e. functions created via v8::FunctionTemplate)
|
185
|
+
> * creating typed arrays, since the backing store may be allocated outside of V8
|
186
|
+
>
|
187
|
+
> And of course, values derived from sources such as `Math.random` or `Date.now`
|
188
|
+
> are fixed once the snapshot has been captured. They are no longer really random
|
189
|
+
> nor reflect the current time.
|
191
190
|
|
192
191
|
Also note that snapshots can be warmed up, using the `warmup!` method, which allows you to call functions which are otherwise lazily compiled to get them to compile right away; any side effect of your warm up code being then dismissed. [More details on warming up here](https://github.com/electron/electron/issues/169#issuecomment-76783481), and a small example:
|
193
192
|
|
194
193
|
```ruby
|
194
|
+
snapshot = MiniRacer::Snapshot.new("var counter = 0; function hello() { counter++; return 'world! '; }")
|
195
195
|
|
196
|
-
snapshot
|
197
|
-
|
198
|
-
snapshot.warmup!('hello()')
|
196
|
+
snapshot.warmup!("hello()")
|
199
197
|
|
200
198
|
context = MiniRacer::Context.new(snapshot: snapshot)
|
201
199
|
|
202
|
-
context.eval(
|
200
|
+
context.eval("hello()")
|
203
201
|
# => "world! 1"
|
204
|
-
context.eval(
|
202
|
+
context.eval("counter")
|
205
203
|
# => 1
|
206
|
-
|
207
204
|
```
|
208
205
|
|
209
206
|
### Shared isolates
|
@@ -211,7 +208,6 @@ context.eval('counter')
|
|
211
208
|
By default, MiniRacer's contexts each have their own isolate (V8 runtime). For efficiency, it is possible to re-use an isolate across contexts:
|
212
209
|
|
213
210
|
```ruby
|
214
|
-
|
215
211
|
isolate = MiniRacer::Isolate.new
|
216
212
|
|
217
213
|
context1 = MiniRacer::Context.new(isolate: isolate)
|
@@ -228,7 +224,7 @@ The caveat with this is that a given isolate can only execute one context at a t
|
|
228
224
|
Also, note that if you want to use shared isolates together with snapshots, you need to first create an isolate with that snapshot, and then create contexts from that isolate:
|
229
225
|
|
230
226
|
```ruby
|
231
|
-
snapshot = MiniRacer::Snapshot.new(
|
227
|
+
snapshot = MiniRacer::Snapshot.new("function hello() { return 'world!'; }")
|
232
228
|
|
233
229
|
isolate = MiniRacer::Isolate.new(snapshot)
|
234
230
|
|
@@ -252,7 +248,6 @@ isolate.idle_notification(100)
|
|
252
248
|
|
253
249
|
# force V8 to perform a full GC
|
254
250
|
isolate.low_memory_notification
|
255
|
-
|
256
251
|
```
|
257
252
|
|
258
253
|
This can come in handy to force V8 GC runs for example in between requests if you use MiniRacer on a web application.
|
@@ -270,11 +265,13 @@ MiniRacer::Platform.set_flags! :noconcurrent_recompilation, max_inlining_levels:
|
|
270
265
|
```
|
271
266
|
|
272
267
|
This can come in handy if you want to use MiniRacer with Unicorn, which doesn't seem to always appreciate V8's liberal use of threading:
|
268
|
+
|
273
269
|
```ruby
|
274
270
|
MiniRacer::Platform.set_flags! :noconcurrent_recompilation, :noconcurrent_sweeping
|
275
271
|
```
|
276
272
|
|
277
273
|
Or else to unlock experimental features in V8, for example tail recursion optimization:
|
274
|
+
|
278
275
|
```ruby
|
279
276
|
MiniRacer::Platform.set_flags! :harmony
|
280
277
|
|
@@ -295,6 +292,7 @@ context = MiniRacer::Context.new
|
|
295
292
|
context.eval js
|
296
293
|
# => "foo"
|
297
294
|
```
|
295
|
+
|
298
296
|
The same code without the harmony runtime flag results in a `MiniRacer::RuntimeError: RangeError: Maximum call stack size exceeded` exception.
|
299
297
|
Please refer to http://node.green/ as a reference on other harmony features.
|
300
298
|
|
@@ -304,17 +302,18 @@ Note that runtime flags must be set before any other operation (e.g. creating a
|
|
304
302
|
|
305
303
|
Flags:
|
306
304
|
|
307
|
-
|
308
|
-
|
309
|
-
|
305
|
+
* `:expose_gc`: Will expose `gc()` which you can run in JavaScript to issue a GC run.
|
306
|
+
* `:max_old_space_size`: defaults to 1400 (megs) on 64 bit, you can restrict memory usage by limiting this.
|
307
|
+
|
308
|
+
**NOTE TO READER** our documentation could be awesome we could be properly documenting all the flags, they are hugely useful, if you feel like documenting a few more, PLEASE DO, PRs are welcome.
|
310
309
|
|
311
310
|
## Controlling memory
|
312
311
|
|
313
|
-
When hosting v8 you may want to keep track of memory usage, use
|
312
|
+
When hosting v8 you may want to keep track of memory usage, use `#heap_stats` to get memory usage:
|
314
313
|
|
315
314
|
```ruby
|
316
|
-
context = MiniRacer::Context.new
|
317
|
-
context
|
315
|
+
context = MiniRacer::Context.new
|
316
|
+
# use context
|
318
317
|
p context.heap_stats
|
319
318
|
# {:total_physical_size=>1280640,
|
320
319
|
# :total_heap_size_executable=>4194304,
|
@@ -323,27 +322,27 @@ p context.heap_stats
|
|
323
322
|
# :heap_size_limit=>1501560832}
|
324
323
|
```
|
325
324
|
|
326
|
-
If you wish to dispose of a context before waiting on the GC use
|
325
|
+
If you wish to dispose of a context before waiting on the GC use `#dispose`:
|
327
326
|
|
328
327
|
```ruby
|
329
|
-
context = MiniRacer::Context.new
|
328
|
+
context = MiniRacer::Context.new
|
330
329
|
context.eval("let a='testing';")
|
331
330
|
context.dispose
|
332
331
|
context.eval("a = 2")
|
333
332
|
# MiniRacer::ContextDisposedError
|
334
333
|
|
335
|
-
# nothing works on the context from now on,
|
334
|
+
# nothing works on the context from now on, it's a shell waiting to be disposed
|
336
335
|
```
|
337
336
|
|
338
337
|
A MiniRacer context can also be dumped in a heapsnapshot file using `#write_heap_snapshot(file_or_io)`
|
339
338
|
|
340
339
|
```ruby
|
341
|
-
context = MiniRacer::Context.new
|
342
|
-
context
|
340
|
+
context = MiniRacer::Context.new
|
341
|
+
# use context
|
343
342
|
context.write_heap_snapshot("test.heapsnapshot")
|
344
343
|
```
|
345
344
|
|
346
|
-
This file can then be loaded in the memory tab of the
|
345
|
+
This file can then be loaded in the "memory" tab of the [Chrome DevTools](https://developer.chrome.com/docs/devtools/memory-problems/heap-snapshots/#view_snapshots).
|
347
346
|
|
348
347
|
### Function call
|
349
348
|
|
@@ -351,30 +350,29 @@ This calls the function passed as first argument:
|
|
351
350
|
|
352
351
|
```ruby
|
353
352
|
context = MiniRacer::Context.new
|
354
|
-
context.eval(
|
355
|
-
context.call(
|
353
|
+
context.eval("function hello(name) { return `Hello, ${name}!` }")
|
354
|
+
context.call("hello", "George")
|
356
355
|
# "Hello, George!"
|
357
356
|
```
|
358
357
|
|
359
|
-
Performance is slightly better than running `eval(
|
358
|
+
Performance is slightly better than running `context.eval("hello('George')")` since:
|
360
359
|
|
361
|
-
|
362
|
-
|
360
|
+
* compilation of eval'd string is avoided
|
361
|
+
* function arguments don't need to be converted to JSON
|
363
362
|
|
364
363
|
## Performance
|
365
364
|
|
366
365
|
The `bench` folder contains benchmark.
|
367
366
|
|
368
|
-
### Benchmark minification of Discourse application.js (both minified and
|
367
|
+
### Benchmark minification of Discourse application.js (both minified and non-minified)
|
369
368
|
|
370
369
|
MiniRacer outperforms node when minifying assets via execjs.
|
371
370
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
```
|
371
|
+
* MiniRacer version 0.1.9
|
372
|
+
* node version 6.10
|
373
|
+
* therubyracer version 0.12.2
|
377
374
|
|
375
|
+
```terminal
|
378
376
|
$ bundle exec ruby bench.rb mini_racer
|
379
377
|
Benching with mini_racer
|
380
378
|
mini_racer minify discourse_app.js 9292.72063ms
|
@@ -411,78 +409,64 @@ MiniRacer can fully support source maps but must be configured correctly to do s
|
|
411
409
|
Add this line to your application's Gemfile:
|
412
410
|
|
413
411
|
```ruby
|
414
|
-
gem
|
412
|
+
gem "mini_racer"
|
415
413
|
```
|
416
414
|
|
417
415
|
And then execute:
|
418
416
|
|
419
|
-
|
417
|
+
```terminal
|
418
|
+
$ bundle
|
420
419
|
|
421
420
|
Or install it yourself as:
|
422
421
|
|
423
|
-
|
424
|
-
|
422
|
+
```terminal
|
423
|
+
$ gem install mini_racer
|
424
|
+
```
|
425
425
|
|
426
426
|
**Note** using v8.h and compiling MiniRacer requires a C++11 standard compiler, more specifically clang 3.5 (or later) or GCC 6.3 (or later).
|
427
427
|
|
428
|
-
|
429
|
-
### Troubleshooting
|
430
|
-
|
431
|
-
If you have a problem installing mini_racer, please consider the following steps:
|
432
|
-
|
433
|
-
* make sure you try the latest released version of mini_racer
|
434
|
-
* make sure you have Rubygems >= 3.2.13 and bundler >= 2.2.13 installed via `gem update --system`
|
435
|
-
* if you are using bundler, make sure to have `PLATFORMS` set correctly in `Gemfile.lock` via `bundle lock --add-platform`
|
436
|
-
* make sure to recompile/reinstall `mini_racer` and `libv8-node` after system upgrades (for example via `gem uninstall --all mini_racer libv8-node`)
|
437
|
-
* make sure you are on the latest patch/teeny version of a supported Ruby branch
|
438
|
-
|
439
428
|
## Similar Projects
|
440
429
|
|
441
430
|
### therubyracer
|
442
431
|
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
432
|
+
* https://github.com/cowboyd/therubyracer
|
433
|
+
* Most comprehensive bridge available
|
434
|
+
* Provides the ability to "eval" JavaScript
|
435
|
+
* Provides the ability to invoke Ruby code from JavaScript
|
436
|
+
* Hold references to JavaScript objects and methods in your Ruby code
|
437
|
+
* Hold references to Ruby objects and methods in JavaScript code
|
438
|
+
* Uses libv8, so installation is fast
|
439
|
+
* Supports timeouts for JavaScript execution
|
440
|
+
* Does not release global interpreter lock, so performance is constrained to a single thread
|
441
|
+
* Currently (May 2016) only supports v8 version 3.16.14 (Released approx November 2013), plans to upgrade by July 2016
|
442
|
+
* Supports execjs
|
455
443
|
|
456
444
|
### v8eval
|
457
445
|
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
446
|
+
* https://github.com/sony/v8eval
|
447
|
+
* Provides the ability to "eval" JavaScript using the latest V8 engine
|
448
|
+
* Does not depend on the [libv8](https://github.com/cowboyd/libv8) gem, installation can take 10-20 mins as V8 needs to be downloaded and compiled.
|
449
|
+
* Does not release global interpreter lock when executing JavaScript
|
450
|
+
* Does not allow you to invoke Ruby code from JavaScript
|
451
|
+
* Multi runtime support due to SWIG based bindings
|
452
|
+
* Supports a JavaScript debugger
|
453
|
+
* Does not support timeouts for JavaScript execution
|
454
|
+
* No support for execjs (can not be used with Rails uglifier and coffeescript gems)
|
468
455
|
|
469
456
|
### therubyrhino
|
470
457
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
458
|
+
* https://github.com/cowboyd/therubyrhino
|
459
|
+
* API compatible with therubyracer
|
460
|
+
* Uses Mozilla's Rhino engine https://github.com/mozilla/rhino
|
461
|
+
* Requires JRuby
|
462
|
+
* Support for timeouts for JavaScript execution
|
463
|
+
* Concurrent cause .... JRuby
|
464
|
+
* Supports execjs
|
479
465
|
|
480
466
|
## Contributing
|
481
467
|
|
482
468
|
Bug reports and pull requests are welcome on GitHub at https://github.com/rubyjs/mini_racer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
483
469
|
|
484
|
-
|
485
470
|
## License
|
486
471
|
|
487
472
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
488
|
-
|
@@ -518,7 +518,7 @@ nogvl_context_eval(void* arg) {
|
|
518
518
|
MaybeLocal<Script> parsed_script;
|
519
519
|
|
520
520
|
if (eval_params->filename) {
|
521
|
-
origin = new v8::ScriptOrigin(*eval_params->filename);
|
521
|
+
origin = new v8::ScriptOrigin(isolate, *eval_params->filename);
|
522
522
|
}
|
523
523
|
|
524
524
|
parsed_script = Script::Compile(context, *eval_params->eval, origin);
|
@@ -658,7 +658,7 @@ static VALUE convert_v8_to_ruby(Isolate* isolate, Local<Context> context,
|
|
658
658
|
|
659
659
|
if (value->IsSymbol()) {
|
660
660
|
v8::String::Utf8Value symbol_name(isolate,
|
661
|
-
Local<Symbol>::Cast(value)->
|
661
|
+
Local<Symbol>::Cast(value)->Description(isolate));
|
662
662
|
|
663
663
|
VALUE str_symbol = rb_utf8_str_new(*symbol_name, symbol_name.length());
|
664
664
|
|
@@ -791,7 +791,7 @@ static bool run_extra_code(Isolate *isolate, Local<v8::Context> context,
|
|
791
791
|
}
|
792
792
|
Local<String> resource_name =
|
793
793
|
String::NewFromUtf8(isolate, name).ToLocalChecked();
|
794
|
-
ScriptOrigin origin(resource_name);
|
794
|
+
ScriptOrigin origin(isolate, resource_name);
|
795
795
|
ScriptCompiler::Source source(source_string, origin);
|
796
796
|
Local<Script> script;
|
797
797
|
if (!ScriptCompiler::Compile(context, &source).ToLocal(&script))
|
data/lib/mini_racer/version.rb
CHANGED
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_racer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 16.
|
89
|
+
version: 18.16.0.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 16.
|
96
|
+
version: 18.16.0.0
|
97
97
|
description: Minimal embedded v8 engine for Ruby
|
98
98
|
email:
|
99
99
|
- sam.saffron@gmail.com
|
@@ -103,18 +103,10 @@ extensions:
|
|
103
103
|
- ext/mini_racer_extension/extconf.rb
|
104
104
|
extra_rdoc_files: []
|
105
105
|
files:
|
106
|
-
- ".dockerignore"
|
107
|
-
- ".github/workflows/ci.yml"
|
108
|
-
- ".gitignore"
|
109
106
|
- CHANGELOG
|
110
107
|
- CODE_OF_CONDUCT.md
|
111
|
-
- Dockerfile
|
112
|
-
- Gemfile
|
113
108
|
- LICENSE.txt
|
114
109
|
- README.md
|
115
|
-
- Rakefile
|
116
|
-
- bin/console
|
117
|
-
- bin/setup
|
118
110
|
- ext/mini_racer_extension/extconf.rb
|
119
111
|
- ext/mini_racer_extension/mini_racer_extension.cc
|
120
112
|
- ext/mini_racer_loader/extconf.rb
|
@@ -122,15 +114,16 @@ files:
|
|
122
114
|
- lib/mini_racer.rb
|
123
115
|
- lib/mini_racer/truffleruby.rb
|
124
116
|
- lib/mini_racer/version.rb
|
125
|
-
-
|
117
|
+
- lib/mini_racer_extension.so
|
118
|
+
- lib/mini_racer_loader.so
|
126
119
|
homepage: https://github.com/discourse/mini_racer
|
127
120
|
licenses:
|
128
121
|
- MIT
|
129
122
|
metadata:
|
130
123
|
bug_tracker_uri: https://github.com/discourse/mini_racer/issues
|
131
|
-
changelog_uri: https://github.com/discourse/mini_racer/blob/v0.
|
132
|
-
documentation_uri: https://www.rubydoc.info/gems/mini_racer/0.
|
133
|
-
source_code_uri: https://github.com/discourse/mini_racer/tree/v0.
|
124
|
+
changelog_uri: https://github.com/discourse/mini_racer/blob/v0.8.0/CHANGELOG
|
125
|
+
documentation_uri: https://www.rubydoc.info/gems/mini_racer/0.8.0
|
126
|
+
source_code_uri: https://github.com/discourse/mini_racer/tree/v0.8.0
|
134
127
|
post_install_message:
|
135
128
|
rdoc_options: []
|
136
129
|
require_paths:
|
@@ -140,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
133
|
requirements:
|
141
134
|
- - ">="
|
142
135
|
- !ruby/object:Gem::Version
|
143
|
-
version: '
|
136
|
+
version: '3.0'
|
144
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
138
|
requirements:
|
146
139
|
- - ">="
|