sq_mini_racer 0.2.3.sqreen5 → 0.2.4.sqreen1

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: e471112864a46981c92918e92e0d7ad379fa8c4e4df9ddf5f6ae613d73e701fc
4
- data.tar.gz: 64cbea24b213cbccfa8538082e69fb48136c195c60b669f31bfe23c4be8ed2f1
3
+ metadata.gz: bea40e4059a89f323b790b547c1def910b62bc1d053e16cdb7a1723647640354
4
+ data.tar.gz: dfcec9eefde7e0d2875e0fe65d36e500a43502e60c3d3e6fd201d9ef398fbe59
5
5
  SHA512:
6
- metadata.gz: 1244ff11d07359cda9ba590abff65b134386759a5cfe23620c34185fa7ffd8e509721bd67d8b60d4ccc900f1f1eb0ef6e52cf211bf1f629aa530ea8a48bab21b
7
- data.tar.gz: 6e76f61f8b5cdbdd0deef5bf2d8cedcea92bd81a5a67fd7dd8f38032eaf936f7d48f973f8016b13f3789eb99dc851dc52165cc35e3229464c1cf9a38a2ec408b
6
+ metadata.gz: 146ebbd3f0edd5777adb092eeee08eab299ba4794e3904d18ef94422a742f5f5e26faa3abb7fcaf7dab5821c50defb57c0b22efa27658e3b0c7e39bcfcebc727
7
+ data.tar.gz: 3e417b55e52b2513b54d1a30b9dff96196f8c3592957bea7ad386e205f5d9fcd2e3f5d72bf44e1f99192e6f5ddb40ac87cd3cd533c838b746a8fdc90afe51054
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ - 02-11-2018
2
+
3
+ - 0.2.4
4
+
5
+ - FIX: deadlock releasing context when shared isolates are used
6
+ - FEATURE: include js backtrace when snapshots do not compile
7
+
1
8
  - 28-09-2018
2
9
 
3
10
  - 0.2.3
@@ -81,6 +81,10 @@ public:
81
81
  }
82
82
  }
83
83
 
84
+ int refs() {
85
+ return refs_count;
86
+ }
87
+
84
88
  static void* operator new(size_t size) {
85
89
  return ruby_xmalloc(size);
86
90
  }
@@ -207,9 +211,9 @@ static void gc_callback(Isolate *isolate, GCType type, GCCallbackFlags flags) {
207
211
 
208
212
  size_t softlimit = *(size_t*) isolate->GetData(MEM_SOFTLIMIT_VALUE);
209
213
 
210
- HeapStatistics* stats = new HeapStatistics();
211
- isolate->GetHeapStatistics(stats);
212
- size_t used = stats->used_heap_size();
214
+ HeapStatistics stats;
215
+ isolate->GetHeapStatistics(&stats);
216
+ size_t used = stats.used_heap_size();
213
217
 
214
218
  if(used > softlimit) {
215
219
  isolate->SetData(MEM_SOFTLIMIT_REACHED, (void*)true);
@@ -271,8 +275,8 @@ static void prepare_result(MaybeLocal<Value> v8res,
271
275
  Local<Message> message = trycatch.Message();
272
276
  char buf[1000];
273
277
  int len;
274
- len = snprintf(buf, sizeof(buf), "%s at %s:%i:%i", *String::Utf8Value(message->Get()),
275
- *String::Utf8Value(message->GetScriptResourceName()->ToString()),
278
+ len = snprintf(buf, sizeof(buf), "%s at %s:%i:%i", *String::Utf8Value(isolate, message->Get()),
279
+ *String::Utf8Value(isolate, message->GetScriptResourceName()->ToString()),
276
280
  message->GetLineNumber(),
277
281
  message->GetStartColumn());
278
282
  if ((size_t) len >= sizeof(buf)) {
@@ -288,9 +292,9 @@ static void prepare_result(MaybeLocal<Value> v8res,
288
292
  Local<String> tmp = String::NewFromUtf8(isolate, "JavaScript was terminated (either by timeout or explicitly)");
289
293
  evalRes.message->Reset(isolate, tmp);
290
294
  }
291
- if (!trycatch.StackTrace().IsEmpty()) {
295
+ if (!trycatch.StackTrace(context).IsEmpty()) {
292
296
  evalRes.backtrace = new Persistent<Value>();
293
- evalRes.backtrace->Reset(isolate, trycatch.StackTrace()->ToString());
297
+ evalRes.backtrace->Reset(isolate, trycatch.StackTrace(context).ToLocalChecked()->ToString());
294
298
  }
295
299
  }
296
300
  }
@@ -443,7 +447,7 @@ static VALUE convert_v8_to_ruby(Isolate* isolate, Local<Context> context,
443
447
  }
444
448
 
445
449
  Local<String> rstr = value->ToString();
446
- return rb_enc_str_new(*String::Utf8Value(rstr), rstr->Utf8Length(), rb_enc_find("utf-8"));
450
+ return rb_enc_str_new(*String::Utf8Value(isolate, rstr), rstr->Utf8Length(), rb_enc_find("utf-8"));
447
451
  }
448
452
 
449
453
  static VALUE convert_v8_to_ruby(Isolate* isolate,
@@ -776,7 +780,7 @@ static VALUE convert_result_to_ruby(VALUE self /* context */,
776
780
 
777
781
  if (result.json) {
778
782
  Local<String> rstr = tmp->ToString();
779
- VALUE json_string = rb_enc_str_new(*String::Utf8Value(rstr), rstr->Utf8Length(), rb_enc_find("utf-8"));
783
+ VALUE json_string = rb_enc_str_new(*String::Utf8Value(isolate, rstr), rstr->Utf8Length(), rb_enc_find("utf-8"));
780
784
  ret = rb_funcall(rb_mJSON, rb_intern("parse"), 1, json_string);
781
785
  } else {
782
786
  ret = convert_v8_to_ruby(isolate, *p_ctx, tmp);
@@ -1094,21 +1098,50 @@ void free_isolate(IsolateInfo* isolate_info) {
1094
1098
  delete isolate_info->allocator;
1095
1099
  }
1096
1100
 
1101
+ static void *free_context_raw(void* arg) {
1102
+ ContextInfo* context_info = (ContextInfo*)arg;
1103
+ IsolateInfo* isolate_info = context_info->isolate_info;
1104
+ Persistent<Context>* context = context_info->context;
1105
+
1106
+ if (context && isolate_info && isolate_info->isolate) {
1107
+ Locker lock(isolate_info->isolate);
1108
+ v8::Isolate::Scope isolate_scope(isolate_info->isolate);
1109
+ context->Reset();
1110
+ delete context;
1111
+ }
1112
+
1113
+ if (isolate_info) {
1114
+ isolate_info->release();
1115
+ }
1116
+
1117
+ xfree(context_info);
1118
+ return NULL;
1119
+ }
1120
+
1097
1121
  // destroys everything except freeing the ContextInfo struct (see deallocate())
1098
1122
  static void free_context(ContextInfo* context_info) {
1099
1123
 
1100
1124
  IsolateInfo* isolate_info = context_info->isolate_info;
1101
1125
 
1126
+ ContextInfo* context_info_copy = ALLOC(ContextInfo);
1127
+ context_info_copy->isolate_info = context_info->isolate_info;
1128
+ context_info_copy->context = context_info->context;
1129
+
1130
+ if (isolate_info && isolate_info->refs() > 1) {
1131
+ pthread_t free_context_thread;
1132
+ if (pthread_create(&free_context_thread, NULL, free_context_raw, (void*)context_info_copy)) {
1133
+ fprintf(stderr, "WARNING failed to release memory in MiniRacer, thread to release could not be created, process will leak memory\n");
1134
+ }
1135
+
1136
+ } else {
1137
+ free_context_raw(context_info_copy);
1138
+ }
1139
+
1102
1140
  if (context_info->context && isolate_info && isolate_info->isolate) {
1103
- Locker lock(isolate_info->isolate);
1104
- v8::Isolate::Scope isolate_scope(isolate_info->isolate);
1105
- context_info->context->Reset();
1106
- delete context_info->context;
1107
1141
  context_info->context = NULL;
1108
1142
  }
1109
1143
 
1110
1144
  if (isolate_info) {
1111
- isolate_info->release();
1112
1145
  context_info->isolate_info = NULL;
1113
1146
  }
1114
1147
  }
@@ -1238,6 +1271,19 @@ rb_context_dispose(VALUE self) {
1238
1271
  return Qnil;
1239
1272
  }
1240
1273
 
1274
+ static VALUE
1275
+ rb_context_low_memory_notification(VALUE self) {
1276
+
1277
+ ContextInfo* context_info;
1278
+ Data_Get_Struct(self, ContextInfo, context_info);
1279
+
1280
+ if (context_info->isolate_info && context_info->isolate_info->isolate) {
1281
+ context_info->isolate_info->isolate->LowMemoryNotification();
1282
+ }
1283
+
1284
+ return Qnil;
1285
+ }
1286
+
1241
1287
  #if RUBY_API_VERSION_MAJOR > 1
1242
1288
  static void*
1243
1289
  #else
@@ -1405,7 +1451,8 @@ extern "C" {
1405
1451
 
1406
1452
  rb_define_method(rb_cContext, "stop", (VALUE(*)(...))&rb_context_stop, 0);
1407
1453
  rb_define_method(rb_cContext, "dispose_unsafe", (VALUE(*)(...))&rb_context_dispose, 0);
1408
- rb_define_method(rb_cContext, "heap_stats", (VALUE(*)(...))&rb_heap_stats, 0);
1454
+ rb_define_method(rb_cContext, "low_memory_notification", (VALUE(*)(...))&rb_context_low_memory_notification, 0);
1455
+ rb_define_method(rb_cContext, "heap_stats", (VALUE(*)(...))&rb_heap_stats, 0);
1409
1456
  rb_define_private_method(rb_cContext, "create_isolate_value",(VALUE(*)(...))&rb_context_create_isolate_value, 0);
1410
1457
  rb_define_private_method(rb_cContext, "eval_unsafe",(VALUE(*)(...))&rb_context_eval_unsafe, 2);
1411
1458
  rb_define_private_method(rb_cContext, "call_unsafe", (VALUE(*)(...))&rb_context_call_unsafe, -1);
@@ -331,7 +331,7 @@ module MiniRacer
331
331
  ctx = MiniRacer::Context.new
332
332
  ctx.eval(str)
333
333
  rescue MiniRacer::RuntimeError => e
334
- raise MiniRacer::SnapshotError.new, e.message
334
+ raise MiniRacer::SnapshotError.new, e.message, e.backtrace
335
335
  end
336
336
 
337
337
  @source = str
@@ -349,7 +349,7 @@ module MiniRacer
349
349
  ctx.eval(@source)
350
350
  ctx.eval(src)
351
351
  rescue MiniRacer::RuntimeError => e
352
- raise MiniRacer::SnapshotError.new, e.message
352
+ raise MiniRacer::SnapshotError.new, e.message, e.backtrace
353
353
  end
354
354
 
355
355
  warmup_unsafe!(src)
@@ -2,6 +2,6 @@ module Sqreen
2
2
  module MiniRacer
3
3
  # part before qualifier is the number of the last upstream release
4
4
  # since we synced with it
5
- VERSION = "0.2.3.sqreen5"
5
+ VERSION = "0.2.4.sqreen1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sq_mini_racer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3.sqreen5
4
+ version: 0.2.4.sqreen1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-09 00:00:00.000000000 Z
11
+ date: 2018-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler