From f0d1db4d4d28d0d83f597acb09c730f5bb7dce67 Mon Sep 17 00:00:00 2001 From: huanghan18 Date: Wed, 7 May 2025 15:26:59 +0800 Subject: [PATCH] add debug null check, modify initialization order for UserReference Signed-off-by: huanghan18 --- src/inspector/inspector_socket_server.cpp | 6 +++--- src/js_native_api_v8.cpp | 1 + src/jsvm_reference.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/inspector/inspector_socket_server.cpp b/src/inspector/inspector_socket_server.cpp index 82a440c..4ce6dcc 100644 --- a/src/inspector/inspector_socket_server.cpp +++ b/src/inspector/inspector_socket_server.cpp @@ -327,7 +327,7 @@ SocketSession* InspectorSocketServer::Session(int sessionId) void InspectorSocketServer::SessionStarted(int sessionId, const std::string& targetId, const std::string& wsKey) { SocketSession* session = Session(sessionId); - CHECK_NULL(session); + DCHECK(session != nullptr); if (!TargetExists(targetId)) { session->Decline(); return; @@ -361,7 +361,7 @@ void InspectorSocketServer::SessionTerminated(int sessionId) bool InspectorSocketServer::HandleGetRequest(int sessionId, const std::string& hostName, const std::string& path) { SocketSession* session = Session(sessionId); - CHECK_NULL(session); + DCHECK(session != nullptr); InspectorSocket* socket = session->GetWsSocket(); if (!inspectPublishUid.http) { SendHttpNotFound(socket); @@ -553,7 +553,7 @@ void SocketSession::Delegate::OnHttpGet(const std::string& host, const std::stri { if (!server->HandleGetRequest(usessionId, host, path)) { SocketSession* session = Session(); - CHECK_NULL(session); + DCHECK(session != nullptr); session->GetWsSocket()->CancelHandshake(); } } diff --git a/src/js_native_api_v8.cpp b/src/js_native_api_v8.cpp index 7ba4d7c..dacf67d 100644 --- a/src/js_native_api_v8.cpp +++ b/src/js_native_api_v8.cpp @@ -5398,6 +5398,7 @@ JSVM_EXTERN JSVM_Status OH_JSVM_TraceStart(size_t count, } TraceBuffer* ring_buffer = TraceBuffer::CreateTraceBufferRingBuffer(max_chunks, writer); + DCHECK(controller != nullptr); controller->Initialize(ring_buffer); controller->StartTracing(trace_config); return JSVM_OK; diff --git a/src/jsvm_reference.cpp b/src/jsvm_reference.cpp index ad917b2..66e298f 100644 --- a/src/jsvm_reference.cpp +++ b/src/jsvm_reference.cpp @@ -46,7 +46,7 @@ UserReference* UserReference::NewData(JSVM_Env env, v8::Local value, u } UserReference::UserReference(JSVM_Env env, v8::Local value, bool isValue, uint32_t initialRefcount) - : persistent(env->isolate, value), isValue(isValue), env(env), refcount(initialRefcount), + : persistent(env->isolate, value), env(env), refcount(initialRefcount), isValue(isValue), canBeWeak(isValue && CanBeHeldWeakly(value.As())) { if (refcount == 0) { -- Gitee