mini_racer 0.2.4 → 0.4.0

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
  SHA256:
3
- metadata.gz: 99d9eecfd656415e7b78e2dc350e74fa48efff6ba59c0753435acbcb354a6f1f
4
- data.tar.gz: 5569cf7c40958530af9326e0a73240bbe564eeca8242b4e254fbb72088134de1
3
+ metadata.gz: e73ac3193df3f33b51463ba1125ac4eee312caecd47833c545e098ba91d11ece
4
+ data.tar.gz: d6d754829b36953d239ba85e84d2fc88c0af3ccbadd3f8d2e4cd9759bd24fab2
5
5
  SHA512:
6
- metadata.gz: 2460052cf2bff6b6b6e7ad0971830d409daf71e7e2f6e7c6c15270378ac83758f38d31b24a48ff7eeb4108be6eff012bd8f762f85a2aa2b8f31e96e8f7207719
7
- data.tar.gz: e94abed7909184fa5c2d982cdffbc751731fe9f1618a543842631660380c8fcba77cc5fba3b6b6337d94531f1738f19c6b66c00753e62aa0314179317f8a798a
6
+ metadata.gz: 52a0799d84be10bb03774789b3d12d4f0fe2d4159d310b9c6a1ae3dcf878a99cd6b7c786fae813f29754a894ecf5fcc6b7e07834c0aba994a16da5c54d75595b
7
+ data.tar.gz: bc478bdb582d7b786d28754200063d7ef185396e0da23840f006679bc1af6707f54c7a719918360afa9b24c2b4ab083ca081e2b2d6853095ecd5949a9482ecbd
data/.dockerignore ADDED
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,80 @@
1
+ name: Test
2
+ on:
3
+ - push
4
+
5
+ jobs:
6
+ test-darwin:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ os:
11
+ - '10.15'
12
+ - '11.0'
13
+ platform:
14
+ - x86_64
15
+ # arm64
16
+ name: Test (darwin)
17
+ runs-on: macos-${{ matrix.os }}
18
+ steps:
19
+ - name: Checkout
20
+ uses: actions/checkout@v2
21
+ - name: Bundle
22
+ run: bundle install
23
+ - name: Compile
24
+ run: bundle exec rake compile
25
+ - name: Test
26
+ run: bundle exec rake test
27
+ test-linux:
28
+ strategy:
29
+ fail-fast: false
30
+ matrix:
31
+ ruby:
32
+ - '2.4'
33
+ - '2.5'
34
+ - '2.6'
35
+ - '2.7'
36
+ - '3.0'
37
+ platform:
38
+ - amd64
39
+ - arm64
40
+ # arm
41
+ # ppc64le
42
+ # s390x
43
+ libc:
44
+ - gnu
45
+ - musl
46
+ name: Test (linux)
47
+ runs-on: ubuntu-20.04
48
+ steps:
49
+ - name: Enable ${{ matrix.platform }} platform
50
+ id: qemu
51
+ if: ${{ matrix.platform != 'amd64' }}
52
+ run: |
53
+ docker run --privileged --rm tonistiigi/binfmt:latest --install ${{ matrix.platform }} | tee platforms.json
54
+ echo "::set-output name=platforms::$(cat platforms.json)"
55
+ - name: Start container
56
+ id: container
57
+ run: |
58
+ case ${{ matrix.libc }} in
59
+ gnu)
60
+ echo 'ruby:${{ matrix.ruby }}'
61
+ ;;
62
+ musl)
63
+ echo 'ruby:${{ matrix.ruby }}-alpine'
64
+ ;;
65
+ esac > container_image
66
+ echo "::set-output name=image::$(cat container_image)"
67
+ docker run --rm -d -v "${PWD}":"${PWD}" -w "${PWD}" --platform linux/${{ matrix.platform }} $(cat container_image) /bin/sleep 64d | tee container_id
68
+ docker exec -w "${PWD}" $(cat container_id) uname -a
69
+ echo "::set-output name=id::$(cat container_id)"
70
+ - name: Install Alpine system dependencies
71
+ if: ${{ matrix.libc == 'musl' }}
72
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python2 python3 git curl tar clang binutils-gold
73
+ - name: Checkout
74
+ uses: actions/checkout@v2
75
+ - name: Bundle
76
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle install
77
+ - name: Compile
78
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake compile
79
+ - name: Test
80
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake test
data/.gitignore CHANGED
@@ -8,4 +8,5 @@ Gemfile.lock
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  lib/mini_racer_extension.so
11
+ lib/mini_racer_loader.so
11
12
  *.bundle
data/.travis.yml CHANGED
@@ -1,22 +1,30 @@
1
1
  language: ruby
2
+ os: linux
2
3
  rvm:
3
- - 2.3
4
4
  - 2.4
5
5
  - 2.5
6
+ - 2.6
7
+ - 2.7
8
+ - 3.0
6
9
  - ruby-head
7
- matrix:
10
+ arch:
11
+ - amd64
12
+ - arm64
13
+ jobs:
8
14
  include:
9
- - rvm: 2.5.1
15
+ - rvm: 2.5
10
16
  os: osx
11
17
  osx_image: xcode9.4
12
- - rvm: 2.4.0
18
+ - rvm: 2.6
13
19
  os: osx
14
- osx_image: xcode8.3
15
- - rvm: 2.4.0
20
+ osx_image: xcode11.3
21
+ - rvm: 2.6
16
22
  os: osx
17
- osx_image: xcode7.3
18
- dist: trusty
19
- sudo: true
23
+ osx_image: xcode12.2
24
+ - rvm: 2.7
25
+ os: osx
26
+ osx_image: xcode12.2
27
+ dist: xenial
20
28
  before_install:
21
29
  - gem update --system
22
30
  - gem install bundler -v 1.16.2
data/CHANGELOG CHANGED
@@ -1,3 +1,101 @@
1
+ - 11-04-2021
2
+
3
+ - 0.4.0
4
+
5
+ - FEATURE: upgrade to libv8 node 15.14.0 (v8 8.6.395.17)
6
+ - Promote 0.4.0.beta1 to release, using libv8-node release path
7
+
8
+ - 08-04-2021
9
+
10
+ - 0.4.0.beta1
11
+
12
+ - FIX: on downgrade mkmf was picking the wrong version of libv8, this fix will correct future issues
13
+ - FEATURE: upgraded libv8 to use node libv8 build which supports M1 and various ARM builds v8 moved to (8.6.395.17)
14
+
15
+ - 23-07-2020
16
+
17
+ - 0.3.1
18
+
19
+ - FIX: specify that libv8 must be larger than 8.4.255 but smaller than 8.5, this avoids issues going forward
20
+
21
+ - 22-07-2020
22
+
23
+ - 0.3.0
24
+
25
+ - FEATURE: upgraded to libv8 version 8.4.255.0
26
+
27
+ - 29-06-2020
28
+
29
+ - 0.2.15
30
+
31
+ - FEATURE: basic wasm support via pump_message_loop
32
+
33
+ - 15-05-2020
34
+
35
+ - 0.2.14
36
+
37
+ - FIX: ensure_gc_after_idle should take in milliseconds like the rest of the APIs not seconds
38
+ - FEATURE: strict params on MiniRacer::Context.new
39
+
40
+ - 15-05-2020
41
+
42
+ - 0.2.13
43
+
44
+ - FIX: edge case around ensure_gc_after_idle possibly firing when context is not idle
45
+
46
+ - 15-05-2020
47
+
48
+ - 0.2.12
49
+
50
+ - FEATURE: isolate.low_memory_notification which can force a full GC
51
+ - FEATURE: MiniRacer::Context.new(ensure_gc_after_idle: 2) - to force full GC 2 seconds after context is idle, this allows you to conserve memory on isolates
52
+
53
+ - 14-05-2020
54
+
55
+ - 0.2.11
56
+
57
+ - FIX: dumping heap snapshots was not flushing the file leading to corrupt snapshots
58
+ - FIX: a use-after-free shutdown crash
59
+
60
+ - 0.2.10
61
+
62
+ - 22-04-2020
63
+
64
+ - FEATURE: memory softlimit support for nogvl_context_call
65
+
66
+ - 0.2.9
67
+
68
+ - 09-01-2020
69
+
70
+ - FIX: correct segfault when JS returns a Symbol and properly cast to ruby symbol
71
+
72
+ - 0.2.8
73
+
74
+ - 11-11-2019
75
+
76
+ - FIX: ensure thread live cycle is properly accounter for following file descriptor fix
77
+
78
+ - 0.2.7
79
+
80
+ - 11-11-2019
81
+
82
+ - FIX: release the file descriptor for timeout pipe earlier (this avoids holding too many files open in Ruby 2.7)
83
+
84
+ - 14-05-2019
85
+
86
+ - 0.2.6
87
+
88
+ - FEATURE: add support for write_heap_snapshot which helps you analyze memory
89
+
90
+ - 25-04-2019
91
+
92
+ - 0.2.5
93
+
94
+ - FIX: Compatiblity fixes for V8 7 and above @ignisf
95
+ - FIX: Memory leak in gc_callback @messense
96
+ - IMPROVEMENT: Added example of sourcemap support @ianks
97
+ - URGENT: you will need this release for latest version of libv8 to work
98
+
1
99
  - 02-11-2018
2
100
 
3
101
  - 0.2.4
data/Dockerfile ADDED
@@ -0,0 +1,21 @@
1
+ ARG RUBY_VERSION=2.7
2
+ FROM ruby:${RUBY_VERSION}
3
+
4
+ RUN test ! -f /etc/alpine-release || apk add --no-cache build-base git
5
+
6
+ # without this `COPY .git`, we get the following error:
7
+ # fatal: not a git repository (or any of the parent directories): .git
8
+ # but with it we need the full gem just to compile the extension because
9
+ # of gemspec's `git --ls-files`
10
+ # COPY .git /code/.git
11
+ COPY Gemfile mini_racer.gemspec /code/
12
+ COPY lib/mini_racer/version.rb /code/lib/mini_racer/version.rb
13
+ WORKDIR /code
14
+ RUN bundle install
15
+
16
+ COPY Rakefile /code/
17
+ COPY ext /code/ext/
18
+ RUN bundle exec rake compile
19
+
20
+ COPY . /code/
21
+ CMD bundle exec irb -rmini_racer
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 TODO: Write your name
3
+ Copyright (c) 2016-2019, the mini_racer project authors.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MiniRacer
2
2
 
3
- [![Build Status](https://travis-ci.org/discourse/mini_racer.svg?branch=master)](https://travis-ci.org/discourse/mini_racer)
3
+ [![Build Status](https://travis-ci.org/rubyjs/mini_racer.svg?branch=master)](https://travis-ci.org/rubyjs/mini_racer)
4
4
 
5
5
  Minimal, modern embedded V8 for Ruby.
6
6
 
@@ -97,6 +97,27 @@ context.eval('bar()', filename: 'a/bar.js')
97
97
 
98
98
  ```
99
99
 
100
+ ### Fork safety
101
+
102
+ Some Ruby web servers employ forking (for example unicorn or puma in clustered mode). V8 is not fork safe.
103
+ Sadly Ruby does not have support for fork notifications per [#5446](https://bugs.ruby-lang.org/issues/5446).
104
+
105
+ If you want to ensure your application does not leak memory after fork either:
106
+
107
+ 1. Ensure no MiniRacer::Context objects are created in the master process
108
+
109
+ Or
110
+
111
+ 2. Dispose manually of all MiniRacer::Context objects prior to forking
112
+
113
+ ```ruby
114
+ # before fork
115
+
116
+ require 'objspace'
117
+ ObjectSpace.each_object(MiniRacer::Context){|c| c.dispose}
118
+
119
+ # fork here
120
+ ```
100
121
 
101
122
  ### Threadsafe
102
123
 
@@ -209,12 +230,17 @@ context = MiniRacer::Context.new(isolate: isolate)
209
230
  # give up to 100ms for V8 garbage collection
210
231
  isolate.idle_notification(100)
211
232
 
233
+ # force V8 to perform a full GC
234
+ isolate.low_memory_notification
235
+
212
236
  ```
213
237
 
214
238
  This can come in handy to force V8 GC runs for example in between requests if you use MiniRacer on a web application.
215
239
 
216
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.`
217
241
 
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
+
218
244
  ### V8 Runtime flags
219
245
 
220
246
  It is possible to set V8 Runtime flags:
@@ -223,7 +249,7 @@ It is possible to set V8 Runtime flags:
223
249
  MiniRacer::Platform.set_flags! :noconcurrent_recompilation, max_inlining_levels: 10
224
250
  ```
225
251
 
226
- This can come in handy if you want to use MiniRacer with Unicorn, which doesn't seem to alwatys appreciate V8's liberal use of threading:
252
+ 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:
227
253
  ```ruby
228
254
  MiniRacer::Platform.set_flags! :noconcurrent_recompilation, :noconcurrent_sweeping
229
255
  ```
@@ -252,7 +278,7 @@ context.eval js
252
278
  The same code without the harmony runtime flag results in a `MiniRacer::RuntimeError: RangeError: Maximum call stack size exceeded` exception.
253
279
  Please refer to http://node.green/ as a reference on other harmony features.
254
280
 
255
- A list of all V8 runtime flags can be found using `node --v8-options`, or else by perusing [the V8 source code for flags (make sure to use the right version of V8)](https://github.com/v8/v8/blob/master/src/flag-definitions.h).
281
+ A list of all V8 runtime flags can be found using `node --v8-options`, or else by perusing [the V8 source code for flags (make sure to use the right version of V8)](https://github.com/v8/v8/blob/master/src/flags/flag-definitions.h).
256
282
 
257
283
  Note that runtime flags must be set before any other operation (e.g. creating a context, a snapshot or an isolate), otherwise an exception will be thrown.
258
284
 
@@ -289,6 +315,16 @@ context.eval("a = 2")
289
315
  # nothing works on the context from now on, its a shell waiting to be disposed
290
316
  ```
291
317
 
318
+ A MiniRacer context can also be dumped in a heapsnapshot file using `#write_heap_snapshot(file_or_io)`
319
+
320
+ ```ruby
321
+ context = MiniRacer::Context.new(timeout: 5)
322
+ context.eval("let a='testing';")
323
+ context.write_heap_snapshot("test.heapsnapshot")
324
+ ```
325
+
326
+ This file can then be loaded in the memory tab of the chrome dev console.
327
+
292
328
  ### Function call
293
329
 
294
330
  This calls the function passed as first argument:
@@ -346,6 +382,10 @@ Note how the global interpreter lock release leads to 2 threads doing the same w
346
382
 
347
383
  As a rule MiniRacer strives to always support and depend on the latest stable version of libv8.
348
384
 
385
+ ## Source Maps
386
+
387
+ MiniRacer can fully support source maps but must be configured correctly to do so. [Check out this example](./examples/source-map-support/) for a working implementation.
388
+
349
389
  ## Installation
350
390
 
351
391
  Add this line to your application's Gemfile:
@@ -422,7 +462,7 @@ Add this to your .travis.yml file:
422
462
 
423
463
  ## Contributing
424
464
 
425
- Bug reports and pull requests are welcome on GitHub at https://github.com/discourse/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.
465
+ 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.
426
466
 
427
467
 
428
468
  ## License
data/Rakefile CHANGED
@@ -11,11 +11,28 @@ end
11
11
  task :default => [:compile, :test]
12
12
 
13
13
  gem = Gem::Specification.load( File.dirname(__FILE__) + '/mini_racer.gemspec' )
14
+ Rake::ExtensionTask.new( 'mini_racer_loader', gem )
14
15
  Rake::ExtensionTask.new( 'mini_racer_extension', gem )
15
16
 
16
17
 
17
18
  # via http://blog.flavorjon.es/2009/06/easily-valgrind-gdb-your-ruby-c.html
18
19
  namespace :test do
20
+ desc "run test suite with Address Sanitizer"
21
+ task :asan do
22
+ ENV["CONFIGURE_ARGS"] = [ENV["CONFIGURE_ARGS"], '--enable-asan'].compact.join(' ')
23
+ Rake::Task['compile'].invoke
24
+
25
+ asan_path = `ldconfig -N -p |grep libasan | grep -v 32 | sed 's/.* => \\(.*\\)$/\\1/'`.chomp.split("\n")[-1]
26
+
27
+
28
+ cmdline = "env LD_PRELOAD=\"#{asan_path}\" ruby test/test_leak.rb"
29
+ puts cmdline
30
+ system cmdline
31
+
32
+ cmdline = "env LD_PRELOAD=\"#{asan_path}\" rake test"
33
+ puts cmdline
34
+ system cmdline
35
+ end
19
36
  # partial-loads-ok and undef-value-errors necessary to ignore
20
37
  # spurious (and eminently ignorable) warnings from the ruby
21
38
  # interpreter
@@ -52,3 +69,28 @@ namespace :test do
52
69
  end
53
70
  end
54
71
  end
72
+
73
+ desc 'run clang-tidy linter on mini_racer_extension.cc'
74
+ task :lint do
75
+ require 'mkmf'
76
+ require 'libv8'
77
+
78
+ Libv8.configure_makefile
79
+
80
+ conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
81
+ 'arch_hdrdir' => $arch_hdrdir.quote,
82
+ 'top_srcdir' => $top_srcdir.quote)
83
+ if $universal and (arch_flag = conf['ARCH_FLAG']) and !arch_flag.empty?
84
+ conf['ARCH_FLAG'] = arch_flag.gsub(/(?:\G|\s)-arch\s+\S+/, '')
85
+ end
86
+
87
+ checks = %W(bugprone-*
88
+ cert-*
89
+ cppcoreguidelines-*
90
+ clang-analyzer-*
91
+ performance-*
92
+ portability-*
93
+ readability-*).join(',')
94
+
95
+ sh RbConfig::expand("clang-tidy -checks='#{checks}' ext/mini_racer_extension/mini_racer_extension.cc -- #$INCFLAGS #$CPPFLAGS", conf)
96
+ end
@@ -1,5 +1,7 @@
1
1
  require 'mkmf'
2
- require 'libv8'
2
+ require_relative '../../lib/mini_racer/version'
3
+ gem 'libv8-node', MiniRacer::LIBV8_NODE_VERSION
4
+ require 'libv8-node'
3
5
 
4
6
  IS_DARWIN = RUBY_PLATFORM =~ /darwin/
5
7
 
@@ -11,11 +13,17 @@ $CPPFLAGS += " -rdynamic" unless $CPPFLAGS.split.include? "-rdynamic"
11
13
  $CPPFLAGS += " -fPIC" unless $CPPFLAGS.split.include? "-rdynamic" or IS_DARWIN
12
14
  $CPPFLAGS += " -std=c++0x"
13
15
  $CPPFLAGS += " -fpermissive"
16
+ $CPPFLAGS += " -DV8_COMPRESS_POINTERS"
17
+ $CPPFLAGS += " -fvisibility=hidden "
14
18
 
15
19
  $CPPFLAGS += " -Wno-reserved-user-defined-literal" if IS_DARWIN
16
20
 
17
21
  $LDFLAGS.insert(0, " -stdlib=libc++ ") if IS_DARWIN
18
22
 
23
+ # check for missing symbols at link time
24
+ # $LDFLAGS += " -Wl,--no-undefined " unless IS_DARWIN
25
+ # $LDFLAGS += " -Wl,-undefined,error " if IS_DARWIN
26
+
19
27
  if ENV['CXX']
20
28
  puts "SETTING CXX"
21
29
  CONFIG['CXX'] = ENV['CXX']
@@ -49,10 +57,15 @@ if CONFIG['warnflags']
49
57
  CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '')
50
58
  end
51
59
 
52
- if enable_config('debug')
60
+ if enable_config('debug') || enable_config('asan')
53
61
  CONFIG['debugflags'] << ' -ggdb3 -O0'
54
62
  end
55
63
 
56
- Libv8.configure_makefile
64
+ Libv8::Node.configure_makefile
65
+
66
+ if enable_config('asan')
67
+ $CPPFLAGS.insert(0, " -fsanitize=address ")
68
+ $LDFLAGS.insert(0, " -fsanitize=address ")
69
+ end
57
70
 
58
71
  create_makefile 'mini_racer_extension'