Diff
Modified: trunk/Source/WebCore/ChangeLog (164181 => 164182)
--- trunk/Source/WebCore/ChangeLog 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/ChangeLog 2014-02-16 00:26:53 UTC (rev 164182)
@@ -1,3 +1,13 @@
+2014-02-15 Andreas Kling <[email protected]>
+
+ Add checked casts for ScriptExecutionContext.
+ <https://webkit.org/b/128874>
+
+ Generate casting helpers for casting from ScriptExecutionContext to
+ Document and WorkerGlobalScope. Apply heartily.
+
+ Reviewed by Antti Koivisto.
+
2014-02-15 Alexey Proskuryakov <[email protected]>
[Mac] All WebKit clients should encrypt WebCrypto keys automatically
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp (164181 => 164182)
--- trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -84,8 +84,7 @@
Document* document = toDocument(context);
return document->page()->group().groupSettings().indexedDBDatabasePath();
}
- WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(context);
- const GroupSettings* groupSettings = workerGlobalScope->groupSettings();
+ const GroupSettings* groupSettings = toWorkerGlobalScope(context)->groupSettings();
if (groupSettings)
return groupSettings->indexedDBDatabasePath();
return String();
Modified: trunk/Source/WebCore/Modules/indexeddb/WorkerGlobalScopeIndexedDatabase.cpp (164181 => 164182)
--- trunk/Source/WebCore/Modules/indexeddb/WorkerGlobalScopeIndexedDatabase.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/Modules/indexeddb/WorkerGlobalScopeIndexedDatabase.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -57,8 +57,7 @@
WorkerGlobalScopeIndexedDatabase* supplement = static_cast<WorkerGlobalScopeIndexedDatabase*>(Supplement<ScriptExecutionContext>::from(context, supplementName()));
if (!supplement) {
String databaseDirectoryIdentifier;
- WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(context);
- const GroupSettings* groupSettings = workerGlobalScope->groupSettings();
+ const GroupSettings* groupSettings = toWorkerGlobalScope(context)->groupSettings();
if (groupSettings)
databaseDirectoryIdentifier = groupSettings->indexedDBDatabasePath();
Modified: trunk/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp (164181 => 164182)
--- trunk/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -56,7 +56,7 @@
ASSERT(client);
if (context->isWorkerGlobalScope()) {
- WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(context);
+ WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
WorkerRunLoop& runLoop = workerGlobalScope->thread().runLoop();
String mode = webSocketChannelMode;
mode.append(String::number(runLoop.createUniqueId()));
Modified: trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp (164181 => 164182)
--- trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -120,7 +120,7 @@
return toJSDOMGlobalObject(toDocument(scriptExecutionContext), exec);
if (scriptExecutionContext->isWorkerGlobalScope())
- return static_cast<WorkerGlobalScope*>(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
+ return toWorkerGlobalScope(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
ASSERT_NOT_REACHED();
return 0;
@@ -137,7 +137,7 @@
return toJSDOMGlobalObject(toDocument(scriptExecutionContext), world);
if (scriptExecutionContext->isWorkerGlobalScope())
- return static_cast<WorkerGlobalScope*>(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
+ return toWorkerGlobalScope(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
ASSERT_NOT_REACHED();
return 0;
Modified: trunk/Source/WebCore/bindings/js/JSEventListener.cpp (164181 => 164182)
--- trunk/Source/WebCore/bindings/js/JSEventListener.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/bindings/js/JSEventListener.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -140,7 +140,7 @@
if (scriptExecutionContext->isWorkerGlobalScope()) {
bool terminatorCausedException = (exec->hadException() && isTerminatedExecutionException(exec->exception()));
if (terminatorCausedException || vm.watchdog.didFire())
- static_cast<WorkerGlobalScope*>(scriptExecutionContext)->script()->forbidExecution();
+ toWorkerGlobalScope(scriptExecutionContext)->script()->forbidExecution();
}
if (exec->hadException()) {
Modified: trunk/Source/WebCore/bindings/js/ScheduledAction.cpp (164181 => 164182)
--- trunk/Source/WebCore/bindings/js/ScheduledAction.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/bindings/js/ScheduledAction.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -76,10 +76,8 @@
{
if (context->isDocument())
execute(toDocument(context));
- else {
- ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerGlobalScope());
- execute(static_cast<WorkerGlobalScope*>(context));
- }
+ else
+ execute(toWorkerGlobalScope(context));
}
void ScheduledAction::executeFunctionInContext(JSGlobalObject* globalObject, JSValue thisValue, ScriptExecutionContext* context)
Modified: trunk/Source/WebCore/dom/Document.h (164181 => 164182)
--- trunk/Source/WebCore/dom/Document.h 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/dom/Document.h 2014-02-16 00:26:53 UTC (rev 164182)
@@ -1705,30 +1705,8 @@
Element* eventTargetElementForDocument(Document*);
-inline Document& toDocument(ScriptExecutionContext& scriptExecutionContext)
-{
- ASSERT_WITH_SECURITY_IMPLICATION(scriptExecutionContext.isDocument());
- return static_cast<Document&>(scriptExecutionContext);
-}
+SCRIPT_EXECUTION_CONTEXT_TYPE_CASTS(Document)
-inline const Document& toDocument(const ScriptExecutionContext& scriptExecutionContext)
-{
- ASSERT_WITH_SECURITY_IMPLICATION(scriptExecutionContext.isDocument());
- return static_cast<const Document&>(scriptExecutionContext);
-}
-
-inline Document* toDocument(ScriptExecutionContext* scriptExecutionContext)
-{
- ASSERT_WITH_SECURITY_IMPLICATION(!scriptExecutionContext || scriptExecutionContext->isDocument());
- return static_cast<Document*>(scriptExecutionContext);
-}
-
-inline const Document* toDocument(const ScriptExecutionContext* scriptExecutionContext)
-{
- ASSERT_WITH_SECURITY_IMPLICATION(!scriptExecutionContext || scriptExecutionContext->isDocument());
- return static_cast<const Document*>(scriptExecutionContext);
-}
-
inline bool isDocument(const Node& node) { return node.isDocumentNode(); }
void isDocument(const Document&); // Catch unnecessary runtime check of type known at compile time.
Modified: trunk/Source/WebCore/dom/MessagePort.cpp (164181 => 164182)
--- trunk/Source/WebCore/dom/MessagePort.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/dom/MessagePort.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -157,7 +157,7 @@
while (m_entangledChannel && m_entangledChannel->tryGetMessageFromRemote(message, channels)) {
// close() in Worker onmessage handler should prevent next message from dispatching.
- if (m_scriptExecutionContext->isWorkerGlobalScope() && static_cast<WorkerGlobalScope*>(m_scriptExecutionContext)->isClosing())
+ if (m_scriptExecutionContext->isWorkerGlobalScope() && toWorkerGlobalScope(m_scriptExecutionContext)->isClosing())
return;
std::unique_ptr<MessagePortArray> ports = MessagePort::entanglePorts(*m_scriptExecutionContext, std::move(channels));
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (164181 => 164182)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -146,7 +146,7 @@
{
ASSERT(port);
ASSERT((isDocument() && isMainThread())
- || (isWorkerGlobalScope() && currentThread() == static_cast<WorkerGlobalScope*>(this)->thread().threadID()));
+ || (isWorkerGlobalScope() && currentThread() == toWorkerGlobalScope(this)->thread().threadID()));
m_messagePorts.add(port);
}
@@ -155,7 +155,7 @@
{
ASSERT(port);
ASSERT((isDocument() && isMainThread())
- || (isWorkerGlobalScope() && currentThread() == static_cast<WorkerGlobalScope*>(this)->thread().threadID()));
+ || (isWorkerGlobalScope() && currentThread() == toWorkerGlobalScope(this)->thread().threadID()));
m_messagePorts.remove(port);
}
@@ -411,7 +411,7 @@
return JSDOMWindow::commonVM();
if (isWorkerGlobalScope())
- return static_cast<WorkerGlobalScope*>(this)->script()->vm();
+ return toWorkerGlobalScope(this)->script()->vm();
ASSERT_NOT_REACHED();
return 0;
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (164181 => 164182)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.h 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h 2014-02-16 00:26:53 UTC (rev 164182)
@@ -223,6 +223,9 @@
#endif
};
+#define SCRIPT_EXECUTION_CONTEXT_TYPE_CASTS(ToValueTypeName) \
+ TYPE_CASTS_BASE(ToValueTypeName, ScriptExecutionContext, context, context->is##ToValueTypeName(), context.is##ToValueTypeName())
+
} // namespace WebCore
#endif // ScriptExecutionContext_h
Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (164181 => 164182)
--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -1177,7 +1177,7 @@
InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForNonDocumentContext(ScriptExecutionContext* context)
{
if (context->isWorkerGlobalScope())
- return instrumentationForWorkerGlobalScope(static_cast<WorkerGlobalScope*>(context));
+ return instrumentationForWorkerGlobalScope(toWorkerGlobalScope(context));
return nullptr;
}
Modified: trunk/Source/WebCore/loader/ThreadableLoader.cpp (164181 => 164182)
--- trunk/Source/WebCore/loader/ThreadableLoader.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/loader/ThreadableLoader.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -57,7 +57,7 @@
ASSERT(context);
if (context->isWorkerGlobalScope())
- return WorkerThreadableLoader::create(static_cast<WorkerGlobalScope*>(context), client, WorkerRunLoop::defaultMode(), request, options);
+ return WorkerThreadableLoader::create(toWorkerGlobalScope(context), client, WorkerRunLoop::defaultMode(), request, options);
return DocumentThreadableLoader::create(toDocument(*context), *client, request, options);
}
@@ -67,7 +67,7 @@
ASSERT(context);
if (context->isWorkerGlobalScope()) {
- WorkerThreadableLoader::loadResourceSynchronously(static_cast<WorkerGlobalScope*>(context), request, client, options);
+ WorkerThreadableLoader::loadResourceSynchronously(toWorkerGlobalScope(context), request, client, options);
return;
}
Modified: trunk/Source/WebCore/loader/cache/MemoryCache.cpp (164181 => 164182)
--- trunk/Source/WebCore/loader/cache/MemoryCache.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -816,8 +816,7 @@
void MemoryCache::removeRequestFromCache(ScriptExecutionContext* context, const ResourceRequest& request)
{
if (context->isWorkerGlobalScope()) {
- WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(context);
- workerGlobalScope->thread().workerLoaderProxy().postTaskToLoader(createCallbackTask(&crossThreadRemoveRequestFromCache, request));
+ toWorkerGlobalScope(context)->thread().workerLoaderProxy().postTaskToLoader(createCallbackTask(&crossThreadRemoveRequestFromCache, request));
return;
}
Modified: trunk/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp (164181 => 164182)
--- trunk/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -270,7 +270,7 @@
RefPtr<MessagePort> port = MessagePort::create(*scriptContext);
port->entangle(std::move(m_channel));
ASSERT_WITH_SECURITY_IMPLICATION(scriptContext->isWorkerGlobalScope());
- WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(scriptContext);
+ WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(scriptContext);
// Since close() stops the thread event loop, this should not ever get called while closing.
ASSERT(!workerGlobalScope->isClosing());
ASSERT_WITH_SECURITY_IMPLICATION(workerGlobalScope->isSharedWorkerGlobalScope());
Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (164181 => 164182)
--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -73,10 +73,8 @@
virtual void performTask(ScriptExecutionContext *context)
{
- ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerGlobalScope());
- WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(context);
// Notify parent that this context is closed. Parent is responsible for calling WorkerThread::stop().
- workerGlobalScope->thread().workerReportingProxy().workerGlobalScopeClosed();
+ toWorkerGlobalScope(context)->thread().workerReportingProxy().workerGlobalScopeClosed();
}
virtual bool isCleanupTask() const { return true; }
Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.h (164181 => 164182)
--- trunk/Source/WebCore/workers/WorkerGlobalScope.h 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.h 2014-02-16 00:26:53 UTC (rev 164182)
@@ -182,6 +182,8 @@
RefPtr<SecurityOrigin> m_topOrigin;
};
+SCRIPT_EXECUTION_CONTEXT_TYPE_CASTS(WorkerGlobalScope)
+
} // namespace WebCore
#endif // WorkerGlobalScope_h
Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp (164181 => 164182)
--- trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -259,8 +259,7 @@
virtual void performTask(ScriptExecutionContext *context)
{
AtomicString eventName = m_isOnLine ? eventNames().onlineEvent : eventNames().offlineEvent;
- WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(context);
- workerGlobalScope->dispatchEvent(Event::create(eventName, false, false));
+ toWorkerGlobalScope(context)->dispatchEvent(Event::create(eventName, false, false));
}
bool m_isOnLine;
@@ -285,14 +284,14 @@
{
ASSERT(m_workerObject);
ASSERT((m_scriptExecutionContext->isDocument() && isMainThread())
- || (m_scriptExecutionContext->isWorkerGlobalScope() && currentThread() == static_cast<WorkerGlobalScope*>(m_scriptExecutionContext.get())->thread().threadID()));
+ || (m_scriptExecutionContext->isWorkerGlobalScope() && currentThread() == toWorkerGlobalScope(*m_scriptExecutionContext).thread().threadID()));
}
WorkerMessagingProxy::~WorkerMessagingProxy()
{
ASSERT(!m_workerObject);
ASSERT((m_scriptExecutionContext->isDocument() && isMainThread())
- || (m_scriptExecutionContext->isWorkerGlobalScope() && currentThread() == static_cast<WorkerGlobalScope*>(m_scriptExecutionContext.get())->thread().threadID()));
+ || (m_scriptExecutionContext->isWorkerGlobalScope() && currentThread() == toWorkerGlobalScope(*m_scriptExecutionContext).thread().threadID()));
}
void WorkerMessagingProxy::startWorkerGlobalScope(const URL& scriptURL, const String& userAgent, const String& sourceCode, WorkerThreadStartMode startMode)
@@ -408,8 +407,7 @@
#if ENABLE(INSPECTOR)
static void connectToWorkerGlobalScopeInspectorTask(ScriptExecutionContext* context, bool)
{
- ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerGlobalScope());
- static_cast<WorkerGlobalScope*>(context)->workerInspectorController().connectFrontend();
+ toWorkerGlobalScope(context)->workerInspectorController().connectFrontend();
}
void WorkerMessagingProxy::connectToInspector(WorkerGlobalScopeProxy::PageInspector* pageInspector)
@@ -423,8 +421,7 @@
static void disconnectFromWorkerGlobalScopeInspectorTask(ScriptExecutionContext* context, bool)
{
- ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerGlobalScope());
- static_cast<WorkerGlobalScope*>(context)->workerInspectorController().disconnectFrontend(Inspector::InspectorDisconnectReason::InspectorDestroyed);
+ toWorkerGlobalScope(context)->workerInspectorController().disconnectFrontend(Inspector::InspectorDisconnectReason::InspectorDestroyed);
}
void WorkerMessagingProxy::disconnectFromInspector()
@@ -437,8 +434,7 @@
static void dispatchOnInspectorBackendTask(ScriptExecutionContext* context, const String& message)
{
- ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerGlobalScope());
- static_cast<WorkerGlobalScope*>(context)->workerInspectorController().dispatchMessageFromFrontend(message);
+ toWorkerGlobalScope(context)->workerInspectorController().dispatchMessageFromFrontend(message);
}
void WorkerMessagingProxy::sendMessageToInspector(const String& message)
Modified: trunk/Source/WebCore/workers/WorkerRunLoop.cpp (164181 => 164182)
--- trunk/Source/WebCore/workers/WorkerRunLoop.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/workers/WorkerRunLoop.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -214,8 +214,7 @@
void WorkerRunLoop::Task::performTask(const WorkerRunLoop& runLoop, ScriptExecutionContext* context)
{
- WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(context);
- if ((!workerGlobalScope->isClosing() && !runLoop.terminated()) || m_task->isCleanupTask())
+ if ((!toWorkerGlobalScope(context)->isClosing() && !runLoop.terminated()) || m_task->isCleanupTask())
m_task->performTask(context);
}
Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.cpp (164181 => 164182)
--- trunk/Source/WebCore/workers/WorkerScriptLoader.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -70,7 +70,7 @@
options.crossOriginRequestPolicy = crossOriginRequestPolicy;
options.sendLoadCallbacks = SendCallbacks;
- WorkerThreadableLoader::loadResourceSynchronously(static_cast<WorkerGlobalScope*>(scriptExecutionContext), *request, *this, options);
+ WorkerThreadableLoader::loadResourceSynchronously(toWorkerGlobalScope(scriptExecutionContext), *request, *this, options);
}
void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext* scriptExecutionContext, const URL& url, CrossOriginRequestPolicy crossOriginRequestPolicy, WorkerScriptLoaderClient* client)
Modified: trunk/Source/WebCore/workers/WorkerThread.cpp (164181 => 164182)
--- trunk/Source/WebCore/workers/WorkerThread.cpp 2014-02-15 23:26:21 UTC (rev 164181)
+++ trunk/Source/WebCore/workers/WorkerThread.cpp 2014-02-16 00:26:53 UTC (rev 164182)
@@ -214,10 +214,8 @@
virtual void performTask(ScriptExecutionContext *context)
{
- ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerGlobalScope());
- WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(context);
// It's not safe to call clearScript until all the cleanup tasks posted by functions initiated by WorkerThreadShutdownStartTask have completed.
- workerGlobalScope->clearScript();
+ toWorkerGlobalScope(context)->clearScript();
}
virtual bool isCleanupTask() const { return true; }
@@ -232,8 +230,7 @@
virtual void performTask(ScriptExecutionContext *context)
{
- ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerGlobalScope());
- WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(context);
+ WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
#if ENABLE(SQL_DATABASE)
// FIXME: Should we stop the databases as part of stopActiveDOMObjects() below?