summaryrefslogtreecommitdiff
path: root/src/bindings/js
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-09-01 15:08:49 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-12-23 23:59:40 -0200
commita3db1dddd3ba67c81118f7f2c0bc753dc8aac551 (patch)
tree233ee1be7bfa299bff560207135d20940c4e411f /src/bindings/js
parent1a3cb45f1cc7fdf8d481879e6bd7349d9cb0b3fa (diff)
efl-js: JavaScript Eolian binding
To configure efl sources with bindings to use in nodejs add ––with-js=nodejs in configure flags to generate node files $ configure --with-js=nodejs and compile normally with: $ make $ make install To use, you have to require efl: efl = require('efl') The bindings is divided in two parts: generated and manually written. The generation uses the Eolian library for parsing Eo files and generate C++ code that is compiled against V8 interpreter library to create a efl.node file that can be required in a node.js instance. @feature
Diffstat (limited to 'src/bindings/js')
-rw-r--r--src/bindings/js/ecore_js/Ecore_Js.hh58
-rw-r--r--src/bindings/js/ecore_js/ecore_js_animator.cc608
-rw-r--r--src/bindings/js/ecore_js/ecore_js_event.cc772
-rw-r--r--src/bindings/js/ecore_js/ecore_js_idle.cc294
-rw-r--r--src/bindings/js/ecore_js/ecore_js_init.cc76
-rw-r--r--src/bindings/js/ecore_js/ecore_js_job.cc83
-rw-r--r--src/bindings/js/ecore_js/ecore_js_mainloop.cc207
-rw-r--r--src/bindings/js/ecore_js/ecore_js_poller.cc190
-rw-r--r--src/bindings/js/ecore_js/ecore_js_throttle.cc63
-rw-r--r--src/bindings/js/ecore_js/ecore_js_timer.cc232
-rw-r--r--src/bindings/js/ecore_js/ecore_js_timer.hh38
-rw-r--r--src/bindings/js/efl_js/Efl_Js.hh30
-rw-r--r--src/bindings/js/efl_js/efl_js.cc241
-rw-r--r--src/bindings/js/eina_js/Eina_Js.hh50
-rw-r--r--src/bindings/js/eina_js/eina_js_accessor.cc34
-rw-r--r--src/bindings/js/eina_js/eina_js_accessor.hh87
-rw-r--r--src/bindings/js/eina_js/eina_js_array.hh119
-rw-r--r--src/bindings/js/eina_js/eina_js_compatibility.cc12
-rw-r--r--src/bindings/js/eina_js/eina_js_compatibility.hh918
-rw-r--r--src/bindings/js/eina_js/eina_js_container.cc495
-rw-r--r--src/bindings/js/eina_js/eina_js_container.hh351
-rw-r--r--src/bindings/js/eina_js/eina_js_error.cc24
-rw-r--r--src/bindings/js/eina_js/eina_js_error.hh25
-rw-r--r--src/bindings/js/eina_js/eina_js_get_value.hh449
-rw-r--r--src/bindings/js/eina_js/eina_js_get_value_from_c.hh261
-rw-r--r--src/bindings/js/eina_js/eina_js_iterator.cc32
-rw-r--r--src/bindings/js/eina_js/eina_js_iterator.hh81
-rw-r--r--src/bindings/js/eina_js/eina_js_list.hh132
-rw-r--r--src/bindings/js/eina_js/eina_js_log.cc742
-rw-r--r--src/bindings/js/eina_js/eina_js_log.hh133
-rw-r--r--src/bindings/js/eina_js/eina_js_node.hh14
-rw-r--r--src/bindings/js/eina_js/eina_js_value.cc132
-rw-r--r--src/bindings/js/eina_js/eina_js_value.hh142
-rw-r--r--src/bindings/js/eio_js/Eio_Js.hh44
-rw-r--r--src/bindings/js/eio_js/eio_js.cc1756
-rw-r--r--src/bindings/js/eldbus_js/Eldbus_Js.hh48
-rw-r--r--src/bindings/js/eldbus_js/eldbus_js_connection.cc543
-rw-r--r--src/bindings/js/eldbus_js/eldbus_js_core.cc183
-rw-r--r--src/bindings/js/eldbus_js/eldbus_js_message.cc103
-rw-r--r--src/bindings/js/eldbus_js/eldbus_js_object_mapper.cc100
-rw-r--r--src/bindings/js/eldbus_js/eldbus_js_util.hh836
-rw-r--r--src/bindings/js/eo_js/Eo_Js.hh15
-rw-r--r--src/bindings/js/eo_js/eo_js_call_function.hh288
-rw-r--r--src/bindings/js/eo_js/eo_js_construct_from_eo.hh39
-rw-r--r--src/bindings/js/eo_js/eo_js_constructor.hh136
-rw-r--r--src/bindings/js/eo_js/eo_js_direction.hh12
-rw-r--r--src/bindings/js/eo_js/eo_js_event.hh126
-rw-r--r--src/bindings/js/eo_js/eo_js_namespace.hh24
-rw-r--r--src/bindings/js/eo_js/eo_js_struct.hh106
-rw-r--r--src/bindings/js/ethumb_js/Ethumb_Js.hh48
-rw-r--r--src/bindings/js/ethumb_js/ethumb_js_client.cc571
51 files changed, 12103 insertions, 0 deletions
diff --git a/src/bindings/js/ecore_js/Ecore_Js.hh b/src/bindings/js/ecore_js/Ecore_Js.hh
new file mode 100644
index 0000000000..3f877f3fc8
--- /dev/null
+++ b/src/bindings/js/ecore_js/Ecore_Js.hh
@@ -0,0 +1,58 @@
1
2#ifndef EFL_ECORE_JS_HH
3#define EFL_ECORE_JS_HH
4
5#include <Ecore.hh>
6#include <Ecore_File.h>
7#include <Eina_Js.hh>
8
9#ifdef EAPI
10# undef EAPI
11#endif
12
13#ifdef _WIN32
14# ifdef EFL_ECORE_JS_BUILD
15# ifdef DLL_EXPORT
16# define EAPI __declspec(dllexport)
17# else
18# define EAPI
19# endif /* ! DLL_EXPORT */
20# else
21# define EAPI __declspec(dllimport)
22# endif /* ! EFL_ECORE_BUILD */
23#else
24# ifdef __GNUC__
25# if __GNUC__ >= 4
26# define EAPI __attribute__ ((visibility("default")))
27# else
28# define EAPI
29# endif
30# else
31# define EAPI
32# endif
33#endif /* ! _WIN32 */
34
35namespace efl { namespace ecore { namespace js {
36
37using ::efl::eina::js::compatibility_new;
38using ::efl::eina::js::compatibility_return_type;
39using ::efl::eina::js::compatibility_callback_info_type;
40using ::efl::eina::js::compatibility_return;
41using ::efl::eina::js::compatibility_get_pointer_internal_field;
42using ::efl::eina::js::compatibility_set_pointer_internal_field;
43
44EAPI void register_ecore_animator(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
45EAPI void register_ecore_event(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
46EAPI void register_ecore_file(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
47EAPI void register_ecore_idle(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
48EAPI void register_ecore_job(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
49EAPI void register_ecore_mainloop(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
50EAPI void register_ecore_poller(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
51EAPI void register_ecore_throttle(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
52EAPI void register_ecore_timer(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
53
54EAPI void register_ecore(v8::Isolate *isolate,v8::Handle<v8::Object> exports);
55
56} } }
57
58#endif
diff --git a/src/bindings/js/ecore_js/ecore_js_animator.cc b/src/bindings/js/ecore_js/ecore_js_animator.cc
new file mode 100644
index 0000000000..849e4d7f34
--- /dev/null
+++ b/src/bindings/js/ecore_js/ecore_js_animator.cc
@@ -0,0 +1,608 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Ecore_Js.hh>
6
7namespace efl { namespace ecore { namespace js {
8
9static Ecore_Animator* extract_animator(v8::Local<v8::Object> object)
10{
11 auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
12 return reinterpret_cast<Ecore_Animator*>(ptr);
13}
14
15static v8::Local<v8::Object> wrap_animator(Ecore_Animator *animator,
16 v8::Isolate *isolate)
17{
18 using v8::Boolean;
19 using v8::String;
20 using v8::ObjectTemplate;
21 using v8::FunctionTemplate;
22
23 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
24 obj_tpl->SetInternalFieldCount(1);
25 auto ret = obj_tpl->NewInstance();
26
27 auto del = [](compatibility_callback_info_type info)
28 -> compatibility_return_type {
29 if (info.Length() != 0)
30 return compatibility_return();
31
32 ecore_animator_del(extract_animator(info.This()));
33 return compatibility_return();
34 };
35
36 auto freeze = [](compatibility_callback_info_type info)
37 -> compatibility_return_type {
38 if (info.Length() != 0)
39 return compatibility_return();
40
41 ecore_animator_freeze(extract_animator(info.This()));
42 return compatibility_return();
43 };
44
45 auto thaw = [](compatibility_callback_info_type info)
46 -> compatibility_return_type {
47 if (info.Length() != 0)
48 return compatibility_return();
49
50 ecore_animator_thaw(extract_animator(info.This()));
51 return compatibility_return();
52 };
53
54 ret->Set(compatibility_new<String>(isolate, "del"),
55 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
56 ret->Set(compatibility_new<String>(isolate, "freeze"),
57 compatibility_new<FunctionTemplate>(isolate, freeze)
58 ->GetFunction());
59 ret->Set(compatibility_new<String>(isolate, "thaw"),
60 compatibility_new<FunctionTemplate>(isolate, thaw)->GetFunction());
61
62 ret->SetInternalField(0, compatibility_new<v8::External>(isolate,
63 animator));
64
65 return ret;
66}
67
68void register_pos_map_linear(v8::Isolate *isolate,
69 v8::Handle<v8::Object> global,
70 v8::Handle<v8::String> name)
71{
72 using v8::Integer;
73
74 global->Set(name,
75 compatibility_new<Integer>(isolate, ECORE_POS_MAP_LINEAR));
76}
77
78void register_pos_map_accelerate(v8::Isolate *isolate,
79 v8::Handle<v8::Object> global,
80 v8::Handle<v8::String> name)
81{
82 using v8::Integer;
83
84 global->Set(name,
85 compatibility_new<Integer>(isolate, ECORE_POS_MAP_ACCELERATE));
86}
87
88void register_pos_map_decelerate(v8::Isolate *isolate,
89 v8::Handle<v8::Object> global,
90 v8::Handle<v8::String> name)
91{
92 using v8::Integer;
93
94 global->Set(name,
95 compatibility_new<Integer>(isolate, ECORE_POS_MAP_DECELERATE));
96}
97
98void register_pos_map_sinusoidal(v8::Isolate *isolate,
99 v8::Handle<v8::Object> global,
100 v8::Handle<v8::String> name)
101{
102 using v8::Integer;
103
104 global->Set(name,
105 compatibility_new<Integer>(isolate, ECORE_POS_MAP_SINUSOIDAL));
106}
107
108void register_pos_map_accelerate_factor(v8::Isolate *isolate,
109 v8::Handle<v8::Object> global,
110 v8::Handle<v8::String> name)
111{
112 using v8::Integer;
113
114 global->Set(name,
115 compatibility_new<Integer>(isolate,
116 ECORE_POS_MAP_ACCELERATE_FACTOR));
117}
118
119void register_pos_map_decelerate_factor(v8::Isolate *isolate,
120 v8::Handle<v8::Object> global,
121 v8::Handle<v8::String> name)
122{
123 using v8::Integer;
124
125 global->Set(name,
126 compatibility_new<Integer>(isolate,
127 ECORE_POS_MAP_DECELERATE_FACTOR));
128}
129
130void register_pos_map_sinusoidal_factor(v8::Isolate *isolate,
131 v8::Handle<v8::Object> global,
132 v8::Handle<v8::String> name)
133{
134 using v8::Integer;
135
136 global->Set(name,
137 compatibility_new<Integer>(isolate,
138 ECORE_POS_MAP_SINUSOIDAL_FACTOR));
139}
140
141void register_pos_map_divisor_interp(v8::Isolate *isolate,
142 v8::Handle<v8::Object> global,
143 v8::Handle<v8::String> name)
144{
145 using v8::Integer;
146
147 global->Set(name,
148 compatibility_new<Integer>(isolate,
149 ECORE_POS_MAP_DIVISOR_INTERP));
150}
151
152void register_pos_map_bounce(v8::Isolate *isolate,
153 v8::Handle<v8::Object> global,
154 v8::Handle<v8::String> name)
155{
156 using v8::Integer;
157
158 global->Set(name,
159 compatibility_new<Integer>(isolate, ECORE_POS_MAP_BOUNCE));
160}
161
162void register_pos_map_spring(v8::Isolate *isolate,
163 v8::Handle<v8::Object> global,
164 v8::Handle<v8::String> name)
165{
166 using v8::Integer;
167
168 global->Set(name,
169 compatibility_new<Integer>(isolate, ECORE_POS_MAP_SPRING));
170}
171
172void register_pos_map_cubic_bezier(v8::Isolate *isolate,
173 v8::Handle<v8::Object> global,
174 v8::Handle<v8::String> name)
175{
176 using v8::Integer;
177
178 global->Set(name,
179 compatibility_new<Integer>(isolate,
180 ECORE_POS_MAP_CUBIC_BEZIER));
181}
182
183void register_animator_source_timer(v8::Isolate *isolate,
184 v8::Handle<v8::Object> global,
185 v8::Handle<v8::String> name)
186{
187 using v8::Integer;
188
189 global->Set(name,
190 compatibility_new<Integer>(isolate,
191 ECORE_ANIMATOR_SOURCE_TIMER));
192}
193
194void register_animator_frametime_set(v8::Isolate *isolate,
195 v8::Handle<v8::Object> global,
196 v8::Handle<v8::String> name)
197{
198 using v8::FunctionTemplate;
199
200 auto f = [](compatibility_callback_info_type args)
201 -> compatibility_return_type {
202 if (args.Length() != 1 || !args[0]->IsNumber())
203 return compatibility_return();
204
205 ecore_animator_frametime_set(args[0]->NumberValue());
206 return compatibility_return();
207 };
208
209 global->Set(name,
210 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
211}
212
213void register_animator_frametime_get(v8::Isolate *isolate,
214 v8::Handle<v8::Object> global,
215 v8::Handle<v8::String> name)
216{
217 using v8::Number;
218 using v8::FunctionTemplate;
219
220 auto f = [](compatibility_callback_info_type args)
221 -> compatibility_return_type {
222 if (args.Length() != 0)
223 return compatibility_return();
224
225 auto isolate = args.GetIsolate();
226 auto ret = ecore_animator_frametime_get();
227 return compatibility_return(compatibility_new<Number>(isolate, ret),
228 args);
229 };
230
231 global->Set(name,
232 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
233}
234
235void register_animator_pos_map(v8::Isolate *isolate,
236 v8::Handle<v8::Object> global,
237 v8::Handle<v8::String> name)
238{
239 using v8::Number;
240 using v8::FunctionTemplate;
241
242 auto f = [](compatibility_callback_info_type args)
243 -> compatibility_return_type {
244 if (args.Length() != 4 || !args[0]->IsNumber() || !args[1]->IsNumber()
245 || !args[2]->IsNumber() || !args[3]->IsNumber())
246 return compatibility_return();
247
248 Ecore_Pos_Map map;
249
250 switch ((int)(args[1]->NumberValue())) {
251 case ECORE_POS_MAP_LINEAR:
252 map = ECORE_POS_MAP_LINEAR;
253 break;
254 case ECORE_POS_MAP_ACCELERATE:
255 map = ECORE_POS_MAP_ACCELERATE;
256 break;
257 case ECORE_POS_MAP_DECELERATE:
258 map = ECORE_POS_MAP_DECELERATE;
259 break;
260 case ECORE_POS_MAP_SINUSOIDAL:
261 map = ECORE_POS_MAP_SINUSOIDAL;
262 break;
263 case ECORE_POS_MAP_ACCELERATE_FACTOR:
264 map = ECORE_POS_MAP_ACCELERATE_FACTOR;
265 break;
266 case ECORE_POS_MAP_DECELERATE_FACTOR:
267 map = ECORE_POS_MAP_DECELERATE_FACTOR;
268 break;
269 case ECORE_POS_MAP_SINUSOIDAL_FACTOR:
270 map = ECORE_POS_MAP_SINUSOIDAL_FACTOR;
271 break;
272 case ECORE_POS_MAP_DIVISOR_INTERP:
273 map = ECORE_POS_MAP_DIVISOR_INTERP;
274 break;
275 case ECORE_POS_MAP_BOUNCE:
276 map = ECORE_POS_MAP_BOUNCE;
277 break;
278 case ECORE_POS_MAP_SPRING:
279 map = ECORE_POS_MAP_SPRING;
280 break;
281 case ECORE_POS_MAP_CUBIC_BEZIER:
282 map = ECORE_POS_MAP_CUBIC_BEZIER;
283 break;
284 default:
285 return compatibility_return();
286 }
287
288 auto isolate = args.GetIsolate();
289 auto ret = ecore_animator_pos_map(args[0]->NumberValue(), map,
290 args[2]->NumberValue(),
291 args[3]->NumberValue());
292 return compatibility_return(compatibility_new<Number>(isolate, ret),
293 args);
294 };
295
296 global->Set(name,
297 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
298}
299
300void register_animator_pos_map_n(v8::Isolate *isolate,
301 v8::Handle<v8::Object> global,
302 v8::Handle<v8::String> name)
303{
304 using v8::Number;
305 using v8::NumberObject;
306 using v8::FunctionTemplate;
307 using v8::Array;
308
309 auto f = [](compatibility_callback_info_type args)
310 -> compatibility_return_type {
311 if (args.Length() != 3 || !args[0]->IsNumber() || !args[1]->IsNumber()
312 || !args[2]->IsArray())
313 return compatibility_return();
314
315 Ecore_Pos_Map map;
316
317 switch ((int)(args[1]->NumberValue())) {
318 case ECORE_POS_MAP_LINEAR:
319 map = ECORE_POS_MAP_LINEAR;
320 break;
321 case ECORE_POS_MAP_ACCELERATE:
322 map = ECORE_POS_MAP_ACCELERATE;
323 break;
324 case ECORE_POS_MAP_DECELERATE:
325 map = ECORE_POS_MAP_DECELERATE;
326 break;
327 case ECORE_POS_MAP_SINUSOIDAL:
328 map = ECORE_POS_MAP_SINUSOIDAL;
329 break;
330 case ECORE_POS_MAP_ACCELERATE_FACTOR:
331 map = ECORE_POS_MAP_ACCELERATE_FACTOR;
332 break;
333 case ECORE_POS_MAP_DECELERATE_FACTOR:
334 map = ECORE_POS_MAP_DECELERATE_FACTOR;
335 break;
336 case ECORE_POS_MAP_SINUSOIDAL_FACTOR:
337 map = ECORE_POS_MAP_SINUSOIDAL_FACTOR;
338 break;
339 case ECORE_POS_MAP_DIVISOR_INTERP:
340 map = ECORE_POS_MAP_DIVISOR_INTERP;
341 break;
342 case ECORE_POS_MAP_BOUNCE:
343 map = ECORE_POS_MAP_BOUNCE;
344 break;
345 case ECORE_POS_MAP_SPRING:
346 map = ECORE_POS_MAP_SPRING;
347 break;
348 case ECORE_POS_MAP_CUBIC_BEZIER:
349 map = ECORE_POS_MAP_CUBIC_BEZIER;
350 break;
351 default:
352 return compatibility_return();
353 }
354
355 std::vector<double> v;
356 {
357 auto array = Array::Cast(*args[2]);
358 auto s = array->Length();
359 v.reserve(s);
360 for (decltype(s) i = 0;i != s;++i) {
361 auto e = array->Get(i);
362 if (!e->IsNumber())
363 return compatibility_return();
364
365 v.push_back(e->NumberValue());
366 }
367 }
368
369 auto isolate = args.GetIsolate();
370 auto ret = ecore_animator_pos_map_n(args[0]->NumberValue(), map,
371 v.size(), v.data());
372 return compatibility_return(compatibility_new<Number>(isolate, ret),
373 args);
374 };
375
376 global->Set(name,
377 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
378}
379
380void register_animator_source_set(v8::Isolate *isolate,
381 v8::Handle<v8::Object> global,
382 v8::Handle<v8::String> name)
383{
384 using v8::FunctionTemplate;
385
386 auto f = [](compatibility_callback_info_type args)
387 -> compatibility_return_type {
388 if (args.Length() != 1 || !args[0]->IsNumber())
389 return compatibility_return();
390
391 Ecore_Animator_Source source;
392
393 switch ((int)(args[0]->NumberValue())) {
394 case ECORE_ANIMATOR_SOURCE_TIMER:
395 source = ECORE_ANIMATOR_SOURCE_TIMER;
396 break;
397 case ECORE_ANIMATOR_SOURCE_CUSTOM:
398 source = ECORE_ANIMATOR_SOURCE_CUSTOM;
399 break;
400 default:
401 return compatibility_return();
402 }
403
404 ecore_animator_source_set(source);
405 return compatibility_return();
406 };
407
408 global->Set(name,
409 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
410}
411
412void register_animator_source_get(v8::Isolate *isolate,
413 v8::Handle<v8::Object> global,
414 v8::Handle<v8::String> name)
415{
416 using v8::Integer;
417 using v8::FunctionTemplate;
418
419 auto f = [](compatibility_callback_info_type args)
420 -> compatibility_return_type {
421 if (args.Length() != 0)
422 return compatibility_return();
423
424 auto isolate = args.GetIsolate();
425 auto ret = ecore_animator_source_get();
426 return compatibility_return(compatibility_new<Integer>(isolate, ret),
427 args);
428 };
429
430 global->Set(name,
431 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
432}
433
434void register_animator_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
435 v8::Handle<v8::String> name)
436{
437 using v8::Local;
438 using v8::Value;
439 using v8::Undefined;
440 using v8::Function;
441 using v8::FunctionTemplate;
442
443 auto f = [](compatibility_callback_info_type args)
444 -> compatibility_return_type {
445 if (args.Length() != 1 || !args[0]->IsFunction())
446 return compatibility_return();
447
448 auto isolate = args.GetIsolate();
449 auto f = new efl::eina::js::global_ref<Value>(isolate, args[0]);
450
451 auto cb = [](void *data) -> Eina_Bool {
452 auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
453 auto o = persistent->handle();
454
455 auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
456 auto bret = ret->IsBoolean() && ret->BooleanValue();
457
458 if (!bret)
459 {
460 persistent->dispose();
461 delete persistent;
462 }
463
464 return bret ? EINA_TRUE : EINA_FALSE;
465 };
466
467 auto ret = ecore_animator_add(cb, f);
468 return compatibility_return(wrap_animator(ret, isolate), args);
469 };
470
471 global->Set(name,
472 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
473}
474
475void register_animator_timeline_add(v8::Isolate *isolate,
476 v8::Handle<v8::Object> global,
477 v8::Handle<v8::String> name)
478{
479 using v8::Handle;
480 using v8::Local;
481 using v8::Value;
482 using v8::Undefined;
483 using v8::Function;
484 using v8::FunctionTemplate;
485 using v8::Number;
486
487 auto f = [](compatibility_callback_info_type args)
488 -> compatibility_return_type {
489 if (args.Length() != 2 || !args[0]->IsNumber()
490 || !args[1]->IsFunction()) {
491 return compatibility_return();
492 }
493
494 auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[1]);
495
496 auto cb = [](void *data, double pos) -> Eina_Bool {
497 auto persistent
498 = reinterpret_cast<efl::eina::js::global_ref<Value>*>(data);
499 auto o = persistent->handle();
500 auto isolate = v8::Isolate::GetCurrent();
501
502 Handle<Value> args = compatibility_new<Number>(isolate, pos);
503
504 auto ret = Function::Cast(*o)->Call(o->ToObject(), 1, &args);
505 auto bret = ret->IsBoolean() && ret->BooleanValue();
506
507 if (!bret)
508 {
509 persistent->dispose();
510 delete persistent;
511 }
512
513 return bret ? EINA_TRUE : EINA_FALSE;
514 };
515
516 auto ret = ecore_animator_timeline_add(args[0]->NumberValue(), cb, f);
517 return compatibility_return(wrap_animator(ret, args.GetIsolate()),
518 args);
519 };
520
521 global->Set(name,
522 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
523}
524
525void register_ecore_animator(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
526{
527 register_pos_map_linear(isolate, exports,
528 compatibility_new<v8::String>(isolate,
529 "ECORE_POS_MAP_LINEAR"));
530 register_pos_map_accelerate(isolate, exports,
531 compatibility_new<v8::String>(isolate,
532 "ECORE_POS_MAP"
533 "_ACCELERATE"));
534 register_pos_map_decelerate(isolate, exports,
535 compatibility_new<v8::String>(isolate,
536 "ECORE_POS_MAP"
537 "_DECELERATE"));
538 register_pos_map_sinusoidal(isolate, exports,
539 compatibility_new<v8::String>(isolate,
540 "ECORE_POS_MAP"
541 "_SINUSOIDAL"));
542 register_pos_map_accelerate_factor(isolate, exports,
543 compatibility_new<v8::String>(isolate,
544 "ECORE_POS_MAP"
545 "_ACCELERATE"
546 "_FACTOR"));
547 register_pos_map_decelerate_factor(isolate, exports,
548 compatibility_new<v8::String>(isolate,
549 "ECORE_POS_MAP"
550 "_DECELERATE"
551 "_FACTOR"));
552 register_pos_map_sinusoidal_factor(isolate, exports,
553 compatibility_new<v8::String>(isolate,
554 "ECORE_POS_MAP"
555 "_SINUSOIDAL"
556 "_FACTOR"));
557 register_pos_map_divisor_interp(isolate, exports,
558 compatibility_new<v8::String>(isolate,
559 "ECORE_POS_MAP"
560 "_DIVISOR_INTERP"));
561 register_pos_map_bounce(isolate, exports,
562 compatibility_new<v8::String>(isolate,
563 "ECORE_POS_MAP_BOUNCE"));
564 register_pos_map_spring(isolate, exports,
565 compatibility_new<v8::String>(isolate,
566 "ECORE_POS_MAP_SPRING"));
567 register_pos_map_cubic_bezier(isolate, exports,
568 compatibility_new<v8::String>(isolate,
569 "ECORE_POS_MAP_CUBIC"
570 "_BEZIER"));
571 register_animator_source_timer(isolate, exports,
572 compatibility_new<v8::String>(isolate,
573 "ECORE_ANIMATOR"
574 "_SOURCE_TIMER"));
575 register_animator_frametime_set(isolate, exports,
576 compatibility_new<v8::String>(isolate,
577 "ecore_animator"
578 "_frametime_set"));
579 register_animator_frametime_get(isolate, exports,
580 compatibility_new<v8::String>(isolate,
581 "ecore_animator"
582 "_frametime_get"));
583 register_animator_pos_map(isolate, exports,
584 compatibility_new<v8::String>(isolate,
585 "ecore_animator_pos"
586 "_map"));
587 register_animator_pos_map_n(isolate, exports,
588 compatibility_new<v8::String>(isolate,
589 "ecore_animator_pos_map"
590 "_n"));
591 register_animator_source_set(isolate, exports,
592 compatibility_new<v8::String>(isolate,
593 "ecore_animator_source"
594 "_set"));
595 register_animator_source_get(isolate, exports,
596 compatibility_new<v8::String>(isolate,
597 "ecore_animator_source"
598 "_get"));
599 register_animator_add(isolate, exports,
600 compatibility_new<v8::String>(isolate,
601 "ecore_animator_add"));
602 register_animator_timeline_add(isolate, exports,
603 compatibility_new<v8::String>(isolate,
604 "ecore_animator"
605 "_timeline_add"));
606}
607
608} } } // namespace efl { namespace js {
diff --git a/src/bindings/js/ecore_js/ecore_js_event.cc b/src/bindings/js/ecore_js/ecore_js_event.cc
new file mode 100644
index 0000000000..a086d989d6
--- /dev/null
+++ b/src/bindings/js/ecore_js/ecore_js_event.cc
@@ -0,0 +1,772 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Ecore_Js.hh>
6
7namespace efl { namespace ecore { namespace js {
8
9static Ecore_Event *extract_event(v8::Local<v8::Object> object)
10{
11 return compatibility_get_pointer_internal_field<Ecore_Event*>(object, 0);
12}
13
14static v8::Local<v8::Object> wrap_event(Ecore_Event *event,
15 v8::Isolate *isolate)
16{
17 using v8::String;
18 using v8::ObjectTemplate;
19 using v8::FunctionTemplate;
20
21 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
22 obj_tpl->SetInternalFieldCount(1);
23 auto ret = obj_tpl->NewInstance();
24
25 auto del = [](compatibility_callback_info_type info)
26 -> compatibility_return_type {
27 if (info.Length() != 0)
28 return compatibility_return();
29
30 ecore_event_del(extract_event(info.This()));
31 return compatibility_return();
32 };
33
34 ret->Set(compatibility_new<String>(isolate, "del"),
35 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
36
37 compatibility_set_pointer_internal_field(ret, 0, event);
38
39 return ret;
40}
41
42static Ecore_Event_Handler *extract_event_handler(v8::Local<v8::Object> object)
43{
44 return compatibility_get_pointer_internal_field<Ecore_Event_Handler*>
45 (object, 0);
46}
47
48static v8::Local<v8::Object> wrap_event_handler(Ecore_Event_Handler *handler,
49 v8::Isolate *isolate)
50{
51 using v8::String;
52 using v8::ObjectTemplate;
53 using v8::FunctionTemplate;
54 using v8::Value;
55
56 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
57 obj_tpl->SetInternalFieldCount(1);
58 auto ret = obj_tpl->NewInstance();
59
60 auto del = [](compatibility_callback_info_type info)
61 -> compatibility_return_type {
62 if (info.Length() != 0)
63 return compatibility_return();
64
65 auto p = ecore_event_handler_del(extract_event_handler(info.This()));
66
67 delete static_cast<efl::eina::js::global_ref<Value>*>(p);
68 return compatibility_return();
69 };
70
71 ret->Set(compatibility_new<String>(isolate, "del"),
72 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
73
74 compatibility_set_pointer_internal_field(ret, 0, handler);
75
76 return ret;
77}
78
79static Ecore_Event_Filter *extract_event_filter(v8::Local<v8::Object> object)
80{
81 return compatibility_get_pointer_internal_field<Ecore_Event_Filter*>
82 (object, 0);
83}
84
85static v8::Local<v8::Object> wrap_event_filter(Ecore_Event_Filter *filter,
86 v8::Isolate *isolate)
87{
88 using v8::String;
89 using v8::ObjectTemplate;
90 using v8::FunctionTemplate;
91 using v8::Value;
92
93 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
94 obj_tpl->SetInternalFieldCount(1);
95 auto ret = obj_tpl->NewInstance();
96
97 auto del = [](compatibility_callback_info_type info)
98 -> compatibility_return_type {
99 if (info.Length() != 0)
100 return compatibility_return();
101
102 auto p = ecore_event_filter_del(extract_event_filter(info.This()));
103 delete[] static_cast<efl::eina::js::global_ref<Value>*>(p);
104 return compatibility_return();
105 };
106
107 ret->Set(compatibility_new<String>(isolate, "del"),
108 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
109
110 compatibility_set_pointer_internal_field(ret, 0, filter);
111
112 return ret;
113}
114
115EAPI
116void register_event_none(v8::Isolate *isolate, v8::Handle<v8::Object> global,
117 v8::Handle<v8::String> name)
118{
119 using v8::Integer;
120 global->Set(name,
121 compatibility_new<Integer>(isolate, ECORE_EVENT_NONE));
122}
123
124EAPI
125void register_event_signal_user(v8::Isolate *isolate,
126 v8::Handle<v8::Object> global,
127 v8::Handle<v8::String> name)
128{
129 using v8::Integer;
130 global->Set(name,
131 compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_USER));
132}
133
134EAPI
135void register_event_signal_hup(v8::Isolate *isolate,
136 v8::Handle<v8::Object> global,
137 v8::Handle<v8::String> name)
138{
139 using v8::Integer;
140 global->Set(name,
141 compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_HUP));
142}
143
144EAPI
145void register_event_signal_exit(v8::Isolate *isolate,
146 v8::Handle<v8::Object> global,
147 v8::Handle<v8::String> name)
148{
149 using v8::Integer;
150 global->Set(name,
151 compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_EXIT));
152}
153
154EAPI
155void register_event_signal_power(v8::Isolate *isolate,
156 v8::Handle<v8::Object> global,
157 v8::Handle<v8::String> name)
158{
159 using v8::Integer;
160 global->Set(name,
161 compatibility_new<Integer>(isolate, ECORE_EVENT_SIGNAL_POWER));
162}
163
164EAPI
165void register_event_signal_realtime(v8::Isolate *isolate,
166 v8::Handle<v8::Object> global,
167 v8::Handle<v8::String> name)
168{
169 using v8::Integer;
170 global->Set(name,
171 compatibility_new<Integer>(isolate,
172 ECORE_EVENT_SIGNAL_REALTIME));
173}
174
175EAPI
176void register_event_memory_state(v8::Isolate *isolate,
177 v8::Handle<v8::Object> global,
178 v8::Handle<v8::String> name)
179{
180 using v8::Integer;
181 global->Set(name,
182 compatibility_new<Integer>(isolate, ECORE_EVENT_MEMORY_STATE));
183}
184
185EAPI
186void register_event_power_state(v8::Isolate *isolate,
187 v8::Handle<v8::Object> global,
188 v8::Handle<v8::String> name)
189{
190 using v8::Integer;
191 global->Set(name,
192 compatibility_new<Integer>(isolate, ECORE_EVENT_POWER_STATE));
193}
194
195EAPI
196void register_event_locale_changed(v8::Isolate *isolate,
197 v8::Handle<v8::Object> global,
198 v8::Handle<v8::String> name)
199{
200 using v8::Integer;
201 global->Set(name,
202 compatibility_new<Integer>(isolate,
203 ECORE_EVENT_LOCALE_CHANGED));
204}
205
206EAPI
207void register_event_hostname_changed(v8::Isolate *isolate,
208 v8::Handle<v8::Object> global,
209 v8::Handle<v8::String> name)
210{
211 using v8::Integer;
212 global->Set(name,
213 compatibility_new<Integer>(isolate,
214 ECORE_EVENT_HOSTNAME_CHANGED));
215}
216
217EAPI
218void register_event_system_timedate_changed(v8::Isolate *isolate,
219 v8::Handle<v8::Object> global,
220 v8::Handle<v8::String> name)
221{
222 using v8::Integer;
223 global->Set(name,
224 compatibility_new<Integer>(isolate,
225 ECORE_EVENT_SYSTEM_TIMEDATE_CHANGED));
226}
227
228EAPI
229void register_event_type_new(v8::Isolate *isolate,
230 v8::Handle<v8::Object> global,
231 v8::Handle<v8::String> name)
232{
233 using v8::Integer;
234 using v8::FunctionTemplate;
235
236 auto f = [](compatibility_callback_info_type args)
237 -> compatibility_return_type {
238 if (args.Length() != 0)
239 return compatibility_return();
240
241 auto isolate = args.GetIsolate();
242 auto ret = ecore_event_type_new();
243 return compatibility_return(compatibility_new<Integer>(isolate, ret),
244 args);
245 };
246
247 global->Set(name,
248 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
249}
250
251EAPI
252void register_event_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
253 v8::Handle<v8::String> name)
254{
255 using v8::FunctionTemplate;
256
257 auto f = [](compatibility_callback_info_type args)
258 -> compatibility_return_type {
259 if (args.Length() != 1 || !args[0]->IsNumber())
260 return compatibility_return();
261
262 auto isolate = args.GetIsolate();
263 auto ret = ecore_event_add(args[0]->NumberValue(), NULL, NULL, NULL);
264 return compatibility_return(wrap_event(ret, isolate), args);
265 };
266
267 global->Set(name,
268 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
269}
270
271EAPI
272void register_event_handler_add(v8::Isolate *isolate,
273 v8::Handle<v8::Object> global,
274 v8::Handle<v8::String> name)
275{
276 using v8::Integer;
277 using v8::Value;
278 using v8::Function;
279 using v8::Handle;
280 using v8::Local;
281 using v8::FunctionTemplate;
282
283 auto f = [](compatibility_callback_info_type args)
284 -> compatibility_return_type {
285 if (args.Length() != 2 || !args[0]->IsNumber()
286 || !args[1]->IsFunction()) {
287 return compatibility_return();
288 }
289
290 auto isolate = args.GetIsolate();
291
292 auto p = new efl::eina::js::global_ref<Value>(isolate, args[1]);
293
294 auto cb = [](void *d, int type, void */*event*/) -> Eina_Bool {
295 auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(d);
296 auto o = persistent->handle();
297
298 auto isolate = v8::Isolate::GetCurrent();
299 Handle<Value> args = compatibility_new<Integer>(isolate, type);
300
301 auto ret = Function::Cast(*o)->Call(o->ToObject(), 1, &args);
302 auto bret = ret->IsBoolean() && ret->BooleanValue();
303
304 return bret ? EINA_TRUE : EINA_FALSE;
305 };
306
307 auto ret = ecore_event_handler_add(args[0]->Int32Value(), cb, p);
308 return compatibility_return(wrap_event_handler(ret, isolate), args);
309 };
310
311 global->Set(name,
312 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
313}
314
315EAPI
316void register_event_filter_add(v8::Isolate *isolate,
317 v8::Handle<v8::Object> global,
318 v8::Handle<v8::String> name)
319{
320 using v8::Integer;
321 using v8::Value;
322 using v8::Function;
323 using v8::Handle;
324 using v8::Local;
325 using v8::FunctionTemplate;
326
327 auto f = [](compatibility_callback_info_type args)
328 -> compatibility_return_type {
329 if (args.Length() != 3 || !args[0]->IsFunction()
330 || !args[1]->IsFunction() || !args[2]->IsFunction()) {
331 return compatibility_return();
332 }
333
334 auto isolate = args.GetIsolate();
335
336 auto p = new efl::eina::js::global_ref<Value>[3]{{isolate, args[0]},
337 {isolate, args[1]},
338 {isolate, args[2]}};
339
340 auto start_cb = [](void *data) -> void* {
341 auto p = static_cast<efl::eina::js::global_ref<Value>*>(data);
342 auto isolate = v8::Isolate::GetCurrent();
343 auto o = p->handle();
344
345 auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
346 return new efl::eina::js::global_ref<Value>{isolate, ret};
347 };
348
349 auto filter_cb = [](void *data, void *loop_data, int type,
350 void */*event*/) -> Eina_Bool {
351 typedef efl::eina::js::global_ref<Value> p_t;
352
353 auto p = static_cast<p_t*>(data) + 1;
354 auto isolate = v8::Isolate::GetCurrent();
355 auto o = p->handle();
356
357 Handle<Value> args[2]{
358 static_cast<p_t*>(loop_data)->handle(),
359 compatibility_new<Integer>(isolate, type)
360 };
361
362 auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
363 auto bret = ret->IsBoolean() && ret->BooleanValue();
364
365 return bret ? EINA_TRUE : EINA_FALSE;
366 };
367
368 auto end_cb = [](void *user_data, void *func_data) -> void {
369 typedef efl::eina::js::global_ref<Value> p_t;
370
371 auto loop_data = std::unique_ptr<p_t>(static_cast<p_t*>
372 (func_data));
373 auto p = static_cast<p_t*>(user_data) + 2;
374 auto o = p->handle();
375
376 Handle<Value> args = p->handle();
377
378 Function::Cast(*o)->Call(o->ToObject(), 1, &args);
379 };
380
381 auto ret = ecore_event_filter_add(start_cb, filter_cb, end_cb, p);
382 return compatibility_return(wrap_event_filter(ret, isolate), args);
383 };
384
385 global->Set(name,
386 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
387}
388
389EAPI
390void register_event_current_type_get(v8::Isolate *isolate,
391 v8::Handle<v8::Object> global,
392 v8::Handle<v8::String> name)
393{
394 using v8::Integer;
395 using v8::FunctionTemplate;
396
397 auto f = [](compatibility_callback_info_type args)
398 -> compatibility_return_type {
399 if (args.Length() != 0)
400 return compatibility_return();
401
402 auto isolate = args.GetIsolate();
403 auto ret = ecore_event_current_type_get();
404 return compatibility_return(compatibility_new<Integer>(isolate, ret),
405 args);
406 };
407
408 global->Set(name,
409 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
410}
411
412EAPI
413void register_memory_state_normal(v8::Isolate *isolate,
414 v8::Handle<v8::Object> global,
415 v8::Handle<v8::String> name)
416{
417 using v8::Integer;
418 global->Set(name,
419 compatibility_new<Integer>(isolate, ECORE_MEMORY_STATE_NORMAL));
420}
421
422EAPI
423void register_memory_state_low(v8::Isolate *isolate,
424 v8::Handle<v8::Object> global,
425 v8::Handle<v8::String> name)
426{
427 using v8::Integer;
428 global->Set(name,
429 compatibility_new<Integer>(isolate, ECORE_MEMORY_STATE_LOW));
430}
431
432EAPI
433void register_power_state_mains(v8::Isolate *isolate,
434 v8::Handle<v8::Object> global,
435 v8::Handle<v8::String> name)
436{
437 using v8::Integer;
438 global->Set(name,
439 compatibility_new<Integer>(isolate, ECORE_POWER_STATE_MAINS));
440}
441
442EAPI
443void register_power_state_battery(v8::Isolate *isolate,
444 v8::Handle<v8::Object> global,
445 v8::Handle<v8::String> name)
446{
447 using v8::Integer;
448 global->Set(name,
449 compatibility_new<Integer>(isolate, ECORE_POWER_STATE_BATTERY));
450}
451
452EAPI
453void register_power_state_low(v8::Isolate *isolate,
454 v8::Handle<v8::Object> global,
455 v8::Handle<v8::String> name)
456{
457 using v8::Integer;
458 global->Set(name,
459 compatibility_new<Integer>(isolate, ECORE_POWER_STATE_LOW));
460}
461
462EAPI
463void register_memory_state_get(v8::Isolate *isolate,
464 v8::Handle<v8::Object> global,
465 v8::Handle<v8::String> name)
466{
467 using v8::Integer;
468 using v8::FunctionTemplate;
469
470 auto f = [](compatibility_callback_info_type args)
471 -> compatibility_return_type {
472 if (args.Length() != 0)
473 return compatibility_return();
474
475 auto isolate = args.GetIsolate();
476 auto ret = ecore_memory_state_get();
477 return compatibility_return(compatibility_new<Integer>(isolate, ret),
478 args);
479 };
480
481 global->Set(name,
482 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
483}
484
485EAPI
486void register_power_state_get(v8::Isolate *isolate,
487 v8::Handle<v8::Object> global,
488 v8::Handle<v8::String> name)
489{
490 using v8::Integer;
491 using v8::FunctionTemplate;
492
493 auto f = [](compatibility_callback_info_type args)
494 -> compatibility_return_type {
495 if (args.Length() != 0)
496 return compatibility_return();
497
498 auto isolate = args.GetIsolate();
499 auto ret = ecore_power_state_get();
500 return compatibility_return(compatibility_new<Integer>(isolate, ret),
501 args);
502 };
503
504 global->Set(name,
505 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
506}
507
508EAPI
509void register_event_signal_user_handler_add(v8::Isolate *isolate,
510 v8::Handle<v8::Object> global,
511 v8::Handle<v8::String> name)
512{
513 using v8::Integer;
514 using v8::String;
515 using v8::Value;
516 using v8::Object;
517 using v8::Function;
518 using v8::Handle;
519 using v8::Local;
520 using v8::FunctionTemplate;
521
522 auto f = [](compatibility_callback_info_type args)
523 -> compatibility_return_type {
524 if (args.Length() != 1 || !args[0]->IsFunction())
525 return compatibility_return();
526
527 auto isolate = args.GetIsolate();
528
529 auto p = new efl::eina::js::global_ref<Value>(isolate, args[0]);
530
531 auto cb = [](void *d, int type, void *event) -> Eina_Bool {
532 auto p = static_cast<efl::eina::js::global_ref<Value>*>(d);
533 auto isolate = v8::Isolate::GetCurrent();
534 auto o = p->handle();
535
536 auto wrapped_event = compatibility_new<Object>(isolate);
537
538 {
539 auto n
540 = reinterpret_cast<Ecore_Event_Signal_User*>(event)->number;
541 wrapped_event->Set(compatibility_new<String>(isolate, "number"),
542 compatibility_new<Integer>(isolate, n));
543 }
544
545 Handle<Value> args[2]{
546 compatibility_new<Integer>(isolate, type),
547 wrapped_event
548 };
549
550 auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
551 auto bret = ret->IsBoolean() && ret->BooleanValue();
552
553 return bret ? EINA_TRUE : EINA_FALSE;
554 };
555
556 auto ret = ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER, cb, p);
557 return compatibility_return(wrap_event_handler(ret, isolate), args);
558 };
559
560 global->Set(name,
561 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
562}
563
564EAPI
565void register_event_signal_exit_handler_add(v8::Isolate *isolate,
566 v8::Handle<v8::Object> global,
567 v8::Handle<v8::String> name)
568{
569 using v8::Integer;
570 using v8::Boolean;
571 using v8::String;
572 using v8::Value;
573 using v8::Object;
574 using v8::Function;
575 using v8::Handle;
576 using v8::Local;
577 using v8::FunctionTemplate;
578
579 auto f = [](compatibility_callback_info_type args)
580 -> compatibility_return_type {
581 if (args.Length() != 1 || !args[0]->IsFunction())
582 return compatibility_return();
583
584 auto isolate = args.GetIsolate();
585
586 auto p = new efl::eina::js::global_ref<Value>(isolate, args[0]);
587
588 auto cb = [](void *d, int type, void *ev) -> Eina_Bool {
589 auto p = static_cast<efl::eina::js::global_ref<Value>*>(d);
590 auto isolate = v8::Isolate::GetCurrent();
591 auto o = p->handle();
592
593 auto wrapped_event = compatibility_new<Object>(isolate);
594
595 {
596 auto event = reinterpret_cast<Ecore_Event_Signal_Exit*>(ev);
597 auto interrupt = event->interrupt;
598 auto quit = event->quit;
599 auto terminate = event->terminate;
600
601 wrapped_event->Set(compatibility_new<String>(isolate,
602 "interrupt"),
603 compatibility_new<Boolean>(isolate,
604 interrupt));
605 wrapped_event->Set(compatibility_new<String>(isolate, "quit"),
606 compatibility_new<Boolean>(isolate, quit));
607 wrapped_event->Set(compatibility_new<String>(isolate,
608 "terminate"),
609 compatibility_new<Boolean>(isolate,
610 terminate));
611 }
612
613 Handle<Value> args[2]{
614 compatibility_new<Integer>(isolate, type),
615 wrapped_event
616 };
617
618 auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
619 auto bret = ret->IsBoolean() && ret->BooleanValue();
620
621 return bret ? EINA_TRUE : EINA_FALSE;
622 };
623
624 auto ret = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, cb, p);
625 return compatibility_return(wrap_event_handler(ret, isolate), args);
626 };
627
628 global->Set(name,
629 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
630}
631
632EAPI
633void register_event_signal_realtime_handler_add(v8::Isolate *isolate,
634 v8::Handle<v8::Object> global,
635 v8::Handle<v8::String> name)
636{
637 using v8::Integer;
638 using v8::String;
639 using v8::Value;
640 using v8::Object;
641 using v8::Function;
642 using v8::Handle;
643 using v8::Local;
644 using v8::FunctionTemplate;
645
646 auto f = [](compatibility_callback_info_type args)
647 -> compatibility_return_type {
648 if (args.Length() != 1 || !args[0]->IsFunction())
649 return compatibility_return();
650
651 auto isolate = args.GetIsolate();
652
653 auto p = new efl::eina::js::global_ref<Value>(isolate, args[0]);
654
655 auto cb = [](void *d, int type, void *ev) -> Eina_Bool {
656 auto p = static_cast<efl::eina::js::global_ref<Value>*>(d);
657 auto isolate = v8::Isolate::GetCurrent();
658 auto o = p->handle();
659
660 auto wrapped_event = compatibility_new<Object>(isolate);
661
662 {
663 auto n
664 = reinterpret_cast<Ecore_Event_Signal_Realtime*>(ev)->num;
665 wrapped_event->Set(compatibility_new<String>(isolate, "num"),
666 compatibility_new<Integer>(isolate, n));
667 }
668
669 Handle<Value> args[2]{
670 compatibility_new<Integer>(isolate, type),
671 wrapped_event
672 };
673
674 auto ret = Function::Cast(*o)->Call(o->ToObject(), 2, args);
675 auto bret = ret->IsBoolean() && ret->BooleanValue();
676
677 return bret ? EINA_TRUE : EINA_FALSE;
678 };
679
680 auto ret = ecore_event_handler_add(ECORE_EVENT_SIGNAL_REALTIME, cb, p);
681 return compatibility_return(wrap_event_handler(ret, isolate), args);
682 };
683
684 global->Set(name,
685 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
686}
687
688EAPI
689void register_ecore_event(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
690{
691 register_event_none(isolate, exports,
692 compatibility_new<v8::String>(isolate,
693 "ECORE_EVENT_NONE"));
694 register_event_signal_user(isolate, exports,
695 compatibility_new<v8::String>
696 (isolate, "ECORE_EVENT_SIGNAL_USER"));
697 register_event_signal_hup(isolate, exports,
698 compatibility_new<v8::String>
699 (isolate, "ECORE_EVENT_SIGNAL_HUP"));
700 register_event_signal_exit(isolate, exports,
701 compatibility_new<v8::String>
702 (isolate, "ECORE_EVENT_SIGNAL_EXIT"));
703 register_event_signal_power(isolate, exports,
704 compatibility_new<v8::String>
705 (isolate, "ECORE_EVENT_SIGNAL_POWER"));
706 register_event_signal_realtime(isolate, exports,
707 compatibility_new<v8::String>
708 (isolate, "ECORE_EVENT_SIGNAL_REALTIME"));
709 register_event_memory_state(isolate, exports,
710 compatibility_new<v8::String>
711 (isolate, "ECORE_EVENT_MEMORY_STATE"));
712 register_event_power_state(isolate, exports,
713 compatibility_new<v8::String>
714 (isolate, "ECORE_EVENT_POWER_STATE"));
715 register_event_locale_changed(isolate, exports,
716 compatibility_new<v8::String>
717 (isolate, "ECORE_EVENT_LOCALE_CHANGED"));
718 register_event_hostname_changed(isolate, exports,
719 compatibility_new<v8::String>
720 (isolate, "ECORE_EVENT_HOSTNAME_CHANGED"));
721 register_event_system_timedate_changed(isolate, exports,
722 compatibility_new<v8::String>
723 (isolate,
724 "ECORE_EVENT_SYSTEM_TIMEDATE"
725 "_CHANGED"));
726 register_event_type_new(isolate, exports,
727 compatibility_new<v8::String>(isolate,
728 "ecore_event_type_new"));
729 register_event_add(isolate, exports,
730 compatibility_new<v8::String>(isolate, "ecore_event_add"));
731 register_event_handler_add(isolate, exports,
732 compatibility_new<v8::String>
733 (isolate, "ecore_event_handler_add"));
734 register_event_filter_add(isolate, exports,
735 compatibility_new<v8::String>
736 (isolate, "ecore_event_filter_add"));
737 register_event_current_type_get(isolate, exports,
738 compatibility_new<v8::String>
739 (isolate, "ecore_event_current_type_get"));
740 register_memory_state_normal(isolate, exports,
741 compatibility_new<v8::String>
742 (isolate, "ECORE_MEMORY_STATE_NORMAL"));
743 register_memory_state_low(isolate, exports,
744 compatibility_new<v8::String>
745 (isolate, "ECORE_MEMORY_STATE_LOW"));
746 register_power_state_mains(isolate, exports,
747 compatibility_new<v8::String>
748 (isolate, "ECORE_POWER_STATE_MAINS"));
749 register_power_state_battery(isolate, exports,
750 compatibility_new<v8::String>
751 (isolate, "ECORE_POWER_STATE_BATTERY"));
752 register_power_state_low(isolate, exports,
753 compatibility_new<v8::String>(isolate,
754 "ECORE_POWER_STATE_LOW"));
755 register_event_signal_user_handler_add(isolate, exports,
756 compatibility_new<v8::String>
757 (isolate,
758 "ecore_event_signal_user_handler"
759 "_add"));
760 register_event_signal_exit_handler_add(isolate, exports,
761 compatibility_new<v8::String>
762 (isolate,
763 "ecore_event_signal_exit_handler"
764 "_add"));
765 register_event_signal_realtime_handler_add(isolate, exports,
766 compatibility_new<v8::String>
767 (isolate,
768 "ecore_event_signal_realtime"
769 "_handler_add"));
770}
771
772} } } // namespace efl { namespace js {
diff --git a/src/bindings/js/ecore_js/ecore_js_idle.cc b/src/bindings/js/ecore_js/ecore_js_idle.cc
new file mode 100644
index 0000000000..293cef2f45
--- /dev/null
+++ b/src/bindings/js/ecore_js/ecore_js_idle.cc
@@ -0,0 +1,294 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Ecore_Js.hh>
6
7namespace efl { namespace ecore { namespace js {
8
9static Ecore_Idler* extract_idler(v8::Local<v8::Object> object)
10{
11 auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
12 return reinterpret_cast<Ecore_Idler*>(ptr);
13}
14
15static
16v8::Local<v8::Object> wrap_idler(Ecore_Idler *idler, v8::Isolate *isolate)
17{
18 using v8::Boolean;
19 using v8::String;
20 using v8::ObjectTemplate;
21 using v8::FunctionTemplate;
22
23 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
24 obj_tpl->SetInternalFieldCount(1);
25 auto ret = obj_tpl->NewInstance();
26
27 auto del = [](compatibility_callback_info_type info)
28 -> compatibility_return_type {
29 if (info.Length() != 0)
30 return compatibility_return();
31
32 ecore_idler_del(extract_idler(info.This()));
33 return compatibility_return();
34 };
35
36 ret->Set(compatibility_new<String>(isolate, "del"),
37 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
38
39 ret->SetInternalField(0, compatibility_new<v8::External>(isolate, idler));
40
41 return ret;
42}
43
44static Ecore_Idle_Enterer* extract_idle_enterer(v8::Local<v8::Object> object)
45{
46 auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
47 return reinterpret_cast<Ecore_Idle_Enterer*>(ptr);
48}
49
50static v8::Local<v8::Object> wrap_idle_enterer(Ecore_Idle_Enterer *idle_enterer,
51 v8::Isolate *isolate)
52{
53 using v8::Boolean;
54 using v8::String;
55 using v8::ObjectTemplate;
56 using v8::FunctionTemplate;
57 using v8::External;
58
59 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
60 obj_tpl->SetInternalFieldCount(1);
61 auto ret = obj_tpl->NewInstance();
62
63 auto del = [](compatibility_callback_info_type info)
64 -> compatibility_return_type {
65 if (info.Length() != 0)
66 return compatibility_return();
67
68 ecore_idle_enterer_del(extract_idle_enterer(info.This()));
69 return compatibility_return();
70 };
71
72 ret->Set(compatibility_new<String>(isolate, "del"),
73 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
74
75 ret->SetInternalField(0,
76 compatibility_new<External>(isolate, idle_enterer));
77
78 return ret;
79}
80
81static Ecore_Idle_Exiter* extract_idle_exiter(v8::Local<v8::Object> object)
82{
83 auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
84 return reinterpret_cast<Ecore_Idle_Exiter*>(ptr);
85}
86
87static v8::Local<v8::Object> wrap_idle_exiter(Ecore_Idle_Exiter *idle_exiter,
88 v8::Isolate *isolate)
89{
90 using v8::Boolean;
91 using v8::String;
92 using v8::ObjectTemplate;
93 using v8::FunctionTemplate;
94 using v8::External;
95
96 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
97 obj_tpl->SetInternalFieldCount(1);
98 auto ret = obj_tpl->NewInstance();
99
100 auto del = [](compatibility_callback_info_type info)
101 -> compatibility_return_type {
102 if (info.Length() != 0)
103 return compatibility_return();
104
105 ecore_idle_exiter_del(extract_idle_exiter(info.This()));
106 return compatibility_return();
107 };
108
109 ret->Set(compatibility_new<String>(isolate, "del"),
110 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
111
112 ret->SetInternalField(0, compatibility_new<External>(isolate, idle_exiter));
113
114 return ret;
115}
116
117void register_idler_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
118 v8::Handle<v8::String> name)
119{
120 using v8::Local;
121 using v8::Value;
122 using v8::Undefined;
123 using v8::Function;
124 using v8::FunctionTemplate;
125
126 auto f = [](compatibility_callback_info_type args)
127 -> compatibility_return_type {
128 if (args.Length() != 1 || !args[0]->IsFunction())
129 return compatibility_return();
130
131 auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
132 auto ret = ecore_idler_add([](void *data) -> Eina_Bool {
133 auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
134 auto o = persistent->handle();
135
136 auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
137 auto bret = ret->IsBoolean() && ret->BooleanValue();
138
139 if (!bret)
140 {
141 persistent->dispose();
142 delete persistent;
143 }
144
145 return bret ? EINA_TRUE : EINA_FALSE;
146 }, f);
147
148 return compatibility_return(wrap_idler(ret, args.GetIsolate()), args);
149 };
150
151 global->Set(name,
152 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
153}
154
155void register_idle_enterer_add(v8::Isolate *isolate,
156 v8::Handle<v8::Object> global,
157 v8::Handle<v8::String> name)
158{
159 using v8::Local;
160 using v8::Value;
161 using v8::Undefined;
162 using v8::Function;
163 using v8::FunctionTemplate;
164
165 auto f = [](compatibility_callback_info_type args)
166 -> compatibility_return_type {
167 if (args.Length() != 1 || !args[0]->IsFunction())
168 return compatibility_return();
169
170 auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
171 auto ret = ecore_idle_enterer_add([](void *data) -> Eina_Bool {
172 auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
173 auto o = persistent->handle();
174
175 auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
176 auto bret = ret->IsBoolean() && ret->BooleanValue();
177
178 if (!bret)
179 {
180 persistent->dispose();
181 delete persistent;
182 }
183
184 return bret ? EINA_TRUE : EINA_FALSE;
185 }, f);
186
187 return compatibility_return(wrap_idle_enterer(ret, args.GetIsolate()),
188 args);
189 };
190
191 global->Set(name,
192 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
193}
194
195void register_idle_enterer_before_add(v8::Isolate *isolate,
196 v8::Handle<v8::Object> global,
197 v8::Handle<v8::String> name)
198{
199 using v8::Local;
200 using v8::Value;
201 using v8::Undefined;
202 using v8::Function;
203 using v8::FunctionTemplate;
204
205 auto f = [](compatibility_callback_info_type args)
206 -> compatibility_return_type {
207 if (args.Length() != 1 || !args[0]->IsFunction())
208 return compatibility_return();
209
210 auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
211 auto ret = ecore_idle_enterer_before_add([](void *data) -> Eina_Bool {
212 auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
213 auto o = persistent->handle();
214
215 auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
216 auto bret = ret->IsBoolean() && ret->BooleanValue();
217
218 if (!bret)
219 {
220 persistent->dispose();
221 delete persistent;
222 }
223
224 return bret ? EINA_TRUE : EINA_FALSE;
225 }, f);
226
227 return compatibility_return(wrap_idle_enterer(ret, args.GetIsolate()),
228 args);
229 };
230
231 global->Set(name,
232 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
233}
234
235void register_idle_exiter_add(v8::Isolate *isolate,
236 v8::Handle<v8::Object> global,
237 v8::Handle<v8::String> name)
238{
239 using v8::Local;
240 using v8::Value;
241 using v8::Undefined;
242 using v8::Function;
243 using v8::FunctionTemplate;
244
245 auto f = [](compatibility_callback_info_type args)
246 -> compatibility_return_type {
247 if (args.Length() != 1 || !args[0]->IsFunction())
248 return compatibility_return();
249
250 auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
251 auto ret = ecore_idle_exiter_add([](void *data) -> Eina_Bool {
252 auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
253 auto o = persistent->handle();
254
255 auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
256 auto bret = ret->IsBoolean() && ret->BooleanValue();
257
258 if (!bret)
259 {
260 persistent->dispose();
261 delete persistent;
262 }
263
264 return bret ? EINA_TRUE : EINA_FALSE;
265 }, f);
266
267 return compatibility_return(wrap_idle_exiter(ret, args.GetIsolate()),
268 args);
269 };
270
271 global->Set(name,
272 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
273}
274
275EAPI
276void register_ecore_idle(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
277{
278 register_idler_add(isolate, exports,
279 compatibility_new<v8::String>(isolate, "ecore_idler_add"));
280 register_idle_enterer_add(isolate, exports,
281 compatibility_new<v8::String>(isolate,
282 "ecore_idle_enterer"
283 "_add"));
284 register_idle_enterer_before_add(isolate, exports,
285 compatibility_new<v8::String>(isolate,
286 "ecore_idle"
287 "_enterer_before"
288 "_add"));
289 register_idle_exiter_add(isolate, exports,
290 compatibility_new<v8::String>(isolate,
291 "ecore_idle_exiter_add"));
292}
293
294} } } // namespace efl { namespace js {
diff --git a/src/bindings/js/ecore_js/ecore_js_init.cc b/src/bindings/js/ecore_js/ecore_js_init.cc
new file mode 100644
index 0000000000..ba2b04f842
--- /dev/null
+++ b/src/bindings/js/ecore_js/ecore_js_init.cc
@@ -0,0 +1,76 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Ecore_Js.hh>
6
7namespace efl { namespace ecore { namespace js {
8
9namespace {
10
11void register_init(v8::Isolate *isolate, v8::Handle<v8::Object> global,
12 v8::Handle<v8::String> name)
13{
14 using v8::Integer;
15 using v8::FunctionTemplate;
16
17 auto init = [](compatibility_callback_info_type args)
18 -> compatibility_return_type {
19 if (args.Length() != 0)
20 return compatibility_return();
21
22 auto isolate = args.GetIsolate();
23 auto ret = ::ecore_init();
24 return compatibility_return(compatibility_new<Integer>(isolate, ret),
25 args);
26 };
27
28 global->Set(name,
29 compatibility_new<FunctionTemplate>(isolate, init)
30 ->GetFunction());
31}
32
33void register_shutdown(v8::Isolate *isolate, v8::Handle<v8::Object> global,
34 v8::Handle<v8::String> name)
35{
36 using v8::Integer;
37 using v8::FunctionTemplate;
38
39 auto shutdown = [](compatibility_callback_info_type args)
40 -> compatibility_return_type {
41 if (args.Length() != 0)
42 return compatibility_return();
43
44 auto isolate = args.GetIsolate();
45 auto ret = ecore_shutdown();
46 return compatibility_return(compatibility_new<Integer>(isolate, ret),
47 args);
48 };
49
50 global->Set(name,
51 compatibility_new<FunctionTemplate>(isolate, shutdown)
52 ->GetFunction());
53}
54
55}
56
57EAPI
58void register_ecore(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
59{
60 efl::ecore::js::register_init(isolate, exports,
61 efl::eina::js::compatibility_new<v8::String>
62 (isolate, "ecore_init"));
63 efl::ecore::js::register_shutdown(isolate, exports,
64 efl::eina::js::compatibility_new<v8::String>
65 (isolate, "ecore_shutdown"));
66 register_ecore_animator(isolate, exports);
67 register_ecore_event(isolate, exports);
68 register_ecore_idle(isolate, exports);
69 register_ecore_job(isolate, exports);
70 register_ecore_mainloop(isolate, exports);
71 register_ecore_poller(isolate, exports);
72 register_ecore_throttle(isolate, exports);
73 register_ecore_timer(isolate, exports);
74}
75
76} } } // namespace efl { namespace js {
diff --git a/src/bindings/js/ecore_js/ecore_js_job.cc b/src/bindings/js/ecore_js/ecore_js_job.cc
new file mode 100644
index 0000000000..4ec438aaaf
--- /dev/null
+++ b/src/bindings/js/ecore_js/ecore_js_job.cc
@@ -0,0 +1,83 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Ecore_Js.hh>
6
7namespace efl { namespace ecore { namespace js {
8
9static Ecore_Job* extract_job(v8::Local<v8::Object> object)
10{
11 auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
12 return reinterpret_cast<Ecore_Job*>(ptr);
13}
14
15static v8::Local<v8::Object> wrap_job(Ecore_Job *job, v8::Isolate *isolate)
16{
17 using v8::Boolean;
18 using v8::String;
19 using v8::ObjectTemplate;
20 using v8::FunctionTemplate;
21
22 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
23 obj_tpl->SetInternalFieldCount(1);
24 auto ret = obj_tpl->NewInstance();
25
26 auto del = [](compatibility_callback_info_type info)
27 -> compatibility_return_type {
28 if (info.Length() != 0)
29 return compatibility_return();
30
31 ecore_job_del(extract_job(info.This()));
32 return compatibility_return();
33 };
34
35 ret->Set(compatibility_new<String>(isolate, "del"),
36 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
37
38 ret->SetInternalField(0, compatibility_new<v8::External>(isolate, job));
39
40 return ret;
41}
42
43EAPI
44void register_job_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
45 v8::Handle<v8::String> name)
46{
47 using v8::Local;
48 using v8::Value;
49 using v8::Undefined;
50 using v8::Function;
51 using v8::FunctionTemplate;
52
53 auto f = [](compatibility_callback_info_type args)
54 -> compatibility_return_type {
55 if (args.Length() != 1 || !args[0]->IsFunction())
56 return compatibility_return();
57
58 auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
59 auto ret = ecore_job_add([](void *data) {
60 auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
61 auto o = persistent->handle();
62
63 Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
64
65 persistent->dispose();
66 delete persistent;
67 }, f);
68
69 return compatibility_return(wrap_job(ret, args.GetIsolate()), args);
70 };
71
72 global->Set(name,
73 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
74}
75
76EAPI
77void register_ecore_job(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
78{
79 register_job_add(isolate, exports,
80 compatibility_new<v8::String>(isolate, "ecore_job_add"));
81}
82
83} } } // namespace efl { namespace js {
diff --git a/src/bindings/js/ecore_js/ecore_js_mainloop.cc b/src/bindings/js/ecore_js/ecore_js_mainloop.cc
new file mode 100644
index 0000000000..180b35f0f6
--- /dev/null
+++ b/src/bindings/js/ecore_js/ecore_js_mainloop.cc
@@ -0,0 +1,207 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Ecore_Js.hh>
6
7namespace efl { namespace ecore { namespace js {
8
9namespace {
10
11void register_callback_cancel(v8::Isolate *isolate,
12 v8::Handle<v8::Object> global,
13 v8::Handle<v8::String> name)
14{
15 using v8::Boolean;
16 global->Set(name, compatibility_new<Boolean>(isolate,
17 bool{ECORE_CALLBACK_CANCEL}));
18}
19
20void register_callback_renew(v8::Isolate *isolate,
21 v8::Handle<v8::Object> global,
22 v8::Handle<v8::String> name)
23{
24 using v8::Boolean;
25 global->Set(name, compatibility_new<Boolean>(isolate,
26 bool{ECORE_CALLBACK_RENEW}));
27}
28
29void register_callback_pass_on(v8::Isolate *isolate,
30 v8::Handle<v8::Object> global,
31 v8::Handle<v8::String> name)
32{
33 using v8::Boolean;
34 global->Set(name, compatibility_new<Boolean>(isolate,
35 bool{ECORE_CALLBACK_PASS_ON}));
36}
37
38void register_callback_done(v8::Isolate *isolate, v8::Handle<v8::Object> global,
39 v8::Handle<v8::String> name)
40{
41 using v8::Boolean;
42 global->Set(name, compatibility_new<Boolean>(isolate,
43 bool{ECORE_CALLBACK_DONE}));
44}
45
46void register_mainloop_iterate(v8::Isolate *isolate,
47 v8::Handle<v8::Object> global,
48 v8::Handle<v8::String> name)
49{
50 using v8::Integer;
51 using v8::FunctionTemplate;
52
53 auto f = [](compatibility_callback_info_type args)
54 -> compatibility_return_type {
55 if (args.Length() != 0)
56 return compatibility_return();
57
58 ecore_main_loop_iterate();
59 return compatibility_return();
60 };
61
62 global->Set(name,
63 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
64}
65
66void register_mainloop_iterate_may_block(v8::Isolate *isolate,
67 v8::Handle<v8::Object> global,
68 v8::Handle<v8::String> name)
69{
70 using v8::Integer;
71 using v8::FunctionTemplate;
72
73 auto f = [](compatibility_callback_info_type args)
74 -> compatibility_return_type {
75 if (args.Length() != 1 || !args[0]->IsNumber())
76 return compatibility_return();
77
78 auto ret = ecore_main_loop_iterate_may_block(args[0]->NumberValue());
79 return compatibility_return(compatibility_new<Integer>
80 (args.GetIsolate(), ret), args);
81 };
82
83 global->Set(name,
84 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
85}
86
87void register_mainloop_begin(v8::Isolate *isolate,
88 v8::Handle<v8::Object> global,
89 v8::Handle<v8::String> name)
90{
91 using v8::Integer;
92 using v8::FunctionTemplate;
93
94 auto f = [](compatibility_callback_info_type args)
95 -> compatibility_return_type {
96 if (args.Length() != 0)
97 return compatibility_return();
98
99 ecore_main_loop_begin();
100 return compatibility_return();
101 };
102
103 global->Set(name,
104 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
105}
106
107void register_mainloop_quit(v8::Isolate *isolate, v8::Handle<v8::Object> global,
108 v8::Handle<v8::String> name)
109{
110 using v8::Integer;
111 using v8::FunctionTemplate;
112
113 auto f = [](compatibility_callback_info_type args)
114 -> compatibility_return_type {
115 if (args.Length() != 0)
116 return compatibility_return();
117
118 ecore_main_loop_quit();
119 return compatibility_return();
120 };
121
122 global->Set(name,
123 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
124}
125
126void register_mainloop_animator_ticked_get(v8::Isolate *isolate,
127 v8::Handle<v8::Object> global,
128 v8::Handle<v8::String> name)
129{
130 using v8::Boolean;
131 using v8::FunctionTemplate;
132
133 auto f = [](compatibility_callback_info_type args)
134 -> compatibility_return_type {
135 if (args.Length() != 0)
136 return compatibility_return();
137
138 auto ret = ecore_main_loop_animator_ticked_get();
139 return compatibility_return(compatibility_new<Boolean>
140 (args.GetIsolate(), ret), args);
141 };
142
143 global->Set(name,
144 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
145}
146
147void register_mainloop_nested_get(v8::Isolate *isolate,
148 v8::Handle<v8::Object> global,
149 v8::Handle<v8::String> name)
150{
151 using v8::Boolean;
152 using v8::FunctionTemplate;
153
154 auto f = [](compatibility_callback_info_type args)
155 -> compatibility_return_type {
156 if (args.Length() != 0)
157 return compatibility_return();
158
159 auto ret = ecore_main_loop_nested_get();
160 return compatibility_return(compatibility_new<Boolean>
161 (args.GetIsolate(), ret), args);
162 };
163
164 global->Set(name,
165 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
166}
167
168}
169
170EAPI
171void register_ecore_mainloop(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
172{
173 register_callback_cancel(isolate, exports,
174 compatibility_new<v8::String>
175 (isolate, "ECORE_CALLBACK_CANCEL"));
176 register_callback_renew(isolate, exports,
177 compatibility_new<v8::String>
178 (isolate, "ECORE_CALLBACK_RENEW"));
179 register_callback_pass_on(isolate, exports,
180 compatibility_new<v8::String>
181 (isolate, "ECORE_CALLBACK_PASS_ON"));
182 register_callback_done(isolate, exports,
183 compatibility_new<v8::String>
184 (isolate, "ECORE_CALLBACK_DONE"));
185 register_mainloop_iterate(isolate, exports,
186 compatibility_new<v8::String>
187 (isolate, "ecore_mainloop_iterate"));
188 register_mainloop_iterate_may_block(isolate, exports,
189 compatibility_new<v8::String>
190 (isolate,
191 "ecore_mainloop_iterate_may_block"));
192 register_mainloop_begin(isolate, exports,
193 compatibility_new<v8::String>
194 (isolate, "ecore_mainloop_begin"));
195 register_mainloop_quit(isolate, exports,
196 compatibility_new<v8::String>
197 (isolate, "ecore_mainloop_quit"));
198 register_mainloop_animator_ticked_get(isolate, exports,
199 compatibility_new<v8::String>
200 (isolate,
201 "ecore_mainlop_animator_ticked_get"));
202 register_mainloop_nested_get(isolate, exports,
203 compatibility_new<v8::String>
204 (isolate, "ecore_mainloop_nested_get"));
205}
206
207} } } // namespace efl { namespace js {
diff --git a/src/bindings/js/ecore_js/ecore_js_poller.cc b/src/bindings/js/ecore_js/ecore_js_poller.cc
new file mode 100644
index 0000000000..e3bfbc843a
--- /dev/null
+++ b/src/bindings/js/ecore_js/ecore_js_poller.cc
@@ -0,0 +1,190 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Ecore_Js.hh>
6
7namespace efl { namespace ecore { namespace js {
8
9namespace {
10
11Ecore_Poller* extract_poller(v8::Local<v8::Object> object)
12{
13 auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
14 return reinterpret_cast<Ecore_Poller*>(ptr);
15}
16
17v8::Local<v8::Object> wrap_poller(Ecore_Poller *poller,
18 v8::Isolate *isolate)
19{
20 using v8::Boolean;
21 using v8::String;
22 using v8::ObjectTemplate;
23 using v8::FunctionTemplate;
24
25 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
26 obj_tpl->SetInternalFieldCount(1);
27 auto ret = obj_tpl->NewInstance();
28
29 auto del = [](compatibility_callback_info_type info)
30 -> compatibility_return_type {
31 if (info.Length() != 0)
32 return compatibility_return();
33
34 ecore_poller_del(extract_poller(info.This()));
35 return compatibility_return();
36 };
37
38 ret->Set(compatibility_new<String>(isolate, "del"),
39 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
40
41 ret->SetInternalField(0, compatibility_new<v8::External>(isolate, poller));
42
43 return ret;
44}
45
46void register_poller_core(v8::Isolate *isolate, v8::Handle<v8::Object> global,
47 v8::Handle<v8::String> name)
48{
49 using v8::Integer;
50
51 global->Set(name, compatibility_new<Integer>(isolate, ECORE_POLLER_CORE));
52}
53
54void register_poller_poll_interval_set(v8::Isolate *isolate,
55 v8::Handle<v8::Object> global,
56 v8::Handle<v8::String> name)
57{
58 using v8::Integer;
59 using v8::FunctionTemplate;
60
61 auto f = [](compatibility_callback_info_type args)
62 -> compatibility_return_type {
63 if (args.Length() != 2 || !args[0]->IsNumber() || !args[1]->IsNumber())
64 return compatibility_return();
65
66 Ecore_Poller_Type type;
67
68 switch ((int)(args[0]->NumberValue())) {
69 case ECORE_POLLER_CORE:
70 type = ECORE_POLLER_CORE;
71 break;
72 default:
73 return compatibility_return();
74 }
75
76 ecore_poller_poll_interval_set(type, args[1]->NumberValue());
77 return compatibility_return();
78 };
79
80 global->Set(name,
81 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
82}
83
84void register_poller_poll_interval_get(v8::Isolate *isolate,
85 v8::Handle<v8::Object> global,
86 v8::Handle<v8::String> name)
87{
88 using v8::Integer;
89 using v8::FunctionTemplate;
90
91 auto f = [](compatibility_callback_info_type args)
92 -> compatibility_return_type {
93 if (args.Length() != 1 || !args[0]->IsNumber())
94 return compatibility_return();
95
96 Ecore_Poller_Type type;
97
98 switch ((int)(args[0]->NumberValue())) {
99 case ECORE_POLLER_CORE:
100 type = ECORE_POLLER_CORE;
101 break;
102 default:
103 return compatibility_return();
104 }
105
106 auto isolate = args.GetIsolate();
107 auto ret = ecore_poller_poll_interval_get(type);
108 return compatibility_return(compatibility_new<Integer>(isolate, ret),
109 args);
110 };
111
112 global->Set(name,
113 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
114}
115
116void register_poller_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
117 v8::Handle<v8::String> name)
118{
119 using v8::Integer;
120 using v8::Value;
121 using v8::FunctionTemplate;
122 using v8::Isolate;
123 using v8::Function;
124
125 auto f = [](compatibility_callback_info_type args)
126 -> compatibility_return_type {
127 if (args.Length() != 3 || !args[0]->IsNumber() || !args[1]->IsNumber()
128 || !args[2]->IsFunction()) {
129 return compatibility_return();
130 }
131
132 Ecore_Poller_Type type;
133
134 switch ((int)(args[0]->NumberValue())) {
135 case ECORE_POLLER_CORE:
136 type = ECORE_POLLER_CORE;
137 break;
138 default:
139 return compatibility_return();
140 }
141
142 auto isolate = args.GetIsolate();
143 auto f = new efl::eina::js::global_ref<Value>(isolate, args[2]);
144
145 auto cb = [](void *data) -> Eina_Bool {
146 auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
147 auto o = persistent->handle();
148
149 auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
150 auto bret = ret->IsBoolean() && ret->BooleanValue();
151
152 if (!bret)
153 {
154 persistent->dispose();
155 delete persistent;
156 }
157
158 return bret ? EINA_TRUE : EINA_FALSE;
159 };
160
161 auto ret = ecore_poller_add(type, args[1]->NumberValue(), cb, f);
162 return compatibility_return(wrap_poller(ret, isolate), args);
163 };
164
165 global->Set(name,
166 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
167}
168
169}
170
171EAPI
172void register_ecore_poller(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
173{
174 register_poller_core(isolate, exports,
175 compatibility_new<v8::String>(isolate, "ECORE_POLLER_CORE"));
176 register_poller_poll_interval_set(isolate, exports,
177 compatibility_new<v8::String>(isolate,
178 "ecore_poller"
179 "_poll_interval"
180 "_set"));
181 register_poller_poll_interval_get(isolate, exports,
182 compatibility_new<v8::String>(isolate,
183 "ecore_poller"
184 "_poll_interval"
185 "_get"));
186 register_poller_add(isolate, exports,
187 compatibility_new<v8::String>(isolate, "ecore_poller_add"));
188}
189
190} } } // namespace efl { namespace js {
diff --git a/src/bindings/js/ecore_js/ecore_js_throttle.cc b/src/bindings/js/ecore_js/ecore_js_throttle.cc
new file mode 100644
index 0000000000..830a40fec6
--- /dev/null
+++ b/src/bindings/js/ecore_js/ecore_js_throttle.cc
@@ -0,0 +1,63 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Ecore_Js.hh>
6
7namespace efl { namespace ecore { namespace js {
8
9namespace {
10
11void register_throttle_adjust(v8::Isolate *isolate,
12 v8::Handle<v8::Object> global,
13 v8::Handle<v8::String> name)
14{
15 using v8::FunctionTemplate;
16
17 auto f = [](compatibility_callback_info_type args)
18 -> compatibility_return_type {
19 if (args.Length() != 1 || !args[0]->IsNumber())
20 return compatibility_return();
21
22 ecore_throttle_adjust(args[0]->NumberValue());
23 };
24
25 global->Set(name,
26 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
27}
28
29void register_throttle_get(v8::Isolate *isolate, v8::Handle<v8::Object> global,
30 v8::Handle<v8::String> name)
31{
32 using v8::Number;
33 using v8::FunctionTemplate;
34
35 auto f = [](compatibility_callback_info_type args)
36 -> compatibility_return_type {
37 if (args.Length() != 0)
38 return compatibility_return();
39
40 auto isolate = args.GetIsolate();
41 auto ret = ecore_throttle_get();
42 return compatibility_return(compatibility_new<Number>(isolate, ret),
43 args);
44 };
45
46 global->Set(name,
47 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
48}
49
50}
51
52EAPI
53void register_ecore_throttle(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
54{
55 register_throttle_adjust(isolate, exports,
56 compatibility_new<v8::String>(isolate,
57 "ecore_throttle_adjust"));
58 register_throttle_get(isolate, exports,
59 compatibility_new<v8::String>(isolate,
60 "ecore_throttle_get"));
61}
62
63} } } // namespace efl { namespace js {
diff --git a/src/bindings/js/ecore_js/ecore_js_timer.cc b/src/bindings/js/ecore_js/ecore_js_timer.cc
new file mode 100644
index 0000000000..f22100c6a7
--- /dev/null
+++ b/src/bindings/js/ecore_js/ecore_js_timer.cc
@@ -0,0 +1,232 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Ecore_Js.hh>
6
7#include <memory>
8#include <cstdlib>
9
10namespace efl { namespace ecore { namespace js {
11
12namespace {
13
14Ecore_Timer* extract_timer(v8::Local<v8::Object> object)
15{
16 auto ptr = v8::External::Cast(*object->GetInternalField(0))->Value();
17 return reinterpret_cast<Ecore_Timer*>(ptr);
18}
19
20v8::Local<v8::Object> wrap_timer(Ecore_Timer *timer,
21 v8::Isolate *isolate)
22{
23 using v8::Boolean;
24 using v8::String;
25 using v8::ObjectTemplate;
26 using v8::FunctionTemplate;
27
28 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
29 obj_tpl->SetInternalFieldCount(1);
30 auto ret = obj_tpl->NewInstance();
31
32 auto del = [](compatibility_callback_info_type info)
33 -> compatibility_return_type {
34 if (info.Length() != 0)
35 return compatibility_return();
36
37 ecore_timer_del(extract_timer(info.This()));
38 return compatibility_return();
39 };
40
41 auto freeze = [](compatibility_callback_info_type info)
42 -> compatibility_return_type {
43 if (info.Length() != 0)
44 return compatibility_return();
45
46 ecore_timer_freeze(extract_timer(info.This()));
47 return compatibility_return();
48 };
49
50 auto freeze_get = [](compatibility_callback_info_type info)
51 -> compatibility_return_type {
52 if (info.Length() != 0)
53 return compatibility_return();
54
55 auto ret = ecore_timer_freeze_get(extract_timer(info.This()));
56 return compatibility_return(compatibility_new<Boolean>
57 (info.GetIsolate(), bool(ret)),
58 info);
59 };
60
61 auto thaw = [](compatibility_callback_info_type info)
62 -> compatibility_return_type {
63 if (info.Length() != 0)
64 return compatibility_return();
65
66 ecore_timer_thaw(extract_timer(info.This()));
67 return compatibility_return();
68 };
69
70 ret->Set(compatibility_new<String>(isolate, "del"),
71 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
72 ret->Set(compatibility_new<String>(isolate, "freeze"),
73 compatibility_new<FunctionTemplate>(isolate, freeze)
74 ->GetFunction());
75 ret->Set(compatibility_new<String>(isolate, "freeze_get"),
76 compatibility_new<FunctionTemplate>(isolate, freeze_get)
77 ->GetFunction());
78 ret->Set(compatibility_new<String>(isolate, "thaw"),
79 compatibility_new<FunctionTemplate>(isolate, thaw)->GetFunction());
80
81 ret->SetInternalField(0, compatibility_new<v8::External>(isolate, timer));
82
83 return ret;
84}
85
86void register_timer_precision_get(v8::Isolate *isolate,
87 v8::Handle<v8::Object> global,
88 v8::Handle<v8::String> name)
89{
90 using v8::Number;
91 using v8::FunctionTemplate;
92
93 auto f = [](compatibility_callback_info_type args)
94 -> compatibility_return_type {
95 if (args.Length() != 0)
96 return compatibility_return();
97
98 auto ret = ecore_timer_precision_get();
99 return compatibility_return(compatibility_new<Number>
100 (args.GetIsolate(), ret), args);
101 };
102
103 global->Set(name,
104 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
105}
106
107void register_timer_precision_set(v8::Isolate *isolate,
108 v8::Handle<v8::Object> global,
109 v8::Handle<v8::String> name)
110{
111 using v8::FunctionTemplate;
112
113 auto f = [](compatibility_callback_info_type args)
114 -> compatibility_return_type {
115 if (args.Length() != 1 || !args[0]->IsNumber())
116 return compatibility_return();
117
118 ecore_timer_precision_set(args[0]->NumberValue());
119 return compatibility_return();
120 };
121
122 global->Set(name,
123 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
124}
125
126void register_timer_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
127 v8::Handle<v8::String> name)
128{
129 using v8::Local;
130 using v8::Value;
131 using v8::Undefined;
132 using v8::Function;
133 using v8::FunctionTemplate;
134
135 auto f = [](compatibility_callback_info_type args)
136 -> compatibility_return_type {
137 if (args.Length() != 2 || !args[0]->IsNumber()
138 || !args[1]->IsFunction()) {
139 return compatibility_return();
140 }
141
142 auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[1]);
143
144 auto cb = [](void *data) -> Eina_Bool {
145 auto persistent = reinterpret_cast<efl::eina::js::global_ref<Value>*>(data);
146 auto o = persistent->handle();
147
148 auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
149 auto bret = ret->IsBoolean() && ret->BooleanValue();
150
151 if (!bret)
152 {
153 persistent->dispose();
154 delete persistent;
155 }
156
157 return bret ? EINA_TRUE : EINA_FALSE;
158 };
159
160 auto ret = ecore_timer_add(args[0]->NumberValue(), cb, f);
161 return compatibility_return(wrap_timer(ret, args.GetIsolate()), args);
162 };
163
164 global->Set(name,
165 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
166}
167
168void register_timer_loop_add(v8::Isolate *isolate,
169 v8::Handle<v8::Object> global,
170 v8::Handle<v8::String> name)
171{
172 using v8::Local;
173 using v8::Value;
174 using v8::Undefined;
175 using v8::Function;
176 using v8::FunctionTemplate;
177
178 auto f = [](compatibility_callback_info_type args)
179 -> compatibility_return_type {
180 if (args.Length() != 2 || !args[0]->IsNumber()
181 || !args[1]->IsFunction()) {
182 return compatibility_return();
183 }
184
185 auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[1]);
186
187 auto cb = [](void *d) -> Eina_Bool {
188 auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(d);
189 auto o = persistent->handle();
190
191 auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
192 auto bret = ret->IsBoolean() && ret->BooleanValue();
193
194 if (!bret)
195 {
196 persistent->dispose();
197 delete persistent;
198 }
199
200 return bret ? EINA_TRUE : EINA_FALSE;
201 };
202
203 auto ret = ecore_timer_loop_add(args[0]->NumberValue(), cb, f);
204
205 return compatibility_return(wrap_timer(ret, args.GetIsolate()), args);
206 };
207
208 global->Set(name,
209 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
210}
211
212}
213
214EAPI
215void register_ecore_timer(v8::Isolate *isolate,v8::Handle<v8::Object> exports)
216{
217 register_timer_precision_get(isolate, exports,
218 compatibility_new<v8::String>(isolate,
219 "ecore_timer_precision"
220 "_get"));
221 register_timer_precision_set(isolate, exports,
222 compatibility_new<v8::String>(isolate,
223 "ecore_timer_precision"
224 "_set"));
225 register_timer_add(isolate, exports,
226 compatibility_new<v8::String>(isolate, "ecore_timer_add"));
227 register_timer_loop_add(isolate, exports,
228 compatibility_new<v8::String>(isolate,
229 "ecore_timer_loop_add"));
230}
231
232} } } // namespace efl { namespace ecore { namespace js {
diff --git a/src/bindings/js/ecore_js/ecore_js_timer.hh b/src/bindings/js/ecore_js/ecore_js_timer.hh
new file mode 100644
index 0000000000..e002587ee4
--- /dev/null
+++ b/src/bindings/js/ecore_js/ecore_js_timer.hh
@@ -0,0 +1,38 @@
1#ifndef ECORE_JS_TIMER_HH
2#define ECORE_JS_TIMER_HH
3
4#include <Eina.hh>
5
6#include <Eina_Js.hh>
7
8namespace efl { namespace ecore { namespace js {
9
10using ::efl::eina::js::compatibility_new;
11using ::efl::eina::js::compatibility_return_type;
12using ::efl::eina::js::compatibility_callback_info_type;
13using ::efl::eina::js::compatibility_return;
14using ::efl::eina::js::compatibility_get_pointer_internal_field;
15using ::efl::eina::js::compatibility_set_pointer_internal_field;
16using ::efl::eina::js::compatibility_persistent;
17
18void register_timer_precision_get(v8::Isolate *isolate,
19 v8::Handle<v8::Object> global,
20 v8::Handle<v8::String> name);
21
22void register_timer_precision_set(v8::Isolate *isolate,
23 v8::Handle<v8::Object> global,
24 v8::Handle<v8::String> name);
25
26void register_timer_dump(v8::Isolate *isolate, v8::Handle<v8::Object> global,
27 v8::Handle<v8::String> name);
28
29void register_timer_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
30 v8::Handle<v8::String> name);
31
32void register_timer_loop_add(v8::Isolate *isolate,
33 v8::Handle<v8::Object> global,
34 v8::Handle<v8::String> name);
35
36} } } // namespace efl::js
37
38#endif /* ECORE_JS_TIMER_HH */
diff --git a/src/bindings/js/efl_js/Efl_Js.hh b/src/bindings/js/efl_js/Efl_Js.hh
new file mode 100644
index 0000000000..f494b385ce
--- /dev/null
+++ b/src/bindings/js/efl_js/Efl_Js.hh
@@ -0,0 +1,30 @@
1#ifndef EFL_EFL_JS_HH
2#define EFL_EFL_JS_HH
3
4#include <Eina.hh>
5
6#ifdef EAPI
7# undef EAPI
8#endif
9
10#ifdef _WIN32
11# define EAPI __declspec(dllexport)
12#else
13# ifdef __GNUC__
14# if __GNUC__ >= 4
15# define EAPI __attribute__ ((visibility("default")))
16# else
17# define EAPI
18# endif
19# else
20# define EAPI
21# endif
22#endif /* ! _WIN32 */
23
24namespace efl_js {
25
26EAPI void init(v8::Handle<v8::Object> exports);
27
28}
29
30#endif
diff --git a/src/bindings/js/efl_js/efl_js.cc b/src/bindings/js/efl_js/efl_js.cc
new file mode 100644
index 0000000000..5665559b65
--- /dev/null
+++ b/src/bindings/js/efl_js/efl_js.cc
@@ -0,0 +1,241 @@
1
2#ifdef HAVE_CONFIG_H
3#include <config.h>
4#endif
5
6#include <Efl.h>
7#include <Efl_Config.h>
8#include <Ecore.h>
9#include <Ecore_Evas.h>
10#include <Eina.hh>
11#include <Eina_Js.hh>
12#include <Ecore_Js.hh>
13#include <Eio_Js.hh>
14#include <Eldbus_Js.hh>
15#include <Ethumb_Js.hh>
16
17#include <iostream>
18
19#ifdef EAPI
20# undef EAPI
21#endif
22
23#ifdef _WIN32
24# define EAPI __declspec(dllexport)
25#else
26# ifdef __GNUC__
27# if __GNUC__ >= 4
28# define EAPI __attribute__ ((visibility("default")))
29# else
30# define EAPI
31# endif
32# else
33# define EAPI
34# endif
35#endif /* ! _WIN32 */
36
37EAPI void eina_container_register(v8::Handle<v8::Object>, v8::Isolate* isolate);
38EAPI void eina_log_register(v8::Handle<v8::Object>, v8::Isolate* isolate);
39EAPI void eina_value_register(v8::Handle<v8::Object>, v8::Isolate* isolate);
40EAPI void register_ecore_mainloop(v8::Handle<v8::Object> global, v8::Isolate* isolate);
41
42namespace ecore {
43EAPI void register_exe(v8::Handle<v8::Object> global, v8::Isolate* isolate);
44EAPI void register_idler(v8::Handle<v8::Object> global, v8::Isolate* isolate);
45EAPI void register_ecore(v8::Isolate* isolate, v8::Handle<v8::Object> exports);
46namespace idle {
47EAPI void register_enterer(v8::Handle<v8::Object> global, v8::Isolate* isolate);
48EAPI void register_exiter(v8::Handle<v8::Object> global, v8::Isolate* isolate);
49}
50EAPI void register_job(v8::Handle<v8::Object> global, v8::Isolate* isolate);
51EAPI void register_parent(v8::Handle<v8::Object> global, v8::Isolate* isolate);
52EAPI void register_poller(v8::Handle<v8::Object> global, v8::Isolate* isolate);
53EAPI void register_timer(v8::Handle<v8::Object> global, v8::Isolate* isolate);
54namespace con {
55EAPI void register_base(v8::Handle<v8::Object> global, v8::Isolate* isolate);
56EAPI void register_client(v8::Handle<v8::Object> global, v8::Isolate* isolate);
57EAPI void register_connector(v8::Handle<v8::Object> global, v8::Isolate* isolate);
58EAPI void register_server(v8::Handle<v8::Object> global, v8::Isolate* isolate);
59}
60}
61
62namespace efl { namespace network {
63EAPI void register_url(v8::Handle<v8::Object> global, v8::Isolate* isolate);
64}}
65
66EAPI void register_ecore_audio(v8::Handle<v8::Object> global, v8::Isolate* isolate);
67EAPI void register_ecore_audio_in(v8::Handle<v8::Object> global, v8::Isolate* isolate);
68EAPI void register_ecore_audio_in_sndfile(v8::Handle<v8::Object> global, v8::Isolate* isolate);
69EAPI void register_ecore_audio_in_tone(v8::Handle<v8::Object> global, v8::Isolate* isolate);
70EAPI void register_ecore_audio_out(v8::Handle<v8::Object> global, v8::Isolate* isolate);
71EAPI void register_ecore_audio_out_pulse(v8::Handle<v8::Object> global, v8::Isolate* isolate);
72EAPI void register_ecore_audio_out_sndfile(v8::Handle<v8::Object> global, v8::Isolate* isolate);
73
74namespace efl {
75EAPI void register_control(v8::Handle<v8::Object> global, v8::Isolate* isolate);
76EAPI void register_file(v8::Handle<v8::Object> global, v8::Isolate* isolate);
77EAPI void register_image(v8::Handle<v8::Object> global, v8::Isolate* isolate);
78EAPI void register_player(v8::Handle<v8::Object> global, v8::Isolate* isolate);
79EAPI void register_text(v8::Handle<v8::Object> global, v8::Isolate* isolate);
80EAPI void register_text_properties(v8::Handle<v8::Object> global, v8::Isolate* isolate);
81}
82
83namespace eo {
84EAPI void register_abstract_class(v8::Handle<v8::Object> global, v8::Isolate* isolate);
85EAPI void register_base(v8::Handle<v8::Object> global, v8::Isolate* isolate);
86}
87
88namespace evas {
89EAPI void register_box(v8::Handle<v8::Object> global, v8::Isolate* isolate);
90EAPI void register_canvas(v8::Handle<v8::Object> global, v8::Isolate* isolate);
91EAPI void register_clickable_interface(v8::Handle<v8::Object> global, v8::Isolate* isolate);
92EAPI void register_common_interface(v8::Handle<v8::Object> global, v8::Isolate* isolate);
93EAPI void register_draggable_interface(v8::Handle<v8::Object> global, v8::Isolate* isolate);
94EAPI void register_grid(v8::Handle<v8::Object> global, v8::Isolate* isolate);
95EAPI void register_image(v8::Handle<v8::Object> global, v8::Isolate* isolate);
96EAPI void register_line(v8::Handle<v8::Object> global, v8::Isolate* isolate);
97EAPI void register_object(v8::Handle<v8::Object> global, v8::Isolate* isolate);
98EAPI void register_object_smart(v8::Handle<v8::Object> global, v8::Isolate* isolate);
99EAPI void register_out(v8::Handle<v8::Object> global, v8::Isolate* isolate);
100EAPI void register_polygon(v8::Handle<v8::Object> global, v8::Isolate* isolate);
101EAPI void register_rectangle(v8::Handle<v8::Object> global, v8::Isolate* isolate);
102EAPI void register_scrollable_interface(v8::Handle<v8::Object> global, v8::Isolate* isolate);
103EAPI void register_selectable_interface(v8::Handle<v8::Object> global, v8::Isolate* isolate);
104EAPI void register_signal_interface(v8::Handle<v8::Object> global, v8::Isolate* isolate);
105EAPI void register_smart_clipped(v8::Handle<v8::Object> global, v8::Isolate* isolate);
106EAPI void register_table(v8::Handle<v8::Object> global, v8::Isolate* isolate);
107EAPI void register_text(v8::Handle<v8::Object> global, v8::Isolate* isolate);
108EAPI void register_textblock(v8::Handle<v8::Object> global, v8::Isolate* isolate);
109EAPI void register_textgrid(v8::Handle<v8::Object> global, v8::Isolate* isolate);
110EAPI void register_zoomable_interface(v8::Handle<v8::Object> global, v8::Isolate* isolate);
111
112namespace canvas3d {
113EAPI void register_camera(v8::Handle<v8::Object> global, v8::Isolate* isolate);
114EAPI void register_light(v8::Handle<v8::Object> global, v8::Isolate* isolate);
115EAPI void register_material(v8::Handle<v8::Object> global, v8::Isolate* isolate);
116EAPI void register_mesh(v8::Handle<v8::Object> global, v8::Isolate* isolate);
117EAPI void register_node(v8::Handle<v8::Object> global, v8::Isolate* isolate);
118EAPI void register_object(v8::Handle<v8::Object> global, v8::Isolate* isolate);
119EAPI void register_scene(v8::Handle<v8::Object> global, v8::Isolate* isolate);
120EAPI void register_texture(v8::Handle<v8::Object> global, v8::Isolate* isolate);
121} }
122
123namespace edje {
124EAPI void register_edit(v8::Handle<v8::Object> global, v8::Isolate* isolate);
125EAPI void register_object(v8::Handle<v8::Object> global, v8::Isolate* isolate);
126}
127
128namespace emotion {
129EAPI void register_object(v8::Handle<v8::Object> global, v8::Isolate* isolate);
130}
131
132#ifdef HAVE_NODEJS
133
134#include <eina_js_node.hh>
135
136namespace {
137#else
138namespace efl_js {
139#endif
140
141EAPI void init(v8::Handle<v8::Object> exports)
142{
143 ::eina_init();
144 ::ecore_init();
145 ::ecore_file_init();
146 ::ecore_evas_init();
147 ::eo_init();
148 ::eio_init();
149 ::evas_init();
150 try
151 {
152 eina_container_register(exports, v8::Isolate::GetCurrent());
153 eina_log_register(exports, v8::Isolate::GetCurrent());
154 eina_value_register(exports, v8::Isolate::GetCurrent());
155 register_ecore_mainloop(exports, v8::Isolate::GetCurrent());
156 efl::ecore::js::register_ecore(v8::Isolate::GetCurrent(), exports);
157 efl::eio::js::register_eio(v8::Isolate::GetCurrent(), exports);
158 efl::eldbus::js::register_eldbus(v8::Isolate::GetCurrent(), exports);
159 efl::ethumb::js::register_ethumb(v8::Isolate::GetCurrent(), exports);
160 ecore::register_exe(exports, v8::Isolate::GetCurrent());
161 ecore::register_idler(exports, v8::Isolate::GetCurrent());
162 ecore::idle::register_enterer(exports, v8::Isolate::GetCurrent());
163 ecore::idle::register_exiter(exports, v8::Isolate::GetCurrent());
164 ecore::register_job(exports, v8::Isolate::GetCurrent());
165 ecore::register_parent(exports, v8::Isolate::GetCurrent());
166 ecore::register_poller(exports, v8::Isolate::GetCurrent());
167 ecore::register_timer(exports, v8::Isolate::GetCurrent());
168 ecore::con::register_base(exports, v8::Isolate::GetCurrent());
169 ecore::con::register_client(exports, v8::Isolate::GetCurrent());
170 ecore::con::register_connector(exports, v8::Isolate::GetCurrent());
171 ecore::con::register_server(exports, v8::Isolate::GetCurrent());
172 efl::network::register_url(exports, v8::Isolate::GetCurrent());
173#if 1
174 register_ecore_audio(exports, v8::Isolate::GetCurrent());
175 register_ecore_audio_in(exports, v8::Isolate::GetCurrent());
176 register_ecore_audio_in_sndfile(exports, v8::Isolate::GetCurrent());
177 register_ecore_audio_in_tone(exports, v8::Isolate::GetCurrent());
178 register_ecore_audio_out(exports, v8::Isolate::GetCurrent());
179 register_ecore_audio_out_pulse(exports, v8::Isolate::GetCurrent());
180 register_ecore_audio_out_sndfile(exports, v8::Isolate::GetCurrent());
181#endif
182 efl::register_control(exports, v8::Isolate::GetCurrent());
183 efl::register_file(exports, v8::Isolate::GetCurrent());
184 efl::register_image(exports, v8::Isolate::GetCurrent());
185 efl::register_player(exports, v8::Isolate::GetCurrent());
186 efl::register_text(exports, v8::Isolate::GetCurrent());
187 efl::register_text_properties(exports, v8::Isolate::GetCurrent());
188 eo::register_abstract_class(exports, v8::Isolate::GetCurrent());
189 eo::register_base(exports, v8::Isolate::GetCurrent());
190#if 1
191 evas::register_box(exports, v8::Isolate::GetCurrent());
192 evas::register_canvas(exports, v8::Isolate::GetCurrent());
193 evas::register_clickable_interface(exports, v8::Isolate::GetCurrent());
194 evas::register_common_interface(exports, v8::Isolate::GetCurrent());
195 evas::register_draggable_interface(exports, v8::Isolate::GetCurrent());
196 evas::register_grid(exports, v8::Isolate::GetCurrent());
197 evas::register_image(exports, v8::Isolate::GetCurrent());
198 evas::register_line(exports, v8::Isolate::GetCurrent());
199 evas::register_object(exports, v8::Isolate::GetCurrent());
200 evas::register_object_smart(exports, v8::Isolate::GetCurrent());
201 evas::register_out(exports, v8::Isolate::GetCurrent());
202 evas::register_polygon(exports, v8::Isolate::GetCurrent());
203 evas::register_rectangle(exports, v8::Isolate::GetCurrent());
204 evas::register_scrollable_interface(exports, v8::Isolate::GetCurrent());
205 evas::register_selectable_interface(exports, v8::Isolate::GetCurrent());
206 evas::register_signal_interface(exports, v8::Isolate::GetCurrent());
207 evas::register_smart_clipped(exports, v8::Isolate::GetCurrent());
208 evas::register_table(exports, v8::Isolate::GetCurrent());
209 evas::register_text(exports, v8::Isolate::GetCurrent());
210 evas::register_textblock(exports, v8::Isolate::GetCurrent());
211 evas::register_textgrid(exports, v8::Isolate::GetCurrent());
212 evas::register_zoomable_interface(exports, v8::Isolate::GetCurrent());
213 evas::canvas3d::register_camera(exports, v8::Isolate::GetCurrent());
214 evas::canvas3d::register_light(exports, v8::Isolate::GetCurrent());
215 evas::canvas3d::register_material(exports, v8::Isolate::GetCurrent());
216 evas::canvas3d::register_mesh(exports, v8::Isolate::GetCurrent());
217 evas::canvas3d::register_node(exports, v8::Isolate::GetCurrent());
218 evas::canvas3d::register_object(exports, v8::Isolate::GetCurrent());
219 evas::canvas3d::register_scene(exports, v8::Isolate::GetCurrent());
220 evas::canvas3d::register_texture(exports, v8::Isolate::GetCurrent());
221#endif
222#if 1
223 edje::register_edit(exports, v8::Isolate::GetCurrent());
224 edje::register_object(exports, v8::Isolate::GetCurrent());
225#endif
226#if 1
227 emotion::register_object(exports, v8::Isolate::GetCurrent());
228#endif
229 }
230 catch(...)
231 {
232 std::cout << "Exception" << std::endl;
233 }
234}
235
236#ifdef HAVE_NODEJS
237}
238NODE_MODULE(efl, init)
239#else
240} // namespace efl
241#endif
diff --git a/src/bindings/js/eina_js/Eina_Js.hh b/src/bindings/js/eina_js/Eina_Js.hh
new file mode 100644
index 0000000000..b193b5461c
--- /dev/null
+++ b/src/bindings/js/eina_js/Eina_Js.hh
@@ -0,0 +1,50 @@
1
2#ifndef EFL_EINA_JS_HH
3#define EFL_EINA_JS_HH
4
5#include <Eina.hh>
6#include <eo_concrete.hh>
7
8#ifdef EAPI
9# undef EAPI
10#endif
11
12#ifdef _WIN32
13# ifdef EFL_EINA_JS_BUILD
14# ifdef DLL_EXPORT
15# define EAPI __declspec(dllexport)
16# else
17# define EAPI
18# endif /* ! DLL_EXPORT */
19# else
20# define EAPI __declspec(dllimport)
21# endif /* ! EFL_ECORE_BUILD */
22#else
23# ifdef __GNUC__
24# if __GNUC__ >= 4
25# define EAPI __attribute__ ((visibility("default")))
26# else
27# define EAPI
28# endif
29# else
30# define EAPI
31# endif
32#endif /* ! _WIN32 */
33
34#include <eina_js_container.hh>
35#include <eina_js_accessor.hh>
36#include <eina_js_array.hh>
37#include <eina_js_compatibility.hh>
38#include <eina_js_error.hh>
39#include <eina_js_get_value_from_c.hh>
40#include <eina_js_get_value.hh>
41#include <eina_js_iterator.hh>
42#include <eina_js_list.hh>
43#include <eina_js_log.hh>
44#include <eina_js_value.hh>
45#include <eina_js_log.hh>
46
47#undef EAPI
48#define EAPI
49
50#endif
diff --git a/src/bindings/js/eina_js/eina_js_accessor.cc b/src/bindings/js/eina_js/eina_js_accessor.cc
new file mode 100644
index 0000000000..d6891547ed
--- /dev/null
+++ b/src/bindings/js/eina_js/eina_js_accessor.cc
@@ -0,0 +1,34 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Eina.hh>
6
7#include <Eina_Js.hh>
8
9#include <iostream>
10
11namespace efl { namespace eina { namespace js {
12
13EAPI void register_destroy_accessor(v8::Isolate *isolate,
14 v8::Handle<v8::Object> global,
15 v8::Handle<v8::String> name)
16{
17 typedef void (*deleter_t)(void*);
18
19 auto f = [](compatibility_callback_info_type info) -> compatibility_return_type
20 {
21 if (info.Length() != 1 || !info[0]->IsObject())
22 return compatibility_return();
23
24 v8::Handle<v8::Object> o = info[0]->ToObject();
25
26 deleter_t deleter = compatibility_get_pointer_internal_field<deleter_t>(o, 1);
27 deleter(compatibility_get_pointer_internal_field<>(o, 0));
28 return compatibility_return();
29 };
30
31 global->Set(name, compatibility_new<v8::FunctionTemplate>(isolate, f)->GetFunction());
32}
33
34} } } // namespace efl { namespace js {
diff --git a/src/bindings/js/eina_js/eina_js_accessor.hh b/src/bindings/js/eina_js/eina_js_accessor.hh
new file mode 100644
index 0000000000..abf3090fed
--- /dev/null
+++ b/src/bindings/js/eina_js/eina_js_accessor.hh
@@ -0,0 +1,87 @@
1#ifndef EINA_JS_ACCESSOR_HH
2#define EINA_JS_ACCESSOR_HH
3
4#include <memory>
5
6#include <eina_js_value.hh>
7#include <eina_js_compatibility.hh>
8#include <eina_js_get_value.hh>
9#include <eina_js_get_value_from_c.hh>
10
11#include <iostream>
12
13namespace efl { namespace eina { namespace js {
14
15template <typename T, typename A>
16js::compatibility_return_type accessor_get(js::compatibility_callback_info_type info)
17{
18 v8::Isolate* isolate = info.GetIsolate();
19 if (info.Length() != 1 || !info[0]->IsNumber())
20 return js::compatibility_return();
21
22 auto idx = js::get_value_from_javascript
23 (info[0], isolate, "", js::value_tag<std::size_t>());
24
25 std::string class_name;
26 if (info.Data()->IsString())
27 {
28 v8::String::Utf8Value str(info.Data());
29 class_name = *str;
30 }
31
32 void *ptr = compatibility_get_pointer_internal_field(info.Holder(), 0);
33
34 return compatibility_return
35 (::efl::eina::js::get_value_from_c
36 (js::wrap_value<T>(container_unwrap((*static_cast<A*>(ptr))[idx]), js::value_tag<T>{})
37 , isolate, class_name.c_str()), info);
38};
39
40/* Creates a copy from \p a accessor and exports it to be manipulated by the JS
41 code */
42template <typename T, typename W>
43inline v8::Local<v8::Object> export_accessor(::efl::eina::accessor<W> &a, v8::Isolate *isolate, const char* class_name)
44{
45 typedef ::efl::eina::accessor<W> accessor_type;
46
47 static efl::eina::js::global_ref<v8::ObjectTemplate> obj_tpl
48 (isolate,
49 [&]()
50 {
51 auto obj_tpl = compatibility_new<v8::ObjectTemplate>(isolate);
52 (*obj_tpl)->SetInternalFieldCount(1);
53
54 // TODO: (*obj_tpl)->SetIndexedPropertyHandler(&accessor_get<accessor_type>);
55
56 (*obj_tpl)->Set(js::compatibility_new<v8::String>(isolate, "get")
57 , js::compatibility_new<v8::FunctionTemplate>(isolate
58 , &accessor_get<T, accessor_type>
59 , js::compatibility_new<v8::String>(isolate, class_name)));
60 return obj_tpl;
61 }());
62
63 auto instance = obj_tpl.handle()->NewInstance();
64 compatibility_set_pointer_internal_field(instance, 0, &a);
65 return instance;
66}
67
68/* Extracts and returns a copy from the internal accessor object from the JS
69 object */
70template <typename T>
71::efl::eina::accessor<T>& import_accessor(v8::Handle<v8::Object> o)
72{
73 typedef ::efl::eina::accessor<T> accessor_type;
74
75 void* ptr = compatibility_get_pointer_internal_field(o, 0);
76
77 return *static_cast<accessor_type*>(ptr);
78}
79
80/* Registers the function to destroy the accessor objects to the JS code */
81void register_destroy_accessor(v8::Isolate *isolate,
82 v8::Handle<v8::Object> global,
83 v8::Handle<v8::String> name);
84
85} } } // namespace efl::js
86
87#endif /* EINA_JS_ACCESSOR_HH */
diff --git a/src/bindings/js/eina_js/eina_js_array.hh b/src/bindings/js/eina_js/eina_js_array.hh
new file mode 100644
index 0000000000..9cdd142e7c
--- /dev/null
+++ b/src/bindings/js/eina_js/eina_js_array.hh
@@ -0,0 +1,119 @@
1#ifndef EINA_JS_ARRAY_HH
2#define EINA_JS_ARRAY_HH
3
4#include <iostream>
5
6#include <iterator>
7
8#include <eina_js_container.hh>
9
10namespace efl { namespace eina { namespace js {
11
12template <typename T, typename K, typename W>
13struct eina_array : eina_container_common<efl::eina::array
14 <W
15 , typename std::conditional
16 <std::is_base_of<efl::eo::concrete, W>::value
17 , efl::eina::eo_clone_allocator
18 , efl::eina::malloc_clone_allocator
19 >::type>, T, K>
20{
21 typedef eina_container_common<efl::eina::array<W
22 , typename std::conditional
23 <std::is_base_of<efl::eo::concrete, W>::value
24 , efl::eina::eo_clone_allocator
25 , efl::eina::malloc_clone_allocator
26 >::type>, T, K> base_type;
27 using base_type::base_type;
28 typedef typename base_type::container_type container_type;
29
30 eina_container_base* concat(eina_container_base const& other) const
31 {
32 return detail::concat(*this, other);
33 }
34 eina_container_base* slice(std::int64_t i, std::int64_t j) const
35 {
36 return detail::slice(*this, i, j);
37 }
38 v8::Local<v8::Value> set(v8::Isolate* isolate, std::size_t index, v8::Local<v8::Value> v)
39 {
40 return detail::set<T,W>(isolate, *this, index, v);
41 }
42 int push(v8::Isolate* isolate, v8::Local<v8::Value> v)
43 {
44 return detail::push<T,W>(isolate, *this, v);
45 }
46 v8::Local<v8::Value> pop(v8::Isolate* isolate)
47 {
48 return detail::pop<T,W,K>(isolate, *this);
49 }
50 js::container_type get_container_type() const { return array_container_type; }
51};
52
53template <typename T, typename K, typename W>
54struct range_eina_array : eina_container_common<efl::eina::range_array<W>, T, K>
55{
56 typedef eina_container_common<efl::eina::range_array<W>, T, K> base_type;
57 using base_type::base_type;
58 typedef typename base_type::container_type container_type;
59 typedef typename std::conditional
60 <std::is_base_of<efl::eo::concrete, W>::value
61 , efl::eina::eo_clone_allocator
62 , efl::eina::malloc_clone_allocator
63 >::type clone_allocator_type;
64
65 eina_container_base* concat(eina_container_base const& other) const
66 {
67 range_eina_array<T, K, W> const& rhs = static_cast<range_eina_array<T, K, W>const&>(other);
68 efl::eina::array<W, clone_allocator_type>
69 array(this->_container.begin(), this->_container.end());
70 array.insert(array.end(), rhs._container.begin(), rhs._container.end());
71 return new eina_array<T, K, W>(array.release_native_handle());
72 }
73 eina_container_base* slice(std::int64_t i, std::int64_t j) const
74 {
75 efl::eina::array<W, clone_allocator_type>
76 array(std::next(this->_container.begin(), i), std::next(this->_container.begin(), j));
77 return new eina_array<T, K, W>(array.release_native_handle());
78 }
79 js::container_type get_container_type() const { return array_container_type; }
80};
81
82// Problematic types.
83template <>
84struct eina_array<_Elm_Calendar_Mark*, js::nonclass_cls_name_getter, _Elm_Calendar_Mark>
85 : empty_container_base
86{ eina_array(Eina_Array const*){} };
87template <>
88struct eina_array<Elm_Gen_Item*, js::nonclass_cls_name_getter, Elm_Gen_Item>
89 : empty_container_base
90{ eina_array(Eina_Array const*){} };
91template <>
92struct eina_array<_Evas_Textblock_Rectangle*, js::nonclass_cls_name_getter, _Evas_Textblock_Rectangle>
93 : empty_container_base
94{ eina_array(Eina_Array const*){} };
95template <>
96struct eina_array<_Elm_Map_Overlay*, js::nonclass_cls_name_getter, _Elm_Map_Overlay>
97 : empty_container_base
98{ eina_array(Eina_Array const*){} };
99
100template <>
101struct range_eina_array<_Elm_Calendar_Mark*, js::nonclass_cls_name_getter, _Elm_Calendar_Mark>
102 : empty_container_base
103{ range_eina_array(Eina_Array const*){} };
104template <>
105struct range_eina_array<Elm_Gen_Item*, js::nonclass_cls_name_getter, Elm_Gen_Item>
106 : empty_container_base
107{ range_eina_array(Eina_Array const*){} };
108template <>
109struct range_eina_array<_Evas_Textblock_Rectangle*, js::nonclass_cls_name_getter, _Evas_Textblock_Rectangle>
110 : empty_container_base
111{ range_eina_array(Eina_Array const*){} };
112template <>
113struct range_eina_array<_Elm_Map_Overlay*, js::nonclass_cls_name_getter, _Elm_Map_Overlay>
114 : empty_container_base
115{ range_eina_array(Eina_Array const*){} };
116
117} } }
118
119#endif
diff --git a/src/bindings/js/eina_js/eina_js_compatibility.cc b/src/bindings/js/eina_js/eina_js_compatibility.cc
new file mode 100644
index 0000000000..a1d992f59e
--- /dev/null
+++ b/src/bindings/js/eina_js/eina_js_compatibility.cc
@@ -0,0 +1,12 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Eina.hh>
6#include <Eina_Js.hh>
7
8namespace efl { namespace eina { namespace js {
9
10std::map<std::string, v8::Local<v8::Function>> constructors_map_;
11
12} } }
diff --git a/src/bindings/js/eina_js/eina_js_compatibility.hh b/src/bindings/js/eina_js/eina_js_compatibility.hh
new file mode 100644
index 0000000000..9ef0cb814e
--- /dev/null
+++ b/src/bindings/js/eina_js/eina_js_compatibility.hh
@@ -0,0 +1,918 @@
1#ifndef EFL_EINA_JS_COMPATIBILITY_HH
2#define EFL_EINA_JS_COMPATIBILITY_HH
3
4#include <type_traits>
5#include <utility>
6#include <map>
7#include <string>
8#include <cstdlib>
9
10
11#ifdef HAVE_NODE_V8_H
12#include <node/v8.h>
13#elif defined(HAVE_NODEJS_DEPS_V8_V8_H)
14#include <nodejs/deps/v8/v8.h>
15#elif defined(HAVE_NODEJS_DEPS_V8_INCLUDE_V8_H)
16#include <nodejs/deps/v8/include/v8.h>
17#elif defined(HAVE_NODEJS_SRC_V8_H)
18#include <nodejs/src/v8.h>
19#elif defined(HAVE_V8_H)
20#include <v8.h>
21#else
22#error We must have at least one v8 header to include
23#endif
24
25namespace v8 {
26
27template <typename T>
28struct FunctionCallbackInfo;
29template <typename T>
30struct PropertyCallbackInfo;
31template <typename T>
32#ifdef HAVE_V8_GLOBAL
33struct Global;
34#else
35struct UniquePersistent;
36#endif
37
38class AccessorInfo;
39
40class Arguments;
41
42}
43
44namespace efl { namespace eina { namespace js {
45
46template <typename T>
47struct value_tag
48{
49 typedef T type;
50};
51
52template <typename T, typename... U>
53struct complex_tag
54{
55 T value;
56 typedef std::tuple<U...> inner_types;
57};
58
59template <typename T>
60struct make_tag_traits
61{
62 typedef typename std::remove_reference<T>::type a1;
63 typedef typename std::conditional
64 <std::is_pointer<T>::value
65 , typename std::remove_cv<T>::type
66 , T>::type type;
67};
68
69template <typename T, typename... U>
70using make_complex_tag = complex_tag<typename make_tag_traits<T>::type
71 , typename make_tag_traits<U>::type...>;
72
73template <typename T>
74struct struct_tag
75{
76 T value;
77};
78
79template <typename T>
80using make_struct_tag = struct_tag<typename make_tag_traits<T>::type>;
81
82template <typename T>
83struct struct_ptr_tag
84{
85 T value;
86};
87
88template <typename T>
89using make_struct_ptr_tag = struct_ptr_tag<typename make_tag_traits<T>::type>;
90
91template <typename T, typename... Ts>
92struct remove_tag
93{
94 typedef T type;
95};
96
97template <typename T, typename... U>
98struct remove_tag<complex_tag<T, U...>>
99{
100 typedef typename eina::js::remove_tag<T, U...>::type type;
101};
102
103template <typename T>
104struct remove_tag<struct_tag<T>>
105{
106 typedef typename eina::js::remove_tag<T>::type type;
107};
108
109template <typename T>
110struct remove_tag<struct_ptr_tag<T>>
111{
112 typedef typename eina::js::remove_tag<T>::type type;
113};
114
115template <typename T>
116struct is_handable_by_value
117{
118 static constexpr bool value = !std::is_class<T>::value || std::is_same<T, ::efl::eo::concrete>::value;
119};
120
121template <typename... T>
122struct container_wrapper
123{
124 typedef typename eina::js::remove_tag<T...>::type _notag_type;
125 typedef typename std::conditional<
126 std::is_convertible<_notag_type, Eo const* const>::value
127 , typename std::conditional<
128 std::is_const<typename std::remove_pointer<_notag_type>::type>::value
129 , ::efl::eo::concrete const
130 , ::efl::eo::concrete
131 >::type
132 , _notag_type
133 >::type type;
134};
135
136template <typename T>
137T container_wrap(T&& v)
138{
139 return std::forward<T>(v);
140}
141
142inline ::efl::eo::concrete container_wrap(Eo* v)
143{
144 if(v)
145 eo_ref(v);
146 return ::efl::eo::concrete{v};
147}
148
149inline ::efl::eo::concrete container_wrap(Eo const* v)
150{
151 if (v)
152 eo_ref(v);
153 return ::efl::eo::concrete{const_cast<Eo*>(v)};
154}
155
156template <typename T>
157T& container_unwrap(T& v)
158{
159 return v;
160}
161
162inline Eo* container_unwrap(::efl::eo::concrete& v)
163{
164 return v._eo_ptr();
165}
166
167inline Eo* container_unwrap(::efl::eo::concrete const& v)
168{
169 return v._eo_ptr();
170}
171
172template <typename T>
173struct is_complex_tag : std::false_type {};
174
175template <typename... T>
176struct is_complex_tag<complex_tag<T...>> : std::true_type {};
177
178template <typename T>
179struct is_struct_tag : std::false_type {};
180
181template <typename T>
182struct is_struct_tag<struct_tag<T>> : std::true_type {};
183
184template <typename T>
185struct is_struct_ptr_tag : std::false_type {};
186
187template <typename T>
188struct is_struct_ptr_tag<struct_ptr_tag<T>> : std::true_type {};
189
190template <typename T>
191struct is_type_tag
192{
193 static constexpr bool value =
194 is_complex_tag<T>::value
195 || is_struct_tag<T>::value
196 || is_struct_ptr_tag<T>::value;
197};
198
199
200// Class name getters
201struct cls_name_getter_base {};
202struct cls_name_getter_generated_base : cls_name_getter_base {};
203/// Name getter for types that are not classes
204struct nonclass_cls_name_getter : cls_name_getter_base
205{
206 static char const* class_name() { return ""; }
207};
208
209// JS container base
210enum container_type
211{
212 list_container_type
213 , array_container_type
214 , container_type_size
215};
216
217struct eina_container_base
218{
219 virtual ~eina_container_base() {}
220
221 virtual std::size_t size() const = 0;
222 virtual eina_container_base* concat(eina_container_base const& rhs) const = 0;
223 virtual eina_container_base* slice(std::int64_t i, std::int64_t j) const = 0;
224 virtual int index_of(v8::Isolate* isolate, v8::Local<v8::Value> v) const = 0;
225 virtual int last_index_of(v8::Isolate* isolate, v8::Local<v8::Value> v) const = 0;
226 virtual v8::Local<v8::Value> get(v8::Isolate*, std::size_t) const = 0;
227 virtual v8::Local<v8::Value> set(v8::Isolate* isolate, std::size_t index, v8::Local<v8::Value> v) = 0;
228 virtual int push(v8::Isolate* isolate, v8::Local<v8::Value> v) = 0;
229 virtual v8::Local<v8::Value> pop(v8::Isolate* isolate) = 0;
230 virtual v8::Local<v8::String> to_string(v8::Isolate*) const = 0;
231 virtual v8::Local<v8::String> join(v8::Isolate*, v8::Local<v8::Value> separator) const = 0;
232 virtual container_type get_container_type() const = 0;
233 virtual void* get_container_native_handle() = 0;
234 virtual void const* get_container_native_handle() const = 0;
235};
236
237// Containers forward declarations
238
239// Array
240template <typename T, typename K = nonclass_cls_name_getter, typename W = typename container_wrapper<T>::type>
241struct eina_array;
242template <typename T, typename K = nonclass_cls_name_getter, typename W = typename container_wrapper<T>::type>
243struct range_eina_array;
244
245EAPI v8::Handle<v8::Function> get_array_instance_template();
246
247// List
248template <typename T, typename K = nonclass_cls_name_getter, typename W = typename container_wrapper<T>::type>
249struct eina_list;
250template <typename T, typename K = nonclass_cls_name_getter, typename W = typename container_wrapper<T>::type>
251struct range_eina_list;
252
253EAPI v8::Handle<v8::Function> get_list_instance_template();
254
255// Accessor
256template <typename T, typename W>
257v8::Local<v8::Object> export_accessor(::efl::eina::accessor<W>&, v8::Isolate*, const char*);
258
259template <typename T>
260::efl::eina::accessor<T>& import_accessor(v8::Handle<v8::Object>);
261
262// Wrap value functions
263template <typename R, typename T>
264typename std::remove_cv<typename std::remove_reference<R>::type>::type
265wrap_value(T v, value_tag<R>
266 , typename std::enable_if<!is_type_tag<typename std::remove_cv<R>::type>::value>::type* = 0)
267{
268 return v;
269}
270
271template <typename R, typename T>
272R wrap_value(T const& v, value_tag<eina::js::struct_tag<T>>)
273{
274 return R {v};
275}
276
277template <typename R, typename T>
278R wrap_value(T v, value_tag<eina::js::struct_ptr_tag<T>>)
279{
280 return R {v};
281}
282
283template <typename R, typename T, typename... U>
284R wrap_value(T v, value_tag<eina::js::complex_tag<T, U...>>)
285{
286 return R {v};
287}
288
289template <typename T = v8::External>
290struct _libv8_isolate_test
291{
292 using new_signature = v8::Local<T>(*)(v8::Isolate*, void*);
293 static const bool value = std::is_same<decltype(static_cast<new_signature>(&T::New)), new_signature>::value;
294};
295
296template <typename T = v8::FunctionTemplate, typename Enable = void>
297struct _libv8_callback_info_test;
298
299typedef v8::Handle<v8::Value>(*_libv8_invocation_callback)(v8::Arguments const&);
300
301template <typename T>
302struct _libv8_callback_info_test
303<T, typename std::enable_if
304 <!std::is_same<decltype( & T::SetCallHandler)
305 , void (T::*)(_libv8_invocation_callback, v8::Handle<v8::Value>)>::value>::type>
306 : std::true_type
307{
308};
309
310template <typename T>
311struct _libv8_callback_info_test
312<T, typename std::enable_if
313 <std::is_same<decltype( & T::SetCallHandler)
314 , void (T::*)(_libv8_invocation_callback, v8::Handle<v8::Value>)>::value>::type>
315 : std::false_type
316{
317};
318
319template <typename T = v8::ObjectTemplate, typename Enable = void>
320struct _libv8_property_callback_info_test
321 : std::true_type {};
322
323typedef v8::Handle<v8::Value>(*_libv8_getter_callback)(v8::Local<v8::String>, v8::AccessorInfo const&);
324typedef void(*_libv8_setter_callback)(v8::Local<v8::String>, v8::Local<v8::Value>, v8::AccessorInfo const&);
325
326template <typename T>
327struct _libv8_property_callback_info_test
328<T, typename std::enable_if
329 <std::is_same<decltype( & T::SetAccessor)
330 , void (T::*)
331 (v8::Handle<v8::String>
332 , _libv8_getter_callback
333 , _libv8_setter_callback
334 , v8::Handle<v8::Value>
335 , v8::AccessControl
336 , v8::PropertyAttribute
337 , v8::Handle<v8::AccessorSignature>
338 )>::value>::type>
339 : std::false_type
340{
341};
342
343static constexpr bool const v8_uses_isolate = _libv8_isolate_test<>::value;
344static constexpr bool const v8_uses_callback_info = _libv8_callback_info_test<>::value;
345static constexpr bool const v8_uses_property_callback_info = _libv8_property_callback_info_test<>::value;
346
347using compatibility_return_type = std::conditional<v8_uses_callback_info, void, v8::Handle<v8::Value> >::type;
348using compatibility_callback_info_type
349 = std::conditional<v8_uses_callback_info, v8::FunctionCallbackInfo<v8::Value> const&, v8::Arguments const&>
350 ::type;
351using compatibility_callback_info_pointer
352 = std::conditional<v8_uses_callback_info, v8::FunctionCallbackInfo<v8::Value> const*, v8::Arguments const*>
353 ::type;
354
355typedef compatibility_return_type(*compatibility_function_callback)(compatibility_callback_info_type);
356
357using compatibility_accessor_getter_return_type
358 = std::conditional<v8_uses_property_callback_info, void, v8::Handle<v8::Value> >::type;
359using compatibility_accessor_getter_callback_info_type
360 = std::conditional<v8_uses_property_callback_info
361 , v8::PropertyCallbackInfo<v8::Value> const&, v8::AccessorInfo const&>
362 ::type;
363
364using compatibility_accessor_setter_return_type
365 = void;
366using compatibility_accessor_setter_callback_info_type
367 = std::conditional<v8_uses_property_callback_info
368 , v8::PropertyCallbackInfo<void> const&, v8::AccessorInfo const&>
369 ::type;
370
371using compatibility_indexed_property_getset_return_type
372 = std::conditional<v8_uses_property_callback_info, void, v8::Handle<v8::Value> >::type;
373using compatibility_indexed_property_callback_info_type
374 = std::conditional<v8_uses_property_callback_info
375 , v8::PropertyCallbackInfo<v8::Value> const&, v8::AccessorInfo const&>
376 ::type;
377
378static_assert(v8_uses_property_callback_info == v8_uses_callback_info
379 && v8_uses_callback_info == v8_uses_isolate, "");
380
381template <typename T>
382struct compatibility_type_tag {};
383
384template <bool = v8_uses_isolate>
385struct compatibility_string;
386
387template <>
388struct compatibility_string<true> : v8::String
389{
390 template <typename... Args>
391 static v8::Local<v8::String> New(Args...args)
392 {
393 return NewFromUtf8(v8::Isolate::GetCurrent(), args...);
394 }
395};
396
397template <>
398struct compatibility_string<false> : v8::String
399{
400};
401
402template <typename...Args>
403auto compatibility_new_impl(v8::Isolate*, std::true_type, compatibility_type_tag<v8::String>
404 , Args...args) ->
405 decltype(compatibility_string<>::New(args...))
406{
407 return compatibility_string<>::New(args...);
408}
409
410template <typename...Args>
411auto compatibility_new_impl(v8::Isolate*, std::false_type, compatibility_type_tag<v8::String>
412 , Args...args) ->
413 decltype(compatibility_string<>::New(args...))
414{