Ver Fonte

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.
Andrew Kaster há 1 ano atrás
pai
commit
82ec1ea75e
1 ficheiros alterados com 10 adições e 3 exclusões
  1. 10 3
      Userland/Libraries/LibJS/Runtime/VM.h

+ 10 - 3
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;
     }