• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "ecmascript/ohos/module_snapshot_interfaces.h"
16 
17 #include "ecmascript/ohos/ohos_version_info_tools.h"
18 #include "ecmascript/module/module_snapshot.h"
19 #include "ecmascript/platform/filesystem.h"
20 
21 namespace panda::ecmascript::ohos {
22 
Serialize(const EcmaVM * vm,const CString & path)23 void ModuleSnapshotInterfaces::Serialize(const EcmaVM *vm, const CString &path)
24 {
25     LOG_ECMA(INFO) << "ModuleSnapshotInterfaces::Serialize: " << path;
26     ECMA_BYTRACE_NAME(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "ModuleSnapshotInterfaces::Serialize", "");
27     // check application white list
28     if (!filesystem::Exists(path.c_str())) {
29         LOG_ECMA(INFO) << "ModuleSnapshotInterface::Serialize: " << path <<" is not exists";
30         return;
31     }
32     CString version = OhosVersionInfoTools::GetRomVersion();
33     if (version.empty()) {
34         LOG_ECMA(ERROR) << "ModuleSnapshotInterface::Serialize rom version is empty";
35         return;
36     }
37     ModuleSnapshot::SerializeDataAndPostSavingJob(vm, path, version);
38 }
39 
Deserialize(const EcmaVM * vm,const CString & path)40 void ModuleSnapshotInterfaces::Deserialize(const EcmaVM *vm, const CString &path)
41 {
42     LOG_ECMA(DEBUG) << "ModuleSnapshotInterfaces::Deserialize: " << path;
43     ECMA_BYTRACE_NAME(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "ModuleSnapshotInterfaces::Deserialize", "");
44     // check application white list
45     if (!filesystem::Exists(path.c_str())) {
46         LOG_ECMA(INFO) << "ModuleSnapshotInterface::Deserialize: " << path << " is not exists";
47         return;
48     }
49     CString version = OhosVersionInfoTools::GetRomVersion();
50     if (version.empty()) {
51         LOG_ECMA(ERROR) << "ModuleSnapshotInterface::Serialize rom version is empty";
52         return;
53     }
54     ModuleSnapshot::DeserializeData(vm, path, version);
55 }
56 } // namespace panda::ecmascript