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_ecma_string_from_utf8_converted_to_cesu8 (const lit_utf8_byte_t *string_p, 296 lit_utf8_size_t string_size); 297 ecma_string_t *ecma_new_ecma_string_from_code_unit (ecma_char_t code_unit); 298 #if ENABLED (JERRY_ES2015) 299 ecma_string_t *ecma_new_ecma_string_from_code_units (ecma_char_t first_code_unit, ecma_char_t second_code_unit); 300 #endif /* ENABLED (JERRY_ES2015) */ 301 ecma_string_t *ecma_new_ecma_string_from_uint32 (uint32_t uint32_number); 302 ecma_string_t *ecma_new_non_direct_string_from_uint32 (uint32_t uint32_number); 303 ecma_string_t *ecma_get_ecma_string_from_uint32 (uint32_t uint32_number); 304 ecma_string_t *ecma_new_ecma_string_from_number (ecma_number_t num); 305 ecma_string_t *ecma_get_magic_string (lit_magic_string_id_t id); 306 ecma_string_t *ecma_append_chars_to_string (ecma_string_t *string1_p, 307 const lit_utf8_byte_t *cesu8_string2_p, 308 lit_utf8_size_t cesu8_string2_size, 309 lit_utf8_size_t cesu8_string2_length); 310 ecma_string_t *ecma_concat_ecma_strings (ecma_string_t *string1_p, ecma_string_t *string2_p); 311 void ecma_ref_ecma_string (ecma_string_t *string_p); 312 void ecma_deref_ecma_string (ecma_string_t *string_p); 313 void ecma_destroy_ecma_string (ecma_string_t *string_p); 314 ecma_number_t ecma_string_to_number (const ecma_string_t *str_p); 315 uint32_t ecma_string_get_array_index (const ecma_string_t *str_p); 316 317 lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT 318 ecma_string_copy_to_cesu8_buffer (const ecma_string_t *string_desc_p, 319 lit_utf8_byte_t *buffer_p, 320 lit_utf8_size_t buffer_size); 321 lit_utf8_size_t JERRY_ATTR_WARN_UNUSED_RESULT 322 ecma_string_copy_to_utf8_buffer (const ecma_string_t *string_desc_p, 323 lit_utf8_byte_t *buffer_p, 324 lit_utf8_size_t buffer_size); 325 lit_utf8_size_t 326 ecma_substring_copy_to_cesu8_buffer (const ecma_string_t *string_desc_p, 327 ecma_length_t start_pos, 328 ecma_length_t end_pos, 329 lit_utf8_byte_t *buffer_p, 330 lit_utf8_size_t buffer_size); 331 lit_utf8_size_t 332 ecma_substring_copy_to_utf8_buffer (const ecma_string_t *string_desc_p, 333 ecma_length_t start_pos, 334 ecma_length_t end_pos, 335 lit_utf8_byte_t *buffer_p, 336 lit_utf8_size_t buffer_size); 337 void ecma_string_to_utf8_bytes (const ecma_string_t *string_desc_p, lit_utf8_byte_t *buffer_p, 338 lit_utf8_size_t buffer_size); 339 const lit_utf8_byte_t *ecma_string_get_chars (const ecma_string_t *string_p, 340 lit_utf8_size_t *size_p, 341 lit_utf8_size_t *length_p, 342 lit_utf8_byte_t *uint32_buff_p, 343 uint8_t *flags_p); 344 bool ecma_compare_ecma_string_to_magic_id (const ecma_string_t *string_p, lit_magic_string_id_t id); 345 bool ecma_string_is_empty (const ecma_string_t *string_p); 346 bool ecma_string_is_length (const ecma_string_t *string_p); 347 348 jmem_cpointer_t ecma_string_to_property_name (ecma_string_t *prop_name_p, ecma_property_t *name_type_p); 349 ecma_string_t *ecma_string_from_property_name (ecma_property_t property, jmem_cpointer_t prop_name_cp); 350 lit_string_hash_t ecma_string_get_property_name_hash (ecma_property_t property, jmem_cpointer_t prop_name_cp); 351 uint32_t ecma_string_get_property_index (ecma_property_t property, jmem_cpointer_t prop_name_cp); 352 bool ecma_string_compare_to_property_name (ecma_property_t property, jmem_cpointer_t prop_name_cp, 353 const ecma_string_t *string_p); 354 355 bool ecma_compare_ecma_strings (const ecma_string_t *string1_p, const ecma_string_t *string2_p); 356 bool ecma_compare_ecma_non_direct_strings (const ecma_string_t *string1_p, const ecma_string_t *string2_p); 357 bool ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, const ecma_string_t *string2_p); 358 ecma_length_t ecma_string_get_length (const ecma_string_t *string_p); 359 ecma_length_t ecma_string_get_utf8_length (const ecma_string_t *string_p); 360 lit_utf8_size_t ecma_string_get_size (const ecma_string_t *string_p); 361 lit_utf8_size_t ecma_string_get_utf8_size (const ecma_string_t *string_p); 362 ecma_char_t ecma_string_get_char_at_pos (const ecma_string_t *string_p, ecma_length_t index); 363 364 lit_magic_string_id_t ecma_get_string_magic (const ecma_string_t *string_p); 365 366 lit_string_hash_t ecma_string_hash (const ecma_string_t *string_p); 367 ecma_string_t *ecma_string_substr (const ecma_string_t *string_p, ecma_length_t start_pos, ecma_length_t end_pos); 368 void ecma_string_trim_helper (const lit_utf8_byte_t **utf8_str_p, 369 lit_utf8_size_t *utf8_str_size); 370 ecma_string_t *ecma_string_trim (const ecma_string_t *string_p); 371 372 ecma_stringbuilder_t ecma_stringbuilder_create (void); 373 ecma_stringbuilder_t ecma_stringbuilder_create_from (ecma_string_t *string_p); 374 ecma_stringbuilder_t ecma_stringbuilder_create_raw (const lit_utf8_byte_t *data_p, 375 const lit_utf8_size_t data_size); 376 lit_utf8_size_t ecma_stringbuilder_get_size (ecma_stringbuilder_t *builder_p); 377 lit_utf8_byte_t *ecma_stringbuilder_get_data (ecma_stringbuilder_t *builder_p); 378 void ecma_stringbuilder_revert (ecma_stringbuilder_t *builder_p, const lit_utf8_size_t size); 379 void ecma_stringbuilder_append (ecma_stringbuilder_t *builder_p, const ecma_string_t *string_p); 380 void ecma_stringbuilder_append_magic (ecma_stringbuilder_t *builder_p, const lit_magic_string_id_t id); 381 void ecma_stringbuilder_append_raw (ecma_stringbuilder_t *builder_p, 382 const lit_utf8_byte_t *data_p, 383 const lit_utf8_size_t data_size); 384 void ecma_stringbuilder_append_char (ecma_stringbuilder_t *builder_p, const ecma_char_t c); 385 void ecma_stringbuilder_append_byte (ecma_stringbuilder_t *builder_p, const lit_utf8_byte_t); 386 ecma_string_t *ecma_stringbuilder_finalize (ecma_stringbuilder_t *builder_p); 387 void ecma_stringbuilder_destroy (ecma_stringbuilder_t *builder_p); 388 389 /* ecma-helpers-number.c */ 390 ecma_number_t ecma_number_make_nan (void); 391 ecma_number_t ecma_number_make_infinity (bool sign); 392 bool ecma_number_is_nan (ecma_number_t num); 393 bool ecma_number_is_negative (ecma_number_t num); 394 bool ecma_number_is_zero (ecma_number_t num); 395 bool ecma_number_is_infinity (ecma_number_t num); 396 bool ecma_number_is_finite (ecma_number_t num); 397 ecma_number_t 398 ecma_number_make_from_sign_mantissa_and_exponent (bool sign, uint64_t mantissa, int32_t exponent); 399 ecma_number_t ecma_number_get_prev (ecma_number_t num); 400 ecma_number_t ecma_number_get_next (ecma_number_t num); 401 ecma_number_t ecma_number_trunc (ecma_number_t num); 402 ecma_number_t ecma_number_calc_remainder (ecma_number_t left_num, ecma_number_t right_num); 403 ecma_number_t ecma_number_pow (ecma_number_t x, ecma_number_t y); 404 ecma_value_t ecma_number_parse_int (const lit_utf8_byte_t *string_buff, 405 lit_utf8_size_t string_buff_size, 406 ecma_value_t radix); 407 ecma_value_t ecma_number_parse_float (const lit_utf8_byte_t *string_buff, 408 lit_utf8_size_t string_buff_size); 409 ecma_value_t ecma_integer_multiply (ecma_integer_value_t left_integer, ecma_integer_value_t right_integer); 410 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); 411 lit_utf8_size_t ecma_number_to_binary_floating_point_number (ecma_number_t num, 412 lit_utf8_byte_t *out_digits_p, 413 int32_t *out_decimal_exp_p); 414 415 /* ecma-helpers-collection.c */ 416 ecma_collection_t *ecma_new_collection (void); 417 void ecma_collection_push_back (ecma_collection_t *collection_p, ecma_value_t value); 418 void ecma_collection_reserve (ecma_collection_t *collection_p, uint32_t count); 419 void ecma_collection_append (ecma_collection_t *collection_p, const ecma_value_t *buffer_p, uint32_t count); 420 void ecma_collection_destroy (ecma_collection_t *collection_p); 421 void ecma_collection_free (ecma_collection_t *collection_p); 422 void ecma_collection_free_if_not_object (ecma_collection_t *collection_p); 423 void ecma_collection_free_objects (ecma_collection_t *collection_p); 424 425 /* ecma-helpers.c */ 426 ecma_object_t *ecma_create_object (ecma_object_t *prototype_object_p, size_t ext_object_size, ecma_object_type_t type); 427 ecma_object_t *ecma_create_decl_lex_env (ecma_object_t *outer_lexical_environment_p); 428 ecma_object_t *ecma_create_object_lex_env (ecma_object_t *outer_lexical_environment_p, ecma_object_t *binding_obj_p, 429 ecma_lexical_environment_type_t type); 430 bool JERRY_ATTR_PURE ecma_is_lexical_environment (const ecma_object_t *object_p); 431 void ecma_op_ordinary_object_set_extensible (ecma_object_t *object_p); 432 ecma_object_type_t JERRY_ATTR_PURE ecma_get_object_type (const ecma_object_t *object_p); 433 bool JERRY_ATTR_PURE ecma_get_object_is_builtin (const ecma_object_t *object_p); 434 void ecma_set_object_is_builtin (ecma_object_t *object_p); 435 uint8_t ecma_get_object_builtin_id (ecma_object_t *object_p); 436 ecma_lexical_environment_type_t JERRY_ATTR_PURE ecma_get_lex_env_type (const ecma_object_t *object_p); 437 ecma_object_t JERRY_ATTR_PURE *ecma_get_lex_env_binding_object (const ecma_object_t *object_p); 438 ecma_object_t *ecma_clone_decl_lexical_environment (ecma_object_t *lex_env_p, bool copy_values); 439 440 ecma_property_value_t * 441 ecma_create_named_data_property (ecma_object_t *object_p, ecma_string_t *name_p, uint8_t prop_attributes, 442 ecma_property_t **out_prop_p); 443 ecma_property_value_t * 444 ecma_create_named_accessor_property (ecma_object_t *object_p, ecma_string_t *name_p, ecma_object_t *get_p, 445 ecma_object_t *set_p, uint8_t prop_attributes, ecma_property_t **out_prop_p); 446 ecma_property_t * 447 ecma_find_named_property (ecma_object_t *obj_p, ecma_string_t *name_p); 448 ecma_property_value_t * 449 ecma_get_named_data_property (ecma_object_t *obj_p, ecma_string_t *name_p); 450 451 void ecma_free_property (ecma_object_t *object_p, jmem_cpointer_t name_cp, ecma_property_t *property_p); 452 453 void ecma_delete_property (ecma_object_t *object_p, ecma_property_value_t *prop_value_p); 454 455 void ecma_named_data_property_assign_value (ecma_object_t *obj_p, ecma_property_value_t *prop_value_p, 456 ecma_value_t value); 457 458 ecma_getter_setter_pointers_t * 459 ecma_get_named_accessor_property (const ecma_property_value_t *prop_value_p); 460 void ecma_set_named_accessor_property_getter (ecma_object_t *object_p, ecma_property_value_t *prop_value_p, 461 ecma_object_t *getter_p); 462 void ecma_set_named_accessor_property_setter (ecma_object_t *object_p, ecma_property_value_t *prop_value_p, 463 ecma_object_t *setter_p); 464 bool ecma_is_property_writable (ecma_property_t property); 465 void ecma_set_property_writable_attr (ecma_property_t *property_p, bool is_writable); 466 bool ecma_is_property_enumerable (ecma_property_t property); 467 void ecma_set_property_enumerable_attr (ecma_property_t *property_p, bool is_enumerable); 468 bool ecma_is_property_configurable (ecma_property_t property); 469 void ecma_set_property_configurable_attr (ecma_property_t *property_p, bool is_configurable); 470 471 #if ENABLED (JERRY_LCACHE) 472 bool ecma_is_property_lcached (ecma_property_t *property_p); 473 void ecma_set_property_lcached (ecma_property_t *property_p, bool is_lcached); 474 #endif /* ENABLED (JERRY_LCACHE) */ 475 476 ecma_property_descriptor_t ecma_make_empty_property_descriptor (void); 477 void ecma_free_property_descriptor (ecma_property_descriptor_t *prop_desc_p); 478 479 ecma_value_t ecma_create_error_reference (ecma_value_t value, bool is_exception); 480 ecma_value_t ecma_create_error_reference_from_context (void); 481 ecma_value_t ecma_create_error_object_reference (ecma_object_t *object_p); 482 void ecma_ref_error_reference (ecma_error_reference_t *error_ref_p); 483 void ecma_deref_error_reference (ecma_error_reference_t *error_ref_p); 484 void ecma_raise_error_from_error_reference (ecma_value_t value); 485 486 void ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p); 487 void ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p); 488 #if ENABLED (JERRY_ES2015) 489 ecma_collection_t *ecma_compiled_code_get_tagged_template_collection (const ecma_compiled_code_t *bytecode_header_p); 490 #endif /* ENABLED (JERRY_ES2015) */ 491 #if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) || ENABLED (JERRY_ES2015) 492 ecma_length_t ecma_compiled_code_get_formal_params (const ecma_compiled_code_t *bytecode_p); 493 #endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) || ENABLED (JERRY_ES2015) */ 494 #if (JERRY_STACK_LIMIT != 0) 495 uintptr_t ecma_get_current_stack_usage (void); 496 #endif /* (JERRY_STACK_LIMIT != 0) */ 497 498 /* ecma-helpers-external-pointers.c */ 499 bool ecma_create_native_pointer_property (ecma_object_t *obj_p, void *native_p, void *info_p); 500 ecma_native_pointer_t *ecma_get_native_pointer_value (ecma_object_t *obj_p, void *info_p); 501 bool ecma_delete_native_pointer_property (ecma_object_t *obj_p, void *info_p); 502 503 /* ecma-helpers-conversion.c */ 504 ecma_number_t ecma_utf8_string_to_number (const lit_utf8_byte_t *str_p, lit_utf8_size_t str_size); 505 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); 506 uint32_t ecma_number_to_uint32 (ecma_number_t num); 507 int32_t ecma_number_to_int32 (ecma_number_t num); 508 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); 509 510 /* ecma-helpers-errol.c */ 511 lit_utf8_size_t ecma_errol0_dtoa (double val, lit_utf8_byte_t *buffer_p, int32_t *exp_p); 512 513 /** 514 * @} 515 * @} 516 */ 517 518 #endif /* !ECMA_HELPERS_H */ 519