From 82ec1ea75e54812b448491a682e7de0f157c50f4 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 18 Dec 2023 17:21:29 -0700 Subject: [PATCH] LibJS: Provide better assertion for empty execution context stack When calling `running_execution_context` from other VM APIs, and the execution context stack is empty, the verification message is inlined from AK::Vector. Add a specific VERIFY to `running_execution_context` to help diagnose this issue better. --- Userland/Libraries/LibJS/Runtime/VM.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 78ec07adf4..f0a217c524 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/Userland/Libraries/LibJS/Runtime/VM.h @@ -114,8 +114,16 @@ public: // https://tc39.es/ecma262/#running-execution-context // At any point in time, there is at most one execution context per agent that is actually executing code. // This is known as the agent's running execution context. - ExecutionContext& running_execution_context() { return *m_execution_context_stack.last(); } - ExecutionContext const& running_execution_context() const { return *m_execution_context_stack.last(); } + ExecutionContext& running_execution_context() + { + VERIFY(!m_execution_context_stack.is_empty()); + return *m_execution_context_stack.last(); + } + ExecutionContext const& running_execution_context() const + { + VERIFY(!m_execution_context_stack.is_empty()); + return *m_execution_context_stack.last(); + } // https://tc39.es/ecma262/#execution-context-stack // The execution context stack is used to track execution contexts. @@ -156,7 +164,6 @@ public: Value this_value() const { - VERIFY(!m_execution_context_stack.is_empty()); return running_execution_context().this_value; }