diff --git a/RichPreviewer.cpp b/RichPreviewer.cpp index 88afe0b..5dedc85 100644 --- a/RichPreviewer.cpp +++ b/RichPreviewer.cpp @@ -180,5 +180,6 @@ int main(int argc, char* argv[]) std::thread commandThead(ProcessCommand); commandThead.detach(); InitJsApp(); + this_thread::sleep_for(chrono::milliseconds(500)); return 0; } diff --git a/ThinPreviewer.cpp b/ThinPreviewer.cpp index 557d37d..d2116d7 100644 --- a/ThinPreviewer.cpp +++ b/ThinPreviewer.cpp @@ -190,5 +190,6 @@ int main(int argc, char* argv[]) this_thread::sleep_for(chrono::milliseconds(1)); } JsAppImpl::GetInstance().Stop(); + this_thread::sleep_for(chrono::milliseconds(500)); return 0; } diff --git a/automock/mock-generate/src/generate/generateClassDeclaration.ts b/automock/mock-generate/src/generate/generateClassDeclaration.ts index d13851b..344608c 100644 --- a/automock/mock-generate/src/generate/generateClassDeclaration.ts +++ b/automock/mock-generate/src/generate/generateClassDeclaration.ts @@ -54,6 +54,10 @@ export function generateClassDeclaration(rootName: string, classEntity: ClassEnt isExtend = true; classBody += `${value.clauseToken} `; value.types.forEach((val, index) => { + const moduleName = firstCharacterToUppercase(rootName); + if (classEntity.exportModifiers.includes(SyntaxKind.ExportKeyword) && rootName !== '') { + val = `mock${moduleName}().${val}`; + } if (index !== value.types.length - 1) { classBody += `${val},`; } else { diff --git a/jsapp/lite/JsAppImpl.cpp b/jsapp/lite/JsAppImpl.cpp index e565992..f2accc8 100644 --- a/jsapp/lite/JsAppImpl.cpp +++ b/jsapp/lite/JsAppImpl.cpp @@ -126,14 +126,9 @@ JsAppImpl& JsAppImpl::GetInstance() void JsAppImpl::Start() { - if (jsThread != nullptr) { - delete jsThread; - jsThread = nullptr; - } - isFinished = false; isInterrupt = false; - jsThread = new thread(&JsAppImpl::ThreadCallBack, &JsAppImpl::GetInstance()); + jsThread = std::make_unique(&JsAppImpl::ThreadCallBack, &JsAppImpl::GetInstance()); if (jsThread == nullptr) { ELOG("JsApp::Start jsThread memory allocation failed"); } diff --git a/jsapp/lite/JsAppImpl.h b/jsapp/lite/JsAppImpl.h index b016cb0..79bb6f3 100644 --- a/jsapp/lite/JsAppImpl.h +++ b/jsapp/lite/JsAppImpl.h @@ -45,7 +45,7 @@ private: std::unique_ptr deviceCheckTimer; std::unique_ptr jsCheckTimer; std::unique_ptr jsAbility; - std::thread* jsThread; + std::unique_ptr jsThread; void ThreadCallBack(); void InitTimer(); diff --git a/util/WebSocketServer.cpp b/util/WebSocketServer.cpp index c958726..b09dea9 100644 --- a/util/WebSocketServer.cpp +++ b/util/WebSocketServer.cpp @@ -118,11 +118,8 @@ void WebSocketServer::StartWebsocketListening() void WebSocketServer::Run() { - if (serverThread != nullptr) { - delete serverThread; - serverThread = nullptr; - } - serverThread = new std::thread(&WebSocketServer::StartWebsocketListening, &WebSocketServer::GetInstance()); + serverThread = std::make_unique(&WebSocketServer::StartWebsocketListening, + &WebSocketServer::GetInstance()); if (serverThread == nullptr) { ELOG("WebSocketServer::Start serverThread memory allocation failed"); } diff --git a/util/WebSocketServer.h b/util/WebSocketServer.h index 340275c..53bc41a 100644 --- a/util/WebSocketServer.h +++ b/util/WebSocketServer.h @@ -41,7 +41,7 @@ private: WebSocketServer(); virtual ~WebSocketServer(); static void sigint_handler(int sig); - std::thread* serverThread; + std::unique_ptr serverThread; int serverPort; const char* serverHostname = "127.0.0.1"; int websocketMaxConn = 1024; diff --git a/util/unix/CrashHandler.cpp b/util/unix/CrashHandler.cpp index fe9e025..2099a6b 100644 --- a/util/unix/CrashHandler.cpp +++ b/util/unix/CrashHandler.cpp @@ -26,6 +26,9 @@ using namespace std; +static void *oldBacetrace[10] = { nullptr }; +static size_t oldSize = 0; + void CrashHandler::InitExceptionHandler() { if (signal(SIGSEGV, ApplicationCrashHandler) == SIG_ERR) { @@ -36,7 +39,23 @@ void CrashHandler::InitExceptionHandler() void CrashHandler::ApplicationCrashHandler(int signal) { + // get void*'s for all entries on the stack const uint32_t MAX_STACK_SIZE = 128; + int len = 10; + void *array[len]; + size_t size = backtrace(array, MAX_STACK_SIZE); + bool isSame = true; + if (oldSize == size) { + for (size_t i = 0; i < size; i++) { + if (oldBacetrace[i] != array[i]) { + isSame = false; + } + } + } + if (isSame) { + return; + } + // print crash log head int8_t crashBeginLog[] = "[JsEngine Crash]Engine Crash Info Begin.\n"; write(STDERR_FILENO, crashBeginLog, sizeof(crashBeginLog) - 1); int8_t stackIntLog[PublicMethods::MAX_ITOA_BIT] = {0}; @@ -44,13 +63,12 @@ void CrashHandler::ApplicationCrashHandler(int signal) int8_t signalLog[] = "[JsEngine Crash]Error: signal : 0x"; write(STDERR_FILENO, signalLog, sizeof(signalLog) - 1); write(STDERR_FILENO, stackIntLog, itoaLength); - - // get void*'s for all entries on the stack - void *array[10]; - size_t size = backtrace(array, MAX_STACK_SIZE); // print out all the frames to stdout backtrace_symbols_fd(array, size, STDERR_FILENO); - + std::fill(oldBacetrace, oldBacetrace + len, nullptr); + std::copy(array, array + len, oldBacetrace); + oldSize = size; + // print crash log end int8_t crashEndLog[] = "\n[JsEngine Crash]Engine Crash Info End.\n"; write(STDERR_FILENO, crashEndLog, sizeof(crashEndLog) - 1); -} +} \ No newline at end of file