• 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_JS_SHARED_MODULE_H
17 #define ECMASCRIPT_MODULE_JS_SHARED_MODULE_H
18 
19 #include "ecmascript/module/js_module_source_text.h"
20 #include "ecmascript/jspandafile/js_pandafile.h"
21 
22 namespace panda::ecmascript {
23 using JSRecordInfo = JSPandaFile::JSRecordInfo;
24 
25 class SendableClassModule {
26 public:
27     static JSHandle<JSTaggedValue> GenerateSendableFuncModule(JSThread *thread, const JSHandle<JSTaggedValue> &module);
28 
29     static void CloneEnvOfSModule(JSThread *thread, JSHandle<SourceTextModule> &module,
30                                   JSHandle<TaggedArray> &envRec);
31 
32     static JSHandle<TaggedArray> CloneModuleEnvironment(JSThread *thread,
33                                                         const JSHandle<JSTaggedValue> &moduleEnvironment);
34 
35 private:
36     static JSHandle<JSTaggedValue> CloneRecordIndexBinding(JSThread *thread, JSTaggedValue indexBinding);
37 
38     static JSHandle<JSTaggedValue> CloneRecordNameBinding(JSThread *thread, JSTaggedValue binding);
39 };
40 
41 class JSSharedModule {
42 public:
43     static JSHandle<TaggedArray> CloneEnvForSModule(JSThread *thread, const JSHandle<SourceTextModule> &module,
44         JSHandle<TaggedArray> &envRec);
45     static JSHandle<ModuleNamespace> SModuleNamespaceCreate(JSThread *thread, const JSHandle<JSTaggedValue> &module,
46                                                             const JSHandle<TaggedArray> &exports);
47 private:
48     static JSHandle<JSTaggedValue> CreateSharedSortedExports(JSThread *thread, const JSHandle<TaggedArray> &exports);
49     static JSHandle<TaggedArray> GenerateSharedExports(JSThread *thread, const JSHandle<TaggedArray> &oldExports);
50 };
51 
52 class ResolvedRecordIndexBinding final : public Record {
53 public:
54     CAST_CHECK(ResolvedRecordIndexBinding, IsResolvedRecordIndexBinding);
55 
56     static constexpr size_t MODULE_RECORD_INDEX_OFFSET = Record::SIZE;
57     ACCESSORS(ModuleRecord, MODULE_RECORD_INDEX_OFFSET, ABC_FILE_NAME);
58     ACCESSORS(AbcFileName, ABC_FILE_NAME, INDEX_OFFSET);
59     ACCESSORS_PRIMITIVE_FIELD(Index, int32_t, INDEX_OFFSET, END_OFFSET);
60     DEFINE_ALIGN_SIZE(END_OFFSET);
61 
62     DECL_DUMP()
63     DECL_VISIT_OBJECT(MODULE_RECORD_INDEX_OFFSET, INDEX_OFFSET)
64 };
65 
66 class ResolvedRecordBinding final : public Record {
67 public:
68     CAST_CHECK(ResolvedRecordBinding, IsResolvedRecordBinding);
69 
70     static constexpr size_t MODULE_RECORD_OFFSET = Record::SIZE;
71     ACCESSORS(ModuleRecord, MODULE_RECORD_OFFSET, BINDING_NAME_OFFSET);
72     ACCESSORS(BindingName, BINDING_NAME_OFFSET, SIZE);
73 
74     DECL_DUMP()
75     DECL_VISIT_OBJECT(MODULE_RECORD_OFFSET, SIZE)
76 };
77 
78 class SharedModuleHelper {
79 public:
80     static JSHandle<JSTaggedValue> ParseSharedModule(JSThread *thread, const JSPandaFile *jsPandaFile,
81                                                      const CString &descriptor, const CString &moduleFilename,
82                                                      JSRecordInfo *recordInfo);
83 };
84 
85 }  // namespace panda::ecmascript
86 #endif  // ECMASCRIPT_MODULE_JS_SHARED_MODULE_H
87