Line | Branch | Exec | Source |
---|---|---|---|
1 | #include <core.h> | ||
2 | #include <interface.h> | ||
3 | |||
4 | |||
5 | /** | ||
6 | * ES callback. Return bTree height | ||
7 | */ | ||
8 | 6 | napi_value esHeight(napi_env env, napi_callback_info cbInfo) { | |
9 | napi_value esHeight; | ||
10 | napi_value esThis; | ||
11 | BTree_t *bTree; | ||
12 | |||
13 | // Get es this | ||
14 |
1/6✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
6 | NAPI_CALL(env, false, |
15 | napi_get_cb_info(env, cbInfo, NULL, NULL, &esThis, NULL)); | ||
16 | |||
17 | // Extract native BTree pointer | ||
18 |
1/6✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
6 | NAPI_CALL(env, false, |
19 | napi_unwrap(env, esThis, (void **) &bTree)); | ||
20 | |||
21 | // Native call to glib tree | ||
22 | 6 | gint nativeHeight = g_tree_height(bTree->nativeTree); | |
23 | |||
24 | // Convert from C type to es type | ||
25 |
1/6✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
6 | NAPI_CALL(env, false, |
26 | napi_create_int64(env, nativeHeight, &esHeight)); | ||
27 | |||
28 | 6 | return esHeight; | |
29 | } | ||
30 | |||
31 | napi_value | ||
32 | 10 | esForeachReverse(napi_env env, napi_callback_info cbInfo) { | |
33 | napi_value esThis, callback, cbThis, cbArgv[4], argv[2]; | ||
34 | 10 | size_t argc = 2; | |
35 | |||
36 |
1/6✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
10 | NAPI_CALL(env, false, |
37 | napi_get_cb_info(env, cbInfo, &argc, argv, &esThis, NULL)); | ||
38 | |||
39 |
3/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
10 | CHECK_ARGC(1, msgTooFewArguments); |
40 | 9 | callback = argv[0]; | |
41 | |||
42 | BTree_t *btree; | ||
43 |
1/6✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
9 | EXTRACT_BTREE(env, esThis, btree); |
44 | |||
45 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
|
9 | if (argc > 1) { |
46 | 2 | cbThis = argv[1]; | |
47 | 2 | } | |
48 | else { | ||
49 | 7 | cbThis = getEsGlobal(env); | |
50 | } | ||
51 | |||
52 | #ifdef HAS_GTREE_NODE | ||
53 | 9 | GTreeNode *current = g_tree_node_last(btree->nativeTree); | |
54 | |||
55 | 9 | gint idx = 0; | |
56 | 9 | gint revIdx = g_tree_nnodes(btree->nativeTree); | |
57 | |||
58 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 9 times.
|
36 | while (current) { |
59 | 27 | cbArgv[0] = getNodeEsValue(env, current); | |
60 | 27 | cbArgv[1] = getNodeEsKey(env, current); | |
61 | |||
62 |
1/6✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
27 | NAPI_CALL(env, false, |
63 | napi_create_int64(env, idx, &cbArgv[2])); | ||
64 | |||
65 | 27 | idx++; | |
66 | 27 | revIdx--; | |
67 | |||
68 |
1/6✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
27 | NAPI_CALL(env, false, |
69 | napi_create_int64(env, revIdx, &cbArgv[3])); | ||
70 | |||
71 |
1/6✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
27 | NAPI_CALL(env, false, |
72 | napi_call_function( | ||
73 | env, | ||
74 | cbThis, | ||
75 | callback, | ||
76 | (sizeof(cbArgv) / sizeof(napi_value)), | ||
77 | cbArgv, | ||
78 | NULL | ||
79 | ) | ||
80 | ); | ||
81 | |||
82 | 27 | current = g_tree_node_previous(current); | |
83 | } | ||
84 | #else | ||
85 | GPtrArray *arr = gtreeToPtrArray(btree->nativeTree); | ||
86 | |||
87 | napi_value key, value; | ||
88 | napi_ref item ; | ||
89 | for (glong revIdx = arr->len - 1, idx = 0; revIdx >= 0; revIdx--, idx++) { | ||
90 | item = (napi_ref) g_ptr_array_index(arr, revIdx); | ||
91 | |||
92 | unrefBtreeNodeEsObject(env, item, &key, &value); | ||
93 | |||
94 | cbArgv[0] = value; | ||
95 | cbArgv[1] = key; | ||
96 | |||
97 | NAPI_CALL(env, false, | ||
98 | napi_create_int64(env, idx, &cbArgv[2])); | ||
99 | |||
100 | NAPI_CALL(env, false, | ||
101 | napi_create_int64(env, revIdx, &cbArgv[3])); | ||
102 | |||
103 | NAPI_CALL(env, false, | ||
104 | napi_call_function( | ||
105 | env, | ||
106 | cbThis, | ||
107 | callback, | ||
108 | (sizeof(cbArgv) / sizeof(napi_value)), | ||
109 | cbArgv, | ||
110 | NULL | ||
111 | ) | ||
112 | ); | ||
113 | } | ||
114 | |||
115 | g_ptr_array_free(arr, TRUE); | ||
116 | #endif | ||
117 | |||
118 | 9 | return getEsUndef(env); | |
119 | 10 | } | |
120 | |||
121 |