JSDocumentCustom.cpp [plain text]
#include "config.h"
#include "JSDocument.h"
#include "Document.h"
#include "HTMLDocument.h"
#include "JSHTMLDocument.h"
#include "kjs_binding.h"
#include "kjs_window.h"
#if ENABLE(SVG)
#include "JSSVGDocument.h"
#include "SVGDocument.h"
#endif
namespace WebCore {
using namespace KJS;
void JSDocument::mark()
{
DOMObject::mark();
ScriptInterpreter::markDOMNodesForDocument(static_cast<Document*>(impl()));
}
JSValue* toJS(ExecState* exec, Document* doc)
{
if (!doc)
return jsNull();
ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter());
JSDocument* ret = static_cast<JSDocument*>(interp->getDOMObject(doc));
if (ret)
return ret;
if (doc->isHTMLDocument())
ret = new JSHTMLDocument(exec, static_cast<HTMLDocument*>(doc));
#if ENABLE(SVG)
else if (doc->isSVGDocument())
ret = new JSSVGDocument(exec, static_cast<SVGDocument*>(doc));
#endif
else
ret = new JSDocument(exec, doc);
if (doc->frame())
Window::retrieveWindow(doc->frame())->putDirect("document", ret, DontDelete|ReadOnly);
else {
size_t nodeCount = 0;
for (Node* n = doc; n; n = n->traverseNextNode())
nodeCount++;
Collector::reportExtraMemoryCost(nodeCount * sizeof(Node));
}
interp->putDOMObject(doc, ret);
return ret;
}
}