1 /* 2 * Copyright (c) 2023 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_MODULE_JS_MODULE_DEREGISTER_H 17 #define ECMASCRIPT_MODULE_JS_MODULE_DEREGISTER_H 18 19 #include "ecmascript/js_object.h" 20 #include "ecmascript/js_tagged_value.h" 21 #include "ecmascript/module/js_module_source_text.h" 22 23 namespace panda::ecmascript { 24 class ModuleDeregister { 25 public: InitForDeregisterModule(JSThread * thread,JSHandle<JSTaggedValue> moduleRecord,bool excuteFromJob)26 static inline void InitForDeregisterModule(JSThread *thread, 27 JSHandle<JSTaggedValue> moduleRecord, bool excuteFromJob) 28 { 29 if (!excuteFromJob) { 30 return; 31 } 32 LoadingTypes moduleLoadingType = LoadingTypes::DYNAMITC_MODULE; 33 JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleRecord); 34 module->SetLoadingTypes(moduleLoadingType); 35 module->SetRegisterCounts(1); 36 thread->GetEcmaVM()->PushToDeregisterModuleList( 37 ConvertToString(SourceTextModule::GetModuleName(moduleRecord.GetTaggedValue()))); 38 } 39 ProcessModuleReference(JSThread * thread,const JSHandle<JSTaggedValue> & nameSpVal)40 static inline void ProcessModuleReference(JSThread *thread, const JSHandle<JSTaggedValue> &nameSpVal) 41 { 42 JSHandle<ModuleNamespace> nameSp = JSHandle<ModuleNamespace>::Cast(nameSpVal); 43 JSHandle<SourceTextModule> moduleRecord(thread, nameSp->GetModule()); 44 JSTaggedValue weakNameSp = JSTaggedValue(nameSpVal->CreateAndGetWeakRef()); 45 moduleRecord->SetNamespace(thread, weakNameSp); 46 } 47 48 static void FreeModuleRecord(void *pointer, void *hint); 49 50 static void RemoveModule(JSThread *thread, JSHandle<SourceTextModule> module); 51 52 static void ReviseLoadedModuleCount(JSThread *thread, JSTaggedValue moduleName); 53 54 static void IncreaseRegisterCounts(JSThread *thread, JSHandle<SourceTextModule> module, 55 std::set<CString> &increaseModule); 56 57 static void DecreaseRegisterCounts(JSThread *thread, JSHandle<SourceTextModule> module, 58 std::set<CString> &decreaseModule); 59 }; 60 } // namespace panda::ecmascript 61 #endif // ECMASCRIPT_MODULE_JS_MODULE_DEREGISTER_H 62