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_IMPL_ARK_NATIVE_VALUE_ARK_NATIVE_OBJECT_H 17 #define FOUNDATION_ACE_NAPI_NATIVE_ENGINE_IMPL_ARK_NATIVE_VALUE_ARK_NATIVE_OBJECT_H 18 19 #include <mutex> 20 21 #include "ark_native_value.h" 22 23 class ArkNativeObject : public ArkNativeValue, public NativeObject { 24 public: 25 explicit ArkNativeObject(ArkNativeEngine* engine); 26 ArkNativeObject(ArkNativeEngine* engine, Local<JSValueRef> value); 27 ArkNativeObject(ArkNativeEngine* engine, void* detach, void* attach); 28 ArkNativeObject(ArkNativeEngine* engine, DetachCallback detach, AttachCallback attach); 29 ~ArkNativeObject() override; 30 31 bool ConvertToNativeBindingObject( 32 void* engine, DetachCallback detach, AttachCallback attach, void *object, void *hint) override; 33 void* GetInterface(int interfaceId) override; 34 static void* DetachFuncCallback(void* engine, void* object, void* hint, void* detachData); 35 static Local<JSValueRef> AttachFuncCallback(void* engine, void* object, void* hint, void* attachData); 36 void SetNativePointer(void* pointer, NativeFinalize cb, void* hint, NativeReference** reference = nullptr, 37 size_t nativeBindingSize = 0) override; 38 void* GetNativePointer() override; 39 void SetNativeBindingPointer(void* enginePointer, void* objPointer, 40 void* hint, void* detachData, void* attachData) override; 41 void* GetNativeBindingPointer(uint32_t index) override; 42 void AddFinalizer(void* pointer, NativeFinalize cb, void* hint) override; 43 void Freeze() override; 44 void Seal() override; 45 NativeValue* GetPropertyNames() override; 46 NativeValue* GetEnumerablePropertyNames() override; 47 48 NativeValue* GetPrototype() override; 49 50 bool DefineProperty(NativePropertyDescriptor propertyDescriptor) override; 51 52 bool SetProperty(NativeValue* key, NativeValue* value) override; 53 NativeValue* GetProperty(NativeValue* key) override; 54 bool HasProperty(NativeValue* key) override; 55 bool DeleteProperty(NativeValue* key) override; 56 57 bool SetProperty(const char* name, NativeValue* value) override; 58 NativeValue* GetProperty(const char* name) override; 59 bool HasProperty(const char* name) override; 60 bool DeleteProperty(const char* name) override; 61 62 bool SetPrivateProperty(const char* name, NativeValue* value) override; 63 NativeValue* GetPrivateProperty(const char* name) override; 64 bool HasPrivateProperty(const char* name) override; 65 bool DeletePrivateProperty(const char* name) override; 66 67 NativeValue* GetAllPropertyNames( 68 napi_key_collection_mode keyMode, napi_key_filter keyFilter, napi_key_conversion keyConversion) override; 69 bool AssociateTypeTag(NapiTypeTag* typeTag) override; 70 bool CheckTypeTag(NapiTypeTag* typeTag) override; 71 void SetModuleName(std::string moduleName); 72 std::string GetModuleName(); 73 74 private: 75 static AttachCallback attach_; 76 static DetachCallback detach_; 77 std::mutex funcMutex_; 78 }; 79 80 #endif /* FOUNDATION_ACE_NAPI_NATIVE_ENGINE_IMPL_ARK_NATIVE_VALUE_ARK_NATIVE_OBJECT_H */ 81