Merge lp:~marcustomlinson/v8-cpp/v8runner into lp:v8-cpp
- v8runner
- Merge into trunk
Proposed by
Marcus Tomlinson
Status: | Merged |
---|---|
Merged at revision: | 11 |
Proposed branch: | lp:~marcustomlinson/v8-cpp/v8runner |
Merge into: | lp:v8-cpp |
Diff against target: |
491 lines (+360/-14) 12 files modified
.bzrignore (+4/-0) CMakeLists.txt (+5/-3) deps/build-deps.sh (+30/-0) src/CMakeLists.txt (+24/-3) src/internal/require.h (+137/-0) src/module.h (+23/-5) src/run.h (+95/-0) src/v8-cpp.h (+1/-0) test/CMakeLists.txt (+7/-3) test/addon.cpp (+1/-0) v8runner/CMakeLists.txt (+9/-0) v8runner/v8runner.cpp (+24/-0) |
To merge this branch: | bzr merge lp:~marcustomlinson/v8-cpp/v8runner |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marcus Tomlinson | Pending | ||
Review via email: mp+263641@code.launchpad.net |
Commit message
Added v8runner executable that runs a JS script and supports the "require()" keyword to load in V8 (incl. Node) modules.
Description of the change
To post a comment you must log in.
- 33. By Marcus Tomlinson
-
Retrieve dependencies on build rather than cmake
- 34. By Marcus Tomlinson
-
Oops, fixed v8cpp_script_path_
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2015-06-10 05:57:04 +0000 | |||
3 | +++ .bzrignore 2015-07-02 11:58:46 +0000 | |||
4 | @@ -1,1 +1,5 @@ | |||
5 | 1 | ./CMakeLists.txt.user | 1 | ./CMakeLists.txt.user |
6 | 2 | ./deps/.gclient | ||
7 | 3 | ./deps/.gclient_entries | ||
8 | 4 | ./deps/depot_tools | ||
9 | 5 | ./deps/v8 | ||
10 | 2 | 6 | ||
11 | === modified file 'CMakeLists.txt' | |||
12 | --- CMakeLists.txt 2015-06-10 06:20:49 +0000 | |||
13 | +++ CMakeLists.txt 2015-07-02 11:58:46 +0000 | |||
14 | @@ -13,12 +13,14 @@ | |||
15 | 13 | -fPIC | 13 | -fPIC |
16 | 14 | ) | 14 | ) |
17 | 15 | 15 | ||
18 | 16 | find_package(Node REQUIRED) | ||
19 | 17 | |||
20 | 18 | include_directories( | 16 | include_directories( |
21 | 19 | ${NODE_INCLUDE_DIRS} | ||
22 | 20 | ${CMAKE_CURRENT_SOURCE_DIR}/src | 17 | ${CMAKE_CURRENT_SOURCE_DIR}/src |
23 | 18 | ${CMAKE_CURRENT_SOURCE_DIR}/deps/v8/include | ||
24 | 19 | ) | ||
25 | 20 | link_directories( | ||
26 | 21 | ${CMAKE_CURRENT_SOURCE_DIR}/deps/v8/out/native/obj.target/tools/gyp | ||
27 | 21 | ) | 22 | ) |
28 | 22 | 23 | ||
29 | 23 | add_subdirectory(src) | 24 | add_subdirectory(src) |
30 | 24 | add_subdirectory(test) | 25 | add_subdirectory(test) |
31 | 26 | add_subdirectory(v8runner) | ||
32 | 25 | 27 | ||
33 | === added directory 'deps' | |||
34 | === added file 'deps/build-deps.sh' | |||
35 | --- deps/build-deps.sh 1970-01-01 00:00:00 +0000 | |||
36 | +++ deps/build-deps.sh 2015-07-02 11:58:46 +0000 | |||
37 | @@ -0,0 +1,30 @@ | |||
38 | 1 | #!/bin/bash | ||
39 | 2 | |||
40 | 3 | DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]})) | ||
41 | 4 | |||
42 | 5 | cd $DIR | ||
43 | 6 | |||
44 | 7 | if ! [ -d "depot_tools" ]; then | ||
45 | 8 | git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git | ||
46 | 9 | fi | ||
47 | 10 | |||
48 | 11 | if ! [ -d "v8" ]; then | ||
49 | 12 | git clone --depth 1 --branch 3.28.73 https://chromium.googlesource.com/v8/v8.git | ||
50 | 13 | fi | ||
51 | 14 | |||
52 | 15 | export PATH=./depot_tools:"$PATH" | ||
53 | 16 | gclient config --spec 'solutions = [ | ||
54 | 17 | { "name" : "v8", | ||
55 | 18 | "url" : "https://chromium.googlesource.com/v8/v8.git", | ||
56 | 19 | "deps_file" : "DEPS", | ||
57 | 20 | "managed" : False, | ||
58 | 21 | "custom_deps" : { | ||
59 | 22 | }, | ||
60 | 23 | "safesync_url": "", | ||
61 | 24 | }, | ||
62 | 25 | ] | ||
63 | 26 | cache_dir = None' | ||
64 | 27 | gclient sync | ||
65 | 28 | |||
66 | 29 | cd v8 | ||
67 | 30 | make -j3 native i18nsupport=off | ||
68 | 0 | 31 | ||
69 | === modified file 'src/CMakeLists.txt' | |||
70 | --- src/CMakeLists.txt 2015-06-10 05:57:04 +0000 | |||
71 | +++ src/CMakeLists.txt 2015-07-02 11:58:46 +0000 | |||
72 | @@ -4,7 +4,28 @@ | |||
73 | 4 | *.h | 4 | *.h |
74 | 5 | ) | 5 | ) |
75 | 6 | 6 | ||
79 | 7 | add_custom_target( | 7 | add_library( |
80 | 8 | source_files | 8 | v8-cpp SHARED |
81 | 9 | SOURCES ${SRC_FILES} | 9 | ${SRC_FILES} |
82 | 10 | ) | ||
83 | 11 | |||
84 | 12 | set_target_properties( | ||
85 | 13 | v8-cpp PROPERTIES | ||
86 | 14 | LINKER_LANGUAGE CXX | ||
87 | 15 | ) | ||
88 | 16 | |||
89 | 17 | target_link_libraries( | ||
90 | 18 | v8-cpp | ||
91 | 19 | |||
92 | 20 | v8_base | ||
93 | 21 | v8_libbase | ||
94 | 22 | v8_snapshot | ||
95 | 23 | |||
96 | 24 | dl | ||
97 | 25 | pthread | ||
98 | 26 | ) | ||
99 | 27 | |||
100 | 28 | add_custom_command( | ||
101 | 29 | TARGET v8-cpp PRE_LINK | ||
102 | 30 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../deps/build-deps.sh | ||
103 | 10 | ) | 31 | ) |
104 | 11 | 32 | ||
105 | === added file 'src/internal/require.h' | |||
106 | --- src/internal/require.h 1970-01-01 00:00:00 +0000 | |||
107 | +++ src/internal/require.h 2015-07-02 11:58:46 +0000 | |||
108 | @@ -0,0 +1,137 @@ | |||
109 | 1 | /* | ||
110 | 2 | * Copyright (C) 2015 Canonical Ltd | ||
111 | 3 | * | ||
112 | 4 | * This program is free software: you can redistribute it and/or modify | ||
113 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
114 | 6 | * published by the Free Software Foundation. | ||
115 | 7 | * | ||
116 | 8 | * This program is distributed in the hope that it will be useful, | ||
117 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
118 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
119 | 11 | * GNU Lesser General Public License for more details. | ||
120 | 12 | * | ||
121 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
122 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
123 | 15 | * | ||
124 | 16 | * Authored by: Marcus Tomlinson <marcus.tomlinson@canonical.com> | ||
125 | 17 | */ | ||
126 | 18 | |||
127 | 19 | #pragma once | ||
128 | 20 | |||
129 | 21 | #include <dlfcn.h> | ||
130 | 22 | #include <iostream> | ||
131 | 23 | |||
132 | 24 | namespace v8cpp | ||
133 | 25 | { | ||
134 | 26 | namespace internal | ||
135 | 27 | { | ||
136 | 28 | |||
137 | 29 | using ModuleInitFunc = void(v8::Handle<v8::Object> exports); | ||
138 | 30 | ModuleInitFunc* node_init_func_; | ||
139 | 31 | std::string v8cpp_script_path_; | ||
140 | 32 | |||
141 | 33 | struct NodeModule | ||
142 | 34 | { | ||
143 | 35 | int nm_version; | ||
144 | 36 | unsigned int nm_flags; | ||
145 | 37 | void* nm_dso_handle; | ||
146 | 38 | const char* nm_filename; | ||
147 | 39 | ModuleInitFunc* nm_register_func; | ||
148 | 40 | //... | ||
149 | 41 | }; | ||
150 | 42 | |||
151 | 43 | extern "C" void node_module_register(void* m) | ||
152 | 44 | { | ||
153 | 45 | auto mp = static_cast<NodeModule*>(m); | ||
154 | 46 | |||
155 | 47 | // For now we only know that version 14 works here | ||
156 | 48 | if (mp->nm_version == 14) | ||
157 | 49 | { | ||
158 | 50 | node_init_func_ = mp->nm_register_func; | ||
159 | 51 | } | ||
160 | 52 | else | ||
161 | 53 | { | ||
162 | 54 | std::cerr << "node_module_register(): ignoring node module. nm_version " << mp->nm_version << " not supported" | ||
163 | 55 | << std::endl; | ||
164 | 56 | } | ||
165 | 57 | } | ||
166 | 58 | |||
167 | 59 | class Console | ||
168 | 60 | { | ||
169 | 61 | public: | ||
170 | 62 | inline static void log(v8::FunctionCallbackInfo<v8::Value> const& args) | ||
171 | 63 | { | ||
172 | 64 | for (int i = 0; i < args.Length(); ++i) | ||
173 | 65 | { | ||
174 | 66 | if (args[i]->IsInt32()) | ||
175 | 67 | { | ||
176 | 68 | std::cout << v8cpp::from_v8<int>(v8::Isolate::GetCurrent(), args[i]) << std::endl; | ||
177 | 69 | } | ||
178 | 70 | if (args[i]->IsUint32()) | ||
179 | 71 | { | ||
180 | 72 | std::cout << v8cpp::from_v8<unsigned int>(v8::Isolate::GetCurrent(), args[i]) << std::endl; | ||
181 | 73 | } | ||
182 | 74 | else if (args[i]->IsNumber()) | ||
183 | 75 | { | ||
184 | 76 | std::cout << v8cpp::from_v8<float>(v8::Isolate::GetCurrent(), args[i]) << std::endl; | ||
185 | 77 | } | ||
186 | 78 | else if (args[i]->IsBoolean()) | ||
187 | 79 | { | ||
188 | 80 | std::cout << v8cpp::from_v8<bool>(v8::Isolate::GetCurrent(), args[i]) << std::endl; | ||
189 | 81 | } | ||
190 | 82 | else if (args[i]->IsString()) | ||
191 | 83 | { | ||
192 | 84 | std::cout << v8cpp::from_v8<std::string>(v8::Isolate::GetCurrent(), args[i]) << std::endl; | ||
193 | 85 | } | ||
194 | 86 | } | ||
195 | 87 | std::cout.flush(); | ||
196 | 88 | } | ||
197 | 89 | }; | ||
198 | 90 | |||
199 | 91 | inline v8::Local<v8::Object> require(std::string const& module_path) | ||
200 | 92 | { | ||
201 | 93 | node_init_func_ = nullptr; | ||
202 | 94 | v8::Local<v8::Object> exports = v8::Object::New(v8::Isolate::GetCurrent()); | ||
203 | 95 | |||
204 | 96 | // Try append ".node" to module_path | ||
205 | 97 | std::string suffixed_module_path = v8cpp_script_path_ + module_path + ".node"; | ||
206 | 98 | auto module = dlopen(suffixed_module_path.c_str(), RTLD_LAZY); | ||
207 | 99 | if (!module) | ||
208 | 100 | { | ||
209 | 101 | // Didn't work, now try append ".so" to module_path | ||
210 | 102 | suffixed_module_path = v8cpp_script_path_ + module_path + ".so"; | ||
211 | 103 | module = dlopen(suffixed_module_path.c_str(), RTLD_LAZY); | ||
212 | 104 | if (!module) | ||
213 | 105 | { | ||
214 | 106 | // Still didn't work, just try module_path as is | ||
215 | 107 | suffixed_module_path = v8cpp_script_path_ + module_path; | ||
216 | 108 | module = dlopen(suffixed_module_path.c_str(), RTLD_LAZY); | ||
217 | 109 | if (!module) | ||
218 | 110 | { | ||
219 | 111 | std::cerr << "dlopen failed: " << dlerror() << std::endl; | ||
220 | 112 | return exports; | ||
221 | 113 | } | ||
222 | 114 | } | ||
223 | 115 | } | ||
224 | 116 | |||
225 | 117 | if (node_init_func_) | ||
226 | 118 | { | ||
227 | 119 | node_init_func_(exports); | ||
228 | 120 | } | ||
229 | 121 | else | ||
230 | 122 | { | ||
231 | 123 | auto v8cpp_init_func = (ModuleInitFunc*)dlsym(module, "init_module"); | ||
232 | 124 | if (!v8cpp_init_func) | ||
233 | 125 | { | ||
234 | 126 | std::cerr << "dlsym failed: " << dlerror() << std::endl; | ||
235 | 127 | return exports; | ||
236 | 128 | } | ||
237 | 129 | |||
238 | 130 | v8cpp_init_func(exports); | ||
239 | 131 | } | ||
240 | 132 | |||
241 | 133 | return exports; | ||
242 | 134 | } | ||
243 | 135 | |||
244 | 136 | } // namespace internal | ||
245 | 137 | } // namespace v8cpp | ||
246 | 0 | 138 | ||
247 | === modified file 'src/module.h' | |||
248 | --- src/module.h 2015-06-11 05:51:30 +0000 | |||
249 | +++ src/module.h 2015-07-02 11:58:46 +0000 | |||
250 | @@ -32,7 +32,7 @@ | |||
251 | 32 | public: | 32 | public: |
252 | 33 | explicit Module(v8::Isolate* isolate) | 33 | explicit Module(v8::Isolate* isolate) |
253 | 34 | : isolate_(isolate) | 34 | : isolate_(isolate) |
255 | 35 | , object_(v8::ObjectTemplate::New(isolate)) | 35 | , object_template_(v8::ObjectTemplate::New(isolate)) |
256 | 36 | { | 36 | { |
257 | 37 | } | 37 | } |
258 | 38 | 38 | ||
259 | @@ -40,7 +40,7 @@ | |||
260 | 40 | template <typename T> | 40 | template <typename T> |
261 | 41 | Module& add_class(char const* name, Class<T>& cl) | 41 | Module& add_class(char const* name, Class<T>& cl) |
262 | 42 | { | 42 | { |
264 | 43 | object_->Set(to_v8(isolate_, name), cl.class_.proto_template()->GetFunction()); | 43 | object_template_->Set(to_v8(isolate_, name), cl.class_.proto_template()->GetFunction()); |
265 | 44 | return *this; | 44 | return *this; |
266 | 45 | } | 45 | } |
267 | 46 | 46 | ||
268 | @@ -48,19 +48,37 @@ | |||
269 | 48 | template <typename F> | 48 | template <typename F> |
270 | 49 | Module& add_function(char const* name, F func) | 49 | Module& add_function(char const* name, F func) |
271 | 50 | { | 50 | { |
273 | 51 | object_->Set(to_v8(isolate_, name), internal::export_function(isolate_, func)); | 51 | object_template_->Set(to_v8(isolate_, name), internal::export_function(isolate_, func)); |
274 | 52 | return *this; | 52 | return *this; |
275 | 53 | } | 53 | } |
276 | 54 | 54 | ||
277 | 55 | // Create an instance of this module in V8 | 55 | // Create an instance of this module in V8 |
278 | 56 | v8::Local<v8::Object> create_prototype() | 56 | v8::Local<v8::Object> create_prototype() |
279 | 57 | { | 57 | { |
281 | 58 | return object_->NewInstance(); | 58 | return object_template_->NewInstance(); |
282 | 59 | } | ||
283 | 60 | |||
284 | 61 | v8::Handle<v8::ObjectTemplate> object_template() | ||
285 | 62 | { | ||
286 | 63 | return object_template_; | ||
287 | 59 | } | 64 | } |
288 | 60 | 65 | ||
289 | 61 | private: | 66 | private: |
290 | 62 | v8::Isolate* isolate_; | 67 | v8::Isolate* isolate_; |
292 | 63 | v8::Handle<v8::ObjectTemplate> object_; | 68 | v8::Handle<v8::ObjectTemplate> object_template_; |
293 | 64 | }; | 69 | }; |
294 | 65 | 70 | ||
295 | 71 | // Create a V8-cpp module by exposing it's init function | ||
296 | 72 | #define V8CPP_MODULE(module_name, init_func)\ | ||
297 | 73 | extern "C"\ | ||
298 | 74 | {\ | ||
299 | 75 | namespace v8cpp\ | ||
300 | 76 | {\ | ||
301 | 77 | void init_module(Handle<Object> exports)\ | ||
302 | 78 | {\ | ||
303 | 79 | init_func(exports);\ | ||
304 | 80 | }\ | ||
305 | 81 | }\ | ||
306 | 82 | } | ||
307 | 83 | |||
308 | 66 | } // namespace v8cpp | 84 | } // namespace v8cpp |
309 | 67 | 85 | ||
310 | === added file 'src/run.h' | |||
311 | --- src/run.h 1970-01-01 00:00:00 +0000 | |||
312 | +++ src/run.h 2015-07-02 11:58:46 +0000 | |||
313 | @@ -0,0 +1,95 @@ | |||
314 | 1 | /* | ||
315 | 2 | * Copyright (C) 2015 Canonical Ltd | ||
316 | 3 | * | ||
317 | 4 | * This program is free software: you can redistribute it and/or modify | ||
318 | 5 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
319 | 6 | * published by the Free Software Foundation. | ||
320 | 7 | * | ||
321 | 8 | * This program is distributed in the hope that it will be useful, | ||
322 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
323 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
324 | 11 | * GNU Lesser General Public License for more details. | ||
325 | 12 | * | ||
326 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
327 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
328 | 15 | * | ||
329 | 16 | * Authored by: Marcus Tomlinson <marcus.tomlinson@canonical.com> | ||
330 | 17 | */ | ||
331 | 18 | |||
332 | 19 | #pragma once | ||
333 | 20 | |||
334 | 21 | #include <internal/require.h> | ||
335 | 22 | |||
336 | 23 | #include <fstream> | ||
337 | 24 | |||
338 | 25 | namespace v8cpp | ||
339 | 26 | { | ||
340 | 27 | |||
341 | 28 | template <typename T = v8::Handle<v8::Value>> | ||
342 | 29 | T run_script(v8::Isolate* isolate, std::string const& source, std::string const& filename = "") | ||
343 | 30 | { | ||
344 | 31 | // Create an isolate scope. | ||
345 | 32 | v8::Isolate::Scope isolate_scope(isolate); | ||
346 | 33 | |||
347 | 34 | // Create a stack-allocated handle scope. | ||
348 | 35 | v8::HandleScope handle_scope(isolate); | ||
349 | 36 | |||
350 | 37 | // Prepare console class | ||
351 | 38 | v8cpp::Class<internal::Console> console(isolate); | ||
352 | 39 | console | ||
353 | 40 | .set_constructor() | ||
354 | 41 | .add_method("log", &internal::Console::log); | ||
355 | 42 | |||
356 | 43 | // Create a new context that supports "require()" and "console". | ||
357 | 44 | v8cpp::Module module(isolate); | ||
358 | 45 | { | ||
359 | 46 | v8::Context::Scope context_scope(v8::Context::New(isolate)); | ||
360 | 47 | |||
361 | 48 | // Store the script filename for use in require() later | ||
362 | 49 | internal::v8cpp_script_path_.clear(); | ||
363 | 50 | std::size_t found = filename.find_last_of("/"); | ||
364 | 51 | if (found != std::string::npos) | ||
365 | 52 | { | ||
366 | 53 | internal::v8cpp_script_path_ = filename.substr(0, found) + "/"; | ||
367 | 54 | } | ||
368 | 55 | |||
369 | 56 | module.add_function("require", &internal::require); | ||
370 | 57 | module.add_class("console", console); | ||
371 | 58 | } | ||
372 | 59 | v8::Local<v8::Context> context = v8::Context::New(isolate, nullptr, module.object_template()); | ||
373 | 60 | |||
374 | 61 | // Enter the context for compiling and running the script. | ||
375 | 62 | v8::Context::Scope context_scope(context); | ||
376 | 63 | |||
377 | 64 | // Compile the script. | ||
378 | 65 | v8::Local<v8::Script> script = v8::Script::Compile(v8cpp::to_v8(isolate, source), v8cpp::to_v8(isolate, filename)); | ||
379 | 66 | |||
380 | 67 | // Run the script. | ||
381 | 68 | if (script.IsEmpty()) | ||
382 | 69 | { | ||
383 | 70 | if (!filename.empty()) | ||
384 | 71 | { | ||
385 | 72 | throw std::runtime_error("run_script(): Failed to compile script file: \"" + filename + "\""); | ||
386 | 73 | } | ||
387 | 74 | else | ||
388 | 75 | { | ||
389 | 76 | throw std::runtime_error("run_script(): Failed to compile script."); | ||
390 | 77 | } | ||
391 | 78 | } | ||
392 | 79 | |||
393 | 80 | return v8cpp::from_v8<T>(isolate, script->Run()); | ||
394 | 81 | } | ||
395 | 82 | |||
396 | 83 | template <typename T = v8::Handle<v8::Value>> | ||
397 | 84 | T run_script_file(v8::Isolate* isolate, std::string const& filename) | ||
398 | 85 | { | ||
399 | 86 | std::ifstream stream(filename.c_str()); | ||
400 | 87 | if (!stream) | ||
401 | 88 | { | ||
402 | 89 | throw std::runtime_error("run_script_file(): Failed to locate script file: \"" + filename + "\""); | ||
403 | 90 | } | ||
404 | 91 | |||
405 | 92 | std::istreambuf_iterator<char> begin(stream), end; | ||
406 | 93 | return run_script<T>(isolate, std::string(begin, end), filename); | ||
407 | 94 | } | ||
408 | 95 | } | ||
409 | 0 | 96 | ||
410 | === modified file 'src/v8-cpp.h' | |||
411 | --- src/v8-cpp.h 2015-06-10 05:57:04 +0000 | |||
412 | +++ src/v8-cpp.h 2015-07-02 11:58:46 +0000 | |||
413 | @@ -20,3 +20,4 @@ | |||
414 | 20 | #include <class.h> | 20 | #include <class.h> |
415 | 21 | #include <convert.h> | 21 | #include <convert.h> |
416 | 22 | #include <module.h> | 22 | #include <module.h> |
417 | 23 | #include <run.h> | ||
418 | 23 | 24 | ||
419 | === modified file 'test/CMakeLists.txt' | |||
420 | --- test/CMakeLists.txt 2015-06-10 05:57:04 +0000 | |||
421 | +++ test/CMakeLists.txt 2015-07-02 11:58:46 +0000 | |||
422 | @@ -1,9 +1,13 @@ | |||
423 | 1 | find_package(Node REQUIRED) | ||
424 | 2 | |||
425 | 3 | include_directories( | ||
426 | 4 | ${NODE_INCLUDE_DIRS} | ||
427 | 5 | ) | ||
428 | 6 | |||
429 | 1 | file( | 7 | file( |
430 | 2 | GLOB | 8 | GLOB |
431 | 3 | TEST_FILES | 9 | TEST_FILES |
435 | 4 | *.h | 10 | *.h *.cpp *.js |
433 | 5 | *.cpp | ||
434 | 6 | *.js | ||
436 | 7 | ) | 11 | ) |
437 | 8 | 12 | ||
438 | 9 | configure_file(test.js test.js) | 13 | configure_file(test.js test.js) |
439 | 10 | 14 | ||
440 | === modified file 'test/addon.cpp' | |||
441 | --- test/addon.cpp 2015-06-22 16:40:30 +0000 | |||
442 | +++ test/addon.cpp 2015-07-02 11:58:46 +0000 | |||
443 | @@ -119,3 +119,4 @@ | |||
444 | 119 | } | 119 | } |
445 | 120 | 120 | ||
446 | 121 | NODE_MODULE(addon, InitAll) | 121 | NODE_MODULE(addon, InitAll) |
447 | 122 | V8CPP_MODULE(addon, InitAll) | ||
448 | 122 | 123 | ||
449 | === added directory 'v8runner' | |||
450 | === added file 'v8runner/CMakeLists.txt' | |||
451 | --- v8runner/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
452 | +++ v8runner/CMakeLists.txt 2015-07-02 11:58:46 +0000 | |||
453 | @@ -0,0 +1,9 @@ | |||
454 | 1 | add_executable( | ||
455 | 2 | v8runner | ||
456 | 3 | v8runner.cpp | ||
457 | 4 | ) | ||
458 | 5 | |||
459 | 6 | target_link_libraries( | ||
460 | 7 | v8runner | ||
461 | 8 | v8-cpp | ||
462 | 9 | ) | ||
463 | 0 | 10 | ||
464 | === added file 'v8runner/v8runner.cpp' | |||
465 | --- v8runner/v8runner.cpp 1970-01-01 00:00:00 +0000 | |||
466 | +++ v8runner/v8runner.cpp 2015-07-02 11:58:46 +0000 | |||
467 | @@ -0,0 +1,24 @@ | |||
468 | 1 | #include <v8-cpp.h> | ||
469 | 2 | |||
470 | 3 | using namespace v8; | ||
471 | 4 | |||
472 | 5 | int main(int argc, char* argv[]) | ||
473 | 6 | { | ||
474 | 7 | // Check args. | ||
475 | 8 | if (argc != 2) | ||
476 | 9 | { | ||
477 | 10 | std::cerr << "usage: v8runner script.js" << std::endl; | ||
478 | 11 | return -1; | ||
479 | 12 | } | ||
480 | 13 | |||
481 | 14 | // Create a new isolate to run our script in. | ||
482 | 15 | Isolate* isolate = Isolate::New(); | ||
483 | 16 | |||
484 | 17 | // Run script. | ||
485 | 18 | v8cpp::run_script_file(isolate, argv[1]); | ||
486 | 19 | |||
487 | 20 | // Clean up. | ||
488 | 21 | isolate->Dispose(); | ||
489 | 22 | |||
490 | 23 | return 0; | ||
491 | 24 | } |