v8eval 0.2.11 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CMakeLists.txt +27 -14
- data/README.md +11 -3
- data/build.sh +68 -68
- data/ruby/Gemfile +1 -1
- data/ruby/build.sh +8 -8
- data/ruby/ext/v8eval/extconf.rb +24 -14
- data/ruby/lib/v8eval.rb +0 -16
- data/ruby/spec/v8eval_spec.rb +0 -17
- data/src/v8eval.cxx +7 -129
- data/src/v8eval.h +1 -37
- data/v8eval.gemspec +5 -5
- metadata +25 -27
- data/src/dbgsrv.cxx +0 -211
- data/src/dbgsrv.h +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ba6f55974dccb6f5ffac2408df5fb6a1c76ecf1
|
4
|
+
data.tar.gz: 05a1dbbd82922892e311a77f2b21679d246ef457
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e5eda16cf3d7a1bb51fa3bb591b2417b517ed9cb3e36a1464a236890a2dd8b051df98088954019eefe72f6c0432c670eea242ea89fb8585c883c98a3ef4b7ea
|
7
|
+
data.tar.gz: e2f6dc37e8251d0cc38b585786c2390e2847e89b96cb458c363a5b66ff325b88e12527bb5fa6464ca2f5977238a1f160d3c1860e7e955d085d4c940d58ddeda6
|
data/CMakeLists.txt
CHANGED
@@ -11,30 +11,29 @@ endif(COMMAND cmake_policy)
|
|
11
11
|
include_directories(
|
12
12
|
v8
|
13
13
|
v8/include
|
14
|
-
uv/include
|
15
14
|
src
|
16
|
-
|
15
|
+
v8/third_party/googletest/src/googletest/include
|
17
16
|
)
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
endif(APPLE)
|
18
|
+
set(v8eval-linkdirs
|
19
|
+
v8/out.gn/x64.release/obj
|
20
|
+
v8/out.gn/x64.release/obj/third_party/googletest
|
21
|
+
)
|
24
22
|
|
25
23
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
26
|
-
|
27
|
-
|
24
|
+
set(v8eval-linkdirs
|
25
|
+
${v8eval-linkdirs}
|
26
|
+
v8/out.gn/x64.release/obj/buildtools/third_party/libc++
|
27
|
+
v8/out.gn/x64.release/obj/buildtools/third_party/libc++abi
|
28
28
|
)
|
29
29
|
endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
30
30
|
|
31
31
|
link_directories(
|
32
|
-
|
32
|
+
${v8eval-linkdirs}
|
33
33
|
)
|
34
34
|
|
35
35
|
add_library(v8eval STATIC
|
36
36
|
src/v8eval.cxx
|
37
|
-
src/dbgsrv.cxx
|
38
37
|
)
|
39
38
|
|
40
39
|
add_library(v8eval_go STATIC
|
@@ -51,7 +50,6 @@ add_library(v8eval_ruby STATIC
|
|
51
50
|
|
52
51
|
set(v8eval-cflags
|
53
52
|
-Wall
|
54
|
-
-Wendif-labels
|
55
53
|
-Werror
|
56
54
|
-Wno-missing-field-initializers
|
57
55
|
-Wno-unused-parameter
|
@@ -61,13 +59,28 @@ set(v8eval-cflags
|
|
61
59
|
-fno-rtti
|
62
60
|
-fno-strict-aliasing
|
63
61
|
-fno-threadsafe-statics
|
64
|
-
-fstrict-aliasing
|
65
62
|
-fvisibility=hidden
|
66
63
|
-fvisibility-inlines-hidden
|
67
64
|
-gdwarf-2
|
68
|
-
-std=c++
|
65
|
+
-std=c++14
|
69
66
|
)
|
70
67
|
|
68
|
+
if(APPLE)
|
69
|
+
set(v8eval-cflags
|
70
|
+
${v8eval-cflags}
|
71
|
+
-stdlib=libc++
|
72
|
+
)
|
73
|
+
endif(APPLE)
|
74
|
+
|
75
|
+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
76
|
+
set(v8eval-cflags
|
77
|
+
${v8eval-cflags}
|
78
|
+
-nostdinc++
|
79
|
+
-isystem ${CMAKE_CURRENT_SOURCE_DIR}/v8/buildtools/third_party/libc++/trunk/include
|
80
|
+
-isystem ${CMAKE_CURRENT_SOURCE_DIR}/v8/buildtools/third_party/libc++abi/trunk/include
|
81
|
+
)
|
82
|
+
endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
83
|
+
|
71
84
|
string(REPLACE ";" " " v8eval-cflags "${v8eval-cflags}")
|
72
85
|
|
73
86
|
set_target_properties(v8eval PROPERTIES
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
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
|
9
|
+
Currently v8eval provides Go, Python and Ruby bindings to the latest V8 7.1 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
|
@@ -25,9 +25,17 @@ The installation takes several tens of minutes due to V8 build.
|
|
25
25
|
|
26
26
|
#### Go
|
27
27
|
|
28
|
+
v8eval requires Go 1.10 or later.
|
29
|
+
|
30
|
+
```
|
31
|
+
git clone https://github.com/sony/v8eval.git ${GOPATH}/src/github.com/sony/v8eval
|
32
|
+
${GOPATH}/src/github.com/sony/v8eval/go/build.sh install
|
33
|
+
```
|
34
|
+
|
35
|
+
In the case of Linux, you need to build your Go program with `build.sh`:
|
36
|
+
|
28
37
|
```
|
29
|
-
|
30
|
-
$GOPATH/src/github.com/sony/v8eval/go/build.sh install
|
38
|
+
${GOPATH}/src/github.com/sony/v8eval/go/build.sh go build
|
31
39
|
```
|
32
40
|
|
33
41
|
#### Python
|
data/build.sh
CHANGED
@@ -1,123 +1,123 @@
|
|
1
1
|
#!/bin/sh
|
2
2
|
|
3
|
-
V8EVAL_ROOT=`cd $(dirname $0) && pwd`
|
3
|
+
V8EVAL_ROOT=`cd $(dirname ${0}) && pwd`
|
4
4
|
|
5
5
|
PLATFORM=`uname`
|
6
|
-
if [ $PLATFORM = "Linux" ]; then
|
7
|
-
NUM_CPU_CORES=`cat /proc/cpuinfo | grep cores | grep -o '[0-9]\+' | awk '{total=total+$1}; END{print total}'`
|
8
|
-
|
9
|
-
export CC=$V8EVAL_ROOT/v8/third_party/llvm-build/Release+Asserts/bin/clang
|
10
|
-
export CXX=$V8EVAL_ROOT/v8/third_party/llvm-build/Release+Asserts/bin/clang++
|
11
|
-
elif [ $PLATFORM = "Darwin" ]; then
|
12
|
-
NUM_CPU_CORES=`sysctl -n hw.ncpu`
|
13
|
-
|
14
|
-
export CC=`which clang`
|
15
|
-
export CXX=`which clang++`
|
16
|
-
export CPP="`which clang` -E"
|
17
|
-
export LINK="`which clang++`"
|
18
|
-
export CC_host=`which clang`
|
19
|
-
export CXX_host=`which clang++`
|
20
|
-
export CPP_host="`which clang` -E"
|
21
|
-
export LINK_host=`which clang++`
|
22
|
-
export GYP_DEFINES="clang=1 mac_deployment_target=10.10"
|
23
|
-
else
|
6
|
+
if [ ! ${PLATFORM} = "Linux" -a ! ${PLATFORM} = "Darwin" ]; then
|
24
7
|
echo "unsupported platform: ${PLATFORM}"
|
25
8
|
exit 1
|
26
9
|
fi
|
27
10
|
|
11
|
+
export CC=${V8EVAL_ROOT}/v8/third_party/llvm-build/Release+Asserts/bin/clang
|
12
|
+
export CXX=${V8EVAL_ROOT}/v8/third_party/llvm-build/Release+Asserts/bin/clang++
|
13
|
+
|
14
|
+
if [ ${PLATFORM} = "Linux" ]; then
|
15
|
+
export PATH=${V8EVAL_ROOT}/v8/third_party/binutils/Linux_x64/Release/bin:${PATH}
|
16
|
+
fi
|
17
|
+
|
28
18
|
install_depot_tools() {
|
29
|
-
export PATH=$V8EVAL_ROOT/depot_tools:$PATH
|
30
|
-
if [ -d $V8EVAL_ROOT/depot_tools ]; then
|
19
|
+
export PATH=${V8EVAL_ROOT}/depot_tools:${PATH}
|
20
|
+
if [ -d ${V8EVAL_ROOT}/depot_tools ]; then
|
31
21
|
return 0
|
32
22
|
fi
|
33
23
|
|
34
|
-
cd $V8EVAL_ROOT
|
24
|
+
cd ${V8EVAL_ROOT}
|
35
25
|
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
|
36
26
|
}
|
37
27
|
|
38
|
-
|
39
|
-
if [ -d $V8EVAL_ROOT/
|
28
|
+
install_v8() {
|
29
|
+
if [ -d ${V8EVAL_ROOT}/v8 ]; then
|
40
30
|
return 0
|
41
31
|
fi
|
42
32
|
|
43
|
-
cd $V8EVAL_ROOT
|
44
|
-
|
45
|
-
|
33
|
+
cd ${V8EVAL_ROOT}
|
34
|
+
fetch v8
|
35
|
+
cd v8
|
36
|
+
git checkout 7.1.177
|
37
|
+
gclient sync
|
38
|
+
if [ ${PLATFORM} = "Linux" ]; then
|
39
|
+
./build/install-build-deps.sh
|
40
|
+
fi
|
41
|
+
tools/dev/v8gen.py x64.release -- v8_use_snapshot=false v8_enable_i18n_support=false
|
42
|
+
ninja -v -C out.gn/x64.release
|
46
43
|
}
|
47
44
|
|
48
|
-
|
49
|
-
if [ -
|
45
|
+
archive_lib() {
|
46
|
+
if [ -f ${1}/lib${2}.a ]; then
|
50
47
|
return 0
|
51
48
|
fi
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
if [ `echo ${2} | cut -c 1-3` = "lib" ]; then
|
51
|
+
ar cr ${1}/${2}.a ${1}/${2}/*.o
|
52
|
+
else
|
53
|
+
ar cr ${1}/lib${2}.a ${1}/${2}/*.o
|
57
54
|
fi
|
55
|
+
}
|
58
56
|
|
59
|
-
|
60
|
-
fetch v8
|
61
|
-
cd v8
|
62
|
-
git checkout 6.3.288
|
63
|
-
gclient sync
|
64
|
-
if [ $PY_VER = 3 ]; then
|
65
|
-
sed -i -e 's/python -c/python2 -c/' Makefile
|
66
|
-
fi
|
67
|
-
CFLAGS="-fPIC -Wno-unknown-warning-option" CXXFLAGS="-fPIC -Wno-unknown-warning-option" make x64.release -j$NUM_CPU_CORES i18nsupport=off V=1
|
57
|
+
V8_OUT=${V8EVAL_ROOT}/v8/out.gn/x64.release/obj
|
68
58
|
|
69
|
-
|
70
|
-
|
71
|
-
|
59
|
+
archive_v8() {
|
60
|
+
archive_lib ${V8_OUT} v8_base
|
61
|
+
archive_lib ${V8_OUT} v8_libsampler
|
62
|
+
archive_lib ${V8_OUT} v8_init
|
63
|
+
archive_lib ${V8_OUT} v8_initializers
|
64
|
+
archive_lib ${V8_OUT} v8_nosnapshot
|
65
|
+
archive_lib ${V8_OUT} torque_generated_initializers
|
72
66
|
}
|
73
67
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
68
|
+
archive_libcxx() {
|
69
|
+
archive_lib ${V8_OUT}/buildtools/third_party/libc++ libc++
|
70
|
+
}
|
71
|
+
|
72
|
+
archive_libcxxabi() {
|
73
|
+
archive_lib ${V8_OUT}/buildtools/third_party/libc++abi libc++abi
|
74
|
+
}
|
78
75
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
git checkout v1.7.5
|
83
|
-
sh autogen.sh
|
84
|
-
./configure --with-pic --disable-shared
|
85
|
-
make V=1
|
76
|
+
archive_googletest() {
|
77
|
+
archive_lib ${V8_OUT}/third_party/googletest gtest
|
78
|
+
archive_lib ${V8_OUT}/third_party/googletest gtest_main
|
86
79
|
}
|
87
80
|
|
88
81
|
build() {
|
89
82
|
install_depot_tools
|
90
83
|
install_v8
|
91
|
-
|
84
|
+
archive_v8
|
85
|
+
if [ ${PLATFORM} = "Linux" ]; then
|
86
|
+
archive_libcxx
|
87
|
+
archive_libcxxabi
|
88
|
+
fi
|
92
89
|
|
93
|
-
cd $V8EVAL_ROOT
|
90
|
+
cd ${V8EVAL_ROOT}
|
94
91
|
mkdir -p build
|
95
92
|
cd build
|
96
93
|
cmake -DCMAKE_BUILD_TYPE=Release -DV8EVAL_TEST=OFF ..
|
97
94
|
make VERBOSE=1
|
95
|
+
|
96
|
+
cd ${V8EVAL_ROOT}
|
97
|
+
rm -rf old_v8_tools_luci-go.git
|
98
98
|
}
|
99
99
|
|
100
100
|
docs() {
|
101
|
-
cd $V8EVAL_ROOT/docs
|
101
|
+
cd ${V8EVAL_ROOT}/docs
|
102
102
|
rm -rf ./html
|
103
103
|
doxygen
|
104
104
|
}
|
105
105
|
|
106
106
|
test() {
|
107
107
|
build
|
108
|
-
|
108
|
+
archive_googletest
|
109
109
|
|
110
|
-
cd $V8EVAL_ROOT/build
|
110
|
+
cd ${V8EVAL_ROOT}/build
|
111
111
|
cmake -DCMAKE_BUILD_TYPE=Release -DV8EVAL_TEST=ON ..
|
112
112
|
make VERBOSE=1
|
113
113
|
./test/v8eval-test
|
114
114
|
}
|
115
115
|
|
116
|
-
# dispatch
|
117
|
-
SUBCOMMAND
|
118
|
-
case
|
119
|
-
""
|
120
|
-
"docs"
|
121
|
-
"test"
|
122
|
-
*
|
116
|
+
# dispatch subcommands
|
117
|
+
SUBCOMMAND=${1}
|
118
|
+
case ${SUBCOMMAND} in
|
119
|
+
"" ) build ;;
|
120
|
+
"docs" ) docs ;;
|
121
|
+
"test" ) test ;;
|
122
|
+
* ) echo "unknown subcommand: ${SUBCOMMAND}"; exit 1 ;;
|
123
123
|
esac
|
data/ruby/Gemfile
CHANGED
data/ruby/build.sh
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
#!/bin/sh
|
2
2
|
|
3
|
-
V8EVAL_ROOT=`cd $(dirname $0)/.. && pwd`
|
3
|
+
V8EVAL_ROOT=`cd $(dirname ${0})/.. && pwd`
|
4
4
|
|
5
5
|
build() {
|
6
|
-
cd $V8EVAL_ROOT/ruby
|
6
|
+
cd ${V8EVAL_ROOT}/ruby
|
7
7
|
rake prepare_build
|
8
8
|
rake build_ext
|
9
9
|
}
|
10
10
|
|
11
11
|
install() {
|
12
|
-
cd $V8EVAL_ROOT
|
12
|
+
cd ${V8EVAL_ROOT}
|
13
13
|
gem build v8eval.gemspec
|
14
14
|
gem install v8eval-*.gem
|
15
15
|
}
|
16
16
|
|
17
17
|
docs() {
|
18
|
-
cd $V8EVAL_ROOT/ruby
|
18
|
+
cd ${V8EVAL_ROOT}/ruby
|
19
19
|
rm -rf ./doc
|
20
20
|
mkdir ./doc
|
21
21
|
yardoc --main ../README.md lib/v8eval.rb
|
@@ -25,15 +25,15 @@ test() {
|
|
25
25
|
build
|
26
26
|
|
27
27
|
gem install bundler -v 1.14.5
|
28
|
-
cd $V8EVAL_ROOT/ruby
|
28
|
+
cd ${V8EVAL_ROOT}/ruby
|
29
29
|
bundle install
|
30
30
|
|
31
|
-
rspec --init
|
32
|
-
rspec
|
31
|
+
bundle exec rspec --init
|
32
|
+
bundle exec rspec
|
33
33
|
}
|
34
34
|
|
35
35
|
# dispatch subcommand
|
36
|
-
SUBCOMMAND="$1";
|
36
|
+
SUBCOMMAND="${1}";
|
37
37
|
case "${SUBCOMMAND}" in
|
38
38
|
"" ) build ;;
|
39
39
|
"install" ) install ;;
|
data/ruby/ext/v8eval/extconf.rb
CHANGED
@@ -6,7 +6,6 @@ require_relative '../../lib/setup/extension_builder'
|
|
6
6
|
# set path variables
|
7
7
|
v8eval_root = File.expand_path('../../..', Dir.pwd)
|
8
8
|
v8_dir = v8eval_root + '/v8'
|
9
|
-
uv_dir = v8eval_root + '/uv'
|
10
9
|
|
11
10
|
# make instance of BuildTool class
|
12
11
|
tool = BuildTool.new(v8eval_root)
|
@@ -23,32 +22,43 @@ INCLUDEDIR = RbConfig::CONFIG['includedir']
|
|
23
22
|
header_dirs = [
|
24
23
|
v8_dir,
|
25
24
|
v8_dir + '/include',
|
26
|
-
uv_dir + '/include',
|
27
25
|
INCLUDEDIR
|
28
26
|
]
|
29
27
|
|
30
28
|
lib_dirs = [
|
31
29
|
v8eval_root + '/build',
|
32
|
-
|
30
|
+
v8_dir + '/out.gn/x64.release/obj',
|
33
31
|
LIBDIR
|
34
32
|
]
|
35
33
|
|
36
|
-
if RUBY_PLATFORM =~ /
|
34
|
+
if RUBY_PLATFORM =~ /linux/
|
37
35
|
lib_dirs += [
|
38
|
-
v8_dir + '/out/x64.release'
|
36
|
+
v8_dir + '/out.gn/x64.release/obj/buildtools/third_party/libc++',
|
37
|
+
v8_dir + '/out.gn/x64.release/obj/buildtools/third_party/libc++abi'
|
39
38
|
]
|
40
|
-
elsif RUBY_PLATFORM =~ /linux/
|
41
|
-
lib_dirs += [
|
42
|
-
v8_dir + '/out/x64.release/obj.target/src'
|
43
|
-
]
|
44
|
-
|
45
|
-
RbConfig::MAKEFILE_CONFIG['CC'] = v8_dir + '/third_party/llvm-build/Release+Asserts/bin/clang'
|
46
|
-
RbConfig::MAKEFILE_CONFIG['CXX'] = v8_dir + '/third_party/llvm-build/Release+Asserts/bin/clang++'
|
47
39
|
end
|
48
40
|
|
49
41
|
dir_config('', header_dirs, lib_dirs)
|
50
42
|
|
51
|
-
|
52
|
-
|
43
|
+
RbConfig::MAKEFILE_CONFIG['CC'] = v8_dir + '/third_party/llvm-build/Release+Asserts/bin/clang'
|
44
|
+
RbConfig::MAKEFILE_CONFIG['CXX'] = v8_dir + '/third_party/llvm-build/Release+Asserts/bin/clang++'
|
45
|
+
|
46
|
+
$LDFLAGS << ' -lv8eval' +
|
47
|
+
' -lv8eval_ruby' +
|
48
|
+
' -lv8_libplatform' +
|
49
|
+
' -lv8_base' +
|
50
|
+
' -lv8_libbase' +
|
51
|
+
' -lv8_libsampler' +
|
52
|
+
' -lv8_init' +
|
53
|
+
' -lv8_initializers' +
|
54
|
+
' -lv8_nosnapshot' +
|
55
|
+
' -ltorque_generated_initializers'
|
56
|
+
$CPPFLAGS << ' -O3 -std=c++14 -stdlib=libc++'
|
57
|
+
|
58
|
+
if RUBY_PLATFORM =~ /linux/
|
59
|
+
$LDFLAGS << ' -lrt -lc++ -lc++abi'
|
60
|
+
$CPPFLAGS << ' -isystem' + v8_dir + '/buildtools/third_party/libc++/trunk/include' +
|
61
|
+
' -isystem' + v8_dir + '/buildtools/third_party/libc++abi/trunk/include'
|
62
|
+
end
|
53
63
|
|
54
64
|
create_makefile('v8eval/v8eval')
|
data/ruby/lib/v8eval.rb
CHANGED
@@ -58,22 +58,6 @@ module V8Eval
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
62
|
-
# Starts a debug server associated with the V8 instance.
|
63
|
-
# @param [Integer] port TCP/IP port the server will listen, at localhost.
|
64
|
-
# @return nil.
|
65
|
-
# @raise [TypeError] If port is not an int.
|
66
|
-
# @raise [V8Error] If failing to start the debug server.
|
67
|
-
def enable_debugger(port)
|
68
|
-
fail TypeError, 'port not integer' unless port.is_a?(Integer)
|
69
|
-
fail V8Error, 'failed to start debug server' unless @v8.enable_debugger(port)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Stops the debug server, if running.
|
73
|
-
# @return nil.
|
74
|
-
def disable_debugger
|
75
|
-
@v8.disable_debugger
|
76
|
-
end
|
77
61
|
end
|
78
62
|
end
|
79
63
|
|
data/ruby/spec/v8eval_spec.rb
CHANGED
@@ -55,20 +55,3 @@ RSpec.describe V8Eval, '#multithreading' do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
59
|
-
RSpec.describe V8Eval, '#test_debugger' do
|
60
|
-
context 'with debugging functionality' do
|
61
|
-
it 'should enable and disable debugger properly' do
|
62
|
-
v8 = V8Eval::V8.new
|
63
|
-
expect { v8.enable_debugger(0.1) }.to raise_exception(TypeError)
|
64
|
-
expect { v8.enable_debugger(-1) }.to raise_exception(V8Eval::V8Error)
|
65
|
-
|
66
|
-
port = 12_345
|
67
|
-
expect(v8.enable_debugger(port)).to be nil
|
68
|
-
expect { v8.enable_debugger(port) }.to raise_exception(V8Eval::V8Error)
|
69
|
-
expect(v8.disable_debugger).to be nil
|
70
|
-
expect(v8.enable_debugger(port)).to be nil
|
71
|
-
expect(v8.disable_debugger).to be nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/src/v8eval.cxx
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#include "v8eval.h"
|
2
|
-
#include "dbgsrv.h"
|
3
2
|
|
4
3
|
#include <cassert>
|
5
4
|
#include <cstdlib>
|
@@ -40,39 +39,12 @@ bool dispose() {
|
|
40
39
|
return true;
|
41
40
|
}
|
42
41
|
|
43
|
-
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
|
44
|
-
public:
|
45
|
-
virtual void* Allocate(size_t length) {
|
46
|
-
void* data = AllocateUninitialized(length);
|
47
|
-
return data == NULL ? data : memset(data, 0, length);
|
48
|
-
}
|
49
|
-
|
50
|
-
virtual void* AllocateUninitialized(size_t length) {
|
51
|
-
return malloc(length);
|
52
|
-
}
|
53
|
-
|
54
|
-
virtual void Free(void* data, size_t) {
|
55
|
-
free(data);
|
56
|
-
}
|
57
|
-
};
|
58
|
-
|
59
|
-
static ArrayBufferAllocator allocator;
|
60
|
-
|
61
42
|
_V8::_V8() {
|
62
43
|
v8::Isolate::CreateParams create_params;
|
63
|
-
create_params.array_buffer_allocator =
|
44
|
+
create_params.array_buffer_allocator =
|
45
|
+
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
|
64
46
|
isolate_ = v8::Isolate::New(create_params);
|
65
47
|
|
66
|
-
dbg_server_ = nullptr;
|
67
|
-
dbg_isolate_ = nullptr;
|
68
|
-
callback_ = nullptr;
|
69
|
-
callback_opq_ = nullptr;
|
70
|
-
|
71
|
-
// Use Isolate's local storage to store a pointer to the associated
|
72
|
-
// V8 instance. This is retrieved in the V8 debugger's callback, as
|
73
|
-
// the instance pointer is the only context we get from the caller.
|
74
|
-
isolate_->SetData(0, this);
|
75
|
-
|
76
48
|
v8::Locker locker(isolate_);
|
77
49
|
|
78
50
|
v8::Isolate::Scope isolate_scope(isolate_);
|
@@ -81,11 +53,6 @@ _V8::_V8() {
|
|
81
53
|
}
|
82
54
|
|
83
55
|
_V8::~_V8() {
|
84
|
-
if (dbg_server_) {
|
85
|
-
delete dbg_server_;
|
86
|
-
}
|
87
|
-
|
88
|
-
context_.Reset();
|
89
56
|
isolate_->Dispose();
|
90
57
|
}
|
91
58
|
|
@@ -107,14 +74,14 @@ v8::Local<v8::String> _V8::new_string(const char* str) {
|
|
107
74
|
return v8::String::NewFromUtf8(isolate_, str ? str : "", v8::NewStringType::kNormal).ToLocalChecked();
|
108
75
|
}
|
109
76
|
|
110
|
-
|
111
|
-
v8::String::Utf8Value str(value);
|
77
|
+
std::string _V8::to_std_string(v8::Local<v8::Value> value) {
|
78
|
+
v8::String::Utf8Value str(isolate_, value);
|
112
79
|
return *str ? *str : "Error: Cannot convert to string";
|
113
80
|
}
|
114
81
|
|
115
82
|
v8::Local<v8::Value> _V8::json_parse(v8::Local<v8::Context> context, v8::Local<v8::String> str) {
|
116
83
|
v8::Local<v8::Object> global = context->Global();
|
117
|
-
v8::Local<v8::Object> json = global->Get(context, new_string("JSON")).ToLocalChecked()->ToObject();
|
84
|
+
v8::Local<v8::Object> json = global->Get(context, new_string("JSON")).ToLocalChecked()->ToObject(isolate_);
|
118
85
|
v8::Local<v8::Function> parse = v8::Local<v8::Function>::Cast(json->Get(context, new_string("parse")).ToLocalChecked());
|
119
86
|
|
120
87
|
v8::Local<v8::Value> result;
|
@@ -128,14 +95,14 @@ v8::Local<v8::Value> _V8::json_parse(v8::Local<v8::Context> context, v8::Local<v
|
|
128
95
|
|
129
96
|
v8::Local<v8::String> _V8::json_stringify(v8::Local<v8::Context> context, v8::Local<v8::Value> value) {
|
130
97
|
v8::Local<v8::Object> global = context->Global();
|
131
|
-
v8::Local<v8::Object> json = global->Get(context, new_string("JSON")).ToLocalChecked()->ToObject();
|
98
|
+
v8::Local<v8::Object> json = global->Get(context, new_string("JSON")).ToLocalChecked()->ToObject(isolate_);
|
132
99
|
v8::Local<v8::Function> stringify = v8::Local<v8::Function>::Cast(json->Get(context, new_string("stringify")).ToLocalChecked());
|
133
100
|
|
134
101
|
v8::Local<v8::Value> result;
|
135
102
|
if (!stringify->Call(context, json, 1, &value).ToLocal(&result)) {
|
136
103
|
return new_string("");
|
137
104
|
} else {
|
138
|
-
return result->ToString();
|
105
|
+
return result->ToString(isolate_);
|
139
106
|
}
|
140
107
|
}
|
141
108
|
|
@@ -207,95 +174,6 @@ std::string _V8::call(const std::string& func, const std::string& args) {
|
|
207
174
|
}
|
208
175
|
}
|
209
176
|
|
210
|
-
bool _V8::enable_debugger(int port) {
|
211
|
-
if (dbg_server_) {
|
212
|
-
return false;
|
213
|
-
}
|
214
|
-
|
215
|
-
dbg_server_ = new DbgSrv(*this);
|
216
|
-
if (!dbg_server_->start(port)) {
|
217
|
-
delete dbg_server_;
|
218
|
-
dbg_server_ = nullptr;
|
219
|
-
return false;
|
220
|
-
}
|
221
|
-
|
222
|
-
return true;
|
223
|
-
}
|
224
|
-
|
225
|
-
void _V8::disable_debugger() {
|
226
|
-
if (dbg_server_) {
|
227
|
-
delete dbg_server_;
|
228
|
-
dbg_server_ = nullptr;
|
229
|
-
}
|
230
|
-
}
|
231
|
-
|
232
|
-
void _V8::debugger_message_handler(const v8::Debug::Message& message) {
|
233
|
-
v8::Isolate* isolate = message.GetIsolate();
|
234
|
-
_V8 *_v8 = (v8eval::_V8*)isolate->GetData(0);
|
235
|
-
std::string string = *v8::String::Utf8Value(message.GetJSON());
|
236
|
-
|
237
|
-
if (_v8->callback_) {
|
238
|
-
_v8->callback_(string, _v8->callback_opq_);
|
239
|
-
}
|
240
|
-
}
|
241
|
-
|
242
|
-
bool _V8::debugger_init(debugger_cb cb, void *cbopq) {
|
243
|
-
v8::Isolate::CreateParams create_params;
|
244
|
-
create_params.array_buffer_allocator = &allocator;
|
245
|
-
dbg_isolate_ = v8::Isolate::New(create_params);
|
246
|
-
|
247
|
-
if (callback_) {
|
248
|
-
return false;
|
249
|
-
}
|
250
|
-
|
251
|
-
callback_ = cb;
|
252
|
-
callback_opq_ = cbopq;
|
253
|
-
|
254
|
-
// Set Debuger callback.
|
255
|
-
v8::Locker locker(isolate_);
|
256
|
-
v8::Isolate::Scope isolate_scope(isolate_);
|
257
|
-
v8::HandleScope handle_scope(isolate_);
|
258
|
-
v8::Debug::SetMessageHandler(isolate_, debugger_message_handler);
|
259
|
-
|
260
|
-
return true;
|
261
|
-
}
|
262
|
-
|
263
|
-
void _V8::debugger_process() {
|
264
|
-
// Process debug messages on behalf of the V8 instance.
|
265
|
-
v8::Locker locker(isolate_);
|
266
|
-
v8::Isolate::Scope isolate_scope(isolate_);
|
267
|
-
v8::HandleScope handle_scope(isolate_);
|
268
|
-
|
269
|
-
v8::Debug::ProcessDebugMessages(isolate_);
|
270
|
-
}
|
271
|
-
|
272
|
-
bool _V8::debugger_send(const std::string& cmd) {
|
273
|
-
v8::Locker locker(dbg_isolate_);
|
274
|
-
v8::Isolate::Scope isolate_scope(dbg_isolate_);
|
275
|
-
v8::HandleScope handle_scope(dbg_isolate_);
|
276
|
-
|
277
|
-
if (!callback_) {
|
278
|
-
return false;
|
279
|
-
}
|
280
|
-
|
281
|
-
v8::Local<v8::String> vstr = v8::String::NewFromUtf8(dbg_isolate_, cmd.c_str(), v8::NewStringType::kNormal).ToLocalChecked();
|
282
|
-
v8::String::Value v(vstr);
|
283
|
-
v8::Debug::SendCommand(isolate_, *v, v.length());
|
284
|
-
return true;
|
285
|
-
}
|
286
|
-
|
287
|
-
void _V8::debugger_stop() {
|
288
|
-
v8::Locker locker(isolate_);
|
289
|
-
v8::Isolate::Scope isolate_scope(isolate_);
|
290
|
-
v8::HandleScope handle_scope(isolate_);
|
291
|
-
v8::Debug::SetMessageHandler(isolate_, nullptr);
|
292
|
-
|
293
|
-
callback_ = nullptr;
|
294
|
-
callback_opq_ = nullptr;
|
295
|
-
dbg_isolate_->Dispose();
|
296
|
-
dbg_isolate_ = nullptr;
|
297
|
-
}
|
298
|
-
|
299
177
|
void Heap(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
300
178
|
v8::Isolate* isolate = args.GetIsolate();
|
301
179
|
|
data/src/v8eval.h
CHANGED
@@ -4,15 +4,10 @@
|
|
4
4
|
#include <string>
|
5
5
|
|
6
6
|
#include "v8.h"
|
7
|
-
#include "v8-debug.h"
|
8
7
|
|
9
8
|
/// \file
|
10
9
|
namespace v8eval {
|
11
10
|
|
12
|
-
class DbgSrv;
|
13
|
-
|
14
|
-
typedef void (*debugger_cb)(std::string&, void *opq);
|
15
|
-
|
16
11
|
/// \brief Set the given V8 flags
|
17
12
|
///
|
18
13
|
/// This method sets the given V8 flags.
|
@@ -58,23 +53,6 @@ class _V8 {
|
|
58
53
|
/// If some JavaScript exception happens in runtime, the exception message is returned.
|
59
54
|
std::string call(const std::string& func, const std::string& args);
|
60
55
|
|
61
|
-
/// \brief Start a debug server associated with the V8 instance
|
62
|
-
/// \param port The TCP/IP port the debugger will listen, at localhost
|
63
|
-
/// \return success or not as boolean
|
64
|
-
///
|
65
|
-
/// After the debugger is successfully started, it will be possible to
|
66
|
-
/// send commands and receive events at the specified port. When the
|
67
|
-
/// debugger is started, the Javascript's "debugger" statement will
|
68
|
-
/// cause the V8 instance to halt and wait for instructions through
|
69
|
-
/// the debugger port.
|
70
|
-
bool enable_debugger(int port);
|
71
|
-
|
72
|
-
/// \brief Stop the debug server, if running.
|
73
|
-
///
|
74
|
-
/// The debug server, if currently running, will be stopped, causing
|
75
|
-
/// connections to remote debuggers to be dropped.
|
76
|
-
void disable_debugger();
|
77
|
-
|
78
56
|
protected:
|
79
57
|
void enable_heap_report();
|
80
58
|
|
@@ -85,25 +63,11 @@ class _V8 {
|
|
85
63
|
v8::Local<v8::String> new_string(const char* str);
|
86
64
|
v8::Local<v8::Value> json_parse(v8::Local<v8::Context> context, v8::Local<v8::String> str);
|
87
65
|
v8::Local<v8::String> json_stringify(v8::Local<v8::Context> context, v8::Local<v8::Value> value);
|
88
|
-
|
89
|
-
private:
|
90
|
-
static void debugger_message_handler(const v8::Debug::Message& message);
|
91
|
-
|
92
|
-
bool debugger_init(debugger_cb cb, void *cbopq);
|
93
|
-
bool debugger_send(const std::string& cmd);
|
94
|
-
void debugger_process();
|
95
|
-
void debugger_stop();
|
66
|
+
std::string to_std_string(v8::Local<v8::Value> value);
|
96
67
|
|
97
68
|
private:
|
98
69
|
v8::Isolate* isolate_;
|
99
70
|
v8::Persistent<v8::Context> context_;
|
100
|
-
|
101
|
-
DbgSrv* dbg_server_;
|
102
|
-
v8::Isolate* dbg_isolate_;
|
103
|
-
debugger_cb callback_;
|
104
|
-
void* callback_opq_;
|
105
|
-
|
106
|
-
friend class DbgSrv;
|
107
71
|
};
|
108
72
|
|
109
73
|
} // namespace v8eval
|
data/v8eval.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
Gem::Specification.new 'v8eval', '1.0' do |s|
|
2
2
|
s.name = 'v8eval'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.3.0'
|
4
4
|
s.licenses = ['MIT']
|
5
5
|
s.description = 'Run JavaScript engine V8 in Ruby'
|
6
|
-
s.summary = 'v8eval gem is ruby binding to the latest V8
|
6
|
+
s.summary = 'v8eval gem is ruby binding to the latest V8 and supports
|
7
7
|
Linux and Mac OS X.'
|
8
|
-
s.authors = ['Prateek Papriwal']
|
9
|
-
s.email = '
|
8
|
+
s.authors = ['Prateek Papriwal', 'Yoshiyuki Mineo']
|
9
|
+
s.email = 'Yoshiyuki.Mineo@sony.com'
|
10
10
|
s.homepage = 'https://github.com/sony/v8eval'
|
11
11
|
s.extra_rdoc_files = ['README.md']
|
12
12
|
|
@@ -19,7 +19,7 @@ Gem::Specification.new 'v8eval', '1.0' do |s|
|
|
19
19
|
|
20
20
|
s.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2'
|
21
21
|
s.add_development_dependency 'rspec', '~> 3.0'
|
22
|
-
s.add_development_dependency 'yard', '0.
|
22
|
+
s.add_development_dependency 'yard', '>= 0.9.11'
|
23
23
|
|
24
24
|
s.required_ruby_version = '>= 2.0.0'
|
25
25
|
end
|
metadata
CHANGED
@@ -1,86 +1,81 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: v8eval
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Prateek Papriwal
|
8
|
+
- Yoshiyuki Mineo
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2018-
|
12
|
+
date: 2018-11-09 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rake
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- -
|
18
|
+
- - ~>
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: '10.4'
|
20
|
-
- -
|
21
|
+
- - '>='
|
21
22
|
- !ruby/object:Gem::Version
|
22
23
|
version: 10.4.2
|
23
24
|
type: :development
|
24
25
|
prerelease: false
|
25
26
|
version_requirements: !ruby/object:Gem::Requirement
|
26
27
|
requirements:
|
27
|
-
- -
|
28
|
+
- - ~>
|
28
29
|
- !ruby/object:Gem::Version
|
29
30
|
version: '10.4'
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: 10.4.2
|
33
34
|
- !ruby/object:Gem::Dependency
|
34
35
|
name: rspec
|
35
36
|
requirement: !ruby/object:Gem::Requirement
|
36
37
|
requirements:
|
37
|
-
- -
|
38
|
+
- - ~>
|
38
39
|
- !ruby/object:Gem::Version
|
39
40
|
version: '3.0'
|
40
41
|
type: :development
|
41
42
|
prerelease: false
|
42
43
|
version_requirements: !ruby/object:Gem::Requirement
|
43
44
|
requirements:
|
44
|
-
- -
|
45
|
+
- - ~>
|
45
46
|
- !ruby/object:Gem::Version
|
46
47
|
version: '3.0'
|
47
48
|
- !ruby/object:Gem::Dependency
|
48
49
|
name: yard
|
49
50
|
requirement: !ruby/object:Gem::Requirement
|
50
51
|
requirements:
|
51
|
-
- - '
|
52
|
+
- - '>='
|
52
53
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.
|
54
|
+
version: 0.9.11
|
54
55
|
type: :development
|
55
56
|
prerelease: false
|
56
57
|
version_requirements: !ruby/object:Gem::Requirement
|
57
58
|
requirements:
|
58
|
-
- - '
|
59
|
+
- - '>='
|
59
60
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0.
|
61
|
+
version: 0.9.11
|
61
62
|
description: Run JavaScript engine V8 in Ruby
|
62
|
-
email:
|
63
|
+
email: Yoshiyuki.Mineo@sony.com
|
63
64
|
executables: []
|
64
65
|
extensions:
|
65
66
|
- ruby/ext/v8eval/extconf.rb
|
66
67
|
extra_rdoc_files:
|
67
68
|
- README.md
|
68
69
|
files:
|
69
|
-
- CMakeLists.txt
|
70
|
-
- LICENSE
|
71
|
-
- README.md
|
72
|
-
- build.sh
|
73
|
-
- ruby/Gemfile
|
74
|
-
- ruby/Rakefile
|
75
70
|
- ruby/build.sh
|
76
71
|
- ruby/example/js_add.rb
|
77
72
|
- ruby/ext/v8eval/extconf.rb
|
78
73
|
- ruby/ext/v8eval/v8eval.i
|
74
|
+
- ruby/Gemfile
|
79
75
|
- ruby/lib/setup/extension_builder.rb
|
80
76
|
- ruby/lib/v8eval.rb
|
77
|
+
- ruby/Rakefile
|
81
78
|
- ruby/spec/v8eval_spec.rb
|
82
|
-
- src/dbgsrv.cxx
|
83
|
-
- src/dbgsrv.h
|
84
79
|
- src/v8eval.cxx
|
85
80
|
- src/v8eval.h
|
86
81
|
- src/v8eval_go.cxx
|
@@ -89,6 +84,10 @@ files:
|
|
89
84
|
- src/v8eval_python.h
|
90
85
|
- src/v8eval_ruby.cxx
|
91
86
|
- src/v8eval_ruby.h
|
87
|
+
- build.sh
|
88
|
+
- README.md
|
89
|
+
- LICENSE
|
90
|
+
- CMakeLists.txt
|
92
91
|
- v8eval.gemspec
|
93
92
|
homepage: https://github.com/sony/v8eval
|
94
93
|
licenses:
|
@@ -101,20 +100,19 @@ require_paths:
|
|
101
100
|
- ruby/ext
|
102
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
102
|
requirements:
|
104
|
-
- -
|
103
|
+
- - '>='
|
105
104
|
- !ruby/object:Gem::Version
|
106
105
|
version: 2.0.0
|
107
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
107
|
requirements:
|
109
|
-
- -
|
108
|
+
- - '>='
|
110
109
|
- !ruby/object:Gem::Version
|
111
110
|
version: '0'
|
112
111
|
requirements: []
|
113
112
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.0.14.1
|
115
114
|
signing_key:
|
116
115
|
specification_version: 4
|
117
|
-
summary: v8eval gem is ruby binding to the latest V8
|
118
|
-
|
116
|
+
summary: v8eval gem is ruby binding to the latest V8 and supports Linux and Mac OS
|
117
|
+
X.
|
119
118
|
test_files: []
|
120
|
-
has_rdoc:
|
data/src/dbgsrv.cxx
DELETED
@@ -1,211 +0,0 @@
|
|
1
|
-
#include "dbgsrv.h"
|
2
|
-
#include "v8eval.h"
|
3
|
-
|
4
|
-
namespace v8eval {
|
5
|
-
|
6
|
-
//
|
7
|
-
// DbgSrv
|
8
|
-
//
|
9
|
-
|
10
|
-
// container_of helper function
|
11
|
-
//
|
12
|
-
// libuv does not accept opaque values in its callbacks, so we have to
|
13
|
-
// recover the instance of the debug server (and associated v8 vm)
|
14
|
-
// through a C++ version of offsetof().
|
15
|
-
template<class A, class B, class C>
|
16
|
-
A* container_of(B* ptr, const C A::* member) {
|
17
|
-
size_t offset = (size_t) &(reinterpret_cast<A*>(0)->*member);
|
18
|
-
return (A*)((char *)ptr - offset);
|
19
|
-
}
|
20
|
-
|
21
|
-
DbgSrv::DbgSrv(_V8& v8) : v8_(v8) {
|
22
|
-
dbgsrv_port_ = 0;
|
23
|
-
uv_loop_init(&dbgsrv_loop_);
|
24
|
-
|
25
|
-
// Start up the Debugger Processing Loop
|
26
|
-
uv_loop_init(&dbgproc_loop_);
|
27
|
-
uv_async_init(&dbgproc_loop_, &dbgproc_proc_, dbgproc_do_proc);
|
28
|
-
uv_async_init(&dbgproc_loop_, &dbgproc_stop_, dbgproc_do_stop);
|
29
|
-
uv_thread_create(&dbgproc_thread_, dbgproc, this);
|
30
|
-
|
31
|
-
status_ = dbgsrv_offline;
|
32
|
-
}
|
33
|
-
|
34
|
-
DbgSrv::~DbgSrv() {
|
35
|
-
if (status_ != dbgsrv_offline) {
|
36
|
-
v8_.debugger_stop();
|
37
|
-
uv_async_send(&dbgsrv_stop_);
|
38
|
-
uv_thread_join(&dbgsrv_thread_);
|
39
|
-
}
|
40
|
-
uv_loop_close(&dbgsrv_loop_);
|
41
|
-
|
42
|
-
uv_async_send(&dbgproc_stop_);
|
43
|
-
uv_thread_join(&dbgproc_thread_);
|
44
|
-
uv_loop_close(&dbgproc_loop_);
|
45
|
-
}
|
46
|
-
|
47
|
-
static void end_write(uv_write_t *req, int status) {
|
48
|
-
if (status) {
|
49
|
-
fprintf(stderr, "write: %s\n", uv_strerror(status));
|
50
|
-
}
|
51
|
-
free(req);
|
52
|
-
}
|
53
|
-
|
54
|
-
void DbgSrv::dbgsrv_do_send(uv_async_t *async) {
|
55
|
-
DbgSrv *db = container_of(async, &DbgSrv::dbgsrv_send_);
|
56
|
-
uv_buf_t buf;
|
57
|
-
uv_write_t *wreq;
|
58
|
-
|
59
|
-
while (!db->msg_queue_.empty()) {
|
60
|
-
std::string& str = db->msg_queue_.back();
|
61
|
-
|
62
|
-
buf = uv_buf_init((char *)str.c_str(), (unsigned int)str.size());
|
63
|
-
wreq = (uv_write_t *)malloc(sizeof(*wreq));
|
64
|
-
uv_write(wreq, (uv_stream_t *)&db->dbgsrv_clnt_, &buf, 1, end_write);
|
65
|
-
db->msg_queue_.pop_back();
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
void DbgSrv::dbgsrv_do_clnt(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) {
|
70
|
-
DbgSrv *db = container_of(client, &DbgSrv::dbgsrv_clnt_);
|
71
|
-
|
72
|
-
if (nread == 0) return;
|
73
|
-
|
74
|
-
if (nread < 0) {
|
75
|
-
// Close the client
|
76
|
-
uv_close((uv_handle_t *)&db->dbgsrv_send_, NULL);
|
77
|
-
uv_close((uv_handle_t *)&db->dbgsrv_clnt_, NULL);
|
78
|
-
db->status_ = dbgsrv_started;
|
79
|
-
return;
|
80
|
-
}
|
81
|
-
|
82
|
-
const std::string string(buf->base, nread);
|
83
|
-
db->v8_.debugger_send(string);
|
84
|
-
free(buf->base);
|
85
|
-
|
86
|
-
uv_async_send(&db->dbgproc_proc_);
|
87
|
-
}
|
88
|
-
|
89
|
-
static void alloc_buffer(uv_handle_t *handle, size_t size, uv_buf_t *buf) {
|
90
|
-
buf->len = size;
|
91
|
-
buf->base = (char*) malloc(size);
|
92
|
-
}
|
93
|
-
|
94
|
-
void DbgSrv::dbgsrv_do_serv(uv_stream_t *server, int status) {
|
95
|
-
DbgSrv *db = container_of(server, &DbgSrv::dbgsrv_serv_);
|
96
|
-
|
97
|
-
if (status < 0) {
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
|
101
|
-
// Connect with the client.
|
102
|
-
uv_tcp_init(&db->dbgsrv_loop_, &db->dbgsrv_clnt_);
|
103
|
-
if (uv_accept(server, (uv_stream_t *)&db->dbgsrv_clnt_)) {
|
104
|
-
uv_close((uv_handle_t *)&db->dbgsrv_clnt_, NULL);
|
105
|
-
return;
|
106
|
-
}
|
107
|
-
|
108
|
-
// Setup async R/W callbacks.
|
109
|
-
uv_async_init(&db->dbgsrv_loop_, &db->dbgsrv_send_, dbgsrv_do_send);
|
110
|
-
uv_read_start((uv_stream_t *)&db->dbgsrv_clnt_, alloc_buffer, dbgsrv_do_clnt);
|
111
|
-
|
112
|
-
db->status_ = dbgsrv_connected;
|
113
|
-
}
|
114
|
-
|
115
|
-
void DbgSrv::dbgsrv_do_stop(uv_async_t *async) {
|
116
|
-
DbgSrv *db = container_of(async, &DbgSrv::dbgsrv_stop_);
|
117
|
-
|
118
|
-
// Stop Server Loop
|
119
|
-
if (db->status_ == dbgsrv_connected) {
|
120
|
-
uv_close((uv_handle_t *)&db->dbgsrv_send_, NULL);
|
121
|
-
uv_close((uv_handle_t *)&db->dbgsrv_clnt_, NULL);
|
122
|
-
db->status_ = dbgsrv_started;
|
123
|
-
}
|
124
|
-
if (db->status_ == dbgsrv_started) {
|
125
|
-
uv_close((uv_handle_t *)&db->dbgsrv_serv_, NULL);
|
126
|
-
uv_close((uv_handle_t *)&db->dbgsrv_stop_, NULL);
|
127
|
-
}
|
128
|
-
}
|
129
|
-
|
130
|
-
void DbgSrv::dbgsrv(void *ptr) {
|
131
|
-
DbgSrv *db = (DbgSrv*)ptr;
|
132
|
-
|
133
|
-
uv_run(&db->dbgsrv_loop_, UV_RUN_DEFAULT);
|
134
|
-
}
|
135
|
-
|
136
|
-
void DbgSrv::dbgproc_do_stop(uv_async_t *async) {
|
137
|
-
DbgSrv *db = container_of(async, &DbgSrv::dbgproc_stop_);
|
138
|
-
|
139
|
-
uv_close((uv_handle_t *)&db->dbgproc_proc_, NULL);
|
140
|
-
uv_close((uv_handle_t *)&db->dbgproc_stop_, NULL);
|
141
|
-
}
|
142
|
-
|
143
|
-
void DbgSrv::dbgproc_do_proc(uv_async_t *async) {
|
144
|
-
DbgSrv *db = container_of(async, &DbgSrv::dbgproc_proc_);
|
145
|
-
|
146
|
-
db->v8_.debugger_process();
|
147
|
-
}
|
148
|
-
|
149
|
-
void DbgSrv::dbgproc(void *ptr) {
|
150
|
-
DbgSrv *db = (DbgSrv*)ptr;
|
151
|
-
|
152
|
-
uv_run(&db->dbgproc_loop_, UV_RUN_DEFAULT);
|
153
|
-
}
|
154
|
-
|
155
|
-
void DbgSrv::recv_from_debugger(std::string& string, void *opq) {
|
156
|
-
DbgSrv *db = (DbgSrv *)opq;
|
157
|
-
|
158
|
-
db->msg_queue_.push_front(string);
|
159
|
-
uv_async_send(&db->dbgsrv_send_);
|
160
|
-
}
|
161
|
-
|
162
|
-
bool DbgSrv::start(int port) {
|
163
|
-
struct sockaddr_in addr;
|
164
|
-
|
165
|
-
if (status_ != dbgsrv_offline) {
|
166
|
-
return false;
|
167
|
-
}
|
168
|
-
|
169
|
-
if (port != (uint16_t)port) {
|
170
|
-
return false;
|
171
|
-
}
|
172
|
-
|
173
|
-
// Set up the TCP Connection.
|
174
|
-
uv_tcp_init(&dbgsrv_loop_, &dbgsrv_serv_);
|
175
|
-
uv_ip4_addr("0.0.0.0", port, &addr);
|
176
|
-
if (uv_tcp_bind(&dbgsrv_serv_, (const struct sockaddr*)&addr, 0)) {
|
177
|
-
uv_close((uv_handle_t *)&dbgsrv_serv_, NULL);
|
178
|
-
perror("bind");
|
179
|
-
return false;
|
180
|
-
}
|
181
|
-
|
182
|
-
if (port == 0) {
|
183
|
-
int addrlen = sizeof(addr);
|
184
|
-
if (uv_tcp_getsockname(&dbgsrv_serv_, (struct sockaddr*)&addr, &addrlen)) {
|
185
|
-
uv_close((uv_handle_t *)&dbgsrv_serv_, NULL);
|
186
|
-
perror("getsockname");
|
187
|
-
return false;
|
188
|
-
}
|
189
|
-
dbgsrv_port_ = ntohs(addr.sin_port);
|
190
|
-
} else {
|
191
|
-
dbgsrv_port_ = port;
|
192
|
-
}
|
193
|
-
|
194
|
-
if (uv_listen((uv_stream_t *)&dbgsrv_serv_, 0, dbgsrv_do_serv)) {
|
195
|
-
uv_close((uv_handle_t *)&dbgsrv_serv_, NULL);
|
196
|
-
perror("listen");
|
197
|
-
return false;
|
198
|
-
}
|
199
|
-
|
200
|
-
// Start V8 debugger
|
201
|
-
v8_.debugger_init(recv_from_debugger, this);
|
202
|
-
|
203
|
-
// Start the Debug Server Loop
|
204
|
-
uv_async_init(&dbgsrv_loop_, &dbgsrv_stop_, dbgsrv_do_stop);
|
205
|
-
uv_thread_create(&dbgsrv_thread_, dbgsrv, this);
|
206
|
-
|
207
|
-
status_ = dbgsrv_started;
|
208
|
-
return true;
|
209
|
-
}
|
210
|
-
|
211
|
-
} // namespace v8eval
|
data/src/dbgsrv.h
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
#ifndef DBGSRV_H_
|
2
|
-
#define DBGSRV_H_
|
3
|
-
|
4
|
-
#include "uv.h"
|
5
|
-
#include <string>
|
6
|
-
#include <list>
|
7
|
-
|
8
|
-
namespace v8eval {
|
9
|
-
|
10
|
-
class _V8;
|
11
|
-
|
12
|
-
/// \class DbgSrv
|
13
|
-
///
|
14
|
-
/// A debugger server is associated to a _V8 instance and accepts
|
15
|
-
/// TCP/IP connections to exchange messages in the V8 debugger
|
16
|
-
/// protocol.
|
17
|
-
class DbgSrv {
|
18
|
-
public:
|
19
|
-
DbgSrv(_V8& v8);
|
20
|
-
~DbgSrv();
|
21
|
-
|
22
|
-
/// \brief Starts a debugger server
|
23
|
-
/// \param port TCP/IP port the server will listen
|
24
|
-
/// \return success or not as boolean
|
25
|
-
///
|
26
|
-
/// The debugger server gets bound to 0.0.0.0:[port].
|
27
|
-
/// The port can be set to 0 to have a port automatically assigned.
|
28
|
-
bool start(int port);
|
29
|
-
|
30
|
-
/// \brief Get the TCP/IP port the system is currently listening from
|
31
|
-
/// \return A TCP/IP port or 0 if not currently set.
|
32
|
-
inline int get_port() { return dbgsrv_port_; }
|
33
|
-
|
34
|
-
private:
|
35
|
-
static void recv_from_debugger(std::string& string, void *opq);
|
36
|
-
|
37
|
-
static void dbgsrv_do_clnt(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf);
|
38
|
-
static void dbgsrv_do_send(uv_async_t *async);
|
39
|
-
static void dbgsrv_do_serv(uv_stream_t *server, int status);
|
40
|
-
static void dbgsrv_do_stop(uv_async_t *async);
|
41
|
-
static void dbgsrv(void *);
|
42
|
-
|
43
|
-
static void dbgproc_do_proc(uv_async_t *);
|
44
|
-
static void dbgproc_do_stop(uv_async_t *);
|
45
|
-
static void dbgproc(void *);
|
46
|
-
|
47
|
-
private:
|
48
|
-
_V8& v8_;
|
49
|
-
|
50
|
-
enum {
|
51
|
-
dbgsrv_offline,
|
52
|
-
dbgsrv_started,
|
53
|
-
dbgsrv_connected
|
54
|
-
} status_;
|
55
|
-
std::list<std::string> msg_queue_;
|
56
|
-
|
57
|
-
int dbgsrv_port_;
|
58
|
-
uv_tcp_t dbgsrv_serv_;
|
59
|
-
uv_tcp_t dbgsrv_clnt_;
|
60
|
-
uv_async_t dbgsrv_send_;
|
61
|
-
uv_async_t dbgsrv_stop_;
|
62
|
-
uv_thread_t dbgsrv_thread_;
|
63
|
-
uv_loop_t dbgsrv_loop_;
|
64
|
-
|
65
|
-
uv_async_t dbgproc_proc_;
|
66
|
-
uv_async_t dbgproc_stop_;
|
67
|
-
uv_thread_t dbgproc_thread_;
|
68
|
-
uv_loop_t dbgproc_loop_;
|
69
|
-
};
|
70
|
-
|
71
|
-
} // namespace v8eval
|
72
|
-
|
73
|
-
#endif // DBGSRV_H_
|