2 * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "JSWorkerContext.h"
32 #include "JSDOMBinding.h"
33 #include "JSDOMGlobalObject.h"
34 #include "JSEventListener.h"
35 #include "JSMessageChannelConstructor.h"
36 #include "JSMessagePort.h"
37 #include "JSWorkerLocation.h"
38 #include "JSWorkerNavigator.h"
39 #include "JSXMLHttpRequestConstructor.h"
40 #include "ScheduledAction.h"
41 #include "WorkerContext.h"
42 #include "WorkerLocation.h"
43 #include "WorkerNavigator.h"
44 #include <interpreter/Interpreter.h>
50 void JSWorkerContext::mark()
54 JSGlobalData& globalData = *this->globalData();
56 markActiveObjectsForContext(globalData, scriptExecutionContext());
58 markDOMObjectWrapper(globalData, impl()->optionalLocation());
59 markDOMObjectWrapper(globalData, impl()->optionalNavigator());
61 markIfNotNull(impl()->onerror());
62 markIfNotNull(impl()->onmessage());
64 typedef WorkerContext::EventListenersMap EventListenersMap;
65 typedef WorkerContext::ListenerVector ListenerVector;
66 EventListenersMap& eventListeners = impl()->eventListeners();
67 for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) {
68 for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter)
69 (*vecIter)->markJSFunction();
73 bool JSWorkerContext::getOwnPropertySlotDelegate(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
75 // Look for overrides before looking at any of our own properties.
76 if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot))
81 JSValue JSWorkerContext::xmlHttpRequest(ExecState* exec) const
83 return getDOMConstructor<JSXMLHttpRequestConstructor>(exec, this);
86 JSValue JSWorkerContext::importScripts(ExecState* exec, const ArgList& args)
92 for (unsigned i = 0; i < args.size(); i++) {
93 urls.append(args.at(i).toString(exec));
94 if (exec->hadException())
102 exec->interpreter()->retrieveLastCaller(exec, signedLineNumber, sourceID, sourceURL, function);
104 impl()->importScripts(urls, sourceURL, signedLineNumber >= 0 ? signedLineNumber : 0, ec);
105 setDOMException(exec, ec);
106 return jsUndefined();
109 JSValue JSWorkerContext::addEventListener(ExecState* exec, const ArgList& args)
111 RefPtr<JSEventListener> listener = findOrCreateJSEventListener(args.at(1));
113 return jsUndefined();
114 impl()->addEventListener(args.at(0).toString(exec), listener.release(), args.at(2).toBoolean(exec));
115 return jsUndefined();
118 JSValue JSWorkerContext::removeEventListener(ExecState* exec, const ArgList& args)
120 JSEventListener* listener = findJSEventListener(args.at(1));
122 return jsUndefined();
123 impl()->removeEventListener(args.at(0).toString(exec), listener, args.at(2).toBoolean(exec));
124 return jsUndefined();
127 JSValue JSWorkerContext::setTimeout(ExecState* exec, const ArgList& args)
129 ScheduledAction* action = ScheduledAction::create(exec, args);
130 if (exec->hadException())
131 return jsUndefined();
132 int delay = args.at(1).toInt32(exec);
133 return jsNumber(exec, impl()->setTimeout(action, delay));
136 JSValue JSWorkerContext::setInterval(ExecState* exec, const ArgList& args)
138 ScheduledAction* action = ScheduledAction::create(exec, args);
139 if (exec->hadException())
140 return jsUndefined();
141 int delay = args.at(1).toInt32(exec);
142 return jsNumber(exec, impl()->setInterval(action, delay));
146 #if ENABLE(CHANNEL_MESSAGING)
147 JSValue JSWorkerContext::messageChannel(ExecState* exec) const
149 return getDOMConstructor<JSMessageChannelConstructor>(exec, this);
153 } // namespace WebCore
155 #endif // ENABLE(WORKERS)