mini_racer 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG +7 -0
- data/README.md +21 -0
- data/Rakefile +16 -0
- data/ext/mini_racer_extension/extconf.rb +6 -1
- data/ext/mini_racer_extension/mini_racer_extension.cc +28 -15
- data/lib/mini_racer.rb +3 -1
- data/lib/mini_racer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d194b6215e99a045c3f3464042f03257c79317a28b093be76ef10b98a7ce84b5
|
4
|
+
data.tar.gz: 754e28ec33401634506fb3edccd8459ff84c0eb9b86c93ac967a8dca6e9f1fb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fe549674ed12bc928a7bd259a7ba4cd279f039dd8ea25941974f3b9748ec89ce9140f7281ff333ed21aa442b204a7ddf8b719f71f5b038a53c10792d986676b
|
7
|
+
data.tar.gz: 3b4a9c5b0fd80926a7c8dea7cec4b6a6a857d80c91e55f6fcc621fc01eda4335af46d10006e6db8bdda9c509f4900205178b8745cda4bcbd3c1333606188ec35
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -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
|
|
data/Rakefile
CHANGED
@@ -16,6 +16,22 @@ Rake::ExtensionTask.new( 'mini_racer_extension', gem )
|
|
16
16
|
|
17
17
|
# via http://blog.flavorjon.es/2009/06/easily-valgrind-gdb-your-ruby-c.html
|
18
18
|
namespace :test do
|
19
|
+
desc "run test suite with Address Sanitizer"
|
20
|
+
task :asan do
|
21
|
+
ENV["CONFIGURE_ARGS"] = [ENV["CONFIGURE_ARGS"], '--enable-asan'].compact.join(' ')
|
22
|
+
Rake::Task['compile'].invoke
|
23
|
+
|
24
|
+
asan_path = `ldconfig -N -p |grep libasan | grep -v 32 | sed 's/.* => \\(.*\\)$/\\1/'`.chomp.split("\n")[-1]
|
25
|
+
|
26
|
+
|
27
|
+
cmdline = "env LD_PRELOAD=\"#{asan_path}\" ruby test/test_leak.rb"
|
28
|
+
puts cmdline
|
29
|
+
system cmdline
|
30
|
+
|
31
|
+
cmdline = "env LD_PRELOAD=\"#{asan_path}\" rake test"
|
32
|
+
puts cmdline
|
33
|
+
system cmdline
|
34
|
+
end
|
19
35
|
# partial-loads-ok and undef-value-errors necessary to ignore
|
20
36
|
# spurious (and eminently ignorable) warnings from the ruby
|
21
37
|
# interpreter
|
@@ -49,10 +49,15 @@ if CONFIG['warnflags']
|
|
49
49
|
CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '')
|
50
50
|
end
|
51
51
|
|
52
|
-
if enable_config('debug')
|
52
|
+
if enable_config('debug') || enable_config('asan')
|
53
53
|
CONFIG['debugflags'] << ' -ggdb3 -O0'
|
54
54
|
end
|
55
55
|
|
56
56
|
Libv8.configure_makefile
|
57
57
|
|
58
|
+
if enable_config('asan')
|
59
|
+
$CPPFLAGS.insert(0, " -fsanitize=address ")
|
60
|
+
$LDFLAGS.insert(0, " -fsanitize=address ")
|
61
|
+
end
|
62
|
+
|
58
63
|
create_makefile 'mini_racer_extension'
|
@@ -152,7 +152,7 @@ static VALUE rb_mJSON;
|
|
152
152
|
static VALUE rb_cFailedV8Conversion;
|
153
153
|
static VALUE rb_cDateTime = Qnil;
|
154
154
|
|
155
|
-
static Platform
|
155
|
+
static std::unique_ptr<Platform> current_platform = NULL;
|
156
156
|
static std::mutex platform_lock;
|
157
157
|
|
158
158
|
static VALUE rb_platform_set_flag_as_str(VALUE _klass, VALUE flag_as_str) {
|
@@ -189,8 +189,8 @@ static void init_v8() {
|
|
189
189
|
|
190
190
|
if (current_platform == NULL) {
|
191
191
|
V8::InitializeICU();
|
192
|
-
current_platform = platform::
|
193
|
-
V8::InitializePlatform(current_platform);
|
192
|
+
current_platform = platform::NewDefaultPlatform();
|
193
|
+
V8::InitializePlatform(current_platform.get());
|
194
194
|
V8::Initialize();
|
195
195
|
}
|
196
196
|
|
@@ -241,7 +241,7 @@ static void prepare_result(MaybeLocal<Value> v8res,
|
|
241
241
|
Local<Object> object = local_value->ToObject(context).ToLocalChecked();
|
242
242
|
const unsigned argc = 1;
|
243
243
|
Local<Value> argv[argc] = { object };
|
244
|
-
MaybeLocal<Value> json = stringify->Call(JSON, argc, argv);
|
244
|
+
MaybeLocal<Value> json = stringify->Call(context, JSON, argc, argv);
|
245
245
|
|
246
246
|
if (json.IsEmpty()) {
|
247
247
|
evalRes.executed = false;
|
@@ -1086,8 +1086,10 @@ static VALUE rb_external_function_notify_v8(VALUE self) {
|
|
1086
1086
|
Local<Context> context = context_info->context->Get(isolate);
|
1087
1087
|
Context::Scope context_scope(context);
|
1088
1088
|
|
1089
|
-
Local<String> v8_str =
|
1090
|
-
|
1089
|
+
Local<String> v8_str =
|
1090
|
+
String::NewFromUtf8(isolate, RSTRING_PTR(name),
|
1091
|
+
NewStringType::kNormal, (int)RSTRING_LEN(name))
|
1092
|
+
.ToLocalChecked();
|
1091
1093
|
|
1092
1094
|
// copy self so we can access from v8 external
|
1093
1095
|
VALUE* self_copy;
|
@@ -1097,24 +1099,35 @@ static VALUE rb_external_function_notify_v8(VALUE self) {
|
|
1097
1099
|
Local<Value> external = External::New(isolate, self_copy);
|
1098
1100
|
|
1099
1101
|
if (parent_object == Qnil) {
|
1100
|
-
context->Global()->Set(
|
1101
|
-
|
1102
|
+
context->Global()->Set(
|
1103
|
+
v8_str, FunctionTemplate::New(isolate, ruby_callback, external)
|
1104
|
+
->GetFunction(context)
|
1105
|
+
.ToLocalChecked());
|
1102
1106
|
|
1103
|
-
|
1104
|
-
|
1107
|
+
} else {
|
1108
|
+
Local<String> eval =
|
1109
|
+
String::NewFromUtf8(isolate, RSTRING_PTR(parent_object_eval),
|
1110
|
+
NewStringType::kNormal,
|
1111
|
+
(int)RSTRING_LEN(parent_object_eval))
|
1112
|
+
.ToLocalChecked();
|
1105
1113
|
|
1106
1114
|
MaybeLocal<Script> parsed_script = Script::Compile(context, eval);
|
1107
1115
|
if (parsed_script.IsEmpty()) {
|
1108
|
-
|
1116
|
+
parse_error = true;
|
1109
1117
|
} else {
|
1110
|
-
MaybeLocal<Value> maybe_value =
|
1118
|
+
MaybeLocal<Value> maybe_value =
|
1119
|
+
parsed_script.ToLocalChecked()->Run(context);
|
1111
1120
|
attach_error = true;
|
1112
1121
|
|
1113
1122
|
if (!maybe_value.IsEmpty()) {
|
1114
1123
|
Local<Value> value = maybe_value.ToLocalChecked();
|
1115
|
-
if (value->IsObject()){
|
1116
|
-
|
1117
|
-
|
1124
|
+
if (value->IsObject()) {
|
1125
|
+
value.As<Object>()->Set(
|
1126
|
+
v8_str, FunctionTemplate::New(
|
1127
|
+
isolate, ruby_callback, external)
|
1128
|
+
->GetFunction(context)
|
1129
|
+
.ToLocalChecked());
|
1130
|
+
attach_error = false;
|
1118
1131
|
}
|
1119
1132
|
}
|
1120
1133
|
}
|
data/lib/mini_racer.rb
CHANGED
data/lib/mini_racer/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|