mini_racer 0.6.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,20 +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
- ### A note about Ruby version Support
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
- If you require support for older versions of Ruby install an older version of the gem.
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
+
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
18
28
 
19
29
  ## Features
20
30
 
@@ -24,8 +34,8 @@ You can simply eval one or many JavaScript snippets in a shared context
24
34
 
25
35
  ```ruby
26
36
  context = MiniRacer::Context.new
27
- context.eval 'var adder = (a,b)=>a+b;'
28
- puts context.eval 'adder(20,22)'
37
+ context.eval("var adder = (a,b)=>a+b;")
38
+ puts context.eval("adder(20,22)")
29
39
  # => 42
30
40
  ```
31
41
 
@@ -36,20 +46,20 @@ You can attach one or many ruby proc that can be accessed via JavaScript
36
46
  ```ruby
37
47
  context = MiniRacer::Context.new
38
48
  context.attach("math.adder", proc{|a,b| a+b})
39
- puts context.eval 'math.adder(20,22)'
49
+ puts context.eval("math.adder(20,22)")
40
50
  # => 42
41
51
  ```
42
52
 
43
53
  ```ruby
44
54
  context = MiniRacer::Context.new
45
55
  context.attach("array_and_hash", proc{{a: 1, b: [1, {a: 1}]}})
46
- puts context.eval 'array_and_hash()'
56
+ puts context.eval("array_and_hash()")
47
57
  # => {"a" => 1, "b" => [1, {"a" => 1}]}
48
58
  ```
49
59
 
50
60
  ### GIL free JavaScript execution
51
61
 
52
- The Ruby Global interpreter lock is released when scripts are executing
62
+ The Ruby Global interpreter lock is released when scripts are executing:
53
63
 
54
64
  ```ruby
55
65
  context = MiniRacer::Context.new
@@ -57,35 +67,34 @@ Thread.new do
57
67
  sleep 1
58
68
  context.stop
59
69
  end
60
- context.eval 'while(true){}'
70
+ context.eval("while(true){}")
61
71
  # => exception is raised
62
72
  ```
63
73
 
64
74
  This allows you to execute multiple scripts in parallel.
65
75
 
66
- ### Timeout support
76
+ ### Timeout Support
67
77
 
68
78
  Contexts can specify a default timeout for scripts
69
79
 
70
80
  ```ruby
71
- # times out after 1 second (1000 ms)
72
81
  context = MiniRacer::Context.new(timeout: 1000)
73
- context.eval 'while(true){}'
74
- # => exception is raised
82
+ context.eval("while(true){}")
83
+ # => exception is raised after 1 second (1000 ms)
75
84
  ```
76
85
 
77
- ### Memory softlimit support
86
+ ### Memory softlimit Support
78
87
 
79
88
  Contexts can specify a memory softlimit for scripts
80
89
 
81
90
  ```ruby
82
91
  # terminates script if heap usage exceeds 200mb after V8 garbage collection has run
83
- context = MiniRacer::Context.new(max_memory: 200000000)
84
- context.eval 'var a = new Array(10000); while(true) {a = a.concat(new Array(10000)); print("loop " + a.length);}'
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)) }")
85
94
  # => V8OutOfMemoryError is raised
86
95
  ```
87
96
 
88
- ### Object marshal max stackdepth support
97
+ ### Object marshal max Stack Ddepth Support
89
98
 
90
99
  Contexts can specify a stack depth limit for object marshalling. Max depth is unbounded by default.
91
100
 
@@ -98,23 +107,24 @@ context.eval("let arr = []; arr.push(arr); a(arr)")
98
107
  # => RuntimeError is raised
99
108
  ```
100
109
 
101
- ### Rich debugging with "filename" support
110
+ ### Rich Debugging with File Name in Stack Trace Support
102
111
 
103
- ```ruby
112
+ You can provide `filename:` to `#eval` which will be used in stack traces produced by V8:
104
113
 
114
+ ```ruby
105
115
  context = MiniRacer::Context.new
106
- context.eval('var foo = function() {bar();}', filename: 'a/foo.js')
107
- context.eval('bar()', filename: 'a/bar.js')
108
-
109
- # 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")
110
118
 
119
+ # JavaScript at a/bar.js:1:1: ReferenceError: bar is not defined (MiniRacer::RuntimeError)
120
+ # …
111
121
  ```
112
122
 
113
- ### Fork safety
123
+ ### Fork Safety
114
124
 
115
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).
116
126
 
117
- 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:
118
128
 
119
129
  ```ruby
120
130
  MiniRacer::Platform.set_flags!(:single_threaded)
@@ -122,16 +132,13 @@ MiniRacer::Platform.set_flags!(:single_threaded)
122
132
 
123
133
  If you want to ensure your application does not leak memory after fork either:
124
134
 
125
- 1. Ensure no `MiniRacer::Context` objects are created in the master process
126
-
127
- Or
128
-
135
+ 1. Ensure no `MiniRacer::Context` objects are created in the master process; or
129
136
  2. Dispose manually of all `MiniRacer::Context` objects prior to forking
130
137
 
131
138
  ```ruby
132
139
  # before fork
133
140
 
134
- require 'objspace'
141
+ require "objspace"
135
142
  ObjectSpace.each_object(MiniRacer::Context){|c| c.dispose}
136
143
 
137
144
  # fork here
@@ -142,9 +149,8 @@ ObjectSpace.each_object(MiniRacer::Context){|c| c.dispose}
142
149
  Context usage is threadsafe
143
150
 
144
151
  ```ruby
145
-
146
152
  context = MiniRacer::Context.new
147
- context.eval('counter=0; plus=()=>counter++;')
153
+ context.eval("counter=0; plus=()=>counter++;")
148
154
 
149
155
  (1..10).map do
150
156
  Thread.new {
@@ -154,7 +160,6 @@ end.each(&:join)
154
160
 
155
161
  puts context.eval("counter")
156
162
  # => 10
157
-
158
163
  ```
159
164
 
160
165
  ### Snapshots
@@ -162,46 +167,40 @@ puts context.eval("counter")
162
167
  Contexts can be created with pre-loaded snapshots:
163
168
 
164
169
  ```ruby
165
-
166
- snapshot = MiniRacer::Snapshot.new('function hello() { return "world!"; }')
170
+ snapshot = MiniRacer::Snapshot.new("function hello() { return 'world!'; }")
167
171
 
168
172
  context = MiniRacer::Context.new(snapshot: snapshot)
169
173
 
170
174
  context.eval("hello()")
171
175
  # => "world!"
172
-
173
- ```
174
-
175
- 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:
176
-
177
176
  ```
178
- There is an important limitation to snapshots: they can only capture V8’s
179
- heap. Any interaction from V8 with the outside is off-limits when creating the
180
- snapshot. Such interactions include:
181
177
 
182
- * defining and calling API callbacks (i.e. functions created via v8::FunctionTemplate)
183
- * 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:
184
179
 
185
- And of course, values derived from sources such as `Math.random` or `Date.now`
186
- are fixed once the snapshot has been captured. They are no longer really random
187
- nor reflect the current time.
188
- ```
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.
189
190
 
190
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:
191
192
 
192
193
  ```ruby
194
+ snapshot = MiniRacer::Snapshot.new("var counter = 0; function hello() { counter++; return 'world! '; }")
193
195
 
194
- snapshot = MiniRacer::Snapshot.new('var counter = 0; function hello() { counter++; return "world! "; }')
195
-
196
- snapshot.warmup!('hello()')
196
+ snapshot.warmup!("hello()")
197
197
 
198
198
  context = MiniRacer::Context.new(snapshot: snapshot)
199
199
 
200
- context.eval('hello()')
200
+ context.eval("hello()")
201
201
  # => "world! 1"
202
- context.eval('counter')
202
+ context.eval("counter")
203
203
  # => 1
204
-
205
204
  ```
206
205
 
207
206
  ### Shared isolates
@@ -209,7 +208,6 @@ context.eval('counter')
209
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:
210
209
 
211
210
  ```ruby
212
-
213
211
  isolate = MiniRacer::Isolate.new
214
212
 
215
213
  context1 = MiniRacer::Context.new(isolate: isolate)
@@ -226,7 +224,7 @@ The caveat with this is that a given isolate can only execute one context at a t
226
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:
227
225
 
228
226
  ```ruby
229
- snapshot = MiniRacer::Snapshot.new('function hello() { return "world!"; }')
227
+ snapshot = MiniRacer::Snapshot.new("function hello() { return 'world!'; }")
230
228
 
231
229
  isolate = MiniRacer::Isolate.new(snapshot)
232
230
 
@@ -250,7 +248,6 @@ isolate.idle_notification(100)
250
248
 
251
249
  # force V8 to perform a full GC
252
250
  isolate.low_memory_notification
253
-
254
251
  ```
255
252
 
256
253
  This can come in handy to force V8 GC runs for example in between requests if you use MiniRacer on a web application.
@@ -268,11 +265,13 @@ MiniRacer::Platform.set_flags! :noconcurrent_recompilation, max_inlining_levels:
268
265
  ```
269
266
 
270
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
+
271
269
  ```ruby
272
270
  MiniRacer::Platform.set_flags! :noconcurrent_recompilation, :noconcurrent_sweeping
273
271
  ```
274
272
 
275
273
  Or else to unlock experimental features in V8, for example tail recursion optimization:
274
+
276
275
  ```ruby
277
276
  MiniRacer::Platform.set_flags! :harmony
278
277
 
@@ -293,6 +292,7 @@ context = MiniRacer::Context.new
293
292
  context.eval js
294
293
  # => "foo"
295
294
  ```
295
+
296
296
  The same code without the harmony runtime flag results in a `MiniRacer::RuntimeError: RangeError: Maximum call stack size exceeded` exception.
297
297
  Please refer to http://node.green/ as a reference on other harmony features.
298
298
 
@@ -302,17 +302,18 @@ Note that runtime flags must be set before any other operation (e.g. creating a
302
302
 
303
303
  Flags:
304
304
 
305
- - :expose_gc : Will expose `gc()` which you can run in JavaScript to issue a gc
306
- - :max_old_space_size : defaults to 1400 (megs) on 64 bit, you can restric memory usage by limiting this.
307
- - **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.
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.
308
309
 
309
310
  ## Controlling memory
310
311
 
311
- When hosting v8 you may want to keep track of memory usage, use #heap_stats to get memory usage:
312
+ When hosting v8 you may want to keep track of memory usage, use `#heap_stats` to get memory usage:
312
313
 
313
314
  ```ruby
314
- context = MiniRacer::Context.new(timeout: 5)
315
- context.eval("let a='testing';")
315
+ context = MiniRacer::Context.new
316
+ # use context
316
317
  p context.heap_stats
317
318
  # {:total_physical_size=>1280640,
318
319
  # :total_heap_size_executable=>4194304,
@@ -321,27 +322,27 @@ p context.heap_stats
321
322
  # :heap_size_limit=>1501560832}
322
323
  ```
323
324
 
324
- 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`:
325
326
 
326
327
  ```ruby
327
- context = MiniRacer::Context.new(timeout: 5)
328
+ context = MiniRacer::Context.new
328
329
  context.eval("let a='testing';")
329
330
  context.dispose
330
331
  context.eval("a = 2")
331
332
  # MiniRacer::ContextDisposedError
332
333
 
333
- # nothing works on the context from now on, its a shell waiting to be disposed
334
+ # nothing works on the context from now on, it's a shell waiting to be disposed
334
335
  ```
335
336
 
336
337
  A MiniRacer context can also be dumped in a heapsnapshot file using `#write_heap_snapshot(file_or_io)`
337
338
 
338
339
  ```ruby
339
- context = MiniRacer::Context.new(timeout: 5)
340
- context.eval("let a='testing';")
340
+ context = MiniRacer::Context.new
341
+ # use context
341
342
  context.write_heap_snapshot("test.heapsnapshot")
342
343
  ```
343
344
 
344
- This file can then be loaded in the memory tab of the chrome dev console.
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).
345
346
 
346
347
  ### Function call
347
348
 
@@ -349,30 +350,29 @@ This calls the function passed as first argument:
349
350
 
350
351
  ```ruby
351
352
  context = MiniRacer::Context.new
352
- context.eval('function hello(name) { return "Hello, " + name + "!" }')
353
- context.call('hello', 'George')
353
+ context.eval("function hello(name) { return `Hello, ${name}!` }")
354
+ context.call("hello", "George")
354
355
  # "Hello, George!"
355
356
  ```
356
357
 
357
- Performance is slightly better than running `eval('hello("George")')` since:
358
+ Performance is slightly better than running `context.eval("hello('George')")` since:
358
359
 
359
- - compilation of eval'd string is avoided
360
- - function arguments don't need to be converted to JSON
360
+ * compilation of eval'd string is avoided
361
+ * function arguments don't need to be converted to JSON
361
362
 
362
363
  ## Performance
363
364
 
364
365
  The `bench` folder contains benchmark.
365
366
 
366
- ### Benchmark minification of Discourse application.js (both minified and unminified)
367
+ ### Benchmark minification of Discourse application.js (both minified and non-minified)
367
368
 
368
369
  MiniRacer outperforms node when minifying assets via execjs.
369
370
 
370
- - MiniRacer version 0.1.9
371
- - node version 6.10
372
- - therubyracer version 0.12.2
373
-
374
- ```
371
+ * MiniRacer version 0.1.9
372
+ * node version 6.10
373
+ * therubyracer version 0.12.2
375
374
 
375
+ ```terminal
376
376
  $ bundle exec ruby bench.rb mini_racer
377
377
  Benching with mini_racer
378
378
  mini_racer minify discourse_app.js 9292.72063ms
@@ -409,78 +409,64 @@ MiniRacer can fully support source maps but must be configured correctly to do s
409
409
  Add this line to your application's Gemfile:
410
410
 
411
411
  ```ruby
412
- gem 'mini_racer'
412
+ gem "mini_racer"
413
413
  ```
414
414
 
415
415
  And then execute:
416
416
 
417
- $ bundle
417
+ ```terminal
418
+ $ bundle
418
419
 
419
420
  Or install it yourself as:
420
421
 
421
- $ gem install mini_racer
422
-
422
+ ```terminal
423
+ $ gem install mini_racer
424
+ ```
423
425
 
424
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).
425
427
 
426
-
427
- ### Troubleshooting
428
-
429
- If you have a problem installing mini_racer, please consider the following steps:
430
-
431
- * make sure you try the latest released version of mini_racer
432
- * make sure you have Rubygems >= 3.2.13 and bundler >= 2.2.13 installed via `gem update --system`
433
- * if you are using bundler, make sure to have `PLATFORMS` set correctly in `Gemfile.lock` via `bundle lock --add-platform`
434
- * make sure to recompile/reinstall `mini_racer` and `libv8-node` after system upgrades (for example via `gem uninstall --all mini_racer libv8-node`)
435
- * make sure you are on the latest patch/teeny version of a supported Ruby branch
436
-
437
428
  ## Similar Projects
438
429
 
439
430
  ### therubyracer
440
431
 
441
- - https://github.com/cowboyd/therubyracer
442
- - Most comprehensive bridge available
443
- - Provides the ability to "eval" JavaScript
444
- - Provides the ability to invoke Ruby code from JavaScript
445
- - Hold references to JavaScript objects and methods in your Ruby code
446
- - Hold references to Ruby objects and methods in JavaScript code
447
- - Uses libv8, so installation is fast
448
- - Supports timeouts for JavaScript execution
449
- - Does not release global interpreter lock, so performance is constrained to a single thread
450
- - Currently (May 2016) only supports v8 version 3.16.14 (Released approx November 2013), plans to upgrade by July 2016
451
- - Supports execjs
452
-
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
453
443
 
454
444
  ### v8eval
455
445
 
456
- - https://github.com/sony/v8eval
457
- - Provides the ability to "eval" JavaScript using the latest V8 engine
458
- - 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.
459
- - Does not release global interpreter lock when executing JavaScript
460
- - Does not allow you to invoke Ruby code from JavaScript
461
- - Multi runtime support due to SWIG based bindings
462
- - Supports a JavaScript debugger
463
- - Does not support timeouts for JavaScript execution
464
- - No support for execjs (can not be used with Rails uglifier and coffeescript gems)
465
-
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)
466
455
 
467
456
  ### therubyrhino
468
457
 
469
- - https://github.com/cowboyd/therubyrhino
470
- - API compatible with therubyracer
471
- - Uses Mozilla's Rhino engine https://github.com/mozilla/rhino
472
- - Requires JRuby
473
- - Support for timeouts for JavaScript execution
474
- - Concurrent cause .... JRuby
475
- - Supports execjs
476
-
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
477
465
 
478
466
  ## Contributing
479
467
 
480
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.
481
469
 
482
-
483
470
  ## License
484
471
 
485
472
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
486
-
@@ -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)->Name());
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))
@@ -71,7 +71,9 @@ module MiniRacer
71
71
  end
72
72
 
73
73
  unless Polyglot.languages.include? "js"
74
- warn "You also need to install the 'js' component with 'gu install js' on GraalVM 22.2+", uplevel: 0 if $VERBOSE
74
+ raise "The language 'js' is not available, you likely need to `export TRUFFLERUBYOPT='--jvm --polyglot'`\n" \
75
+ "You also need to install the 'js' component with 'gu install js' on GraalVM 22.2+\n" \
76
+ "Note that you need TruffleRuby+GraalVM and not just the TruffleRuby standalone to use MiniRacer"
75
77
  end
76
78
 
77
79
  @context = Polyglot::InnerContext.new(on_cancelled: -> {
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniRacer
4
- VERSION = "0.6.3"
5
- LIBV8_NODE_VERSION = "~> 16.10.0.0"
4
+ VERSION = "0.8.0"
5
+ LIBV8_NODE_VERSION = "~> 18.16.0.0"
6
6
  end
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.6.3
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: 2022-08-16 00:00:00.000000000 Z
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.10.0.0
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.10.0.0
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
- - mini_racer.gemspec
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.6.3/CHANGELOG
132
- documentation_uri: https://www.rubydoc.info/gems/mini_racer/0.6.3
133
- source_code_uri: https://github.com/discourse/mini_racer/tree/v0.6.3
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,14 +133,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
133
  requirements:
141
134
  - - ">="
142
135
  - !ruby/object:Gem::Version
143
- version: '2.6'
136
+ version: '3.0'
144
137
  required_rubygems_version: !ruby/object:Gem::Requirement
145
138
  requirements:
146
139
  - - ">="
147
140
  - !ruby/object:Gem::Version
148
141
  version: '0'
149
142
  requirements: []
150
- rubygems_version: 3.3.20
143
+ rubygems_version: 3.4.6
151
144
  signing_key:
152
145
  specification_version: 4
153
146
  summary: Minimal embedded v8 for Ruby
data/.dockerignore DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- lib/mini_racer_extension.so
11
- lib/mini_racer_loader.so
12
- *.bundle