REGRESSION(r179429): Can't type comments in Facebook
[WebKit-https.git] / Source / WebCore / bindings / js / JSWorkerGlobalScopeBase.cpp
1 /*
2  * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
3  * Copyright (C) 2009 Google Inc. All Rights Reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
25  *
26  */
27
28 #include "config.h"
29
30 #include "JSWorkerGlobalScopeBase.h"
31
32 #include "DOMWrapperWorld.h"
33 #include "JSDOMGlobalObjectTask.h"
34 #include "JSDedicatedWorkerGlobalScope.h"
35 #include "JSWorkerGlobalScope.h"
36 #include "WorkerGlobalScope.h"
37 #include <runtime/JSCJSValueInlines.h>
38 #include <runtime/Microtask.h>
39
40 using namespace JSC;
41
42 namespace WebCore {
43
44 const ClassInfo JSWorkerGlobalScopeBase::s_info = { "WorkerGlobalScope", &JSDOMGlobalObject::s_info, 0, CREATE_METHOD_TABLE(JSWorkerGlobalScopeBase) };
45
46 const GlobalObjectMethodTable JSWorkerGlobalScopeBase::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, &queueTaskToEventLoop, &shouldInterruptScriptBeforeTimeout };
47
48 JSWorkerGlobalScopeBase::JSWorkerGlobalScopeBase(JSC::VM& vm, JSC::Structure* structure, PassRefPtr<WorkerGlobalScope> impl)
49     : JSDOMGlobalObject(vm, structure, &normalWorld(vm), &s_globalObjectMethodTable)
50     , m_impl(impl)
51 {
52 }
53
54 void JSWorkerGlobalScopeBase::finishCreation(VM& vm)
55 {
56     Base::finishCreation(vm);
57     ASSERT(inherits(info()));
58 }
59
60 void JSWorkerGlobalScopeBase::destroy(JSCell* cell)
61 {
62     static_cast<JSWorkerGlobalScopeBase*>(cell)->JSWorkerGlobalScopeBase::~JSWorkerGlobalScopeBase();
63 }
64
65 ScriptExecutionContext* JSWorkerGlobalScopeBase::scriptExecutionContext() const
66 {
67     return m_impl.get();
68 }
69
70 bool JSWorkerGlobalScopeBase::allowsAccessFrom(const JSGlobalObject* object, ExecState* exec)
71 {
72     return JSGlobalObject::allowsAccessFrom(object, exec);
73 }
74
75 bool JSWorkerGlobalScopeBase::supportsProfiling(const JSGlobalObject* object)
76 {
77     return JSGlobalObject::supportsProfiling(object);
78 }
79
80 bool JSWorkerGlobalScopeBase::supportsRichSourceInfo(const JSGlobalObject* object)
81 {
82     return JSGlobalObject::supportsRichSourceInfo(object);
83 }
84
85 bool JSWorkerGlobalScopeBase::shouldInterruptScript(const JSGlobalObject* object)
86 {
87     return JSGlobalObject::shouldInterruptScript(object);
88 }
89
90 bool JSWorkerGlobalScopeBase::shouldInterruptScriptBeforeTimeout(const JSGlobalObject* object)
91 {
92     return JSGlobalObject::shouldInterruptScriptBeforeTimeout(object);
93 }
94
95 RuntimeFlags JSWorkerGlobalScopeBase::javaScriptRuntimeFlags(const JSGlobalObject* object)
96 {
97     return JSGlobalObject::javaScriptRuntimeFlags(object);
98 }
99
100 void JSWorkerGlobalScopeBase::queueTaskToEventLoop(const JSGlobalObject* object, PassRefPtr<Microtask> task)
101 {
102     const JSWorkerGlobalScopeBase* thisObject = static_cast<const JSWorkerGlobalScopeBase*>(object);
103     thisObject->scriptExecutionContext()->postTask(JSGlobalObjectTask((JSDOMGlobalObject*)thisObject, task));
104 }
105
106 JSValue toJS(ExecState* exec, JSDOMGlobalObject*, WorkerGlobalScope* workerGlobalScope)
107 {
108     return toJS(exec, workerGlobalScope);
109 }
110
111 JSValue toJS(ExecState*, WorkerGlobalScope* workerGlobalScope)
112 {
113     if (!workerGlobalScope)
114         return jsNull();
115     WorkerScriptController* script = workerGlobalScope->script();
116     if (!script)
117         return jsNull();
118     JSWorkerGlobalScope* contextWrapper = script->workerGlobalScopeWrapper();
119     ASSERT(contextWrapper);
120     return contextWrapper;
121 }
122
123 JSDedicatedWorkerGlobalScope* toJSDedicatedWorkerGlobalScope(JSValue value)
124 {
125     if (!value.isObject())
126         return 0;
127     const ClassInfo* classInfo = asObject(value)->classInfo();
128     if (classInfo == JSDedicatedWorkerGlobalScope::info())
129         return jsCast<JSDedicatedWorkerGlobalScope*>(asObject(value));
130     if (classInfo == JSProxy::info())
131         return jsDynamicCast<JSDedicatedWorkerGlobalScope*>(jsCast<JSProxy*>(asObject(value))->target());
132     return 0;
133 }
134
135
136 JSWorkerGlobalScope* toJSWorkerGlobalScope(JSValue value)
137 {
138     return toJSDedicatedWorkerGlobalScope(value);
139 }
140
141 } // namespace WebCore