From eae3427b58d9b555896cabbe0c34642d137e5344 Mon Sep 17 00:00:00 2001 From: cybran Date: Tue, 4 Apr 2023 19:00:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=B8=A6=E6=9C=89=20shebang=20=E7=9A=84=20JS=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deps/miniv8/src/MiniV8Api.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/deps/miniv8/src/MiniV8Api.cpp b/deps/miniv8/src/MiniV8Api.cpp index 8bfff227..d887a102 100644 --- a/deps/miniv8/src/MiniV8Api.cpp +++ b/deps/miniv8/src/MiniV8Api.cpp @@ -4928,6 +4928,19 @@ void readFile(const wchar_t* path, std::vector* buffer) b = b; } +static void removeShebang(std::string& str) +{ + if (str.length() >= 2 && str[0] == '#' && str[1] == '!') { + size_t pos = str.find_first_of('\n'); + if (pos != std::string::npos) { + str.erase(0, pos + 1); + } + else { + str.clear(); + } + } +} + static std::string getHookedSrc(const std::string& srcName, miniv8::V8String* sourceStr) { std::vector buffer; @@ -4940,7 +4953,9 @@ static std::string getHookedSrc(const std::string& srcName, miniv8::V8String* so buffer.push_back(0); return buffer.data(); } - return sourceStr->getStr(); + std::string str = sourceStr->getStr(); + removeShebang(str); + return str; } // Òª¿¼ÂÇv8::ScriptCompiler::CreateCodeCacheForFunction»á±àÒëv8::Function -- Gitee