• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 OHOS_ABILITY_JS_ENVIRONMENT_SOURCE_MAP_OPERATOR_H
17 #define OHOS_ABILITY_JS_ENVIRONMENT_SOURCE_MAP_OPERATOR_H
18 #include <memory>
19 #include <set>
20 #include <string>
21 
22 #include "js_env_logger.h"
23 #include "source_map.h"
24 
25 namespace OHOS {
26 namespace JsEnv {
27 class SourceMapOperator {
28 public:
SourceMapOperator(const std::string bundleName,bool isModular)29     SourceMapOperator(const std::string bundleName, bool isModular)
30         : bundleName_(bundleName), isModular_(isModular) {}
31 
32     ~SourceMapOperator() = default;
33 
TranslateBySourceMap(const std::string & stackStr)34     std::string TranslateBySourceMap(const std::string& stackStr)
35     {
36         SourceMap sourceMapObj;
37         std::vector<std::string> hapList;
38         sourceMapObj.GetHapPath(bundleName_, hapList);
39         for (auto &hapInfo : hapList) {
40             if (!hapInfo.empty()) {
41                 sourceMapObj.Init(isModular_, hapInfo);
42             }
43         }
44         return sourceMapObj.TranslateBySourceMap(stackStr);
45     }
46 
TranslateUrlPositionBySourceMap(std::string & url,int & line,int & column)47     bool TranslateUrlPositionBySourceMap(std::string& url, int& line, int& column)
48     {
49         SourceMap sourceMapObj;
50         std::vector<std::string> hapList;
51         sourceMapObj.GetHapPath(bundleName_, hapList);
52         for (auto &hapInfo : hapList) {
53             if (!hapInfo.empty()) {
54                 sourceMapObj.Init(isModular_, hapInfo);
55             }
56         }
57         return sourceMapObj.TranslateUrlPositionBySourceMap(url, line, column);
58     }
59 
60 private:
61     const std::string bundleName_;
62     bool isModular_ = false;
63 };
64 } // namespace JsEnv
65 } // namespace OHOS
66 #endif // OHOS_ABILITY_JS_ENVIRONMENT_SOURCE_MAP_OPERATOR_H
67