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()->onmessage());
63 typedef WorkerContext::EventListenersMap EventListenersMap;
64 typedef WorkerContext::ListenerVector ListenerVector;
65 EventListenersMap& eventListeners = impl()->eventListeners();
66 for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) {
67 for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter)
68 (*vecIter)->markJSFunction();
72 bool JSWorkerContext::getOwnPropertySlotDelegate(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
74 // Look for overrides before looking at any of our own properties.
75 if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot))
80 JSValue JSWorkerContext::xmlHttpRequest(ExecState* exec) const
82 return getDOMConstructor<JSXMLHttpRequestConstructor>(exec, this);
85 JSValue JSWorkerContext::importScripts(ExecState* exec, const ArgList& args)
91 for (unsigned i = 0; i < args.size(); i++) {
92 urls.append(args.at(i).toString(exec));
93 if (exec->hadException())
101 exec->interpreter()->retrieveLastCaller(exec, signedLineNumber, sourceID, sourceURL, function);
103 impl()->importScripts(urls, sourceURL, signedLineNumber >= 0 ? signedLineNumber : 0, ec);
104 setDOMException(exec, ec);
105 return jsUndefined();
108 JSValue JSWorkerContext::addEventListener(ExecState* exec, const ArgList& args)
110 RefPtr<JSEventListener> listener = findOrCreateJSEventListener(args.at(1));
112 return jsUndefined();
113 impl()->addEventListener(args.at(0).toString(exec), listener.release(), args.at(2).toBoolean(exec));
114 return jsUndefined();
117 JSValue JSWorkerContext::removeEventListener(ExecState* exec, const ArgList& args)
119 JSEventListener* listener = findJSEventListener(args.at(1));
121 return jsUndefined();
122 impl()->removeEventListener(args.at(0).toString(exec), listener, args.at(2).toBoolean(exec));
123 return jsUndefined();
126 JSValue JSWorkerContext::setTimeout(ExecState* exec, const ArgList& args)
128 ScheduledAction* action = ScheduledAction::create(exec, args);
129 if (exec->hadException())
130 return jsUndefined();
131 int delay = args.at(1).toInt32(exec);
132 return jsNumber(exec, impl()->setTimeout(action, delay));
135 JSValue JSWorkerContext::setInterval(ExecState* exec, const ArgList& args)
137 ScheduledAction* action = ScheduledAction::create(exec, args);
138 if (exec->hadException())
139 return jsUndefined();
140 int delay = args.at(1).toInt32(exec);
141 return jsNumber(exec, impl()->setInterval(action, delay));
145 #if ENABLE(CHANNEL_MESSAGING)
146 JSValue JSWorkerContext::messageChannel(ExecState* exec) const
148 return getDOMConstructor<JSMessageChannelConstructor>(exec, this);
152 } // namespace WebCore
154 #endif // ENABLE(WORKERS)