• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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  * @addtogroup JSVM
17  * @{
18  *
19  * @brief Provides the standard JavaScript engine capabilities.
20  *
21  * Provides API to Provide independent, standard, and complete JavaScript engine capabilities for developers,
22  * including managing the engine lifecycle, compiling and running JS code, implementing JS/C++ cross language calls,
23  * and taking snapshots.
24  *
25  * @since 11
26  */
27 
28 /**
29  * @file jsvm_types.h
30  *
31  * @brief Provides the JSVM API type define.
32  *
33  * Provides API to Provide independent, standard, and complete JavaScript engine capabilities for developers,
34  * including managing the engine lifecycle, compiling and running JS code, implementing JS/C++ cross language calls,
35  * and taking snapshots.
36  * @library libjsvm.so
37  * @kit ArkTS
38  * @syscap SystemCapability.ArkCompiler.JSVM
39  * @since 11
40  */
41 
42 #ifndef ARK_RUNTIME_JSVM_JSVM_TYPE_H
43 #define ARK_RUNTIME_JSVM_JSVM_TYPE_H
44 
45 
46 #include <stddef.h>  // NOLINT(modernize-deprecated-headers)
47 #include <stdint.h>  // NOLINT(modernize-deprecated-headers)
48 #include <stdbool.h>  // NOLINT(modernize-deprecated-headers)
49 
50 #if !defined __cplusplus || (defined(_MSC_VER) && _MSC_VER < 1900)
51 typedef uint16_t char16_t;
52 #endif
53 
54 #ifndef JSVM_CDECL
55 #ifdef _WIN32
56 #define JSVM_CDECL __cdecl
57 #else
58 #define JSVM_CDECL
59 #endif
60 #endif
61 
62 /**
63  * @brief To represent a JavaScript VM instance.
64  *
65  * @since 11
66  */
67 typedef struct JSVM_VM__* JSVM_VM;
68 
69 /**
70  * @brief To represent a JavaScript VM scope.
71  *
72  * @since 11
73  */
74 typedef struct JSVM_VMScope__* JSVM_VMScope;
75 
76 /**
77  * @brief To represent a JavaScript VM environment scope.
78  *
79  * @since 11
80  */
81 typedef struct JSVM_EnvScope__* JSVM_EnvScope;
82 
83 /**
84  * @brief To represent a JavaScript code.
85  *
86  * @since 11
87  */
88 typedef struct JSVM_Script__* JSVM_Script;
89 
90 /**
91  * @brief To represent a JavaScript VM instance.
92  *
93  * @since 11
94  */
95 typedef struct JSVM_Env__* JSVM_Env;
96 
97 /**
98  * @brief To represent a JavaScript profiler.
99  *
100  * @since 12
101  */
102 typedef struct JSVM_CpuProfiler__* JSVM_CpuProfiler;
103 
104 /**
105  * @brief To represent a JavaScript VM environment.
106  *
107  * @since 11
108  */
109 typedef struct JSVM_Value__* JSVM_Value;
110 
111 /**
112  * @brief To represent a JavaScript value references.
113  *
114  * @since 11
115  */
116 typedef struct JSVM_Ref__* JSVM_Ref;
117 
118 /**
119  * @brief To represent a JavaScript VM handle scope.
120  *
121  * @since 11
122  */
123 typedef struct JSVM_HandleScope__* JSVM_HandleScope;
124 
125 /**
126  * @brief To represent a JavaScript VM escapable handle scope.
127  *
128  * @since 11
129  */
130 typedef struct JSVM_EscapableHandleScope__* JSVM_EscapableHandleScope;
131 
132 /**
133  * @brief To represent a JavaScript VM callback additional information.
134  *
135  * @since 11
136  */
137 typedef struct JSVM_CallbackInfo__* JSVM_CallbackInfo;
138 
139 /**
140  * @brief To represent a JavaScript VM value deferred.
141  *
142  * @since 11
143  */
144 typedef struct JSVM_Deferred__* JSVM_Deferred;
145 
146 
147 /**
148  * @brief Callback function pointer and data for user-provided native function which are to exposed to js via JSVM-API.
149  *
150  * @since 11
151  */
152 typedef struct {
153     JSVM_Value(JSVM_CDECL* callback)(JSVM_Env env,
154                                    JSVM_CallbackInfo info);
155     void* data;
156 } JSVM_CallbackStruct;
157 
158 /**
159  * @brief Function pointer type for user-provided native function which are to exposed to js via JSVM-API.
160  *
161  * @since 11
162  */
163 typedef JSVM_CallbackStruct* JSVM_Callback;
164 
165 /**
166  * @brief Function pointer type for add-on provided function that allow the user to be notified.
167  *
168  * @since 11
169  */
170 typedef void(JSVM_CDECL* JSVM_Finalize)(JSVM_Env env,
171                                         void* finalizeData,
172                                         void* finalizeHint);
173 
174 /**
175  * @brief Function pointer type for callback of ASCII output stream. The first parameter data is the data pointer.
176  * And the second parameter size is the data size to output. A null data pointer indicates the end of the stream.
177  * The third parameter streamData is the pointer passed in together with the callback to the API functions that
178  * generate data to the output stream. The callback returns true to indicate the stream can continue to accept
179  * data. Otherwise, it will abort the stream.
180  *
181  * @since 12
182  */
183 typedef bool(JSVM_CDECL* JSVM_OutputStream)(const char* data,
184                                             int size,
185                                             void* streamData);
186 
187 /**
188  * @brief JSVM_PropertyAttributes are flag used to control the behavior of properties set on a js object.
189  *
190  * @since 11
191  */
192 typedef enum {
193     /** No explicit attributes are set on the property. */
194     JSVM_DEFAULT = 0,
195     /** The property is writable. */
196     JSVM_WRITABLE = 1 << 0,
197     /** The property is enumeable. */
198     JSVM_ENUMERABLE = 1 << 1,
199     /** The property is configurable. */
200     JSVM_CONFIGURABLE = 1 << 2,
201     /** Used to mark the receiver of a native method need not be checked.
202      *  If JSVM_NO_RECEIVER_CHECK is not set, the method only accept instance of the defined class as receiver,
203      *  Otherwise Exception "Type Error: Illegal Ivocation" will be throw into JSVM.
204     */
205     JSVM_NO_RECEIVER_CHECK = 1 << 3,
206     /** Used with OH_JSVM_DefineClass to distinguish static properties from instance properties. */
207     JSVM_STATIC = 1 << 10,
208     /** Default for class methods. */
209     JSVM_DEFAULT_METHOD = JSVM_WRITABLE | JSVM_CONFIGURABLE,
210     /** Class method with no receiver check*/
211     JSVM_METHOD_NO_RECEIVER_CHECK = JSVM_DEFAULT_METHOD | JSVM_NO_RECEIVER_CHECK,
212     /** Default for object properties, like in JS obj[prop]. */
213     JSVM_DEFAULT_JSPROPERTY = JSVM_WRITABLE | JSVM_ENUMERABLE | JSVM_CONFIGURABLE,
214     /** Object properties with no receiver check*/
215     JSVM_JSPROPERTY_NO_RECEIVER_CHECK = JSVM_DEFAULT_JSPROPERTY | JSVM_NO_RECEIVER_CHECK,
216 } JSVM_PropertyAttributes;
217 
218 /**
219  * @brief Describes the type of a JSVM_Value.
220  *
221  * @since 11
222  */
223 typedef enum {
224     /** undefined type. */
225     JSVM_UNDEFINED,
226     /** null type. */
227     JSVM_NULL,
228     /** boolean type. */
229     JSVM_BOOLEAN,
230     /** number type. */
231     JSVM_NUMBER,
232     /** string type. */
233     JSVM_STRING,
234     /** symbol type. */
235     JSVM_SYMBOL,
236     /** object type. */
237     JSVM_OBJECT,
238     /** function type. */
239     JSVM_FUNCTION,
240     /** external type. */
241     JSVM_EXTERNAL,
242     /** bigint type. */
243     JSVM_BIGINT,
244 } JSVM_ValueType;
245 
246 /**
247  * @brief Describes the type of a typedarray.
248  *
249  * @since 11
250  */
251 typedef enum {
252     /** int8 type. */
253     JSVM_INT8_ARRAY,
254     /** uint8 type. */
255     JSVM_UINT8_ARRAY,
256     /** uint8 clamped type. */
257     JSVM_UINT8_CLAMPED_ARRAY,
258     /** int16 type. */
259     JSVM_INT16_ARRAY,
260     /** uint16 type. */
261     JSVM_UINT16_ARRAY,
262     /** int32 type. */
263     JSVM_INT32_ARRAY,
264     /** uint32 type. */
265     JSVM_UINT32_ARRAY,
266     /** float32 type. */
267     JSVM_FLOAT32_ARRAY,
268     /** float64 type. */
269     JSVM_FLOAT64_ARRAY,
270     /** bigint64 type. */
271     JSVM_BIGINT64_ARRAY,
272     /** biguint64 type. */
273     JSVM_BIGUINT64_ARRAY,
274 } JSVM_TypedarrayType;
275 
276 /**
277  * @brief Integral status code indicating the success or failure of a JSVM-API call.
278  *
279  * @since 11
280  */
281 typedef enum {
282     /** success status. */
283     JSVM_OK,
284     /** invalidarg status. */
285     JSVM_INVALID_ARG,
286     /** object expected status. */
287     JSVM_OBJECT_EXPECTED,
288     /** string expected status. */
289     JSVM_STRING_EXPECTED,
290     /** name expected status. */
291     JSVM_NAME_EXPECTED,
292     /** function expected status. */
293     JSVM_FUNCTION_EXPECTED,
294     /** number expected status. */
295     JSVM_NUMBER_EXPECTED,
296     /** boolean expected status. */
297     JSVM_BOOLEAN_EXPECTED,
298     /** array expected status. */
299     JSVM_ARRAY_EXPECTED,
300     /** generic failure status. */
301     JSVM_GENERIC_FAILURE,
302     /** pending exception status. */
303     JSVM_PENDING_EXCEPTION,
304     /** cancelled status. */
305     JSVM_CANCELLED,
306     /** escape called twice status. */
307     JSVM_ESCAPE_CALLED_TWICE,
308     /** handle scope mismatch status. */
309     JSVM_HANDLE_SCOPE_MISMATCH,
310     /** callback scope mismatch status. */
311     JSVM_CALLBACK_SCOPE_MISMATCH,
312     /** queue full status. */
313     JSVM_QUEUE_FULL,
314     /** closing status. */
315     JSVM_CLOSING,
316     /** bigint expected status. */
317     JSVM_BIGINT_EXPECTED,
318     /** date expected status. */
319     JSVM_DATE_EXPECTED,
320     /** arraybuffer expected status. */
321     JSVM_ARRAYBUFFER_EXPECTED,
322     /** detachable arraybuffer expected status. */
323     JSVM_DETACHABLE_ARRAYBUFFER_EXPECTED,
324     /** would deadlock status. */
325     JSVM_WOULD_DEADLOCK,
326     /** no external buffers allowed status. */
327     JSVM_NO_EXTERNAL_BUFFERS_ALLOWED,
328     /** cannot run +js status. */
329     JSVM_CANNOT_RUN_JS,
330     /** invalid input type status.
331      * @since 18
332      */
333     JSVM_INVALID_TYPE,
334     /** jit mode expected status.
335      * @since 18
336      */
337     JSVM_JIT_MODE_EXPECTED,
338 } JSVM_Status;
339 
340 /**
341  * @brief  limits the range of collected properties..
342  *
343  * @since 11
344  */
345 typedef enum {
346     /** will include all keys of the objects's prototype chain as well. */
347     JSVM_KEY_INCLUDE_PROTOTYPES,
348     /** limits the collected properties to the given object only. */
349     JSVM_KEY_OWN_ONLY
350 } JSVM_KeyCollectionMode;
351 
352 /**
353  * @brief Property filter bits. They can be or'ed to build a composite filter..
354  *
355  * @since 11
356  */
357 typedef enum {
358     /** key all properties. */
359     JSVM_KEY_ALL_PROPERTIES = 0,
360     /** key writable. */
361     JSVM_KEY_WRITABLE = 1,
362     /** key enumerable. */
363     JSVM_KEY_ENUMERABLE = 1 << 1,
364     /** key configurable. */
365     JSVM_KEY_CONFIGURABLE = 1 << 2,
366     /** key skip strings. */
367     JSVM_KEY_SKIP_STRINGS = 1 << 3,
368     /** key skip symbols. */
369     JSVM_KEY_SKIP_SYMBOLS = 1 << 4
370 } JSVM_KeyFilter;
371 
372 /**
373  * @brief key conversion select.
374  *
375  * @since 11
376  */
377 typedef enum {
378     /** will return numbers for integer indices. */
379     JSVM_KEY_KEEP_NUMBERS,
380     /**  will convert integer indices to strings. */
381     JSVM_KEY_NUMBERS_TO_STRINGS
382 } JSVM_KeyConversion;
383 
384 /**
385  * @brief Memory pressure level.
386  *
387  * @since 11
388  */
389 typedef enum {
390     /** none pressure. */
391     JSVM_MEMORY_PRESSURE_LEVEL_NONE,
392     /** moderate pressure. */
393     JSVM_MEMORY_PRESSURE_LEVEL_MODERATE,
394     /** critical pressure. */
395     JSVM_MEMORY_PRESSURE_LEVEL_CRITICAL,
396 } JSVM_MemoryPressureLevel;
397 
398 /**
399  *
400  * @brief Compile mode
401  *
402  * @since 12
403  */
404 typedef enum {
405     /** default mode. */
406     JSVM_COMPILE_MODE_DEFAULT,
407     /** consume code cache. */
408     JSVM_COMPILE_MODE_CONSUME_CODE_CACHE,
409     /** apply eager compile. */
410     JSVM_COMPILE_MODE_EAGER_COMPILE,
411     /** preset for compile profile. */
412     JSVM_COMPILE_MODE_PRODUCE_COMPILE_PROFILE,
413     /** consume compile profile. */
414     JSVM_COMPILE_MODE_CONSUME_COMPILE_PROFILE,
415 } JSVM_CompileMode;
416 
417 /**
418  * @brief Compile option id
419  *
420  * @since 12
421  */
422 typedef enum {
423     /** compile mode. */
424     JSVM_COMPILE_MODE,
425     /** code cache content. */
426     JSVM_COMPILE_CODE_CACHE,
427     /** script origin. */
428     JSVM_COMPILE_SCRIPT_ORIGIN,
429     /** compile profile content. */
430     JSVM_COMPILE_COMPILE_PROFILE,
431     /** switch for source map support. */
432     JSVM_COMPILE_ENABLE_SOURCE_MAP,
433 } JSVM_CompileOptionId;
434 
435 /**
436  * @brief Heap statisics.
437  *
438  * @since 12
439  */
440 typedef struct {
441     /** the size of the total heap. */
442     size_t totalHeapSize;
443     /** the executable size of the total heap. */
444     size_t totalHeapSizeExecutable;
445     /** the physical size of the total heap. */
446     size_t totalPhysicalSize;
447     /** the available size of the total heap. */
448     size_t totalAvailableSize;
449     /** used size of the heap. */
450     size_t usedHeapSize;
451     /** heap size limit. */
452     size_t heapSizeLimit;
453     /** memory requested by the heap. */
454     size_t mallocedMemory;
455     /** heap-requested external memory. */
456     size_t externalMemory;
457     /** peak memory requested by the heap. */
458     size_t peakMallocedMemory;
459     /** the number of native contexts. */
460     size_t numberOfNativeContexts;
461     /** the number of detached contexts. */
462     size_t numberOfDetachedContexts;
463     /** the size of the total global handles. */
464     size_t totalGlobalHandlesSize;
465     /** the size of the used global handles. */
466     size_t usedGlobalHandlesSize;
467 } JSVM_HeapStatistics;
468 
469 /**
470  * @brief Init the JavaScript VM with init option.
471  *
472  * @since 11
473  */
474 typedef struct {
475     /**
476      * Optional nullptr-terminated array of raw adddresses in the embedder that the
477      * VM can match against during serialization and use for deserialization. This
478      * array and its content must stay valid for the entire lifetime of the VM
479      * instance.
480     */
481     const intptr_t* externalReferences;
482 
483     /**
484      * Flags for the VM. IF removeFlags is true, recognized flags will be removed
485      * from (argc, argv). Note that these flags are specific to VM.
486      * They are mainly used for development. Do not include them in production as
487      * they might not take effect if the VM is different from the development
488      * environment.
489      */
490     int* argc;
491     /** argv . */
492     char** argv;
493     /** remove flags. */
494     bool removeFlags;
495 } JSVM_InitOptions;
496 
497 /**
498  * @brief Create the JavaScript VM with init option.
499  *
500  * @since 11
501  */
502 typedef struct {
503     /** optional limits of memory use of the vm. */
504     size_t maxOldGenerationSize;
505     /** optional limits of memory use of the vm. */
506     size_t maxYoungGenerationSize;
507     /** optional limits of memory use of the vm. */
508     size_t initialOldGenerationSize;
509     /** optional limits of memory use of the vm. */
510     size_t initialYoungGenerationSize;
511     /** Optional startup snapshot data. */
512     const char* snapshotBlobData;
513     /** Optional size of the startup snapshot data. */
514     size_t snapshotBlobSize;
515     /** Whether the VM is used for creating snapshot. */
516     bool isForSnapshotting;
517 } JSVM_CreateVMOptions;
518 
519 /**
520  * @brief JavaScript VM info.
521  *
522  * @since 11
523  */
524 typedef struct {
525     /** The highest API version this VM supports. */
526     uint32_t apiVersion;
527     /** The engine name implementing the VM. */
528     const char* engine;
529     /** The version of the VM. */
530     const char* version;
531     /** The cached data version tag. */
532     uint32_t cachedDataVersionTag;
533 } JSVM_VMInfo;
534 
535 /**
536  * @brief Property descriptor.
537  *
538  * @since 11
539  */
540 typedef struct {
541     /** Optional string describing the key for the property, encoded as UTF8.
542      * One of utf8name or name must be provided for the property.
543      */
544     const char* utf8name;
545     /** Optional value that points to a JavaScript string or symbol to be used as the key for the property. */
546     JSVM_Value name;
547     /** Set this to make the property descriptor object's value property to be
548      * a JavaScript function represented by method.
549      */
550     JSVM_Callback method;
551     /** A function to call when a get access of the property is performed. */
552     JSVM_Callback getter;
553     /** A function to call when a set access of the property is performed. */
554     JSVM_Callback setter;
555     /** The value that's retrieved by a get access of the property if the property is a data property. */
556     JSVM_Value value;
557     /** The attributes associated with the particular property. */
558     JSVM_PropertyAttributes attributes;
559 } JSVM_PropertyDescriptor;
560 
561 /**
562  * @brief JSVM-API uses both return values and JavaScript exceptions for error handling
563  * @since 11
564  */
565 typedef struct {
566     /** UTF8-encoded string containing a VM-neutral description of the error. */
567     const char* errorMessage;
568     /** Reserved for VM-specific error details. This is currently not implemented for any VM. */
569     void* engineReserved;
570     /** VM-specific error code. This is currently not implemented for any VM. */
571     uint32_t engineErrorCode;
572     /** The JSVM-API status code that originated with the last error. */
573     JSVM_Status errorCode;
574 } JSVM_ExtendedErrorInfo;
575 
576 /**
577  * @brief A 128-bit value stored as two unsigned 64-bit integers.
578  * It serves as a UUID with which JavaScript objects or externals can be "tagged"
579  * in order to ensure that they are of a certain type.
580  *
581  * @since 11
582  */
583 typedef struct {
584     /** lower type. */
585     uint64_t lower;
586     /** upper type. */
587     uint64_t upper;
588 } JSVM_TypeTag;
589 
590 /**
591  * @brief When the object's getter, setter, deleter, and enumerator operations are performed, the corresponding
592  * callback will be triggered.
593  *
594  * @since 12
595  */
596 typedef struct {
597     /** A callback function triggered by getting a named property of an instance object. */
598     JSVM_Value(JSVM_CDECL* genericNamedPropertyGetterCallback)(JSVM_Env env,
599                                                                JSVM_Value name,
600                                                                JSVM_Value thisArg,
601                                                                JSVM_Value namedPropertyData);
602 
603     /** A callback function triggered by setting a named property of an instance object. */
604     JSVM_Value(JSVM_CDECL* genericNamedPropertySetterCallback)(JSVM_Env env,
605                                                                JSVM_Value name,
606                                                                JSVM_Value property,
607                                                                JSVM_Value thisArg,
608                                                                JSVM_Value namedPropertyData);
609 
610     /** A callback function triggered by deleting a named property of an instance object. */
611     JSVM_Value(JSVM_CDECL* genericNamedPropertyDeleterCallback)(JSVM_Env env,
612                                                                 JSVM_Value name,
613                                                                 JSVM_Value thisArg,
614                                                                 JSVM_Value namedPropertyData);
615 
616     /** A callback function triggered by getting all named properties requests on an object. */
617     JSVM_Value(JSVM_CDECL* genericNamedPropertyEnumeratorCallback)(JSVM_Env env,
618                                                                    JSVM_Value thisArg,
619                                                                    JSVM_Value namedPropertyData);
620 
621     /** A callback function triggered by getting an indexed property of an instance object. */
622     JSVM_Value(JSVM_CDECL* genericIndexedPropertyGetterCallback)(JSVM_Env env,
623                                                                  JSVM_Value index,
624                                                                  JSVM_Value thisArg,
625                                                                  JSVM_Value indexedPropertyData);
626 
627     /** A callback function triggered by setting an indexed property of an instance object. */
628     JSVM_Value(JSVM_CDECL* genericIndexedPropertySetterCallback)(JSVM_Env env,
629                                                                  JSVM_Value index,
630                                                                  JSVM_Value property,
631                                                                  JSVM_Value thisArg,
632                                                                  JSVM_Value indexedPropertyData);
633 
634     /** A callback function triggered by deleting an indexed property of an instance object. */
635     JSVM_Value(JSVM_CDECL* genericIndexedPropertyDeleterCallback)(JSVM_Env env,
636                                                                   JSVM_Value index,
637                                                                   JSVM_Value thisArg,
638                                                                   JSVM_Value indexedPropertyData);
639 
640     /** A callback function triggered by getting all indexed properties requests on an object. */
641     JSVM_Value(JSVM_CDECL* genericIndexedPropertyEnumeratorCallback)(JSVM_Env env,
642                                                                      JSVM_Value thisArg,
643                                                                      JSVM_Value indexedPropertyData);
644 
645     /** data will be utilized by the named property callbacks in this struct. */
646     JSVM_Value namedPropertyData;
647 
648     /** data will be utilized by the indexed property callbacks in this struct. */
649     JSVM_Value indexedPropertyData;
650 } JSVM_PropertyHandlerConfigurationStruct;
651 
652 /**
653  * @brief The pointer type of the structure which contains the property handlers.
654  *
655  * @since 12
656  */
657 typedef JSVM_PropertyHandlerConfigurationStruct* JSVM_PropertyHandlerCfg;
658 
659 /**
660  * @brief Source code information.
661  *
662  * @since 12
663  */
664 typedef struct {
665     /** Sourcemap url. */
666     const char* sourceMapUrl;
667     /** Resource name. */
668     const char* resourceName;
669     /** Resource line offset. */
670     size_t resourceLineOffset;
671     /** Resource column offset. */
672     size_t resourceColumnOffset;
673 } JSVM_ScriptOrigin;
674 
675 /**
676  * @brief Compile Options
677  *
678  * @since 12
679  */
680 typedef struct {
681     /** compile option id. */
682     JSVM_CompileOptionId id;
683     /** option content. */
684     union {
685         /** ptr type. */
686         void *ptr;
687         /** int type. */
688         int num;
689         /** bool type. */
690         bool boolean;
691     } content;
692 } JSVM_CompileOptions;
693 
694 /**
695  * @brief code cache passed with JSVM_COMPILE_CODE_CACHE
696  *
697  * @since 12
698  */
699 typedef struct {
700     /** cache pointer. */
701     uint8_t *cache;
702     /** length. */
703     size_t length;
704 } JSVM_CodeCache;
705 
706 /**
707  * @brief compile profile passed with JSVM_COMPILE_COMPILE_PROFILE
708  *
709  * @since 12
710  */
711 typedef const struct {
712     /** profile pointer. */
713     int *profile;
714     /** length. */
715     size_t length;
716 } JSVM_CompileProfile;
717 
718 /**
719  * @brief Regular expression flag bits. They can be or'ed to enable a set of flags.
720  *
721  * @since 12
722  */
723 typedef enum {
724     /** None mode. */
725     JSVM_REGEXP_NONE = 0,
726     /** Global mode. */
727     JSVM_REGEXP_GLOBAL = 1 << 0,
728     /** Ignore Case mode. */
729     JSVM_REGEXP_IGNORE_CASE = 1 << 1,
730     /** Multiline mode. */
731     JSVM_REGEXP_MULTILINE = 1 << 2,
732     /** Sticky mode. */
733     JSVM_REGEXP_STICKY = 1 << 3,
734     /** Unicode mode. */
735     JSVM_REGEXP_UNICODE = 1 << 4,
736     /** dotAll mode. */
737     JSVM_REGEXP_DOT_ALL = 1 << 5,
738     /** Linear mode. */
739     JSVM_REGEXP_LINEAR = 1 << 6,
740     /** Has Indices mode. */
741     JSVM_REGEXP_HAS_INDICES = 1 << 7,
742     /** Unicode Sets mode. */
743     JSVM_REGEXP_UNICODE_SETS = 1 << 8,
744 } JSVM_RegExpFlags;
745 
746 /**
747  * @brief initialization flag
748  *
749  * @since 12
750  */
751 typedef enum {
752     /** initialize with zero. */
753     JSVM_ZERO_INITIALIZED,
754     /** leave uninitialized. */
755     JSVM_UNINITIALIZED,
756 } JSVM_InitializedFlag;
757 
758 /**
759  * @brief WebAssembly function optimization level
760  *
761  * @since 12
762  */
763 typedef enum {
764     /** baseline optimization level. */
765     JSVM_WASM_OPT_BASELINE = 10,
766     /** high optimization level. */
767     JSVM_WASM_OPT_HIGH = 20,
768 } JSVM_WasmOptLevel;
769 
770 /**
771  * @brief Cache data type
772  *
773  * @since 12
774  */
775 typedef enum {
776     /** js code cache, generated by OH_JSVM_CreateCodeCache */
777     JSVM_CACHE_TYPE_JS,
778     /** WebAssembly cache, generated by OH_JSVM_CreateWasmCache */
779     JSVM_CACHE_TYPE_WASM,
780 } JSVM_CacheType;
781 
782 /**
783  * @brief Microtask policies of JSVM.
784  *
785  * @since 18
786  */
787 typedef enum {
788     /** Microtasks are invoked with the OH_JSVM_PerformMicrotaskCheckpoint() method. */
789     JSVM_MICROTASK_EXPLICIT = 0,
790     /** Microtasks are invoked when the script call depth decrements to zero.
791      *  Default mode.
792      */
793     JSVM_MICROTASK_AUTO,
794 } JSVM_MicrotaskPolicy;
795 
796 /**
797  * @brief Trace category for jsvm internal trace events.
798  *
799  * @since 18
800  */
801 typedef enum {
802     /** Tracing main interface invoking of JSVM, such as run scripts. */
803     JSVM_TRACE_VM,
804     /** Tracing interface invoking about compilation, such as CompileCodeBackground. */
805     JSVM_TRACE_COMPILE,
806     /** Tracing interface invoking about execution status, such as Interrupts and Microtasks. */
807     JSVM_TRACE_EXECUTE,
808     /** Tracing external callback */
809     JSVM_TRACE_RUNTIME,
810     /** Tracing stack trace in JSVM. */
811     JSVM_TRACE_STACK_TRACE,
812     /** Tracing Main interface invoking of WASM, such as Compile Wasm Module and Instantiate. */
813     JSVM_TRACE_WASM,
814     /** Tracing more detailed interface invoking of WASM, such as background compilation and wrappers. */
815     JSVM_TRACE_WASM_DETAILED
816 } JSVM_TraceCategory;
817 
818 /**
819  * @brief The promise-reject event.
820  *
821  * @since 18
822  */
823 typedef enum {
824     /** Promise is rejected for other reasons. */
825     JSVM_PROMISE_REJECT_OTHER_REASONS = 0,
826     /** Promise rejected with no handler. */
827     JSVM_PROMISE_REJECT_WITH_NO_HANDLER = 1,
828     /** Add the handler after Promise has been rejected. */
829     JSVM_PROMISE_ADD_HANDLER_AFTER_REJECTED = 2,
830     /** After the Promise has been resolved, try to reject the Promise again. */
831     JSVM_PROMISE_REJECT_AFTER_RESOLVED = 3,
832     /** After the Promise has been resolved, try resolving the Promise again. */
833     JSVM_PROMISE_RESOLVE_AFTER_RESOLVED = 4,
834 } JSVM_PromiseRejectEvent;
835 
836 /**
837  * @brief The level of message error.
838  *
839  * @since 18
840  */
841 typedef enum {
842     /** Log level message. */
843     JSVM_MESSAGE_LOG = (1 << 0),
844     /** Debug level message. */
845     JSVM_MESSAGE_DEBUG = (1 << 1),
846     /** Info level message. */
847     JSVM_MESSAGE_INFO = (1 << 2),
848     /** Error level message. */
849     JSVM_MESSAGE_ERROR = (1 << 3),
850     /** Warning level message. */
851     JSVM_MESSAGE_WARNING = (1 << 4),
852     /** All level message. */
853     JSVM_MESSAGE_ALL = JSVM_MESSAGE_LOG | JSVM_MESSAGE_DEBUG | JSVM_MESSAGE_INFO | JSVM_MESSAGE_ERROR |
854                        JSVM_MESSAGE_WARNING,
855 } JSVM_MessageErrorLevel;
856 
857 /**
858  * @brief Function pointer type of OOM-Error callback.
859  *
860  * @param location The location information of the OOM error.
861  * @param detail The detail of the OOM error.
862  * @param isHeapOOM Determine whether the OOM type is Heap OOM.
863  *
864  * @since 18
865  */
866 typedef void(JSVM_CDECL* JSVM_HandlerForOOMError)(const char* location,
867                                                   const char* detail,
868                                                   bool isHeapOOM);
869 
870 /**
871  * @brief Function pointer type of Fatal-Error callback.
872  *
873  * @param location The location information of the Fatal error.
874  * @param message The message of the Fatal error.
875  *
876  * @since 18
877  */
878 typedef void(JSVM_CDECL* JSVM_HandlerForFatalError)(const char* location,
879                                                     const char* message);
880 
881 /**
882  * @brief Function pointer type of Promise-Reject callback.
883  *
884  * @param env The environment that the function is invoked under.
885  * @param rejectEvent The promise-reject event.
886  * @param rejectInfo An JS-object containing two properties: 'promise' and 'value'.
887  * The 'promise' represents a reference to the Promise object that was rejected.
888  * The 'value' represents the rejection reason associated with that promise.
889  *
890  * @since 18
891  */
892 typedef void(JSVM_CDECL* JSVM_HandlerForPromiseReject)(JSVM_Env env,
893                                                        JSVM_PromiseRejectEvent rejectEvent,
894                                                        JSVM_Value rejectInfo);
895 
896 /**
897  * @brief DefineClass options id.
898  *
899  * @since 18
900  */
901 typedef enum {
902     /** Defining a class in normal mode. */
903     JSVM_DEFINE_CLASS_NORMAL,
904     /** Defining a class with count. */
905     JSVM_DEFINE_CLASS_WITH_COUNT,
906     /** Defining a class with property handler. */
907     JSVM_DEFINE_CLASS_WITH_PROPERTY_HANDLER,
908 } JSVM_DefineClassOptionsId;
909 
910 /**
911  * @brief DefineClass options.
912  *
913  * @since 18
914  */
915 typedef struct {
916     /** DefineClass option id. */
917     JSVM_DefineClassOptionsId id;
918     /** option content. */
919     union {
920         /** for option value with pointer type. */
921         void* ptr;
922         /** for option value with integer type  */
923         int num;
924         /** for option value with bool type */
925         bool boolean;
926     } content;
927 } JSVM_DefineClassOptions;
928 
929 /**
930  * @brief The property-handler used to define class.
931  *
932  * @since 18
933  */
934 typedef struct {
935     /** The instance object triggers the corresponding callback function. */
936     JSVM_PropertyHandlerCfg propertyHandlerCfg;
937     /** Calling an instance object as a function will trigger this callback. */
938     JSVM_Callback callAsFunctionCallback;
939 } JSVM_PropertyHandler;
940 
941 /**
942  * @brief The timing of GC callback trigger.
943  *
944  * @since 18
945  */
946 typedef enum {
947     /** Trigger GC callback before GC. */
948     JSVM_CB_TRIGGER_BEFORE_GC,
949     /** Trigger GC callback after GC. */
950     JSVM_CB_TRIGGER_AFTER_GC,
951 } JSVM_CBTriggerTimeForGC;
952 
953 /**
954  * @brief The GC type.
955  *
956  * @since 18
957  */
958 typedef enum {
959     /** The GC algorithm is Scavenge. */
960     JSVM_GC_TYPE_SCAVENGE = 1 << 0,
961     /** The GC algorithm is Minor-Mark-Compact. */
962     JSVM_GC_TYPE_MINOR_MARK_COMPACT = 1 << 1,
963     /** The GC algorithm is Mark-Sweep-Compact. */
964     JSVM_GC_TYPE_MARK_SWEEP_COMPACT = 1 << 2,
965     /** The GC algorithm is Incremental-Marking. */
966     JSVM_GC_TYPE_INCREMENTAL_MARKING = 1 << 3,
967     /** The GC algorithm is Weak-Callbacks. */
968     JSVM_GC_TYPE_PROCESS_WEAK_CALLBACKS = 1 << 4,
969     /** All GC algorithm. */
970     JSVM_GC_TYPE_ALL = JSVM_GC_TYPE_SCAVENGE | JSVM_GC_TYPE_MINOR_MARK_COMPACT |
971                        JSVM_GC_TYPE_MARK_SWEEP_COMPACT | JSVM_GC_TYPE_INCREMENTAL_MARKING |
972                        JSVM_GC_TYPE_PROCESS_WEAK_CALLBACKS,
973 } JSVM_GCType;
974 
975 /**
976  * @brief The GC callback flags.
977  *
978  * @since 18
979  */
980 typedef enum {
981     /** No GC callback falgs. */
982     JSVM_NO_GC_CALLBACK_FLAGS,
983     /** Reserved object information will be built in the garbage collection callback. */
984     JSVM_GC_CALLBACK_CONSTRUCT_RETAINED_OBJECT_INFOS,
985     /** Enforce Garbage Collection Callback. */
986     JSVM_GC_CALLBACK_FORCED,
987     /** Synchronous phantom callback processing. */
988     JSVM_GC_CALLBACK_SYNCHRONOUS_PHANTOM_CALLBACK_PROCESSING,
989     /** All available garbage objects are collected during garbage collection. */
990     JSVM_GC_CALLBACK_COLLECT_ALL_AVAILABLE_GARBAGE,
991     /** Garbage collection collects all external memory. */
992     JSVM_GC_CALLBACK_COLLECT_ALL_EXTERNAL_MEMORY,
993     /** Schedule Garbage Collection at Idle Time. */
994     JSVM_GC_CALLBACK_SCHEDULE_IDLE_GARBAGE_COLLECTION,
995 } JSVM_GCCallbackFlags;
996 
997 /**
998  * @brief Function pointer type of GC callback.
999  *
1000  * @param vm The VM instance that the JSVM-API call is invoked under.
1001  * @param gcType The gc type.
1002  * @param flags The GC callback flags.
1003  * @param data The native pointer data.
1004  *
1005  * @since 18
1006  */
1007 typedef void(JSVM_CDECL* JSVM_HandlerForGC)(JSVM_VM vm,
1008                                             JSVM_GCType gcType,
1009                                             JSVM_GCCallbackFlags flags,
1010                                             void* data);
1011 
1012 /**
1013  * @brief To represent a JavaScript Data type.
1014  *
1015  * @since 18
1016  */
1017 typedef struct JSVM_Data__* JSVM_Data;
1018 
1019 /**
1020  * @brief Debug options.
1021  *
1022  * @since 20
1023  */
1024 typedef enum {
1025     /** Scope check. */
1026     JSVM_SCOPE_CHECK,
1027 } JSVM_DebugOption;
1028 /** @} */
1029 #endif /* ARK_RUNTIME_JSVM_JSVM_TYPE_H */
1030 
1031