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
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 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "JSDOMWindowShell.h"
33 #include "JSDOMWindow.h"
34 #include "DOMWindow.h"
35 #include "ScriptController.h"
36 #include <heap/StrongInlines.h>
37 #include <runtime/JSObject.h>
43 ASSERT_CLASS_FITS_IN_CELL(JSDOMWindowShell);
45 const ClassInfo JSDOMWindowShell::s_info = { "JSDOMWindowShell", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSDOMWindowShell) };
47 JSDOMWindowShell::JSDOMWindowShell(Structure* structure, DOMWrapperWorld* world)
48 : Base(*world->globalData(), structure)
53 void JSDOMWindowShell::finishCreation(JSGlobalData& globalData, PassRefPtr<DOMWindow> window)
55 Base::finishCreation(globalData);
56 ASSERT(inherits(&s_info));
60 JSDOMWindowShell::~JSDOMWindowShell()
64 void JSDOMWindowShell::setWindow(PassRefPtr<DOMWindow> domWindow)
66 // Replacing JSDOMWindow via telling JSDOMWindowShell to use the same DOMWindow it already uses makes no sense,
67 // so we'd better never try to.
68 ASSERT(!window() || domWindow.get() != window()->impl());
69 // Explicitly protect the global object's prototype so it isn't collected
70 // when we allocate the global object. (Once the global object is fully
71 // constructed, it can mark its own prototype.)
72 Structure* prototypeStructure = JSDOMWindowPrototype::createStructure(*JSDOMWindow::commonJSGlobalData(), 0, jsNull());
73 Strong<JSDOMWindowPrototype> prototype(*JSDOMWindow::commonJSGlobalData(), JSDOMWindowPrototype::create(*JSDOMWindow::commonJSGlobalData(), 0, prototypeStructure));
75 Structure* structure = JSDOMWindow::createStructure(*JSDOMWindow::commonJSGlobalData(), 0, prototype.get());
76 JSDOMWindow* jsDOMWindow = JSDOMWindow::create(*JSDOMWindow::commonJSGlobalData(), structure, domWindow, this);
77 prototype->structure()->setGlobalObject(*JSDOMWindow::commonJSGlobalData(), jsDOMWindow);
78 setWindow(*JSDOMWindow::commonJSGlobalData(), jsDOMWindow);
79 ASSERT(jsDOMWindow->globalObject() == jsDOMWindow);
80 ASSERT(prototype->globalObject() == jsDOMWindow);
87 UString JSDOMWindowShell::className(const JSObject* object)
89 const JSDOMWindowShell* thisObject = jsCast<const JSDOMWindowShell*>(object);
90 return thisObject->window()->methodTable()->className(thisObject->window());
93 bool JSDOMWindowShell::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
95 JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(cell);
96 return thisObject->window()->methodTable()->getOwnPropertySlot(thisObject->window(), exec, propertyName, slot);
99 bool JSDOMWindowShell::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
101 JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(object);
102 return thisObject->window()->methodTable()->getOwnPropertyDescriptor(thisObject->window(), exec, propertyName, descriptor);
105 void JSDOMWindowShell::put(JSCell* cell, ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
107 JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(cell);
108 thisObject->window()->methodTable()->put(thisObject->window(), exec, propertyName, value, slot);
111 void JSDOMWindowShell::putWithAttributes(JSObject* object, ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes)
113 JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(object);
114 thisObject->window()->putWithAttributes(thisObject->window(), exec, propertyName, value, attributes);
117 bool JSDOMWindowShell::defineOwnProperty(JSC::JSObject* object, JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertyDescriptor& descriptor, bool shouldThrow)
119 JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(object);
120 return thisObject->window()->methodTable()->defineOwnProperty(thisObject->window(), exec, propertyName, descriptor, shouldThrow);
123 bool JSDOMWindowShell::deleteProperty(JSCell* cell, ExecState* exec, const Identifier& propertyName)
125 JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(cell);
126 return thisObject->window()->methodTable()->deleteProperty(thisObject->window(), exec, propertyName);
129 void JSDOMWindowShell::getPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
131 JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(object);
132 thisObject->window()->methodTable()->getPropertyNames(thisObject->window(), exec, propertyNames, mode);
135 void JSDOMWindowShell::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
137 JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(object);
138 thisObject->window()->methodTable()->getOwnPropertyNames(thisObject->window(), exec, propertyNames, mode);
141 void JSDOMWindowShell::defineGetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes)
143 JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(object);
144 thisObject->window()->methodTable()->defineGetter(thisObject->window(), exec, propertyName, getterFunction, attributes);
147 void JSDOMWindowShell::defineSetter(JSObject* object, ExecState* exec, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes)
149 JSDOMWindowShell* thisObject = jsCast<JSDOMWindowShell*>(object);
150 thisObject->window()->methodTable()->defineSetter(thisObject->window(), exec, propertyName, setterFunction, attributes);
155 // JSDOMWindow methods
158 DOMWindow* JSDOMWindowShell::impl() const
160 return window()->impl();
163 void* JSDOMWindowShell::operator new(size_t size)
165 Heap& heap = JSDOMWindow::commonJSGlobalData()->heap;
166 #if ENABLE(GC_VALIDATION)
167 ASSERT(!heap.globalData()->isInitializingObject());
168 heap.globalData()->setInitializingObject(true);
170 return heap.allocate(size);
174 // Conversion methods
177 JSValue toJS(ExecState* exec, Frame* frame)
181 return frame->script()->windowShell(currentWorld(exec));
184 JSDOMWindowShell* toJSDOMWindowShell(Frame* frame, DOMWrapperWorld* isolatedWorld)
188 return frame->script()->windowShell(isolatedWorld);
191 } // namespace WebCore