JSDocumentCustom.cpp [plain text]
#include "config.h"
#include "JSDocument.h"
#include "ExceptionCode.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "HTMLDocument.h"
#include "JSCanvasRenderingContext2D.h"
#if ENABLE(WEBGL)
#include "JSWebGLRenderingContext.h"
#endif
#include "JSDOMWindowCustom.h"
#include "JSHTMLDocument.h"
#include "JSLocation.h"
#include "JSTouch.h"
#include "JSTouchList.h"
#include "Location.h"
#include "ScriptController.h"
#include "TouchList.h"
#if ENABLE(SVG)
#include "JSSVGDocument.h"
#include "SVGDocument.h"
#endif
#include <wtf/GetPtr.h>
using namespace JSC;
namespace WebCore {
JSValue JSDocument::location(ExecState* exec) const
{
Frame* frame = static_cast<Document*>(impl())->frame();
if (!frame)
return jsNull();
Location* location = frame->domWindow()->location();
if (JSDOMWrapper* wrapper = getCachedWrapper(currentWorld(exec), location))
return wrapper;
JSLocation* jsLocation = JSLocation::create(getDOMStructure<JSLocation>(exec, globalObject()), globalObject(), location);
cacheWrapper(currentWorld(exec), location, jsLocation);
return jsLocation;
}
void JSDocument::setLocation(ExecState* exec, JSValue value)
{
Frame* frame = static_cast<Document*>(impl())->frame();
if (!frame)
return;
UString locationString = value.toString(exec)->value(exec);
if (exec->hadException())
return;
if (Location* location = frame->domWindow()->location())
location->setHref(ustringToString(locationString), activeDOMWindow(exec), firstDOMWindow(exec));
}
JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Document* document)
{
if (!document)
return jsNull();
JSDOMWrapper* wrapper = getCachedWrapper(currentWorld(exec), document);
if (wrapper)
return wrapper;
if (document->isHTMLDocument())
wrapper = CREATE_DOM_WRAPPER(exec, globalObject, HTMLDocument, document);
#if ENABLE(SVG)
else if (document->isSVGDocument())
wrapper = CREATE_DOM_WRAPPER(exec, globalObject, SVGDocument, document);
#endif
else
wrapper = CREATE_DOM_WRAPPER(exec, globalObject, Document, document);
if (!document->frame()) {
size_t nodeCount = 0;
for (Node* n = document; n; n = n->traverseNextNode())
nodeCount++;
exec->heap()->reportExtraMemoryCost(nodeCount * sizeof(Node));
}
return wrapper;
}
JSValue JSDocument::createTouchList(ExecState* exec)
{
RefPtr<TouchList> touchList = TouchList::create();
for (size_t i = 0; i < exec->argumentCount(); i++)
touchList->append(toTouch(exec->argument(i)));
return toJS(exec, globalObject(), touchList.release());
}
}