mini_racer 0.2.13 → 0.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 420c1d474734931c13f1246154eb045600ce24db66c05904c5df19681a03e41b
4
- data.tar.gz: 403320470422a7085305e6139cf769cdd5fe7e0df236830038d412ac2558c961
3
+ metadata.gz: d31e1517a2d52257af3ecd56079e6fcaed4a569ff2256fba4db7c92f922b6cbd
4
+ data.tar.gz: 777208a006502e94f375e54f43541273b49ecdc7657ac004bec88515b1e620b7
5
5
  SHA512:
6
- metadata.gz: ef58b7272a5f641f3dc264241414d45cde6d689a34d3433b5a039dc1caeac054c435150a3b5c2532f7957efad083584fe43d4a6c8b21789c542d611c632ae080
7
- data.tar.gz: 74b33249d8141b4d869b3c8f74617e40e271c36e472b32950391a061d27069c9b108a29884acf056ce1467c4bc3c22a6f4f84e022df53153cf30ccae387c69f1
6
+ metadata.gz: c08eecc3edcc923625a8cd6cd87b4c88a4c4f80d64c9c4edee1f68897b595f5cf02927d1d3268f8bdb1d9e81b170c75dfe3875cc1c436fdeed11ebc40759b64c
7
+ data.tar.gz: 3d82acdd3ec745bc2467e5429c849f1719bf3c711a454b588db9871b36770df64aa37947103eedc553846a04e0e754752d214c208f9f65a6eae1e35686f3068e
data/CHANGELOG CHANGED
@@ -1,6 +1,14 @@
1
1
  - 15-05-2020
2
2
 
3
+ - 0.2.14
4
+
5
+ - FIX: ensure_gc_after_idle should take in milliseconds like the rest of the APIs not seconds
6
+ - FEATURE: strict params on MiniRacer::Context.new
7
+
8
+ - 15-05-2020
9
+
3
10
  - 0.2.13
11
+
4
12
  - FIX: edge case around ensure_gc_after_idle possibly firing when context is not idle
5
13
 
6
14
  - 15-05-2020
data/README.md CHANGED
@@ -239,7 +239,7 @@ This can come in handy to force V8 GC runs for example in between requests if yo
239
239
 
240
240
  Note that this method maps directly to [`v8::Isolate::IdleNotification`](http://bespin.cz/~ondras/html/classv8_1_1Isolate.html#aea16cbb2e351de9a3ae7be2b7cb48297), and that in particular its return value is the same (true if there is no further garbage to collect, false otherwise) and the same caveats apply, in particular that `there is no guarantee that the [call will return] within the time limit.`
241
241
 
242
- Additionally you may automate this process on a context by defining it with `MiniRacer::Content.new(ensure_gc_after_idle: 1)`. Using this will ensure V8 will run a full GC using `context.isolate.low_memory_notification` 1 second after the last eval on the context. Low memory notification is both slower and more aggressive than an idle_notification and will ensure long living isolates use minimal amounts of memory.
242
+ Additionally you may automate this process on a context by defining it with `MiniRacer::Content.new(ensure_gc_after_idle: 1000)`. Using this will ensure V8 will run a full GC using `context.isolate.low_memory_notification` 1 second after the last eval on the context. Low memory notification is both slower and more aggressive than an idle_notification and will ensure long living isolates use minimal amounts of memory.
243
243
 
244
244
  ### V8 Runtime flags
245
245
 
@@ -130,23 +130,22 @@ module MiniRacer
130
130
  end
131
131
  end
132
132
 
133
- def initialize(options = nil)
133
+ def initialize(max_memory: nil, timeout: nil, isolate: nil, ensure_gc_after_idle: nil, snapshot: nil)
134
134
  options ||= {}
135
135
 
136
- check_init_options!(options)
136
+ check_init_options!(isolate: isolate, snapshot: snapshot, max_memory: max_memory, ensure_gc_after_idle: ensure_gc_after_idle, timeout: timeout)
137
137
 
138
138
  @functions = {}
139
139
  @timeout = nil
140
140
  @max_memory = nil
141
141
  @current_exception = nil
142
- @timeout = options[:timeout]
143
- if options[:max_memory].is_a?(Numeric) && options[:max_memory] > 0
144
- @max_memory = options[:max_memory]
145
- end
142
+ @timeout = timeout
143
+ @max_memory = max_memory
144
+
146
145
  # false signals it should be fetched if requested
147
- @isolate = options[:isolate] || false
146
+ @isolate = isolate || false
148
147
 
149
- @ensure_gc_after_idle = options[:ensure_gc_after_idle]
148
+ @ensure_gc_after_idle = ensure_gc_after_idle
150
149
 
151
150
  if @ensure_gc_after_idle
152
151
  @last_eval = nil
@@ -162,7 +161,7 @@ module MiniRacer
162
161
  @eval_thread = nil
163
162
 
164
163
  # defined in the C class
165
- init_unsafe(options[:isolate], options[:snapshot])
164
+ init_unsafe(isolate, snapshot)
166
165
  end
167
166
 
168
167
  def isolate
@@ -290,6 +289,7 @@ module MiniRacer
290
289
  @ensure_gc_mutex.synchronize do
291
290
  @ensure_gc_thread = nil if !@ensure_gc_thread&.alive?
292
291
  @ensure_gc_thread ||= Thread.new do
292
+ ensure_gc_after_idle_seconds = @ensure_gc_after_idle / 1000.0
293
293
  done = false
294
294
  while !done
295
295
  now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@@ -299,7 +299,7 @@ module MiniRacer
299
299
  break
300
300
  end
301
301
 
302
- if !@eval_thread && @ensure_gc_after_idle < now - @last_eval
302
+ if !@eval_thread && ensure_gc_after_idle_seconds < now - @last_eval
303
303
  @ensure_gc_mutex.synchronize do
304
304
  isolate_mutex.synchronize do
305
305
  if !@eval_thread
@@ -310,7 +310,7 @@ module MiniRacer
310
310
  end
311
311
  end
312
312
  end
313
- sleep @ensure_gc_after_idle if !done
313
+ sleep ensure_gc_after_idle_seconds if !done
314
314
  end
315
315
  end
316
316
  end
@@ -369,15 +369,29 @@ module MiniRacer
369
369
  rp.close if rp
370
370
  end
371
371
 
372
- def check_init_options!(options)
373
- assert_option_is_nil_or_a('isolate', options[:isolate], Isolate)
374
- assert_option_is_nil_or_a('snapshot', options[:snapshot], Snapshot)
372
+ def check_init_options!(isolate:, snapshot:, max_memory:, ensure_gc_after_idle:, timeout:)
373
+ assert_option_is_nil_or_a('isolate', isolate, Isolate)
374
+ assert_option_is_nil_or_a('snapshot', snapshot, Snapshot)
375
375
 
376
- if options[:isolate] && options[:snapshot]
376
+ assert_numeric_or_nil('max_memory', max_memory, min_value: 10_000)
377
+ assert_numeric_or_nil('ensure_gc_after_idle', ensure_gc_after_idle, min_value: 1)
378
+ assert_numeric_or_nil('timeout', timeout, min_value: 1)
379
+
380
+ if isolate && snapshot
377
381
  raise ArgumentError, 'can only pass one of isolate and snapshot options'
378
382
  end
379
383
  end
380
384
 
385
+ def assert_numeric_or_nil(option_name, object, min_value:)
386
+ if object.is_a?(Numeric) && object < min_value
387
+ raise ArgumentError, "#{option_name} must be larger than #{min_value}"
388
+ end
389
+
390
+ if !object.nil? && !object.is_a?(Numeric)
391
+ raise ArgumentError, "#{option_name} must be a number, passed a #{object.inspect}"
392
+ end
393
+ end
394
+
381
395
  def assert_option_is_nil_or_a(option_name, object, klass)
382
396
  unless object.nil? || object.is_a?(klass)
383
397
  raise ArgumentError, "#{option_name} must be a #{klass} object, passed a #{object.inspect}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniRacer
4
- VERSION = "0.2.13"
4
+ VERSION = "0.2.14"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_racer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
@@ -108,9 +108,9 @@ licenses:
108
108
  - MIT
109
109
  metadata:
110
110
  bug_tracker_uri: https://github.com/discourse/mini_racer/issues
111
- changelog_uri: https://github.com/discourse/mini_racer/blob/v0.2.13/CHANGELOG
112
- documentation_uri: https://www.rubydoc.info/gems/mini_racer/0.2.13
113
- source_code_uri: https://github.com/discourse/mini_racer/tree/v0.2.13
111
+ changelog_uri: https://github.com/discourse/mini_racer/blob/v0.2.14/CHANGELOG
112
+ documentation_uri: https://www.rubydoc.info/gems/mini_racer/0.2.14
113
+ source_code_uri: https://github.com/discourse/mini_racer/tree/v0.2.14
114
114
  post_install_message:
115
115
  rdoc_options: []
116
116
  require_paths: