Commit 1669824c authored by ap's avatar ap
Browse files

Reviewed by Eric.

        Whitespace cleanup; rename *job variables to *loader.

        * bindings/js/JSXMLHttpRequest.cpp:
        (KJS::JSXMLHttpRequestConstructorImp::JSXMLHttpRequestConstructorImp):
        (KJS::JSXMLHttpRequestConstructorImp::implementsConstruct):
        (KJS::JSXMLHttpRequestConstructorImp::construct):
        (KJS::JSXMLHttpRequest::getOwnPropertySlot):
        (KJS::JSXMLHttpRequest::getValueProperty):
        (KJS::JSXMLHttpRequest::put):
        (KJS::JSXMLHttpRequest::putValueProperty):
        (KJS::JSXMLHttpRequest::mark):
        (KJS::JSXMLHttpRequest::JSXMLHttpRequest):
        (KJS::JSXMLHttpRequest::~JSXMLHttpRequest):
        (KJS::JSXMLHttpRequestProtoFunc::callAsFunction):
        * bindings/js/JSXMLHttpRequest.h:
        (KJS::JSXMLHttpRequest::toBoolean):
        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::XMLHttpRequest):
        (WebCore::XMLHttpRequest::urlMatchesDocumentDomain):
        (WebCore::XMLHttpRequest::send):
        (WebCore::XMLHttpRequest::abort):
        (WebCore::XMLHttpRequest::receivedAllData):
        (WebCore::XMLHttpRequest::receivedData):
        * xml/xmlhttprequest.h:
        (WebCore::):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@16560 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent aacdbc64
2006-09-25 Alexey Proskuryakov <ap@nypop.com>
Reviewed by Eric.
Whitespace cleanup; rename *job variables to *loader.
* bindings/js/JSXMLHttpRequest.cpp:
(KJS::JSXMLHttpRequestConstructorImp::JSXMLHttpRequestConstructorImp):
(KJS::JSXMLHttpRequestConstructorImp::implementsConstruct):
(KJS::JSXMLHttpRequestConstructorImp::construct):
(KJS::JSXMLHttpRequest::getOwnPropertySlot):
(KJS::JSXMLHttpRequest::getValueProperty):
(KJS::JSXMLHttpRequest::put):
(KJS::JSXMLHttpRequest::putValueProperty):
(KJS::JSXMLHttpRequest::mark):
(KJS::JSXMLHttpRequest::JSXMLHttpRequest):
(KJS::JSXMLHttpRequest::~JSXMLHttpRequest):
(KJS::JSXMLHttpRequestProtoFunc::callAsFunction):
* bindings/js/JSXMLHttpRequest.h:
(KJS::JSXMLHttpRequest::toBoolean):
* xml/xmlhttprequest.cpp:
(WebCore::XMLHttpRequest::XMLHttpRequest):
(WebCore::XMLHttpRequest::urlMatchesDocumentDomain):
(WebCore::XMLHttpRequest::send):
(WebCore::XMLHttpRequest::abort):
(WebCore::XMLHttpRequest::receivedAllData):
(WebCore::XMLHttpRequest::receivedData):
* xml/xmlhttprequest.h:
(WebCore::):
2006-09-25 Timothy Hatcher <timothy@apple.com>
 
Reviewed by Brady.
......@@ -50,7 +50,7 @@ KJS_DEFINE_PROTOTYPE(JSXMLHttpRequestProto)
KJS_IMPLEMENT_PROTOFUNC(JSXMLHttpRequestProtoFunc)
KJS_IMPLEMENT_PROTOTYPE("JSXMLHttpRequest", JSXMLHttpRequestProto, JSXMLHttpRequestProtoFunc)
JSXMLHttpRequestConstructorImp::JSXMLHttpRequestConstructorImp(ExecState *exec, Document *d)
JSXMLHttpRequestConstructorImp::JSXMLHttpRequestConstructorImp(ExecState* exec, Document* d)
: doc(d)
{
setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
......@@ -59,12 +59,12 @@ JSXMLHttpRequestConstructorImp::JSXMLHttpRequestConstructorImp(ExecState *exec,
bool JSXMLHttpRequestConstructorImp::implementsConstruct() const
{
return true;
return true;
}
JSObject *JSXMLHttpRequestConstructorImp::construct(ExecState *exec, const List &)
JSObject* JSXMLHttpRequestConstructorImp::construct(ExecState* exec, const List&)
{
return new JSXMLHttpRequest(exec, doc.get());
return new JSXMLHttpRequest(exec, doc.get());
}
const ClassInfo JSXMLHttpRequest::info = { "JSXMLHttpRequest", 0, &JSXMLHttpRequestTable, 0 };
......@@ -81,175 +81,180 @@ const ClassInfo JSXMLHttpRequest::info = { "JSXMLHttpRequest", 0, &JSXMLHttpRequ
@end
*/
bool JSXMLHttpRequest::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
bool JSXMLHttpRequest::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
return getStaticValueSlot<JSXMLHttpRequest, DOMObject>(exec, &JSXMLHttpRequestTable, this, propertyName, slot);
return getStaticValueSlot<JSXMLHttpRequest, DOMObject>(exec, &JSXMLHttpRequestTable, this, propertyName, slot);
}
JSValue* JSXMLHttpRequest::getValueProperty(ExecState *exec, int token) const
JSValue* JSXMLHttpRequest::getValueProperty(ExecState* exec, int token) const
{
ExceptionCode ec = 0;
switch (token) {
case ReadyState:
return jsNumber(m_impl->getReadyState());
case ResponseText:
return jsStringOrNull(m_impl->getResponseText());
case ResponseXML:
if (Document* responseXML = m_impl->getResponseXML())
return toJS(exec, responseXML);
return jsNull();
case Status: {
JSValue* result = jsNumber(m_impl->getStatus(ec));
setDOMException(exec, ec);
return result;
}
case StatusText: {
JSValue* result = jsString(m_impl->getStatusText(ec));
setDOMException(exec, ec);
return result;
}
case Onreadystatechange:
if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onReadyStateChangeListener()))
if (JSObject* listenerObj = listener->listenerObj())
return listenerObj;
return jsNull();
case Onload:
if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onLoadListener()))
if (JSObject* listenerObj = listener->listenerObj())
return listenerObj;
return jsNull();
default:
return 0;
}
ExceptionCode ec = 0;
switch (token) {
case ReadyState:
return jsNumber(m_impl->getReadyState());
case ResponseText:
return jsStringOrNull(m_impl->getResponseText());
case ResponseXML:
if (Document* responseXML = m_impl->getResponseXML())
return toJS(exec, responseXML);
return jsNull();
case Status: {
JSValue* result = jsNumber(m_impl->getStatus(ec));
setDOMException(exec, ec);
return result;
}
case StatusText: {
JSValue* result = jsString(m_impl->getStatusText(ec));
setDOMException(exec, ec);
return result;
}
case Onreadystatechange:
if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onReadyStateChangeListener()))
if (JSObject* listenerObj = listener->listenerObj())
return listenerObj;
return jsNull();
case Onload:
if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onLoadListener()))
if (JSObject* listenerObj = listener->listenerObj())
return listenerObj;
return jsNull();
default:
return 0;
}
}
void JSXMLHttpRequest::put(ExecState *exec, const Identifier &propertyName, JSValue* value, int attr)
void JSXMLHttpRequest::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr)
{
lookupPut<JSXMLHttpRequest,DOMObject>(exec, propertyName, value, attr, &JSXMLHttpRequestTable, this );
lookupPut<JSXMLHttpRequest,DOMObject>(exec, propertyName, value, attr, &JSXMLHttpRequestTable, this );
}
void JSXMLHttpRequest::putValueProperty(ExecState *exec, int token, JSValue* value, int /*attr*/)
void JSXMLHttpRequest::putValueProperty(ExecState* exec, int token, JSValue* value, int /*attr*/)
{
switch(token) {
case Onreadystatechange:
m_impl->setOnReadyStateChangeListener(Window::retrieveActive(exec)->getJSUnprotectedEventListener(value, true));
break;
case Onload:
m_impl->setOnLoadListener(Window::retrieveActive(exec)->getJSUnprotectedEventListener(value, true));
break;
}
switch (token) {
case Onreadystatechange:
m_impl->setOnReadyStateChangeListener(Window::retrieveActive(exec)->getJSUnprotectedEventListener(value, true));
break;
case Onload:
m_impl->setOnLoadListener(Window::retrieveActive(exec)->getJSUnprotectedEventListener(value, true));
break;
}
}
void JSXMLHttpRequest::mark()
{
DOMObject::mark();
DOMObject::mark();
JSUnprotectedEventListener* onReadyStateChangeListener = static_cast<JSUnprotectedEventListener*>(m_impl->onReadyStateChangeListener());
JSUnprotectedEventListener* onLoadListener = static_cast<JSUnprotectedEventListener*>(m_impl->onLoadListener());
JSUnprotectedEventListener* onReadyStateChangeListener = static_cast<JSUnprotectedEventListener*>(m_impl->onReadyStateChangeListener());
JSUnprotectedEventListener* onLoadListener = static_cast<JSUnprotectedEventListener*>(m_impl->onLoadListener());
if (onReadyStateChangeListener)
onReadyStateChangeListener->mark();
if (onReadyStateChangeListener)
onReadyStateChangeListener->mark();
if (onLoadListener)
onLoadListener->mark();
if (onLoadListener)
onLoadListener->mark();
}
JSXMLHttpRequest::JSXMLHttpRequest(ExecState *exec, Document *d)
JSXMLHttpRequest::JSXMLHttpRequest(ExecState* exec, Document* d)
: m_impl(new XMLHttpRequest(d))
{
setPrototype(JSXMLHttpRequestProto::self(exec));
ScriptInterpreter::putDOMObject(m_impl.get(), this);
setPrototype(JSXMLHttpRequestProto::self(exec));
ScriptInterpreter::putDOMObject(m_impl.get(), this);
}
JSXMLHttpRequest::~JSXMLHttpRequest()
{
m_impl->setOnReadyStateChangeListener(0);
m_impl->setOnLoadListener(0);
ScriptInterpreter::forgetDOMObject(m_impl.get());
m_impl->setOnReadyStateChangeListener(0);
m_impl->setOnLoadListener(0);
ScriptInterpreter::forgetDOMObject(m_impl.get());
}
JSValue* JSXMLHttpRequestProtoFunc::callAsFunction(ExecState *exec, JSObject* thisObj, const List& args)
JSValue* JSXMLHttpRequestProtoFunc::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
if (!thisObj->inherits(&JSXMLHttpRequest::info))
return throwError(exec, TypeError);
if (!thisObj->inherits(&JSXMLHttpRequest::info))
return throwError(exec, TypeError);
JSXMLHttpRequest *request = static_cast<JSXMLHttpRequest *>(thisObj);
JSXMLHttpRequest* request = static_cast<JSXMLHttpRequest*>(thisObj);
ExceptionCode ec = 0;
ExceptionCode ec = 0;
switch (id) {
case JSXMLHttpRequest::Abort:
request->m_impl->abort();
return jsUndefined();
case JSXMLHttpRequest::GetAllResponseHeaders:
return jsStringOrUndefined(request->m_impl->getAllResponseHeaders());
case JSXMLHttpRequest::GetResponseHeader:
if (args.size() < 1)
return throwError(exec, SyntaxError, "Not enough arguments");
return jsStringOrUndefined(request->m_impl->getResponseHeader(args[0]->toString(exec)));
case JSXMLHttpRequest::Open:
{
if (args.size() < 2)
return throwError(exec, SyntaxError, "Not enough arguments");
String method = args[0]->toString(exec);
KURL url = KURL(Window::retrieveActive(exec)->frame()->document()->completeURL(DeprecatedString(args[1]->toString(exec))));
bool async = true;
if (args.size() >= 3)
async = args[2]->toBoolean(exec);
String user;
if (args.size() >= 4)
user = args[3]->toString(exec);
String password;
if (args.size() >= 5)
password = args[4]->toString(exec);
request->m_impl->open(method, url, async, user, password, ec);
setDOMException(exec, ec);
return jsUndefined();
}
case JSXMLHttpRequest::Send:
{
String body;
if (args.size() >= 1) {
if (args[0]->toObject(exec)->inherits(&JSDocument::info)) {
Document *doc = static_cast<Document *>(static_cast<JSDocument *>(args[0]->toObject(exec))->impl());
body = doc->toString().deprecatedString();
} else {
// converting certain values (like null) to object can set an exception
if (exec->hadException())
exec->clearException();
else
body = args[0]->toString(exec);
switch (id) {
case JSXMLHttpRequest::Abort:
request->m_impl->abort();
return jsUndefined();
case JSXMLHttpRequest::GetAllResponseHeaders:
return jsStringOrUndefined(request->m_impl->getAllResponseHeaders());
case JSXMLHttpRequest::GetResponseHeader:
if (args.size() < 1)
return throwError(exec, SyntaxError, "Not enough arguments");
return jsStringOrUndefined(request->m_impl->getResponseHeader(args[0]->toString(exec)));
case JSXMLHttpRequest::Open: {
if (args.size() < 2)
return throwError(exec, SyntaxError, "Not enough arguments");
String method = args[0]->toString(exec);
KURL url = KURL(Window::retrieveActive(exec)->frame()->document()->completeURL(DeprecatedString(args[1]->toString(exec))));
bool async = true;
if (args.size() >= 3)
async = args[2]->toBoolean(exec);
String user;
if (args.size() >= 4)
user = args[3]->toString(exec);
String password;
if (args.size() >= 5)
password = args[4]->toString(exec);
request->m_impl->open(method, url, async, user, password, ec);
setDOMException(exec, ec);
return jsUndefined();
}
}
case JSXMLHttpRequest::Send: {
String body;
if (args.size() >= 1) {
if (args[0]->toObject(exec)->inherits(&JSDocument::info)) {
Document* doc = static_cast<Document*>(static_cast<JSDocument*>(args[0]->toObject(exec))->impl());
body = doc->toString().deprecatedString();
} else {
// converting certain values (like null) to object can set an exception
if (exec->hadException())
exec->clearException();
else
body = args[0]->toString(exec);
}
}
request->m_impl->send(body, ec);
setDOMException(exec, ec);
return jsUndefined();
}
case JSXMLHttpRequest::SetRequestHeader:
if (args.size() < 2)
return throwError(exec, SyntaxError, "Not enough arguments");
request->m_impl->setRequestHeader(args[0]->toString(exec), args[1]->toString(exec), ec);
setDOMException(exec, ec);
return jsUndefined();
request->m_impl->send(body, ec);
setDOMException(exec, ec);
case JSXMLHttpRequest::OverrideMIMEType:
if (args.size() < 1)
return throwError(exec, SyntaxError, "Not enough arguments");
return jsUndefined();
request->m_impl->overrideMIMEType(args[0]->toString(exec));
return jsUndefined();
}
case JSXMLHttpRequest::SetRequestHeader:
if (args.size() < 2)
return throwError(exec, SyntaxError, "Not enough arguments");
request->m_impl->setRequestHeader(args[0]->toString(exec), args[1]->toString(exec), ec);
setDOMException(exec, ec);
return jsUndefined();
case JSXMLHttpRequest::OverrideMIMEType:
if (args.size() < 1)
return throwError(exec, SyntaxError, "Not enough arguments");
request->m_impl->overrideMIMEType(args[0]->toString(exec));
return jsUndefined();
}
return jsUndefined();
return jsUndefined();
}
} // end namespace
......@@ -25,24 +25,26 @@
#include "kjs_binding.h"
namespace WebCore {
class XMLHttpRequest;
class Document;
class XMLHttpRequest;
class Document;
}
namespace KJS {
class JSXMLHttpRequestConstructorImp : public DOMObject {
public:
JSXMLHttpRequestConstructorImp(ExecState *exec, WebCore::Document *d);
class JSXMLHttpRequestConstructorImp : public DOMObject {
public:
JSXMLHttpRequestConstructorImp(ExecState*, WebCore::Document*);
virtual bool implementsConstruct() const;
virtual JSObject *construct(ExecState *exec, const List &args);
private:
virtual JSObject* construct(ExecState*, const List&);
private:
RefPtr<WebCore::Document> doc;
};
};
class JSXMLHttpRequest : public DOMObject {
public:
JSXMLHttpRequest(ExecState *, WebCore::Document *d);
class JSXMLHttpRequest : public DOMObject {
public:
JSXMLHttpRequest(ExecState*, WebCore::Document*);
~JSXMLHttpRequest();
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
......@@ -50,17 +52,17 @@ namespace KJS {
StatusText, Abort, GetAllResponseHeaders, GetResponseHeader, Open, Send, SetRequestHeader,
OverrideMIMEType };
virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
JSValue *getValueProperty(ExecState *exec, int token) const;
virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
void putValueProperty(ExecState *exec, int token, JSValue *value, int /*attr*/);
virtual bool toBoolean(ExecState *) const { return true; }
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
JSValue* getValueProperty(ExecState*, int token) const;
virtual void put(ExecState*, const Identifier& propertyName, JSValue* value, int attr = None);
void putValueProperty(ExecState*, int token, JSValue* value, int /*attr*/);
virtual bool toBoolean(ExecState*) const { return true; }
virtual void mark();
private:
private:
friend class JSXMLHttpRequestProtoFunc;
RefPtr<WebCore::XMLHttpRequest> m_impl;
};
};
} // namespace
......
......@@ -186,10 +186,10 @@ void XMLHttpRequest::setOnLoadListener(EventListener* eventListener)
m_onLoadListener = eventListener;
}
XMLHttpRequest::XMLHttpRequest(Document *d)
XMLHttpRequest::XMLHttpRequest(Document* d)
: m_doc(d)
, m_async(true)
, m_job(0)
, m_loader(0)
, m_state(Uninitialized)
, m_response("", 0)
, m_createdDocument(false)
......@@ -224,7 +224,7 @@ void XMLHttpRequest::callReadyStateChangeListener()
bool XMLHttpRequest::urlMatchesDocumentDomain(const KURL& url) const
{
KURL documentURL(m_doc->URL());
KURL documentURL(m_doc->URL());
// a local file can load anything
if (documentURL.protocol().lower() == "file")
......@@ -291,8 +291,8 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
return;
}
// FIXME: Should this abort or raise an exception instead if we already have a m_job going?
if (m_job)
// FIXME: Should this abort or raise an exception instead if we already have a m_loader going?
if (m_loader)
return;
m_aborted = false;
......@@ -314,16 +314,16 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
if (!m_encoding.isValid()) // FIXME: report an error?
m_encoding = UTF8Encoding();
m_job = new ResourceLoader(m_async ? this : 0, m_method, m_url, m_encoding.encode(body.characters(), body.length()));
m_loader = new ResourceLoader(m_async ? this : 0, m_method, m_url, m_encoding.encode(body.characters(), body.length()));
} else {
// FIXME: HEAD requests just crash; see <rdar://4460899> and the commented out tests in http/tests/xmlhttprequest/methods.html.
if (m_method == "HEAD")
m_method = "GET";
m_job = new ResourceLoader(m_async ? this : 0, m_method, m_url);
m_loader = new ResourceLoader(m_async ? this : 0, m_method, m_url);
}
if (m_requestHeaders.length())
m_job->addMetaData("customHTTPHeader", m_requestHeaders);
m_loader->addMetaData("customHTTPHeader", m_requestHeaders);
if (!m_async) {
Vector<char> data;
......@@ -333,10 +333,10 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
{
// avoid deadlock in case the loader wants to use JS on a background thread
KJS::JSLock::DropAllLocks dropLocks;
data = ServeSynchronousRequest(Cache::loader(), m_doc->docLoader(), m_job, finalURL, headers);
data = ServeSynchronousRequest(Cache::loader(), m_doc->docLoader(), m_loader, finalURL, headers);
}
m_job = 0;
m_loader = 0;
processSyncLoadResults(data, finalURL, headers);
return;
......@@ -351,24 +351,24 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
gcProtectNullTolerant(KJS::ScriptInterpreter::getDOMObject(this));
}
if (!m_job->start(m_doc->docLoader())) {
if (!m_loader->start(m_doc->docLoader())) {
LOG_ERROR("Failed to send an XMLHttpRequest for %s", m_url.url().ascii());
m_job = 0;
m_loader = 0;
}
}
void XMLHttpRequest::abort()
{
bool hadJob = m_job;
bool hadLoader = m_loader;
if (hadJob) {
m_job->kill();
m_job = 0;
if (hadLoader) {
m_loader->kill();
m_loader = 0;
}
m_decoder = 0;
m_aborted = true;
if (hadJob) {
if (hadLoader) {
{
KJS::JSLock lock;
gcUnprotectNullTolerant(KJS::ScriptInterpreter::getDOMObject(this));
......@@ -522,8 +522,8 @@ void XMLHttpRequest::processSyncLoadResults(const Vector<char>& data, const KURL
void XMLHttpRequest::receivedAllData(ResourceLoader*)
{
if (m_responseHeaders.isEmpty() && m_job)
m_responseHeaders = m_job->queryMetaData("HTTP-Headers");
if (m_responseHeaders.isEmpty() && m_loader)
m_responseHeaders = m_loader->queryMetaData("HTTP-Headers");
if (m_state < Sent)
changeState(Sent);
......@@ -531,13 +531,13 @@ void XMLHttpRequest::receivedAllData(ResourceLoader*)
if (m_decoder)
m_response += m_decoder->flush();
bool hadJob = m_job;
m_job = 0;
bool hadLoader = m_loader;
m_loader = 0;
changeState(Loaded);
m_decoder = 0;
if (hadJob) {
if (hadLoader) {
{
KJS::JSLock lock;
gcUnprotectNullTolerant(KJS::ScriptInterpreter::getDOMObject(this));
......@@ -552,10 +552,10 @@ void XMLHttpRequest::receivedRedirect(ResourceLoader*, const KURL& m_url)
abort();
}
void XMLHttpRequest::receivedData(ResourceLoader*, const char *data, int len)
void XMLHttpRequest::receivedData(ResourceLoader*, const char* data, int len)
{
if (m_responseHeaders.isEmpty() && m_job)
m_responseHeaders = m_job->queryMetaData("HTTP-Headers");
if (m_responseHeaders.isEmpty() && m_loader)
m_responseHeaders = m_loader->queryMetaData("HTTP-Headers");
if (m_state < Sent)
changeState(Sent);
......@@ -564,8 +564,8 @@ void XMLHttpRequest::receivedData(ResourceLoader*, const char *data, int len)
m_encoding = getCharset(m_mimeTypeOverride);
if (m_encoding.isEmpty())
m_encoding = getCharset(getResponseHeader("Content-Type"));
if (m_encoding.isEmpty() && m_job)
m_encoding = m_job->queryMetaData("charset");
if (m_encoding.isEmpty() && m_loader)
m_encoding = m_loader->queryMetaData("charset");
if (!m_encoding.isEmpty())
m_decoder = new Decoder("text/plain", m_encoding);
......
......@@ -29,28 +29,28 @@
namespace WebCore {
class Decoder;
class Document;
class EventListener;
class String;
class Decoder;