Have is<>(T*) function do a null check on the pointer argument
[WebKit-https.git] / Source / WebCore / Modules / websockets / ThreadableWebSocketChannel.cpp
index 029e4ff..a272852 100644 (file)
 #include "ThreadableWebSocketChannel.h"
 
 #include "Document.h"
-#include "PlatformString.h"
 #include "ScriptExecutionContext.h"
 #include "ThreadableWebSocketChannelClientWrapper.h"
 #include "WebSocketChannel.h"
 #include "WebSocketChannelClient.h"
-#include "WorkerContext.h"
+#include "WorkerGlobalScope.h"
 #include "WorkerRunLoop.h"
 #include "WorkerThread.h"
 #include "WorkerThreadableWebSocketChannel.h"
-
 #include <wtf/PassRefPtr.h>
+#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
@@ -56,18 +55,16 @@ PassRefPtr<ThreadableWebSocketChannel> ThreadableWebSocketChannel::create(Script
     ASSERT(context);
     ASSERT(client);
 
-#if ENABLE(WORKERS)
-    if (context->isWorkerContext()) {
-        WorkerContext* workerContext = static_cast<WorkerContext*>(context);
-        WorkerRunLoop& runLoop = workerContext->thread()->runLoop();
-        String mode = webSocketChannelMode;
-        mode.append(String::number(runLoop.createUniqueId()));
-        return WorkerThreadableWebSocketChannel::create(workerContext, client, mode);
+    if (is<WorkerGlobalScope>(*context)) {
+        WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(*context);
+        WorkerRunLoop& runLoop = workerGlobalScope.thread().runLoop();
+        StringBuilder mode;
+        mode.appendLiteral(webSocketChannelMode);
+        mode.appendNumber(runLoop.createUniqueId());
+        return WorkerThreadableWebSocketChannel::create(&workerGlobalScope, client, mode.toString());
     }
-#endif // ENABLE(WORKERS)
 
-    ASSERT(context->isDocument());
-    return WebSocketChannel::create(static_cast<Document*>(context), client);
+    return WebSocketChannel::create(downcast<Document>(context), client);
 }
 
 } // namespace WebCore