v8eval 0.2.2 → 0.2.3

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.
@@ -16,9 +16,10 @@ class BuildTool
16
16
 
17
17
  def run_swig
18
18
  system('cp ' + @v8eval_root + '/src/v8eval.h ' + @rb_ext_v8eval_dir)
19
+ system('cp ' + @v8eval_root + '/src/v8eval_ruby.h ' + @rb_ext_v8eval_dir)
19
20
  system('swig -c++ -ruby -autorename -outdir ' + @rb_ext_v8eval_dir +
20
- ' -o ' + @rb_ext_v8eval_dir + '/v8eval_wrap.cxx ' + @v8eval_root +
21
- '/src/v8eval.i')
21
+ ' -o ' + @rb_ext_v8eval_dir + '/v8eval_wrap.cxx ' + @rb_ext_v8eval_dir +
22
+ '/v8eval.i')
22
23
  end
23
24
 
24
25
  def build_ext
@@ -0,0 +1,261 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ Q1 = $(V:1=)
7
+ Q = $(Q1:0=@)
8
+ ECHO1 = $(V:1=@:)
9
+ ECHO = $(ECHO1:0=@echo)
10
+ NULLCMD = :
11
+
12
+ #### Start of system configuration section. ####
13
+
14
+ srcdir = .
15
+ topdir = /usr/local/Cellar/ruby/2.3.0/include/ruby-2.3.0
16
+ hdrdir = $(topdir)
17
+ arch_hdrdir = /usr/local/Cellar/ruby/2.3.0/include/ruby-2.3.0/x86_64-darwin15
18
+ PATH_SEPARATOR = :
19
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
20
+ prefix = $(DESTDIR)/usr/local/Cellar/ruby/2.3.0
21
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
22
+ rubyarchprefix = $(rubylibprefix)/$(arch)
23
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
24
+ exec_prefix = $(prefix)
25
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
26
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
27
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
28
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
29
+ sitehdrdir = $(rubyhdrdir)/site_ruby
30
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
31
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
32
+ vendorlibdir = $(vendordir)/$(ruby_version)
33
+ vendordir = $(DESTDIR)/usr/local/lib/ruby/vendor_ruby
34
+ sitearchdir = $(sitelibdir)/$(sitearch)
35
+ sitelibdir = $(sitedir)/$(ruby_version)
36
+ sitedir = $(DESTDIR)/usr/local/lib/ruby/site_ruby
37
+ rubyarchdir = $(rubylibdir)/$(arch)
38
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
39
+ sitearchincludedir = $(includedir)/$(sitearch)
40
+ archincludedir = $(includedir)/$(arch)
41
+ sitearchlibdir = $(libdir)/$(sitearch)
42
+ archlibdir = $(libdir)/$(arch)
43
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
44
+ mandir = $(datarootdir)/man
45
+ localedir = $(datarootdir)/locale
46
+ libdir = $(exec_prefix)/lib
47
+ psdir = $(docdir)
48
+ pdfdir = $(docdir)
49
+ dvidir = $(docdir)
50
+ htmldir = $(docdir)
51
+ infodir = $(datarootdir)/info
52
+ docdir = $(datarootdir)/doc/$(PACKAGE)
53
+ oldincludedir = $(DESTDIR)/usr/include
54
+ includedir = $(prefix)/include
55
+ localstatedir = $(prefix)/var
56
+ sharedstatedir = $(prefix)/com
57
+ sysconfdir = $(prefix)/etc
58
+ datadir = $(datarootdir)
59
+ datarootdir = $(prefix)/share
60
+ libexecdir = $(exec_prefix)/libexec
61
+ sbindir = $(exec_prefix)/sbin
62
+ bindir = $(exec_prefix)/bin
63
+ archdir = $(rubyarchdir)
64
+
65
+
66
+ CC = clang
67
+ CXX = clang++
68
+ LIBRUBY = $(LIBRUBY_SO)
69
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
70
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
71
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework CoreFoundation
72
+ empty =
73
+ OUTFLAG = -o $(empty)
74
+ COUTFLAG = -o $(empty)
75
+
76
+ RUBY_EXTCONF_H =
77
+ cflags = $(optflags) $(debugflags) $(warnflags)
78
+ cxxflags = $(optflags) $(debugflags) $(warnflags)
79
+ optflags = -O3 -fno-fast-math
80
+ debugflags = -ggdb3
81
+ warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens
82
+ CCDLFLAGS = -fno-common
83
+ CFLAGS = $(CCDLFLAGS) $(cflags) -fno-common -pipe $(ARCH_FLAG)
84
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
85
+ DEFS =
86
+ CPPFLAGS = -I/Users/prateekpapriwal/gocodes/src/github.com/sony/v8eval/v8 -I/Users/prateekpapriwal/gocodes/src/github.com/sony/v8eval/v8/include -I/Users/prateekpapriwal/gocodes/src/github.com/sony/v8eval/uv/include -I/usr/local/Cellar/ruby/2.3.0/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/openssl/include -I/usr/local/opt/readline/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags) -g -O3 -std=c++11
87
+ CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG)
88
+ ldflags = -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -lv8eval -lv8_libplatform -lv8_base -lv8_libbase -lv8_nosnapshot -licui18n -licuuc -licudata -luv
89
+ dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib
90
+ ARCH_FLAG =
91
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
92
+ LDSHARED = $(CC) -dynamic -bundle
93
+ LDSHAREDXX = $(CXX) -dynamic -bundle
94
+ AR = ar
95
+ EXEEXT =
96
+
97
+ RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
98
+ RUBY_SO_NAME = ruby.2.3.0
99
+ RUBYW_INSTALL_NAME =
100
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
101
+ RUBYW_BASE_NAME = rubyw
102
+ RUBY_BASE_NAME = ruby
103
+
104
+ arch = x86_64-darwin15
105
+ sitearch = $(arch)
106
+ ruby_version = 2.3.0
107
+ ruby = $(bindir)/$(RUBY_BASE_NAME)
108
+ RUBY = $(ruby)
109
+ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
110
+
111
+ RM = rm -f
112
+ RM_RF = $(RUBY) -run -e rm -- -rf
113
+ RMDIRS = rmdir -p
114
+ MAKEDIRS = mkdir -p
115
+ INSTALL = /usr/bin/install -c
116
+ INSTALL_PROG = $(INSTALL) -m 0755
117
+ INSTALL_DATA = $(INSTALL) -m 644
118
+ COPY = cp
119
+ TOUCH = exit >
120
+
121
+ #### End of system configuration section. ####
122
+
123
+ preload =
124
+
125
+ libpath = . $(libdir) /Users/prateekpapriwal/gocodes/src/github.com/sony/v8eval/build /Users/prateekpapriwal/gocodes/src/github.com/sony/v8eval/uv/.libs /usr/local/Cellar/ruby/2.3.0/lib /Users/prateekpapriwal/gocodes/src/github.com/sony/v8eval/v8/out/x64.release /usr/local/opt/libyaml/lib /usr/local/opt/openssl/lib /usr/local/opt/readline/lib
126
+ LIBPATH = -L. -L$(libdir) -L/Users/prateekpapriwal/gocodes/src/github.com/sony/v8eval/build -L/Users/prateekpapriwal/gocodes/src/github.com/sony/v8eval/uv/.libs -L/usr/local/Cellar/ruby/2.3.0/lib -L/Users/prateekpapriwal/gocodes/src/github.com/sony/v8eval/v8/out/x64.release -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib
127
+ DEFFILE =
128
+
129
+ CLEANFILES = mkmf.log
130
+ DISTCLEANFILES =
131
+ DISTCLEANDIRS =
132
+
133
+ extout =
134
+ extout_prefix =
135
+ target_prefix = /v8eval
136
+ LOCAL_LIBS =
137
+ LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lobjc
138
+ ORIG_SRCS = v8eval_wrap.cxx
139
+ SRCS = $(ORIG_SRCS)
140
+ OBJS = v8eval_wrap.o
141
+ HDRS = $(srcdir)/v8eval.h
142
+ TARGET = v8eval
143
+ TARGET_NAME = v8eval
144
+ TARGET_ENTRY = Init_$(TARGET_NAME)
145
+ DLLIB = $(TARGET).bundle
146
+ EXTSTATIC =
147
+ STATIC_LIB =
148
+
149
+ TIMESTAMP_DIR = .
150
+ BINDIR = $(bindir)
151
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
152
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
153
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
154
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
155
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
156
+
157
+ TARGET_SO = $(DLLIB)
158
+ CLEANLIBS = $(TARGET).bundle
159
+ CLEANOBJS = *.o *.bak
160
+
161
+ all: $(DLLIB)
162
+ static: $(STATIC_LIB) install-rb
163
+ .PHONY: all install static install-so install-rb
164
+ .PHONY: clean clean-so clean-static clean-rb
165
+
166
+ clean-static::
167
+ clean-rb-default::
168
+ clean-rb::
169
+ clean-so::
170
+ clean: clean-so clean-static clean-rb-default clean-rb
171
+ -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
172
+
173
+ distclean-rb-default::
174
+ distclean-rb::
175
+ distclean-so::
176
+ distclean-static::
177
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
178
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
179
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
180
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
181
+
182
+ realclean: distclean
183
+ install: install-so install-rb
184
+
185
+ install-so: $(DLLIB) $(TIMESTAMP_DIR)/.RUBYARCHDIR.-.v8eval.time
186
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
187
+ clean-static::
188
+ -$(Q)$(RM) $(STATIC_LIB)
189
+ install-rb: pre-install-rb install-rb-default
190
+ install-rb-default: pre-install-rb-default
191
+ pre-install-rb: Makefile
192
+ pre-install-rb-default: Makefile
193
+ pre-install-rb-default:
194
+ @$(NULLCMD)
195
+ $(TIMESTAMP_DIR)/.RUBYARCHDIR.-.v8eval.time:
196
+ $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
197
+ $(Q) $(TOUCH) $@
198
+
199
+ site-install: site-install-so site-install-rb
200
+ site-install-so: install-so
201
+ site-install-rb: install-rb
202
+
203
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S
204
+
205
+ .cc.o:
206
+ $(ECHO) compiling $(<)
207
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
208
+
209
+ .cc.S:
210
+ $(ECHO) translating $(<)
211
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
212
+
213
+ .mm.o:
214
+ $(ECHO) compiling $(<)
215
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
216
+
217
+ .mm.S:
218
+ $(ECHO) translating $(<)
219
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
220
+
221
+ .cxx.o:
222
+ $(ECHO) compiling $(<)
223
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
224
+
225
+ .cxx.S:
226
+ $(ECHO) translating $(<)
227
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
228
+
229
+ .cpp.o:
230
+ $(ECHO) compiling $(<)
231
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
232
+
233
+ .cpp.S:
234
+ $(ECHO) translating $(<)
235
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $<
236
+
237
+ .c.o:
238
+ $(ECHO) compiling $(<)
239
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
240
+
241
+ .c.S:
242
+ $(ECHO) translating $(<)
243
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $<
244
+
245
+ .m.o:
246
+ $(ECHO) compiling $(<)
247
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
248
+
249
+ .m.S:
250
+ $(ECHO) translating $(<)
251
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $<
252
+
253
+ $(DLLIB): $(OBJS) Makefile
254
+ $(ECHO) linking shared-object v8eval/$(DLLIB)
255
+ -$(Q)$(RM) $(@)
256
+ $(Q) $(LDSHAREDXX) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
257
+ $(Q) $(POSTLINK)
258
+
259
+
260
+
261
+ $(OBJS): $(HDRS) $(ruby_headers)
@@ -0,0 +1,55 @@
1
+ # extconf.rb
2
+ require 'rbconfig'
3
+ require 'mkmf'
4
+ require_relative '../../lib/setup/extension_builder'
5
+
6
+ # set path variables
7
+ v8eval_root = File.expand_path('../../..', Dir.pwd)
8
+ v8_dir = v8eval_root + '/v8'
9
+ uv_dir = v8eval_root + '/uv'
10
+
11
+ # make instance of BuildTool class
12
+ tool = BuildTool.new(v8eval_root)
13
+
14
+ # install v8 and build libv8eval.a
15
+ tool.install_v8
16
+
17
+ # generate v8eval_wrap.cxx
18
+ tool.run_swig
19
+
20
+ LIBDIR = RbConfig::CONFIG['libdir']
21
+ INCLUDEDIR = RbConfig::CONFIG['includedir']
22
+
23
+ header_dirs = [
24
+ v8_dir,
25
+ v8_dir + '/include',
26
+ uv_dir + '/include',
27
+ INCLUDEDIR
28
+ ]
29
+
30
+ lib_dirs = [
31
+ v8eval_root + '/build',
32
+ uv_dir + '/.libs',
33
+ LIBDIR
34
+ ]
35
+
36
+ if RUBY_PLATFORM =~ /darwin/
37
+ lib_dirs += [
38
+ v8_dir + '/out/x64.release'
39
+ ]
40
+ elsif RUBY_PLATFORM =~ /linux/
41
+ lib_dirs += [
42
+ v8_dir + '/out/x64.release/obj.target/tools/gyp',
43
+ v8_dir + '/out/x64.release/obj.target/third_party/icu'
44
+ ]
45
+
46
+ RbConfig::MAKEFILE_CONFIG['CC'] = v8_dir + '/third_party/llvm-build/Release+Asserts/bin/clang'
47
+ RbConfig::MAKEFILE_CONFIG['CXX'] = v8_dir + '/third_party/llvm-build/Release+Asserts/bin/clang++'
48
+ end
49
+
50
+ dir_config('', header_dirs, lib_dirs)
51
+
52
+ $LDFLAGS << ' -lv8eval -lv8_libplatform -lv8_base -lv8_libbase -lv8_nosnapshot -licui18n -licuuc -licudata -luv'
53
+ $CPPFLAGS << ' -g -O3 -std=c++11'
54
+
55
+ create_makefile('v8eval/v8eval')
@@ -0,0 +1,99 @@
1
+ #ifndef V8EVAL_H_
2
+ #define V8EVAL_H_
3
+
4
+ #include <string>
5
+
6
+ #include "v8.h"
7
+ #include "v8-debug.h"
8
+
9
+ /// \file
10
+ namespace v8eval {
11
+
12
+ class DbgSrv;
13
+
14
+ typedef void (*debugger_cb)(std::string&, void *opq);
15
+
16
+ /// \brief Initialize the V8 runtime environment
17
+ /// \return success or not as boolean
18
+ ///
19
+ /// This method initializes the V8 runtime environment. It must be called before creating any V8 instance.
20
+ bool initialize();
21
+
22
+ /// \brief Dispose the V8 runtime environment
23
+ /// \return success or not as boolean
24
+ ///
25
+ /// This method disposes the V8 runtime environment.
26
+ bool dispose();
27
+
28
+ /// \class _V8
29
+ ///
30
+ /// _V8 instances can be used in multiple threads.
31
+ /// But each _V8 instance can be used in only one thread at a time.
32
+ class _V8 {
33
+ public:
34
+ _V8();
35
+ virtual ~_V8();
36
+
37
+ /// \brief Evaluate JavaScript code
38
+ /// \param src JavaScript code
39
+ /// \return JSON-encoded result or exception message
40
+ ///
41
+ /// This method evaluates the given JavaScript code 'src' and returns the result in JSON.
42
+ /// If some JavaScript exception happens in runtime, the exception message is returned.
43
+ std::string eval(const std::string& src);
44
+
45
+ /// \brief Call a JavaScript function
46
+ /// \param func Name of a JavaScript function
47
+ /// \param args JSON-encoded argument array
48
+ /// \return JSON-encoded result or exception message
49
+ ///
50
+ /// This method calls the JavaScript function specified by 'func'
51
+ /// with the JSON-encoded argument array 'args'
52
+ /// and returns the result in JSON.
53
+ /// If some JavaScript exception happens in runtime, the exception message is returned.
54
+ std::string call(const std::string& func, const std::string& args);
55
+
56
+ /// \brief Start a debug server associated with the V8 instance
57
+ /// \param port The TCP/IP port the debugger will listen, at localhost
58
+ /// \return success or not as boolean
59
+ ///
60
+ /// After the debugger is successfully started, it will be possible to
61
+ /// send commands and receive events at the specified port. When the
62
+ /// debugger is started, the Javascript's "debugger" statement will
63
+ /// cause the V8 instance to halt and wait for instructions through
64
+ /// the debugger port.
65
+ bool enable_debugger(int port);
66
+
67
+ /// \brief Stop the debug server, if running.
68
+ ///
69
+ /// The debug server, if currently running, will be stopped, causing
70
+ /// connections to remote debuggers to be dropped.
71
+ void disable_debugger();
72
+
73
+ private:
74
+ static void debugger_message_handler(const v8::Debug::Message& message);
75
+ v8::Local<v8::Context> new_context();
76
+ v8::Local<v8::String> new_string(const char* str);
77
+ v8::Local<v8::Value> json_parse(v8::Local<v8::Context> context, v8::Local<v8::String> str);
78
+ v8::Local<v8::String> json_stringify(v8::Local<v8::Context> context, v8::Local<v8::Value> value);
79
+
80
+ bool debugger_init(debugger_cb cb, void *cbopq);
81
+ bool debugger_send(const std::string& cmd);
82
+ void debugger_process();
83
+ void debugger_stop();
84
+
85
+ private:
86
+ v8::Isolate* isolate_;
87
+ v8::Persistent<v8::Context> context_;
88
+
89
+ DbgSrv* dbg_server_;
90
+ v8::Isolate* dbg_isolate_;
91
+ debugger_cb callback_;
92
+ void* callback_opq_;
93
+
94
+ friend class DbgSrv;
95
+ };
96
+
97
+ } // namespace v8eval
98
+
99
+ #endif // V8EVAL_H_