133eb0b6dSopenharmony_ci/* 233eb0b6dSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 333eb0b6dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 433eb0b6dSopenharmony_ci * you may not use this file except in compliance with the License. 533eb0b6dSopenharmony_ci * You may obtain a copy of the License at 633eb0b6dSopenharmony_ci * 733eb0b6dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 833eb0b6dSopenharmony_ci * 933eb0b6dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1033eb0b6dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1133eb0b6dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1233eb0b6dSopenharmony_ci * See the License for the specific language governing permissions and 1333eb0b6dSopenharmony_ci * limitations under the License. 1433eb0b6dSopenharmony_ci */ 1533eb0b6dSopenharmony_ci 1633eb0b6dSopenharmony_ci#ifndef FOUNDATION_ACE_NAPI_NATIVE_ENGINE_NATIVE_UTILS_H 1733eb0b6dSopenharmony_ci#define FOUNDATION_ACE_NAPI_NATIVE_ENGINE_NATIVE_UTILS_H 1833eb0b6dSopenharmony_ci 1933eb0b6dSopenharmony_ci#include <cstring> 2033eb0b6dSopenharmony_ci#include "securec.h" 2133eb0b6dSopenharmony_ci 2233eb0b6dSopenharmony_ci#include "ecmascript/napi/include/jsnapi.h" 2333eb0b6dSopenharmony_ci#include "interfaces/inner_api/napi/native_node_api.h" 2433eb0b6dSopenharmony_ci#include "utils/log.h" 2533eb0b6dSopenharmony_ci 2633eb0b6dSopenharmony_cistatic constexpr uint64_t NAPI_SPECIAL_STATUS = 5; 2733eb0b6dSopenharmony_ci 2833eb0b6dSopenharmony_ciinline napi_value JsValueFromLocalValue(panda::Local<panda::JSValueRef> local) 2933eb0b6dSopenharmony_ci{ 3033eb0b6dSopenharmony_ci return reinterpret_cast<napi_value>(*local); 3133eb0b6dSopenharmony_ci} 3233eb0b6dSopenharmony_ci 3333eb0b6dSopenharmony_ciinline panda::Local<panda::JSValueRef> LocalValueFromJsValue(napi_value v) 3433eb0b6dSopenharmony_ci{ 3533eb0b6dSopenharmony_ci panda::Local<panda::JSValueRef> local(reinterpret_cast<uintptr_t>(v)); 3633eb0b6dSopenharmony_ci return local; 3733eb0b6dSopenharmony_ci} 3833eb0b6dSopenharmony_ci 3933eb0b6dSopenharmony_ciinline bool NapiStatusValidationCheck(panda::JSValueRef* value) 4033eb0b6dSopenharmony_ci{ 4133eb0b6dSopenharmony_ci if ((value != nullptr) && (*(panda::JSTaggedType *)(value) == NAPI_SPECIAL_STATUS)) { 4233eb0b6dSopenharmony_ci return false; 4333eb0b6dSopenharmony_ci } 4433eb0b6dSopenharmony_ci return true; 4533eb0b6dSopenharmony_ci} 4633eb0b6dSopenharmony_ci 4733eb0b6dSopenharmony_ciinline bool NapiStatusValidationCheck(panda::Local<panda::JSValueRef> value) 4833eb0b6dSopenharmony_ci{ 4933eb0b6dSopenharmony_ci // Since we sink napi heavy logics to ark runtime, 5033eb0b6dSopenharmony_ci // we need to check napi status using a special value. 5133eb0b6dSopenharmony_ci // Here we use JSTaggedValue::Hole(0x5) as the special value. 5233eb0b6dSopenharmony_ci return NapiStatusValidationCheck(*value); 5333eb0b6dSopenharmony_ci} 5433eb0b6dSopenharmony_ci#endif // FOUNDATION_ACE_NAPI_NATIVE_ENGINE_NATIVE_UTILS_H 55