JSDOMWindowProxy.cpp [plain text]
#include "config.h"
#include "JSDOMWindowProxy.h"
#include "CommonVM.h"
#include "Frame.h"
#include "GCController.h"
#include "JSDOMWindow.h"
#include "JSDOMWindowProperties.h"
#include "JSEventTarget.h"
#include "ScriptController.h"
#include <heap/StrongInlines.h>
#include <runtime/JSObject.h>
using namespace JSC;
namespace WebCore {
const ClassInfo JSDOMWindowProxy::s_info = { "JSDOMWindowProxy", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSDOMWindowProxy) };
JSDOMWindowProxy::JSDOMWindowProxy(VM& vm, Structure* structure, DOMWrapperWorld& world)
: Base(vm, structure)
, m_world(world)
{
}
void JSDOMWindowProxy::finishCreation(VM& vm, RefPtr<DOMWindow>&& window)
{
Base::finishCreation(vm);
ASSERT(inherits(vm, info()));
setWindow(WTFMove(window));
}
void JSDOMWindowProxy::destroy(JSCell* cell)
{
static_cast<JSDOMWindowProxy*>(cell)->JSDOMWindowProxy::~JSDOMWindowProxy();
}
void JSDOMWindowProxy::setWindow(VM& vm, JSDOMWindow* window)
{
ASSERT_ARG(window, window);
setTarget(vm, window);
structure()->setGlobalObject(vm, window);
GCController::singleton().garbageCollectSoon();
}
void JSDOMWindowProxy::setWindow(RefPtr<DOMWindow>&& domWindow)
{
ASSERT(!window() || domWindow.get() != &window()->wrapped());
VM& vm = commonVM();
Structure* prototypeStructure = JSDOMWindowPrototype::createStructure(vm, nullptr, jsNull());
Strong<JSDOMWindowPrototype> prototype(vm, JSDOMWindowPrototype::create(vm, nullptr, prototypeStructure));
Structure* structure = JSDOMWindow::createStructure(vm, nullptr, prototype.get());
JSDOMWindow* jsDOMWindow = JSDOMWindow::create(vm, structure, *domWindow, this);
prototype->structure()->setGlobalObject(vm, jsDOMWindow);
Structure* windowPropertiesStructure = JSDOMWindowProperties::createStructure(vm, jsDOMWindow, JSEventTarget::prototype(vm, *jsDOMWindow));
JSDOMWindowProperties* windowProperties = JSDOMWindowProperties::create(windowPropertiesStructure, *jsDOMWindow);
prototype->structure()->setPrototypeWithoutTransition(vm, windowProperties);
setWindow(vm, jsDOMWindow);
ASSERT(jsDOMWindow->globalObject() == jsDOMWindow);
ASSERT(prototype->globalObject() == jsDOMWindow);
}
DOMWindow& JSDOMWindowProxy::wrapped() const
{
return window()->wrapped();
}
DOMWindow* JSDOMWindowProxy::toWrapped(VM& vm, JSObject* value)
{
auto* wrapper = jsDynamicDowncast<JSDOMWindowProxy*>(vm, value);
if (!wrapper)
return nullptr;
return &wrapper->window()->wrapped();
}
JSValue toJS(ExecState* exec, Frame& frame)
{
return frame.script().windowProxy(currentWorld(exec));
}
JSDOMWindowProxy* toJSDOMWindowProxy(Frame& frame, DOMWrapperWorld& world)
{
return frame.script().windowProxy(world);
}
}