• 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 PANDA_RUNTIME_INCLUDE_CORETYPES_NATIVE_POINTER_H_
17 #define PANDA_RUNTIME_INCLUDE_CORETYPES_NATIVE_POINTER_H_
18 
19 #include "runtime/include/language_context.h"
20 #include "runtime/include/object_header.h"
21 
22 namespace panda::coretypes {
23 
24 // Used 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 external_pointer_;
30     }
31 
SetExternalPointer(void * external_pointer)32     inline void SetExternalPointer(void *external_pointer)
33     {
34         external_pointer_ = external_pointer;
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, external_pointer_);
45     }
46 
47     ~NativePointer() = default;
48     DEFAULT_COPY_SEMANTIC(NativePointer);
49     DEFAULT_MOVE_SEMANTIC(NativePointer);
50 
51 private:
NativePointer()52     NativePointer() : ObjectHeader() {}
53 
54     void *external_pointer_ {nullptr};
55 };
56 
57 }  // namespace panda::coretypes
58 
59 #endif  // PANDA_RUNTIME_INCLUDE_CORETYPES_NATIVE_POINTER_H_
60