Commit 8e3eabe9 authored by yhirano@chromium.org's avatar yhirano@chromium.org

Stop calling [de]ref in ScriptPromiseResolverWithContext destructor.

The ScriptPromiseResolverWithContext destructor is checking if it is misused,
but the current code calls ref() and deref(), which are  invalid in the destructor.
This CL replaces the implementation with a simple assertion.

BUG=386479

Review URL: https://codereview.chromium.org/344733004

git-svn-id: svn://svn.chromium.org/blink/trunk@176518 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ae8e13b1
......@@ -16,20 +16,14 @@ ScriptPromiseResolverWithContext::ScriptPromiseResolverWithContext(ScriptState*
, m_mode(Default)
, m_timer(this, &ScriptPromiseResolverWithContext::onTimerFired)
, m_resolver(ScriptPromiseResolver::create(m_scriptState.get()))
#if ASSERTION_ENABLED
, m_isPromiseCalled(false)
#endif
{
if (executionContext()->activeDOMObjectsAreStopped())
m_state = ResolvedOrRejected;
}
ScriptPromiseResolverWithContext::~ScriptPromiseResolverWithContext()
{
if (m_state != ResolvedOrRejected) {
ScriptState::Scope scope(m_scriptState.get());
reject(v8::Exception::Error(v8::String::NewFromUtf8(m_scriptState->isolate(),
"ScriptPromiseResolverWithContext is destructed without resolve / reject")));
}
}
void ScriptPromiseResolverWithContext::suspend()
{
m_timer.stop();
......@@ -92,7 +86,7 @@ void ScriptPromiseResolverWithContext::clear()
m_resolver.clear();
m_value.clear();
if (m_mode == KeepAliveWhilePending) {
// |ref| was called in the constructor.
// |ref| was called in |keepAliveWhilePending|.
deref();
}
// |this| may be deleted here, but it is safe to check |state| because
......
......@@ -38,7 +38,14 @@ public:
return resolver.release();
}
virtual ~ScriptPromiseResolverWithContext();
virtual ~ScriptPromiseResolverWithContext()
{
// This assertion fails if:
// - promise() is called at least once and
// - this resolver is destructed before it is resolved, rejected or
// the associated ExecutionContext is stopped.
ASSERT(m_state == ResolvedOrRejected || !m_isPromiseCalled);
}
// Anything that can be passed to toV8Value can be passed to this function.
template <typename T>
......@@ -60,6 +67,9 @@ public:
// reject is called.
ScriptPromise promise()
{
#if ASSERT_ENABLED
m_isPromiseCalled = true;
#endif
return m_resolver ? m_resolver->promise() : ScriptPromise();
}
......@@ -124,6 +134,10 @@ private:
Timer<ScriptPromiseResolverWithContext> m_timer;
RefPtr<ScriptPromiseResolver> m_resolver;
ScopedPersistent<v8::Value> m_value;
#if ASSERT_ENABLED
// True if promise() is called.
bool m_isPromiseCalled;
#endif
};
} // namespace WebCore
......
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