• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ecma-alloc.h"
17 #include "ecma-helpers.h"
18 #include "ecma-builtin-helpers.h"
19 #include "lit-char-helpers.h"
20 
21 #if ENABLED (JERRY_BUILTIN_JSON)
22 
23 /** \addtogroup ecma ECMA
24  * @{
25  *
26  * \addtogroup ecmabuiltinhelpers ECMA builtin helper operations
27  * @{
28  */
29 
30 /**
31  * Check whether the object is pushed onto the occurence stack
32  *
33  * Used by:
34  *         - ecma_builtin_json_object step 1
35  *         - ecma_builtin_json_array step 1
36  *
37  * @return true - if the object is pushed onto the occurence stack
38  *         false - otherwise
39  */
40 bool
ecma_json_has_object_in_stack(ecma_json_occurence_stack_item_t * stack_p,ecma_object_t * object_p)41 ecma_json_has_object_in_stack (ecma_json_occurence_stack_item_t *stack_p, /**< stack */
42                                ecma_object_t *object_p) /**< object */
43 {
44   while (stack_p != NULL)
45   {
46     if (stack_p->object_p == object_p)
47     {
48       return true;
49     }
50 
51     stack_p = stack_p->next_p;
52   }
53 
54   return false;
55 } /* ecma_json_has_object_in_stack */
56 
57 /**
58  * Check the string value existance in the collection.
59  *
60  * Used by:
61  *         - ecma_builtin_json_stringify step 4.b.ii.5
62  *
63  * @return true, if the string is already in the collection.
64  */
65 bool
ecma_has_string_value_in_collection(ecma_collection_t * collection_p,ecma_string_t * string_p)66 ecma_has_string_value_in_collection (ecma_collection_t *collection_p, /**< collection */
67                                      ecma_string_t *string_p) /**< string */
68 {
69   ecma_value_t *buffer_p = collection_p->buffer_p;
70 
71   for (uint32_t i = 0; i < collection_p->item_count; i++)
72   {
73     ecma_string_t *current_p = ecma_get_string_from_value (buffer_p[i]);
74 
75     if (ecma_compare_ecma_strings (current_p, string_p))
76     {
77       return true;
78     }
79   }
80 
81   return false;
82 } /* ecma_has_string_value_in_collection */
83 
84 #endif /* ENABLED (JERRY_BUILTIN_JSON) */
85 
86 /**
87  * @}
88  * @}
89  */
90