• 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_NAPI_JSNAPI_HELPER_INL_H
17 #define ECMASCRIPT_NAPI_JSNAPI_HELPER_INL_H
18 
19 #include "ecmascript/js_tagged_value.h"
20 #include "jsnapi_helper.h"
21 #include "libpandabase/macros.h"
22 
23 namespace panda {
24 template<typename T>
ToLocal(ecmascript::JSHandle<ecmascript::JSTaggedValue> from)25 Local<T> JSNApiHelper::ToLocal(ecmascript::JSHandle<ecmascript::JSTaggedValue> from)
26 {
27     return Local<T>(from.GetAddress());
28 }
29 
ToJSTaggedValue(JSValueRef * from)30 ecmascript::JSTaggedValue JSNApiHelper::ToJSTaggedValue(JSValueRef *from)
31 {
32     ASSERT(from != nullptr);
33     return *reinterpret_cast<ecmascript::JSTaggedValue *>(from);
34 }
35 
ToJSHandle(Local<JSValueRef> from)36 ecmascript::JSHandle<ecmascript::JSTaggedValue> JSNApiHelper::ToJSHandle(Local<JSValueRef> from)
37 {
38     ASSERT(!from.IsEmpty());
39     return ecmascript::JSHandle<ecmascript::JSTaggedValue>(reinterpret_cast<uintptr_t>(*from));
40 }
41 
ToJSHandle(JSValueRef * from)42 ecmascript::JSHandle<ecmascript::JSTaggedValue> JSNApiHelper::ToJSHandle(JSValueRef *from)
43 {
44     ASSERT(from != nullptr);
45     return ecmascript::JSHandle<ecmascript::JSTaggedValue>(reinterpret_cast<uintptr_t>(from));
46 }
47 }  // namespace panda
48 #endif  // ECMASCRIPT_NAPI_JSNAPI_HELPER_INL_H