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 #ifndef ECMASCRIPT_MODULE_MANAGER_HELPER_H
17 #define ECMASCRIPT_MODULE_MANAGER_HELPER_H
18 
19 #include "ecmascript/module/js_module_source_text.h"
20 
21 namespace panda::ecmascript {
22 
23 class ModuleManagerHelper {
24 public:
25     static JSTaggedValue PUBLIC_API GetModuleValue(JSThread *thread, JSHandle<SourceTextModule> module, int index);
26 
27     static JSTaggedValue GetModuleValue(JSThread *thread,
28                                         JSHandle<SourceTextModule> module,
29                                         JSTaggedValue bindingName);
30 
31     static JSTaggedValue GetNativeOrCjsModuleValue(JSThread *thread,
32                                                    JSTaggedValue resolvedModule,
33                                                    int32_t index);
34 
35     static JSHandle<JSTaggedValue> GetNativeOrCjsExports(JSThread *thread,
36                                                          JSTaggedValue resolvedModule);
37 
38     static JSTaggedValue PUBLIC_API GetModuleValueFromIndexBinding(JSThread *thread,
39                                                                    JSHandle<SourceTextModule> module,
40                                                                    JSTaggedValue resolvedBinding);
41 
42     static JSTaggedValue PUBLIC_API GetModuleValueFromRecordBinding(JSThread *thread,
43                                                                     JSHandle<SourceTextModule> module,
44                                                                     JSTaggedValue resolvedBinding);
45 
46     static JSHandle<SourceTextModule> GetResolvedRecordIndexBindingModule(
47         JSThread *thread, JSHandle<SourceTextModule> module, JSHandle<ResolvedRecordIndexBinding> binding);
48 
49     static JSHandle<SourceTextModule> GetResolvedRecordBindingModule(
50         JSThread *thread, JSHandle<SourceTextModule> module, JSHandle<ResolvedRecordBinding> binding);
51 
52     static JSTaggedValue GetLazyModuleValueFromIndexBinding(JSThread *thread,
53                                                             JSHandle<SourceTextModule> module,
54                                                             JSTaggedValue resolvedBinding);
55 
56     static JSTaggedValue GetLazyModuleValueFromRecordBinding(JSThread *thread,
57                                                              JSHandle<SourceTextModule> module,
58                                                              JSTaggedValue resolvedBinding);
59 
60     static JSTaggedValue UpdateBindingAndGetModuleValue(JSThread *thread, JSHandle<SourceTextModule> module,
61         JSHandle<SourceTextModule> requiredModule, int32_t index, JSTaggedValue bindingName);
62 };
63 }  // namespace panda::ecmascript
64 #endif  // ECMASCRIPT_MODULE_JS_SHARED_MODULE_H
65