• 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 ECMASCRIPT_GLOBAL_HANDLE_COLLECTION_H
17 #define ECMASCRIPT_GLOBAL_HANDLE_COLLECTION_H
18 
19 #include "ecmascript/js_thread.h"
20 
21 namespace panda::ecmascript {
22 template<typename T>
23 class JSHandle;
24 class GlobalHandleCollection {
25 public:
GlobalHandleCollection(JSThread * thread)26     explicit GlobalHandleCollection(JSThread *thread) : thread_(thread) {}
27 
28     ~GlobalHandleCollection() = default;
29 
30     DEFAULT_MOVE_SEMANTIC(GlobalHandleCollection);
31     DEFAULT_COPY_SEMANTIC(GlobalHandleCollection);
32 
33     template<typename T>
NewHandle(JSTaggedType value)34     JSHandle<T> NewHandle(JSTaggedType value)
35     {
36         uintptr_t addr = thread_->NewGlobalHandle(value);
37         return JSHandle<T>(addr);
38     }
39 
40     template<typename T>
Dispose(JSHandle<T> handle)41     void Dispose(JSHandle<T> handle)
42     {
43         thread_->DisposeGlobalHandle(handle.GetAddress());
44     }
45 
46 private:
47     JSThread *thread_{nullptr};
48 };
49 }  // namespace panda::ecmascript
50 
51 #endif  // ECMASCRIPT_GLOBAL_HANDLE_COLLECTION_H
52