mini_racer 0.2.5 → 0.2.6
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 +4 -4
- data/CHANGELOG +6 -0
- data/Rakefile +25 -0
- data/ext/mini_racer_extension/mini_racer_extension.cc +67 -0
- data/lib/mini_racer.rb +22 -0
- 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: 0c16fa0feb3cbf1b8421934aa90d12326e054ae439355e205f419ae1b74f6ad5
|
4
|
+
data.tar.gz: ae46660f1ae64a14a528d26d53e3a1a0d7229556124cd17e0b7f5fdb16e42267
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55eaf9550322b6d3151b0dc17e86e9faadff9fe48cf64765d722281a8d6cd2af42ab8d46614f1ac59946aeffe2c02dbb09673042006c164e4eb132224acfe069
|
7
|
+
data.tar.gz: 2b367ff94b68ed24579c6d750aef1532398bacedcd42a6149c16fbf176a76d079eddb12e9c3f15b12fb141703b0f38d37ca6e017e46d685826db64891347475e
|
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -52,3 +52,28 @@ namespace :test do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
desc 'run clang-tidy linter on mini_racer_extension.cc'
|
57
|
+
task :lint do
|
58
|
+
require 'mkmf'
|
59
|
+
require 'libv8'
|
60
|
+
|
61
|
+
Libv8.configure_makefile
|
62
|
+
|
63
|
+
conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
|
64
|
+
'arch_hdrdir' => $arch_hdrdir.quote,
|
65
|
+
'top_srcdir' => $top_srcdir.quote)
|
66
|
+
if $universal and (arch_flag = conf['ARCH_FLAG']) and !arch_flag.empty?
|
67
|
+
conf['ARCH_FLAG'] = arch_flag.gsub(/(?:\G|\s)-arch\s+\S+/, '')
|
68
|
+
end
|
69
|
+
|
70
|
+
checks = %W(bugprone-*
|
71
|
+
cert-*
|
72
|
+
cppcoreguidelines-*
|
73
|
+
clang-analyzer-*
|
74
|
+
performance-*
|
75
|
+
portability-*
|
76
|
+
readability-*).join(',')
|
77
|
+
|
78
|
+
sh RbConfig::expand("clang-tidy -checks='#{checks}' ext/mini_racer_extension/mini_racer_extension.cc -- #$INCFLAGS #$CPPFLAGS", conf)
|
79
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
#include <stdio.h>
|
2
2
|
#include <ruby.h>
|
3
3
|
#include <ruby/thread.h>
|
4
|
+
#include <ruby/io.h>
|
4
5
|
#include <v8.h>
|
6
|
+
#include <v8-profiler.h>
|
5
7
|
#include <libplatform/libplatform.h>
|
6
8
|
#include <ruby/encoding.h>
|
7
9
|
#include <pthread.h>
|
@@ -1315,6 +1317,69 @@ rb_heap_stats(VALUE self) {
|
|
1315
1317
|
return rval;
|
1316
1318
|
}
|
1317
1319
|
|
1320
|
+
// https://github.com/bnoordhuis/node-heapdump/blob/master/src/heapdump.cc
|
1321
|
+
class FileOutputStream : public OutputStream {
|
1322
|
+
public:
|
1323
|
+
FileOutputStream(FILE* stream) : stream_(stream) {}
|
1324
|
+
|
1325
|
+
virtual int GetChunkSize() {
|
1326
|
+
return 65536;
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
virtual void EndOfStream() {}
|
1330
|
+
|
1331
|
+
virtual WriteResult WriteAsciiChunk(char* data, int size) {
|
1332
|
+
const size_t len = static_cast<size_t>(size);
|
1333
|
+
size_t off = 0;
|
1334
|
+
|
1335
|
+
while (off < len && !feof(stream_) && !ferror(stream_))
|
1336
|
+
off += fwrite(data + off, 1, len - off, stream_);
|
1337
|
+
|
1338
|
+
return off == len ? kContinue : kAbort;
|
1339
|
+
}
|
1340
|
+
|
1341
|
+
private:
|
1342
|
+
FILE* stream_;
|
1343
|
+
};
|
1344
|
+
|
1345
|
+
|
1346
|
+
static VALUE
|
1347
|
+
rb_heap_snapshot(VALUE self, VALUE file) {
|
1348
|
+
|
1349
|
+
rb_io_t *fptr;
|
1350
|
+
|
1351
|
+
fptr = RFILE(file)->fptr;
|
1352
|
+
|
1353
|
+
if (!fptr) return Qfalse;
|
1354
|
+
|
1355
|
+
FILE* fp;
|
1356
|
+
fp = fdopen(fptr->fd, "w");
|
1357
|
+
if (fp == NULL) return Qfalse;
|
1358
|
+
|
1359
|
+
|
1360
|
+
ContextInfo* context_info;
|
1361
|
+
Data_Get_Struct(self, ContextInfo, context_info);
|
1362
|
+
Isolate* isolate;
|
1363
|
+
isolate = context_info->isolate_info ? context_info->isolate_info->isolate : NULL;
|
1364
|
+
|
1365
|
+
if (!isolate) return Qfalse;
|
1366
|
+
|
1367
|
+
Locker lock(isolate);
|
1368
|
+
Isolate::Scope isolate_scope(isolate);
|
1369
|
+
HandleScope handle_scope(isolate);
|
1370
|
+
|
1371
|
+
HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
|
1372
|
+
|
1373
|
+
const HeapSnapshot* const snap = heap_profiler->TakeHeapSnapshot();
|
1374
|
+
|
1375
|
+
FileOutputStream stream(fp);
|
1376
|
+
snap->Serialize(&stream, HeapSnapshot::kJSON);
|
1377
|
+
|
1378
|
+
const_cast<HeapSnapshot*>(snap)->Delete();
|
1379
|
+
|
1380
|
+
return Qtrue;
|
1381
|
+
}
|
1382
|
+
|
1318
1383
|
static VALUE
|
1319
1384
|
rb_context_stop(VALUE self) {
|
1320
1385
|
|
@@ -1500,6 +1565,8 @@ extern "C" {
|
|
1500
1565
|
rb_define_method(rb_cContext, "stop", (VALUE(*)(...))&rb_context_stop, 0);
|
1501
1566
|
rb_define_method(rb_cContext, "dispose_unsafe", (VALUE(*)(...))&rb_context_dispose, 0);
|
1502
1567
|
rb_define_method(rb_cContext, "heap_stats", (VALUE(*)(...))&rb_heap_stats, 0);
|
1568
|
+
rb_define_method(rb_cContext, "write_heap_snapshot_unsafe", (VALUE(*)(...))&rb_heap_snapshot, 1);
|
1569
|
+
|
1503
1570
|
rb_define_private_method(rb_cContext, "create_isolate_value",(VALUE(*)(...))&rb_context_create_isolate_value, 0);
|
1504
1571
|
rb_define_private_method(rb_cContext, "eval_unsafe",(VALUE(*)(...))&rb_context_eval_unsafe, 2);
|
1505
1572
|
rb_define_private_method(rb_cContext, "call_unsafe", (VALUE(*)(...))&rb_context_call_unsafe, -1);
|
data/lib/mini_racer.rb
CHANGED
@@ -167,6 +167,28 @@ module MiniRacer
|
|
167
167
|
eval(File.read(filename))
|
168
168
|
end
|
169
169
|
|
170
|
+
def write_heap_snapshot(file_or_io)
|
171
|
+
f = nil
|
172
|
+
implicit = false
|
173
|
+
|
174
|
+
|
175
|
+
if String === file_or_io
|
176
|
+
f = File.open(file_or_io, "w")
|
177
|
+
implicit = true
|
178
|
+
else
|
179
|
+
f = file_or_io
|
180
|
+
end
|
181
|
+
|
182
|
+
if !(File === f)
|
183
|
+
raise ArgumentError("file_or_io")
|
184
|
+
end
|
185
|
+
|
186
|
+
write_heap_snapshot_unsafe(f)
|
187
|
+
|
188
|
+
ensure
|
189
|
+
f.close if implicit
|
190
|
+
end
|
191
|
+
|
170
192
|
def eval(str, options=nil)
|
171
193
|
raise(ContextDisposedError, 'attempted to call eval on a disposed context!') if @disposed
|
172
194
|
|
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.6
|
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-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|