summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/ecore_js/Ecore_Js.hh58
-rw-r--r--src/bindings/ecore_js/ecore_js_animator.cc728
-rw-r--r--src/bindings/ecore_js/ecore_js_event.cc772
-rw-r--r--src/bindings/ecore_js/ecore_js_file.cc1457
-rw-r--r--src/bindings/ecore_js/ecore_js_idle.cc294
-rw-r--r--src/bindings/ecore_js/ecore_js_init.cc77
-rw-r--r--src/bindings/ecore_js/ecore_js_job.cc83
-rw-r--r--src/bindings/ecore_js/ecore_js_mainloop.cc207
-rw-r--r--src/bindings/ecore_js/ecore_js_poller.cc190
-rw-r--r--src/bindings/ecore_js/ecore_js_throttle.cc63
-rw-r--r--src/bindings/ecore_js/ecore_js_timer.cc263
-rw-r--r--src/bindings/ecore_js/ecore_js_timer.hh38
-rw-r--r--src/bindings/eina_cxx/Eina.hh1
-rw-r--r--src/bindings/eina_cxx/eina_accessor.hh5
-rw-r--r--src/bindings/eina_cxx/eina_array.hh250
-rw-r--r--src/bindings/eina_cxx/eina_clone_allocators.hh3
-rw-r--r--src/bindings/eina_cxx/eina_function.hh26
-rw-r--r--src/bindings/eina_cxx/eina_integer_sequence.hh2
-rw-r--r--src/bindings/eina_cxx/eina_list.hh14
-rw-r--r--src/bindings/eina_cxx/eina_logical.hh34
-rw-r--r--src/bindings/eina_cxx/eina_pp.hh8
-rw-r--r--src/bindings/eina_cxx/eina_ptrarray.hh16
-rw-r--r--src/bindings/eina_cxx/eina_ptrlist.hh79
-rw-r--r--src/bindings/eina_cxx/eina_range_types.hh58
-rw-r--r--src/bindings/eina_cxx/eina_tuple.hh60
-rw-r--r--src/bindings/eina_cxx/eina_tuple_c.hh24
-rw-r--r--src/bindings/eina_cxx/eina_type_traits.hh16
-rw-r--r--src/bindings/eina_js/Eina_Js.hh50
-rw-r--r--src/bindings/eina_js/eina_js_accessor.cc34
-rw-r--r--src/bindings/eina_js/eina_js_accessor.hh87
-rw-r--r--src/bindings/eina_js/eina_js_array.hh119
-rw-r--r--src/bindings/eina_js/eina_js_compatibility.cc12
-rw-r--r--src/bindings/eina_js/eina_js_compatibility.hh918
-rw-r--r--src/bindings/eina_js/eina_js_container.cc495
-rw-r--r--src/bindings/eina_js/eina_js_container.hh351
-rw-r--r--src/bindings/eina_js/eina_js_error.cc24
-rw-r--r--src/bindings/eina_js/eina_js_error.hh25
-rw-r--r--src/bindings/eina_js/eina_js_get_value.hh449
-rw-r--r--src/bindings/eina_js/eina_js_get_value_from_c.hh261
-rw-r--r--src/bindings/eina_js/eina_js_iterator.cc32
-rw-r--r--src/bindings/eina_js/eina_js_iterator.hh81
-rw-r--r--src/bindings/eina_js/eina_js_list.hh132
-rw-r--r--src/bindings/eina_js/eina_js_log.cc742
-rw-r--r--src/bindings/eina_js/eina_js_log.hh133
-rw-r--r--src/bindings/eina_js/eina_js_node.hh14
-rw-r--r--src/bindings/eina_js/eina_js_value.cc132
-rw-r--r--src/bindings/eina_js/eina_js_value.hh142
-rw-r--r--src/bindings/eio_js/Eio_Js.hh44
-rw-r--r--src/bindings/eio_js/eio_js.cc1756
-rw-r--r--src/bindings/eldbus_cxx/eldbus_freedesktop.hh1
-rw-r--r--src/bindings/eldbus_js/Eldbus_Js.hh48
-rw-r--r--src/bindings/eldbus_js/eldbus_js_connection.cc543
-rw-r--r--src/bindings/eldbus_js/eldbus_js_core.cc183
-rw-r--r--src/bindings/eldbus_js/eldbus_js_message.cc103
-rw-r--r--src/bindings/eldbus_js/eldbus_js_object_mapper.cc100
-rw-r--r--src/bindings/eldbus_js/eldbus_js_util.hh836
-rw-r--r--src/bindings/eo_cxx/eo_concrete.hh7
-rw-r--r--src/bindings/eo_js/Eo_Js.hh15
-rw-r--r--src/bindings/eo_js/eo_js_call_function.hh288
-rw-r--r--src/bindings/eo_js/eo_js_construct_from_eo.hh39
-rw-r--r--src/bindings/eo_js/eo_js_constructor.hh136
-rw-r--r--src/bindings/eo_js/eo_js_direction.hh12
-rw-r--r--src/bindings/eo_js/eo_js_event.hh126
-rw-r--r--src/bindings/eo_js/eo_js_namespace.hh24
-rw-r--r--src/bindings/eo_js/eo_js_struct.hh106
-rw-r--r--src/bindings/ethumb_js/Ethumb_Js.hh48
-rw-r--r--src/bindings/ethumb_js/ethumb_js_client.cc571
67 files changed, 13984 insertions, 61 deletions
diff --git a/src/bindings/ecore_js/Ecore_Js.hh b/src/bindings/ecore_js/Ecore_Js.hh
new file mode 100644
index 0000000..3f877f3
--- /dev/null
+++ b/src/bindings/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/ecore_js/ecore_js_animator.cc b/src/bindings/ecore_js/ecore_js_animator.cc
new file mode 100644
index 0000000..52f8576
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_animator.cc
@@ -0,0 +1,728 @@
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_source_custom(v8::Isolate *isolate,
195 v8::Handle<v8::Object> global,
196 v8::Handle<v8::String> name)
197{
198 using v8::Integer;
199
200 global->Set(name,
201 compatibility_new<Integer>(isolate,
202 ECORE_ANIMATOR_SOURCE_CUSTOM));
203}
204
205void register_animator_frametime_set(v8::Isolate *isolate,
206 v8::Handle<v8::Object> global,
207 v8::Handle<v8::String> name)
208{
209 using v8::FunctionTemplate;
210
211 auto f = [](compatibility_callback_info_type args)
212 -> compatibility_return_type {
213 if (args.Length() != 1 || !args[0]->IsNumber())
214 return compatibility_return();
215
216 ecore_animator_frametime_set(args[0]->NumberValue());
217 return compatibility_return();
218 };
219
220 global->Set(name,
221 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
222}
223
224void register_animator_frametime_get(v8::Isolate *isolate,
225 v8::Handle<v8::Object> global,
226 v8::Handle<v8::String> name)
227{
228 using v8::Number;
229 using v8::FunctionTemplate;
230
231 auto f = [](compatibility_callback_info_type args)
232 -> compatibility_return_type {
233 if (args.Length() != 0)
234 return compatibility_return();
235
236 auto isolate = args.GetIsolate();
237 auto ret = ecore_animator_frametime_get();
238 return compatibility_return(compatibility_new<Number>(isolate, ret),
239 args);
240 };
241
242 global->Set(name,
243 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
244}
245
246void register_animator_pos_map(v8::Isolate *isolate,
247 v8::Handle<v8::Object> global,
248 v8::Handle<v8::String> name)
249{
250 using v8::Number;
251 using v8::FunctionTemplate;
252
253 auto f = [](compatibility_callback_info_type args)
254 -> compatibility_return_type {
255 if (args.Length() != 4 || !args[0]->IsNumber() || !args[1]->IsNumber()
256 || !args[2]->IsNumber() || !args[3]->IsNumber())
257 return compatibility_return();
258
259 Ecore_Pos_Map map;
260
261 switch ((int)(args[1]->NumberValue())) {
262 case ECORE_POS_MAP_LINEAR:
263 map = ECORE_POS_MAP_LINEAR;
264 break;
265 case ECORE_POS_MAP_ACCELERATE:
266 map = ECORE_POS_MAP_ACCELERATE;
267 break;
268 case ECORE_POS_MAP_DECELERATE:
269 map = ECORE_POS_MAP_DECELERATE;
270 break;
271 case ECORE_POS_MAP_SINUSOIDAL:
272 map = ECORE_POS_MAP_SINUSOIDAL;
273 break;
274 case ECORE_POS_MAP_ACCELERATE_FACTOR:
275 map = ECORE_POS_MAP_ACCELERATE_FACTOR;
276 break;
277 case ECORE_POS_MAP_DECELERATE_FACTOR:
278 map = ECORE_POS_MAP_DECELERATE_FACTOR;
279 break;
280 case ECORE_POS_MAP_SINUSOIDAL_FACTOR:
281 map = ECORE_POS_MAP_SINUSOIDAL_FACTOR;
282 break;
283 case ECORE_POS_MAP_DIVISOR_INTERP:
284 map = ECORE_POS_MAP_DIVISOR_INTERP;
285 break;
286 case ECORE_POS_MAP_BOUNCE:
287 map = ECORE_POS_MAP_BOUNCE;
288 break;
289 case ECORE_POS_MAP_SPRING:
290 map = ECORE_POS_MAP_SPRING;
291 break;
292 case ECORE_POS_MAP_CUBIC_BEZIER:
293 map = ECORE_POS_MAP_CUBIC_BEZIER;
294 break;
295 default:
296 return compatibility_return();
297 }
298
299 auto isolate = args.GetIsolate();
300 auto ret = ecore_animator_pos_map(args[0]->NumberValue(), map,
301 args[2]->NumberValue(),
302 args[3]->NumberValue());
303 return compatibility_return(compatibility_new<Number>(isolate, ret),
304 args);
305 };
306
307 global->Set(name,
308 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
309}
310
311void register_animator_pos_map_n(v8::Isolate *isolate,
312 v8::Handle<v8::Object> global,
313 v8::Handle<v8::String> name)
314{
315 using v8::Number;
316 using v8::NumberObject;
317 using v8::FunctionTemplate;
318 using v8::Array;
319
320 auto f = [](compatibility_callback_info_type args)
321 -> compatibility_return_type {
322 if (args.Length() != 3 || !args[0]->IsNumber() || !args[1]->IsNumber()
323 || !args[2]->IsArray())
324 return compatibility_return();
325
326 Ecore_Pos_Map map;
327
328 switch ((int)(args[1]->NumberValue())) {
329 case ECORE_POS_MAP_LINEAR:
330 map = ECORE_POS_MAP_LINEAR;
331 break;
332 case ECORE_POS_MAP_ACCELERATE:
333 map = ECORE_POS_MAP_ACCELERATE;
334 break;
335 case ECORE_POS_MAP_DECELERATE:
336 map = ECORE_POS_MAP_DECELERATE;
337 break;
338 case ECORE_POS_MAP_SINUSOIDAL:
339 map = ECORE_POS_MAP_SINUSOIDAL;
340 break;
341 case ECORE_POS_MAP_ACCELERATE_FACTOR:
342 map = ECORE_POS_MAP_ACCELERATE_FACTOR;
343 break;
344 case ECORE_POS_MAP_DECELERATE_FACTOR:
345 map = ECORE_POS_MAP_DECELERATE_FACTOR;
346 break;
347 case ECORE_POS_MAP_SINUSOIDAL_FACTOR:
348 map = ECORE_POS_MAP_SINUSOIDAL_FACTOR;
349 break;
350 case ECORE_POS_MAP_DIVISOR_INTERP:
351 map = ECORE_POS_MAP_DIVISOR_INTERP;
352 break;
353 case ECORE_POS_MAP_BOUNCE:
354 map = ECORE_POS_MAP_BOUNCE;
355 break;
356 case ECORE_POS_MAP_SPRING:
357 map = ECORE_POS_MAP_SPRING;
358 break;
359 case ECORE_POS_MAP_CUBIC_BEZIER:
360 map = ECORE_POS_MAP_CUBIC_BEZIER;
361 break;
362 default:
363 return compatibility_return();
364 }
365
366 std::vector<double> v;
367 {
368 auto array = Array::Cast(*args[2]);
369 auto s = array->Length();
370 v.reserve(s);
371 for (decltype(s) i = 0;i != s;++i) {
372 auto e = array->Get(i);
373 if (!e->IsNumber())
374 return compatibility_return();
375
376 v.push_back(e->NumberValue());
377 }
378 }
379
380 auto isolate = args.GetIsolate();
381 auto ret = ecore_animator_pos_map_n(args[0]->NumberValue(), map,
382 v.size(), v.data());
383 return compatibility_return(compatibility_new<Number>(isolate, ret),
384 args);
385 };
386
387 global->Set(name,
388 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
389}
390
391void register_animator_source_set(v8::Isolate *isolate,
392 v8::Handle<v8::Object> global,
393 v8::Handle<v8::String> name)
394{
395 using v8::FunctionTemplate;
396
397 auto f = [](compatibility_callback_info_type args)
398 -> compatibility_return_type {
399 if (args.Length() != 1 || !args[0]->IsNumber())
400 return compatibility_return();
401
402 Ecore_Animator_Source source;
403
404 switch ((int)(args[0]->NumberValue())) {
405 case ECORE_ANIMATOR_SOURCE_TIMER:
406 source = ECORE_ANIMATOR_SOURCE_TIMER;
407 break;
408 case ECORE_ANIMATOR_SOURCE_CUSTOM:
409 source = ECORE_ANIMATOR_SOURCE_CUSTOM;
410 break;
411 default:
412 return compatibility_return();
413 }
414
415 ecore_animator_source_set(source);
416 return compatibility_return();
417 };
418
419 global->Set(name,
420 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
421}
422
423void register_animator_source_get(v8::Isolate *isolate,
424 v8::Handle<v8::Object> global,
425 v8::Handle<v8::String> name)
426{
427 using v8::Integer;
428 using v8::FunctionTemplate;
429
430 auto f = [](compatibility_callback_info_type args)
431 -> compatibility_return_type {
432 if (args.Length() != 0)
433 return compatibility_return();
434
435 auto isolate = args.GetIsolate();
436 auto ret = ecore_animator_source_get();
437 return compatibility_return(compatibility_new<Integer>(isolate, ret),
438 args);
439 };
440
441 global->Set(name,
442 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
443}
444
445static
446efl::eina::js::global_ref<v8::Value> animator_custom_source_tick_begin_cb_data;
447static
448efl::eina::js::global_ref<v8::Value> animator_custom_source_tick_end_cb_data;
449
450void
451register_animator_custom_source_tick_begin_callback_set(v8::Isolate *isolate,
452 v8::Handle<v8::Object>
453 global,
454 v8::Handle<v8::String>
455 name)
456{
457 using v8::FunctionCallbackInfo;
458 using v8::Value;
459 using v8::FunctionTemplate;
460
461 auto f = [](compatibility_callback_info_type args) {
462 if (args.Length() != 1 || !args[0]->IsFunction())
463 return compatibility_return();
464
465 animator_custom_source_tick_begin_cb_data
466 = efl::eina::js::global_ref<Value>(args.GetIsolate(), args[0]);
467 ecore_animator_custom_source_tick_begin_callback_set([](void*) {
468 using v8::Function;
469 using v8::Undefined;
470 using v8::Isolate;
471
472 auto o = animator_custom_source_tick_begin_cb_data.handle();
473 Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
474 }, NULL);
475 };
476
477 global->Set(name,
478 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
479}
480
481void
482register_animator_custom_source_tick_end_callback_set(v8::Isolate *isolate,
483 v8::Handle<v8::Object>
484 global,
485 v8::Handle<v8::String>
486 name)
487{
488 using v8::FunctionCallbackInfo;
489 using v8::Value;
490 using v8::FunctionTemplate;
491
492 auto f = [](compatibility_callback_info_type args) {
493 if (args.Length() != 1 || !args[0]->IsFunction())
494 return compatibility_return();
495
496 efl::eina::js::global_ref<v8::Value>* data
497 = new efl::eina::js::global_ref<v8::Value>(args.GetIsolate(), args[0]);
498 ecore_animator_custom_source_tick_end_callback_set([](void* data) {
499 using v8::Function;
500 using v8::Undefined;
501 using v8::Isolate;
502
503 efl::eina::js::global_ref<v8::Value>*
504 d = static_cast<efl::eina::js::global_ref<v8::Value>*>(data);
505 auto o = d->handle();
506 Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
507 d->dispose();
508 delete d;
509 }, data);
510 };
511
512 global->Set(name,
513 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
514}
515
516void
517register_animator_custom_tick(v8::Isolate *isolate,
518 v8::Handle<v8::Object> global,
519 v8::Handle<v8::String> name)
520{
521 using v8::FunctionCallbackInfo;
522 using v8::Value;
523 using v8::FunctionTemplate;
524
525 auto f = [](compatibility_callback_info_type args) {
526 if (args.Length() != 0)
527 return compatibility_return();
528
529 ecore_animator_custom_tick();
530 };
531
532 global->Set(name,
533 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
534}
535
536void register_animator_add(v8::Isolate *isolate, v8::Handle<v8::Object> global,
537 v8::Handle<v8::String> name)
538{
539 using v8::Local;
540 using v8::Value;
541 using v8::Undefined;
542 using v8::Function;
543 using v8::FunctionTemplate;
544
545 auto f = [](compatibility_callback_info_type args)
546 -> compatibility_return_type {
547 if (args.Length() != 1 || !args[0]->IsFunction())
548 return compatibility_return();
549
550 auto isolate = args.GetIsolate();
551 auto f = new efl::eina::js::global_ref<Value>(isolate, args[0]);
552
553 auto cb = [](void *data) -> Eina_Bool {
554 auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
555 auto o = persistent->handle();
556
557 auto ret = Function::Cast(*o)->Call(o->ToObject(), 0, NULL);
558 auto bret = ret->IsBoolean() && ret->BooleanValue();
559
560 if (!bret)
561 {
562 persistent->dispose();
563 delete persistent;
564 }
565
566 return bret ? EINA_TRUE : EINA_FALSE;
567 };
568
569 auto ret = ecore_animator_add(cb, f);
570 return compatibility_return(wrap_animator(ret, isolate), args);
571 };
572
573 global->Set(name,
574 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
575}
576
577void register_animator_timeline_add(v8::Isolate *isolate,
578 v8::Handle<v8::Object> global,
579 v8::Handle<v8::String> name)
580{
581 using v8::Handle;
582 using v8::Local;
583 using v8::Value;
584 using v8::Undefined;
585 using v8::Function;
586 using v8::FunctionTemplate;
587 using v8::Number;
588
589 auto f = [](compatibility_callback_info_type args)
590 -> compatibility_return_type {
591 if (args.Length() != 2 || !args[0]->IsNumber()
592 || !args[1]->IsFunction()) {
593 return compatibility_return();
594 }
595
596 auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[1]);
597
598 auto cb = [](void *data, double pos) -> Eina_Bool {
599 auto persistent
600 = reinterpret_cast<efl::eina::js::global_ref<Value>*>(data);
601 auto o = persistent->handle();
602 auto isolate = v8::Isolate::GetCurrent();
603
604 Handle<Value> args = compatibility_new<Number>(isolate, pos);
605
606 auto ret = Function::Cast(*o)->Call(o->ToObject(), 1, &args);
607 auto bret = ret->IsBoolean() && ret->BooleanValue();
608
609 if (!bret)
610 {
611 persistent->dispose();
612 delete persistent;
613 }
614
615 return bret ? EINA_TRUE : EINA_FALSE;
616 };
617
618 auto ret = ecore_animator_timeline_add(args[0]->NumberValue(), cb, f);
619 return compatibility_return(wrap_animator(ret, args.GetIsolate()),
620 args);
621 };
622
623 global->Set(name,
624 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
625}
626
627void register_ecore_animator(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
628{
629 register_pos_map_linear(isolate, exports,
630 compatibility_new<v8::String>(isolate,
631 "ECORE_POS_MAP_LINEAR"));
632 register_pos_map_accelerate(isolate, exports,
633 compatibility_new<v8::String>(isolate,
634 "ECORE_POS_MAP"
635 "_ACCELERATE"));
636 register_pos_map_decelerate(isolate, exports,
637 compatibility_new<v8::String>(isolate,
638 "ECORE_POS_MAP"
639 "_DECELERATE"));
640 register_pos_map_sinusoidal(isolate, exports,
641 compatibility_new<v8::String>(isolate,
642 "ECORE_POS_MAP"
643 "_SINUSOIDAL"));
644 register_pos_map_accelerate_factor(isolate, exports,
645 compatibility_new<v8::String>(isolate,
646 "ECORE_POS_MAP"
647 "_ACCELERATE"
648 "_FACTOR"));
649 register_pos_map_decelerate_factor(isolate, exports,
650 compatibility_new<v8::String>(isolate,
651 "ECORE_POS_MAP"
652 "_DECELERATE"
653 "_FACTOR"));
654 register_pos_map_sinusoidal_factor(isolate, exports,
655 compatibility_new<v8::String>(isolate,
656 "ECORE_POS_MAP"
657 "_SINUSOIDAL"
658 "_FACTOR"));
659 register_pos_map_divisor_interp(isolate, exports,
660 compatibility_new<v8::String>(isolate,
661 "ECORE_POS_MAP"
662 "_DIVISOR_INTERP"));
663 register_pos_map_bounce(isolate, exports,
664 compatibility_new<v8::String>(isolate,
665 "ECORE_POS_MAP_BOUNCE"));
666 register_pos_map_spring(isolate, exports,
667 compatibility_new<v8::String>(isolate,
668 "ECORE_POS_MAP_SPRING"));
669 register_pos_map_cubic_bezier(isolate, exports,
670 compatibility_new<v8::String>(isolate,
671 "ECORE_POS_MAP_CUBIC"
672 "_BEZIER"));
673 register_animator_source_timer(isolate, exports,
674 compatibility_new<v8::String>(isolate,
675 "ECORE_ANIMATOR"
676 "_SOURCE_TIMER"));
677 register_animator_source_custom(isolate, exports,
678 compatibility_new<v8::String>(isolate,
679 "ECORE_ANIMATOR"
680 "_SOURCE_CUSTOM"));
681 register_animator_frametime_set(isolate, exports,
682 compatibility_new<v8::String>(isolate,
683 "ecore_animator"
684 "_frametime_set"));
685 register_animator_frametime_get(isolate, exports,
686 compatibility_new<v8::String>(isolate,
687 "ecore_animator"
688 "_frametime_get"));
689 register_animator_pos_map(isolate, exports,
690 compatibility_new<v8::String>(isolate,
691 "ecore_animator_pos"
692 "_map"));
693 register_animator_pos_map_n(isolate, exports,
694 compatibility_new<v8::String>(isolate,
695 "ecore_animator_pos_map"
696 "_n"));
697 register_animator_source_set(isolate, exports,
698 compatibility_new<v8::String>(isolate,
699 "ecore_animator_source"
700 "_set"));
701 register_animator_source_get(isolate, exports,
702 compatibility_new<v8::String>(isolate,
703 "ecore_animator_source"
704 "_get"));
705 register_animator_custom_source_tick_begin_callback_set
706 (isolate, exports,
707 compatibility_new<v8::String>(isolate,
708 "ecore_animator_custom_source_tick_begin"
709 "_callback_set"));
710 register_animator_custom_source_tick_end_callback_set
711 (isolate, exports,
712 compatibility_new<v8::String>(isolate,
713 "ecore_animator_custom_source_tick_end"
714 "_callback_set"));
715 register_animator_custom_tick(isolate, exports,
716 compatibility_new<v8::String>(isolate,
717 "ecore_animator"
718 "_custom_tick"));
719 register_animator_add(isolate, exports,
720 compatibility_new<v8::String>(isolate,
721 "ecore_animator_add"));
722 register_animator_timeline_add(isolate, exports,
723 compatibility_new<v8::String>(isolate,
724 "ecore_animator"
725 "_timeline_add"));
726}
727
728} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_event.cc b/src/bindings/ecore_js/ecore_js_event.cc
new file mode 100644
index 0000000..a086d98
--- /dev/null
+++ b/src/bindings/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/ecore_js/ecore_js_file.cc b/src/bindings/ecore_js/ecore_js_file.cc
new file mode 100644
index 0000000..eea300f
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_file.cc
@@ -0,0 +1,1457 @@
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
10#include <unistd.h>
11
12namespace efl { namespace ecore { namespace js {
13
14namespace {
15
16Ecore_File_Monitor* extract_monitor(v8::Local<v8::Object> object)
17{
18 return compatibility_get_pointer_internal_field<Ecore_File_Monitor*>(object,
19 0);
20}
21
22v8::Local<v8::Object> wrap_monitor(Ecore_File_Monitor *monitor,
23 v8::Isolate *isolate)
24{
25 using v8::String;
26 using v8::ObjectTemplate;
27 using v8::FunctionTemplate;
28
29 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
30 obj_tpl->SetInternalFieldCount(1);
31 auto ret = obj_tpl->NewInstance();
32
33 auto del = [](compatibility_callback_info_type info)
34 -> compatibility_return_type {
35 if (info.Length() != 0)
36 return compatibility_return();
37
38 ecore_file_monitor_del(extract_monitor(info.This()));
39 return compatibility_return();
40 };
41
42 auto path_get = [](compatibility_callback_info_type info)
43 -> compatibility_return_type {
44 if (info.Length() != 0)
45 return compatibility_return();
46
47 auto ret = ecore_file_monitor_path_get(extract_monitor(info.This()));
48 return compatibility_return(compatibility_new<String>(info.GetIsolate(),
49 ret),
50 info);
51 };
52
53 ret->Set(compatibility_new<String>(isolate, "del"),
54 compatibility_new<FunctionTemplate>(isolate, del)->GetFunction());
55 ret->Set(compatibility_new<String>(isolate, "path_get"),
56 compatibility_new<FunctionTemplate>(isolate, path_get)
57 ->GetFunction());
58
59 compatibility_set_pointer_internal_field(ret, 0, monitor);
60
61 return ret;
62}
63
64static Ecore_File_Download_Job *extract_download_job(v8::Local<v8::Object> o)
65{
66 return compatibility_get_pointer_internal_field<Ecore_File_Download_Job*>
67 (o, 0);
68}
69
70static
71v8::Local<v8::Object> wrap_download_job(Ecore_File_Download_Job *download_job,
72 v8::Isolate *isolate)
73{
74 using v8::String;
75 using v8::ObjectTemplate;
76 using v8::FunctionTemplate;
77
78 auto obj_tpl = compatibility_new<ObjectTemplate>(isolate);
79 obj_tpl->SetInternalFieldCount(1);
80 auto ret = obj_tpl->NewInstance();
81
82 auto abort = [](compatibility_callback_info_type info)
83 -> compatibility_return_type {
84 if (info.Length() != 0)
85 return compatibility_return();
86
87 ecore_file_download_abort(extract_download_job(info.This()));
88 return compatibility_return();
89 };
90
91 ret->Set(compatibility_new<String>(isolate, "abort"),
92 compatibility_new<FunctionTemplate>(isolate, abort)
93 ->GetFunction());
94
95 compatibility_set_pointer_internal_field(ret, 0, download_job);
96
97 return ret;
98}
99
100void register_file_event_none(v8::Isolate *isolate,
101 v8::Handle<v8::Object> exports,
102 v8::Handle<v8::String> name)
103{
104 using v8::Integer;
105 exports->Set(name,
106 compatibility_new<Integer>(isolate, ECORE_FILE_EVENT_NONE));
107}
108
109void register_file_event_created_file(v8::Isolate *isolate,
110 v8::Handle<v8::Object> exports,
111 v8::Handle<v8::String> name)
112{
113 using v8::Integer;
114 exports->Set(name,
115 compatibility_new<Integer>(isolate,
116 ECORE_FILE_EVENT_CREATED_FILE));
117}
118
119void register_file_event_created_directory(v8::Isolate *isolate,
120 v8::Handle<v8::Object> exports,
121 v8::Handle<v8::String> name)
122{
123 using v8::Integer;
124 exports->Set(name,
125 compatibility_new<Integer>(isolate,
126 ECORE_FILE_EVENT_CREATED_DIRECTORY));
127}
128
129void register_file_event_deleted_file(v8::Isolate *isolate,
130 v8::Handle<v8::Object> exports,
131 v8::Handle<v8::String> name)
132{
133 using v8::Integer;
134 exports->Set(name,
135 compatibility_new<Integer>(isolate,
136 ECORE_FILE_EVENT_DELETED_FILE));
137}
138
139void register_file_event_deleted_directory(v8::Isolate *isolate,
140 v8::Handle<v8::Object> exports,
141 v8::Handle<v8::String> name)
142{
143 using v8::Integer;
144 exports->Set(name,
145 compatibility_new<Integer>(isolate,
146 ECORE_FILE_EVENT_DELETED_DIRECTORY));
147}
148
149void register_file_event_deleted_self(v8::Isolate *isolate,
150 v8::Handle<v8::Object> exports,
151 v8::Handle<v8::String> name)
152{
153 using v8::Integer;
154 exports->Set(name,
155 compatibility_new<Integer>(isolate,
156 ECORE_FILE_EVENT_DELETED_SELF));
157}
158
159void register_file_event_modified(v8::Isolate *isolate,
160 v8::Handle<v8::Object> exports,
161 v8::Handle<v8::String> name)
162{
163 using v8::Integer;
164 exports->Set(name,
165 compatibility_new<Integer>(isolate, ECORE_FILE_EVENT_MODIFIED));
166}
167
168void register_file_event_closed(v8::Isolate *isolate,
169 v8::Handle<v8::Object> exports,
170 v8::Handle<v8::String> name)
171{
172 using v8::Integer;
173 exports->Set(name,
174 compatibility_new<Integer>(isolate, ECORE_FILE_EVENT_CLOSED));
175}
176
177void register_file_progress_continue(v8::Isolate *isolate,
178 v8::Handle<v8::Object> exports,
179 v8::Handle<v8::String> name)
180{
181 using v8::Integer;
182 exports->Set(name,
183 compatibility_new<Integer>(isolate,
184 ECORE_FILE_PROGRESS_CONTINUE));
185}
186
187void register_file_progress_abort(v8::Isolate *isolate,
188 v8::Handle<v8::Object> exports,
189 v8::Handle<v8::String> name)
190{
191 using v8::Integer;
192 exports->Set(name,
193 compatibility_new<Integer>(isolate, ECORE_FILE_PROGRESS_ABORT));
194}
195
196void register_file_init(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
197 v8::Handle<v8::String> name)
198{
199 using v8::Integer;
200 using v8::FunctionTemplate;
201
202 auto f = [](compatibility_callback_info_type args)
203 -> compatibility_return_type {
204 if (args.Length() != 0)
205 return compatibility_return();
206
207 auto isolate = args.GetIsolate();
208 auto ret = ecore_file_init();
209 return compatibility_return(compatibility_new<Integer>(isolate, ret),
210 args);
211 };
212
213 exports->Set(name,
214 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
215}
216
217void register_file_shutdown(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
218 v8::Handle<v8::String> name)
219{
220 using v8::Integer;
221 using v8::FunctionTemplate;
222
223 auto f = [](compatibility_callback_info_type args)
224 -> compatibility_return_type {
225 if (args.Length() != 0)
226 return compatibility_return();
227
228 auto isolate = args.GetIsolate();
229 auto ret = ecore_file_shutdown();
230 return compatibility_return(compatibility_new<Integer>(isolate, ret),
231 args);
232 };
233
234 exports->Set(name,
235 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
236}
237
238void register_file_mod_time(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
239 v8::Handle<v8::String> name)
240{
241 using v8::Date;
242 using v8::String;
243 using v8::FunctionTemplate;
244
245 auto f = [](compatibility_callback_info_type args)
246 -> compatibility_return_type {
247 if (args.Length() != 1 || !args[0]->IsString())
248 return compatibility_return();
249
250 auto isolate = args.GetIsolate();
251
252 /* TODO: be less ofensive on the comment below once the documentation of
253 `ecore_file_mod_time` is fixed. I'm planning to submit a patch. */
254 /* `ecore_file_mod_time` returns "the time of the last data
255 modification", which is one of the most useless descriptions of a
256 function I ever found. The return type is `long long`, but looking at
257 the implementation, I see the value is the number of seconds since
258 the Epoch.
259
260 v8's `Date` constructor takes the number of milliseconds since the
261 Epoch represented as a `double`. */
262 double ret = ecore_file_mod_time(*String::Utf8Value(args[0]));
263 ret *= 1000;
264
265 return compatibility_return(compatibility_new<Date>(isolate, ret),
266 args);
267 };
268
269 exports->Set(name,
270 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
271}
272
273void register_file_size(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
274 v8::Handle<v8::String> name)
275{
276 using v8::Integer;
277 using v8::String;
278 using v8::FunctionTemplate;
279
280 auto f = [](compatibility_callback_info_type args)
281 -> compatibility_return_type {
282 if (args.Length() != 1 || !args[0]->IsString())
283 return compatibility_return();
284
285 auto isolate = args.GetIsolate();
286 auto ret = ecore_file_size(*String::Utf8Value(args[0]));
287 return compatibility_return(compatibility_new<Integer>(isolate, ret),
288 args);
289 };
290
291 exports->Set(name,
292 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
293}
294
295void register_file_exists(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
296 v8::Handle<v8::String> name)
297{
298 using v8::Boolean;
299 using v8::String;
300 using v8::FunctionTemplate;
301
302 auto f = [](compatibility_callback_info_type args)
303 -> compatibility_return_type {
304 if (args.Length() != 1 || !args[0]->IsString())
305 return compatibility_return();
306
307 auto isolate = args.GetIsolate();
308 auto ret = ecore_file_exists(*String::Utf8Value(args[0]));
309 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
310 args);
311 };
312
313 exports->Set(name,
314 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
315}
316
317void register_file_is_dir(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
318 v8::Handle<v8::String> name)
319{
320 using v8::Boolean;
321 using v8::String;
322 using v8::FunctionTemplate;
323
324 auto f = [](compatibility_callback_info_type args)
325 -> compatibility_return_type {
326 if (args.Length() != 1 || !args[0]->IsString())
327 return compatibility_return();
328
329 auto isolate = args.GetIsolate();
330 auto ret = ecore_file_is_dir(*String::Utf8Value(args[0]));
331 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
332 args);
333 };
334
335 exports->Set(name,
336 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
337}
338
339void register_file_mkdir(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
340 v8::Handle<v8::String> name)
341{
342 using v8::Boolean;
343 using v8::String;
344 using v8::FunctionTemplate;
345
346 auto f = [](compatibility_callback_info_type args)
347 -> compatibility_return_type {
348 if (args.Length() != 1 || !args[0]->IsString())
349 return compatibility_return();
350
351 auto isolate = args.GetIsolate();
352 auto ret = ecore_file_mkdir(*String::Utf8Value(args[0]));
353 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
354 args);
355 };
356
357 exports->Set(name,
358 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
359}
360
361void register_file_mkdirs(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
362 v8::Handle<v8::String> name)
363{
364 using v8::Integer;
365 using v8::String;
366 using v8::Array;
367 using v8::FunctionTemplate;
368
369 auto f = [](compatibility_callback_info_type args)
370 -> compatibility_return_type {
371 if (args.Length() != 1 || !args[0]->IsArray())
372 return compatibility_return();
373
374 auto isolate = args.GetIsolate();
375 std::vector<std::string> dirs_data;
376 std::vector<const char*> dirs;
377 {
378 auto array = Array::Cast(*args[0]);
379 auto s = array->Length();
380 dirs_data.reserve(s);
381 dirs.reserve(s + 1);
382 for (decltype(s) i = 0;i != s;++i) {
383 auto e = array->Get(i);
384 if (!e->IsString())
385 return compatibility_return();
386
387 dirs_data.push_back(*String::Utf8Value(e));
388 dirs.push_back(dirs_data.back().data());
389 }
390 }
391 dirs.push_back(NULL);
392 auto ret = ecore_file_mkdirs(dirs.data());
393 return compatibility_return(compatibility_new<Integer>(isolate, ret),
394 args);
395 };
396
397 exports->Set(name,
398 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
399}
400
401void register_file_mksubdirs(v8::Isolate *isolate,
402 v8::Handle<v8::Object> exports,
403 v8::Handle<v8::String> name)
404{
405 using v8::Integer;
406 using v8::String;
407 using v8::Array;
408 using v8::FunctionTemplate;
409
410 auto f = [](compatibility_callback_info_type args)
411 -> compatibility_return_type {
412 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsArray())
413 return compatibility_return();
414
415 auto isolate = args.GetIsolate();
416 std::vector<std::string> subdirs_data;
417 std::vector<const char*> subdirs;
418 {
419 auto array = Array::Cast(*args[1]);
420 auto s = array->Length();
421 subdirs_data.reserve(s);
422 subdirs.reserve(s + 1);
423 for (decltype(s) i = 0;i != s;++i) {
424 auto e = array->Get(i);
425 if (!e->IsString())
426 return compatibility_return();
427
428 subdirs_data.push_back(*String::Utf8Value(e));
429 subdirs.push_back(subdirs_data.back().data());
430 }
431 }
432 subdirs.push_back(NULL);
433 auto ret = ecore_file_mksubdirs(*String::Utf8Value(args[0]),
434 subdirs.data());
435 return compatibility_return(compatibility_new<Integer>(isolate, ret),
436 args);
437 };
438
439 exports->Set(name,
440 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
441}
442
443void register_file_rmdir(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
444 v8::Handle<v8::String> name)
445{
446 using v8::Boolean;
447 using v8::String;
448 using v8::FunctionTemplate;
449
450 auto f = [](compatibility_callback_info_type args)
451 -> compatibility_return_type {
452 if (args.Length() != 1 || !args[0]->IsString())
453 return compatibility_return();
454
455 auto isolate = args.GetIsolate();
456 auto ret = ecore_file_rmdir(*String::Utf8Value(args[0]));
457 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
458 args);
459 };
460
461 exports->Set(name,
462 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
463}
464
465void register_file_unlink(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
466 v8::Handle<v8::String> name)
467{
468 using v8::Boolean;
469 using v8::String;
470 using v8::FunctionTemplate;
471
472 auto f = [](compatibility_callback_info_type args)
473 -> compatibility_return_type {
474 if (args.Length() != 1 || !args[0]->IsString())
475 return compatibility_return();
476
477 auto isolate = args.GetIsolate();
478 auto ret = ecore_file_unlink(*String::Utf8Value(args[0]));
479 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
480 args);
481 };
482
483 exports->Set(name,
484 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
485}
486
487void register_file_remove(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
488 v8::Handle<v8::String> name)
489{
490 using v8::Boolean;
491 using v8::String;
492 using v8::FunctionTemplate;
493
494 auto f = [](compatibility_callback_info_type args)
495 -> compatibility_return_type {
496 if (args.Length() != 1 || !args[0]->IsString())
497 return compatibility_return();
498
499 auto isolate = args.GetIsolate();
500 auto ret = ecore_file_remove(*String::Utf8Value(args[0]));
501 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
502 args);
503 };
504
505 exports->Set(name,
506 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
507}
508
509void register_file_recursive_rm(v8::Isolate *isolate,
510 v8::Handle<v8::Object> exports,
511 v8::Handle<v8::String> name)
512{
513 using v8::Boolean;
514 using v8::String;
515 using v8::FunctionTemplate;
516
517 auto f = [](compatibility_callback_info_type args)
518 -> compatibility_return_type {
519 if (args.Length() != 1 || !args[0]->IsString())
520 return compatibility_return();
521
522 auto isolate = args.GetIsolate();
523 auto ret = ecore_file_recursive_rm(*String::Utf8Value(args[0]));
524 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
525 args);
526 };
527
528 exports->Set(name,
529 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
530}
531
532void register_file_mkpath(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
533 v8::Handle<v8::String> name)
534{
535 using v8::Boolean;
536 using v8::String;
537 using v8::FunctionTemplate;
538
539 auto f = [](compatibility_callback_info_type args)
540 -> compatibility_return_type {
541 if (args.Length() != 1 || !args[0]->IsString())
542 return compatibility_return();
543
544 auto isolate = args.GetIsolate();
545 auto ret = ecore_file_mkpath(*String::Utf8Value(args[0]));
546 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
547 args);
548 };
549
550 exports->Set(name,
551 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
552}
553
554void register_file_mkpaths(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
555 v8::Handle<v8::String> name)
556{
557 using v8::Integer;
558 using v8::String;
559 using v8::Array;
560 using v8::FunctionTemplate;
561
562 auto f = [](compatibility_callback_info_type args)
563 -> compatibility_return_type {
564 if (args.Length() != 1 || !args[0]->IsArray())
565 return compatibility_return();
566
567 auto isolate = args.GetIsolate();
568 std::vector<std::string> paths_data;
569 std::vector<const char*> paths;
570 {
571 auto array = Array::Cast(*args[0]);
572 auto s = array->Length();
573 paths_data.reserve(s);
574 paths.reserve(s + 1);
575 for (decltype(s) i = 0;i != s;++i) {
576 auto e = array->Get(i);
577 if (!e->IsString())
578 return compatibility_return();
579
580 paths_data.push_back(*String::Utf8Value(e));
581 paths.push_back(paths_data.back().data());
582 }
583 }
584 paths.push_back(NULL);
585 auto ret = ecore_file_mkpaths(paths.data());
586 return compatibility_return(compatibility_new<Integer>(isolate, ret),
587 args);
588 };
589
590 exports->Set(name,
591 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
592}
593
594void register_file_cp(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
595 v8::Handle<v8::String> name)
596{
597 using v8::Boolean;
598 using v8::String;
599 using v8::FunctionTemplate;
600
601 auto f = [](compatibility_callback_info_type args)
602 -> compatibility_return_type {
603 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString())
604 return compatibility_return();
605
606 auto isolate = args.GetIsolate();
607 auto ret = ecore_file_cp(*String::Utf8Value(args[0]),
608 *String::Utf8Value(args[1]));
609 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
610 args);
611 };
612
613 exports->Set(name,
614 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
615}
616
617void register_file_mv(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
618 v8::Handle<v8::String> name)
619{
620 using v8::Boolean;
621 using v8::String;
622 using v8::FunctionTemplate;
623
624 auto f = [](compatibility_callback_info_type args)
625 -> compatibility_return_type {
626 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString())
627 return compatibility_return();
628
629 auto isolate = args.GetIsolate();
630 auto ret = ecore_file_mv(*String::Utf8Value(args[0]),
631 *String::Utf8Value(args[1]));
632 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
633 args);
634 };
635
636 exports->Set(name,
637 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
638}
639
640void register_file_symlink(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
641 v8::Handle<v8::String> name)
642{
643 using v8::Boolean;
644 using v8::String;
645 using v8::FunctionTemplate;
646
647 auto f = [](compatibility_callback_info_type args)
648 -> compatibility_return_type {
649 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString())
650 return compatibility_return();
651
652 auto isolate = args.GetIsolate();
653 auto ret = ecore_file_symlink(*String::Utf8Value(args[0]),
654 *String::Utf8Value(args[1]));
655 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
656 args);
657 };
658
659 exports->Set(name,
660 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
661}
662
663void register_file_realpath(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
664 v8::Handle<v8::String> name)
665{
666 using v8::String;
667 using v8::FunctionTemplate;
668 using std::unique_ptr;
669 using std::free;
670
671 typedef unique_ptr<char, void(*)(char*)> guard_t;
672
673 auto f = [](compatibility_callback_info_type args)
674 -> compatibility_return_type {
675 if (args.Length() != 1 || !args[0]->IsString())
676 return compatibility_return();
677
678 auto isolate = args.GetIsolate();
679 auto rp = guard_t(ecore_file_realpath(*String::Utf8Value(args[0])),
680 [](char *str) { free(str); });
681 auto ret = compatibility_new<String>(isolate, rp ? rp.get() : "");
682 return compatibility_return(ret, args);
683 };
684
685 exports->Set(name,
686 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
687}
688
689void register_file_file_get(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
690 v8::Handle<v8::String> name)
691{
692 using v8::String;
693 using v8::FunctionTemplate;
694
695 auto f = [](compatibility_callback_info_type args)
696 -> compatibility_return_type {
697 if (args.Length() != 1 || !args[0]->IsString())
698 return compatibility_return();
699
700 auto isolate = args.GetIsolate();
701 String::Utf8Value str(args[0]);
702 auto ret = ecore_file_file_get(*str);
703 return compatibility_return(compatibility_new<String>(isolate, ret),
704 args);
705 };
706
707 exports->Set(name,
708 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
709}
710
711void register_file_dir_get(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
712 v8::Handle<v8::String> name)
713{
714 using v8::String;
715 using v8::FunctionTemplate;
716 using std::unique_ptr;
717 using std::free;
718
719 typedef unique_ptr<char, void(*)(char*)> guard_t;
720
721 auto f = [](compatibility_callback_info_type args)
722 -> compatibility_return_type {
723 if (args.Length() != 1 || !args[0]->IsString())
724 return compatibility_return();
725
726 auto isolate = args.GetIsolate();
727 auto d = guard_t(ecore_file_dir_get(*String::Utf8Value(args[0])),
728 [](char *str) { free(str); });
729 auto ret = compatibility_new<String>(isolate, d ? d.get() : "");
730 return compatibility_return(ret, args);
731 };
732
733 exports->Set(name,
734 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
735}
736
737void register_file_can_read(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
738 v8::Handle<v8::String> name)
739{
740 using v8::Boolean;
741 using v8::String;
742 using v8::FunctionTemplate;
743
744 auto f = [](compatibility_callback_info_type args)
745 -> compatibility_return_type {
746 if (args.Length() != 1 || !args[0]->IsString())
747 return compatibility_return();
748
749 auto isolate = args.GetIsolate();
750 auto ret = ecore_file_can_read(*String::Utf8Value(args[0]));
751 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
752 args);
753 };
754
755 exports->Set(name,
756 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
757}
758
759void register_file_can_write(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
760 v8::Handle<v8::String> name)
761{
762 using v8::Boolean;
763 using v8::String;
764 using v8::FunctionTemplate;
765
766 auto f = [](compatibility_callback_info_type args)
767 -> compatibility_return_type {
768 if (args.Length() != 1 || !args[0]->IsString())
769 return compatibility_return();
770
771 auto isolate = args.GetIsolate();
772 auto ret = ecore_file_can_write(*String::Utf8Value(args[0]));
773 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
774 args);
775 };
776
777 exports->Set(name,
778 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
779}
780
781void register_file_can_exec(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
782 v8::Handle<v8::String> name)
783{
784 using v8::Boolean;
785 using v8::String;
786 using v8::FunctionTemplate;
787
788 auto f = [](compatibility_callback_info_type args)
789 -> compatibility_return_type {
790 if (args.Length() != 1 || !args[0]->IsString())
791 return compatibility_return();
792
793 auto isolate = args.GetIsolate();
794 auto ret = ecore_file_can_exec(*String::Utf8Value(args[0]));
795 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
796 args);
797 };
798
799 exports->Set(name,
800 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
801}
802
803void register_file_readlink(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
804 v8::Handle<v8::String> name)
805{
806 using v8::String;
807 using v8::FunctionTemplate;
808 using std::unique_ptr;
809 using std::free;
810
811 typedef unique_ptr<char, void(*)(char*)> guard_t;
812
813 auto f = [](compatibility_callback_info_type args)
814 -> compatibility_return_type {
815 if (args.Length() != 1 || !args[0]->IsString())
816 return compatibility_return();
817
818 auto isolate = args.GetIsolate();
819 auto l = guard_t(ecore_file_readlink(*String::Utf8Value(args[0])),
820 [](char *str) { free(str); });
821 auto ret = compatibility_new<String>(isolate, l ? l.get() : "");
822 return compatibility_return(ret, args);
823 };
824
825 exports->Set(name,
826 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
827}
828
829void register_file_ls(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
830 v8::Handle<v8::String> name)
831{
832 using v8::Array;
833 using v8::String;
834 using v8::FunctionTemplate;
835 using std::unique_ptr;
836 using std::free;
837
838 typedef unique_ptr<Eina_List, Eina_List*(*)(Eina_List*)> guard_t;
839
840 auto f = [](compatibility_callback_info_type args)
841 -> compatibility_return_type {
842 if (args.Length() != 1 || !args[0]->IsString())
843 return compatibility_return();
844
845 auto isolate = args.GetIsolate();
846 auto list = guard_t(ecore_file_ls(*String::Utf8Value(args[0])),
847 eina_list_free);
848 auto ret = compatibility_new<Array>(isolate);
849 {
850 uint32_t idx = 0;
851 for (Eina_List *l = list.get() ; l ; l = eina_list_next(l)) {
852 /* Not using idiomatic RAII here because it'd be a fake safety,
853 given that remaining objects would leak if an exception is
854 throw. It shouldn't be a problem because v8 doesn't use
855 exceptions (nor idiomatic C++). */
856 auto data = reinterpret_cast<char*>(eina_list_data_get(l));
857 ret->Set(idx++, compatibility_new<String>(isolate, data));
858 free(data);
859 }
860 }
861 return compatibility_return(ret, args);
862 };
863
864 exports->Set(name,
865 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
866}
867
868void register_file_app_exe_get(v8::Isolate *isolate,
869 v8::Handle<v8::Object> exports,
870 v8::Handle<v8::String> name)
871{
872 using v8::String;
873 using v8::FunctionTemplate;
874 using std::unique_ptr;
875 using std::free;
876
877 typedef unique_ptr<char, void(*)(char*)> guard_t;
878
879 auto f = [](compatibility_callback_info_type args)
880 -> compatibility_return_type {
881 if (args.Length() != 1 || !args[0]->IsString())
882 return compatibility_return();
883
884 auto isolate = args.GetIsolate();
885 auto e = guard_t(ecore_file_app_exe_get(*String::Utf8Value(args[0])),
886 [](char *str) { free(str); });
887 auto ret = compatibility_new<String>(isolate, e ? e.get() : "");
888 return compatibility_return(ret, args);
889 };
890
891 exports->Set(name,
892 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
893}
894
895void register_file_escape_name(v8::Isolate *isolate,
896 v8::Handle<v8::Object> exports,
897 v8::Handle<v8::String> name)
898{
899 using v8::String;
900 using v8::FunctionTemplate;
901 using std::unique_ptr;
902 using std::free;
903
904 typedef unique_ptr<char, void(*)(char*)> guard_t;
905
906 auto f = [](compatibility_callback_info_type args)
907 -> compatibility_return_type {
908 if (args.Length() != 1 || !args[0]->IsString())
909 return compatibility_return();
910
911 auto isolate = args.GetIsolate();
912 auto n = guard_t(ecore_file_escape_name(*String::Utf8Value(args[0])),
913 [](char *str) { free(str); });
914 auto ret = compatibility_new<String>(isolate, n ? n.get() : "");
915 return compatibility_return(ret, args);
916 };
917
918 exports->Set(name,
919 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
920}
921
922void register_file_strip_ext(v8::Isolate *isolate,
923 v8::Handle<v8::Object> exports,
924 v8::Handle<v8::String> name)
925{
926 using v8::String;
927 using v8::FunctionTemplate;
928 using std::unique_ptr;
929 using std::free;
930
931 typedef unique_ptr<char, void(*)(char*)> guard_t;
932
933 auto f = [](compatibility_callback_info_type args)
934 -> compatibility_return_type {
935 if (args.Length() != 1 || !args[0]->IsString())
936 return compatibility_return();
937
938 auto isolate = args.GetIsolate();
939 auto n = guard_t(ecore_file_strip_ext(*String::Utf8Value(args[0])),
940 [](char *str) { free(str); });
941 auto ret = compatibility_new<String>(isolate, n ? n.get() : "");
942 return compatibility_return(ret, args);
943 };
944
945 exports->Set(name,
946 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
947}
948
949void register_file_dir_is_empty(v8::Isolate *isolate,
950 v8::Handle<v8::Object> exports,
951 v8::Handle<v8::String> name)
952{
953 using v8::Integer;
954 using v8::String;
955 using v8::FunctionTemplate;
956
957 auto f = [](compatibility_callback_info_type args)
958 -> compatibility_return_type {
959 if (args.Length() != 1 || !args[0]->IsString())
960 return compatibility_return();
961
962 auto isolate = args.GetIsolate();
963 auto ret = ecore_file_dir_is_empty(*String::Utf8Value(args[0]));
964 return compatibility_return(compatibility_new<Integer>(isolate, ret),
965 args);
966 };
967
968 exports->Set(name,
969 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
970}
971
972void register_file_monitor_add(v8::Isolate *isolate,
973 v8::Handle<v8::Object> exports,
974 v8::Handle<v8::String> name)
975{
976 using v8::String;
977 using v8::Integer;
978 using v8::FunctionTemplate;
979 using v8::Handle;
980 using v8::Value;
981 using v8::Function;
982
983 auto f = [](compatibility_callback_info_type args)
984 -> compatibility_return_type {
985 if (args.Length() != 2 || !args[0]->IsString()
986 || !args[1]->IsFunction()) {
987 return compatibility_return();
988 }
989
990 auto f = new efl::eina::js::global_ref<Value>(args.GetIsolate(), args[1]);
991
992 auto cb = [](void *data, Ecore_File_Monitor *em, Ecore_File_Event event,
993 const char *path) {
994 auto persistent = static_cast<efl::eina::js::global_ref<Value>*>(data);
995 auto o = persistent->handle();
996
997 auto isolate = v8::Isolate::GetCurrent();
998
999 Handle<Value> args[3] = {
1000 wrap_monitor(em, isolate),
1001 compatibility_new<Integer>(isolate, event),
1002 compatibility_new<String>(isolate, path)
1003 };
1004
1005 Function::Cast(*o)->Call(o->ToObject(), 3, args);
1006
1007 persistent->dispose();
1008 delete persistent;
1009 };
1010
1011 auto isolate = args.GetIsolate();
1012 auto ret = ecore_file_monitor_add(*String::Utf8Value(args[0]), cb, f);
1013 return compatibility_return(wrap_monitor(ret, isolate), args);
1014 };
1015
1016 exports->Set(name,
1017 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
1018}
1019
1020void register_file_path_dir_exists(v8::Isolate *isolate,
1021 v8::Handle<v8::Object> exports,
1022 v8::Handle<v8::String> name)
1023{
1024 using v8::Boolean;
1025 using v8::String;
1026 using v8::FunctionTemplate;
1027
1028 auto f = [](compatibility_callback_info_type args)
1029 -> compatibility_return_type {
1030 if (args.Length() != 1 || !args[0]->IsString())
1031 return compatibility_return();
1032
1033 auto isolate = args.GetIsolate();
1034 Eina_Bool ret = ecore_file_path_dir_exists(*String::Utf8Value(args[0]));
1035 return compatibility_return(compatibility_new<Boolean>(isolate, ret == EINA_TRUE ? true : false),
1036 args);
1037 };
1038
1039 exports->Set(name,
1040 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
1041}
1042
1043void register_file_app_installed(v8::Isolate *isolate,
1044 v8::Handle<v8::Object> exports,
1045 v8::Handle<v8::String> name)
1046{
1047 using v8::Boolean;
1048 using v8::String;
1049 using v8::FunctionTemplate;
1050
1051 auto f = [](compatibility_callback_info_type args)
1052 -> compatibility_return_type {
1053 if (args.Length() != 1 || !args[0]->IsString())
1054 return compatibility_return();
1055
1056 auto isolate = args.GetIsolate();
1057 auto ret = ecore_file_app_installed(*String::Utf8Value(args[0]));
1058 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
1059 args);
1060 };
1061
1062 exports->Set(name,
1063 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
1064}
1065
1066void register_file_app_list(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
1067 v8::Handle<v8::String> name)
1068{
1069 using v8::Array;
1070 using v8::String;
1071 using v8::FunctionTemplate;
1072 using std::unique_ptr;
1073 using std::free;
1074
1075 typedef unique_ptr<Eina_List, Eina_List*(*)(Eina_List*)> guard_t;
1076
1077 auto f = [](compatibility_callback_info_type args)
1078 -> compatibility_return_type {
1079 if (args.Length() != 0)
1080 return compatibility_return();
1081
1082 auto isolate = args.GetIsolate();
1083 auto list = guard_t(ecore_file_app_list(), eina_list_free);
1084 auto ret = compatibility_new<Array>(isolate);
1085 {
1086 uint32_t idx = 0;
1087 for (Eina_List *l = list.get() ; l ; l = eina_list_next(l)) {
1088 /* Not using idiomatic RAII here because it'd be a fake safety,
1089 given that remaining objects would leak if an exception is
1090 throw. It shouldn't be a problem because v8 doesn't use
1091 exceptions (nor idiomatic C++). */
1092 auto data = reinterpret_cast<char*>(eina_list_data_get(l));
1093 ret->Set(idx++, compatibility_new<String>(isolate, data));
1094 free(data);
1095 }
1096 }
1097 return compatibility_return(ret, args);
1098 };
1099
1100 exports->Set(name,
1101 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
1102}
1103
1104void register_file_download(v8::Isolate *isolate, v8::Handle<v8::Object> exports,
1105 v8::Handle<v8::String> name)
1106{
1107 using v8::Boolean;
1108 using v8::Integer;
1109 using v8::String;
1110 using v8::Object;
1111 using v8::Function;
1112 using v8::Value;
1113 using v8::Handle;
1114 using v8::FunctionTemplate;
1115 using std::unique_ptr;
1116 using std::free;
1117
1118 typedef unique_ptr<Eina_Hash, void(*)(Eina_Hash*)> guard_t;
1119 typedef efl::eina::js::global_ref<Value> persistent_t;
1120
1121 auto f = [](compatibility_callback_info_type args)
1122 -> compatibility_return_type {
1123 if ((args.Length() != 4 && args.Length() != 5) || !args[0]->IsString()
1124 || !args[1]->IsString() || !args[2]->IsFunction()
1125 || !args[3]->IsFunction()
1126 || (args.Length() == 5 && !args[4]->IsObject()))
1127 return compatibility_return();
1128
1129 auto isolate = args.GetIsolate();
1130
1131 auto cb_data = unique_ptr<persistent_t[]>(new persistent_t[2]);
1132 cb_data[0] = persistent_t(isolate, args[2]);
1133 cb_data[1] = persistent_t(isolate, args[3]);
1134
1135 String::Utf8Value url(args[0]);
1136 String::Utf8Value dst(args[1]);
1137 auto completion_cb = [](void *data, const char *file, int status) {
1138 auto persistent = reinterpret_cast<persistent_t*>(data);
1139 auto o = persistent->handle();
1140
1141 auto isolate = v8::Isolate::GetCurrent();
1142
1143 Handle<Value> args[2] = {
1144 compatibility_new<String>(isolate, file),
1145 compatibility_new<Integer>(isolate, status)
1146 };
1147
1148 Function::Cast(*o)->Call(o->ToObject(), 2, args);
1149
1150 delete[] persistent;
1151 };
1152 auto progress_cb = [](void *data, const char *file, long int dltotal,
1153 long int dlnow, long int ultotal,
1154 long int ulnow) -> int {
1155 auto persistent = reinterpret_cast<persistent_t*>(data) + 1;
1156 auto o = persistent->handle();
1157
1158 auto isolate = v8::Isolate::GetCurrent();
1159
1160 Handle<Value> args[5] = {
1161 compatibility_new<String>(isolate, file),
1162 compatibility_new<Integer>(isolate, dltotal),
1163 compatibility_new<Integer>(isolate, dlnow),
1164 compatibility_new<Integer>(isolate, ultotal),
1165 compatibility_new<Integer>(isolate, ulnow)
1166 };
1167
1168 auto ret = Function::Cast(*o)->Call(o->ToObject(), 5, args);
1169 auto iret = ret->IsNumber() ? int(ret->NumberValue()) : 0;
1170 if (iret != ECORE_FILE_PROGRESS_CONTINUE)
1171 delete[] (persistent - 1);
1172
1173 return iret;
1174 };
1175 Ecore_File_Download_Job *job_ret = NULL;
1176 auto ret = compatibility_new<Object>(isolate);
1177 bool bret;
1178
1179 if (args.Length() == 4) {
1180 bret = ecore_file_download(*url, *dst, completion_cb, progress_cb,
1181 cb_data.get(), &job_ret);
1182 } else {
1183 auto headers = guard_t(eina_hash_string_djb2_new(free),
1184 eina_hash_free);
1185 auto js_headers = Object::Cast(*args[4]);
1186 auto keys = js_headers->GetOwnPropertyNames();
1187 for (uint32_t i = 0;i != keys->Length();++i) {
1188 auto key = keys->CloneElementAt(i);
1189 if (!key->IsString())
1190 return compatibility_return();
1191
1192 auto value = js_headers->Get(key);
1193 if (!value->IsString())
1194 return compatibility_return();
1195
1196 eina_hash_add(headers.get(), *String::Utf8Value(key),
1197 strdup(*String::Utf8Value(value)));
1198 }
1199 bret = ecore_file_download_full(*url, *dst, completion_cb,
1200 progress_cb, cb_data.get(),
1201 &job_ret, headers.get());
1202 }
1203 if (bret)
1204 cb_data.release();
1205
1206 ret->Set(compatibility_new<String>(isolate, "ok"),
1207 compatibility_new<Boolean>(isolate, bret));
1208
1209 if (job_ret) {
1210 ret->Set(compatibility_new<String>(isolate, "job"),
1211 wrap_download_job(job_ret, isolate));
1212 }
1213
1214 return compatibility_return(ret, args);
1215 };
1216
1217 exports->Set(name,
1218 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
1219}
1220
1221void register_file_download_abort_all(v8::Isolate *isolate,
1222 v8::Handle<v8::Object> exports,
1223 v8::Handle<v8::String> name)
1224{
1225 using v8::Integer;
1226 using v8::FunctionTemplate;
1227
1228 auto f = [](compatibility_callback_info_type args)
1229 -> compatibility_return_type {
1230 if (args.Length() != 0)
1231 return compatibility_return();
1232
1233 ecore_file_download_abort_all();
1234 return compatibility_return();
1235 };
1236
1237 exports->Set(name,
1238 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
1239}
1240
1241void register_file_download_protocol_available(v8::Isolate *isolate,
1242 v8::Handle<v8::Object> exports,
1243 v8::Handle<v8::String> name)
1244{
1245 using v8::Boolean;
1246 using v8::String;
1247 using v8::FunctionTemplate;
1248
1249 auto f = [](compatibility_callback_info_type args)
1250 -> compatibility_return_type {
1251 if (args.Length() != 1 || !args[0]->IsString())
1252 return compatibility_return();
1253
1254 auto isolate = args.GetIsolate();
1255 String::Utf8Value protocol(args[0]);
1256 auto ret = ecore_file_download_protocol_available(*protocol);
1257 return compatibility_return(compatibility_new<Boolean>(isolate, ret),
1258 args);
1259 };
1260
1261 exports->Set(name,
1262 compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
1263}
1264
1265void register_file_mkstemp(v8::Isolate *isolate,
1266 v8::Handle<v8::Object> exports,
1267 v8::Handle<v8::String> name)
1268{
1269 auto f = [](compatibility_callback_info_type args)
1270 -> compatibility_return_type {
1271 if (args.Length() != 1 || !args[0]->IsString())
1272 return compatibility_return();
1273
1274 v8::String::Utf8Value buffer(args[0]);
1275 char* buf = (char*)malloc(std::strlen(*buffer)+1);
1276 struct free_buf
1277 {
1278 free_buf(char* p) : p(p) {}
1279 ~free_buf() { free(p); }
1280 char* p;
1281 } free_buf_(buf);
1282 std::strcpy(buf, *buffer);
1283 int fd = mkstemp(buf);
1284
1285 if(fd > 0)
1286 {
1287 close(fd);
1288
1289 return compatibility_return(compatibility_new<v8::String>(nullptr, buf), args);
1290 }
1291 else
1292 return compatibility_return();
1293 };
1294 exports->Set(name, compatibility_new<v8::FunctionTemplate>(isolate, f)->GetFunction());
1295}
1296
1297void register_file_environment_tmp(v8::Isolate *isolate,
1298 v8::Handle<v8::Object> exports,
1299 v8::Handle<v8::String> name)
1300{
1301 auto f = [](compatibility_callback_info_type args)
1302 -> compatibility_return_type {
1303
1304 return compatibility_return(compatibility_new<v8::String>(nullptr, eina_environment_tmp_get()), args);
1305 };
1306 exports->Set(name, compatibility_new<v8::FunctionTemplate>(isolate, f)->GetFunction());
1307}
1308
1309}
1310
1311EAPI
1312void register_ecore_file(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
1313{
1314 register_file_event_none(isolate, exports,
1315 compatibility_new<v8::String>(isolate,
1316 "ECORE_FILE_EVENT_NONE"));
1317 register_file_event_created_file(isolate, exports,
1318 compatibility_new<v8::String>(isolate,
1319 "ECORE_FILE_EVENT"
1320 "_CREATED_FILE"));
1321 register_file_event_created_directory(isolate, exports,
1322 compatibility_new<v8::String>
1323 (isolate,
1324 "ECORE_FILE_EVENT_CREATED_DIRECTORY"));
1325 register_file_event_deleted_file(isolate, exports,
1326 compatibility_new<v8::String>(isolate,
1327 "ECORE_FILE_EVENT"
1328 "_DELETED_FILE"));
1329 register_file_event_deleted_directory(isolate, exports,
1330 compatibility_new<v8::String>
1331 (isolate,
1332 "ECORE_FILE_EVENT_DELETED_DIRECTORY"));
1333 register_file_event_deleted_self(isolate, exports,
1334 compatibility_new<v8::String>(isolate,
1335 "ECORE_FILE_EVENT"
1336 "_DELETED_SELF"));
1337 register_file_event_modified(isolate, exports,
1338 compatibility_new<v8::String>(isolate,
1339 "ECORE_FILE_EVENT"
1340 "_MODIFIED"));
1341 register_file_event_closed(isolate, exports,
1342 compatibility_new<v8::String>(isolate,
1343 "ECORE_FILE_EVENT"
1344 "_CLOSED"));
1345 register_file_progress_continue(isolate, exports,
1346 compatibility_new<v8::String>
1347 (isolate, "ECORE_FILE_PROGRESS_CONTINUE"));
1348 register_file_progress_abort(isolate, exports,
1349 compatibility_new<v8::String>
1350 (isolate, "ECORE_FILE_PROGRESS_ABORT"));
1351 register_file_init(isolate, exports,
1352 compatibility_new<v8::String>(isolate, "ecore_file_init"));
1353 register_file_shutdown(isolate, exports,
1354 compatibility_new<v8::String>(isolate,
1355 "ecore_file_shutdown"));
1356 register_file_mod_time(isolate, exports,
1357 compatibility_new<v8::String>(isolate,
1358 "ecore_file_mod_time"));
1359 register_file_size(isolate, exports,
1360 compatibility_new<v8::String>(isolate, "ecore_file_size"));
1361 register_file_exists(isolate, exports,
1362 compatibility_new<v8::String>(isolate, "ecore_file_exists"));
1363 register_file_is_dir(isolate, exports,
1364 compatibility_new<v8::String>(isolate, "ecore_file_is_dir"));
1365 register_file_mkdir(isolate, exports,
1366 compatibility_new<v8::String>(isolate, "ecore_file_mkdir"));
1367 register_file_mkdirs(isolate, exports,
1368 compatibility_new<v8::String>(isolate, "ecore_file_mkdirs"));
1369 register_file_mksubdirs(isolate, exports,
1370 compatibility_new<v8::String>(isolate,
1371 "ecore_file_mksubdirs"));
1372 register_file_rmdir(isolate, exports,
1373 compatibility_new<v8::String>(isolate, "ecore_file_rmdir"));
1374 register_file_unlink(isolate, exports,
1375 compatibility_new<v8::String>(isolate, "ecore_file_unlink"));
1376 register_file_remove(isolate, exports,
1377 compatibility_new<v8::String>(isolate, "ecore_file_remove"));
1378 register_file_recursive_rm(isolate, exports,
1379 compatibility_new<v8::String>
1380 (isolate, "ecore_file_recursive_rm"));
1381 register_file_mkpath(isolate, exports,
1382 compatibility_new<v8::String>(isolate, "ecore_file_mkpath"));
1383 register_file_mkpaths(isolate, exports,
1384 compatibility_new<v8::String>(isolate,
1385 "ecore_file_mkpaths"));
1386 register_file_cp(isolate, exports,
1387 compatibility_new<v8::String>(isolate, "ecore_file_cp"));
1388 register_file_mv(isolate, exports,
1389 compatibility_new<v8::String>(isolate, "ecore_file_mv"));
1390 register_file_symlink(isolate, exports,
1391 compatibility_new<v8::String>(isolate,
1392 "ecore_file_symlink"));
1393 register_file_realpath(isolate, exports,
1394 compatibility_new<v8::String>(isolate,
1395 "ecore_file_realpath"));
1396 register_file_file_get(isolate, exports,
1397 compatibility_new<v8::String>(isolate,
1398 "ecore_file_file_get"));
1399 register_file_dir_get(isolate, exports,
1400 compatibility_new<v8::String>(isolate,
1401 "ecore_file_dir_get"));
1402 register_file_can_read(isolate, exports,
1403 compatibility_new<v8::String>(isolate,
1404 "ecore_file_can_read"));
1405 register_file_can_write(isolate, exports,
1406 compatibility_new<v8::String>(isolate,
1407 "ecore_file_can_write"));
1408 register_file_can_exec(isolate, exports,
1409 compatibility_new<v8::String>(isolate,
1410 "ecore_file_can_exec"));
1411 register_file_readlink(isolate, exports,
1412 compatibility_new<v8::String>(isolate,
1413 "ecore_file_readlink"));
1414 register_file_ls(isolate, exports,
1415 compatibility_new<v8::String>(isolate, "ecore_file_ls"));
1416 register_file_app_exe_get(isolate, exports,
1417 compatibility_new<v8::String>
1418 (isolate, "ecore_file_app_exe_get"));
1419 register_file_escape_name(isolate, exports,
1420 compatibility_new<v8::String>
1421 (isolate, "ecore_file_escape_name"));
1422 register_file_strip_ext(isolate, exports,
1423 compatibility_new<v8::String>(isolate,
1424 "ecore_file_strip_ext"));
1425 register_file_dir_is_empty(isolate, exports,
1426 compatibility_new<v8::String>
1427 (isolate, "ecore_file_dir_is_empty"));
1428 register_file_monitor_add(isolate, exports,
1429 compatibility_new<v8::String>
1430 (isolate, "ecore_file_monitor_add"));
1431 register_file_path_dir_exists(isolate, exports,
1432 compatibility_new<v8::String>
1433 (isolate, "ecore_file_path_dir_exists"));
1434 register_file_app_installed(isolate, exports,
1435 compatibility_new<v8::String>
1436 (isolate, "ecore_file_app_installed"));
1437 register_file_app_list(isolate, exports,
1438 compatibility_new<v8::String>(isolate,
1439 "ecore_file_app_list"));
1440 register_file_download(isolate, exports,
1441 compatibility_new<v8::String>(isolate,
1442 "ecore_file_download"));
1443 register_file_download_abort_all(isolate, exports,
1444 compatibility_new<v8::String>
1445 (isolate, "ecore_file_download_abort_all"));
1446 register_file_download_protocol_available(isolate, exports,
1447 compatibility_new<v8::String>
1448 (isolate,
1449 "ecore_file_download_protocol"
1450 "_available"));
1451 register_file_mkstemp(isolate, exports,
1452 compatibility_new<v8::String>(isolate, "mkstemp"));
1453 register_file_environment_tmp(isolate, exports,
1454 compatibility_new<v8::String>(isolate, "environment_tmp"));
1455}
1456
1457} } } // namespace efl { namespace ecore { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_idle.cc b/src/bindings/ecore_js/ecore_js_idle.cc
new file mode 100644
index 0000000..293cef2
--- /dev/null
+++ b/src/bindings/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/ecore_js/ecore_js_init.cc b/src/bindings/ecore_js/ecore_js_init.cc
new file mode 100644
index 0000000..724d16a
--- /dev/null
+++ b/src/bindings/ecore_js/ecore_js_init.cc
@@ -0,0 +1,77 @@
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_file(isolate, exports);
69 register_ecore_idle(isolate, exports);
70 register_ecore_job(isolate, exports);
71 register_ecore_mainloop(isolate, exports);
72 register_ecore_poller(isolate, exports);
73 register_ecore_throttle(isolate, exports);
74 register_ecore_timer(isolate, exports);
75}
76
77} } } // namespace efl { namespace js {
diff --git a/src/bindings/ecore_js/ecore_js_job.cc b/src/bindings/ecore_js/ecore_js_job.cc
new file mode 100644
index 0000000..4ec438a
--- /dev/null
+++ b/src/bindings/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/ecore_js/ecore_js_mainloop.cc b/src/bindings/ecore_js/ecore_js_mainloop.cc
new file mode 100644
index 0000000..180b35f
--- /dev/null
+++ b/src/bindings/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;