mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-02 20:42:49 +00:00
Bug 885701 - [DOMRequest] Implement DOMRequestService.fireDetailedError. r,sr=sicking
This commit is contained in:
parent
4b30bbfc5b
commit
2001687ad7
@ -157,6 +157,20 @@ DOMRequest::FireError(nsresult aError)
|
||||
FireEvent(NS_LITERAL_STRING("error"), true, true);
|
||||
}
|
||||
|
||||
void
|
||||
DOMRequest::FireDetailedError(nsISupports* aError)
|
||||
{
|
||||
NS_ASSERTION(!mDone, "mDone shouldn't have been set to true already!");
|
||||
NS_ASSERTION(!mError, "mError shouldn't have been set!");
|
||||
NS_ASSERTION(mResult == JSVAL_VOID, "mResult shouldn't have been set!");
|
||||
NS_ASSERTION(aError, "No detailed error provided");
|
||||
|
||||
mDone = true;
|
||||
mError = aError;
|
||||
|
||||
FireEvent(NS_LITERAL_STRING("error"), true, true);
|
||||
}
|
||||
|
||||
void
|
||||
DOMRequest::FireEvent(const nsAString& aType, bool aBubble, bool aCancelable)
|
||||
{
|
||||
@ -239,6 +253,16 @@ DOMRequestService::FireError(nsIDOMDOMRequest* aRequest,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DOMRequestService::FireDetailedError(nsIDOMDOMRequest* aRequest,
|
||||
nsISupports* aError)
|
||||
{
|
||||
NS_ENSURE_STATE(aRequest);
|
||||
static_cast<DOMRequest*>(aRequest)->FireDetailedError(aError);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
class FireSuccessAsyncTask : public nsRunnable
|
||||
{
|
||||
|
||||
|
@ -23,7 +23,7 @@ class DOMRequest : public nsDOMEventTargetHelper,
|
||||
{
|
||||
protected:
|
||||
JS::Heap<JS::Value> mResult;
|
||||
nsRefPtr<DOMError> mError;
|
||||
nsCOMPtr<nsISupports> mError;
|
||||
bool mDone;
|
||||
bool mRooted;
|
||||
|
||||
@ -58,7 +58,7 @@ public:
|
||||
return mResult;
|
||||
}
|
||||
|
||||
DOMError* GetError() const
|
||||
nsISupports* GetError() const
|
||||
{
|
||||
NS_ASSERTION(mDone || !mError,
|
||||
"Error should be null when pending");
|
||||
@ -72,6 +72,7 @@ public:
|
||||
void FireSuccess(JS::Handle<JS::Value> aResult);
|
||||
void FireError(const nsAString& aError);
|
||||
void FireError(nsresult aError);
|
||||
void FireDetailedError(nsISupports* aError);
|
||||
|
||||
DOMRequest(nsIDOMWindow* aWindow);
|
||||
DOMRequest();
|
||||
|
@ -24,7 +24,7 @@ interface nsIDOMDOMRequest : nsIDOMEventTarget
|
||||
[implicit_jscontext] attribute jsval onerror;
|
||||
};
|
||||
|
||||
[scriptable, builtinclass, uuid(060df968-fd71-47ca-91a8-6b64dadceb2c)]
|
||||
[scriptable, builtinclass, uuid(df58d5d6-4b02-4e4c-9b29-adbff06c6206)]
|
||||
interface nsIDOMRequestService : nsISupports
|
||||
{
|
||||
nsIDOMDOMRequest createRequest(in nsIDOMWindow window);
|
||||
@ -38,6 +38,7 @@ interface nsIDOMRequestService : nsISupports
|
||||
|
||||
void fireSuccess(in nsIDOMDOMRequest request, in jsval result);
|
||||
void fireError(in nsIDOMDOMRequest request, in DOMString error);
|
||||
void fireDetailedError(in nsIDOMDOMRequest request, in nsISupports error);
|
||||
void fireSuccessAsync(in nsIDOMDOMRequest request, in jsval result);
|
||||
void fireErrorAsync(in nsIDOMDOMRequest request, in DOMString error);
|
||||
void fireDone(in nsIDOMDOMCursor cursor);
|
||||
|
@ -50,13 +50,26 @@ req.onerror = function(e) {
|
||||
ev = e;
|
||||
}
|
||||
reqserv.fireError(req, "OhMyError");
|
||||
ok(ev, "got success event");
|
||||
ok(ev, "got error event");
|
||||
is(ev.type, "error", "correct type during error");
|
||||
is(ev.target, req, "correct target during error");
|
||||
is(req.readyState, "done", "correct readyState after error");
|
||||
is(req.error.name, "OhMyError", "correct error after error");
|
||||
is(req.result, undefined, "correct result after error");
|
||||
|
||||
// fire detailed error
|
||||
req = reqserv.createRequest(window);
|
||||
ev = null;
|
||||
req.onerror = function(e) {
|
||||
ev = e;
|
||||
};
|
||||
reqserv.fireDetailedError(req, new DOMError("detailedError"));
|
||||
ok(ev, "got error event");
|
||||
is(ev.type, "error", "correct type during error");
|
||||
is(ev.target, req, "correct target during error");
|
||||
is(req.readyState, "done", "correct readyState after error");
|
||||
is(req.error.name, "detailedError", "correct error after error");
|
||||
is(req.result, undefined, "correct result after error");
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
@ -4,6 +4,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
interface Window;
|
||||
interface nsISupports;
|
||||
|
||||
enum DOMRequestReadyState { "pending", "done" };
|
||||
|
||||
@ -11,7 +12,7 @@ interface DOMRequest : EventTarget {
|
||||
readonly attribute DOMRequestReadyState readyState;
|
||||
|
||||
readonly attribute any result;
|
||||
readonly attribute DOMError? error;
|
||||
readonly attribute nsISupports? error;
|
||||
|
||||
[SetterThrows]
|
||||
attribute EventHandler onsuccess;
|
||||
|
@ -1251,7 +1251,8 @@ SpecialPowersAPI.prototype = {
|
||||
var serv = Cc["@mozilla.org/dom/dom-request-service;1"].
|
||||
getService(Ci.nsIDOMRequestService);
|
||||
var res = { __exposedProps__: {} };
|
||||
var props = ["createRequest", "createCursor", "fireError", "fireSuccess", "fireDone"];
|
||||
var props = ["createRequest", "createCursor", "fireError", "fireSuccess",
|
||||
"fireDone", "fireDetailedError"];
|
||||
for (i in props) {
|
||||
let prop = props[i];
|
||||
res[prop] = function() { return serv[prop].apply(serv, arguments) };
|
||||
|
Loading…
x
Reference in New Issue
Block a user