• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 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 #ifndef OHOS_ACELITE_JSI_H
17 #define OHOS_ACELITE_JSI_H
18 
19 #include <cstdlib>
20 
21 #include "jsi_types.h"
22 #include "memory_heap.h"
23 
24 /**
25  * Enable JS TypedArray type support.
26  */
27 #ifndef JS_FWK_TYPEDARRAY
28 #define JS_FWK_TYPEDARRAY 1
29 #endif
30 
31 /**
32  * Disable JS Symbol value support.
33  */
34 #ifndef JS_FWK_SYMBOL
35 #define JS_FWK_SYMBOL 0
36 #endif
37 
38 namespace OHOS {
39 namespace ACELite {
40 /**
41  * @brief End flag used in ReleaseValueList(JSIValue value, ...).
42  */
43 static const JSIValue ARGS_END = (JSIValue)(uintptr_t)-1;
44 
45 /**
46  * @brief Function pointer type used to create function callback.
47  *
48  * @param [in] thisVal: the this value provided for the function call
49  * @param [in] args: the function arguments, array of JavaScript values
50  * @param [in] argsNum: the number of arguments
51  */
52 typedef JSIValue (*JSIFunctionHandler)(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum);
53 
54 /**
55  * @brief Description of JerryScript heap memory status.
56  */
57 struct JSHeapStatus : public MemoryHeap {
58     size_t totalBytes;     // heap total size
59     size_t allocBytes;     // currently allocated bytes
60     size_t peakAllocBytes; // peak allocated bytes
61 
62     JSHeapStatus(const JSHeapStatus &) = delete;
63     JSHeapStatus &operator=(const JSHeapStatus &) = delete;
64     JSHeapStatus(JSHeapStatus &&) = delete;
65     JSHeapStatus &operator=(JSHeapStatus &&) = delete;
JSHeapStatusJSHeapStatus66     JSHeapStatus() : totalBytes(0), allocBytes(0), peakAllocBytes(0) {}
67 };
68 
69 /**
70  * @brief Struct definition for JS property descriptor
71  */
72 struct JSPropertyDescriptor : public MemoryHeap {
73     JSIFunctionHandler setter; // access function for setting value
74     JSIFunctionHandler getter; // access function for getting value
75 
JSPropertyDescriptorJSPropertyDescriptor76     JSPropertyDescriptor() : setter(nullptr), getter(nullptr) {}
77 };
78 
79 /**
80  * @brief JavaScriptInterface for adapatation to javascript engines.
81  */
82 class JSI final : public MemoryHeap {
83 public:
84     /**
85      * @brief Get the global javascript object.
86      *
87      * @return the global object acquired
88      * value returned should be released by caller with ReleaseValue when it won't be used any more
89      */
90     static JSIValue GetGlobalObject();
91 
92     /**
93      * @brief Create a javascript object.
94      *
95      * @return the object created
96      * value returned should be released by caller with ReleaseValue when it won't be used any more
97      */
98     static JSIValue CreateObject();
99 
100     /**
101      * @brief Set property to given javascript object.
102      *
103      * @param [in] object: host object to set
104      * @param [in] key: key of the property to set
105      * @param [in] value: value of the property to set
106      */
107     static void SetProperty(JSIValue object, JSIValue key, JSIValue value);
108 
109     /**
110      * @brief Set property to javascript object with given name.
111      *
112      * @param [in] object: host object to set
113      * @param [in] propName: name of the property to set
114      * @param [in] value: value of the property to set
115      */
116     static void SetNamedProperty(JSIValue object, const char * const propName, JSIValue value);
117 
118     /**
119      * @brief Set number property to javascript object with given name.
120      *
121      * @param [in] object: host object to set
122      * @param [in] propName: name of the number property to set
123      * @param [in] value: number value of the property to set
124      */
125     static void SetNumberProperty(JSIValue object, const char * const propName, double value);
126 
127     /**
128      * @brief Set boolean property to javascript object with given name.
129      *
130      * @param [in] object: host object to set
131      * @param [in] propName: name of the boolean property to set
132      * @param [in] value: boolean value of the property to set
133      */
134     static void SetBooleanProperty(JSIValue object, const char * const propName, bool value);
135 
136     /**
137      * @brief Set string property to javascript object with given name.
138      *
139      * @param [in] object: host object to set
140      * @param [in] propName: name of the string property to set
141      * @param [in] value: string value of the property to set
142      */
143     static void SetStringProperty(JSIValue object, const char * const propName, const char *value);
144 
145     /**
146      * @brief Set string property to javascript object with given name.
147      *
148      * @param [in] object: host object to set
149      * @param [in] propName: name of the string property to set
150      * @param [in] value: string value of the property to set
151      * @param [in] size: string size of the property to set
152      */
153     static void
154         SetStringPropertyWithBufferSize(JSIValue object, const char *const propName, const char *value, size_t size);
155 
156     /**
157      * @brief Create javascript function with given native function.
158      *
159      * @param [in] handler: native function pointer
160      * @return javascript function object
161      * value returned should be released by caller with ReleaseValue when it won't be used any more
162      */
163     static JSIValue CreateFunction(JSIFunctionHandler handler);
164 
165     /**
166      * @brief Create javascript string object with character string.
167      *
168      * @param [in] str: string source
169      * @return the string object created
170      * value returned should be released by caller with ReleaseValue when it won't be used any more
171      */
172     static JSIValue CreateString(const char * const str);
173 
174     /**
175      * @brief Create javascript string object with character string.
176      *
177      * @param [in] str: string source
178      * @param [in] size: string length
179      * @return the string object created
180      * value returned should be released by caller with ReleaseValue when it won't be used any more
181      */
182     static JSIValue CreateStringWithBufferSize(const char * const str, size_t size);
183 
184     /**
185      * @brief Create an undefined object.
186      *
187      * @return the undefined object created
188      * value returned should be released by caller with ReleaseValue when it won't be used any more
189      */
190     static JSIValue CreateUndefined();
191 
192     /**
193      * @brief Check if the specified value is a function object value, the value must be created by jerry interface.
194      *
195      * @param [in] value: value to check
196      * @return true: if the given value is a function
197      *         false: otherwise
198      */
199     static bool ValueIsFunction(JSIValue value);
200 
201     /**
202      * @brief Check if the specified value is undefined.
203      *
204      * @param [in] value: value to check
205      * @return true: if the given value is undefined
206      *         false: otherwise
207      */
208     static bool ValueIsUndefined(JSIValue value);
209 
210     /**
211      * @brief Check if the specified value is a number.
212      *
213      * @param [in] value: value to check
214      * @return true: if the given value is a number
215      *         false: otherwise
216      */
217     static bool ValueIsNumber(JSIValue value);
218 
219     /**
220      * @brief Check if the specified value is a string value.
221      *
222      * @param [in] value: value to check
223      * @return true: if the given value is a string value
224      *         false: otherwise
225      */
226     static bool ValueIsString(JSIValue value);
227 
228     /**
229      * @brief Check if the specified value is a boolean value.
230      *
231      * @param [in] value: value to check
232      * @return true: if the given value is a boolean value
233      *         false: otherwise
234      */
235     static bool ValueIsBoolean(JSIValue value);
236 
237     /**
238      * @brief Check if the specified value is a null value.
239      *
240      * @param [in] value: value to check
241      * @return true: if the given value is a null value
242      *         false: otherwise
243      */
244     static bool ValueIsNull(JSIValue value);
245 
246     /**
247      * @brief Check if the specified value is an object value.
248      *
249      * @param [in] value: value to check
250      * @return true: if the given value is an object value
251      *         false: otherwise
252      */
253     static bool ValueIsObject(JSIValue value);
254 
255     /**
256      * @brief Check if the specified value is error value.
257      *
258      * @param [in] value: value to check
259      * @return true: if the given value is error value
260      *         false: otherwise
261      */
262     static bool ValueIsError(JSIValue value);
263 
264     /**
265      * @brief Get the same value as json.stringify().
266      *
267      * @param [in] value: value which can be json stringfied
268      * @return the json string created
269      * value returned should be released with ReleaseString(char *&str) when it won't be used any more
270      */
271     static char *JsonStringify(JSIValue value);
272 
273     /**
274      * @brief Get the same value as json.parse().
275      *
276      * @param [in] str: character string which is in json pattern
277      * @return JSI value created
278      * value returned should be released by caller with ReleaseValue when it won't be used any more
279      */
280     static JSIValue JsonParse(const char * const str);
281 
282     /**
283      * @brief Get value of a property from the specified object with the given key.
284      *
285      * @param [in] object: object value
286      * @param [in] key: property name
287      * @return acquired value of the property
288      * value returned should be released by caller with ReleaseValue when it won't be used any more
289      */
290     static JSIValue GetProperty(JSIValue object, JSIValue key);
291 
292     /**
293      * @brief Get value of a property from the specified object with the given character name.
294      *
295      * @param [in] object: object value
296      * @param [in] propName: property name in character string
297      * @return acquired value of the property
298      * value returned should be released by caller with ReleaseValue when it won't be used any more
299      */
300     static JSIValue GetNamedProperty(JSIValue object, const char * const propName);
301 
302     /**
303      * @brief Get number value from the specified object with the given property name.
304      *
305      * @param [in] object: object value
306      * @param [in] propName: the number property name
307      * @return number value acquired
308      * 0.0 will be returned if the argument passed is not a number object
309      */
310     static double GetNumberProperty(JSIValue object, const char * const propName);
311 
312     /**
313      * @brief Get boolean value from the specified object with the given property name.
314      *
315      * @param [in] object: object value
316      * @param [in] propName: the boolean property name
317      * @return true: if the property value is logical true
318      *         false: otherwise
319      */
320     static bool GetBooleanProperty(JSIValue object, const char * const propName);
321 
322     /**
323      * @brief Get string value from the specified object with the given property name.
324      *
325      * @param [in] object: object value
326      * @param [in] propName: the string property name
327      * @return the string value acquired
328      * value returned should be released with ReleaseString(char *&str) when it won't be used any more
329      */
330     static char *GetStringProperty(JSIValue object, const char * const propName);
331 
332     /**
333      * @brief Get string value from the specified object with the given property name.
334      *
335      * @param [in] object: object value
336      * @param [in] propName: the string property name
337      * @param [out] size: the string property size
338      * @return the string value acquired
339      * value returned should be released with ReleaseString(char *&str) when it won't be used any more
340      */
341     static char *GetStringPropertyWithBufferSize(JSIValue object, const char * const propName, size_t &size);
342 
343     /**
344      * @brief: Release specified API value.
345      *
346      * @param: value JSI value to release
347      */
348     static void ReleaseValue(JSIValue value);
349 
ReleaseValueList()350     static void ReleaseValueList() {}
351 
352     /**
353      * @brief: Release API value list.
354      *
355      * @param: JSI value list to release
356      */
ReleaseValueList(T head,Args...rest)357     template<class T, class... Args> static void ReleaseValueList(T head, Args... rest)
358     {
359         ReleaseValue(head);
360         ReleaseValueList(rest...);
361     }
362 
363     /**
364      * @brief: Release string value.
365      *
366      * @param: str: pointer to the buffer to be released
367      */
368     static void ReleaseString(char *&str);
369 
370     /**
371      * @brief Call javascript function specified by a function value.
372      *
373      * @param [in] funcObj: the function object to call
374      * @param [in] thisVal: object for 'this' binding
375      * @param [in] argv:  function's call arguments
376      * @param [in] argc: number of arguments
377      */
378     static void CallFunction(JSIValue funcObj, JSIValue thisVal, const JSIValue *argv, uint8_t argc);
379 
380     /**
381      * @brief Create javascript number value.
382      *
383      * @param [in] value: source number
384      * @return the number value created
385      * value returned should be released by caller with ReleaseValue when it won't be used any more
386      */
387     static JSIValue CreateNumber(double value);
388 
389     /**
390      * @brief Create a JSIValue representing a not-a-number value.
391      *
392      * @return a JSIValue representing the not-a-number value
393      * value returned should be released by caller with ReleaseValue when it won't be used any more
394      */
395     static JSIValue CreateNumberNaN();
396 
397     /**
398      * @brief Create javascript error object.
399      *
400      * @param [in] type: error type
401      * @param [in] errorMsg: value of 'message' property of constructed error object
402      * @return value of the constructed error object
403      * value returned should be released by caller with ReleaseValue when it won't be used any more
404      */
405     static JSIValue CreateError(JsiErrorType type, const char * const errorMsg);
406 
407     /**
408      * @brief Get the type of the error object.
409      *
410      * @param [in] errorValue: error value to get
411      * @return the type of the error object
412      */
413     static JsiErrorType GetErrorType(JSIValue errorValue);
414 
415     /**
416      * @brief Create javascript boolean value.
417      *
418      * @param [in] value: bool value
419      * @return the boolean value created
420      * value returned should be released by caller with ReleaseValue when it won't be used any more
421      */
422     static JSIValue CreateBoolean(bool value);
423 
424     /**
425      * @brief Create javascript null object.
426      *
427      * @return the null object created
428      * value returned should be released by caller with ReleaseValue when it won't be used any more
429      */
430     static JSIValue CreateNull();
431 
432 #if (JS_FWK_SYMBOL == 1)
433     /**
434      * @brief Create a javascript symbol.
435      *
436      * @param [in] description: source value
437      * @return the symbol object created
438      * value returned should be released by caller with ReleaseValue when it won't be used any more
439      */
440     static JSIValue CreateSymbol(JSIValue description);
441 
442     /**
443      * @brief Check if the specified value is a symbol value.
444      *
445      * @param [in] value: value to check
446      * @return true: if the given value is a symbol value
447      *         false: otherwise
448      */
449     static bool ValueIsSymbol(JSIValue value);
450 #endif // JS_FWK_SYMBOL
451 
452     /**
453      * @brief Create a javascript array.
454      *
455      * @param [in] length: array length
456      * @return the array object created
457      * value returned should be released by caller with ReleaseValue when it won't be used any more
458      */
459     static JSIValue CreateArray(uint32_t length);
460 
461     /**
462      * @brief Set indexed value in the specified javascript object.
463      *
464      * @param [in] object: object to set
465      * @param [in] index: index number
466      * @param [in] value: value to set
467      * @return true: if the operation succeed
468      *         false: otherwise
469      */
470     static bool SetPropertyByIndex(JSIValue object, uint32_t index, JSIValue value);
471 
472     /**
473      * @brief Get the string value of the given JSIValue object.
474      *
475      * @param [in] value: source value
476      * @return the string value created
477      * value returned should be released with ReleaseString(char *&str) when it won't be used any more
478      */
479     static char *ValueToString(JSIValue value);
480 
481     /**
482      * @brief Get the string value of the given JSIValue object.
483      *
484      * @param [in] value: source value
485      * @param [out] size: source size
486      * @return the string value created
487      * value returned should be released with ReleaseString(char *&str) when it won't be used any more
488      */
489     static char *ValueToStringWithBufferSize(JSIValue value, size_t &size);
490 
491     /**
492      * @brief Get the number value of the given JSIValue object.
493      *
494      * @param [in] value: source value
495      * @return double value acquired
496      * 0.0 will be returned if the argument passed is not a number object
497      */
498     static double ValueToNumber(JSIValue value);
499 
500     /**
501      * @brief Get the boolean value of the given JSIValue object.
502      *
503      * @param [in] value: source value
504      * @return true: if the given value is logical true
505      *         false: otherwise
506      */
507     static bool ValueToBoolean(JSIValue value);
508 
509     /**
510      * @brief Get the string value of the given any JSIValue.
511      *
512      * @param [in] jsi value: source value
513      * @return the string value created
514      * value returned should be released with ReleaseString(char *&str) when it won't be used any more
515      */
516     static char *JSIValueToString(JSIValue value);
517 
518     /**
519      * @brief Check if the specified value is an array object.
520      *
521      * @param [in] value: array value
522      * @return array length acquired
523      * 0 will be returned if the argument passed is not an array object
524      */
525     static uint32_t GetArrayLength(JSIValue value);
526 
527     /**
528      * @brief Get indexed value from the javascript array object.
529      *
530      * @param [in] object: source array object
531      * @param [in] index: index number
532      * @return value acquired from the specified index of the array
533      * value returned should be released by caller with ReleaseValue when it won't be used any more
534      */
535     static JSIValue GetPropertyByIndex(JSIValue object, uint32_t index);
536 
537     /**
538      * @brief Get keys of the specified object value.
539      *
540      * @param [in] object: object value
541      * @return array object of the given object keys
542      * value returned should be released by caller with ReleaseValue when it won't be used any more
543      */
544     static JSIValue GetObjectKeys(JSIValue object);
545 
546     /**
547      * @brief Get heap memory status.
548      *
549      * @param [out] heapStatus: struct for heap memory status acquired
550      * @return true: if the operation succeed
551      *         false: otherwise
552      */
553     static bool GetJSHeapStatus(JSHeapStatus &heapStatus);
554 
555     /**
556      * @brief Check if the specified value is an array object.
557      *
558      * @param [in] value: value to check
559      * @return true: if the given value is an array object
560      *         false: otherwise
561      */
562     static bool ValueIsArray(JSIValue value);
563 
564     /**
565      * @brief Acquire the specified JSI value to create a reference
566      *
567      * @param [in] value: JSI value to acquire
568      * @return acquired value that may be used outside of the engine
569      * value returned should be released by caller with ReleaseValue when it won't be used any more
570      */
571     static JSIValue AcquireValue(JSIValue value);
572 
573     /**
574      * @brief Set API for given exports object
575      *
576      * @param [in] exports: object to set
577      * @param [in] name: API name
578      * @param [in] handler: pointer to the native implementation of this JS API
579      */
580     static void SetModuleAPI(JSIValue exports, const char * const name, JSIFunctionHandler handler);
581 
582     /**
583      * @brief Set JS page destroy callback on given module object
584      *
585      * @param [in] object: JS module object
586      * @param [in] callback: native destroy callback
587      * Note: this function is deprecated, use the other one alternatively
588      */
589     static void SetOnDestroy(JSIValue object, NativeCallback callback);
590 
591     /**
592      * @brief set JS page destroy callback on given module object
593      *
594      * @param [in] object: JS module object
595      * @param [in] callback: native destroy callback
596      */
597     static void SetOnDestroy(JSIValue object, JsiCallback callback);
598 
599     /**
600      * @brief set JS ability terminate callback on given module object
601      *
602      * @param [in] object: JS module object
603      * @param [in] callback: native terminate callback
604      * Note: this function is deprecated, use the other one alternatively
605      */
606     static void SetOnTerminate(JSIValue object, NativeCallback callback);
607 
608     /**
609      * @brief set JS ability terminate callback on given module object
610      *
611      * @param [in] object: JS module object
612      * @param [in] callback: native terminate callback
613      */
614     static void SetOnTerminate(JSIValue object, JsiCallback callback);
615 
616 #if (JS_FWK_TYPEDARRAY == 1)
617     /**
618      * @brief Get the properties of the given javascript TypedArray object.
619      *
620      * @param [in] typedArray: TypedArray object
621      * @param [out] type: type of the TypedArray, one of the TypedArrayType enum value
622      * @param [out] length: the element number of the TypedArray
623      * 0 if the typedArray parameter is not a TypedArray object
624      * @param [out] arrayBuffer: the ArrayBuffer object used by the TypedArray object
625      * value should be released by caller with ReleaseValue when it won't be used any more
626      * @param [out] byteOffset: the start offset of the ArrayBuffer for the TypedArray
627      * @return pointer to the Array Buffer's data area
628      * must ensure that the output pointer is used correctly, that is there is no out of bounds reads or writes
629      * the lifetime of the underlying data buffer is managed by the ArrayBuffer value, thus, do not release the
630      * pointer returned
631      */
632     static uint8_t *GetTypedArrayInfo(JSIValue typedArray,
633                                       TypedArrayType &type,
634                                       size_t &length,
635                                       JSIValue &arrayBuffer,
636                                       size_t &byteOffset);
637 
638     /**
639      * @brief Create a TypedArray object using an already existing ArrayBuffer object.
640      *
641      * @param [in] type: type of the TypedArray, one of the TypedArrayType enum value
642      * @param [in] length: the element number of the TypedArray
643      * @param [in] arrayBuffer: the ArrayBuffer object to use for the new TypedArray
644      * @param [in] byteOffset: the start offset of the ArrayBuffer for the TypedArray
645      * @return the TypedArray object created
646      * value returned should be released by caller with ReleaseValue when it won't be used any more.
647      */
648     static JSIValue CreateTypedArray(TypedArrayType type, size_t length, JSIValue arrayBuffer, size_t byteOffset);
649 
650     /**
651      * @brief Get the properties of the given ArrayBuffer object.
652      *
653      * @param [in] arrayBuffer: ArrayBuffer object
654      * @param [out] byteLength size of the ArrayBuffer in bytes
655      * 0 if the arrayBuffer parameter is not an ArrayBuffer object
656      * @return pointer to the Array Buffer's data area
657      * must ensure that the output pointer is used correctly, that is there is no out of bounds reads or writes
658      * the lifetime of the underlying data buffer is managed by the ArrayBuffer value, thus, do not release the
659      * pointer returned
660      */
661     static uint8_t *GetArrayBufferInfo(JSIValue arrayBuffer, size_t &byteLength);
662 
663     /**
664      * @brief Create an ArrayBuffer object.
665      *
666      * @param [in] byteLength: size of the ArrayBuffer to create in bytes
667      * @param [out] buffPtr: pointer to the Array Buffer's data area
668      * must ensure that the output pointer is used correctly, that is there is no out of bounds reads or writes
669      * the lifetime of the underlying data buffer is managed by the ArrayBuffer value, thus, do not release the pointer
670      * @return the ArrayBuffer object created
671      * result should be released by caller with ReleaseValue when it won't be used any more
672      */
673     static JSIValue CreateArrayBuffer(size_t byteLength, uint8_t *&buffPtr);
674 
675     /**
676      * @brief Check if the specified value is an ArrayBuffer object.
677      *
678      * @param [in] value: value to check
679      * @return true: if the given value is an ArrayBuffer object
680      *         false: otherwise
681      */
682     static bool ValueIsArrayBuffer(JSIValue value);
683 
684     /**
685      * @brief Check if the specified value is a TypedArray object.
686      *
687      * @param [in] value: value to check
688      * @return true: if the given value is an TypedArray object
689      *         false: otherwise
690      */
691     static bool ValueIsTypedArray(JSIValue value);
692 #endif // JS_FWK_TYPEDARRAY
693 
694     /**
695      * @brief Define a property on the specified object with the given name.
696      *
697      * @param [in] object: object to define property on
698      * @param [in] propName: property name
699      * @param [in] descriptor: property descriptor
700      * @return true: if success
701      *         false: otherwise
702      */
703     static bool DefineProperty(JSIValue object, JSIValue propName, JSPropertyDescriptor descriptor);
704 
705     /**
706      * @brief Define a property on the specified object with the given character name.
707      *
708      * @param [in] object: object to define property on
709      * @param [in] propNameStr: property name in character string
710      * @param [in] descriptor: property descriptor
711      * @return true: if success
712      *         false: otherwise
713      */
714     static bool DefineNamedProperty(JSIValue object, const char * const propNameStr, JSPropertyDescriptor descriptor);
715 
716     /**
717      * @brief Define a property on the specified object with the given setter and getter.
718      *
719      * @param [in] object: object to define property on
720      * @param [in] propNameStr: property name in character string
721      * @param [in] setter: access function for setting value
722      * @param [in] getter: access function for getting value
723      * @return true: if success
724      *         false: otherwise
725      */
726     static bool DefineNamedProperty(JSIValue object,
727                                     const char * const propNameStr,
728                                     JSIFunctionHandler setter,
729                                     JSIFunctionHandler getter);
730 
731     /**
732      * @brief Call fail and complete callbacks acquired from args.
733      *
734      * @param [in] thisVal: object for 'this' binding
735      * @param [in] args: object to acquire function callbacks from
736      * @param [in] errCode: error code for fail callback
737      * @param [in] errDesc: error description for fail callback
738      */
739     static void FailCallback(const JSIValue thisVal, const JSIValue args, int32_t errCode, const char * const errDesc);
740 
741     /**
742      * @brief Call success and complete callbacks acquired from args.
743      *
744      * @param [in] thisVal: object for 'this' binding
745      * @param [in] args: object to acquire function callbacks from
746      * @param [in] argv: arguments for success callback
747      * @param [in] argc: number of arguments for success callback
748      */
749     static void SuccessCallback(const JSIValue thisVal, const JSIValue args, const JSIValue *argv, uint8_t argc);
750 
751     /**
752      * @brief Create javascript error object with error code and error message.
753      * This interface can be used to create one uniform error object, which can be throw to JS API caller,
754      * The error object's structure is shown as following,
755      *    {
756      *       code: 100001, // the error code
757      *       message: "error details" // the error message
758      *       data: {} // more error info, this is optional
759      *    }
760      *
761      * @param [in] errCode: the error code which can indicate
762      * @param [in] errorMsg: value of 'message' property of constructed error object
763      * @param [in] extraErrData: value of 'data' property of constructed error object, which is optional,
764      *             if it's given by caller, it must be one object, and it should be released by caller itself
765      * @return value of the constructed error object
766      *
767      * value returned should be released by caller with ReleaseValue when it won't be used any more
768      */
769     static JSIValue CreateErrorWithCode(uint32_t errCode,
770                                         const char * const errMsg,
771                                         const JSIValue extraErrData = 0);
772 
773 private:
774     // private constructor for singleton instance
JSI()775     JSI() {}
~JSI()776     ~JSI() {}
777     static void SetNamedPointer(JSIValue object, const char * const name, JsiCallback callback);
778 };
779 } // namespace ACELite
780 } // namespace OHOS
781 
782 #endif // OHOS_ACELITE_JSI_H
783