• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TOOLS_H
17 #define ECMASCRIPT_MODULE_TOOLS_H
18 
19 #include "ecmascript/module/js_module_source_text.h"
20 
21 namespace panda::ecmascript {
22 
23 class ModuleTools {
24 public:
25     static JSTaggedValue GetModuleValueFromIndexBindingForLog(JSThread *thread,
26         JSHandle<SourceTextModule> module, JSTaggedValue resolvedBinding, int32_t index);
27 
28     static JSTaggedValue GetModuleValueFromRecordBindingForLog(JSThread *thread,
29         JSHandle<SourceTextModule> module, JSTaggedValue resolvedBinding, int32_t index);
30 
31     static JSTaggedValue ProcessModuleLoadInfo(JSThread *thread, JSHandle<SourceTextModule> currentModule,
32                                                JSTaggedValue resolvedBinding, int32_t index);
33 
34     static JSTaggedValue ProcessModuleNameSpaceLoadInfo(JSThread *thread,
35                                                         JSHandle<SourceTextModule> currentModule,
36                                                         JSHandle<SourceTextModule> requiredModule);
37     // for lazy
38     static JSTaggedValue GetLazyModuleValueFromIndexBindingForLog(
39         JSThread *thread, JSHandle<SourceTextModule> module, JSTaggedValue resolvedBinding, int32_t index);
40 
41     static JSTaggedValue GetLazyModuleValueFromRecordBindingForLog(
42         JSThread *thread, JSHandle<SourceTextModule> module, JSTaggedValue resolvedBinding, int32_t index);
43 
44     static JSTaggedValue ProcessLazyModuleLoadInfo(JSThread *thread, JSHandle<SourceTextModule> currentModule,
45         JSTaggedValue resolvedBinding, int32_t index);
46 };
47 
48 class ModuleTraceScope {
49 public:
ModuleTraceScope(JSThread * thread,const CString traceInfo)50     ModuleTraceScope(JSThread *thread, [[maybe_unused]]const CString traceInfo)
51         : enableESMTrace_(thread->GetEcmaVM()->GetJSOptions().EnableESMTrace())
52     {
53         if (enableESMTrace_) {
54             ECMA_BYTRACE_START_TRACE(HITRACE_TAG_ARK, traceInfo.c_str());
55         }
56     }
57 
~ModuleTraceScope()58     ~ModuleTraceScope()
59     {
60         if (enableESMTrace_) {
61             ECMA_BYTRACE_FINISH_TRACE(HITRACE_TAG_ARK);
62         }
63     }
64 private:
65     bool enableESMTrace_ {false};
66 };
67 } // namespace panda::ecmascript
68 #endif // ECMASCRIPT_MODULE_MODULE_TOOLS_H
69