1/* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "arg-internal.h"
17#include "jerryscript-ext/arg.h"
18#include "jerryscript.h"
19
20/**
21 * Pop the current JS argument from the iterator.
22 * It will change the index and js_arg_p value in the iterator.
23 *
24 * @return the current JS argument.
25 */
26jerry_value_t
27jerryx_arg_js_iterator_pop (jerryx_arg_js_iterator_t *js_arg_iter_p) /**< the JS arg iterator */
28{
29 return (js_arg_iter_p->js_arg_idx++ < js_arg_iter_p->js_arg_cnt ? *js_arg_iter_p->js_arg_p++
30 : jerry_create_undefined ());
31} /* jerryx_arg_js_iterator_pop */
32
33/**
34 * Restore the previous JS argument from the iterator.
35 * It will change the index and js_arg_p value in the iterator.
36 *
37 * @return the restored (now current) JS argument.
38 */
39jerry_value_t
40jerryx_arg_js_iterator_restore (jerryx_arg_js_iterator_t *js_arg_iter_p) /**< the JS arg iterator */
41{
42 if (js_arg_iter_p->js_arg_idx == 0)
43 {
44 return jerry_create_undefined ();
45 }
46
47 --js_arg_iter_p->js_arg_idx;
48 --js_arg_iter_p->js_arg_p;
49
50 return *js_arg_iter_p->js_arg_p;
51} /* jerryx_arg_js_iterator_restore */
52
53/**
54 * Get the current JS argument from the iterator.
55 *
56 * Note:
57 * Unlike jerryx_arg_js_iterator_pop, it will not change index and
58 * js_arg_p value in the iterator.
59 *
60 * @return the current JS argument.
61 */
62jerry_value_t
63jerryx_arg_js_iterator_peek (jerryx_arg_js_iterator_t *js_arg_iter_p) /**< the JS arg iterator */
64{
65 return (js_arg_iter_p->js_arg_idx < js_arg_iter_p->js_arg_cnt ? *js_arg_iter_p->js_arg_p
66 : jerry_create_undefined ());
67} /* jerryx_arg_js_iterator_peek */
68
69/**
70 * Get the index of the current JS argument
71 *
72 * @return the index
73 */
74jerry_length_t
75jerryx_arg_js_iterator_index (jerryx_arg_js_iterator_t *js_arg_iter_p) /**< the JS arg iterator */
76{
77 return js_arg_iter_p->js_arg_idx;
78} /* jerryx_arg_js_iterator_index */
79