1 | /* |
2 | * Copyright (C) 2008, 2009 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 | |
27 | #pragma once |
28 | |
29 | #include "JSDOMGlobalObject.h" |
30 | #include "JSDOMWrapper.h" |
31 | |
32 | #if ENABLE(SERVICE_WORKER) |
33 | #include "ServiceWorkerGlobalScope.h" |
34 | #endif |
35 | |
36 | namespace JSC { |
37 | class JSProxy; |
38 | } |
39 | |
40 | namespace WebCore { |
41 | |
42 | class JSDedicatedWorkerGlobalScope; |
43 | class JSWorkerGlobalScope; |
44 | class WorkerGlobalScope; |
45 | |
46 | #if ENABLE(SERVICE_WORKER) |
47 | class JSServiceWorkerGlobalScope; |
48 | #endif |
49 | |
50 | class JSWorkerGlobalScopeBase : public JSDOMGlobalObject { |
51 | typedef JSDOMGlobalObject Base; |
52 | public: |
53 | static void destroy(JSC::JSCell*); |
54 | |
55 | DECLARE_INFO; |
56 | |
57 | WorkerGlobalScope& wrapped() const { return *m_wrapped; } |
58 | JSC::JSProxy* proxy() const { ASSERT(m_proxy); return m_proxy.get(); } |
59 | ScriptExecutionContext* scriptExecutionContext() const; |
60 | |
61 | static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) |
62 | { |
63 | return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::GlobalObjectType, StructureFlags), info()); |
64 | } |
65 | |
66 | static const JSC::GlobalObjectMethodTable s_globalObjectMethodTable; |
67 | |
68 | static bool supportsRichSourceInfo(const JSC::JSGlobalObject*); |
69 | static bool shouldInterruptScript(const JSC::JSGlobalObject*); |
70 | static bool shouldInterruptScriptBeforeTimeout(const JSC::JSGlobalObject*); |
71 | static JSC::RuntimeFlags javaScriptRuntimeFlags(const JSC::JSGlobalObject*); |
72 | static void queueTaskToEventLoop(JSC::JSGlobalObject&, Ref<JSC::Microtask>&&); |
73 | |
74 | void clearDOMGuardedObjects(); |
75 | |
76 | protected: |
77 | JSWorkerGlobalScopeBase(JSC::VM&, JSC::Structure*, RefPtr<WorkerGlobalScope>&&); |
78 | void finishCreation(JSC::VM&, JSC::JSProxy*); |
79 | |
80 | static void visitChildren(JSC::JSCell*, JSC::SlotVisitor&); |
81 | |
82 | private: |
83 | RefPtr<WorkerGlobalScope> m_wrapped; |
84 | JSC::WriteBarrier<JSC::JSProxy> m_proxy; |
85 | }; |
86 | |
87 | // Returns a JSWorkerGlobalScope or jsNull() |
88 | // Always ignores the execState and passed globalObject, WorkerGlobalScope is itself a globalObject and will always use its own prototype chain. |
89 | JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, WorkerGlobalScope&); |
90 | inline JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, WorkerGlobalScope* scope) { return scope ? toJS(exec, globalObject, *scope) : JSC::jsNull(); } |
91 | JSC::JSValue toJS(JSC::ExecState*, WorkerGlobalScope&); |
92 | inline JSC::JSValue toJS(JSC::ExecState* exec, WorkerGlobalScope* scope) { return scope ? toJS(exec, *scope) : JSC::jsNull(); } |
93 | |
94 | JSDedicatedWorkerGlobalScope* toJSDedicatedWorkerGlobalScope(JSC::VM&, JSC::JSValue); |
95 | JSWorkerGlobalScope* toJSWorkerGlobalScope(JSC::VM&, JSC::JSValue); |
96 | |
97 | #if ENABLE(SERVICE_WORKER) |
98 | JSServiceWorkerGlobalScope* toJSServiceWorkerGlobalScope(JSC::VM&, JSC::JSValue); |
99 | #endif |
100 | } // namespace WebCore |
101 | |