1 /** 2 * Copyright (c) 2021-2024 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 #include "plugins/ets/runtime/ets_utils.h" 17 #include "plugins/ets/runtime/types/ets_class.h" 18 #include "plugins/ets/runtime/types/ets_method.h" 19 20 namespace ark::ets { 21 IsEtsGlobalClassName(const std::string & descriptor)22bool IsEtsGlobalClassName(const std::string &descriptor) 23 { 24 ASSERT(descriptor.length() >= 2U); // L...; 25 ASSERT('L' == descriptor[0]); 26 ASSERT(';' == descriptor[descriptor.size() - 1]); 27 28 constexpr size_t ETSGLOBAL_SEMICOLON_LENGTH = sizeof(ETSGLOBAL_CLASS_NAME); 29 30 const auto etsGlobalSubstringPos = descriptor.rfind(ETSGLOBAL_CLASS_NAME); 31 const bool etsGlobalClass = (1 == etsGlobalSubstringPos) && descriptor.length() == 1 + ETSGLOBAL_SEMICOLON_LENGTH; 32 const bool endsWithETSGLOBAL = descriptor.length() - ETSGLOBAL_SEMICOLON_LENGTH == etsGlobalSubstringPos; 33 const bool etsGlobalClassInPackage = endsWithETSGLOBAL && '/' == descriptor[etsGlobalSubstringPos - 1]; 34 35 return etsGlobalClass || etsGlobalClassInPackage; 36 } 37 InvokeVoid(EtsCoroutine * coro,EtsObject * lambda)38void LambdaUtils::InvokeVoid(EtsCoroutine *coro, EtsObject *lambda) 39 { 40 EtsMethod *invoke = lambda->GetClass()->GetMethod("invoke"); 41 if (invoke == nullptr) { 42 LOG(FATAL, RUNTIME) << "No method 'invoke' found"; 43 return; 44 } 45 Value arg(lambda->GetCoreType()); 46 invoke->GetPandaMethod()->InvokeVoid(coro, &arg); 47 } 48 } // namespace ark::ets 49