1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation 2425bb815Sopenharmony_ci * 3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License. 5425bb815Sopenharmony_ci * You may obtain a copy of the License at 6425bb815Sopenharmony_ci * 7425bb815Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8425bb815Sopenharmony_ci * 9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS 11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and 13425bb815Sopenharmony_ci * limitations under the License. 14425bb815Sopenharmony_ci */ 15425bb815Sopenharmony_ci 16425bb815Sopenharmony_ci#include "ecma-alloc.h" 17425bb815Sopenharmony_ci#include "ecma-helpers.h" 18425bb815Sopenharmony_ci#include "ecma-builtin-helpers.h" 19425bb815Sopenharmony_ci#include "lit-char-helpers.h" 20425bb815Sopenharmony_ci 21425bb815Sopenharmony_ci#if ENABLED (JERRY_BUILTIN_JSON) 22425bb815Sopenharmony_ci 23425bb815Sopenharmony_ci/** \addtogroup ecma ECMA 24425bb815Sopenharmony_ci * @{ 25425bb815Sopenharmony_ci * 26425bb815Sopenharmony_ci * \addtogroup ecmabuiltinhelpers ECMA builtin helper operations 27425bb815Sopenharmony_ci * @{ 28425bb815Sopenharmony_ci */ 29425bb815Sopenharmony_ci 30425bb815Sopenharmony_ci/** 31425bb815Sopenharmony_ci * Check whether the object is pushed onto the occurence stack 32425bb815Sopenharmony_ci * 33425bb815Sopenharmony_ci * Used by: 34425bb815Sopenharmony_ci * - ecma_builtin_json_object step 1 35425bb815Sopenharmony_ci * - ecma_builtin_json_array step 1 36425bb815Sopenharmony_ci * 37425bb815Sopenharmony_ci * @return true - if the object is pushed onto the occurence stack 38425bb815Sopenharmony_ci * false - otherwise 39425bb815Sopenharmony_ci */ 40425bb815Sopenharmony_cibool 41425bb815Sopenharmony_ciecma_json_has_object_in_stack (ecma_json_occurence_stack_item_t *stack_p, /**< stack */ 42425bb815Sopenharmony_ci ecma_object_t *object_p) /**< object */ 43425bb815Sopenharmony_ci{ 44425bb815Sopenharmony_ci while (stack_p != NULL) 45425bb815Sopenharmony_ci { 46425bb815Sopenharmony_ci if (stack_p->object_p == object_p) 47425bb815Sopenharmony_ci { 48425bb815Sopenharmony_ci return true; 49425bb815Sopenharmony_ci } 50425bb815Sopenharmony_ci 51425bb815Sopenharmony_ci stack_p = stack_p->next_p; 52425bb815Sopenharmony_ci } 53425bb815Sopenharmony_ci 54425bb815Sopenharmony_ci return false; 55425bb815Sopenharmony_ci} /* ecma_json_has_object_in_stack */ 56425bb815Sopenharmony_ci 57425bb815Sopenharmony_ci/** 58425bb815Sopenharmony_ci * Check the string value existance in the collection. 59425bb815Sopenharmony_ci * 60425bb815Sopenharmony_ci * Used by: 61425bb815Sopenharmony_ci * - ecma_builtin_json_stringify step 4.b.ii.5 62425bb815Sopenharmony_ci * 63425bb815Sopenharmony_ci * @return true, if the string is already in the collection. 64425bb815Sopenharmony_ci */ 65425bb815Sopenharmony_cibool 66425bb815Sopenharmony_ciecma_has_string_value_in_collection (ecma_collection_t *collection_p, /**< collection */ 67425bb815Sopenharmony_ci ecma_string_t *string_p) /**< string */ 68425bb815Sopenharmony_ci{ 69425bb815Sopenharmony_ci ecma_value_t *buffer_p = collection_p->buffer_p; 70425bb815Sopenharmony_ci 71425bb815Sopenharmony_ci for (uint32_t i = 0; i < collection_p->item_count; i++) 72425bb815Sopenharmony_ci { 73425bb815Sopenharmony_ci ecma_string_t *current_p = ecma_get_string_from_value (buffer_p[i]); 74425bb815Sopenharmony_ci 75425bb815Sopenharmony_ci if (ecma_compare_ecma_strings (current_p, string_p)) 76425bb815Sopenharmony_ci { 77425bb815Sopenharmony_ci return true; 78425bb815Sopenharmony_ci } 79425bb815Sopenharmony_ci } 80425bb815Sopenharmony_ci 81425bb815Sopenharmony_ci return false; 82425bb815Sopenharmony_ci} /* ecma_has_string_value_in_collection */ 83425bb815Sopenharmony_ci 84425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_BUILTIN_JSON) */ 85425bb815Sopenharmony_ci 86425bb815Sopenharmony_ci/** 87425bb815Sopenharmony_ci * @} 88425bb815Sopenharmony_ci * @} 89425bb815Sopenharmony_ci */ 90