1 /* 2 * Copyright (c) 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 "ark_interop_scope.h" 17 18 namespace CJ { 19 std::vector<ARKTS_ScopeManager> ARKTS_ScopeManager::scopeStack_{}; 20 OpenScope(panda::ecmascript::EcmaVM* vm)21ARKTS_Scope ARKTS_ScopeManager::OpenScope(panda::ecmascript::EcmaVM* vm) 22 { 23 scopeStack_.emplace_back(vm); 24 size_t scopeId = scopeStack_.size(); 25 return P_CAST(scopeId, ARKTS_Scope); 26 } 27 CloseScope(ARKTS_Scope target)28bool ARKTS_ScopeManager::CloseScope(ARKTS_Scope target) 29 { 30 auto targetScope = P_CAST(target, int64_t); 31 if (targetScope > (int64_t)scopeStack_.size()) { 32 return false; 33 } 34 while ((int64_t)scopeStack_.size() >= targetScope) { 35 scopeStack_.pop_back(); 36 } 37 return true; 38 } 39 ARKTS_ScopeManager(panda::ecmascript::EcmaVM* vm)40ARKTS_ScopeManager::ARKTS_ScopeManager(panda::ecmascript::EcmaVM* vm): scope_(vm) 41 { 42 } 43 }