Foo::s_info should be Foo::info(), so that you can change how the s_info is actually...
[WebKit-https.git] / Source / WebCore / bindings / js / JSWorkerGlobalScopeCustom.cpp
1 /*
2  * Copyright (C) 2008, 2009, 2011 Apple Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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. 
24  */
25
26 #include "config.h"
27
28 #if ENABLE(WORKERS)
29
30 #include "JSWorkerGlobalScope.h"
31
32 #include "ExceptionCode.h"
33 #include "JSDOMBinding.h"
34 #include "JSDOMGlobalObject.h"
35 #include "JSEventListener.h"
36 #include "JSEventSource.h"
37 #include "JSMessageChannel.h"
38 #include "JSMessagePort.h"
39 #include "JSWorkerLocation.h"
40 #include "JSWorkerNavigator.h"
41 #include "JSXMLHttpRequest.h"
42 #include "ScheduledAction.h"
43 #include "WorkerGlobalScope.h"
44 #include "WorkerLocation.h"
45 #include "WorkerNavigator.h"
46 #include <interpreter/Interpreter.h>
47
48 #if ENABLE(WEB_SOCKETS)
49 #include "JSWebSocket.h"
50 #endif
51
52 using namespace JSC;
53
54 namespace WebCore {
55
56 void JSWorkerGlobalScope::visitChildren(JSCell* cell, SlotVisitor& visitor)
57 {
58     JSWorkerGlobalScope* thisObject = jsCast<JSWorkerGlobalScope*>(cell);
59     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
60     COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
61     ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
62     Base::visitChildren(thisObject, visitor);
63
64     if (WorkerLocation* location = thisObject->impl()->optionalLocation())
65         visitor.addOpaqueRoot(location);
66     if (WorkerNavigator* navigator = thisObject->impl()->optionalNavigator())
67         visitor.addOpaqueRoot(navigator);
68
69     thisObject->impl()->visitJSEventListeners(visitor);
70 }
71
72 bool JSWorkerGlobalScope::getOwnPropertySlotDelegate(ExecState* exec, PropertyName propertyName, PropertySlot& slot)
73 {
74     // Look for overrides before looking at any of our own properties.
75     if (JSGlobalObject::getOwnPropertySlot(this, exec, propertyName, slot))
76         return true;
77     return false;
78 }
79
80 bool JSWorkerGlobalScope::getOwnPropertyDescriptorDelegate(ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
81 {
82     // Look for overrides before looking at any of our own properties.
83     if (JSGlobalObject::getOwnPropertyDescriptor(this, exec, propertyName, descriptor))
84         return true;
85     return false;
86 }
87
88 JSValue JSWorkerGlobalScope::importScripts(ExecState* exec)
89 {
90     if (!exec->argumentCount())
91         return jsUndefined();
92
93     Vector<String> urls;
94     for (unsigned i = 0; i < exec->argumentCount(); i++) {
95         urls.append(exec->argument(i).toString(exec)->value(exec));
96         if (exec->hadException())
97             return jsUndefined();
98     }
99     ExceptionCode ec = 0;
100
101     impl()->importScripts(urls, ec);
102     setDOMException(exec, ec);
103     return jsUndefined();
104 }
105
106 JSValue JSWorkerGlobalScope::setTimeout(ExecState* exec)
107 {
108     OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, currentWorld(exec), impl()->contentSecurityPolicy());
109     if (exec->hadException())
110         return jsUndefined();
111     if (!action)
112         return jsNumber(0);
113     int delay = exec->argument(1).toInt32(exec);
114     return jsNumber(impl()->setTimeout(action.release(), delay));
115 }
116
117 JSValue JSWorkerGlobalScope::setInterval(ExecState* exec)
118 {
119     OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, currentWorld(exec), impl()->contentSecurityPolicy());
120     if (exec->hadException())
121         return jsUndefined();
122     if (!action)
123         return jsNumber(0);
124     int delay = exec->argument(1).toInt32(exec);
125     return jsNumber(impl()->setInterval(action.release(), delay));
126 }
127
128 } // namespace WebCore
129
130 #endif // ENABLE(WORKERS)