From da3fa75f802fd61dab2a7647a516f6f07306433c Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Sat, 13 May 2023 15:17:35 +0200 Subject: [PATCH] Revert "client: Bytecode changes" This reverts commit d07cd36177f9d7a50165998df953295bf14f9e85. --- client/src/IImportHandler.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/client/src/IImportHandler.cpp b/client/src/IImportHandler.cpp index 53409328..eed6d5f6 100644 --- a/client/src/IImportHandler.cpp +++ b/client/src/IImportHandler.cpp @@ -296,15 +296,27 @@ v8::MaybeLocal IImportHandler::ResolveBytecode(const std::string& na { v8::Isolate* isolate = v8::Isolate::GetCurrent(); + // Copy source code size + int sourceCodeSize = 0; + memcpy(&sourceCodeSize, buffer + sizeof(bytecodeMagic), sizeof(int)); // Copy bytecode buffer - size_t bytecodeSize = size - sizeof(bytecodeMagic); + size_t bytecodeSize = size - sizeof(bytecodeMagic) - sizeof(int); uint8_t* bytecode = new uint8_t[bytecodeSize]; - memcpy(bytecode, buffer + sizeof(bytecodeMagic), bytecodeSize); + memcpy(bytecode, buffer + sizeof(bytecodeMagic) + sizeof(int), bytecodeSize); v8::ScriptCompiler::CachedData* cachedData = new v8::ScriptCompiler::CachedData(bytecode, bytecodeSize, v8::ScriptCompiler::CachedData::BufferOwned); v8::ScriptOrigin origin(isolate, V8Helpers::JSValue(name), 0, 0, false, -1, v8::Local(), false, false, true, v8::Local()); - v8::ScriptCompiler::Source source{ V8Helpers::JSValue(" "), origin, cachedData }; + // Create source string + std::string sourceString; + sourceString.reserve(sourceCodeSize + 2); + sourceString += "'"; + for(size_t i = 0; i < sourceCodeSize; i++) + { + sourceString += "a"; + } + sourceString += "'"; + v8::ScriptCompiler::Source source{ V8Helpers::JSValue(sourceString), origin, cachedData }; v8::MaybeLocal module = v8::ScriptCompiler::CompileModule(isolate, &source, v8::ScriptCompiler::kConsumeCodeCache); if(cachedData->rejected) {