#include "config.h"
#include "JSDOMParser.h"
#include "JSDOMParser.lut.h"
#include "HTMLDocument.h"
#include "DOMImplementation.h"
using namespace WebCore;
namespace KJS {
KJS_DEFINE_PROTOTYPE(DOMParserProto)
KJS_IMPLEMENT_PROTOFUNC(DOMParserProtoFunc)
KJS_IMPLEMENT_PROTOTYPE("DOMParser",DOMParserProto,DOMParserProtoFunc)
DOMParserConstructorImp::DOMParserConstructorImp(ExecState *exec, Document *d)
: doc(d)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
putDirect(prototypePropertyName, DOMParserProto::self(exec), None);
}
bool DOMParserConstructorImp::implementsConstruct() const
{
return true;
}
JSObject *DOMParserConstructorImp::construct(ExecState *exec, const List &)
{
return new JSDOMParser(exec, doc.get());
}
const ClassInfo JSDOMParser::info = { "DOMParser", 0, &DOMParserTable, 0 };
JSDOMParser::JSDOMParser(ExecState *exec, Document *d)
: doc(d)
{
setPrototype(DOMParserProto::self(exec));
}
JSValue *DOMParserProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
{
if (!thisObj->inherits(&JSDOMParser::info))
return throwError(exec, TypeError);
JSDOMParser *parser = static_cast<JSDOMParser *>(thisObj);
switch (id) {
case JSDOMParser::ParseFromString:
{
if (args.size() != 2)
return jsUndefined();
DeprecatedString str = args[0]->toString(exec);
DeprecatedString contentType = DeprecatedString(args[1]->toString(exec)).stripWhiteSpace();
if (DOMImplementation::isXMLMIMEType(contentType)) {
RefPtr<Document> doc = parser->doc->implementation()->createDocument();
doc->open();
doc->write(str);
doc->finishParsing();
doc->close();
return toJS(exec, doc.get());
}
}
}
return jsUndefined();
}
}