2009-05-01 Sam Weinig <sam@webkit.org>
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 May 2009 02:33:21 +0000 (02:33 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 May 2009 02:33:21 +0000 (02:33 +0000)
        Reviewed by Oliver Hunt.

        Cleanup workers code a bit.

        * bindings/js/JSWorkerContextBase.cpp:
        (WebCore::toJS):
        * bindings/js/JSWorkerContextBase.h:
        * bindings/js/JSWorkerContextCustom.cpp:
        (WebCore::JSWorkerContext::customGetOwnPropertySlot):
        * workers/WorkerContext.h:
        (WebCore::WorkerContext::toWorkerContext):
        (WebCore::WorkerContext::self):
        (WebCore::WorkerContext::setOnmessage):
        (WebCore::WorkerContext::onmessage):
        * workers/WorkerContext.idl:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@43136 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/bindings/js/JSWorkerContextBase.cpp
WebCore/bindings/js/JSWorkerContextBase.h
WebCore/bindings/js/JSWorkerContextCustom.cpp
WebCore/workers/WorkerContext.h
WebCore/workers/WorkerContext.idl

index 53f88c3..54f711c 100644 (file)
@@ -1,5 +1,23 @@
 2009-05-01  Sam Weinig  <sam@webkit.org>
 
+        Reviewed by Oliver Hunt.
+
+        Cleanup workers code a bit.
+
+        * bindings/js/JSWorkerContextBase.cpp:
+        (WebCore::toJS):
+        * bindings/js/JSWorkerContextBase.h:
+        * bindings/js/JSWorkerContextCustom.cpp:
+        (WebCore::JSWorkerContext::customGetOwnPropertySlot):
+        * workers/WorkerContext.h:
+        (WebCore::WorkerContext::toWorkerContext):
+        (WebCore::WorkerContext::self):
+        (WebCore::WorkerContext::setOnmessage):
+        (WebCore::WorkerContext::onmessage):
+        * workers/WorkerContext.idl:
+
+2009-05-01  Sam Weinig  <sam@webkit.org>
+
         Reviewed by Darin Adler.
 
         A little clean up.
index 668252c..c71f45b 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "JSWorkerContextBase.h"
 
+#include "JSWorkerContext.h"
 #include "WorkerContext.h"
 
 using namespace JSC;
@@ -56,6 +57,16 @@ ScriptExecutionContext* JSWorkerContextBase::scriptExecutionContext() const
     return m_impl.get();
 }
 
+JSValue toJS(ExecState*, WorkerContext* workerContext)
+{
+    if (!workerContext)
+        return jsNull();
+    WorkerScriptController* script = workerContext->script();
+    if (!script)
+        return jsNull();
+    return script->workerContextWrapper();
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WORKERS)
index f266689..dcbc5c3 100644 (file)
@@ -51,6 +51,9 @@ namespace WebCore {
         RefPtr<WorkerContext> m_impl;
     };
 
+    // Returns a JSWorkerContext or jsNull()
+    JSC::JSValue toJS(JSC::ExecState*, WorkerContext*);
+
 } // namespace WebCore
 
 #endif // ENABLE(WORKERS)
index 44676c3..6824914 100644 (file)
@@ -44,14 +44,6 @@ using namespace JSC;
 
 namespace WebCore {
 
-bool JSWorkerContext::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
-{
-    // Look for overrides before looking at any of our own properties.
-    if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot))
-        return true;
-    return false;
-}
-
 void JSWorkerContext::mark()
 {
     Base::mark();
@@ -74,14 +66,12 @@ void JSWorkerContext::mark()
     }
 }
 
-JSValue JSWorkerContext::self(ExecState*) const
-{
-    return JSValue(this);
-}
-
-void JSWorkerContext::setSelf(ExecState* exec, JSValue value)
+bool JSWorkerContext::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
 {
-    putDirect(Identifier(exec, "self"), value);
+    // Look for overrides before looking at any of our own properties.
+    if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot))
+        return true;
+    return false;
 }
 
 JSValue JSWorkerContext::xmlHttpRequest(ExecState* exec) const
index 9db4274..bfddef1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -57,6 +57,8 @@ namespace WebCore {
 
         virtual bool isWorkerContext() const { return true; }
 
+        virtual WorkerContext* toWorkerContext() { return this; }
+
         virtual ScriptExecutionContext* scriptExecutionContext() const;
 
         const KURL& url() const { return m_url; }
@@ -64,11 +66,9 @@ namespace WebCore {
 
         virtual String userAgent(const KURL&) const;
 
-        WorkerLocation* location() const;
-        WorkerNavigator* navigator() const;
-
         WorkerScriptController* script() { return m_script.get(); }
         void clearScript() { return m_script.clear(); }
+
         WorkerThread* thread() { return m_thread; }
 
         bool hasPendingActivity() const;
@@ -78,10 +78,22 @@ namespace WebCore {
         virtual void resourceRetrievedByXMLHttpRequest(unsigned long identifier, const ScriptString& sourceString);
         virtual void scriptImported(unsigned long identifier, const String& sourceString);
 
-        virtual WorkerContext* toWorkerContext() { return this; }
+        virtual void postTask(PassRefPtr<Task>); // Executes the task on context's thread asynchronously.
+
+
+        // WorkerGlobalScope
+        WorkerContext* self() { return this; }
+        WorkerLocation* location() const;
+
+        // WorkerUtils
+        void importScripts(const Vector<String>& urls, const String& callerURL, int callerLine, ExceptionCode&);
+        WorkerNavigator* navigator() const;
+
 
+        // DedicatedWorkerGlobalScope
         void postMessage(const String& message);
-        virtual void postTask(PassRefPtr<Task>); // Executes the task on context's thread asynchronously.
+        void setOnmessage(PassRefPtr<EventListener> eventListener) { m_onmessageListener = eventListener; }
+        EventListener* onmessage() const { return m_onmessageListener.get(); }
 
         // Timers
         int setTimeout(ScheduledAction*, int timeout);
@@ -89,20 +101,16 @@ namespace WebCore {
         int setInterval(ScheduledAction*, int timeout);
         void clearInterval(int timeoutId);
 
-        void dispatchMessage(const String&);
-
+        // EventTarget
         virtual void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
         virtual void removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
         virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&);
 
-        void setOnmessage(PassRefPtr<EventListener> eventListener) { m_onmessageListener = eventListener; }
-        EventListener* onmessage() const { return m_onmessageListener.get(); }
-
         typedef Vector<RefPtr<EventListener> > ListenerVector;
         typedef HashMap<AtomicString, ListenerVector> EventListenersMap;
         EventListenersMap& eventListeners() { return m_eventListeners; }
 
-        void importScripts(const Vector<String>& urls, const String& callerURL, int callerLine, ExceptionCode&);
+        void dispatchMessage(const String&);
 
         // These methods are used for GC marking. See JSWorkerContext::mark() in
         // JSWorkerContextCustom.cpp.
@@ -113,13 +121,13 @@ namespace WebCore {
         using RefCounted<WorkerContext>::deref;
 
     private:
+        WorkerContext(const KURL&, const String&, WorkerThread*);
+
         virtual void refScriptExecutionContext() { ref(); }
         virtual void derefScriptExecutionContext() { deref(); }
         virtual void refEventTarget() { ref(); }
         virtual void derefEventTarget() { deref(); }
 
-        WorkerContext(const KURL&, const String&, WorkerThread*);
-
         virtual const KURL& virtualURL() const;
         virtual KURL virtualCompleteURL(const String&) const;
 
index f6ec3b4..855abef 100644 (file)
@@ -34,31 +34,35 @@ module threads {
         LegacyParent=JSWorkerContextBase,
         NoStaticTables
     ] WorkerContext {
-#if defined(LANGUAGE_JAVASCRIPT)
-        attribute [Custom] WorkerContext self;
-#endif
 
-        attribute EventListener onmessage;
-        void postMessage(in DOMString message);
-        [Custom] void importScripts(/* urls */);
+        // WorkerGlobalScope
+                 attribute [Replaceable] WorkerContext self;
+                 attribute [Replaceable] WorkerLocation location;
+        // void close();
+        //         attribute EventListener onclose;
+        //         attribute EventListener onerror;
 
-        attribute [Replaceable] WorkerLocation location;
-        attribute [Replaceable] WorkerNavigator navigator;
-        
-        attribute MessageEventConstructor MessageEvent;
-        attribute WorkerLocationConstructor WorkerLocation;
+        // WorkerUtils
+        [Custom] void importScripts(/*[Variadic] in DOMString urls */);
+                 attribute [Replaceable] WorkerNavigator navigator;
+        // Database openDatabase(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize);
+        // DatabaseSync openDatabaseSync(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize);
+
+
+        // DedicatedWorkerGlobalScope
+        void postMessage(in DOMString message);
+                 attribute EventListener onmessage;
 
-        attribute [JSCCustomGetter] XMLHttpRequestConstructor XMLHttpRequest;
 
         // Timers
         [Custom] long setTimeout(in TimeoutHandler handler, in long timeout);
         // [Custom] long setTimeout(in DOMString code, in long timeout);
         void clearTimeout(in long handle);
-
         [Custom] long setInterval(in TimeoutHandler handler, in long timeout);
         // [Custom] long setInterval(in DOMString code, in long timeout);
         void clearInterval(in long handle);
 
+
         // EventTarget interface
         [Custom] void addEventListener(in DOMString type, 
                                        in EventListener listener, 
@@ -68,6 +72,13 @@ module threads {
                                           in boolean useCapture);
         boolean dispatchEvent(in Event evt)
             raises(EventException);
+
+
+        // Constructors
+        attribute MessageEventConstructor MessageEvent;
+        attribute WorkerLocationConstructor WorkerLocation;
+
+        attribute [JSCCustomGetter] XMLHttpRequestConstructor XMLHttpRequest;
     };
 
 }