JSDOMWindowShell.cpp [plain text]
#include "config.h"
#include "JSDOMWindowShell.h"
#include "Frame.h"
#include "GCController.h"
#include "JSDOMWindow.h"
#include "DOMWindow.h"
#include "ScriptController.h"
#include <heap/StrongInlines.h>
#include <runtime/JSObject.h>
using namespace JSC;
namespace WebCore {
const ClassInfo JSDOMWindowShell::s_info = { "JSDOMWindowShell", &Base::s_info, 0, CREATE_METHOD_TABLE(JSDOMWindowShell) };
JSDOMWindowShell::JSDOMWindowShell(VM& vm, Structure* structure, DOMWrapperWorld& world)
: Base(vm, structure)
, m_world(world)
{
}
void JSDOMWindowShell::finishCreation(VM& vm, PassRefPtr<DOMWindow> window)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
setWindow(window);
}
void JSDOMWindowShell::destroy(JSCell* cell)
{
static_cast<JSDOMWindowShell*>(cell)->JSDOMWindowShell::~JSDOMWindowShell();
}
void JSDOMWindowShell::setWindow(VM& vm, JSDOMWindow* window)
{
ASSERT_ARG(window, window);
setTarget(vm, window);
structure()->setGlobalObject(vm, window);
GCController::singleton().garbageCollectSoon();
}
void JSDOMWindowShell::setWindow(PassRefPtr<DOMWindow> domWindow)
{
ASSERT(!window() || domWindow.get() != &window()->impl());
VM& vm = JSDOMWindow::commonVM();
Structure* prototypeStructure = JSDOMWindowPrototype::createStructure(vm, 0, jsNull());
Strong<JSDOMWindowPrototype> prototype(vm, JSDOMWindowPrototype::create(vm, 0, prototypeStructure));
Structure* structure = JSDOMWindow::createStructure(vm, 0, prototype.get());
JSDOMWindow* jsDOMWindow = JSDOMWindow::create(vm, structure, *domWindow, this);
prototype->structure()->setGlobalObject(vm, jsDOMWindow);
setWindow(vm, jsDOMWindow);
ASSERT(jsDOMWindow->globalObject() == jsDOMWindow);
ASSERT(prototype->globalObject() == jsDOMWindow);
}
DOMWindow& JSDOMWindowShell::impl() const
{
return window()->impl();
}
JSValue toJS(ExecState* exec, Frame* frame)
{
if (!frame)
return jsNull();
return frame->script().windowShell(currentWorld(exec));
}
JSDOMWindowShell* toJSDOMWindowShell(Frame* frame, DOMWrapperWorld& world)
{
if (!frame)
return 0;
return frame->script().windowShell(world);
}
}