Refactor module_data_extractor

--------------------------
https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I6JCH3?from=project-issue
--------------------------
1.move JsonParse from Module_Manager to ModuleDataExtractor
2.move Module_Manager.cpp/.h from js_pandafile to module

Signed-off-by: yaochaonan <yaochaonan@huawei.com>
Change-Id: I798b1772f8ccbbfecf0ad8eeeb2b2ffcd27abc9c
This commit is contained in:
yaochaonan 2023-03-05 18:05:15 +08:00
parent 95c3bf8b8e
commit 9aa712d62a
9 changed files with 27 additions and 28 deletions

View File

@ -551,7 +551,6 @@ ecma_source = [
"ecmascript/jspandafile/class_info_extractor.cpp",
"ecmascript/jspandafile/debug_info_extractor.cpp",
"ecmascript/jspandafile/literal_data_extractor.cpp",
"ecmascript/jspandafile/module_data_extractor.cpp",
"ecmascript/jspandafile/accessor/module_data_accessor.cpp",
"ecmascript/jspandafile/panda_file_translator.cpp",
"ecmascript/jspandafile/js_pandafile_executor.cpp",
@ -652,6 +651,7 @@ ecma_source = [
"ecmascript/module/js_module_namespace.cpp",
"ecmascript/module/js_module_record.cpp",
"ecmascript/module/js_module_source_text.cpp",
"ecmascript/module/module_data_extractor.cpp",
"ecmascript/napi/jsnapi.cpp",
"ecmascript/object_factory.cpp",
"ecmascript/object_operator.cpp",

View File

@ -53,7 +53,6 @@
#include "ecmascript/jspandafile/constpool_value.h"
#include "ecmascript/jspandafile/js_pandafile.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/jspandafile/module_data_extractor.h"
#include "ecmascript/jspandafile/panda_file_translator.h"
#include "ecmascript/jspandafile/program_object.h"
#include "ecmascript/js_arraybuffer.h"
@ -69,6 +68,7 @@
#include "ecmascript/napi/include/dfx_jsnapi.h"
#include "ecmascript/taskpool/task.h"
#include "ecmascript/module/js_module_manager.h"
#include "ecmascript/module/module_data_extractor.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/patch/quick_fix_manager.h"
#include "ecmascript/pgo_profiler/pgo_profiler_manager.h"

View File

@ -16,17 +16,16 @@
#include "ecmascript/aot_file_manager.h"
#include "ecmascript/base/path_helper.h"
#include "ecmascript/builtins/builtins_json.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/frame_handler.h"
#include "ecmascript/interpreter/fast_runtime_stub-inl.h"
#include "ecmascript/jspandafile/module_data_extractor.h"
#include "ecmascript/jspandafile/js_pandafile.h"
#include "ecmascript/jspandafile/js_pandafile_executor.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/js_array.h"
#include "ecmascript/linked_hash_table.h"
#include "ecmascript/module/js_module_source_text.h"
#include "ecmascript/module/module_data_extractor.h"
#include "ecmascript/tagged_dictionary.h"
#include "ecmascript/require/js_cjs_module.h"
#ifdef PANDA_TARGET_WINDOWS
@ -34,7 +33,6 @@
#endif
namespace panda::ecmascript {
using BuiltinsJson = builtins::BuiltinsJson;
using PathHelper = base::PathHelper;
namespace {
@ -574,18 +572,6 @@ int ModuleManager::GetExportObjectIndex(EcmaVM *vm, JSHandle<SourceTextModule> e
return index;
}
JSTaggedValue ModuleManager::JsonParse(JSThread *thread, const JSPandaFile *jsPandaFile, CString entryPoint)
{
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
EcmaRuntimeCallInfo *info =
EcmaInterpreter::NewRuntimeCallInfo(
thread, undefined, undefined, undefined, 1); // 1 : argument numbers
CString value = jsPandaFile->GetJsonStringId(thread, entryPoint);
JSHandle<JSTaggedValue> arg0(thread->GetEcmaVM()->GetFactory()->NewFromASCII(value));
info->SetCallArg(arg0.GetTaggedValue());
return BuiltinsJson::Parse(info);
}
std::pair<bool, ModuleTypes> ModuleManager::CheckNativeModule(const CString &moduleRequestName)
{
if (moduleRequestName.compare(0, OHOS_PREFIX_SIZE, REQUIRE_NAPI_OHOS_PREFIX) == 0) {

View File

@ -77,7 +77,6 @@ public:
static CString GetRecordName(JSTaggedValue module);
static int GetExportObjectIndex(EcmaVM *vm, JSHandle<SourceTextModule> ecmaModule, const std::string &key);
static JSTaggedValue JsonParse(JSThread *thread, const JSPandaFile *jsPandaFile, CString entryPoint);
inline static bool IsNativeModule(ModuleTypes moduleType)
{

View File

@ -20,10 +20,10 @@
#include "ecmascript/base/string_helper.h"
#include "ecmascript/jspandafile/js_pandafile_executor.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/jspandafile/module_data_extractor.h"
#include "ecmascript/linked_hash_table.h"
#include "ecmascript/module/js_module_manager.h"
#include "ecmascript/module/js_module_namespace.h"
#include "ecmascript/module/module_data_extractor.h"
#include "ecmascript/platform/file.h"
#include "ecmascript/tagged_dictionary.h"

View File

@ -13,19 +13,21 @@
* limitations under the License.
*/
#include "ecmascript/jspandafile/module_data_extractor.h"
#include "ecmascript/jspandafile/accessor/module_data_accessor.h"
#include "ecmascript/base/string_helper.h"
#include "ecmascript/builtins/builtins_json.h"
#include "ecmascript/ecma_string.h"
#include "ecmascript/global_env.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/tagged_array-inl.h"
#include "ecmascript/module/js_module_manager.h"
#include "ecmascript/module/module_data_extractor.h"
#include "libpandafile/literal_data_accessor-inl.h"
namespace panda::ecmascript {
using StringData = panda_file::StringData;
using BuiltinsJson = builtins::BuiltinsJson;
JSHandle<JSTaggedValue> ModuleDataExtractor::ParseModule(JSThread *thread, const JSPandaFile *jsPandaFile,
const CString &descriptor, const CString &moduleFilename)
@ -109,7 +111,7 @@ JSHandle<JSTaggedValue> ModuleDataExtractor::ParseJsonModule(JSThread *thread, c
JSHandle<JSTaggedValue> defaultName = thread->GlobalConstants()->GetHandledDefaultString();
JSHandle<LocalExportEntry> localExportEntry = factory->NewLocalExportEntry(defaultName, defaultName);
SourceTextModule::AddLocalExportEntry(thread, moduleRecord, localExportEntry, 0, 1); // 1 means len
JSTaggedValue jsonData = ModuleManager::JsonParse(thread, jsPandaFile, recordName);
JSTaggedValue jsonData = JsonParse(thread, jsPandaFile, recordName);
moduleRecord->StoreModuleValue(thread, 0, JSHandle<JSTaggedValue>(thread, jsonData)); // index = 0
JSHandle<EcmaString> ecmaModuleFilename = factory->NewFromUtf8(moduleFilename);
@ -141,4 +143,16 @@ JSHandle<JSTaggedValue> ModuleDataExtractor::ParseNativeModule(JSThread *thread,
return JSHandle<JSTaggedValue>::Cast(moduleRecord);
}
JSTaggedValue ModuleDataExtractor::JsonParse(JSThread *thread, const JSPandaFile *jsPandaFile, CString entryPoint)
{
JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
EcmaRuntimeCallInfo *info =
EcmaInterpreter::NewRuntimeCallInfo(
thread, undefined, undefined, undefined, 1); // 1 : argument numbers
CString value = jsPandaFile->GetJsonStringId(thread, entryPoint);
JSHandle<JSTaggedValue> arg0(thread->GetEcmaVM()->GetFactory()->NewFromASCII(value));
info->SetCallArg(arg0.GetTaggedValue());
return BuiltinsJson::Parse(info);
}
} // namespace panda::ecmascript

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef ECMASCRIPT_JSPANDAFILE_MODULE_DATA_EXTRACTOR_H
#define ECMASCRIPT_JSPANDAFILE_MODULE_DATA_EXTRACTOR_H
#ifndef ECMASCRIPT_MODULE_MODULE_DATA_EXTRACTOR_H
#define ECMASCRIPT_MODULE_MODULE_DATA_EXTRACTOR_H
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/module/js_module_source_text.h"
@ -41,6 +41,7 @@ public:
const CString &moduleFilename, const CString &recordName = nullptr);
static JSHandle<JSTaggedValue> ParseNativeModule(JSThread *thread,
const CString &moduleRequestName, ModuleTypes moduleType);
static JSTaggedValue JsonParse(JSThread *thread, const JSPandaFile *jsPandaFile, CString entryPoint);
};
} // namespace panda::ecmascript
#endif // ECMASCRIPT_JSPANDAFILE_MODULE_DATA_EXTRACTOR_H
#endif // ECMASCRIPT_MODULE_MODULE_DATA_EXTRACTOR_H

View File

@ -22,9 +22,9 @@
#include "ecmascript/jspandafile/js_pandafile.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/jspandafile/program_object.h"
#include "ecmascript/jspandafile/module_data_extractor.h"
#include "ecmascript/module/js_module_manager.h"
#include "ecmascript/module/js_module_source_text.h"
#include "ecmascript/module/module_data_extractor.h"
#include "ecmascript/tests/test_helper.h"
#include "ecmascript/linked_hash_table.h"

View File

@ -17,7 +17,6 @@
#include "ecmascript/aot_file_manager.h"
#include "ecmascript/base/path_helper.h"
#include "ecmascript/builtins/builtins_json.h"
#include "ecmascript/interpreter/interpreter-inl.h"
#include "ecmascript/interpreter/slow_runtime_stub.h"
#include "ecmascript/platform/file.h"
@ -26,9 +25,9 @@
#include "ecmascript/jspandafile/js_pandafile.h"
#include "ecmascript/jspandafile/js_pandafile_executor.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/module/module_data_extractor.h"
namespace panda::ecmascript {
using BuiltinsJson = builtins::BuiltinsJson;
using PathHelper = base::PathHelper;
void CjsModule::InitializeModule(JSThread *thread, JSHandle<CjsModule> &module,
@ -134,7 +133,7 @@ JSHandle<JSTaggedValue> CjsModule::Load(JSThread *thread, JSHandle<EcmaString> &
if (jsPandaFile->IsJson(thread, requestEntryPoint)) {
JSHandle<JSTaggedValue> result = JSHandle<JSTaggedValue>(thread,
ModuleManager::JsonParse(thread, jsPandaFile, requestEntryPoint));
ModuleDataExtractor::JsonParse(thread, jsPandaFile, requestEntryPoint));
// Set module.exports ---> exports
JSHandle<JSTaggedValue> exportsKey = thread->GlobalConstants()->GetHandledCjsExportsString();
SlowRuntimeStub::StObjByName(thread, module.GetTaggedValue(), exportsKey.GetTaggedValue(),