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 COMPUTER, 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 COMPUTER, 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.
28 #include "JSDOMGlobalObject.h"
31 #include "JSDOMWindow.h"
32 #include "JSEventListener.h"
35 #include "JSWorkerContext.h"
36 #include "WorkerContext.h"
43 const ClassInfo JSDOMGlobalObject::s_info = { "DOMGlobalObject", &JSGlobalObject::s_info, 0, 0, CREATE_METHOD_TABLE(JSDOMGlobalObject) };
45 JSDOMGlobalObject::JSDOMGlobalObject(JSGlobalData& globalData, Structure* structure, PassRefPtr<DOMWrapperWorld> world, const GlobalObjectMethodTable* globalObjectMethodTable)
46 : JSGlobalObject(globalData, structure, globalObjectMethodTable)
52 JSDOMGlobalObject::~JSDOMGlobalObject()
56 void JSDOMGlobalObject::finishCreation(JSGlobalData& globalData)
58 Base::finishCreation(globalData);
59 ASSERT(inherits(&s_info));
62 void JSDOMGlobalObject::finishCreation(JSGlobalData& globalData, JSGlobalThis* thisValue)
64 Base::finishCreation(globalData, thisValue);
65 ASSERT(inherits(&s_info));
68 void JSDOMGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
70 JSDOMGlobalObject* thisObject = jsCast<JSDOMGlobalObject*>(cell);
71 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
72 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
73 ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
74 Base::visitChildren(thisObject, visitor);
76 JSDOMStructureMap::iterator end = thisObject->structures().end();
77 for (JSDOMStructureMap::iterator it = thisObject->structures().begin(); it != end; ++it)
78 visitor.append(&it->second);
80 JSDOMConstructorMap::iterator end2 = thisObject->constructors().end();
81 for (JSDOMConstructorMap::iterator it2 = thisObject->constructors().begin(); it2 != end2; ++it2)
82 visitor.append(&it2->second);
84 if (thisObject->m_injectedScript)
85 visitor.append(&thisObject->m_injectedScript);
88 void JSDOMGlobalObject::setCurrentEvent(Event* currentEvent)
90 m_currentEvent = currentEvent;
93 Event* JSDOMGlobalObject::currentEvent() const
95 return m_currentEvent;
98 void JSDOMGlobalObject::setInjectedScript(JSObject* injectedScript)
100 m_injectedScript.setMayBeNull(globalData(), this, injectedScript);
103 JSObject* JSDOMGlobalObject::injectedScript() const
105 return m_injectedScript.get();
108 JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, JSC::ExecState* exec)
110 return toJSDOMWindow(document->frame(), currentWorld(exec));
113 JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, JSC::ExecState* exec)
115 if (scriptExecutionContext->isDocument())
116 return toJSDOMGlobalObject(static_cast<Document*>(scriptExecutionContext), exec);
119 if (scriptExecutionContext->isWorkerContext())
120 return static_cast<WorkerContext*>(scriptExecutionContext)->script()->workerContextWrapper();
123 ASSERT_NOT_REACHED();
127 JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, DOMWrapperWorld* world)
129 return toJSDOMWindow(document->frame(), world);
132 JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, DOMWrapperWorld* world)
134 if (scriptExecutionContext->isDocument())
135 return toJSDOMGlobalObject(static_cast<Document*>(scriptExecutionContext), world);
138 if (scriptExecutionContext->isWorkerContext())
139 return static_cast<WorkerContext*>(scriptExecutionContext)->script()->workerContextWrapper();
142 ASSERT_NOT_REACHED();
146 } // namespace WebCore