• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)22 bool 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     if (etsGlobalSubstringPos == std::string::npos) {
32         return false;
33     }
34     const bool etsGlobalClass = (1 == etsGlobalSubstringPos) && descriptor.length() == 1 + ETSGLOBAL_SEMICOLON_LENGTH;
35     const bool endsWithETSGLOBAL = descriptor.length() - ETSGLOBAL_SEMICOLON_LENGTH == etsGlobalSubstringPos;
36     const bool etsGlobalClassInPackage = endsWithETSGLOBAL && '/' == descriptor[etsGlobalSubstringPos - 1];
37 
38     return etsGlobalClass || etsGlobalClassInPackage;
39 }
40 
InvokeVoid(EtsCoroutine * coro,EtsObject * lambda)41 void LambdaUtils::InvokeVoid(EtsCoroutine *coro, EtsObject *lambda)
42 {
43     EtsMethod *invoke = lambda->GetClass()->GetMethod("invoke");
44     if (invoke == nullptr) {
45         LOG(FATAL, RUNTIME) << "No method 'invoke' found";
46         return;
47     }
48     Value arg(lambda->GetCoreType());
49     invoke->GetPandaMethod()->InvokeVoid(coro, &arg);
50 }
51 }  // namespace ark::ets
52