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 #ifndef ECMA_HELPERS_H 17 #define ECMA_HELPERS_H 18 19 #include "ecma-globals.h" 20 #include "jmem.h" 21 #include "lit-strings.h" 22 23 /** \addtogroup ecma ECMA 24 * @{ 25 * 26 * \addtogroup ecmahelpers Helpers for operations with ECMA data types 27 * @{ 28 */ 29 30 /** 31 * Get value of pointer from specified non-null compressed pointer. 32 */ 33 #define ECMA_GET_NON_NULL_POINTER(type, field) JMEM_CP_GET_NON_NULL_POINTER (type, field) 34 35 /** 36 * Extract value of pointer from specified pointer-tag value 37 */ 38 #define ECMA_GET_NON_NULL_POINTER_FROM_POINTER_TAG(type, field) \ 39 JMEM_CP_GET_NON_NULL_POINTER_FROM_POINTER_TAG (type, field) 40 41 /** 42 * Get value of pointer from specified compressed pointer. 43 */ 44 #define ECMA_GET_POINTER(type, field) JMEM_CP_GET_POINTER (type, field) 45 46 /** 47 * Set value of non-null compressed pointer so that it will correspond 48 * to specified non_compressed_pointer. 49 */ 50 #define ECMA_SET_NON_NULL_POINTER(field, non_compressed_pointer) JMEM_CP_SET_NON_NULL_POINTER (field, \ 51 non_compressed_pointer) 52 53 /** 54 * Set value of pointer-tag value so that it will correspond 55 * to specified non_compressed_pointer along with tag 56 */ 57 #define ECMA_SET_NON_NULL_POINTER_TAG(field, non_compressed_pointer, tag) \ 58 JMEM_CP_SET_NON_NULL_POINTER_TAG (field, non_compressed_pointer, tag) 59 60 /** 61 * Set value of compressed pointer so that it will correspond 62 * to specified non_compressed_pointer. 63 */ 64 #define ECMA_SET_POINTER(field, non_compressed_pointer) JMEM_CP_SET_POINTER (field, non_compressed_pointer) 65 66 /** 67 * Get value of each tag bit from specified pointer-tag value 68 */ 69 #define ECMA_GET_FIRST_BIT_FROM_POINTER_TAG(field) \ 70 JMEM_CP_GET_FIRST_BIT_FROM_POINTER_TAG (field) /**< get first tag bit from jmem_cpointer_tag_t **/ 71 #define ECMA_GET_SECOND_BIT_FROM_POINTER_TAG(field) \ 72 JMEM_CP_GET_SECOND_BIT_FROM_POINTER_TAG (field) /**< get second tag bit from jmem_cpointer_tag_t **/ 73 #define ECMA_GET_THIRD_BIT_FROM_POINTER_TAG(field) \ 74 JMEM_CP_GET_THIRD_BIT_FROM_POINTER_TAG (field) /**< get third tag bit from jmem_cpointer_tag_t **/ 75 76 /** 77 * Set value of each tag bit to specified pointer-tag value 78 */ 79 #define ECMA_SET_FIRST_BIT_TO_POINTER_TAG(field) \ 80 JMEM_CP_SET_FIRST_BIT_TO_POINTER_TAG (field) /**< set first tag bit to jmem_cpointer_tag_t **/ 81 #define ECMA_SET_SECOND_BIT_TO_POINTER_TAG(field) \ 82 JMEM_CP_SET_SECOND_BIT_TO_POINTER_TAG (field) /**< set second tag bit to jmem_cpointer_tag_t **/ 83 #define ECMA_SET_THIRD_BIT_TO_POINTER_TAG(field) \ 84 JMEM_CP_SET_THIRD_BIT_TO_POINTER_TAG (field) /**< set third tag bit to jmem_cpointer_tag_t **/ 85 86 /** 87 * Status flags for ecma_string_get_chars function 88 */ 89 typedef enum 90 { 91 ECMA_STRING_FLAG_EMPTY = 0, /**< No options are provided. */ 92 ECMA_STRING_FLAG_IS_ASCII = (1 << 0), /**< The string contains only ASCII characters. */ 93 ECMA_STRING_FLAG_REHASH_NEEDED = (1 << 1), /**< The hash of the string must be recalculated. 94 * For more details see ecma_append_chars_to_string */ 95 ECMA_STRING_FLAG_IS_UINT32 = (1 << 2), /**< The string repesents an UINT32 number */ 96 ECMA_STRING_FLAG_MUST_BE_FREED = (1 << 3), /**< The returned buffer must be freed */ 97 } ecma_string_flag_t; 98 99 /** 100 * Convert ecma-string's contents to a cesu-8 string and put it into a buffer. 101 */ 102 #define ECMA_STRING_TO_UTF8_STRING(ecma_str_ptr, /**< ecma string pointer */ \ 103 utf8_ptr, /**< [out] output buffer pointer */ \ 104 utf8_str_size) /**< [out] output buffer size */ \ 105 lit_utf8_size_t utf8_str_size; \ 106 uint8_t utf8_ptr ## flags = ECMA_STRING_FLAG_EMPTY; \ 107 const lit_utf8_byte_t *utf8_ptr = ecma_string_get_chars (ecma_str_ptr, \ 108 &utf8_str_size, \ 109 NULL, \ 110 NULL, \ 111 &utf8_ptr ## flags); 112 113 /** 114 * Free the cesu-8 string buffer allocated by 'ECMA_STRING_TO_UTF8_STRING' 115 */ 116 #define ECMA_FINALIZE_UTF8_STRING(utf8_ptr, /**< pointer to character buffer */ \ 117 utf8_str_size) /**< buffer size */ \ 118 if (utf8_ptr ## flags & ECMA_STRING_FLAG_MUST_BE_FREED) \ 119 { \ 120 JERRY_ASSERT (utf8_ptr != NULL); \ 121 jmem_heap_free_block ((void *) utf8_ptr, utf8_str_size); \ 122 } 123 124 #ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY 125 126 /** 127 * Set an internal property value from pointer. 128 */ 129 #define ECMA_SET_INTERNAL_VALUE_POINTER(field, pointer) \ 130 (field) = ((ecma_value_t) pointer) 131 132 /** 133 * Set an internal property value from pointer. Pointer can be NULL. 134 */ 135 #define ECMA_SET_INTERNAL_VALUE_ANY_POINTER(field, pointer) \ 136 (field) = ((ecma_value_t) pointer) 137 138 /** 139 * Convert an internal property value to pointer. 140 */ 141 #define ECMA_GET_INTERNAL_VALUE_POINTER(type, field) \ 142 ((type *) field) 143 144 /** 145 * Convert an internal property value to pointer. Result can be NULL. 146 */ 147 #define ECMA_GET_INTERNAL_VALUE_ANY_POINTER(type, field) \ 148 ((type *) field) 149 150 #else /* !ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ 151 152 /** 153 * Set an internal property value from pointer. 154 */ 155 #define ECMA_SET_INTERNAL_VALUE_POINTER(field, pointer) \ 156 ECMA_SET_NON_NULL_POINTER (field, pointer) 157 158 /** 159 * Set an internal property value from pointer. Pointer can be NULL. 160 */ 161 #define ECMA_SET_INTERNAL_VALUE_ANY_POINTER(field, pointer) \ 162 ECMA_SET_POINTER (field, pointer) 163 164 /** 165 * Convert an internal property value to pointer. 166 */ 167 #define ECMA_GET_INTERNAL_VALUE_POINTER(type, field) \ 168 ECMA_GET_NON_NULL_POINTER (type, field) 169 170 /** 171 * Convert an internal property value to pointer. Result can be NULL. 172 */ 173 #define ECMA_GET_INTERNAL_VALUE_ANY_POINTER(type, field) \ 174 ECMA_GET_POINTER (type, field) 175 176 #endif /* ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY */ 177 178 /** 179 * Convert boolean to bitfield value. 180 */ 181 #define ECMA_BOOL_TO_BITFIELD(x) ((x) ? 1 : 0) 182 183 #if ENABLED (JERRY_ES2015) 184 /** 185 * JERRY_ASSERT compatible macro for checking whether the given ecma-value is symbol 186 */ 187 #define ECMA_ASSERT_VALUE_IS_SYMBOL(value) (ecma_is_value_symbol ((value))) 188 #else /* !ENABLED (JERRY_ES2015) */ 189 /** 190 * JERRY_ASSERT compatible macro for checking whether the given ecma-value is symbol 191 */ 192 #define ECMA_ASSERT_VALUE_IS_SYMBOL(value) (false) 193 #endif /* ENABLED (JERRY_ES2015) */ 194 195 /** 196 * Check whether the given type is ECMA_OBJECT_TYPE_PROXY 197 * 198 * @param type object type 199 */ 200 #define ECMA_OBJECT_TYPE_IS_PROXY(type) (JERRY_UNLIKELY ((type) == ECMA_OBJECT_TYPE_PROXY)) 201 202 /** 203 * Check whether the given object has [[ProxyHandler]] and [[ProxyTarger]] internal slots 204 * 205 * @param obj_p ecma-object 206 */ 207 #if ENABLED (JERRY_ES2015_BUILTIN_PROXY) 208 #define ECMA_OBJECT_IS_PROXY(obj_p) (ECMA_OBJECT_TYPE_IS_PROXY (ecma_get_object_type ((obj_p)))) 209 #else /* !ENABLED (JERRY_ES2015_BUILTIN_PROXY) */ 210 #define ECMA_OBJECT_IS_PROXY(obj_p) (false) 211 #endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */ 212 213 /* ecma-helpers-value.c */ 214 ecma_type_t JERRY_ATTR_CONST ecma_get_value_type_field (ecma_value_t value); 215 bool JERRY_ATTR_CONST ecma_is_value_direct (ecma_value_t value); 216 bool JERRY_ATTR_CONST ecma_is_value_simple (ecma_value_t value); 217 bool JERRY_ATTR_CONST ecma_is_value_empty (ecma_value_t value); 218 bool JERRY_ATTR_CONST ecma_is_value_undefined (ecma_value_t value); 219 bool JERRY_ATTR_CONST ecma_is_value_null (ecma_value_t value); 220 bool JERRY_ATTR_CONST ecma_is_value_boolean (ecma_value_t value); 221 bool JERRY_ATTR_CONST ecma_is_value_true (ecma_value_t value); 222 bool JERRY_ATTR_CONST ecma_is_value_false (ecma_value_t value); 223 bool JERRY_ATTR_CONST ecma_is_value_found (ecma_value_t value); 224 bool JERRY_ATTR_CONST ecma_is_value_array_hole (ecma_value_t value); 225 226 bool JERRY_ATTR_CONST ecma_is_value_integer_number (ecma_value_t value); 227 bool JERRY_ATTR_CONST ecma_are_values_integer_numbers (ecma_value_t first_value, ecma_value_t second_value); 228 bool JERRY_ATTR_CONST ecma_is_value_float_number (ecma_value_t value); 229 bool JERRY_ATTR_CONST ecma_is_value_number (ecma_value_t value); 230 bool JERRY_ATTR_CONST ecma_is_value_string (ecma_value_t value); 231 #if ENABLED (JERRY_ES2015) 232 bool JERRY_ATTR_CONST ecma_is_value_symbol (ecma_value_t value); 233 #endif /* ENABLED (JERRY_ES2015) */ 234 bool JERRY_ATTR_CONST ecma_is_value_prop_name (ecma_value_t value); 235 bool JERRY_ATTR_CONST ecma_is_value_direct_string (ecma_value_t value); 236 bool JERRY_ATTR_CONST ecma_is_value_non_direct_string (ecma_value_t value); 237 bool JERRY_ATTR_CONST ecma_is_value_object (ecma_value_t value); 238 bool JERRY_ATTR_CONST ecma_is_value_error_reference (ecma_value_t value); 239 ecma_value_t ecma_is_value_array (ecma_value_t arg); 240 241 void ecma_check_value_type_is_spec_defined (ecma_value_t value); 242 243 ecma_value_t JERRY_ATTR_CONST ecma_make_boolean_value (bool boolean_value); 244 ecma_value_t JERRY_ATTR_CONST ecma_make_integer_value (ecma_integer_value_t integer_value); 245 ecma_value_t ecma_make_nan_value (void); 246 ecma_value_t ecma_make_float_value (ecma_number_t *ecma_num_p); 247 ecma_value_t ecma_make_number_value (ecma_number_t ecma_number); 248 ecma_value_t ecma_make_int32_value (int32_t int32_number); 249 ecma_value_t ecma_make_uint32_value (uint32_t uint32_number); 250 ecma_value_t JERRY_ATTR_PURE ecma_make_string_value (const ecma_string_t *ecma_string_p); 251 #if ENABLED (JERRY_ES2015) 252 ecma_value_t JERRY_ATTR_PURE ecma_make_symbol_value (const ecma_string_t *ecma_symbol_p); 253 #endif /* ENABLED (JERRY_ES2015) */ 254 ecma_value_t JERRY_ATTR_PURE ecma_make_prop_name_value (const ecma_string_t *ecma_prop_name_p); 255 ecma_value_t JERRY_ATTR_PURE ecma_make_magic_string_value (lit_magic_string_id_t id); 256 ecma_value_t JERRY_ATTR_PURE ecma_make_object_value (const ecma_object_t *object_p); 257 ecma_value_t JERRY_ATTR_PURE ecma_make_error_reference_value (const ecma_error_reference_t *error_ref_p); 258 ecma_integer_value_t JERRY_ATTR_CONST ecma_get_integer_from_value (ecma_value_t value); 259 ecma_number_t JERRY_ATTR_PURE ecma_get_float_from_value (ecma_value_t value); 260 ecma_number_t * ecma_get_pointer_from_float_value (ecma_value_t value); 261 ecma_number_t JERRY_ATTR_PURE ecma_get_number_from_value (ecma_value_t value); 262 ecma_string_t JERRY_ATTR_PURE *ecma_get_string_from_value (ecma_value_t value); 263 #if ENABLED (JERRY_ES2015) 264 ecma_string_t JERRY_ATTR_PURE *ecma_get_symbol_from_value (ecma_value_t value); 265 #endif /* ENABLED (JERRY_ES2015) */ 266 ecma_string_t JERRY_ATTR_PURE *ecma_get_prop_name_from_value (ecma_value_t value); 267 ecma_object_t JERRY_ATTR_PURE *ecma_get_object_from_value (ecma_value_t value); 268 ecma_error_reference_t JERRY_ATTR_PURE *ecma_get_error_reference_from_value (ecma_value_t value); 269 ecma_value_t JERRY_ATTR_CONST ecma_invert_boolean_value (ecma_value_t value); 270 ecma_value_t ecma_copy_value (ecma_value_t value); 271 ecma_value_t ecma_fast_copy_value (ecma_value_t value); 272 ecma_value_t ecma_copy_value_if_not_object (ecma_value_t value); 273 void ecma_ref_if_object (ecma_value_t value); 274 void ecma_deref_if_object (ecma_value_t value); 275 ecma_value_t ecma_update_float_number (ecma_value_t float_value, ecma_number_t new_number); 276 void ecma_value_assign_value (ecma_value_t *value_p, ecma_value_t ecma_value); 277 void ecma_value_assign_number (ecma_value_t *value_p, ecma_number_t ecma_number); 278 void ecma_free_value (ecma_value_t value); 279 void ecma_fast_free_value (ecma_value_t value); 280 void ecma_free_value_if_not_object (ecma_value_t value); 281 void ecma_free_number (ecma_value_t value); 282 lit_magic_string_id_t ecma_get_typeof_lit_id (ecma_value_t value); 283 284 /* ecma-helpers-string.c */ 285 #if ENABLED (JERRY_ES2015) 286 ecma_string_t *ecma_new_symbol_from_descriptor_string (ecma_value_t string_desc); 287 bool ecma_prop_name_is_symbol (ecma_string_t *string_p); 288 uint32_t ecma_op_advance_string_index (ecma_string_t *str_p, uint32_t index, bool is_unicode); 289 #endif /* ENABLED (JERRY_ES2015) */ 290 #if ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET) 291 ecma_string_t *ecma_new_map_key_string (ecma_value_t value); 292 bool ecma_prop_name_is_map_key (ecma_string_t *string_p); 293 #endif /* ENABLED (JERRY_ES2015_BUILTIN_MAP) || ENABLED (JERRY_ES2015_BUILTIN_SET) */ 294 ecma_string_t *ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size); 295 ecma_string_t *ecma_new_nonref_ecma_string_from_utf8 (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size); 296 ecma_string_t *ecma_find_special_string (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size); 297 bool ecma_compare_ecma_strings_with_literal (const ecma_string_t *string1_p, const ecma_string_t *string2_p, const lit_utf8_byte_t *chars_p); 298 ecma_string_t *ecma_new_ecma_string_from_utf8_converted_to_cesu8 (const lit_utf8_byte_t *string_p, 299 lit_utf8_size_t string_size); 300 ecma_string_t *ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit); 301 #if ENABLED (JERRY_ES2015) 302 ecma_string_t *ecma_new_ecma_string_from_code_units (ecma_char_t first_code_unit, ecma_char_t second_code_unit); 303 #endif /* ENABLED (JERRY_ES2015) */ 304 ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t uint32_number); 305 ecma_string_t *ecma_new_non_direct_string_from_uint32 (uint32_t uint32_number); 306 ecma_string_t *ecma_get_ecma_string_from_uint32 (uint32_t uint32_number); 307 ecma_string_t *ecma_new_ecma_string_from_number (ecma_number_t num); 308 ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t id); 309 ecma_string_t *ecma_append_chars_to_string (ecma_string_t *string1_p, 310 const lit_utf8_byte_t *cesu8_string2_p, 311 lit_utf8_size_t cesu8_string2_size, 312 lit_utf8_size_t cesu8_string2_length); 313 ecma_string_t *ecma_concat_ecma_strings (ecma_string_t *string1_p, ecma_string_t *string2_p); 314 void ecma_ref_ecma_string (ecma_string_t *string_p); 315 void ecma_deref_ecma_string (ecma_string_t *string_p); 316 void ecma_destroy_ecma_string (ecma_string_t *string_p); 317 ecma_number_t ecma_string_to_number (const ecma_string_t *str_p); 318 uint32_t ecma_string_get_array_index (const ecma_string_t *str_p); 319 320 lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT 321 ecma_string_copy_to_cesu8_buffer (const ecma_string_t *string_desc_p, 322 lit_utf8_byte_t *buffer_p, 323 lit_utf8_size_t buffer_size); 324 lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT 325 ecma_string_copy_to_utf8_buffer (const ecma_string_t *string_desc_p, 326 lit_utf8_byte_t *buffer_p, 327 lit_utf8_size_t buffer_size); 328 lit_utf8_size_t 329 ecma_substring_copy_to_cesu8_buffer (const ecma_string_t *string_desc_p, 330 ecma_length_t start_pos, 331 ecma_length_t end_pos, 332 lit_utf8_byte_t *buffer_p, 333 lit_utf8_size_t buffer_size); 334 lit_utf8_size_t 335 ecma_substring_copy_to_utf8_buffer (const ecma_string_t *string_desc_p, 336 ecma_length_t start_pos, 337 ecma_length_t end_pos, 338 lit_utf8_byte_t *buffer_p, 339 lit_utf8_size_t buffer_size); 340 void ecma_string_to_utf8_bytes (const ecma_string_t *string_desc_p, lit_utf8_byte_t *buffer_p, 341 lit_utf8_size_t buffer_size); 342 const lit_utf8_byte_t *ecma_string_get_chars (const ecma_string_t *string_p, 343 lit_utf8_size_t *size_p, 344 lit_utf8_size_t *length_p, 345 lit_utf8_byte_t *uint32_buff_p, 346 uint8_t *flags_p); 347 bool ecma_compare_ecma_string_to_magic_id (const ecma_string_t *string_p, lit_magic_string_id_t id); 348 bool ecma_string_is_empty (const ecma_string_t *string_p); 349 bool ecma_string_is_length (const ecma_string_t *string_p); 350 351 jmem_cpointer_t ecma_string_to_property_name (ecma_string_t *prop_name_p, ecma_property_t *name_type_p); 352 ecma_string_t *ecma_string_from_property_name (ecma_property_t property, jmem_cpointer_t prop_name_cp); 353 lit_string_hash_t ecma_string_get_property_name_hash (ecma_property_t property, jmem_cpointer_t prop_name_cp); 354 uint32_t ecma_string_get_property_index (ecma_property_t property, jmem_cpointer_t prop_name_cp); 355 bool ecma_string_compare_to_property_name (ecma_property_t property, jmem_cpointer_t prop_name_cp, 356 const ecma_string_t *string_p); 357 358 bool ecma_compare_ecma_strings (const ecma_string_t *string1_p, const ecma_string_t *string2_p); 359 bool ecma_compare_ecma_non_direct_strings (const ecma_string_t *string1_p, const ecma_string_t *string2_p); 360 bool ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, const ecma_string_t *string2_p); 361 ecma_length_t ecma_string_get_length (const ecma_string_t *string_p); 362 ecma_length_t ecma_string_get_utf8_length (const ecma_string_t *string_p); 363 lit_utf8_size_t ecma_string_get_size (const ecma_string_t *string_p); 364 lit_utf8_size_t ecma_string_get_utf8_size (const ecma_string_t *string_p); 365 ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *string_p, ecma_length_t index); 366 367 lit_magic_string_id_t ecma_get_string_magic (const ecma_string_t *string_p); 368 369 lit_string_hash_t ecma_string_hash (const ecma_string_t *string_p); 370 ecma_string_t *ecma_string_substr (const ecma_string_t *string_p, ecma_length_t start_pos, ecma_length_t end_pos); 371 void ecma_string_trim_helper (const lit_utf8_byte_t **utf8_str_p, 372 lit_utf8_size_t *utf8_str_size); 373 ecma_string_t *ecma_string_trim (const ecma_string_t *string_p); 374 375 ecma_stringbuilder_t ecma_stringbuilder_create (void); 376 ecma_stringbuilder_t ecma_stringbuilder_create_from (ecma_string_t *string_p); 377 ecma_stringbuilder_t ecma_stringbuilder_create_raw (const lit_utf8_byte_t *data_p, 378 const lit_utf8_size_t data_size); 379 lit_utf8_size_t ecma_stringbuilder_get_size (ecma_stringbuilder_t *builder_p); 380 lit_utf8_byte_t *ecma_stringbuilder_get_data (ecma_stringbuilder_t *builder_p); 381 void ecma_stringbuilder_revert (ecma_stringbuilder_t *builder_p, const lit_utf8_size_t size); 382 void ecma_stringbuilder_append (ecma_stringbuilder_t *builder_p, const ecma_string_t *string_p); 383 void ecma_stringbuilder_append_magic (ecma_stringbuilder_t *builder_p, const lit_magic_string_id_t id); 384 void ecma_stringbuilder_append_raw (ecma_stringbuilder_t *builder_p, 385 const lit_utf8_byte_t *data_p, 386 const lit_utf8_size_t data_size); 387 void ecma_stringbuilder_append_char (ecma_stringbuilder_t *builder_p, const ecma_char_t c); 388 void ecma_stringbuilder_append_byte (ecma_stringbuilder_t *builder_p, const lit_utf8_byte_t); 389 ecma_string_t *ecma_stringbuilder_finalize (ecma_stringbuilder_t *builder_p); 390 void ecma_stringbuilder_destroy (ecma_stringbuilder_t *builder_p); 391 392 /* ecma-helpers-number.c */ 393 ecma_number_t ecma_number_make_nan (void); 394 ecma_number_t ecma_number_make_infinity (bool sign); 395 bool ecma_number_is_nan (ecma_number_t num); 396 bool ecma_number_is_negative (ecma_number_t num); 397 bool ecma_number_is_zero (ecma_number_t num); 398 bool ecma_number_is_infinity (ecma_number_t num); 399 bool ecma_number_is_finite (ecma_number_t num); 400 ecma_number_t 401 ecma_number_make_from_sign_mantissa_and_exponent (bool sign, uint64_t mantissa, int32_t exponent); 402 ecma_number_t ecma_number_get_prev (ecma_number_t num); 403 ecma_number_t ecma_number_get_next (ecma_number_t num); 404 ecma_number_t ecma_number_trunc (ecma_number_t num); 405 ecma_number_t ecma_number_calc_remainder (ecma_number_t left_num, ecma_number_t right_num); 406 ecma_number_t ecma_number_pow (ecma_number_t x, ecma_number_t y); 407 ecma_value_t ecma_number_parse_int (const lit_utf8_byte_t *string_buff, 408 lit_utf8_size_t string_buff_size, 409 ecma_value_t radix); 410 ecma_value_t ecma_number_parse_float (const lit_utf8_byte_t *string_buff, 411 lit_utf8_size_t string_buff_size); 412 ecma_value_t ecma_integer_multiply (ecma_integer_value_t left_integer, ecma_integer_value_t right_integer); 413 lit_utf8_size_t ecma_number_to_decimal (ecma_number_t num, lit_utf8_byte_t *out_digits_p, int32_t *out_decimal_exp_p); 414 lit_utf8_size_t ecma_number_to_binary_floating_point_number (ecma_number_t num, 415 lit_utf8_byte_t *out_digits_p, 416 int32_t *out_decimal_exp_p); 417 418 /* ecma-helpers-collection.c */ 419 ecma_collection_t *ecma_new_collection (void); 420 void ecma_collection_push_back (ecma_collection_t *collection_p, ecma_value_t value); 421 void ecma_collection_reserve (ecma_collection_t *collection_p, uint32_t count); 422 void ecma_collection_append (ecma_collection_t *collection_p, const ecma_value_t *buffer_p, uint32_t count); 423 void ecma_collection_destroy (ecma_collection_t *collection_p); 424 void ecma_collection_free (ecma_collection_t *collection_p); 425 void ecma_collection_free_if_not_object (ecma_collection_t *collection_p); 426 void ecma_collection_free_objects (ecma_collection_t *collection_p); 427 428 /* ecma-helpers.c */ 429 ecma_object_t *ecma_create_object (ecma_object_t *prototype_object_p, size_t ext_object_size, ecma_object_type_t type); 430 ecma_object_t *ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p); 431 ecma_object_t *ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, ecma_object_t *binding_obj_p, 432 ecma_lexical_environment_type_t type); 433 bool JERRY_ATTR_PURE ecma_is_lexical_environment (const ecma_object_t *object_p); 434 void ecma_op_ordinary_object_set_extensible (ecma_object_t *object_p); 435 ecma_object_type_t JERRY_ATTR_PURE ecma_get_object_type (const ecma_object_t *object_p); 436 bool JERRY_ATTR_PURE ecma_get_object_is_builtin (const ecma_object_t *object_p); 437 void ecma_set_object_is_builtin (ecma_object_t *object_p); 438 uint8_t ecma_get_object_builtin_id (ecma_object_t *object_p); 439 ecma_lexical_environment_type_t JERRY_ATTR_PURE ecma_get_lex_env_type (const ecma_object_t *object_p); 440 ecma_object_t JERRY_ATTR_PURE *ecma_get_lex_env_binding_object (const ecma_object_t *object_p); 441 ecma_object_t *ecma_clone_decl_lexical_environment (ecma_object_t *lex_env_p, bool copy_values); 442 443 ecma_property_value_t * 444 ecma_create_named_data_property (ecma_object_t *object_p, ecma_string_t *name_p, uint8_t prop_attributes, 445 ecma_property_t **out_prop_p); 446 ecma_property_value_t * 447 ecma_create_named_accessor_property (ecma_object_t *object_p, ecma_string_t *name_p, ecma_object_t *get_p, 448 ecma_object_t *set_p, uint8_t prop_attributes, ecma_property_t **out_prop_p); 449 ecma_property_t * 450 ecma_find_named_property (ecma_object_t *obj_p, ecma_string_t *name_p); 451 ecma_property_value_t * 452 ecma_get_named_data_property (ecma_object_t *obj_p, ecma_string_t *name_p); 453 454 void ecma_free_property (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *property_p); 455 456 void ecma_delete_property (ecma_object_t *object_p, ecma_property_value_t *prop_value_p); 457 458 void ecma_named_data_property_assign_value (ecma_object_t *obj_p, ecma_property_value_t *prop_value_p, 459 ecma_value_t value); 460 461 ecma_getter_setter_pointers_t * 462 ecma_get_named_accessor_property (const ecma_property_value_t *prop_value_p); 463 void ecma_set_named_accessor_property_getter (ecma_object_t *object_p, ecma_property_value_t *prop_value_p, 464 ecma_object_t *getter_p); 465 void ecma_set_named_accessor_property_setter (ecma_object_t *object_p, ecma_property_value_t *prop_value_p, 466 ecma_object_t *setter_p); 467 bool ecma_is_property_writable (ecma_property_t property); 468 void ecma_set_property_writable_attr (ecma_property_t *property_p, bool is_writable); 469 bool ecma_is_property_enumerable (ecma_property_t property); 470 void ecma_set_property_enumerable_attr (ecma_property_t *property_p, bool is_enumerable); 471 bool ecma_is_property_configurable (ecma_property_t property); 472 void ecma_set_property_configurable_attr (ecma_property_t *property_p, bool is_configurable); 473 474 #if ENABLED (JERRY_LCACHE) 475 bool ecma_is_property_lcached (ecma_property_t *property_p); 476 void ecma_set_property_lcached (ecma_property_t *property_p, bool is_lcached); 477 #endif /* ENABLED (JERRY_LCACHE) */ 478 479 ecma_property_descriptor_t ecma_make_empty_property_descriptor (void); 480 void ecma_free_property_descriptor (ecma_property_descriptor_t *prop_desc_p); 481 482 ecma_value_t ecma_create_error_reference (ecma_value_t value, bool is_exception); 483 ecma_value_t ecma_create_error_reference_from_context (void); 484 ecma_value_t ecma_create_error_object_reference (ecma_object_t *object_p); 485 void ecma_ref_error_reference (ecma_error_reference_t *error_ref_p); 486 void ecma_deref_error_reference (ecma_error_reference_t *error_ref_p); 487 void ecma_raise_error_from_error_reference (ecma_value_t value); 488 489 void ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p); 490 void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p); 491 #if ENABLED (JERRY_ES2015) 492 ecma_collection_t *ecma_compiled_code_get_tagged_template_collection (const ecma_compiled_code_t *bytecode_header_p); 493 #endif /* ENABLED (JERRY_ES2015) */ 494 #if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) || ENABLED (JERRY_ES2015) 495 ecma_length_t ecma_compiled_code_get_formal_params (const ecma_compiled_code_t *bytecode_p); 496 #endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) || ENABLED (JERRY_ES2015) */ 497 #if (JERRY_STACK_LIMIT != 0) 498 uintptr_t ecma_get_current_stack_usage (void); 499 #endif /* (JERRY_STACK_LIMIT != 0) */ 500 501 /* ecma-helpers-external-pointers.c */ 502 bool ecma_create_native_pointer_property (ecma_object_t *obj_p, void *native_p, void *info_p); 503 ecma_native_pointer_t *ecma_get_native_pointer_value (ecma_object_t *obj_p, void *info_p); 504 bool ecma_delete_native_pointer_property (ecma_object_t *obj_p, void *info_p); 505 506 /* ecma-helpers-conversion.c */ 507 ecma_number_t ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, lit_utf8_size_t str_size); 508 lit_utf8_size_t ecma_uint32_to_utf8_string (uint32_t value, lit_utf8_byte_t *out_buffer_p, lit_utf8_size_t buffer_size); 509 uint32_t ecma_number_to_uint32 (ecma_number_t num); 510 int32_t ecma_number_to_int32 (ecma_number_t num); 511 lit_utf8_size_t ecma_number_to_utf8_string (ecma_number_t num, lit_utf8_byte_t *buffer_p, lit_utf8_size_t buffer_size); 512 513 /* ecma-helpers-errol.c */ 514 lit_utf8_size_t ecma_errol0_dtoa (double val, lit_utf8_byte_t *buffer_p, int32_t *exp_p); 515 516 /** 517 * @} 518 * @} 519 */ 520 521 #endif /* !ECMA_HELPERS_H */ 522