v8eval 0.2.4 → 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/CMakeLists.txt +0 -3
- data/README.md +2 -2
- data/build.sh +16 -3
- data/ruby/ext/v8eval/extconf.rb +2 -3
- data/src/v8eval.cxx +58 -15
- data/src/v8eval.h +15 -3
- data/src/v8eval_go.cxx +3 -1
- data/v8eval.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd3a65a1288166c5c433ceb7981e7d01b7c0a2ff
|
4
|
+
data.tar.gz: 3b9aefd54850cc461f59aa07863b0122d18e5113
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbfb3232413f1a115d035e8a8149de25360167be6edd6b9546039a18821877eaffb90cd86219dda7063822868dd928212bc8e410ae69cab3d29f55ba2f0966ee
|
7
|
+
data.tar.gz: 4f84bbbe86f67b9ef29ff3b69a0725b2ecf178fc832a57f1b66c33e44cafe6b6fbafc614b487c4fd8989596e1fd92a5d2778defd5ee055cf8874e6d105215836
|
data/CMakeLists.txt
CHANGED
@@ -11,8 +11,6 @@ endif(COMMAND cmake_policy)
|
|
11
11
|
include_directories(
|
12
12
|
v8
|
13
13
|
v8/include
|
14
|
-
v8/third_party/icu/source/i18n
|
15
|
-
v8/third_party/icu/source/common
|
16
14
|
uv/include
|
17
15
|
src
|
18
16
|
test/googletest/googletest/include
|
@@ -27,7 +25,6 @@ endif(APPLE)
|
|
27
25
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
28
26
|
link_directories(
|
29
27
|
v8/out/x64.release/obj.target/src
|
30
|
-
v8/out/x64.release/obj.target/third_party/icu
|
31
28
|
)
|
32
29
|
endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
33
30
|
|
data/README.md
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
[](http://badge.fury.io/py/v8eval)
|
4
4
|
[](https://badge.fury.io/rb/v8eval)
|
5
|
-
[](http://godoc.org/github.com/sony/v8eval/go/v8eval)
|
6
6
|
|
7
7
|
Multi-language bindings to JavaScript engine V8.
|
8
8
|
|
9
|
-
Currently v8eval provides Go, Python and Ruby bindings to the latest V8 5.
|
9
|
+
Currently v8eval provides Go, Python and Ruby bindings to the latest V8 5.6 and supports Linux and Mac OS X.
|
10
10
|
v8eval uses SWIG and can be extended easily for other languages.
|
11
11
|
|
12
12
|
## Pre-installation
|
data/build.sh
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
V8EVAL_ROOT=`cd $(dirname $0) && pwd`
|
4
4
|
|
5
5
|
PLATFORM=`uname`
|
6
|
-
if [ $PLATFORM = "Linux" ]
|
6
|
+
if [ $PLATFORM = "Linux" ]; then
|
7
7
|
NUM_CPU_CORES=`cat /proc/cpuinfo | grep cores | grep -o '[0-9]\+' | awk '{total=total+$1}; END{print total}'`
|
8
8
|
|
9
9
|
export CC=$V8EVAL_ROOT/v8/third_party/llvm-build/Release+Asserts/bin/clang
|
@@ -50,11 +50,24 @@ install_v8() {
|
|
50
50
|
return 0
|
51
51
|
fi
|
52
52
|
|
53
|
+
PY_VER=`python -c 'import sys; print(sys.version_info[0])'`
|
54
|
+
if [ $PY_VER = 3 ]; then
|
55
|
+
OLD_PATH=$PATH
|
56
|
+
export PATH=$V8EVAL_ROOT/python/bin:$PATH
|
57
|
+
fi
|
58
|
+
|
53
59
|
cd $V8EVAL_ROOT
|
54
60
|
fetch v8
|
55
61
|
cd v8
|
56
|
-
git checkout 5.
|
57
|
-
|
62
|
+
git checkout 5.6.142
|
63
|
+
if [ $PY_VER = 3 ]; then
|
64
|
+
sed -i -e 's/python -c/python2 -c/' Makefile
|
65
|
+
fi
|
66
|
+
CFLAGS="-fPIC -Wno-unknown-warning-option" CXXFLAGS="-fPIC -Wno-unknown-warning-option" make x64.release -j$NUM_CPU_CORES i18nsupport=off V=1
|
67
|
+
|
68
|
+
if [ $PY_VER = 3 ]; then
|
69
|
+
export PATH=$OLD_PATH
|
70
|
+
fi
|
58
71
|
}
|
59
72
|
|
60
73
|
install_libuv() {
|
data/ruby/ext/v8eval/extconf.rb
CHANGED
@@ -39,8 +39,7 @@ if RUBY_PLATFORM =~ /darwin/
|
|
39
39
|
]
|
40
40
|
elsif RUBY_PLATFORM =~ /linux/
|
41
41
|
lib_dirs += [
|
42
|
-
v8_dir + '/out/x64.release/obj.target/src'
|
43
|
-
v8_dir + '/out/x64.release/obj.target/third_party/icu'
|
42
|
+
v8_dir + '/out/x64.release/obj.target/src'
|
44
43
|
]
|
45
44
|
|
46
45
|
RbConfig::MAKEFILE_CONFIG['CC'] = v8_dir + '/third_party/llvm-build/Release+Asserts/bin/clang'
|
@@ -49,7 +48,7 @@ end
|
|
49
48
|
|
50
49
|
dir_config('', header_dirs, lib_dirs)
|
51
50
|
|
52
|
-
$LDFLAGS << ' -lv8eval -lv8eval_ruby -lv8_libplatform -lv8_base -lv8_libbase -
|
51
|
+
$LDFLAGS << ' -lv8eval -lv8eval_ruby -lv8_libplatform -lv8_base -lv8_libbase -lv8_libsampler -lv8_nosnapshot -luv'
|
53
52
|
$CPPFLAGS << ' -g -O3 -std=c++11'
|
54
53
|
|
55
54
|
create_makefile('v8eval/v8eval')
|
data/src/v8eval.cxx
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
#include "v8eval.h"
|
2
2
|
#include "dbgsrv.h"
|
3
3
|
|
4
|
-
#include <
|
5
|
-
#include <
|
4
|
+
#include <cassert>
|
5
|
+
#include <cstdlib>
|
6
|
+
#include <cstring>
|
6
7
|
|
7
8
|
#include "libplatform/libplatform.h"
|
8
9
|
|
@@ -10,15 +11,15 @@ namespace v8eval {
|
|
10
11
|
|
11
12
|
static v8::Platform* platform = nullptr;
|
12
13
|
|
14
|
+
void set_flags(const std::string& flags) {
|
15
|
+
v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.length()));
|
16
|
+
}
|
17
|
+
|
13
18
|
bool initialize() {
|
14
19
|
if (platform) {
|
15
20
|
return false;
|
16
21
|
}
|
17
22
|
|
18
|
-
if (!v8::V8::InitializeICU()) {
|
19
|
-
return false;
|
20
|
-
}
|
21
|
-
|
22
23
|
platform = v8::platform::CreateDefaultPlatform();
|
23
24
|
v8::V8::InitializePlatform(platform);
|
24
25
|
|
@@ -88,12 +89,17 @@ _V8::~_V8() {
|
|
88
89
|
isolate_->Dispose();
|
89
90
|
}
|
90
91
|
|
91
|
-
v8::Local<v8::Context> _V8::
|
92
|
-
|
92
|
+
v8::Local<v8::Context> _V8::context() {
|
93
|
+
assert(context_.IsEmpty());
|
94
|
+
return v8::Local<v8::Context>::New(isolate_, context_);
|
95
|
+
}
|
96
|
+
|
97
|
+
v8::Local<v8::Context> _V8::new_context(v8::Local<v8::ObjectTemplate> global_tmpl, v8::Local<v8::Value> global_obj) {
|
98
|
+
if (global_tmpl.IsEmpty() && global_obj.IsEmpty()) {
|
93
99
|
v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate_);
|
94
100
|
return v8::Context::New(isolate_, nullptr, global);
|
95
101
|
} else {
|
96
|
-
return v8::
|
102
|
+
return v8::Context::New(isolate_, nullptr, global_tmpl, global_obj);
|
97
103
|
}
|
98
104
|
}
|
99
105
|
|
@@ -139,7 +145,7 @@ std::string _V8::eval(const std::string& src) {
|
|
139
145
|
v8::Isolate::Scope isolate_scope(isolate_);
|
140
146
|
v8::HandleScope handle_scope(isolate_);
|
141
147
|
|
142
|
-
v8::Local<v8::Context> context =
|
148
|
+
v8::Local<v8::Context> context = this->context();
|
143
149
|
v8::Context::Scope context_scope(context);
|
144
150
|
|
145
151
|
v8::TryCatch try_catch(isolate_);
|
@@ -155,7 +161,12 @@ std::string _V8::eval(const std::string& src) {
|
|
155
161
|
} else {
|
156
162
|
v8::Local<v8::Value> result;
|
157
163
|
if (!script->Run(context).ToLocal(&result)) {
|
158
|
-
|
164
|
+
v8::Local<v8::Value> stack;
|
165
|
+
if (!try_catch.StackTrace(context).ToLocal(&stack)) {
|
166
|
+
return to_std_string(try_catch.Exception());
|
167
|
+
} else {
|
168
|
+
return to_std_string(stack);
|
169
|
+
}
|
159
170
|
} else {
|
160
171
|
return to_std_string(json_stringify(context, result));
|
161
172
|
}
|
@@ -168,7 +179,7 @@ std::string _V8::call(const std::string& func, const std::string& args) {
|
|
168
179
|
v8::Isolate::Scope isolate_scope(isolate_);
|
169
180
|
v8::HandleScope handle_scope(isolate_);
|
170
181
|
|
171
|
-
v8::Local<v8::Context> context =
|
182
|
+
v8::Local<v8::Context> context = this->context();
|
172
183
|
v8::Context::Scope context_scope(context);
|
173
184
|
|
174
185
|
v8::TryCatch try_catch(isolate_);
|
@@ -244,7 +255,7 @@ bool _V8::debugger_init(debugger_cb cb, void *cbopq) {
|
|
244
255
|
v8::Locker locker(isolate_);
|
245
256
|
v8::Isolate::Scope isolate_scope(isolate_);
|
246
257
|
v8::HandleScope handle_scope(isolate_);
|
247
|
-
v8::Debug::SetMessageHandler(debugger_message_handler);
|
258
|
+
v8::Debug::SetMessageHandler(isolate_, debugger_message_handler);
|
248
259
|
|
249
260
|
return true;
|
250
261
|
}
|
@@ -255,7 +266,7 @@ void _V8::debugger_process() {
|
|
255
266
|
v8::Isolate::Scope isolate_scope(isolate_);
|
256
267
|
v8::HandleScope handle_scope(isolate_);
|
257
268
|
|
258
|
-
v8::Debug::ProcessDebugMessages();
|
269
|
+
v8::Debug::ProcessDebugMessages(isolate_);
|
259
270
|
}
|
260
271
|
|
261
272
|
bool _V8::debugger_send(const std::string& cmd) {
|
@@ -277,7 +288,7 @@ void _V8::debugger_stop() {
|
|
277
288
|
v8::Locker locker(isolate_);
|
278
289
|
v8::Isolate::Scope isolate_scope(isolate_);
|
279
290
|
v8::HandleScope handle_scope(isolate_);
|
280
|
-
v8::Debug::SetMessageHandler(nullptr);
|
291
|
+
v8::Debug::SetMessageHandler(isolate_, nullptr);
|
281
292
|
|
282
293
|
callback_ = nullptr;
|
283
294
|
callback_opq_ = nullptr;
|
@@ -285,4 +296,36 @@ void _V8::debugger_stop() {
|
|
285
296
|
dbg_isolate_ = nullptr;
|
286
297
|
}
|
287
298
|
|
299
|
+
void Heap(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
300
|
+
v8::Isolate* isolate = args.GetIsolate();
|
301
|
+
|
302
|
+
v8::HeapStatistics s;
|
303
|
+
isolate->GetHeapStatistics(&s);
|
304
|
+
|
305
|
+
v8::Local<v8::Object> obj = v8::Object::New(isolate);
|
306
|
+
obj->Set(v8::String::NewFromUtf8(isolate, "totalHeapSize"), v8::Number::New(isolate, s.total_heap_size()));
|
307
|
+
obj->Set(v8::String::NewFromUtf8(isolate, "totalHeapSizeExecutable"), v8::Number::New(isolate, s.total_heap_size_executable()));
|
308
|
+
obj->Set(v8::String::NewFromUtf8(isolate, "totalPhysicalSize"), v8::Number::New(isolate, s.total_physical_size()));
|
309
|
+
obj->Set(v8::String::NewFromUtf8(isolate, "totalAvailableSize"), v8::Number::New(isolate, s.total_available_size()));
|
310
|
+
obj->Set(v8::String::NewFromUtf8(isolate, "usedHeapSize"), v8::Number::New(isolate, s.used_heap_size()));
|
311
|
+
obj->Set(v8::String::NewFromUtf8(isolate, "heapSizeLimit"), v8::Number::New(isolate, s.heap_size_limit()));
|
312
|
+
obj->Set(v8::String::NewFromUtf8(isolate, "mallocedMemory"), v8::Number::New(isolate, s.malloced_memory()));
|
313
|
+
obj->Set(v8::String::NewFromUtf8(isolate, "peakMallocedMemory"), v8::Number::New(isolate, s.peak_malloced_memory()));
|
314
|
+
obj->Set(v8::String::NewFromUtf8(isolate, "doesZapGarbage"), v8::Number::New(isolate, s.does_zap_garbage()));
|
315
|
+
|
316
|
+
args.GetReturnValue().Set(obj);
|
317
|
+
}
|
318
|
+
|
319
|
+
void _V8::enable_heap_report() {
|
320
|
+
v8::Locker locker(isolate_);
|
321
|
+
|
322
|
+
v8::Isolate::Scope isolate_scope(isolate_);
|
323
|
+
v8::HandleScope handle_scope(isolate_);
|
324
|
+
|
325
|
+
v8::Local<v8::Context> context = this->context();
|
326
|
+
v8::Context::Scope context_scope(context);
|
327
|
+
|
328
|
+
context->Global()->Set(new_string("heap"), v8::FunctionTemplate::New(isolate_, Heap)->GetFunction());
|
329
|
+
}
|
330
|
+
|
288
331
|
} // namespace v8eval
|
data/src/v8eval.h
CHANGED
@@ -13,6 +13,11 @@ class DbgSrv;
|
|
13
13
|
|
14
14
|
typedef void (*debugger_cb)(std::string&, void *opq);
|
15
15
|
|
16
|
+
/// \brief Set the given V8 flags
|
17
|
+
///
|
18
|
+
/// This method sets the given V8 flags.
|
19
|
+
void set_flags(const std::string& flags);
|
20
|
+
|
16
21
|
/// \brief Initialize the V8 runtime environment
|
17
22
|
/// \return success or not as boolean
|
18
23
|
///
|
@@ -70,13 +75,20 @@ class _V8 {
|
|
70
75
|
/// connections to remote debuggers to be dropped.
|
71
76
|
void disable_debugger();
|
72
77
|
|
73
|
-
|
74
|
-
|
75
|
-
|
78
|
+
protected:
|
79
|
+
void enable_heap_report();
|
80
|
+
|
81
|
+
v8::Local<v8::Context> context();
|
82
|
+
v8::Local<v8::Context> new_context(
|
83
|
+
v8::Local<v8::ObjectTemplate> global_tmpl = v8::Local<v8::ObjectTemplate>(),
|
84
|
+
v8::Local<v8::Value> global_obj = v8::Local<v8::Value>());
|
76
85
|
v8::Local<v8::String> new_string(const char* str);
|
77
86
|
v8::Local<v8::Value> json_parse(v8::Local<v8::Context> context, v8::Local<v8::String> str);
|
78
87
|
v8::Local<v8::String> json_stringify(v8::Local<v8::Context> context, v8::Local<v8::Value> value);
|
79
88
|
|
89
|
+
private:
|
90
|
+
static void debugger_message_handler(const v8::Debug::Message& message);
|
91
|
+
|
80
92
|
bool debugger_init(debugger_cb cb, void *cbopq);
|
81
93
|
bool debugger_send(const std::string& cmd);
|
82
94
|
void debugger_process();
|
data/src/v8eval_go.cxx
CHANGED
data/v8eval.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: v8eval
|
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
|
- Prateek Papriwal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.4.
|
114
|
+
rubygems_version: 2.4.5.1
|
115
115
|
signing_key:
|
116
116
|
specification_version: 4
|
117
117
|
summary: v8eval gem is ruby binding to the latest V8 4.7 and supports Linux and Mac
|