1 /* 2 * Copyright (c) 2021 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_TOOLING_BASE_PT_SCRIPT_H 17 #define ECMASCRIPT_TOOLING_BASE_PT_SCRIPT_H 18 19 #include "base/pt_types.h" 20 21 #include "libpandabase/macros.h" 22 23 namespace panda::ecmascript::tooling { 24 enum class ScriptMatchType : uint8_t { 25 URL, 26 FILE_NAME, 27 HASH, 28 }; 29 30 class PtScript { 31 public: 32 PtScript(ScriptId scriptId, const std::string &fileName, const std::string &url, const std::string &source); 33 ~PtScript() = default; 34 GetScriptId()35 ScriptId GetScriptId() const 36 { 37 return scriptId_; 38 } 39 SetScriptId(ScriptId scriptId)40 void SetScriptId(ScriptId scriptId) 41 { 42 scriptId_ = scriptId; 43 } 44 GetFileName()45 const std::string &GetFileName() const 46 { 47 return fileName_; 48 } 49 SetFileName(const std::string & fileName)50 void SetFileName(const std::string &fileName) 51 { 52 fileName_ = fileName; 53 } 54 GetUrl()55 const std::string &GetUrl() const 56 { 57 return url_; 58 } 59 SetUrl(const std::string & url)60 void SetUrl(const std::string &url) 61 { 62 url_ = url; 63 } 64 GetHash()65 const std::string &GetHash() const 66 { 67 return hash_; 68 } 69 SetHash(const std::string & hash)70 void SetHash(const std::string &hash) 71 { 72 hash_ = hash; 73 } 74 GetScriptSource()75 const std::string &GetScriptSource() const 76 { 77 return scriptSource_; 78 } 79 SetScriptSource(const std::string & scriptSource)80 void SetScriptSource(const std::string &scriptSource) 81 { 82 scriptSource_ = scriptSource; 83 } 84 GetSourceMapUrl()85 const std::string &GetSourceMapUrl() const 86 { 87 return sourceMapUrl_; 88 } 89 SetSourceMapUrl(const std::string & sourceMapUrl)90 void SetSourceMapUrl(const std::string &sourceMapUrl) 91 { 92 sourceMapUrl_ = sourceMapUrl; 93 } 94 GetEndLine()95 int32_t GetEndLine() const 96 { 97 return endLine_; 98 } 99 SetEndLine(int32_t endLine)100 void SetEndLine(int32_t endLine) 101 { 102 endLine_ = endLine; 103 } 104 105 private: 106 NO_COPY_SEMANTIC(PtScript); 107 NO_MOVE_SEMANTIC(PtScript); 108 109 ScriptId scriptId_ {0}; // start from 0, such as "0","1","2"... 110 std::string fileName_ {}; // binary file name, such as xx.bin 111 std::string url_ {}; // source file name, such as xx.js 112 std::string hash_ {}; // js source file hash code 113 std::string scriptSource_ {}; // js source code 114 std::string sourceMapUrl_ {}; // source map url 115 int32_t endLine_ {0}; // total line number of source file 116 }; 117 } // namespace panda::ecmascript::tooling 118 #endif 119