• 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 #ifndef ECMA_GLOBALS_H
17 #define ECMA_GLOBALS_H
18 
19 #include "config.h"
20 #include "jrt.h"
21 #include "lit-magic-strings.h"
22 #include "jmem.h"
23 
24 /** \addtogroup ecma ECMA
25  * @{
26  *
27  * \addtogroup ecmatypes ECMA types
28  * @{
29  *
30  * \addtogroup compressedpointer Compressed pointer
31  * @{
32  */
33 
34 /**
35  * The NULL value for compressed pointers
36  */
37 #define ECMA_NULL_POINTER JMEM_CP_NULL
38 
39 #if defined (JMEM_CAN_STORE_POINTER_VALUE_DIRECTLY)
40 
41 /**
42  * JMEM_ALIGNMENT_LOG aligned pointers can be stored directly in ecma_value_t
43  */
44 #define ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY
45 
46 #endif /* JMEM_CAN_STORE_POINTER_VALUE_DIRECTLY */
47 
48 /**
49  * @}
50  */
51 
52 /**
53  * JerryScript init flags.
54  */
55 typedef enum
56 {
57   ECMA_INIT_EMPTY               = (0u),      /**< empty flag set */
58   ECMA_INIT_SHOW_OPCODES        = (1u << 0), /**< dump byte-code to log after parse */
59   ECMA_INIT_SHOW_REGEXP_OPCODES = (1u << 1), /**< dump regexp byte-code to log after compilation */
60   ECMA_INIT_MEM_STATS           = (1u << 2), /**< dump memory statistics */
61 } ecma_init_flag_t;
62 
63 /**
64  * JerryScript status flags.
65  */
66 typedef enum
67 {
68   ECMA_STATUS_API_AVAILABLE     = (1u << 0), /**< api available */
69   ECMA_STATUS_DIRECT_EVAL       = (1u << 1), /**< eval is called directly */
70 #if ENABLED (JERRY_PROPRETY_HASHMAP)
71   ECMA_STATUS_HIGH_PRESSURE_GC  = (1u << 2), /**< last gc was under high pressure */
72 #endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
73   ECMA_STATUS_EXCEPTION         = (1u << 3), /**< last exception is a normal exception */
74   ECMA_STATUS_ABORT             = (1u << 4), /**< last exception is an abort */
75 } ecma_status_flag_t;
76 
77 /**
78  * Type of ecma value
79  */
80 typedef enum
81 {
82   ECMA_TYPE_DIRECT = 0, /**< directly encoded value, a 28 bit signed integer or a simple value */
83   ECMA_TYPE_STRING = 1, /**< pointer to description of a string */
84   ECMA_TYPE_FLOAT = 2, /**< pointer to a 64 or 32 bit floating point number */
85   ECMA_TYPE_OBJECT = 3, /**< pointer to description of an object */
86   ECMA_TYPE_SYMBOL = 4, /**< pointer to description of a symbol */
87   ECMA_TYPE_DIRECT_STRING = 5, /**< directly encoded string values */
88   ECMA_TYPE_ERROR = 7, /**< pointer to description of an error reference (only supported by C API) */
89   ECMA_TYPE_SNAPSHOT_OFFSET = ECMA_TYPE_ERROR, /**< offset to a snapshot number/string */
90   ECMA_TYPE___MAX = ECMA_TYPE_ERROR /** highest value for ecma types */
91 } ecma_type_t;
92 
93 #if ENABLED (JERRY_DEBUGGER)
94 /**
95  * Shift for scope chain index part in ecma_parse_opts
96  */
97 #define ECMA_PARSE_CHAIN_INDEX_SHIFT 16
98 #endif /* ENABLED (JERRY_DEBUGGER) */
99 
100 /**
101  * Option flags for parser_parse_script and internal flags for global_status_flags in parser context.
102  * Note:
103  *      the last 16 bits is reserved for internal parser flags, because the debugger uses these
104  *      16 bits to encode the scope chain skip index as well (see ECMA_PARSE_CHAIN_INDEX_SHIFT)
105  */
106 typedef enum
107 {
108   ECMA_PARSE_NO_OPTS = 0, /**< no options passed */
109   ECMA_PARSE_STRICT_MODE = (1u << 0), /**< enable strict mode, must be same as PARSER_IS_STRICT */
110   ECMA_PARSE_MODULE = (1u << 1), /**< module is parsed */
111   ECMA_PARSE_EVAL = (1u << 2), /**< eval is called */
112   ECMA_PARSE_DIRECT_EVAL = (1u << 3), /**< eval is called directly (ECMA-262 v5, 15.1.2.1.1) */
113   ECMA_PARSE_CLASS_CONSTRUCTOR = (1u << 4), /**< a class constructor is being parsed */
114 
115   /* These four status flags must be in this order. The first three are also parser status flags.
116    * See PARSER_SAVE_STATUS_FLAGS / PARSER_RESTORE_STATUS_FLAGS. */
117   ECMA_PARSE_ALLOW_SUPER = (1u << 5), /**< allow super property access */
118   ECMA_PARSE_ALLOW_SUPER_CALL = (1u << 6), /**< allow super constructor call */
119   ECMA_PARSE_ALLOW_NEW_TARGET = (1u << 7), /**< allow new.target access */
120   ECMA_PARSE_FUNCTION_CONTEXT = (1u << 8), /**< function context is present (ECMA_PARSE_DIRECT_EVAL must be set) */
121 
122   ECMA_PARSE_GENERATOR_FUNCTION = (1u << 9), /**< generator function is parsed */
123 
124   /* These flags are internally used by the parser. */
125 #ifndef JERRY_NDEBUG
126   /**
127    * This flag represents an error in for in/of statements, which cannot be set
128    * if the parsing is completed successfully.
129    */
130   ECMA_PARSE_INTERNAL_FOR_IN_OFF_CONTEXT_ERROR = (1u << 30),
131 #endif /* !JERRY_NDEBUG */
132 } ecma_parse_opts_t;
133 
134 /**
135  * Description of an ecma value
136  *
137  * Bit-field structure: type (3) | value (29)
138  */
139 typedef uint32_t ecma_value_t;
140 
141 /**
142  * Type for directly encoded integer numbers in JerryScript.
143  */
144 typedef int32_t ecma_integer_value_t;
145 
146 /**
147  * Mask for ecma types in ecma_value_t
148  */
149 #define ECMA_VALUE_TYPE_MASK 0x7u
150 
151 /**
152  * Shift for value part in ecma_value_t
153  */
154 #define ECMA_VALUE_SHIFT 3
155 
156 /**
157  * Mask for directly encoded values
158  */
159 #define ECMA_DIRECT_TYPE_MASK ((1u << ECMA_VALUE_SHIFT) | ECMA_VALUE_TYPE_MASK)
160 
161 /**
162  * Ecma integer value type
163  */
164 #define ECMA_DIRECT_TYPE_INTEGER_VALUE ((0u << ECMA_VALUE_SHIFT) | ECMA_TYPE_DIRECT)
165 
166 /**
167  * Ecma simple value type
168  */
169 #define ECMA_DIRECT_TYPE_SIMPLE_VALUE ((1u << ECMA_VALUE_SHIFT) | ECMA_TYPE_DIRECT)
170 
171 /**
172  * Shift for directly encoded values in ecma_value_t
173  */
174 #define ECMA_DIRECT_SHIFT 4
175 
176 /**
177  * ECMA make simple value
178  */
179 #define ECMA_MAKE_VALUE(value) \
180   ((((ecma_value_t) (value)) << ECMA_DIRECT_SHIFT) | ECMA_DIRECT_TYPE_SIMPLE_VALUE)
181 
182 /**
183  * Simple ecma values
184  */
185 enum
186 {
187   /**
188    * Empty value is implementation defined value, used for representing:
189    *   - empty (uninitialized) values
190    *   - immutable binding values
191    *   - special register or stack values for vm
192    */
193   ECMA_VALUE_EMPTY = ECMA_MAKE_VALUE (0), /**< uninitialized value */
194   ECMA_VALUE_ERROR = ECMA_MAKE_VALUE (1), /**< an error is currently thrown */
195   ECMA_VALUE_FALSE = ECMA_MAKE_VALUE (2), /**< boolean false */
196   ECMA_VALUE_TRUE = ECMA_MAKE_VALUE (3), /**< boolean true */
197   ECMA_VALUE_UNDEFINED = ECMA_MAKE_VALUE (4), /**< undefined value */
198   ECMA_VALUE_NULL = ECMA_MAKE_VALUE (5), /**< null value */
199   ECMA_VALUE_ARRAY_HOLE = ECMA_MAKE_VALUE (6), /**< array hole, used for
200                                                 *   initialization of an array literal */
201   ECMA_VALUE_NOT_FOUND = ECMA_MAKE_VALUE (7), /**< a special value returned by
202                                                *   ecma_op_object_find */
203   ECMA_VALUE_REGISTER_REF = ECMA_MAKE_VALUE (8), /**< register reference,
204                                                   *   a special "base" value for vm */
205   ECMA_VALUE_RELEASE_LEX_ENV = ECMA_MAKE_VALUE (9), /**< if this error remains on the stack when an exception occours
206                                                          the top lexical environment of the VM frame should be popped */
207   ECMA_VALUE_UNINITIALIZED = ECMA_MAKE_VALUE (10), /**< a special value for uninitialized let/const declarations */
208   ECMA_VALUE_SPREAD_ELEMENT = ECMA_MAKE_VALUE (11), /**< a special value for spread elements in array initialization
209                                                      *   or function call argument list */
210 };
211 
212 #if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
213 /**
214  * Maximum integer number for an ecma value
215  */
216 #define ECMA_INTEGER_NUMBER_MAX         0x7fffff
217 /**
218  * Maximum integer number for an ecma value (shifted left with ECMA_DIRECT_SHIFT)
219  */
220 #define ECMA_INTEGER_NUMBER_MAX_SHIFTED 0x7fffff0
221 #else /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
222 /**
223  * Maximum integer number for an ecma value
224  */
225 #define ECMA_INTEGER_NUMBER_MAX         0x7ffffff
226 /**
227  * Maximum integer number for an ecma value (shifted left with ECMA_DIRECT_SHIFT)
228  */
229 #define ECMA_INTEGER_NUMBER_MAX_SHIFTED 0x7ffffff0
230 #endif /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
231 
232 #if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
233 /**
234  * Minimum integer number for an ecma value
235  */
236 #define ECMA_INTEGER_NUMBER_MIN         -0x7fffff
237 /**
238  * Minimum integer number for an ecma value (shifted left with ECMA_DIRECT_SHIFT)
239  */
240 #define ECMA_INTEGER_NUMBER_MIN_SHIFTED -0x7fffff0
241 #else /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
242 /**
243  * Minimum integer number for an ecma value
244  */
245 #define ECMA_INTEGER_NUMBER_MIN         -0x8000000
246 /**
247  * Minimum integer number for an ecma value (shifted left with ECMA_DIRECT_SHIFT)
248  */
249 #define ECMA_INTEGER_NUMBER_MIN_SHIFTED (-0x7fffffff - 1) /* -0x80000000 */
250 #endif /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
251 
252 #if ECMA_DIRECT_SHIFT != 4
253 #error "Please update ECMA_INTEGER_NUMBER_MIN/MAX_SHIFTED according to the new value of ECMA_DIRECT_SHIFT."
254 #endif
255 
256 /**
257  * Checks whether the integer number is in the integer number range.
258  */
259 #define ECMA_IS_INTEGER_NUMBER(num) \
260   (ECMA_INTEGER_NUMBER_MIN <= (num) && (num) <= ECMA_INTEGER_NUMBER_MAX)
261 
262 /**
263  * Maximum integer number, which if squared, still fits in ecma_integer_value_t
264  */
265 #if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
266 #define ECMA_INTEGER_MULTIPLY_MAX 0xb50
267 #else /* ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
268 #define ECMA_INTEGER_MULTIPLY_MAX 0x2d41
269 #endif /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
270 
271 /**
272  * Checks whether the error flag is set.
273  */
274 #define ECMA_IS_VALUE_ERROR(value) \
275   (JERRY_UNLIKELY ((value) == ECMA_VALUE_ERROR))
276 
277 /**
278  * Callback which tells whether the ECMAScript execution should be stopped.
279  */
280 typedef ecma_value_t (*ecma_vm_exec_stop_callback_t) (void *user_p);
281 
282 /**
283  * Type of an external function handler.
284  */
285 typedef ecma_value_t (*ecma_external_handler_t) (const ecma_value_t function_obj,
286                                                  const ecma_value_t this_val,
287                                                  const ecma_value_t args_p[],
288                                                  const ecma_length_t args_count);
289 
290 /**
291  * Native free callback of an object.
292  */
293 typedef void (*ecma_object_native_free_callback_t) (void *native_p);
294 
295 /**
296  * Type information of a native pointer.
297  */
298 typedef struct
299 {
300   ecma_object_native_free_callback_t free_cb; /**< the free callback of the native pointer */
301 } ecma_object_native_info_t;
302 
303 /**
304  * Representation for native pointer data.
305  */
306 typedef struct ecma_native_pointer_t
307 {
308   void *data_p; /**< points to the data of the object */
309   ecma_object_native_info_t *info_p; /**< native info */
310   struct ecma_native_pointer_t *next_p; /**< points to the next ecma_native_pointer_t element */
311 } ecma_native_pointer_t;
312 
313 /**
314  * Property list:
315  *   The property list of an object is a chain list of various items.
316  *   The type of each item is stored in the first byte of the item.
317  *
318  *   The most common item is the property pair, which contains two
319  *   ecmascript properties. It is also important, that after the
320  *   first property pair, only property pair items are allowed.
321  *
322  *   Example for other items is property name hash map, or array of items.
323  */
324 
325 /**
326  * Property type list.
327  */
328 typedef enum
329 {
330   ECMA_PROPERTY_TYPE_SPECIAL, /**< special purpose property (deleted / hashmap) */
331   ECMA_PROPERTY_TYPE_NAMEDDATA, /**< property is named data */
332   ECMA_PROPERTY_TYPE_NAMEDACCESSOR, /**< property is named accessor */
333   ECMA_PROPERTY_TYPE_INTERNAL, /**< internal property with custom data field */
334   ECMA_PROPERTY_TYPE_VIRTUAL = ECMA_PROPERTY_TYPE_INTERNAL, /**< property is virtual data property */
335 
336   ECMA_PROPERTY_TYPE__MAX = ECMA_PROPERTY_TYPE_VIRTUAL, /**< highest value for property types. */
337 } ecma_property_types_t;
338 
339 /**
340  * Property name listing options.
341  */
342 typedef enum
343 {
344   ECMA_LIST_NO_OPTS = (0), /**< no options are provided */
345   ECMA_LIST_ARRAY_INDICES = (1 << 0), /**< exclude properties with names
346                                        *   that are not indices */
347   ECMA_LIST_ENUMERABLE = (1 << 1), /**< exclude non-enumerable properties */
348   ECMA_LIST_PROTOTYPE = (1 << 2), /**< list properties from prototype chain */
349 #if ENABLED (JERRY_ES2015)
350   ECMA_LIST_SYMBOLS = (1 << 3), /**< list symbol properties */
351   ECMA_LIST_SYMBOLS_ONLY = (1 << 4), /**< list symbol properties only */
352 #endif /* ENABLED (JERRY_ES2015) */
353   ECMA_LIST_CONVERT_FAST_ARRAYS = (1 << 5), /**< after listing the properties convert
354                                              *   the fast access mode array back to normal array */
355 } ecma_list_properties_options_t;
356 
357 /**
358  * List enumerable properties and include the prototype chain.
359  */
360 #define ECMA_LIST_ENUMERABLE_PROTOTYPE (ECMA_LIST_ENUMERABLE | ECMA_LIST_PROTOTYPE)
361 
362 /**
363  * Property type mask.
364  */
365 #define ECMA_PROPERTY_TYPE_MASK 0x3
366 
367 /**
368  * Property flags base shift.
369  */
370 #define ECMA_PROPERTY_FLAG_SHIFT 2
371 
372 /**
373  * Property flag list (for ECMA_PROPERTY_TYPE_NAMEDDATA
374  * and ECMA_PROPERTY_TYPE_NAMEDACCESSOR).
375  */
376 typedef enum
377 {
378   ECMA_PROPERTY_FLAG_CONFIGURABLE = 1u << (ECMA_PROPERTY_FLAG_SHIFT + 0), /**< property is configurable */
379   ECMA_PROPERTY_FLAG_ENUMERABLE = 1u << (ECMA_PROPERTY_FLAG_SHIFT + 1), /**< property is enumerable */
380   ECMA_PROPERTY_FLAG_WRITABLE = 1u << (ECMA_PROPERTY_FLAG_SHIFT + 2), /**< property is writable */
381   ECMA_PROPERTY_FLAG_LCACHED = 1u << (ECMA_PROPERTY_FLAG_SHIFT + 3), /**< property is lcached */
382 } ecma_property_flags_t;
383 
384 /**
385  * Property flags configurable, enumerable, writable.
386  */
387 #define ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE_WRITABLE \
388   (ECMA_PROPERTY_FLAG_CONFIGURABLE | ECMA_PROPERTY_FLAG_ENUMERABLE | ECMA_PROPERTY_FLAG_WRITABLE)
389 
390 /**
391  * Property flags configurable, enumerable.
392  */
393 #define ECMA_PROPERTY_CONFIGURABLE_ENUMERABLE \
394   (ECMA_PROPERTY_FLAG_CONFIGURABLE | ECMA_PROPERTY_FLAG_ENUMERABLE)
395 
396 /**
397  * Property flags configurable, enumerable.
398  */
399 #define ECMA_PROPERTY_CONFIGURABLE_WRITABLE \
400   (ECMA_PROPERTY_FLAG_CONFIGURABLE | ECMA_PROPERTY_FLAG_WRITABLE)
401 
402 /**
403  * Property flags enumerable, writable.
404  */
405 #define ECMA_PROPERTY_ENUMERABLE_WRITABLE \
406   (ECMA_PROPERTY_FLAG_ENUMERABLE | ECMA_PROPERTY_FLAG_WRITABLE)
407 
408 /**
409  * No attributes can be changed for this property.
410  */
411 #define ECMA_PROPERTY_FIXED 0
412 
413 /**
414  * Default flag of length property.
415  */
416 #if ENABLED (JERRY_ES2015)
417 #define ECMA_PROPERTY_FLAG_DEFAULT_LENGTH ECMA_PROPERTY_FLAG_CONFIGURABLE
418 #else /* !ENABLED (JERRY_ES2015) */
419 #define ECMA_PROPERTY_FLAG_DEFAULT_LENGTH ECMA_PROPERTY_FIXED
420 #endif /* ENABLED (JERRY_ES2015) */
421 
422 /**
423  * Shift for property name part.
424  */
425 #define ECMA_PROPERTY_NAME_TYPE_SHIFT (ECMA_PROPERTY_FLAG_SHIFT + 4)
426 
427 /**
428  * Convert data property to internal property.
429  */
430 #define ECMA_CONVERT_DATA_PROPERTY_TO_INTERNAL_PROPERTY(property_p) \
431    *(property_p) = (uint8_t) (*(property_p) + (ECMA_PROPERTY_TYPE_INTERNAL - ECMA_PROPERTY_TYPE_NAMEDDATA))
432 
433 /**
434  * Convert internal property to data property.
435  */
436 #define ECMA_CONVERT_INTERNAL_PROPERTY_TO_DATA_PROPERTY(property_p) \
437    *(property_p) = (uint8_t) (*(property_p) - (ECMA_PROPERTY_TYPE_INTERNAL - ECMA_PROPERTY_TYPE_NAMEDDATA))
438 
439 /**
440  * Special property identifiers.
441  */
442 typedef enum
443 {
444   /* Note: when new special types are added
445    * ECMA_PROPERTY_IS_PROPERTY_PAIR must be updated as well. */
446   ECMA_SPECIAL_PROPERTY_HASHMAP, /**< hashmap property */
447   ECMA_SPECIAL_PROPERTY_DELETED, /**< deleted property */
448 
449   ECMA_SPECIAL_PROPERTY__COUNT /**< Number of special property types */
450 } ecma_special_property_id_t;
451 
452 /**
453  * Define special property type.
454  */
455 #define ECMA_SPECIAL_PROPERTY_VALUE(type) \
456   ((uint8_t) (ECMA_PROPERTY_TYPE_SPECIAL | ((type) << ECMA_PROPERTY_NAME_TYPE_SHIFT)))
457 
458 /**
459  * Type of deleted property.
460  */
461 #define ECMA_PROPERTY_TYPE_DELETED ECMA_SPECIAL_PROPERTY_VALUE (ECMA_SPECIAL_PROPERTY_DELETED)
462 
463 /**
464  * Type of hash-map property.
465  */
466 #define ECMA_PROPERTY_TYPE_HASHMAP ECMA_SPECIAL_PROPERTY_VALUE (ECMA_SPECIAL_PROPERTY_HASHMAP)
467 
468 /**
469  * Type of property not found.
470  */
471 #define ECMA_PROPERTY_TYPE_NOT_FOUND ECMA_PROPERTY_TYPE_HASHMAP
472 
473 /**
474  * Type of property not found and no more searching in the proto chain.
475  */
476 #define ECMA_PROPERTY_TYPE_NOT_FOUND_AND_STOP ECMA_PROPERTY_TYPE_DELETED
477 
478 /**
479  * Abstract property representation.
480  *
481  * A property is a type_and_flags byte and an ecma_value_t value pair.
482  * This pair is represented by a single pointer in JerryScript. Although
483  * a packed struct would only consume sizeof(ecma_value_t)+1 memory
484  * bytes, accessing such structure is inefficient from the CPU viewpoint
485  * because the value is not naturally aligned. To improve performance,
486  * two type bytes and values are packed together. The memory layout is
487  * the following:
488  *
489  *  [type 1, type 2, unused byte 1, unused byte 2][value 1][value 2]
490  *
491  * The unused two bytes are used to store a compressed pointer for the
492  * next property pair.
493  *
494  * The advantage of this layout is that the value reference can be computed
495  * from the property address. However, property pointers cannot be compressed
496  * anymore.
497  */
498 typedef uint8_t ecma_property_t; /**< ecma_property_types_t (3 bit) and ecma_property_flags_t */
499 
500 /**
501  * Number of items in a property pair.
502  */
503 #define ECMA_PROPERTY_PAIR_ITEM_COUNT 2
504 
505 /**
506  * Property header for all items in a property list.
507  */
508 typedef struct
509 {
510 #if ENABLED (JERRY_CPOINTER_32_BIT)
511   jmem_cpointer_t next_property_cp; /**< next cpointer */
512 #endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
513   ecma_property_t types[ECMA_PROPERTY_PAIR_ITEM_COUNT]; /**< two property type slot. The first represent
514                                                          *   the type of this property (e.g. property pair) */
515 #if ENABLED (JERRY_CPOINTER_32_BIT)
516   uint16_t padding; /**< an unused value */
517 #else /* !ENABLED (JERRY_CPOINTER_32_BIT) */
518   jmem_cpointer_t next_property_cp; /**< next cpointer */
519 #endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
520 } ecma_property_header_t;
521 
522 /**
523  * Pair of pointers - to property's getter and setter
524  */
525 typedef struct
526 {
527   jmem_cpointer_t getter_cp; /**< compressed pointer to getter object */
528   jmem_cpointer_t setter_cp; /**< compressed pointer to setter object */
529 } ecma_getter_setter_pointers_t;
530 
531 /**
532  * Property data.
533  */
534 typedef union
535 {
536   ecma_value_t value; /**< value of a property */
537 #if ENABLED (JERRY_CPOINTER_32_BIT)
538   jmem_cpointer_t getter_setter_pair_cp; /**< cpointer to getter setter pair */
539 #else /* !ENABLED (JERRY_CPOINTER_32_BIT) */
540   ecma_getter_setter_pointers_t getter_setter_pair; /**< getter setter pair */
541 #endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
542 } ecma_property_value_t;
543 
544 /**
545  * Property pair.
546  */
547 typedef struct
548 {
549   ecma_property_header_t header; /**< header of the property */
550   ecma_property_value_t values[ECMA_PROPERTY_PAIR_ITEM_COUNT]; /**< property value slots */
551   jmem_cpointer_t names_cp[ECMA_PROPERTY_PAIR_ITEM_COUNT]; /**< property name slots */
552 } ecma_property_pair_t;
553 
554 /**
555  * Get property type.
556  */
557 #define ECMA_PROPERTY_GET_TYPE(property) \
558   ((ecma_property_types_t) ((property) & ECMA_PROPERTY_TYPE_MASK))
559 
560 /**
561  * Get property name type.
562  */
563 #define ECMA_PROPERTY_GET_NAME_TYPE(property) \
564   ((property) >> ECMA_PROPERTY_NAME_TYPE_SHIFT)
565 
566 /**
567  * Returns true if the property pointer is a property pair.
568  */
569 #define ECMA_PROPERTY_IS_PROPERTY_PAIR(property_header_p) \
570   ((property_header_p)->types[0] != ECMA_PROPERTY_TYPE_HASHMAP)
571 
572 /**
573  * Returns true if the property is named property.
574  */
575 #define ECMA_PROPERTY_IS_NAMED_PROPERTY(property) \
576   (ECMA_PROPERTY_GET_TYPE (property) != ECMA_PROPERTY_TYPE_SPECIAL)
577 
578 /**
579  * Add the offset part to a property for computing its property data pointer.
580  */
581 #define ECMA_PROPERTY_VALUE_ADD_OFFSET(property_p) \
582   ((uintptr_t) ((((uint8_t *) (property_p)) + (sizeof (ecma_property_value_t) * 2 - 1))))
583 
584 /**
585  * Align the property for computing its property data pointer.
586  */
587 #define ECMA_PROPERTY_VALUE_DATA_PTR(property_p) \
588   (ECMA_PROPERTY_VALUE_ADD_OFFSET (property_p) & ~(sizeof (ecma_property_value_t) - 1))
589 
590 /**
591  * Compute the property data pointer of a property.
592  * The property must be part of a property pair.
593  */
594 #define ECMA_PROPERTY_VALUE_PTR(property_p) \
595   ((ecma_property_value_t *) ECMA_PROPERTY_VALUE_DATA_PTR (property_p))
596 
597 /**
598  * Property reference. It contains the value pointer
599  * for real, and the value itself for virtual properties.
600  */
601 typedef union
602 {
603   ecma_property_value_t *value_p; /**< property value pointer for real properties */
604   ecma_value_t virtual_value; /**< property value for virtual properties */
605 } ecma_property_ref_t;
606 
607 /**
608  * Extended property reference, which also contains the
609  * property descriptor pointer for real properties.
610  */
611 typedef struct
612 {
613   ecma_property_ref_t property_ref; /**< property reference */
614   ecma_property_t *property_p; /**< property descriptor pointer for real properties */
615 } ecma_extended_property_ref_t;
616 
617 /**
618  * Option flags for ecma_op_object_get_property.
619  */
620 typedef enum
621 {
622   ECMA_PROPERTY_GET_NO_OPTIONS = 0, /**< no option flags for ecma_op_object_get_property */
623   ECMA_PROPERTY_GET_VALUE = 1u << 0, /**< fill virtual_value field for virtual properties */
624   ECMA_PROPERTY_GET_EXT_REFERENCE = 1u << 1, /**< get extended reference to the property */
625   ECMA_PROPERTY_GET_HAS_OWN_PROP = 1u << 2, /**< internal [[HasOwnProperty]] method */
626 } ecma_property_get_option_bits_t;
627 
628 /**
629  * Internal object types.
630  */
631 typedef enum
632 {
633   ECMA_OBJECT_TYPE_GENERAL = 0, /**< all objects that are not belongs to the sub-types below. */
634   ECMA_OBJECT_TYPE_CLASS = 1, /**< Objects with class property */
635   ECMA_OBJECT_TYPE_ARRAY = 2, /**< Array object (15.4) */
636   ECMA_OBJECT_TYPE_PSEUDO_ARRAY  = 3, /**< Array-like object, such as Arguments object (10.6) */
637   ECMA_OBJECT_TYPE_PROXY  = 4, /**< Proxy object ECMAScript v6 26.2 */
638   /* Note: these 4 types must be in this order. See IsCallable operation.  */
639   ECMA_OBJECT_TYPE_FUNCTION = 5, /**< Function objects (15.3), created through 13.2 routine */
640   ECMA_OBJECT_TYPE_BOUND_FUNCTION = 6, /**< Function objects (15.3), created through 15.3.4.5 routine */
641   ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION = 7, /**< External (host) function object */
642   /* Types between 13-15 cannot have a built-in flag. See ecma_lexical_environment_type_t. */
643 
644   ECMA_OBJECT_TYPE__MAX /**< maximum value */
645 } ecma_object_type_t;
646 
647 /**
648  * Types of objects with class property.
649  */
650 typedef enum
651 {
652   ECMA_PSEUDO_ARRAY_ARGUMENTS = 0, /**< Arguments object (10.6) */
653   ECMA_PSEUDO_ARRAY_TYPEDARRAY = 1, /**< TypedArray which does NOT need extra space to store length and offset */
654   ECMA_PSEUDO_ARRAY_TYPEDARRAY_WITH_INFO = 2, /**< TypedArray which NEEDS extra space to store length and offset */
655   ECMA_PSEUDO_ARRAY_ITERATOR = 3, /**< Array iterator object (ECMAScript v6, 22.1.5.1) */
656   ECMA_PSEUDO_SET_ITERATOR = 4, /**< Set iterator object (ECMAScript v6, 23.2.5.1) */
657   ECMA_PSEUDO_MAP_ITERATOR = 5, /**< Map iterator object (ECMAScript v6, 23.1.5.1) */
658   ECMA_PSEUDO_STRING_ITERATOR = 6, /**< String iterator object (ECMAScript v6, 22.1.5.1) */
659   ECMA_PSEUDO_ARRAY__MAX = ECMA_PSEUDO_STRING_ITERATOR /**< maximum value */
660 } ecma_pseudo_array_type_t;
661 
662 /**
663  * Types of lexical environments.
664  */
665 typedef enum
666 {
667   /* Types between 0 - 12 are ecma_object_type_t which can have a built-in flag. */
668 
669   ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE = 13, /**< declarative lexical environment */
670   ECMA_LEXICAL_ENVIRONMENT_THIS_OBJECT_BOUND = 14, /**< object-bound lexical environment
671                                                     *   with provideThis flag */
672   ECMA_LEXICAL_ENVIRONMENT_HOME_OBJECT_BOUND = 15, /**< object-bound lexical environment
673                                                      *  with provided home object reference */
674 
675   ECMA_LEXICAL_ENVIRONMENT_TYPE_START = ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE, /**< first lexical
676                                                                                *   environment type */
677   ECMA_LEXICAL_ENVIRONMENT_TYPE__MAX = ECMA_LEXICAL_ENVIRONMENT_HOME_OBJECT_BOUND /**< maximum value */
678 } ecma_lexical_environment_type_t;
679 
680 #if ENABLED (JERRY_ES2015)
681 
682 /**
683  * Types of array iterators.
684  */
685 typedef enum
686 {
687   ECMA_ITERATOR_KEYS, /**< List only key indices */
688   ECMA_ITERATOR_VALUES, /**< List only key values */
689   ECMA_ITERATOR_KEYS_VALUES, /**< List key indices and values */
690 } ecma_array_iterator_type_t;
691 
692 #endif /* ENABLED (JERRY_ES2015) */
693 
694 /**
695  * Offset for JERRY_CONTEXT (status_flags) top 8 bits.
696  */
697 #define ECMA_LOCAL_PARSE_OPTS_OFFSET ((sizeof (uint32_t) - sizeof (uint8_t)) * JERRY_BITSINBYTE)
698 
699 /**
700  * Set JERRY_CONTEXT (status_flags) top 8 bits to the specified 'opts'.
701  */
702 #define ECMA_SET_LOCAL_PARSE_OPTS(opts) \
703   do \
704   { \
705     JERRY_CONTEXT (status_flags) |= ((uint32_t) opts << ECMA_LOCAL_PARSE_OPTS_OFFSET) | ECMA_STATUS_DIRECT_EVAL; \
706   } while (0)
707 
708 /**
709  * Get JERRY_CONTEXT (status_flags) top 8 bits.
710  */
711 #define ECMA_GET_LOCAL_PARSE_OPTS() \
712   (JERRY_CONTEXT (status_flags) >> (ECMA_LOCAL_PARSE_OPTS_OFFSET - JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER)))
713 
714 /**
715  * Clear JERRY_CONTEXT (status_flags) top 8 bits.
716  */
717 #define ECMA_CLEAR_LOCAL_PARSE_OPTS() \
718   do \
719   { \
720     JERRY_CONTEXT (status_flags) &= ((1 << ECMA_LOCAL_PARSE_OPTS_OFFSET) - 1); \
721   } while (0)
722 
723 /**
724  * Ecma object type mask for getting the object type.
725  */
726 #define ECMA_OBJECT_TYPE_MASK 0x0fu
727 
728 /**
729  * Ecma object is built-in or lexical environment. When this flag is set, the object is a
730  *   - built-in, if object type is less than ECMA_LEXICAL_ENVIRONMENT_TYPES_START
731  *   - lexical environment, if object type is greater or equal than ECMA_LEXICAL_ENVIRONMENT_TYPES_START
732  */
733 #define ECMA_OBJECT_FLAG_BUILT_IN_OR_LEXICAL_ENV 0x10
734 
735 /**
736  * Extensible object.
737  */
738 #define ECMA_OBJECT_FLAG_EXTENSIBLE 0x20
739 
740 /**
741  * Non closure flag for debugger.
742  */
743 #define ECMA_OBJECT_FLAG_BLOCK ECMA_OBJECT_FLAG_EXTENSIBLE
744 
745 /**
746  * Bitshift index for an ecma-object reference count field
747  */
748 #define ECMA_OBJECT_REF_SHIFT 6
749 
750 /**
751  * Bitmask for an ecma-object reference count field
752  */
753 #define ECMA_OBJECT_REF_MASK (((1u << 10) - 1) << ECMA_OBJECT_REF_SHIFT)
754 
755 /**
756  * Value for increasing or decreasing the object reference counter.
757  */
758 #define ECMA_OBJECT_REF_ONE (1u << ECMA_OBJECT_REF_SHIFT)
759 
760 /**
761  * Represents non-visited white object
762  */
763 #define ECMA_OBJECT_NON_VISITED (0x3ffu << ECMA_OBJECT_REF_SHIFT)
764 
765 /**
766  * Maximum value of the object reference counter (1022).
767  */
768 #define ECMA_OBJECT_MAX_REF (ECMA_OBJECT_NON_VISITED - ECMA_OBJECT_REF_ONE)
769 
770 /**
771  * Description of ECMA-object or lexical environment
772  * (depending on is_lexical_environment).
773  */
774 typedef struct
775 {
776   /** type : 4 bit : ecma_object_type_t or ecma_lexical_environment_type_t
777                      depending on ECMA_OBJECT_FLAG_BUILT_IN_OR_LEXICAL_ENV
778       flags : 2 bit : ECMA_OBJECT_FLAG_BUILT_IN_OR_LEXICAL_ENV,
779                       ECMA_OBJECT_FLAG_EXTENSIBLE or ECMA_OBJECT_FLAG_BLOCK
780       refs : 10 bit (max 1022) */
781   uint16_t type_flags_refs;
782 
783   /** next in the object chain maintained by the garbage collector */
784   jmem_cpointer_t gc_next_cp;
785 
786   /** compressed pointer to property list or bound object */
787   union
788   {
789     jmem_cpointer_t property_list_cp; /**< compressed pointer to object's
790                                        *   or declerative lexical environments's property list */
791     jmem_cpointer_t bound_object_cp;  /**< compressed pointer to lexical environments's the bound object */
792     jmem_cpointer_t home_object_cp;   /**< compressed pointer to lexical environments's the home object */
793   } u1;
794 
795   /** object prototype or outer reference */
796   union
797   {
798     jmem_cpointer_t prototype_cp; /**< compressed pointer to the object's prototype  */
799     jmem_cpointer_t outer_reference_cp; /**< compressed pointer to the lexical environments's outer reference  */
800   } u2;
801 } ecma_object_t;
802 
803 /**
804  * Description of built-in properties of an object.
805  */
806 typedef struct
807 {
808   uint8_t id; /**< built-in id */
809   uint8_t length_and_bitset_size; /**< length for built-in functions and
810                                    *   bit set size for all built-ins */
811   uint16_t routine_id; /**< routine id for built-in functions */
812   union
813   {
814     uint32_t instantiated_bitset[1]; /**< bit set for instantiated properties */
815     struct
816     {
817       uint16_t name; /**< name of the built-in functions */
818       uint16_t bitset; /**< bit set for instantiated properties of builtin functions */
819     } builtin_routine;
820   } u;
821 } ecma_built_in_props_t;
822 
823 /**
824  * Start position of bit set size in length_and_bitset_size field.
825  */
826 #define ECMA_BUILT_IN_BITSET_SHIFT 5
827 
828 /**
829  * Description of extended ECMA-object.
830  *
831  * The extended object is an object with extra fields.
832  */
833 typedef struct
834 {
835   ecma_object_t object; /**< object header */
836 
837   /**
838    * Description of extra fields. These extra fields depend on the object type.
839    */
840   union
841   {
842     ecma_built_in_props_t built_in; /**< built-in object part */
843 
844     /**
845      * Description of objects with class.
846      */
847     struct
848     {
849       uint16_t class_id; /**< class id of the object */
850       uint16_t extra_info; /**< extra information for the object
851                             *   e.g. array buffer type info (external/internal) */
852 
853       /**
854        * Description of extra fields. These extra fields depend on the class_id.
855        */
856       union
857       {
858         ecma_value_t value; /**< value of the object (e.g. boolean, number, string, etc.) */
859         uint32_t length; /**< length related property (e.g. length of ArrayBuffer) */
860         ecma_value_t target; /**< [[ProxyTarget]] internal property */
861       } u;
862     } class_prop;
863 
864     /**
865      * Description of function objects.
866      */
867     struct
868     {
869       jmem_cpointer_tag_t scope_cp; /**< function scope */
870       ecma_value_t bytecode_cp; /**< function byte code */
871     } function;
872 
873     /**
874      * Description of array objects.
875      */
876     struct
877     {
878       uint32_t length; /**< length property value */
879       union
880       {
881         ecma_property_t length_prop; /**< length property */
882         uint32_t hole_count; /**< number of array holes in a fast access mode array
883                               *   multiplied ECMA_FAST_ACCESS_HOLE_ONE */
884       } u;
885 
886     } array;
887 
888     /**
889      * Description of pseudo array objects.
890      */
891     struct
892     {
893       uint8_t type; /**< pseudo array type, e.g. Arguments, TypedArray, ArrayIterator */
894       uint8_t extra_info; /**< extra information about the object.
895                            *   e.g. the specific builtin id for typed arrays,
896                            *        [[IterationKind]] property for %Iterator% */
897       union
898       {
899         uint16_t length; /**< for arguments: length of names */
900         uint16_t class_id; /**< for typedarray: the specific class name id */
901         uint16_t iterator_index; /**< for %Iterator%: [[%Iterator%NextIndex]] property */
902       } u1;
903       union
904       {
905         ecma_value_t lex_env_cp; /**< for arguments: lexical environment */
906         ecma_value_t arraybuffer; /**< for typedarray: internal arraybuffer */
907         ecma_value_t iterated_value; /**< for %Iterator%: [[IteratedObject]] property */
908         ecma_value_t spread_value; /**< for spread object: spreaded element */
909       } u2;
910     } pseudo_array;
911 
912     /**
913      * Description of bound function object.
914      */
915     struct
916     {
917       jmem_cpointer_tag_t target_function; /**< target function */
918       ecma_value_t args_len_or_this; /**< length of arguments or this value */
919     } bound_function;
920 
921     ecma_external_handler_t external_handler_cb; /**< external function */
922   } u;
923 } ecma_extended_object_t;
924 
925 /**
926  * Description of built-in extended ECMA-object.
927  */
928 typedef struct
929 {
930   ecma_extended_object_t extended_object; /**< extended object part */
931   ecma_built_in_props_t built_in; /**< built-in object part */
932 } ecma_extended_built_in_object_t;
933 
934 /**
935  * Alignment for the fast access mode array length.
936  * The real length is aligned up for allocating the underlying buffer.
937  */
938 #define ECMA_FAST_ARRAY_ALIGNMENT (8)
939 
940 /**
941  * Align the length of the fast mode array to get the allocated size of the underlying buffer
942  */
943 #define ECMA_FAST_ARRAY_ALIGN_LENGTH(length) \
944   (uint32_t) ((((length)) + ECMA_FAST_ARRAY_ALIGNMENT - 1) / ECMA_FAST_ARRAY_ALIGNMENT * ECMA_FAST_ARRAY_ALIGNMENT)
945 
946 /**
947  * Compiled byte code data.
948  */
949 typedef struct
950 {
951   uint16_t size;                    /**< real size >> JMEM_ALIGNMENT_LOG */
952   uint16_t refs;                    /**< reference counter for the byte code */
953   uint16_t status_flags;            /**< various status flags:
954                                      *   CBC_CODE_FLAGS_FUNCTION flag tells whether
955                                      *   the byte code is function or regular expression.
956                                      *   If function, the other flags must be CBC_CODE_FLAGS...
957                                      *   If regexp, the other flags must be RE_FLAG... */
958 } ecma_compiled_code_t;
959 
960 /**
961  * Description of bound function objects.
962  */
963 typedef struct
964 {
965   ecma_extended_object_t header; /**< extended object header */
966 #if ENABLED (JERRY_ES2015)
967   ecma_integer_value_t target_length; /**< length of target function */
968 #endif /* ENABLED (JERRY_ES2015) */
969 } ecma_bound_function_t;
970 
971 #if ENABLED (JERRY_SNAPSHOT_EXEC)
972 
973 /**
974  * Description of static function objects.
975  */
976 typedef struct
977 {
978   ecma_extended_object_t header; /**< header part */
979   const ecma_compiled_code_t *bytecode_p; /**< real byte code pointer */
980 } ecma_static_function_t;
981 
982 #endif /* ENABLED (JERRY_SNAPSHOT_EXEC) */
983 
984 #if ENABLED (JERRY_ES2015)
985 
986 /**
987  * Description of arrow function objects.
988  */
989 typedef struct
990 {
991   ecma_extended_object_t header; /**< extended object header */
992   ecma_value_t this_binding; /**< value of 'this' binding */
993   ecma_value_t new_target; /**< value of new.target */
994 } ecma_arrow_function_t;
995 
996 #if ENABLED (JERRY_SNAPSHOT_EXEC)
997 
998 /**
999  * Description of static arrow function objects.
1000  */
1001 typedef struct
1002 {
1003   ecma_arrow_function_t header;
1004   const ecma_compiled_code_t *bytecode_p;
1005 } ecma_static_arrow_function_t;
1006 
1007 #endif /* ENABLED (JERRY_SNAPSHOT_EXEC) */
1008 
1009 #endif /* ENABLED (JERRY_ES2015) */
1010 
1011 #if ENABLED (JERRY_ES2015_BUILTIN_CONTAINER)
1012 /**
1013  * Flags for container objects
1014  */
1015 typedef enum
1016 {
1017   ECMA_CONTAINER_FLAGS_EMPTY = (0), /** empty flags */
1018   ECMA_CONTAINER_FLAGS_WEAK = (1 << 0) /** container object is weak */
1019 } ecma_container_flags_t;
1020 
1021 /**
1022  * Description of map collection.
1023  */
1024 typedef struct
1025 {
1026   ecma_value_t key; /**< key value */
1027   ecma_value_t value; /**< value of the key */
1028 } ecma_container_pair_t;
1029 
1030 /**
1031  * Size of a single element (in ecma_value_t unit).
1032  */
1033 #define ECMA_CONTAINER_VALUE_SIZE 1
1034 
1035 /**
1036  * Size of a key - value pair (in ecma_value_t unit).
1037  */
1038 #define ECMA_CONTAINER_PAIR_SIZE 2
1039 
1040 /**
1041  * Size of the internal buffer.
1042  */
1043 #define ECMA_CONTAINER_GET_SIZE(container_p) \
1044   (container_p->buffer_p[0])
1045 
1046 /**
1047  * Remove the size field of the internal buffer.
1048  */
1049 #define ECMA_CONTAINER_SET_SIZE(container_p, size) \
1050   (container_p->buffer_p[0] = (ecma_value_t) (size))
1051 
1052 /**
1053  * Number of entries of the internal buffer.
1054  */
1055 #define ECMA_CONTAINER_ENTRY_COUNT(collection_p) \
1056   (collection_p->item_count - 1)
1057 
1058 /**
1059  * Pointer to the first entry of the internal buffer.
1060  */
1061 #define ECMA_CONTAINER_START(collection_p) \
1062   (collection_p->buffer_p + 1)
1063 
1064 #endif /* ENABLED (JERRY_ES2015_BUILTIN_CONTAINER) */
1065 
1066 typedef enum
1067 {
1068   ECMA_PROP_NO_OPTS = (0), /** empty property descriptor */
1069   ECMA_PROP_IS_GET_DEFINED = (1 << 0), /** Is [[Get]] defined? */
1070   ECMA_PROP_IS_SET_DEFINED = (1 << 1), /** Is [[Set]] defined? */
1071 
1072   ECMA_PROP_IS_CONFIGURABLE = (1 << 2), /** [[Configurable]] */
1073   ECMA_PROP_IS_ENUMERABLE = (1 << 3), /** [[Enumerable]] */
1074   ECMA_PROP_IS_WRITABLE = (1 << 4), /** [[Writable]] */
1075   ECMA_PROP_IS_THROW = (1 << 5), /** Flag that controls failure handling */
1076 
1077   ECMA_PROP_IS_VALUE_DEFINED = (1 << 6), /** Is [[Value]] defined? */
1078   ECMA_PROP_IS_CONFIGURABLE_DEFINED = (1 << 7), /** Is [[Configurable]] defined? */
1079   ECMA_PROP_IS_ENUMERABLE_DEFINED = (1 << 8), /** Is [[Enumerable]] defined? */
1080   ECMA_PROP_IS_WRITABLE_DEFINED = (1 << 9), /** Is [[Writable]] defined? */
1081 } ecma_property_descriptor_status_flags_t;
1082 
1083 /**
1084  * Description of ECMA property descriptor
1085  *
1086  * See also: ECMA-262 v5, 8.10.
1087  *
1088  * Note:
1089  *      If a component of descriptor is undefined then corresponding
1090  *      field should contain it's default value.
1091  *      The struct members must be in this order or keep in sync with ecma_property_flags_t and ECMA_IS_THROW flag.
1092  */
1093 typedef struct
1094 {
1095 
1096   /** any combination of ecma_property_descriptor_status_flags_t bits */
1097   uint16_t flags;
1098 
1099   /** [[Value]] */
1100   ecma_value_t value;
1101 
1102   /** [[Get]] */
1103   ecma_object_t *get_p;
1104 
1105   /** [[Set]] */
1106   ecma_object_t *set_p;
1107 } ecma_property_descriptor_t;
1108 
1109 /**
1110  * Bitfield which represents a namedata property options in an ecma_property_descriptor_t
1111  * Attributes:
1112  *  - is_get_defined, is_set_defined : false
1113  *  - is_configurable, is_writable, is_enumerable : undefined (false)
1114  *  - is_throw : undefined (false)
1115  *  - is_value_defined : true
1116  *  - is_configurable_defined, is_writable_defined, is_enumerable_defined : true
1117  */
1118 #define ECMA_NAME_DATA_PROPERTY_DESCRIPTOR_BITS 0x3c0
1119 
1120 /**
1121  * Bitmask to get a the physical property flags from an ecma_property_descriptor
1122  */
1123 #define ECMA_PROPERTY_FLAGS_MASK 0x1c
1124 
1125 /**
1126  * Flag that controls failure handling during defining property
1127  *
1128  * Note: This flags represents the [[DefineOwnProperty]] (P, Desc, Throw) 3rd argument
1129  */
1130 #define ECMA_IS_THROW (1 << 5)
1131 
1132 #if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
1133 /**
1134  * Description of an ecma-number
1135  */
1136 typedef float ecma_number_t;
1137 
1138 /**
1139  * It makes possible to read/write an ecma_number_t as uint32_t without strict aliasing rule violation.
1140  */
1141 typedef union
1142 {
1143   ecma_number_t as_ecma_number_t;
1144   uint32_t as_uint32_t;
1145 } ecma_number_accessor_t;
1146 
1147 #define DOUBLE_TO_ECMA_NUMBER_T(value) (ecma_number_t) (value)
1148 
1149 /**
1150  * Maximum number of significant digits that ecma-number can store
1151  */
1152 #define ECMA_NUMBER_MAX_DIGITS  (9)
1153 
1154 /**
1155  * Width of sign field
1156  *
1157  * See also:
1158  *          IEEE-754 2008, 3.6, Table 3.5
1159  */
1160 #define ECMA_NUMBER_SIGN_WIDTH       (1)
1161 
1162 /**
1163  * Width of biased exponent field
1164  *
1165  * See also:
1166  *          IEEE-754 2008, 3.6, Table 3.5
1167  */
1168 #define ECMA_NUMBER_BIASED_EXP_WIDTH (8)
1169 
1170 /**
1171  * Width of fraction field
1172  *
1173  * See also:
1174  *          IEEE-754 2008, 3.6, Table 3.5
1175  */
1176 #define ECMA_NUMBER_FRACTION_WIDTH   (23)
1177 #elif ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
1178 /**
1179  * Description of an ecma-number
1180  */
1181 typedef double ecma_number_t;
1182 
1183 /**
1184  * It makes possible to read/write an ecma_number_t as uint64_t without strict aliasing rule violation.
1185  */
1186 typedef union
1187 {
1188   ecma_number_t as_ecma_number_t;
1189   uint64_t as_uint64_t;
1190 } ecma_number_accessor_t;
1191 
1192 #define DOUBLE_TO_ECMA_NUMBER_T(value) value
1193 
1194 /**
1195  * Maximum number of significant digits that ecma-number can store
1196  */
1197 #define ECMA_NUMBER_MAX_DIGITS  (19)
1198 
1199 /**
1200  * Width of sign field
1201  *
1202  * See also:
1203  *          IEEE-754 2008, 3.6, Table 3.5
1204  */
1205 #define ECMA_NUMBER_SIGN_WIDTH       (1)
1206 
1207 /**
1208  * Width of biased exponent field
1209  *
1210  * See also:
1211  *          IEEE-754 2008, 3.6, Table 3.5
1212  */
1213 #define ECMA_NUMBER_BIASED_EXP_WIDTH (11)
1214 
1215 /**
1216  * Width of fraction field
1217  *
1218  * See also:
1219  *          IEEE-754 2008, 3.6, Table 3.5
1220  */
1221 #define ECMA_NUMBER_FRACTION_WIDTH   (52)
1222 #endif /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
1223 
1224 /**
1225  * Value '0' of ecma_number_t
1226  */
1227 #define ECMA_NUMBER_ZERO ((ecma_number_t) 0)
1228 
1229 /**
1230  * Value '1' of ecma_number_t
1231  */
1232 #define ECMA_NUMBER_ONE  ((ecma_number_t) 1)
1233 
1234 /**
1235  * Value '2' of ecma_number_t
1236  */
1237 #define ECMA_NUMBER_TWO  ((ecma_number_t) 2)
1238 
1239 /**
1240  * Value '0.5' of ecma_number_t
1241  */
1242 #define ECMA_NUMBER_HALF ((ecma_number_t) 0.5f)
1243 
1244 /**
1245  * Value '-1' of ecma_number_t
1246  */
1247 #define ECMA_NUMBER_MINUS_ONE ((ecma_number_t) -1)
1248 
1249 #if !ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
1250 /**
1251  * Number.MIN_VALUE (i.e., the smallest positive value of ecma-number)
1252  *
1253  * See also: ECMA_262 v5, 15.7.3.3
1254  */
1255 # define ECMA_NUMBER_MIN_VALUE (FLT_MIN)
1256 /**
1257  * Number.MAX_VALUE (i.e., the maximum value of ecma-number)
1258  *
1259  * See also: ECMA_262 v5, 15.7.3.2
1260  */
1261 # define ECMA_NUMBER_MAX_VALUE (FLT_MAX)
1262 /**
1263  * Number.EPSILON
1264  *
1265  * See also: ECMA_262 v6, 20.1.2.1
1266  */
1267 # define  ECMA_NUMBER_EPSILON ((ecma_number_t) 1.1920928955078125e-7)
1268 
1269 /**
1270  * Number.MAX_SAFE_INTEGER
1271  *
1272  * See also: ECMA_262 v6, 20.1.2.6
1273  */
1274 # define ECMA_NUMBER_MAX_SAFE_INTEGER ((ecma_number_t) 0xFFFFFF)
1275 
1276 /**
1277  * Number.MIN_SAFE_INTEGER
1278  *
1279  * See also: ECMA_262 v6, 20.1.2.8
1280  */
1281 # define ECMA_NUMBER_MIN_SAFE_INTEGER ((ecma_number_t) -0xFFFFFF)
1282 #elif ENABLED (JERRY_NUMBER_TYPE_FLOAT64)
1283 /**
1284  * Number.MAX_VALUE (i.e., the maximum value of ecma-number)
1285  *
1286  * See also: ECMA_262 v5, 15.7.3.2
1287  */
1288 # define ECMA_NUMBER_MAX_VALUE ((ecma_number_t) 1.7976931348623157e+308)
1289 
1290 /**
1291  * Number.MIN_VALUE (i.e., the smallest positive value of ecma-number)
1292  *
1293  * See also: ECMA_262 v5, 15.7.3.3
1294  */
1295 # define ECMA_NUMBER_MIN_VALUE ((ecma_number_t) 5e-324)
1296 
1297 /**
1298  * Number.EPSILON
1299  *
1300  * See also: ECMA_262 v6, 20.1.2.1
1301  */
1302 # define  ECMA_NUMBER_EPSILON ((ecma_number_t) 2.2204460492503130808472633361816e-16)
1303 
1304 /**
1305  * Number.MAX_SAFE_INTEGER
1306  *
1307  * See also: ECMA_262 v6, 20.1.2.6
1308  */
1309 # define ECMA_NUMBER_MAX_SAFE_INTEGER ((ecma_number_t) 0x1FFFFFFFFFFFFF)
1310 
1311 /**
1312  * Number.MIN_SAFE_INTEGER
1313  *
1314  * See also: ECMA_262 v6, 20.1.2.8
1315  */
1316 # define ECMA_NUMBER_MIN_SAFE_INTEGER ((ecma_number_t) -0x1FFFFFFFFFFFFF)
1317 #endif /* !ENABLED (JERRY_NUMBER_TYPE_FLOAT64) */
1318 
1319 /**
1320  * Euler number
1321  */
1322 #define ECMA_NUMBER_E  ((ecma_number_t) 2.7182818284590452354)
1323 
1324 /**
1325  * Natural logarithm of 10
1326  */
1327 #define ECMA_NUMBER_LN10 ((ecma_number_t) 2.302585092994046)
1328 
1329 /**
1330  * Natural logarithm of 2
1331  */
1332 #define ECMA_NUMBER_LN2 ((ecma_number_t) 0.6931471805599453)
1333 
1334 /**
1335  * Logarithm base 2 of the Euler number
1336  */
1337 #define ECMA_NUMBER_LOG2E ((ecma_number_t) 1.4426950408889634)
1338 
1339 /**
1340  * Logarithm base 10 of the Euler number
1341  */
1342 #define ECMA_NUMBER_LOG10E ((ecma_number_t) 0.4342944819032518)
1343 
1344 /**
1345  * Pi number
1346  */
1347 #define ECMA_NUMBER_PI  ((ecma_number_t) 3.1415926535897932)
1348 
1349 /**
1350  * Square root of 0.5
1351  */
1352 #define ECMA_NUMBER_SQRT_1_2  ((ecma_number_t) 0.7071067811865476)
1353 
1354 /**
1355  * Square root of 2
1356  */
1357 #define ECMA_NUMBER_SQRT2  ((ecma_number_t) 1.4142135623730951)
1358 
1359 /**
1360  * Maximum number of characters in string representation of ecma-number
1361  */
1362 #define ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER 64
1363 
1364 /**
1365  * Maximum number of characters in string representation of ecma-uint32
1366  */
1367 #define ECMA_MAX_CHARS_IN_STRINGIFIED_UINT32 10
1368 
1369 /**
1370  * String is not a valid array index.
1371  */
1372 #define ECMA_STRING_NOT_ARRAY_INDEX UINT32_MAX
1373 
1374 /**
1375  * Ecma-collection: a growable list of ecma-values.
1376  */
1377 typedef struct
1378 {
1379   uint32_t item_count; /**< number of items in the collection */
1380   uint32_t capacity; /**< number of items can be stored in the underlying buffer */
1381   ecma_value_t *buffer_p; /**< underlying data buffer */
1382 } ecma_collection_t;
1383 
1384 /**
1385  * Initial capacity of an ecma-collection
1386  */
1387 #define ECMA_COLLECTION_INITIAL_CAPACITY 4
1388 
1389 /**
1390  * Ecma-collenction grow factor when the collection underlying buffer need to be reallocated
1391  */
1392 #define ECMA_COLLECTION_GROW_FACTOR (ECMA_COLLECTION_INITIAL_CAPACITY * 2)
1393 
1394 /**
1395  * Compute the total allocated size of the collection based on it's capacity
1396  */
1397 #define ECMA_COLLECTION_ALLOCATED_SIZE(capacity) \
1398   (uint32_t) (sizeof (ecma_collection_t) + (capacity * sizeof (ecma_value_t)))
1399 
1400 /**
1401  * Initial allocated size of an ecma-collection
1402  */
1403 #define ECMA_COLLECTION_INITIAL_SIZE ECMA_COLLECTION_ALLOCATED_SIZE (ECMA_COLLECTION_INITIAL_CAPACITY)
1404 
1405 /**
1406  * Direct string types (2 bit).
1407  */
1408 typedef enum
1409 {
1410   ECMA_DIRECT_STRING_PTR = 0, /**< string is a string pointer, only used by property names */
1411   ECMA_DIRECT_STRING_MAGIC = 1, /**< string is a magic string */
1412   ECMA_DIRECT_STRING_UINT = 2, /**< string is an unsigned int */
1413   ECMA_DIRECT_STRING_ECMA_INTEGER = 3, /**< string is an ecma-integer */
1414 } ecma_direct_string_type_t;
1415 
1416 /**
1417  * Maximum value of the immediate part of a direct magic string.
1418  * Must be compatible with the immediate property name.
1419  */
1420 #if ENABLED (JERRY_CPOINTER_32_BIT)
1421 #define ECMA_DIRECT_STRING_MAX_IMM 0x07ffffff
1422 #else /* !ENABLED (JERRY_CPOINTER_32_BIT) */
1423 #define ECMA_DIRECT_STRING_MAX_IMM 0x0000ffff
1424 #endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
1425 
1426 /**
1427  * Shift for direct string value part in ecma_value_t.
1428  */
1429 #define ECMA_DIRECT_STRING_SHIFT (ECMA_VALUE_SHIFT + 2)
1430 
1431 /**
1432  * Full mask for direct strings.
1433  */
1434 #define ECMA_DIRECT_STRING_MASK ((uintptr_t) (ECMA_DIRECT_TYPE_MASK | (0x3u << ECMA_VALUE_SHIFT)))
1435 
1436 /**
1437  * Create an ecma direct string.
1438  */
1439 #define ECMA_CREATE_DIRECT_STRING(type, value) \
1440   ((uintptr_t) (ECMA_TYPE_DIRECT_STRING | ((type) << ECMA_VALUE_SHIFT) | (value) << ECMA_DIRECT_STRING_SHIFT))
1441 
1442 /**
1443  * Create an ecma direct string from the given number.
1444  *
1445  * Note: the given number must be less or equal than ECMA_DIRECT_STRING_MAX_IMM
1446  */
1447 #define ECMA_CREATE_DIRECT_UINT32_STRING(uint32_number) \
1448   ((ecma_string_t *) ECMA_CREATE_DIRECT_STRING (ECMA_DIRECT_STRING_UINT, (uintptr_t) uint32_number))
1449 
1450 /**
1451  * Checks whether the string is direct.
1452  */
1453 #define ECMA_IS_DIRECT_STRING(string_p) \
1454   ((((uintptr_t) (string_p)) & 0x1) != 0)
1455 
1456 /**
1457  * Checks whether the string is direct.
1458  */
1459 #define ECMA_IS_DIRECT_STRING_WITH_TYPE(string_p, type) \
1460   ((((uintptr_t) (string_p)) & ECMA_DIRECT_STRING_MASK) == ECMA_CREATE_DIRECT_STRING (type, 0))
1461 
1462 /**
1463  * Returns the type of a direct string.
1464  */
1465 #define ECMA_GET_DIRECT_STRING_TYPE(string_p) \
1466   ((((uintptr_t) (string_p)) >> ECMA_VALUE_SHIFT) & 0x3)
1467 
1468 /**
1469  * Shift applied to type conversions.
1470  */
1471 #define ECMA_STRING_TYPE_CONVERSION_SHIFT (ECMA_PROPERTY_NAME_TYPE_SHIFT - ECMA_VALUE_SHIFT)
1472 
1473 /**
1474  * Converts direct string type to property name type.
1475  */
1476 #define ECMA_DIRECT_STRING_TYPE_TO_PROP_NAME_TYPE(string_p) \
1477   ((((uintptr_t) (string_p)) & (0x3 << ECMA_VALUE_SHIFT)) << ECMA_STRING_TYPE_CONVERSION_SHIFT)
1478 
1479 /**
1480  * Returns the value of a direct string.
1481  */
1482 #define ECMA_GET_DIRECT_STRING_VALUE(string_p) \
1483   (((uintptr_t) (string_p)) >> ECMA_DIRECT_STRING_SHIFT)
1484 
1485 /**
1486  * Maximum number of bytes that a long-utf8-string is able to store
1487  */
1488 #define ECMA_STRING_SIZE_LIMIT UINT32_MAX
1489 
1490 typedef enum
1491 {
1492   ECMA_STRING_CONTAINER_HEAP_UTF8_STRING, /**< actual data is on the heap as an utf-8 (cesu8) string
1493                                            *   maximum size is 2^16. */
1494   ECMA_STRING_CONTAINER_HEAP_LONG_UTF8_STRING, /**< actual data is on the heap as an utf-8 (cesu8) string
1495                                                 *   maximum size is 2^32. */
1496   ECMA_STRING_CONTAINER_UINT32_IN_DESC, /**< actual data is UInt32-represeneted Number
1497                                              stored locally in the string's descriptor */
1498   ECMA_STRING_CONTAINER_HEAP_ASCII_STRING, /**< actual data is on the heap as an ASCII string
1499                                             *   maximum size is 2^16. */
1500   ECMA_STRING_CONTAINER_MAGIC_STRING_EX, /**< the ecma-string is equal to one of external magic strings */
1501 
1502   ECMA_STRING_CONTAINER_SYMBOL, /**< the ecma-string is a symbol */
1503 
1504   ECMA_STRING_CONTAINER__MAX = ECMA_STRING_CONTAINER_SYMBOL /**< maximum value */
1505 } ecma_string_container_t;
1506 
1507 /**
1508  * Mask for getting the container of a string.
1509  */
1510 #define ECMA_STRING_CONTAINER_MASK 0x7u
1511 
1512 /**
1513  * Value for increasing or decreasing the reference counter.
1514  */
1515 #define ECMA_STRING_REF_ONE (1u << 4)
1516 
1517 /**
1518  * Maximum value of the reference counter (4294967280).
1519  */
1520 #define ECMA_STRING_MAX_REF (0xFFFFFFF0)
1521 
1522 /**
1523  * Flag that identifies that the string is static which means it is stored in JERRY_CONTEXT (string_list_cp)
1524  */
1525 #define ECMA_STATIC_STRING_FLAG (1 << 3)
1526 
1527 /**
1528  * Set an ecma-string as static string
1529  */
1530 #define ECMA_SET_STRING_AS_STATIC(string_p) \
1531   (string_p)->refs_and_container |= ECMA_STATIC_STRING_FLAG
1532 
1533 /**
1534  * Checks whether the ecma-string is static string
1535  */
1536 #define ECMA_STRING_IS_STATIC(string_p) \
1537   ((string_p)->refs_and_container & ECMA_STATIC_STRING_FLAG)
1538 
1539 /**
1540  * Returns with the container type of a string.
1541  */
1542 #define ECMA_STRING_GET_CONTAINER(string_desc_p) \
1543   ((ecma_string_container_t) ((string_desc_p)->refs_and_container & ECMA_STRING_CONTAINER_MASK))
1544 
1545 /**
1546  * Checks whether the reference counter is 1.
1547  */
1548 #define ECMA_STRING_IS_REF_EQUALS_TO_ONE(string_desc_p) \
1549   (((string_desc_p)->refs_and_container >> 4) == 1)
1550 
1551 /**
1552  * ECMA string-value descriptor
1553  */
1554 typedef struct
1555 {
1556   /** Reference counter for the string */
1557   uint32_t refs_and_container;
1558 
1559   /**
1560    * Actual data or identifier of it's place in container (depending on 'container' field)
1561    */
1562   union
1563   {
1564     lit_string_hash_t hash; /**< hash of the ASCII/UTF8 string */
1565     uint32_t magic_string_ex_id; /**< identifier of an external magic string (lit_magic_string_ex_id_t) */
1566     uint32_t uint32_number; /**< uint32-represented number placed locally in the descriptor */
1567   } u;
1568 } ecma_string_t;
1569 
1570 /**
1571  * ECMA ASCII string-value descriptor
1572  */
1573 typedef struct
1574 {
1575   ecma_string_t header; /**< string header */
1576   uint16_t size; /**< size of this ASCII string in bytes */
1577 } ecma_ascii_string_t;
1578 
1579 /**
1580  * ECMA long UTF8 string-value descriptor
1581  */
1582 typedef struct
1583 {
1584   ecma_string_t header; /**< string header */
1585   uint16_t size; /**< size of this utf-8 string in bytes */
1586   uint16_t length; /**< length of this utf-8 string in bytes */
1587 } ecma_utf8_string_t;
1588 
1589 /**
1590  * ECMA UTF8 string-value descriptor
1591  */
1592 typedef struct
1593 {
1594   ecma_string_t header; /**< string header */
1595   lit_utf8_size_t size; /**< size of this long utf-8 string in bytes */
1596   lit_utf8_size_t length; /**< length of this long utf-8 string in bytes */
1597 } ecma_long_utf8_string_t;
1598 
1599 /**
1600  * Get the start position of the string buffer of an ecma ASCII string
1601  */
1602 #define ECMA_ASCII_STRING_GET_BUFFER(string_p) \
1603   ((lit_utf8_byte_t *) ((lit_utf8_byte_t *) (string_p) +  sizeof (ecma_ascii_string_t)))
1604 
1605 /**
1606  * Get the start position of the string buffer of an ecma UTF8 string
1607  */
1608 #define ECMA_UTF8_STRING_GET_BUFFER(string_p) \
1609   ((lit_utf8_byte_t *) ((lit_utf8_byte_t *) (string_p) +  sizeof (ecma_utf8_string_t)))
1610 
1611 /**
1612  * Get the start position of the string buffer of an ecma long UTF8 string
1613  */
1614 #define ECMA_LONG_UTF8_STRING_GET_BUFFER(string_p) \
1615   ((lit_utf8_byte_t *) ((lit_utf8_byte_t *) (string_p) +  sizeof (ecma_long_utf8_string_t)))
1616 
1617 /**
1618  * ECMA extended string-value descriptor
1619  */
1620 typedef struct
1621 {
1622   ecma_string_t header; /**< string header */
1623 
1624   union
1625   {
1626     ecma_value_t symbol_descriptor; /**< symbol descriptor string-value */
1627     ecma_value_t value; /**< original key value corresponds to the map key string */
1628   } u;
1629 } ecma_extended_string_t;
1630 
1631 /**
1632  * String builder header
1633  */
1634 typedef struct
1635 {
1636   lit_utf8_size_t current_size; /**< size of the data in the buffer */
1637 } ecma_stringbuilder_header_t;
1638 
1639 /**
1640  * Get pointer to the beginning of the stored string in the string builder
1641  */
1642 #define ECMA_STRINGBUILDER_STRING_PTR(header_p) \
1643   ((lit_utf8_byte_t *) (((lit_utf8_byte_t *) header_p) + sizeof (ecma_ascii_string_t)))
1644 
1645 /**
1646  * Get the size of the stored string in the string builder
1647  */
1648 #define ECMA_STRINGBUILDER_STRING_SIZE(header_p) \
1649   ((lit_utf8_size_t) (header_p->current_size - sizeof (ecma_ascii_string_t)))
1650 
1651 /**
1652  * String builder handle
1653  */
1654 typedef struct
1655 {
1656   ecma_stringbuilder_header_t *header_p; /**< pointer to header */
1657 } ecma_stringbuilder_t;
1658 
1659 /**
1660  * Abort flag for error reference.
1661  */
1662 #define ECMA_ERROR_REF_ABORT 0x1
1663 
1664 /**
1665  * Value for increasing or decreasing the reference counter.
1666  */
1667 #define ECMA_ERROR_REF_ONE (1u << 1)
1668 
1669 /**
1670  * Maximum value of the reference counter.
1671  */
1672 #define ECMA_ERROR_MAX_REF (UINT32_MAX - 1u)
1673 
1674 /**
1675  * Representation of a thrown value on API level.
1676  */
1677 typedef struct
1678 {
1679   uint32_t refs_and_flags; /**< reference counter */
1680   ecma_value_t value; /**< referenced value */
1681 } ecma_error_reference_t;
1682 
1683 #if ENABLED (JERRY_PROPRETY_HASHMAP)
1684 
1685 /**
1686  * The lowest state of the ecma_prop_hashmap_alloc_state counter.
1687  * If ecma_prop_hashmap_alloc_state other other than this value, it is
1688  * disabled.
1689  */
1690 #define ECMA_PROP_HASHMAP_ALLOC_ON 0
1691 
1692 /**
1693  * The highest state of the ecma_prop_hashmap_alloc_state counter.
1694  */
1695 #define ECMA_PROP_HASHMAP_ALLOC_MAX 4
1696 
1697 #endif /* ENABLED (JERRY_PROPRETY_HASHMAP) */
1698 
1699 /**
1700  * Number of values in a literal storage item
1701  */
1702 #define ECMA_LIT_STORAGE_VALUE_COUNT 3
1703 
1704 /**
1705  * Literal storage item
1706  */
1707 typedef struct
1708 {
1709   jmem_cpointer_t next_cp; /**< cpointer ot next item */
1710   jmem_cpointer_t values[ECMA_LIT_STORAGE_VALUE_COUNT]; /**< list of values */
1711 } ecma_lit_storage_item_t;
1712 
1713 /**
1714  * Number storage item
1715  */
1716 typedef struct
1717 {
1718   jmem_cpointer_t next_cp; /**< cpointer ot next item */
1719   jmem_cpointer_t values[ECMA_LIT_STORAGE_VALUE_COUNT]; /**< list of values */
1720 } ecma_number_storage_item_t;
1721 
1722 #if ENABLED (JERRY_LCACHE)
1723 /**
1724  * Container of an LCache entry identifier
1725  */
1726 #if ENABLED (JERRY_CPOINTER_32_BIT)
1727 typedef uint64_t ecma_lcache_hash_entry_id_t;
1728 #else /* !ENABLED (JERRY_CPOINTER_32_BIT) */
1729 typedef uint32_t ecma_lcache_hash_entry_id_t;
1730 #endif /* ENABLED (JERRY_CPOINTER_32_BIT) */
1731 
1732 /**
1733  * Entry of LCache hash table
1734  */
1735 typedef struct
1736 {
1737   /** Pointer to a property of the object */
1738   ecma_property_t *prop_p;
1739 
1740   /** Entry identifier in LCache */
1741   ecma_lcache_hash_entry_id_t id;
1742 } ecma_lcache_hash_entry_t;
1743 
1744 /**
1745  * Number of rows in LCache's hash table
1746  */
1747 #define ECMA_LCACHE_HASH_ROWS_COUNT 128
1748 
1749 /**
1750  * Number of entries in a row of LCache's hash table
1751  */
1752 #define ECMA_LCACHE_HASH_ROW_LENGTH 2
1753 
1754 #endif /* ENABLED (JERRY_LCACHE) */
1755 
1756 #if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
1757 
1758 /**
1759  * Function callback descriptor of a %TypedArray% object getter
1760  */
1761 typedef ecma_number_t (*ecma_typedarray_getter_fn_t) (lit_utf8_byte_t *src);
1762 
1763 /**
1764  * Function callback descriptor of a %TypedArray% object setter
1765  */
1766 typedef void (*ecma_typedarray_setter_fn_t) (lit_utf8_byte_t *src, ecma_number_t value);
1767 
1768 /**
1769  * Builtin id for the different types of TypedArray's
1770  */
1771 typedef enum
1772 {
1773   ECMA_INT8_ARRAY,          /**< Int8Array */
1774   ECMA_UINT8_ARRAY,         /**< Uint8Array */
1775   ECMA_UINT8_CLAMPED_ARRAY, /**< Uint8ClampedArray */
1776   ECMA_INT16_ARRAY,         /**< Int16Array */
1777   ECMA_UINT16_ARRAY,        /**< Uint16Array */
1778   ECMA_INT32_ARRAY,         /**< Int32Array */
1779   ECMA_UINT32_ARRAY,        /**< Uint32Array */
1780   ECMA_FLOAT32_ARRAY,       /**< Float32Array */
1781   ECMA_FLOAT64_ARRAY,       /**< Float64Array */
1782 } ecma_typedarray_type_t;
1783 
1784 /**
1785  * Extra information for ArrayBuffers.
1786  */
1787 typedef enum
1788 {
1789   ECMA_ARRAYBUFFER_INTERNAL_MEMORY = 0u,        /* ArrayBuffer memory is handled internally. */
1790   ECMA_ARRAYBUFFER_EXTERNAL_MEMORY = (1u << 0), /* ArrayBuffer created via jerry_create_arraybuffer_external. */
1791 } ecma_arraybuffer_extra_flag_t;
1792 
1793 #define ECMA_ARRAYBUFFER_HAS_EXTERNAL_MEMORY(object_p) \
1794     ((((ecma_extended_object_t *) object_p)->u.class_prop.extra_info & ECMA_ARRAYBUFFER_EXTERNAL_MEMORY) != 0)
1795 
1796 /**
1797  * Struct to store information for ArrayBuffers with external memory.
1798  *
1799  * The following elements are stored in Jerry memory.
1800  *
1801  *  buffer_p - pointer to the external memory.
1802  *  free_cb - pointer to a callback function which is called when the ArrayBuffer is freed.
1803  */
1804 typedef struct
1805 {
1806   ecma_extended_object_t extended_object; /**< extended object part */
1807   void *buffer_p; /**< external buffer pointer */
1808   ecma_object_native_free_callback_t free_cb; /**<  the free callback for the above buffer pointer */
1809 } ecma_arraybuffer_external_info;
1810 
1811 /**
1812  * Some internal properties of TypedArray object.
1813  * It is only used when the offset is not 0, and
1814  * the array-length is not buffer-length / element_size.
1815  */
1816 typedef struct
1817 {
1818   ecma_extended_object_t extended_object; /**< extended object part */
1819   ecma_length_t byte_offset; /**< the byteoffset of the above arraybuffer */
1820   ecma_length_t array_length; /**< the array length */
1821 } ecma_extended_typedarray_object_t;
1822 
1823 /**
1824  * General structure for query %TypedArray% object's properties.
1825  **/
1826 typedef struct
1827 {
1828   ecma_object_t *array_buffer_p; /**< pointer to the typedArray's [[ViewedArrayBuffer]] internal slot */
1829   lit_utf8_byte_t *buffer_p; /**< pointer to the underlying raw data buffer.
1830                               *   Note:
1831                               *    - This address is increased by the [ByteOffset]] internal property.
1832                               *    - This address must be used during indexed read/write operation. */
1833   ecma_typedarray_type_t id; /**< [[TypedArrayName]] internal slot */
1834   uint32_t length; /**< [[ByteLength]] internal slot */
1835   ecma_length_t offset; /**< [[ByteOffset]] internal slot. */
1836   uint8_t shift; /**< the element size shift in the typedArray */
1837   uint8_t element_size; /**< element size based on [[TypedArrayName]] in Table 49 */
1838 } ecma_typedarray_info_t;
1839 
1840 #endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
1841 
1842 #if ENABLED (JERRY_ES2015)
1843 
1844 /**
1845  * Executable (e.g. generator, async) object flags.
1846  */
1847 typedef enum
1848 {
1849   ECMA_EXECUTABLE_OBJECT_COMPLETED = (1u << 0), /**< executable object is completed and cannot be resumed */
1850   ECMA_EXECUTABLE_OBJECT_RUNNING = (1u << 1), /**< executable object is currently running */
1851   /* Generator specific flags. */
1852   ECMA_GENERATOR_ITERATE_AND_YIELD = (1u << 2), /**< the generator performs a yield* operation */
1853 } ecma_executable_object_flags_t;
1854 
1855 /**
1856  * Checks whether the executable object is waiting for resuming.
1857  */
1858 #define ECMA_EXECUTABLE_OBJECT_IS_SUSPENDED(extra_info) \
1859   (!((extra_info) & (ECMA_EXECUTABLE_OBJECT_COMPLETED | ECMA_EXECUTABLE_OBJECT_RUNNING)))
1860 
1861 #endif /* ENABLED (JERRY_ES2015) */
1862 
1863 #if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
1864 /**
1865  * Description of DataView objects.
1866  */
1867 typedef struct
1868 {
1869   ecma_extended_object_t header; /**< header part */
1870   ecma_object_t *buffer_p; /**< [[ViewedArrayBuffer]] internal slot */
1871   uint32_t byte_offset; /**< [[ByteOffset]] internal slot */
1872 } ecma_dataview_object_t;
1873 #endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW */
1874 
1875 /**
1876  * Flag for indicating whether the symbol is a well known symbol
1877  *
1878  * See also: 6.1.5.1
1879  */
1880 #define ECMA_GLOBAL_SYMBOL_FLAG 0x01
1881 
1882 /**
1883  * Bitshift index for indicating whether the symbol is a well known symbol
1884  *
1885  * See also: 6.1.5.1
1886  */
1887 #define ECMA_GLOBAL_SYMBOL_SHIFT 1
1888 
1889 /**
1890  * Bitshift index for the symbol hash property
1891  */
1892 #define ECMA_SYMBOL_HASH_SHIFT 2
1893 
1894 #if (JERRY_STACK_LIMIT != 0)
1895 /**
1896  * Set the jerry context stack limit for IAR.
1897  */
1898 #define JERRY_IAR_MEM_STACK_LIMIT (4480) // > 4136b, 3500; < 4.5 * 1024 = 4608
1899 
1900 /**
1901  * Check the current jerry context stack usage.
1902  */
1903 #define CHECK_JERRY_STACK_USAGE(context_p) \
1904 do \
1905 { \
1906   if (ecma_get_current_stack_usage () > JERRY_IAR_MEM_STACK_LIMIT) \
1907   { \
1908     parser_raise_error (context_p, PARSER_ERR_JERRY_STACK_LIMIT_REACHED); \
1909   } \
1910 } while (0)
1911 
1912 /**
1913  * Check the current stack usage. If the limit is reached a RangeError is raised.
1914  */
1915 #define ECMA_CHECK_STACK_USAGE() \
1916 do \
1917 { \
1918   if (ecma_get_current_stack_usage () > CONFIG_MEM_STACK_LIMIT) \
1919   { \
1920     return ecma_raise_range_error (ECMA_ERR_MSG ("Maximum call stack size exceeded.")); \
1921   } \
1922 } while (0)
1923 #else /* JERRY_STACK_LIMIT == 0) */
1924 /**
1925  * If the stack limit is unlimited, this check is an empty macro.
1926  */
1927 #define ECMA_CHECK_STACK_USAGE()
1928 #define CHECK_JERRY_STACK_USAGE(context_p)
1929 #endif /* (JERRY_STACK_LIMIT != 0) */
1930 
1931 /**
1932  * Invalid object pointer which represents abrupt completion
1933  */
1934 #define ECMA_OBJECT_POINTER_ERROR ((ecma_object_t *) 0x01)
1935 
1936 #if ENABLED (JERRY_ES2015_BUILTIN_PROXY)
1937 /**
1938  * Description of Proxy objects.
1939  */
1940 typedef struct
1941 {
1942   ecma_object_t header; /**< header part */
1943   ecma_value_t target; /**< [[ProxyTarget]] internal slot */
1944   ecma_value_t handler; /**< [[ProxyHandler]] internal slot */
1945 } ecma_proxy_object_t;
1946 
1947 /**
1948  * Description of Proxy objects.
1949  */
1950 typedef struct
1951 {
1952   ecma_extended_object_t header; /**< header part */
1953   ecma_value_t proxy; /**< [[RevocableProxy]] internal slot */
1954 } ecma_revocable_proxy_object_t;
1955 #endif /* ENABLED (JERRY_ES2015_BUILTIN_PROXY) */
1956 
1957 /**
1958  * @}
1959  * @}
1960  */
1961 
1962 #endif  /* !ECMA_GLOBALS_H */
1963