1 /** 2 * Copyright (c) 2021-2022 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 PANDA_RUNTIME_ECMASCRIPT_NATIVEPOINTER_H 17 #define PANDA_RUNTIME_ECMASCRIPT_NATIVEPOINTER_H 18 19 #include "runtime/include/language_context.h" 20 #include "runtime/include/object_header.h" 21 22 namespace panda::coretypes { 23 24 // Use for the requirement of ACE that wants to associated a registered C++ resource with a JSObject. 25 class NativePointer : public ObjectHeader { 26 public: GetExternalPointer()27 inline void *GetExternalPointer() const 28 { 29 return externalPointer_; 30 } 31 SetExternalPointer(void * externalPointer)32 inline void SetExternalPointer(void *externalPointer) 33 { 34 externalPointer_ = externalPointer; 35 } 36 Cast(ObjectHeader * object)37 static NativePointer *Cast(ObjectHeader *object) 38 { 39 return static_cast<NativePointer *>(object); 40 } 41 GetExternalPointerOffset()42 static constexpr uint32_t GetExternalPointerOffset() 43 { 44 return MEMBER_OFFSET(NativePointer, externalPointer_); 45 } 46 47 private: NativePointer()48 NativePointer() : ObjectHeader() {} 49 50 void *externalPointer_ {nullptr}; 51 }; 52 53 } // namespace panda::coretypes 54 55 #endif // PANDA_RUNTIME_ECMASCRIPT_NATIVEPOINTER_H 56