Merge lp:~webapps/unity-js-scopes/lp-1476406 into lp:unity-js-scopes

Proposed by Marcus Tomlinson
Status: Merged
Merged at revision: 30
Proposed branch: lp:~webapps/unity-js-scopes/lp-1476406
Merge into: lp:unity-js-scopes
Diff against target: 481 lines (+117/-73)
15 files modified
CMakeLists.txt (+10/-8)
deps/build.sh (+1/-1)
examples/simple/simple.ini (+2/-0)
examples/simple/simple.js (+1/-1)
src/bindings/index.js (+4/-0)
src/bindings/src/addon.cc (+17/-0)
src/bindings/src/canned-query.h (+1/-1)
src/bindings/src/scope-base.cc (+33/-29)
src/bindings/src/scope-base.h (+1/-0)
src/bindings/src/scope.cc (+28/-21)
src/bindings/src/scope.h (+1/-0)
src/bindings/src/search-query.cc (+11/-12)
src/bindings/src/search-query.h (+1/-0)
src/launcher/CMakeLists.txt (+5/-0)
src/launcher/main.cc (+1/-0)
To merge this branch: bzr merge lp:~webapps/unity-js-scopes/lp-1476406
Reviewer Review Type Date Requested Status
WebApps Pending
Review via email: mp+266225@code.launchpad.net

Commit message

* Build io.js as part of the unity-js-scopes build
* Build io.js in Release and Debug, and set link directory accordingly
* Added commented out debug lines to simple.ini for quick debug enable/disable
* Commented out "canned_query.query_string();" line in simple.js (crashes atm)
* Added missing "runtime_config.search" function to index.js
* Added missing "new_categorised_result" function export to addon.cc
* Use v8cpp::Locker to acquire the main isolate lock for incoming callbacks
* Configure runtime_ lazily in scope.cc to provide scope ID to create_scope_runtime()
* Get and store current isolate upon constructing bound scope classes

To post a comment you must log in.
28. By Marcus Tomlinson

Reverted silly change that got left behind

29. By Marcus Tomlinson

Got query string working in simple.js

30. By Marcus Tomlinson

Added all required locks to scope-base.cc and search-query.cc

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-06-25 18:00:25 +0000
3+++ CMakeLists.txt 2015-07-30 13:03:08 +0000
4@@ -43,14 +43,16 @@
5 ${CMAKE_CURRENT_SOURCE_DIR}/deps/v8-cpp/src
6 ${CMAKE_CURRENT_SOURCE_DIR}/src
7 )
8-link_directories(
9- ${CMAKE_CURRENT_SOURCE_DIR}/deps/io.js/out/Release
10- )
11
12-add_custom_target(
13- deps
14- COMMAND
15- ${CMAKE_CURRENT_SOURCE_DIR}/deps/build.sh
16- )
17+string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
18+if(cmake_build_type_tolower STREQUAL "debug")
19+ link_directories(
20+ ${CMAKE_CURRENT_SOURCE_DIR}/deps/io.js/out/Debug
21+ )
22+else()
23+ link_directories(
24+ ${CMAKE_CURRENT_SOURCE_DIR}/deps/io.js/out/Release
25+ )
26+endif()
27
28 add_subdirectory(src)
29
30=== modified file 'deps/build.sh'
31--- deps/build.sh 2015-06-19 20:38:02 +0000
32+++ deps/build.sh 2015-07-30 13:03:08 +0000
33@@ -7,5 +7,5 @@
34 cd $DIR
35
36 cd io.js
37-./configure --enable-static
38+./configure --enable-static --debug
39 make -j3
40
41=== modified file 'examples/simple/simple.ini'
42--- examples/simple/simple.ini 2015-07-22 09:48:34 +0000
43+++ examples/simple/simple.ini 2015-07-30 13:03:08 +0000
44@@ -1,5 +1,7 @@
45 [ScopeConfig]
46 ScopeRunner=/usr/bin/unity-js-scopes-launcher %S %R
47+#ScopeRunner=/usr/bin/gdbserver :10000 /usr/bin/unity-js-scopes-launcher %S %R
48+#DebugMode = true
49 DisplayName = mock.DisplayName
50 Description = mock.Description
51 Author = test
52
53=== modified file 'examples/simple/simple.js'
54--- examples/simple/simple.js 2015-07-20 19:24:44 +0000
55+++ examples/simple/simple.js 2015-07-30 13:03:08 +0000
56@@ -45,7 +45,7 @@
57 var categorised_result =
58 scopes.lib.new_categorised_result(category);
59 categorised_result.set_uri("http://www.ubuntu.com");
60- categorised_result.set_title("Ubuntu");
61+ categorised_result.set_title("'" + qs + "'");
62
63 search_reply.push(categorised_result);
64 },
65
66=== modified file 'src/bindings/index.js'
67--- src/bindings/index.js 2015-07-20 19:24:44 +0000
68+++ src/bindings/index.js 2015-07-30 13:03:08 +0000
69@@ -48,6 +48,10 @@
70 this._base.onstop(runtime_config.stop);
71 }
72
73+ if (runtime_config.search && typeof(runtime_config.search) === 'function') {
74+ this._base.onsearch(runtime_config.search);
75+ }
76+
77 if (runtime_config.preview && typeof(runtime_config.preview) === 'function') {
78 this._base.onpreview(runtime_config.preview);
79 }
80
81=== modified file 'src/bindings/src/addon.cc'
82--- src/bindings/src/addon.cc 2015-07-20 19:24:44 +0000
83+++ src/bindings/src/addon.cc 2015-07-30 13:03:08 +0000
84@@ -288,10 +288,27 @@
85 v8cpp::Class<SearchMetaData> search_metadata(isolate);
86
87 v8cpp::Module module(isolate);
88+ module.add_class("js_scope", js_scope);
89+ module.add_class("scope_base", scope_base);
90+ module.add_class("action_metadata", action_metadata);
91+ module.add_class("category", category);
92+ module.add_class("categorised_result", categorised_result);
93+ module.add_class("canned_query", canned_query);
94+ module.add_class("category_renderer", category_renderer);
95+ module.add_class("column_layout", column_layout);
96+ module.add_class("preview_widget", preview_widget);
97+ module.add_class("preview_query", preview_query);
98+ module.add_class("preview_reply", preview_reply);
99+ module.add_class("result", result);
100+ module.add_class("search_reply", search_reply);
101+ module.add_class("search_query", search_query);
102+ module.add_class("search_metadata", search_metadata);
103+
104 module.add_function("new_scope", &new_scope);
105 module.add_function("new_search_query", &new_search_query);
106 module.add_function("new_category_renderer", &new_category_renderer);
107 module.add_function("new_preview_widget", &new_preview_widget);
108+ module.add_function("new_categorised_result", &new_categorised_result);
109
110 exports->SetPrototype(module.create_prototype());
111 }
112
113=== modified file 'src/bindings/src/canned-query.h'
114--- src/bindings/src/canned-query.h 2015-06-18 16:39:04 +0000
115+++ src/bindings/src/canned-query.h 2015-07-30 13:03:08 +0000
116@@ -39,7 +39,7 @@
117
118 private:
119
120- unity::scopes::CannedQuery const &query_;
121+ unity::scopes::CannedQuery const query_;
122 };
123
124 #endif // _UNITY_JS_CANNED_QUERY_H_
125
126=== modified file 'src/bindings/src/scope-base.cc'
127--- src/bindings/src/scope-base.cc 2015-07-20 19:07:45 +0000
128+++ src/bindings/src/scope-base.cc 2015-07-30 13:03:08 +0000
129@@ -25,7 +25,8 @@
130 #include "action-metadata.h"
131 #include "preview-query.h"
132
133-ScopeBase::ScopeBase() {
134+ScopeBase::ScopeBase()
135+ : isolate_(v8::Isolate::GetCurrent()) {
136 }
137 ScopeBase::~ScopeBase() {
138 if ( ! start_callback_.IsEmpty()) {
139@@ -43,49 +44,51 @@
140 }
141
142 void ScopeBase::start(std::string const& scope_id) {
143+ v8cpp::Locker locker(isolate_);
144+
145 if (start_callback_.IsEmpty()) {
146 return;
147 }
148
149- v8::Isolate * isolate = v8::Isolate::GetCurrent();
150-
151 v8::Local<v8::Function> start_callback =
152- v8cpp::to_local<v8::Function>(isolate, start_callback_);
153+ v8cpp::to_local<v8::Function>(isolate_, start_callback_);
154
155- v8cpp::call_v8(isolate,
156+ v8cpp::call_v8(isolate_,
157 start_callback,
158- v8cpp::to_v8(isolate, scope_id.c_str()));
159+ v8cpp::to_v8(isolate_, scope_id.c_str()));
160 }
161
162 void ScopeBase::stop() {
163+ v8cpp::Locker locker(isolate_);
164+
165 if (stop_callback_.IsEmpty()) {
166 return;
167 }
168
169- v8::Isolate * isolate = v8::Isolate::GetCurrent();
170-
171 v8::Local<v8::Function> stop_callback =
172- v8cpp::to_local<v8::Function>(isolate, stop_callback_);
173+ v8cpp::to_local<v8::Function>(isolate_, stop_callback_);
174
175- v8cpp::call_v8(isolate, stop_callback);
176+ v8cpp::call_v8(isolate_, stop_callback);
177 }
178
179 void ScopeBase::run() {
180+ v8cpp::Locker locker(isolate_);
181+
182 if (run_callback_.IsEmpty()) {
183 return;
184 }
185
186- v8::Isolate * isolate = v8::Isolate::GetCurrent();
187-
188 v8::Local<v8::Function> run_callback =
189- v8cpp::to_local<v8::Function>(isolate, run_callback_);
190+ v8cpp::to_local<v8::Function>(isolate_, run_callback_);
191
192- v8cpp::call_v8(isolate, run_callback);
193+ v8cpp::call_v8(isolate_, run_callback);
194 }
195
196 unity::scopes::SearchQueryBase::UPtr ScopeBase::search(
197 unity::scopes::CannedQuery const &query,
198 unity::scopes::SearchMetadata const &metadata) {
199+ v8cpp::Locker locker(isolate_);
200+
201 if (search_callback_.IsEmpty()) {
202 return nullptr;
203 }
204@@ -94,20 +97,18 @@
205 CannedQuery *q = new CannedQuery(query);
206 SearchMetaData *m = new SearchMetaData(metadata);
207
208- v8::Isolate *isolate = v8::Isolate::GetCurrent();
209-
210 v8::Local<v8::Function> search_callback =
211- v8cpp::to_local<v8::Function>(isolate, search_callback_);
212+ v8cpp::to_local<v8::Function>(isolate_, search_callback_);
213
214- v8::Handle<v8::Value> result =
215- v8cpp::call_v8(isolate,
216+ v8::Handle<v8::Value> result =
217+ v8cpp::call_v8(isolate_,
218 search_callback,
219- v8cpp::to_v8(isolate, q),
220- v8cpp::to_v8(isolate, m));
221+ v8cpp::to_v8(isolate_, q),
222+ v8cpp::to_v8(isolate_, m));
223
224 // TODO watch out release
225 SearchQuery * sq =
226- v8cpp::from_v8<SearchQuery*>(isolate, result);
227+ v8cpp::from_v8<SearchQuery*>(isolate_, result);
228
229 return unity::scopes::SearchQueryBase::UPtr(sq);
230 }
231@@ -115,6 +116,8 @@
232 unity::scopes::ActivationQueryBase::UPtr ScopeBase::activate(
233 unity::scopes::Result const &result,
234 unity::scopes::ActionMetadata const &metadata) {
235+ v8cpp::Locker locker(isolate_);
236+
237 return nullptr;
238 }
239
240@@ -123,12 +126,15 @@
241 unity::scopes::ActionMetadata const &metadata,
242 std::string const &widget_id,
243 std::string const &action_id) {
244+ v8cpp::Locker locker(isolate_);
245 return nullptr;
246 }
247
248 unity::scopes::PreviewQueryBase::UPtr ScopeBase::preview(
249 unity::scopes::Result const &result,
250 unity::scopes::ActionMetadata const &action_metadata) {
251+ v8cpp::Locker locker(isolate_);
252+
253 if (preview_callback_.IsEmpty()) {
254 return nullptr;
255 }
256@@ -137,20 +143,18 @@
257 Result *r = new Result(result);
258 ActionMetaData *m = new ActionMetaData(action_metadata);
259
260- v8::Isolate *isolate = v8::Isolate::GetCurrent();
261-
262 v8::Local<v8::Function> preview_callback =
263- v8cpp::to_local<v8::Function>(isolate, preview_callback_);
264+ v8cpp::to_local<v8::Function>(isolate_, preview_callback_);
265
266 v8::Handle<v8::Value> wrapped_preview =
267- v8cpp::call_v8(isolate,
268+ v8cpp::call_v8(isolate_,
269 preview_callback,
270- v8cpp::to_v8(isolate, r),
271- v8cpp::to_v8(isolate, m));
272+ v8cpp::to_v8(isolate_, r),
273+ v8cpp::to_v8(isolate_, m));
274
275 // TODO watch out release
276 PreviewQuery * sq =
277- v8cpp::from_v8<PreviewQuery*>(isolate, wrapped_preview);
278+ v8cpp::from_v8<PreviewQuery*>(isolate_, wrapped_preview);
279
280 return unity::scopes::PreviewQueryBase::UPtr(sq);
281 }
282
283=== modified file 'src/bindings/src/scope-base.h'
284--- src/bindings/src/scope-base.h 2015-07-09 01:02:19 +0000
285+++ src/bindings/src/scope-base.h 2015-07-30 13:03:08 +0000
286@@ -68,6 +68,7 @@
287 std::string const &action_id) override;
288
289 private:
290+ v8::Isolate* isolate_;
291
292 v8::Persistent<v8::Function> start_callback_;
293 v8::Persistent<v8::Function> stop_callback_;
294
295=== modified file 'src/bindings/src/scope.cc'
296--- src/bindings/src/scope.cc 2015-07-22 09:48:34 +0000
297+++ src/bindings/src/scope.cc 2015-07-30 13:03:08 +0000
298@@ -28,27 +28,8 @@
299
300 JavascriptScopeRuntime::JavascriptScopeRuntime(
301 const std::string& config_file)
302- : scope_base_(new ScopeBase()) {
303- std::string current_runtime_config = config_file;
304-
305- if (current_runtime_config.empty()) {
306- char * env_runtime_config =
307- std::getenv(kJavascriptUnityRuntimeEnvVarName);
308-
309- if (env_runtime_config) {
310- current_runtime_config = env_runtime_config;
311-
312- if ( ! boost::ends_with(current_runtime_config, ".ini")) {
313- throw std::runtime_error("Invalid runtime config (ini file)");
314- }
315-
316- if (!boost::filesystem::path(current_runtime_config).is_absolute()) {
317- current_runtime_config = boost::filesystem::canonical(current_runtime_config).native();
318- }
319- }
320- }
321-
322- runtime_ = unity::scopes::Runtime::create(current_runtime_config);
323+ : scope_base_(new ScopeBase()),
324+ runtime_config_(config_file) {
325 }
326
327 JavascriptScopeRuntime::~JavascriptScopeRuntime() {
328@@ -64,6 +45,7 @@
329 throw std::runtime_error("Scope already running");
330 }
331
332+ // Configure scope_config_
333 std::string current_scope_config = scope_config;
334
335 if (current_scope_config.empty()) {
336@@ -85,6 +67,31 @@
337
338 scope_config_ = current_scope_config;
339
340+ // Configure runtime_
341+ std::string current_runtime_config = runtime_config_;
342+
343+ if (current_runtime_config.empty()) {
344+ char * env_runtime_config =
345+ std::getenv(kJavascriptUnityRuntimeEnvVarName);
346+
347+ if (env_runtime_config) {
348+ current_runtime_config = env_runtime_config;
349+
350+ if ( ! boost::ends_with(current_runtime_config, ".ini")) {
351+ throw std::runtime_error("Invalid runtime config (ini file)");
352+ }
353+
354+ if (!boost::filesystem::path(current_runtime_config).is_absolute()) {
355+ current_runtime_config = boost::filesystem::canonical(current_runtime_config).native();
356+ }
357+ }
358+ }
359+
360+ std::string scope_id = boost::filesystem::path(scope_config_).stem().string();
361+ runtime_ = unity::scopes::Runtime::create_scope_runtime(scope_id, current_runtime_config);
362+
363+ // Unlock access to the main isolate so that our callbacks will work
364+ v8cpp::Unlocker unlocker(v8::Isolate::GetCurrent());
365 runtime_->run_scope(scope_base_.get(), current_scope_config);
366 }
367
368
369=== modified file 'src/bindings/src/scope.h'
370--- src/bindings/src/scope.h 2015-07-20 19:24:44 +0000
371+++ src/bindings/src/scope.h 2015-07-30 13:03:08 +0000
372@@ -43,6 +43,7 @@
373
374 unity::scopes::Runtime::UPtr runtime_;
375 std::unique_ptr<ScopeBase> scope_base_;
376+ std::string runtime_config_;
377 std::string scope_config_;
378 };
379
380
381=== modified file 'src/bindings/src/search-query.cc'
382--- src/bindings/src/search-query.cc 2015-07-09 18:30:28 +0000
383+++ src/bindings/src/search-query.cc 2015-07-30 13:03:08 +0000
384@@ -28,6 +28,7 @@
385 const v8::Local<v8::Function> &run_callback,
386 const v8::Local<v8::Function> &cancelled_callback)
387 : unity::scopes::SearchQueryBase(query, metadata),
388+ isolate_(v8::Isolate::GetCurrent()),
389 run_callback_(v8::Isolate::GetCurrent(), run_callback),
390 cancelled_callback_(v8::Isolate::GetCurrent(), cancelled_callback) {
391 }
392@@ -86,12 +87,12 @@
393 CannedQuery *q =
394 new CannedQuery(unity::scopes::SearchQueryBase::query());
395
396- v8::Isolate *isolate = v8::Isolate::GetCurrent();
397-
398- return v8cpp::to_v8(isolate, q);
399+ return v8cpp::to_v8(isolate_, q);
400 }
401
402 void SearchQuery::run(unity::scopes::SearchReplyProxy const& reply) {
403+ v8cpp::Locker locker(isolate_);
404+
405 if (run_callback_.IsEmpty()) {
406 return;
407 }
408@@ -99,27 +100,25 @@
409 // wrap & fire
410 SearchReply *sr = new SearchReply(reply);
411
412- v8::Isolate *isolate = v8::Isolate::GetCurrent();
413-
414- auto wrapped_sr = v8cpp::to_v8(isolate, sr);
415+ auto wrapped_sr = v8cpp::to_v8(isolate_, sr);
416
417 v8::Local<v8::Function> run_callback =
418- v8cpp::to_local<v8::Function>(isolate, run_callback_);
419+ v8cpp::to_local<v8::Function>(isolate_, run_callback_);
420
421- v8cpp::call_v8(isolate, run_callback, wrapped_sr);
422+ v8cpp::call_v8(isolate_, run_callback, wrapped_sr);
423 }
424
425 void SearchQuery::cancelled() {
426+ v8cpp::Locker locker(isolate_);
427+
428 if (cancelled_callback_.IsEmpty()) {
429 return;
430 }
431
432- v8::Isolate *isolate = v8::Isolate::GetCurrent();
433-
434 v8::Local<v8::Function> cancelled_callback =
435- v8cpp::to_local<v8::Function>(isolate, cancelled_callback_);
436+ v8cpp::to_local<v8::Function>(isolate_, cancelled_callback_);
437
438- v8cpp::call_v8(isolate, cancelled_callback);
439+ v8cpp::call_v8(isolate_, cancelled_callback);
440 }
441
442 v8::Local<v8::Value> SearchQuery::valid(
443
444=== modified file 'src/bindings/src/search-query.h'
445--- src/bindings/src/search-query.h 2015-07-09 01:02:19 +0000
446+++ src/bindings/src/search-query.h 2015-07-30 13:03:08 +0000
447@@ -46,6 +46,7 @@
448 void cancelled() override;
449
450 private:
451+ v8::Isolate* isolate_;
452
453 v8::Persistent<v8::Function> run_callback_;
454 v8::Persistent<v8::Function> cancelled_callback_;
455
456=== modified file 'src/launcher/CMakeLists.txt'
457--- src/launcher/CMakeLists.txt 2015-07-20 21:05:06 +0000
458+++ src/launcher/CMakeLists.txt 2015-07-30 13:03:08 +0000
459@@ -87,5 +87,10 @@
460 dl
461 )
462
463+add_custom_command(
464+ TARGET ${LAUNCHER_EXECUTABLE_NAME} PRE_LINK
465+ COMMAND ${CMAKE_SOURCE_DIR}/deps/build.sh
466+)
467+
468 install(TARGETS ${LAUNCHER_EXECUTABLE_NAME}
469 RUNTIME DESTINATION /usr/bin)
470
471=== modified file 'src/launcher/main.cc'
472--- src/launcher/main.cc 2015-07-22 09:48:34 +0000
473+++ src/launcher/main.cc 2015-07-30 13:03:08 +0000
474@@ -32,6 +32,7 @@
475 std::cout << executable_name()
476 << " "
477 << "<path-to-scope-ini>"
478+ << " "
479 << "[<path-to-runtime-ini>]"
480 << std::endl;
481 }

Subscribers

People subscribed via source and target branches

to all changes: