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_V8_NATIVE_REFERENCE_H 17 #define FOUNDATION_ACE_NAPI_NATIVE_ENGINE_V8_NATIVE_REFERENCE_H 18 19 #include "native_engine/native_value.h" 20 21 #include "native_engine/native_reference.h" 22 23 class V8NativeEngine; 24 25 class V8NativeReference : public NativeReference { 26 public: 27 V8NativeReference(V8NativeEngine* engine, 28 NativeValue* value, 29 uint32_t initialRefcount, 30 bool deleteSelf, 31 NativeFinalize callback = nullptr, 32 void* data = nullptr, 33 void* hint = nullptr); 34 ~V8NativeReference() override; 35 36 uint32_t Ref() override; 37 uint32_t Unref() override; 38 NativeValue* Get() override; 39 void* GetData() override; 40 operator NativeValue*() override; 41 42 private: 43 static void FinalizeCallback(const v8::WeakCallbackInfo<V8NativeReference> &data); 44 static void SecondPassCallback(const v8::WeakCallbackInfo<V8NativeReference> &data); 45 46 V8NativeEngine* engine_; 47 v8::Global<v8::Value> value_; 48 uint32_t refCount_; 49 bool deleteSelf_; 50 NativeFinalize callback_; 51 void *data_; 52 void *hint_; 53 }; 54 55 #endif /* FOUNDATION_ACE_NAPI_NATIVE_ENGINE_V8_NATIVE_REFERENCE_H */ 56