зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1242054. Get rid of AbortablePromise, so we can move Promise into SpiderMonkey more easily. r=khuey
This commit is contained in:
Родитель
c136be558a
Коммит
d4db9bedd0
|
@ -80,10 +80,6 @@ DOMInterfaces = {
|
|||
'nativeType': 'mozilla::dom::Activity',
|
||||
},
|
||||
|
||||
'MozAbortablePromise': {
|
||||
'nativeType': 'mozilla::dom::AbortablePromise',
|
||||
},
|
||||
|
||||
'AbstractWorker': {
|
||||
'concrete': False
|
||||
},
|
||||
|
|
|
@ -5037,11 +5037,6 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
return JSToNativeConversionInfo(template, declType=declType,
|
||||
dealWithOptional=isOptional)
|
||||
|
||||
if descriptor.interface.identifier.name == "AbortablePromise":
|
||||
raise TypeError("Need to figure out what argument conversion "
|
||||
"should look like for AbortablePromise: %s" %
|
||||
sourceDescription)
|
||||
|
||||
# This is an interface that we implement as a concrete class
|
||||
# or an XPCOM interface.
|
||||
|
||||
|
@ -7149,8 +7144,7 @@ class CGPerSignatureCall(CGThing):
|
|||
|
||||
# Hack for making Promise.prototype.then work well over Xrays.
|
||||
if (not static and
|
||||
(descriptor.name == "Promise" or
|
||||
descriptor.name == "MozAbortablePromise") and
|
||||
descriptor.name == "Promise" and
|
||||
idlNode.isMethod() and
|
||||
idlNode.identifier.name == "then"):
|
||||
cgThings.append(CGGeneric(dedent(
|
||||
|
@ -7162,7 +7156,7 @@ class CGPerSignatureCall(CGThing):
|
|||
needsUnwrap = False
|
||||
argsPost = []
|
||||
if isConstructor:
|
||||
if descriptor.name == "Promise" or descriptor.name == "MozAbortablePromise":
|
||||
if descriptor.name == "Promise":
|
||||
# Hack for Promise for now: pass in our desired proto so the
|
||||
# implementation can create the reflector with the right proto.
|
||||
argsPost.append("desiredProto")
|
||||
|
|
|
@ -1,118 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#include "mozilla/dom/AbortablePromise.h"
|
||||
|
||||
#include "mozilla/dom/AbortablePromiseBinding.h"
|
||||
#include "mozilla/dom/PromiseNativeAbortCallback.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "PromiseCallback.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(PromiseNativeAbortCallback)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(PromiseNativeAbortCallback)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PromiseNativeAbortCallback)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
NS_IMPL_CYCLE_COLLECTION_0(PromiseNativeAbortCallback)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(AbortablePromise, Promise)
|
||||
NS_IMPL_RELEASE_INHERITED(AbortablePromise, Promise)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(AbortablePromise)
|
||||
NS_INTERFACE_MAP_END_INHERITING(Promise)
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(AbortablePromise, Promise, mAbortCallback)
|
||||
|
||||
AbortablePromise::AbortablePromise(nsIGlobalObject* aGlobal,
|
||||
PromiseNativeAbortCallback& aAbortCallback)
|
||||
: Promise(aGlobal)
|
||||
, mAbortCallback(&aAbortCallback)
|
||||
{
|
||||
}
|
||||
|
||||
AbortablePromise::AbortablePromise(nsIGlobalObject* aGlobal)
|
||||
: Promise(aGlobal)
|
||||
{
|
||||
}
|
||||
|
||||
AbortablePromise::~AbortablePromise()
|
||||
{
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<AbortablePromise>
|
||||
AbortablePromise::Create(nsIGlobalObject* aGlobal,
|
||||
PromiseNativeAbortCallback& aAbortCallback,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
RefPtr<AbortablePromise> p = new AbortablePromise(aGlobal, aAbortCallback);
|
||||
p->CreateWrapper(nullptr, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
JSObject*
|
||||
AbortablePromise::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return MozAbortablePromiseBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<AbortablePromise>
|
||||
AbortablePromise::Constructor(const GlobalObject& aGlobal, PromiseInit& aInit,
|
||||
AbortCallback& aAbortCallback, ErrorResult& aRv,
|
||||
JS::Handle<JSObject*> aDesiredProto)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global;
|
||||
global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
if (!global) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<AbortablePromise> promise = new AbortablePromise(global);
|
||||
promise->CreateWrapper(aDesiredProto, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
promise->CallInitFunction(aGlobal, aInit, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
promise->mAbortCallback = &aAbortCallback;
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
void
|
||||
AbortablePromise::Abort()
|
||||
{
|
||||
if (IsPending()) {
|
||||
return;
|
||||
}
|
||||
MaybeReject(NS_ERROR_ABORT);
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable =
|
||||
NS_NewRunnableMethod(this, &AbortablePromise::DoAbort);
|
||||
Promise::DispatchToMicroTask(runnable);
|
||||
}
|
||||
|
||||
void
|
||||
AbortablePromise::DoAbort()
|
||||
{
|
||||
if (mAbortCallback.HasWebIDLCallback()) {
|
||||
mAbortCallback.GetWebIDLCallback()->Call();
|
||||
return;
|
||||
}
|
||||
mAbortCallback.GetXPCOMCallback()->Call();
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -1,67 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_AbortablePromise_h__
|
||||
#define mozilla_dom_AbortablePromise_h__
|
||||
|
||||
#include "js/TypeDecls.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/CallbackObject.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class AbortCallback;
|
||||
class PromiseNativeAbortCallback;
|
||||
|
||||
class AbortablePromise
|
||||
: public Promise
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AbortablePromise, Promise)
|
||||
|
||||
public:
|
||||
// It is the same as Promise::Create except that this takes an extra
|
||||
// aAbortCallback parameter to set the abort callback handler.
|
||||
static already_AddRefed<AbortablePromise>
|
||||
Create(nsIGlobalObject* aGlobal, PromiseNativeAbortCallback& aAbortCallback,
|
||||
ErrorResult& aRv);
|
||||
|
||||
protected:
|
||||
// Constructor used to create native AbortablePromise with C++.
|
||||
AbortablePromise(nsIGlobalObject* aGlobal,
|
||||
PromiseNativeAbortCallback& aAbortCallback);
|
||||
|
||||
// Constructor used to create AbortablePromise for JavaScript. It should be
|
||||
// called by the static AbortablePromise::Constructor.
|
||||
explicit AbortablePromise(nsIGlobalObject* aGlobal);
|
||||
|
||||
virtual ~AbortablePromise();
|
||||
|
||||
public:
|
||||
virtual JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
static already_AddRefed<AbortablePromise>
|
||||
Constructor(const GlobalObject& aGlobal, PromiseInit& aInit,
|
||||
AbortCallback& aAbortCallback, ErrorResult& aRv,
|
||||
JS::Handle<JSObject*> aDesiredProto);
|
||||
|
||||
void Abort();
|
||||
|
||||
private:
|
||||
void DoAbort();
|
||||
|
||||
// The callback functions to abort the promise.
|
||||
CallbackObjectHolder<AbortCallback,
|
||||
PromiseNativeAbortCallback> mAbortCallback;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_AbortablePromise_h__
|
|
@ -1,36 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_PromiseNativeAbortCallback_h
|
||||
#define mozilla_dom_PromiseNativeAbortCallback_h
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
/*
|
||||
* PromiseNativeAbortCallback allows C++ to react to an AbortablePromise being
|
||||
* aborted.
|
||||
*/
|
||||
class PromiseNativeAbortCallback : public nsISupports
|
||||
{
|
||||
protected:
|
||||
virtual ~PromiseNativeAbortCallback()
|
||||
{ }
|
||||
|
||||
public:
|
||||
// Implemented in AbortablePromise.cpp.
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(PromiseNativeAbortCallback)
|
||||
|
||||
virtual void Call() = 0;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_PromiseNativeAbortCallback_h
|
|
@ -5,16 +5,13 @@
|
|||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
EXPORTS.mozilla.dom += [
|
||||
'AbortablePromise.h',
|
||||
'Promise.h',
|
||||
'PromiseDebugging.h',
|
||||
'PromiseNativeAbortCallback.h',
|
||||
'PromiseNativeHandler.h',
|
||||
'PromiseWorkerProxy.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'AbortablePromise.cpp',
|
||||
'Promise.cpp',
|
||||
'PromiseCallback.cpp',
|
||||
'PromiseDebugging.cpp'
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
# to go in here, not chrome.ini, apparently.
|
||||
support-files = file_promise_xrays.html
|
||||
|
||||
[test_abortable_promise.html]
|
||||
[test_bug883683.html]
|
||||
[test_promise.html]
|
||||
[test_promise_utils.html]
|
||||
|
|
|
@ -1,116 +0,0 @@
|
|||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Promise.resolve(anything) Test</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript"><!--
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.requestFlakyTimeout("untriaged");
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.abortablepromise.enabled", true]]},
|
||||
runTest);
|
||||
var gTests = [testPending, testResolved, testRejected];
|
||||
|
||||
function runTest() {
|
||||
if (gTests.length == 0) {
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
new Promise(gTests.shift()).then(runTest, SimpleTest.finish);
|
||||
}
|
||||
|
||||
// Aborting pending promise should first reject the promise and then call the
|
||||
// abortable callback.
|
||||
// The test succeeds once both the rejection handler and the abort handler have
|
||||
// been called.
|
||||
function testPending(succeed, fail) {
|
||||
var rejected = false;
|
||||
var aborted = false;
|
||||
|
||||
var p = new MozAbortablePromise(function(resolve, reject) {
|
||||
// Wait for a while so that the promise can be aborted before resolved.
|
||||
SimpleTest.executeSoon(function() {
|
||||
resolve(0);
|
||||
});
|
||||
}, function abortable() {
|
||||
aborted = true;
|
||||
ok(true, "Promise aborted.");
|
||||
if (rejected) {
|
||||
succeed();
|
||||
}
|
||||
});
|
||||
|
||||
p.then(function() {
|
||||
ok(false, "Failed to abort pending promise.");
|
||||
fail();
|
||||
}, function(what) {
|
||||
rejected = true;
|
||||
var isAbortException = (what && what.name) == "NS_ERROR_ABORT";
|
||||
ok(isAbortException, "Should have NS_ERROR_ABORT exception");
|
||||
if (!isAbortException) {
|
||||
fail();
|
||||
}
|
||||
if (aborted) {
|
||||
succeed();
|
||||
}
|
||||
});
|
||||
|
||||
// Abort the promise on creation.
|
||||
p.abort();
|
||||
}
|
||||
|
||||
// Do nothing when aborting resolved promise.
|
||||
function testResolved(succeed, fail) {
|
||||
var p = new MozAbortablePromise(function(resolve, reject) {
|
||||
resolve();
|
||||
}, function abortable() {
|
||||
ok(false, "Should not abort a resolved promise.");
|
||||
fail();
|
||||
});
|
||||
p.then(function() {
|
||||
ok(true, "Promise resolved.");
|
||||
// Wait for a while to ensure abort handle won't be called.
|
||||
setTimeout(succeed, 1000);
|
||||
}, function(what) {
|
||||
ok(false, "Failed to resolve promise: " + what);
|
||||
fail();
|
||||
});
|
||||
p.abort();
|
||||
}
|
||||
|
||||
// Do nothing when aborting rejected promise.
|
||||
function testRejected(succeed, fail) {
|
||||
var p = new MozAbortablePromise(function(resolve, reject) {
|
||||
reject(0);
|
||||
}, function abortable() {
|
||||
ok(false, "Should not abort a rejected promise.");
|
||||
fail();
|
||||
});
|
||||
|
||||
p.then(function() {
|
||||
ok(false, "Failed to reject promise.");
|
||||
fail();
|
||||
}, function(what) {
|
||||
is(what, 0, "promise rejected: " + what);
|
||||
// Wait for a while to ensure abort handle won't be called.
|
||||
setTimeout(succeed, 1000);
|
||||
});
|
||||
p.abort();
|
||||
}
|
||||
// -->
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -118,8 +118,6 @@ var legacyMozPrefixedInterfaces =
|
|||
// IMPORTANT: Do not change the list below without review from a DOM peer!
|
||||
var interfaceNamesInGlobalScope =
|
||||
[
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{name: "MozAbortablePromise", disabled: true},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{name: "AlarmsManager", b2g: true},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
callback AbortCallback = void ();
|
||||
|
||||
[Constructor(PromiseInit init, AbortCallback abortCallback),
|
||||
Pref="dom.abortablepromise.enabled"]
|
||||
interface MozAbortablePromise : _Promise {
|
||||
/*
|
||||
* Aborts the promise.
|
||||
* If the promise has not been resolved or rejected, it should be rejected
|
||||
* with an Exception of type abort and then AbortCallback is called
|
||||
* asynchronously. Otherwise, nothing should be done.
|
||||
*/
|
||||
void abort();
|
||||
};
|
|
@ -16,7 +16,6 @@ PREPROCESSED_WEBIDL_FILES = [
|
|||
]
|
||||
|
||||
WEBIDL_FILES = [
|
||||
'AbortablePromise.webidl',
|
||||
'AbstractWorker.webidl',
|
||||
'ActivityRequestHandler.webidl',
|
||||
'AlarmsManager.webidl',
|
||||
|
|
|
@ -8470,8 +8470,7 @@ AssertIsPromise(JSContext* cx, HandleObject promise)
|
|||
{
|
||||
MOZ_ASSERT(promise);
|
||||
assertSameCompartment(cx, promise);
|
||||
MOZ_ASSERT(strcmp(promise->getClass()->name, "Promise") == 0 ||
|
||||
strcmp(promise->getClass()->name, "MozAbortablePromise") == 0);
|
||||
MOZ_ASSERT(strcmp(promise->getClass()->name, "Promise") == 0);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
|
|
|
@ -112,9 +112,6 @@ pref("offline-apps.quota.warn", 51200);
|
|||
// cache compression turned off for now - see bug #715198
|
||||
pref("browser.cache.compression_level", 0);
|
||||
|
||||
// Whether or not MozAbortablePromise is enabled.
|
||||
pref("dom.abortablepromise.enabled", false);
|
||||
|
||||
// Whether or not testing features are enabled.
|
||||
pref("dom.quotaManager.testing", false);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче