Bug 918806 - Enable DOM Promises. sr=bz

--HG--
extra : rebase_source : dbc7ef836fe7c2a71f38fedda004d7f988361a85
This commit is contained in:
Nikhil Marathe 2014-01-30 13:14:00 -08:00
parent 9cea3e07cf
commit 16a3c5ed8b
14 changed files with 14 additions and 74 deletions

View File

@ -814,9 +814,6 @@ pref("network.sntp.pools", // Servers separated by ';'.
pref("network.sntp.port", 123);
pref("network.sntp.timeout", 30); // In seconds.
// Enable promise
pref("dom.promise.enabled", false);
// Enable dataStore
#ifdef RELEASE_BUILD
pref("dom.datastore.enabled", false);

View File

@ -244,28 +244,6 @@ Promise::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
return PromiseBinding::Wrap(aCx, aScope, this);
}
/* static */ bool
Promise::EnabledForScope(JSContext* aCx, JSObject* /* unused */)
{
if (NS_IsMainThread()) {
// No direct return so the chrome/certified app checks happen below.
if (Preferences::GetBool("dom.promise.enabled", false)) {
return true;
}
} else {
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
return workerPrivate->PromiseEnabled() || workerPrivate->UsesSystemPrincipal();
}
// Enable if the pref is enabled or if we're chrome or if we're a
// certified app.
// Note that we have no concept of a certified app in workers.
// XXXbz well, why not?
// FIXME(nsm): Remove these checks once promises are enabled by default.
nsIPrincipal* prin = nsContentUtils::GetSubjectPrincipal();
return nsContentUtils::IsSystemPrincipal(prin) ||
prin->GetAppStatus() == nsIPrincipal::APP_STATUS_CERTIFIED;
}
void
Promise::MaybeResolve(JSContext* aCx,
JS::Handle<JS::Value> aValue)

View File

@ -45,8 +45,6 @@ public:
Promise(nsPIDOMWindow* aWindow);
~Promise();
static bool EnabledForScope(JSContext* aCx, JSObject* /* unused */);
void MaybeResolve(JSContext* aCx,
JS::Handle<JS::Value> aValue);
void MaybeReject(JSContext* aCx,

View File

@ -33,7 +33,7 @@ function runTest() {
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.promise.enabled", true]]}, runTest);
runTest();
// -->
</script>
</pre>

View File

@ -611,13 +611,8 @@ function runTest() {
test();
}
var p = SpecialPowers.getBoolPref("dom.promise.enabled");
SpecialPowers.setBoolPref("dom.promise.enabled", false);
ok(!("Promise" in window), "Promise object should not exist if disabled by pref");
SpecialPowers.setBoolPref("dom.promise.enabled", p);
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.promise.enabled", true]]}, runTest);
runTest();
// -->
</script>
</pre>

View File

@ -316,7 +316,7 @@ function runTest() {
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.promise.enabled", true]]}, runTest);
runTest();
// -->
</script>
</pre>

View File

@ -58,7 +58,7 @@ function runTest() {
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.promise.enabled", true]]}, runTest);
runTest();
// -->
</script>
</pre>

View File

@ -15,7 +15,7 @@ callback PromiseInit = void (object resolve, object reject);
[TreatNonCallableAsNull]
callback AnyCallback = any (any value);
[Func="mozilla::dom::Promise::EnabledForScope", Constructor(PromiseInit init)]
[Constructor(PromiseInit init)]
interface Promise {
// TODO bug 875289 - static Promise fulfill(any value);
@ -24,9 +24,9 @@ interface Promise {
// the proto of a promise object or someone screws up and manages to create a
// Promise object in this scope without having resolved the interface object
// first.
[NewObject, Throws, Func="mozilla::dom::Promise::EnabledForScope"]
[NewObject, Throws]
static Promise resolve(optional any value);
[NewObject, Throws, Func="mozilla::dom::Promise::EnabledForScope"]
[NewObject, Throws]
static Promise reject(optional any value);
// The [TreatNonCallableAsNull] annotation is required since then() should do
@ -38,12 +38,12 @@ interface Promise {
[NewObject]
Promise catch([TreatNonCallableAsNull] optional AnyCallback? rejectCallback = null);
[NewObject, Throws, Func="mozilla::dom::Promise::EnabledForScope"]
[NewObject, Throws]
static Promise all(sequence<any> iterable);
[NewObject, Throws, Func="mozilla::dom::Promise::EnabledForScope"]
[NewObject, Throws]
static Promise cast(optional any value);
[NewObject, Throws, Func="mozilla::dom::Promise::EnabledForScope"]
[NewObject, Throws]
static Promise race(sequence<any> iterable);
};

View File

@ -64,8 +64,7 @@ WorkerPrivate::RegisterBindings(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
!ImageDataBinding::GetConstructorObject(aCx, aGlobal) ||
!MessageEventBinding::GetConstructorObject(aCx, aGlobal) ||
!MessagePortBinding::GetConstructorObject(aCx, aGlobal) ||
(PromiseEnabled() &&
!PromiseBinding::GetConstructorObject(aCx, aGlobal)) ||
!PromiseBinding::GetConstructorObject(aCx, aGlobal) ||
!TextDecoderBinding::GetConstructorObject(aCx, aGlobal) ||
!TextEncoderBinding::GetConstructorObject(aCx, aGlobal) ||
!XMLHttpRequestBinding_workers::GetConstructorObject(aCx, aGlobal) ||

View File

@ -142,7 +142,6 @@ static_assert(MAX_WORKERS_PER_DOMAIN >= 1,
#define PREF_DOM_WINDOW_DUMP_ENABLED "browser.dom.window.dump.enabled"
#endif
#define PREF_PROMISE_ENABLED "dom.promise.enabled"
#define PREF_WORKERS_LATEST_JS_VERSION "dom.workers.latestJSVersion"
namespace {
@ -1664,10 +1663,6 @@ RuntimeService::Init()
PREF_DOM_WINDOW_DUMP_ENABLED,
reinterpret_cast<void *>(WORKERPREF_DUMP))) ||
#endif
NS_FAILED(Preferences::RegisterCallbackAndCall(
WorkerPrefChanged,
PREF_PROMISE_ENABLED,
reinterpret_cast<void *>(WORKERPREF_PROMISE))) ||
NS_FAILED(Preferences::RegisterCallback(LoadJSContextOptions,
PREF_JS_OPTIONS_PREFIX,
nullptr)) ||
@ -1827,10 +1822,6 @@ RuntimeService::Cleanup()
NS_FAILED(Preferences::UnregisterCallback(LoadJSContextOptions,
PREF_WORKERS_OPTIONS_PREFIX,
nullptr)) ||
NS_FAILED(Preferences::UnregisterCallback(
WorkerPrefChanged,
PREF_PROMISE_ENABLED,
reinterpret_cast<void *>(WORKERPREF_PROMISE))) ||
#if DUMP_CONTROLLED_BY_PREF
NS_FAILED(Preferences::UnregisterCallback(
WorkerPrefChanged,
@ -2302,16 +2293,13 @@ RuntimeService::WorkerPrefChanged(const char* aPrefName, void* aClosure)
MOZ_ASSERT(tmp < WORKERPREF_COUNT);
WorkerPreference key = static_cast<WorkerPreference>(tmp);
if (key == WORKERPREF_PROMISE) {
sDefaultPreferences[WORKERPREF_PROMISE] =
Preferences::GetBool(PREF_PROMISE_ENABLED, false);
#ifdef DUMP_CONTROLLED_BY_PREF
} else if (key == WORKERPREF_DUMP) {
if (key == WORKERPREF_DUMP) {
key = WORKERPREF_DUMP;
sDefaultPreferences[WORKERPREF_DUMP] =
Preferences::GetBool(PREF_DOM_WINDOW_DUMP_ENABLED, false);
#endif
}
#endif
// This function should never be registered as a callback for a preference it
// does not handle.

View File

@ -992,13 +992,6 @@ public:
return mPreferences[WORKERPREF_DUMP];
}
bool
PromiseEnabled() const
{
AssertIsOnWorkerThread();
return mPreferences[WORKERPREF_PROMISE];
}
bool
OnLine() const
{

View File

@ -165,7 +165,6 @@ struct JSSettings
enum WorkerPreference
{
WORKERPREF_DUMP = 0, // browser.dom.window.dump.enabled
WORKERPREF_PROMISE, // dom.promise.enabled
WORKERPREF_COUNT
};

View File

@ -36,7 +36,7 @@
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.promise.enabled", true]]}, runTest);
runTest();
</script>
</pre>
</body>

View File

@ -1872,13 +1872,6 @@ pref("dom.max_script_run_time", 10);
// If true, ArchiveReader will be enabled
pref("dom.archivereader.enabled", false);
// If true, Promise will be enabled
#ifdef RELEASE_BUILD
pref("dom.promise.enabled", false);
#else
pref("dom.promise.enabled", true);
#endif
// Hang monitor timeout after which we kill the browser, in seconds
// (0 is disabled)
// Disabled on all platforms per bug 705748 until the found issues are