+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.
#include "JSWorkerContextBase.h"
+#include "JSWorkerContext.h"
#include "WorkerContext.h"
using namespace JSC;
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)
RefPtr<WorkerContext> m_impl;
};
+ // Returns a JSWorkerContext or jsNull()
+ JSC::JSValue toJS(JSC::ExecState*, WorkerContext*);
+
} // namespace WebCore
#endif // ENABLE(WORKERS)
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();
}
}
-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
/*
- * 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
virtual bool isWorkerContext() const { return true; }
+ virtual WorkerContext* toWorkerContext() { return this; }
+
virtual ScriptExecutionContext* scriptExecutionContext() const;
const KURL& url() const { return m_url; }
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;
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);
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.
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;
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,
in boolean useCapture);
boolean dispatchEvent(in Event evt)
raises(EventException);
+
+
+ // Constructors
+ attribute MessageEventConstructor MessageEvent;
+ attribute WorkerLocationConstructor WorkerLocation;
+
+ attribute [JSCCustomGetter] XMLHttpRequestConstructor XMLHttpRequest;
};
}