• 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 #ifndef FOUNDATION_ACE_NAPI_NATIVE_ENGINE_NATIVE_VALUE_H
17 #define FOUNDATION_ACE_NAPI_NATIVE_ENGINE_NATIVE_VALUE_H
18 
19 #include <cstddef>
20 #include <cstdint>
21 #include <string>
22 
23 #include "interfaces/inner_api/napi/native_node_api.h"
24 
25 namespace panda {
26 class JsiRuntimeCallInfo;
27 namespace ecmascript {
28 struct JsFrameInfo;
29 }
30 }
31 
32 class NativeEngine;
33 class NativeReference;
34 
35 // To be refactor
36 typedef napi_value (*NapiNativeCallback)(napi_env env, panda::JsiRuntimeCallInfo*);
37 typedef void (*NativeFinalize)(NativeEngine* engine, void* data, void* hint);
38 typedef void (*NativeAsyncExecuteCallback)(NativeEngine* engine, void* data);
39 typedef void (*NativeAsyncCompleteCallback)(NativeEngine* engine, int status, void* data);
40 typedef void* (*DetachCallback)(NativeEngine* engine, void* value, void* hint);
41 
42 using ErrorPos = std::pair<uint32_t, uint32_t>;
43 using NativeThreadSafeFunctionCallJs =
44     void (*)(NativeEngine* env, napi_value js_callback, void* context, void* data);
45 
46 struct NativeObjectInfo {
CreateNewInstanceNativeObjectInfo47     static NativeObjectInfo* CreateNewInstance() { return new(std::nothrow) NativeObjectInfo(); }
48     NativeEngine* engine = nullptr;
49     void* nativeObject = nullptr;
50     NativeFinalize callback = nullptr;
51     void* hint = nullptr;
52 };
53 
54 struct NapiFunctionInfo {
CreateNewInstanceNapiFunctionInfo55     static NapiFunctionInfo* CreateNewInstance() { return new(std::nothrow) NapiFunctionInfo(); }
56     NapiNativeCallback callback = nullptr;
57     void* data = nullptr;
58     bool isSendable = false;
59     napi_env env = nullptr;
60 #ifdef ENABLE_CONTAINER_SCOPE
61     int32_t scopeId = -1;
62 #endif
63 };
64 
65 typedef void (*NaitveFinalize)(NativeEngine* env, void* data, void* hint);
66 
67 // To be delete
68 enum NativeValueType {
69     NATIVE_UNDEFINED,
70     NATIVE_NULL,
71     NATIVE_BOOLEAN,
72     NATIVE_NUMBER,
73     NATIVE_STRING,
74     NATIVE_SYMBOL,
75     NATIVE_OBJECT,
76     NATIVE_FUNCTION,
77     NATIVE_EXTERNAL,
78     NATIVE_BIGINT,
79 };
80 
81 // To be delete
82 enum NativeThreadSafeFunctionCallMode {
83     NATIVE_TSFUNC_NONBLOCKING,
84     NATIVE_TSFUNC_BLOCKING,
85 };
86 
87 // To be delete
88 enum NativeThreadSafeFunctionReleaseMode {
89     NATIVE_TSFUNC_RELEASE,
90     NATIVE_TSFUNC_ABORT,
91 };
92 
93 struct JSValueWrapper {
JSValueWrapperJSValueWrapper94     JSValueWrapper()
95     {
96         u.ptr = nullptr;
97         tag = 0;
98     }
99     template<typename T>
JSValueWrapperJSValueWrapper100     JSValueWrapper(T value)
101     {
102         *(T*)this = value;
103     }
TJSValueWrapper104     template<typename T> operator T()
105     {
106         return *(T*)this;
107     }
108     template<typename T> JSValueWrapper& operator=(T value)
109     {
110         *(T*)this = value;
111         return *this;
112     }
113     union {
114         int32_t int32;
115         double float64;
116         void* ptr;
117     } u;
118     int64_t tag = 0;
119 };
120 
121 struct NapiTypeTag {
122     uint64_t lower;
123     uint64_t upper;
124 };
125 
126 // To be delete
127 enum NativeTypedArrayType {
128     NATIVE_INT8_ARRAY,
129     NATIVE_UINT8_ARRAY,
130     NATIVE_UINT8_CLAMPED_ARRAY,
131     NATIVE_INT16_ARRAY,
132     NATIVE_UINT16_ARRAY,
133     NATIVE_INT32_ARRAY,
134     NATIVE_UINT32_ARRAY,
135     NATIVE_FLOAT32_ARRAY,
136     NATIVE_FLOAT64_ARRAY,
137     NATIVE_BIGINT64_ARRAY,
138     NATIVE_BIGUINT64_ARRAY,
139 };
140 
141 #endif /* FOUNDATION_ACE_NAPI_NATIVE_ENGINE_NATIVE_VALUE_H */