Commit 1894813c authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

ScriptPromiseResolver: In debug builds, gather the construction stack trace.

This should allow us to determine which resolvers are not being properly
resolved or detached.

Bug: 873980
Change-Id: I44ead90aaf8b963b7380ba70c56c73ae2b7ad7d1
Reviewed-on: https://chromium-review.googlesource.com/c/1344822Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610936}
parent 4957ab99
......@@ -8,6 +8,10 @@
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#if DCHECK_IS_ON()
#include "base/debug/alias.h"
#endif
namespace blink {
ScriptPromiseResolver::ScriptPromiseResolver(ScriptState* script_state)
......@@ -21,6 +25,25 @@ ScriptPromiseResolver::ScriptPromiseResolver(ScriptState* script_state)
}
}
#if DCHECK_IS_ON()
ScriptPromiseResolver::~ScriptPromiseResolver() {
// This is here temporarily to make it easier to track down which promise
// resolvers are being abandoned.
// TODO(crbug.com/873980): Remove this.
base::debug::StackTrace create_stack_trace(create_stack_trace_);
base::debug::Alias(&create_stack_trace);
// This assertion fails if:
// - promise() is called at least once and
// - this resolver is destructed before it is resolved, rejected,
// detached, the V8 isolate is terminated or the associated
// ExecutionContext is stopped.
DCHECK(state_ == kDetached || !is_promise_called_ ||
!GetScriptState()->ContextIsValid() || !GetExecutionContext() ||
GetExecutionContext()->IsContextDestroyed());
}
#endif
void ScriptPromiseResolver::Reject(ExceptionState& exception_state) {
DCHECK(exception_state.HadException());
Reject(exception_state.GetException());
......
......@@ -18,6 +18,10 @@
#include "third_party/blink/renderer/platform/web_task_runner.h"
#include "v8/include/v8.h"
#if DCHECK_IS_ON()
#include "base/debug/stack_trace.h"
#endif
namespace blink {
// This class wraps v8::Promise::Resolver and provides the following
......@@ -49,16 +53,7 @@ class CORE_EXPORT ScriptPromiseResolver
// from the destructor's assert.
EAGERLY_FINALIZE();
~ScriptPromiseResolver() override {
// This assertion fails if:
// - promise() is called at least once and
// - this resolver is destructed before it is resolved, rejected,
// detached, the V8 isolate is terminated or the associated
// ExecutionContext is stopped.
DCHECK(state_ == kDetached || !is_promise_called_ ||
!GetScriptState()->ContextIsValid() || !GetExecutionContext() ||
GetExecutionContext()->IsContextDestroyed());
}
~ScriptPromiseResolver() override;
#endif
// Anything that can be passed to toV8 can be passed to this function.
......@@ -179,6 +174,8 @@ class CORE_EXPORT ScriptPromiseResolver
#if DCHECK_IS_ON()
// True if promise() is called.
bool is_promise_called_ = false;
base::debug::StackTrace create_stack_trace_{8};
#endif
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment