Commit 6ae3c143 authored by haraken's avatar haraken Committed by Commit bot

Remove ActiveDOMCallback

ActiveDOMCallback is just checking if the associated ExecutionContext
is suspended or detached. We can do the check using m_scriptState->getExecutionContext().
Then we can remove ActiveDOMCallback.

BUG=610176

Review-Url: https://codereview.chromium.org/2605683002
Cr-Commit-Position: refs/heads/master@{#440832}
parent 906d30e0
......@@ -30,8 +30,6 @@ bindings_core_v8_files =
"core/v8/custom/V8PromiseRejectionEventCustom.cpp",
"core/v8/custom/V8WindowCustom.cpp",
"core/v8/custom/V8XMLHttpRequestCustom.cpp",
"core/v8/ActiveDOMCallback.cpp",
"core/v8/ActiveDOMCallback.h",
"core/v8/ActiveScriptWrappable.cpp",
"core/v8/ActiveScriptWrappable.h",
"core/v8/ArrayValue.cpp",
......
/*
* Copyright (C) 2010. 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "bindings/core/v8/ActiveDOMCallback.h"
#include "core/dom/ExecutionContext.h"
#include "core/dom/SuspendableObject.h"
#include "core/workers/WorkerGlobalScope.h"
namespace blink {
ActiveDOMCallback::ActiveDOMCallback(ExecutionContext* context)
: m_context(context) {}
ActiveDOMCallback::~ActiveDOMCallback() {}
bool ActiveDOMCallback::canInvokeCallback() const {
return !m_context->isContextSuspended() && !m_context->isContextDestroyed();
}
DEFINE_TRACE(ActiveDOMCallback) {
visitor->trace(m_context);
}
} // namespace blink
/*
* Copyright (C) 2010, 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ActiveDOMCallback_h
#define ActiveDOMCallback_h
#include "core/CoreExport.h"
#include "platform/heap/Handle.h"
namespace blink {
class ExecutionContext;
// A base class that prevents binding callbacks from executing when
// ContextLifecycleObservers are stopped or suspended, and is used by the
// generated callback v8 bindings code to avoid erroneously CRASH()'ing
// after script execution on a worker has been scheduled to terminate.
//
// Should only be created, used, and destroyed on the script execution
// context thread.
class CORE_EXPORT ActiveDOMCallback : public GarbageCollectedMixin {
public:
explicit ActiveDOMCallback(ExecutionContext*);
virtual ~ActiveDOMCallback();
bool canInvokeCallback() const;
DECLARE_TRACE();
private:
Member<ExecutionContext> m_context;
};
} // namespace blink
#endif // ActiveDOMCallback_h
......@@ -17,9 +17,7 @@ V8IntersectionObserverCallback::V8IntersectionObserverCallback(
v8::Local<v8::Function> callback,
v8::Local<v8::Object> owner,
ScriptState* scriptState)
: ActiveDOMCallback(scriptState->getExecutionContext()),
m_callback(scriptState->isolate(), callback),
m_scriptState(scriptState) {
: m_callback(scriptState->isolate(), callback), m_scriptState(scriptState) {
V8PrivateProperty::getIntersectionObserverCallback(scriptState->isolate())
.set(scriptState->context(), owner, callback);
m_callback.setPhantom();
......@@ -30,9 +28,10 @@ V8IntersectionObserverCallback::~V8IntersectionObserverCallback() {}
void V8IntersectionObserverCallback::handleEvent(
const HeapVector<Member<IntersectionObserverEntry>>& entries,
IntersectionObserver& observer) {
if (!canInvokeCallback())
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return;
if (!m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
......@@ -62,7 +61,6 @@ void V8IntersectionObserverCallback::handleEvent(
DEFINE_TRACE(V8IntersectionObserverCallback) {
IntersectionObserverCallback::trace(visitor);
ActiveDOMCallback::trace(visitor);
}
} // namespace blink
......@@ -5,7 +5,6 @@
#ifndef V8IntersectionObserverCallback_h
#define V8IntersectionObserverCallback_h
#include "bindings/core/v8/ActiveDOMCallback.h"
#include "bindings/core/v8/DOMWrapperWorld.h"
#include "bindings/core/v8/ScopedPersistent.h"
#include "core/CoreExport.h"
......@@ -14,10 +13,7 @@
namespace blink {
class V8IntersectionObserverCallback final
: public IntersectionObserverCallback,
public ActiveDOMCallback {
USING_GARBAGE_COLLECTED_MIXIN(V8IntersectionObserverCallback);
: public IntersectionObserverCallback {
public:
CORE_EXPORT V8IntersectionObserverCallback(v8::Local<v8::Function>,
v8::Local<v8::Object>,
......
......@@ -39,9 +39,7 @@ namespace blink {
V8MutationCallback::V8MutationCallback(v8::Local<v8::Function> callback,
v8::Local<v8::Object> owner,
ScriptState* scriptState)
: ActiveDOMCallback(scriptState->getExecutionContext()),
m_callback(scriptState->isolate(), callback),
m_scriptState(scriptState) {
: m_callback(scriptState->isolate(), callback), m_scriptState(scriptState) {
V8PrivateProperty::getMutationObserverCallback(scriptState->isolate())
.set(scriptState->context(), owner, callback);
m_callback.setPhantom();
......@@ -52,11 +50,11 @@ V8MutationCallback::~V8MutationCallback() {}
void V8MutationCallback::call(
const HeapVector<Member<MutationRecord>>& mutations,
MutationObserver* observer) {
if (!canInvokeCallback())
return;
v8::Isolate* isolate = m_scriptState->isolate();
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return;
if (!m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
......@@ -85,7 +83,6 @@ void V8MutationCallback::call(
DEFINE_TRACE(V8MutationCallback) {
MutationCallback::trace(visitor);
ActiveDOMCallback::trace(visitor);
}
} // namespace blink
......@@ -26,7 +26,6 @@
#ifndef V8MutationCallback_h
#define V8MutationCallback_h
#include "bindings/core/v8/ActiveDOMCallback.h"
#include "bindings/core/v8/ScopedPersistent.h"
#include "bindings/core/v8/ScriptState.h"
#include "core/dom/MutationCallback.h"
......@@ -37,10 +36,7 @@ namespace blink {
class ExecutionContext;
class V8MutationCallback final : public MutationCallback,
public ActiveDOMCallback {
USING_GARBAGE_COLLECTED_MIXIN(V8MutationCallback);
class V8MutationCallback final : public MutationCallback {
public:
static V8MutationCallback* create(v8::Local<v8::Function> callback,
v8::Local<v8::Object> owner,
......
......@@ -15,11 +15,11 @@ namespace blink {
void V8ResizeObserverCallback::handleEvent(
const HeapVector<Member<ResizeObserverEntry>>& entries,
ResizeObserver* observer) {
if (!canInvokeCallback())
return;
v8::Isolate* isolate = m_scriptState->isolate();
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return;
if (!m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
......
......@@ -40,13 +40,13 @@ namespace blink {
bool V8SQLStatementErrorCallback::handleEvent(SQLTransaction* transaction,
SQLError* error) {
if (!canInvokeCallback())
return true;
v8::Isolate* isolate = m_scriptState->isolate();
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return true;
if (!m_scriptState->contextIsValid())
return true;
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Value> transactionHandle =
......
......@@ -39,7 +39,6 @@ import v8_types
import v8_utilities
CALLBACK_INTERFACE_H_INCLUDES = frozenset([
'bindings/core/v8/ActiveDOMCallback.h',
'bindings/core/v8/DOMWrapperWorld.h',
'bindings/core/v8/ScopedPersistent.h',
])
......
......@@ -10,8 +10,7 @@
namespace blink {
{{v8_class}}::{{v8_class}}(v8::Local<v8::Function> callback, ScriptState* scriptState)
: ActiveDOMCallback(scriptState->getExecutionContext())
, m_scriptState(scriptState) {
: m_scriptState(scriptState) {
m_callback.set(scriptState->isolate(), callback);
}
......@@ -19,19 +18,18 @@ namespace blink {
DEFINE_TRACE({{v8_class}}) {
{{cpp_class}}::trace(visitor);
ActiveDOMCallback::trace(visitor);
}
{% for method in methods if not method.is_custom %}
{{method.cpp_type}} {{v8_class}}::{{method.name}}({{method.argument_declarations | join(', ')}}) {
{% set return_default = 'return true'
if method.idl_type == 'boolean' else 'return' %}{# void #}
if (!canInvokeCallback())
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
{{return_default}};
if (!m_scriptState->contextIsValid())
{{return_default}};
ScriptState::Scope scope(m_scriptState.get());
{% if method.call_with_this_handle %}
v8::Local<v8::Value> thisHandle = thisValue.v8Value();
......
......@@ -10,8 +10,7 @@
namespace blink {
class {{v8_class}} final : public {{cpp_class}}, public ActiveDOMCallback {
USING_GARBAGE_COLLECTED_MIXIN({{v8_class}});
class {{v8_class}} final : public {{cpp_class}} {
public:
static {{v8_class}}* create(v8::Local<v8::Function> callback, ScriptState* scriptState) {
return new {{v8_class}}(callback, scriptState);
......
......@@ -22,8 +22,7 @@
namespace blink {
V8TestCallbackInterface::V8TestCallbackInterface(v8::Local<v8::Function> callback, ScriptState* scriptState)
: ActiveDOMCallback(scriptState->getExecutionContext())
, m_scriptState(scriptState) {
: m_scriptState(scriptState) {
m_callback.set(scriptState->isolate(), callback);
}
......@@ -31,16 +30,15 @@ V8TestCallbackInterface::~V8TestCallbackInterface() {}
DEFINE_TRACE(V8TestCallbackInterface) {
TestCallbackInterface::trace(visitor);
ActiveDOMCallback::trace(visitor);
}
void V8TestCallbackInterface::voidMethod() {
if (!canInvokeCallback())
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return;
if (!m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Value> *argv = 0;
......@@ -48,12 +46,12 @@ void V8TestCallbackInterface::voidMethod() {
}
bool V8TestCallbackInterface::booleanMethod() {
if (!canInvokeCallback())
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return true;
if (!m_scriptState->contextIsValid())
return true;
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Value> *argv = 0;
......@@ -64,12 +62,12 @@ bool V8TestCallbackInterface::booleanMethod() {
}
void V8TestCallbackInterface::voidMethodBooleanArg(bool boolArg) {
if (!canInvokeCallback())
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return;
if (!m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Value> boolArgHandle = v8Boolean(boolArg, m_scriptState->isolate());
v8::Local<v8::Value> argv[] = { boolArgHandle };
......@@ -78,12 +76,12 @@ void V8TestCallbackInterface::voidMethodBooleanArg(bool boolArg) {
}
void V8TestCallbackInterface::voidMethodSequenceArg(const HeapVector<Member<TestInterfaceEmpty>>& sequenceArg) {
if (!canInvokeCallback())
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return;
if (!m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Value> sequenceArgHandle = toV8(sequenceArg, m_scriptState->context()->Global(), m_scriptState->isolate());
v8::Local<v8::Value> argv[] = { sequenceArgHandle };
......@@ -92,12 +90,12 @@ void V8TestCallbackInterface::voidMethodSequenceArg(const HeapVector<Member<Test
}
void V8TestCallbackInterface::voidMethodFloatArg(float floatArg) {
if (!canInvokeCallback())
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return;
if (!m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Value> floatArgHandle = v8::Number::New(m_scriptState->isolate(), floatArg);
v8::Local<v8::Value> argv[] = { floatArgHandle };
......@@ -106,12 +104,12 @@ void V8TestCallbackInterface::voidMethodFloatArg(float floatArg) {
}
void V8TestCallbackInterface::voidMethodTestInterfaceEmptyArg(TestInterfaceEmpty* testInterfaceEmptyArg) {
if (!canInvokeCallback())
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return;
if (!m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Value> testInterfaceEmptyArgHandle = toV8(testInterfaceEmptyArg, m_scriptState->context()->Global(), m_scriptState->isolate());
v8::Local<v8::Value> argv[] = { testInterfaceEmptyArgHandle };
......@@ -120,12 +118,12 @@ void V8TestCallbackInterface::voidMethodTestInterfaceEmptyArg(TestInterfaceEmpty
}
void V8TestCallbackInterface::voidMethodTestInterfaceEmptyStringArg(TestInterfaceEmpty* testInterfaceEmptyArg, const String& stringArg) {
if (!canInvokeCallback())
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return;
if (!m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Value> testInterfaceEmptyArgHandle = toV8(testInterfaceEmptyArg, m_scriptState->context()->Global(), m_scriptState->isolate());
v8::Local<v8::Value> stringArgHandle = v8String(m_scriptState->isolate(), stringArg);
......@@ -135,12 +133,12 @@ void V8TestCallbackInterface::voidMethodTestInterfaceEmptyStringArg(TestInterfac
}
void V8TestCallbackInterface::callbackWithThisValueVoidMethodStringArg(ScriptValue thisValue, const String& stringArg) {
if (!canInvokeCallback())
ExecutionContext* executionContext = m_scriptState->getExecutionContext();
if (!executionContext || executionContext->isContextSuspended() ||
executionContext->isContextDestroyed())
return;
if (!m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Value> thisHandle = thisValue.v8Value();
v8::Local<v8::Value> stringArgHandle = v8String(m_scriptState->isolate(), stringArg);
......
......@@ -12,7 +12,6 @@
#ifndef V8TestCallbackInterface_h
#define V8TestCallbackInterface_h
#include "bindings/core/v8/ActiveDOMCallback.h"
#include "bindings/core/v8/DOMWrapperWorld.h"
#include "bindings/core/v8/ScopedPersistent.h"
#include "bindings/tests/idls/core/TestCallbackInterface.h"
......@@ -20,8 +19,7 @@
namespace blink {
class V8TestCallbackInterface final : public TestCallbackInterface, public ActiveDOMCallback {
USING_GARBAGE_COLLECTED_MIXIN(V8TestCallbackInterface);
class V8TestCallbackInterface final : public TestCallbackInterface {
public:
static V8TestCallbackInterface* create(v8::Local<v8::Function> callback, ScriptState* scriptState) {
return new V8TestCallbackInterface(callback, scriptState);
......
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