Bug 1167650 - Expose DOMRequest and DOMCursor to workers. r=bent

This commit is contained in:
Andrew Osmond 2015-06-28 09:34:01 -07:00
parent f61e34d148
commit d4dbf7328b
8 changed files with 31 additions and 16 deletions

View File

@ -27,6 +27,13 @@ DOMCursor::DOMCursor(nsPIDOMWindow* aWindow, nsICursorContinueCallback* aCallbac
{
}
DOMCursor::DOMCursor(nsIGlobalObject* aGlobal, nsICursorContinueCallback* aCallback)
: DOMRequest(aGlobal)
, mCallback(aCallback)
, mFinished(false)
{
}
void
DOMCursor::Reset()
{

View File

@ -26,6 +26,7 @@ public:
DOMRequest)
DOMCursor(nsPIDOMWindow* aWindow, nsICursorContinueCallback *aCallback);
DOMCursor(nsIGlobalObject* aGlobal, nsICursorContinueCallback *aCallback);
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;

View File

@ -20,7 +20,7 @@ using mozilla::dom::DOMRequest;
using mozilla::dom::DOMRequestService;
using mozilla::dom::DOMCursor;
using mozilla::dom::Promise;
using mozilla::AutoSafeJSContext;
using mozilla::dom::AutoJSAPI;
DOMRequest::DOMRequest(nsPIDOMWindow* aWindow)
: DOMEventTargetHelper(aWindow->IsInnerWindow() ?
@ -30,6 +30,13 @@ DOMRequest::DOMRequest(nsPIDOMWindow* aWindow)
{
}
DOMRequest::DOMRequest(nsIGlobalObject* aGlobal)
: DOMEventTargetHelper(aGlobal)
, mResult(JS::UndefinedValue())
, mDone(false)
{
}
DOMRequest::~DOMRequest()
{
mResult.setUndefined();
@ -235,6 +242,7 @@ NS_IMETHODIMP
DOMRequestService::CreateRequest(nsIDOMWindow* aWindow,
nsIDOMDOMRequest** aRequest)
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(aWindow));
NS_ENSURE_STATE(win);
NS_ADDREF(*aRequest = new DOMRequest(win));
@ -306,13 +314,9 @@ public:
Dispatch(DOMRequest* aRequest,
const JS::Value& aResult)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
mozilla::ThreadsafeAutoSafeJSContext cx;
nsRefPtr<FireSuccessAsyncTask> asyncTask = new FireSuccessAsyncTask(cx, aRequest, aResult);
if (NS_FAILED(NS_DispatchToMainThread(asyncTask))) {
NS_WARNING("Failed to dispatch to main thread!");
return NS_ERROR_FAILURE;
}
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToCurrentThread(asyncTask)));
return NS_OK;
}
@ -323,11 +327,6 @@ public:
return NS_OK;
}
~FireSuccessAsyncTask()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
}
private:
nsRefPtr<DOMRequest> mReq;
JS::PersistentRooted<JS::Value> mResult;
@ -369,10 +368,7 @@ DOMRequestService::FireErrorAsync(nsIDOMDOMRequest* aRequest,
NS_ENSURE_STATE(aRequest);
nsCOMPtr<nsIRunnable> asyncTask =
new FireErrorAsyncTask(static_cast<DOMRequest*>(aRequest), aError);
if (NS_FAILED(NS_DispatchToMainThread(asyncTask))) {
NS_WARNING("Failed to dispatch to main thread!");
return NS_ERROR_FAILURE;
}
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToCurrentThread(asyncTask)));
return NS_OK;
}

View File

@ -84,6 +84,7 @@ public:
void FireDetailedError(DOMError* aError);
explicit DOMRequest(nsPIDOMWindow* aWindow);
explicit DOMRequest(nsIGlobalObject* aGlobal);
protected:
virtual ~DOMRequest();

View File

@ -3,6 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
[Exposed=(Window,Worker)]
interface DOMCursor : EventTarget {
readonly attribute boolean done;
[Throws]

View File

@ -5,7 +5,7 @@
enum DOMRequestReadyState { "pending", "done" };
[NoInterfaceObject]
[Exposed=(Window,Worker), NoInterfaceObject]
interface DOMRequestShared {
readonly attribute DOMRequestReadyState readyState;
@ -16,6 +16,7 @@ interface DOMRequestShared {
attribute EventHandler onerror;
};
[Exposed=(Window,Worker)]
interface DOMRequest : EventTarget {
// The [TreatNonCallableAsNull] annotation is required since then() should do
// nothing instead of throwing errors when non-callable arguments are passed.

View File

@ -102,10 +102,14 @@ var interfaceNamesInGlobalScope =
{ name: "DataStore", b2g: true },
// IMPORTANT: Do not change this list without review from a DOM peer!
{ name: "DataStoreCursor", b2g: true },
// IMPORTANT: Do not change this list without review from a DOM peer!
"DOMCursor",
// IMPORTANT: Do not change this list without review from a DOM peer!
"DOMError",
// IMPORTANT: Do not change this list without review from a DOM peer!
"DOMException",
// IMPORTANT: Do not change this list without review from a DOM peer!
"DOMRequest",
// IMPORTANT: Do not change this list without review from a DOM peer!
"DOMStringList",
// IMPORTANT: Do not change this list without review from a DOM peer!

View File

@ -98,10 +98,14 @@ var interfaceNamesInGlobalScope =
{ name: "DataStore", b2g: true },
// IMPORTANT: Do not change this list without review from a DOM peer!
{ name: "DataStoreCursor", b2g: true },
// IMPORTANT: Do not change this list without review from a DOM peer!
"DOMCursor",
// IMPORTANT: Do not change this list without review from a DOM peer!
"DOMError",
// IMPORTANT: Do not change this list without review from a DOM peer!
"DOMException",
// IMPORTANT: Do not change this list without review from a DOM peer!
"DOMRequest",
// IMPORTANT: Do not change this list without review from a DOM peer!
"DOMStringList",
// IMPORTANT: Do not change this list without review from a DOM peer!