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 LIT_MAGIC_STRINGS_H
17#define LIT_MAGIC_STRINGS_H
18
19#include "lit-globals.h"
20
21/**
22 * Identifiers of ECMA and implementation-defined magic string constants
23 */
24typedef enum
25{
26/** @cond doxygen_suppress */
27#define LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE(size, id)
28#define LIT_MAGIC_STRING_DEF(id, ascii_zt_string) \
29 id,
30#include "lit-magic-strings.inc.h"
31#undef LIT_MAGIC_STRING_DEF
32#undef LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE
33/** @endcond */
34 LIT_NON_INTERNAL_MAGIC_STRING__COUNT, /**< number of non-internal magic strings */
35 LIT_INTERNAL_MAGIC_API_INTERNAL = LIT_NON_INTERNAL_MAGIC_STRING__COUNT, /**< Used to add non-visible JS properties
36 * from the public API */
37 LIT_INTERNAL_MAGIC_STRING_ITERATOR_NEXT_INDEX, /**< [[%Iterator%NextIndex]] property */
38 LIT_INTERNAL_MAGIC_STRING_MAP_KEY, /**< Property key used when an object is a key in a map object */
39 LIT_INTERNAL_MAGIC_STRING_ARRAY_PROTOTYPE_VALUES, /**< %ArrayProto_values% intrinsic routine */
40 LIT_INTERNAL_MAGIC_STRING_TYPEDARRAY_PROTOTYPE_VALUES, /**< %TypedArray%.prototype values and [@@iterator] routine */
41 LIT_INTERNAL_MAGIC_STRING_SET_PROTOTYPE_VALUES, /**< Set.prototype values, keys and [@@iterator] routines */
42 LIT_INTERNAL_MAGIC_STRING_MAP_PROTOTYPE_ENTRIES, /**< Map.prototype entries and [@@iterator] routines */
43 LIT_INTERNAL_MAGIC_PROMISE_CAPABILITY, /**< PromiseCapability record */
44 /* List of well known symbols */
45 LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR, /**< @@asyncIterator well known symbol */
46 LIT_GLOBAL_SYMBOL__FIRST = LIT_GLOBAL_SYMBOL_ASYNC_ITERATOR, /**< first global symbol */
47 LIT_GLOBAL_SYMBOL_HAS_INSTANCE, /**< @@hasInstance well known symbol */
48 LIT_GLOBAL_SYMBOL_IS_CONCAT_SPREADABLE, /**< @@isConcatSpreadable well known symbol */
49 LIT_GLOBAL_SYMBOL_ITERATOR, /**< @@iterator well known symbol */
50 LIT_GLOBAL_SYMBOL_MATCH, /**< @@match well known symbol */
51 LIT_GLOBAL_SYMBOL_REPLACE, /**< @@replace well known symbol */
52 LIT_GLOBAL_SYMBOL_SEARCH, /**< @@search well known symbol */
53 LIT_GLOBAL_SYMBOL_SPECIES, /**< @@species well known symbol */
54 LIT_GLOBAL_SYMBOL_SPLIT, /**< @@split well known symbol */
55 LIT_GLOBAL_SYMBOL_TO_PRIMITIVE, /**< @@toPrimitive well known symbol */
56 LIT_GLOBAL_SYMBOL_TO_STRING_TAG, /**< @@toStringTag well known symbol */
57 LIT_GLOBAL_SYMBOL_UNSCOPABLES, /**< @@unscopables well known symbol */
58 LIT_GLOBAL_SYMBOL_MATCH_ALL, /**< @@matchAll well known symbol */
59 LIT_GLOBAL_SYMBOL__LAST = LIT_GLOBAL_SYMBOL_MATCH_ALL, /**< last global symbol */
60
61 LIT_INTERNAL_MAGIC_STRING_DELETED, /**< special value for deleted properties */
62 LIT_INTERNAL_MAGIC_STRING_INTERNAL_OBJECT, /**< Internal object ID for internal properties */
63 LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_INIT, /**< function which initializes properties */
64
65 LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER, /**< native pointer info associated with an object */
66 LIT_INTERNAL_MAGIC_STRING_FIRST_DATA = LIT_INTERNAL_MAGIC_STRING_NATIVE_POINTER, /**< first index of special
67 * data properties */
68 LIT_INTERNAL_MAGIC_STRING_ENVIRONMENT_RECORD, /**< dynamic environment record needed by class constructors */
69 LIT_INTERNAL_MAGIC_STRING_CLASS_FIELD_COMPUTED, /**< computed class field name list */
70 LIT_INTERNAL_MAGIC_STRING_WEAK_REFS, /**< Weak references to the current object */
71 LIT_MAGIC_STRING__COUNT /**< number of magic strings */
72} lit_magic_string_id_t;
73
74/**
75 * Checks whether the given id corresponds to a global symbol
76 */
77#define LIT_IS_GLOBAL_SYMBOL(id) ((id) >= LIT_GLOBAL_SYMBOL__FIRST && (id) <= LIT_GLOBAL_SYMBOL__LAST)
78
79/**
80 * Identifiers of implementation-defined external magic string constants
81 */
82typedef uint32_t lit_magic_string_ex_id_t;
83
84uint32_t lit_get_magic_string_ex_count (void);
85
86const lit_utf8_byte_t *lit_get_magic_string_utf8 (uint32_t id);
87lit_utf8_size_t lit_get_magic_string_size (uint32_t id);
88
89const lit_utf8_byte_t *lit_get_magic_string_ex_utf8 (uint32_t id);
90lit_utf8_size_t lit_get_magic_string_ex_size (uint32_t id);
91
92void lit_magic_strings_ex_set (const lit_utf8_byte_t * const *ex_str_items,
93 uint32_t count,
94 const lit_utf8_size_t *ex_str_sizes);
95
96lit_magic_string_id_t lit_is_utf8_string_magic (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size);
97lit_magic_string_id_t lit_is_utf8_string_pair_magic (const lit_utf8_byte_t *string1_p, lit_utf8_size_t string1_size,
98 const lit_utf8_byte_t *string2_p, lit_utf8_size_t string2_size);
99
100lit_magic_string_ex_id_t lit_is_ex_utf8_string_magic (const lit_utf8_byte_t *string_p, lit_utf8_size_t string_size);
101lit_magic_string_ex_id_t lit_is_ex_utf8_string_pair_magic (const lit_utf8_byte_t *string1_p,
102 lit_utf8_size_t string1_size,
103 const lit_utf8_byte_t *string2_p,
104 lit_utf8_size_t string2_size);
105
106lit_utf8_byte_t *lit_copy_magic_string_to_buffer (lit_magic_string_id_t id, lit_utf8_byte_t *buffer_p,
107 lit_utf8_size_t buffer_size);
108
109#endif /* !LIT_MAGIC_STRINGS_H */
110