Bug 918806 - Enable DOM Promises. sr=bz
☠☠ backed out by 7e4ed3b79f4d ☠ ☠
authorNikhil Marathe <nsm.nikhil@gmail.com>
Thu, 30 Jan 2014 09:41:43 -0800
changeset 182108 1d7c2025bb562321c05f7f952e31f385828cb382
parent 182107 d696c67e248946e0359339a1c7e3f2846c250026
child 182109 6db8b08a3aea5f974783b6be6e0419d4e0cae51e
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs918806
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 918806 - Enable DOM Promises. sr=bz
b2g/app/b2g.js
dom/promise/Promise.cpp
dom/promise/Promise.h
dom/promise/tests/test_bug883683.html
dom/promise/tests/test_promise.html
dom/promise/tests/test_promise_utils.html
dom/promise/tests/test_resolve.html
dom/webidl/Promise.webidl
dom/workers/RegisterBindings.cpp
dom/workers/RuntimeService.cpp
dom/workers/WorkerPrivate.h
dom/workers/Workers.h
dom/workers/test/test_promise.html
modules/libpref/src/init/all.js
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -809,19 +809,16 @@ pref("disk_space_watcher.enabled", true)
 // SNTP preferences.
 pref("network.sntp.maxRetryCount", 10);
 pref("network.sntp.refreshPeriod", 86400); // In seconds.
 pref("network.sntp.pools", // Servers separated by ';'.
      "0.pool.ntp.org;1.pool.ntp.org;2.pool.ntp.org;3.pool.ntp.org");
 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);
 #else
 pref("dom.datastore.enabled", true);
 #endif
 
 // DOM Inter-App Communication API.
--- a/dom/promise/Promise.cpp
+++ b/dom/promise/Promise.cpp
@@ -239,38 +239,16 @@ Promise::~Promise()
 }
 
 JSObject*
 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)
 {
   MaybeResolveInternal(aCx, aValue);
 }
 
 void
--- a/dom/promise/Promise.h
+++ b/dom/promise/Promise.h
@@ -40,18 +40,16 @@ class Promise MOZ_FINAL : public nsISupp
 
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Promise)
 
   Promise(nsPIDOMWindow* aWindow);
   ~Promise();
 
-  static bool EnabledForScope(JSContext* aCx, JSObject* /* unused */);
-
   void MaybeResolve(JSContext* aCx,
                     JS::Handle<JS::Value> aValue);
   void MaybeReject(JSContext* aCx,
                    JS::Handle<JS::Value> aValue);
 
   // WebIDL
 
   nsPIDOMWindow* GetParentObject() const
--- a/dom/promise/tests/test_bug883683.html
+++ b/dom/promise/tests/test_bug883683.html
@@ -28,14 +28,14 @@ function runTest() {
 
   [{}, {}, {}, {}, {}].reduce(function(a, b, c, d) { return new Promise(function(r1, r2) { }); });
   ok(true, "No leaks with empty promise?");
 
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
-SpecialPowers.pushPrefEnv({"set": [["dom.promise.enabled", true]]}, runTest);
+runTest();
 // -->
 </script>
 </pre>
 </body>
 </html>
--- a/dom/promise/tests/test_promise.html
+++ b/dom/promise/tests/test_promise.html
@@ -606,21 +606,16 @@ function runTest() {
     SimpleTest.finish();
     return;
   }
 
   var test = tests.shift();
   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>
 </body>
 </html>
 
--- a/dom/promise/tests/test_promise_utils.html
+++ b/dom/promise/tests/test_promise_utils.html
@@ -311,15 +311,15 @@ function runTest() {
     return;
   }
 
   var test = tests.shift();
   test();
 }
 
 SimpleTest.waitForExplicitFinish();
-SpecialPowers.pushPrefEnv({"set": [["dom.promise.enabled", true]]}, runTest);
+runTest();
 // -->
 </script>
 </pre>
 </body>
 </html>
 
--- a/dom/promise/tests/test_resolve.html
+++ b/dom/promise/tests/test_resolve.html
@@ -53,15 +53,15 @@ function runTest() {
       reject(test)
     }).then(cbError, function(what) {
       ok(test === what, "What is: " + what);
     }).then(runTest, cbError);
   });
 }
 
 SimpleTest.waitForExplicitFinish();
-SpecialPowers.pushPrefEnv({"set": [["dom.promise.enabled", true]]}, runTest);
+runTest();
 // -->
 </script>
 </pre>
 </body>
 </html>
 
--- a/dom/webidl/Promise.webidl
+++ b/dom/webidl/Promise.webidl
@@ -10,40 +10,40 @@
 // TODO We use object instead Function.  There is an open issue on WebIDL to
 // have different types for "platform-provided function" and "user-provided
 // function"; for now, we just use "object".
 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);
 
   // Disable the static methods when the interface object is supposed to be
   // disabled, just in case some code decides to walk over to .constructor from
   // 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
   // nothing instead of throwing errors when non-callable arguments are passed.
   [NewObject]
   Promise then([TreatNonCallableAsNull] optional AnyCallback? fulfillCallback = null,
                [TreatNonCallableAsNull] optional AnyCallback? rejectCallback = null);
 
   [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);
 };
--- a/dom/workers/RegisterBindings.cpp
+++ b/dom/workers/RegisterBindings.cpp
@@ -59,18 +59,17 @@ WorkerPrivate::RegisterBindings(JSContex
 
   // Init other paris-bindings.
   if (!DOMExceptionBinding::GetConstructorObject(aCx, aGlobal) ||
       !EventBinding::GetConstructorObject(aCx, aGlobal) ||
       !FileReaderSyncBinding_workers::GetConstructorObject(aCx, 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) ||
       !XMLHttpRequestUploadBinding_workers::GetConstructorObject(aCx, aGlobal) ||
       !URLBinding_workers::GetConstructorObject(aCx, aGlobal) ||
       !URLSearchParamsBinding::GetConstructorObject(aCx, aGlobal) ||
       !WorkerBinding::GetConstructorObject(aCx, aGlobal) ||
       !WorkerLocationBinding_workers::GetConstructorObject(aCx, aGlobal) ||
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -137,17 +137,16 @@ static_assert(MAX_WORKERS_PER_DOMAIN >= 
 #define PREF_MEM_OPTIONS_PREFIX "mem."
 #define PREF_GCZEAL "gcZeal"
 
 #if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
 #define DUMP_CONTROLLED_BY_PREF 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 {
 
 const uint32_t kNoIndex = uint32_t(-1);
 
 const JS::ContextOptions kRequiredJSContextOptions =
   JS::ContextOptions().setDontReportUncaught(true)
@@ -1659,20 +1658,16 @@ RuntimeService::Init()
                                         nullptr)) ||
 #endif
 #if DUMP_CONTROLLED_BY_PREF
       NS_FAILED(Preferences::RegisterCallbackAndCall(
                                   WorkerPrefChanged,
                                   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)) ||
       NS_FAILED(Preferences::RegisterCallbackAndCall(
                                                     LoadJSContextOptions,
                                                     PREF_WORKERS_OPTIONS_PREFIX,
                                                     nullptr)) ||
       NS_FAILED(Preferences::RegisterCallbackAndCall(
@@ -1822,20 +1817,16 @@ RuntimeService::Cleanup()
                                                   PREF_WORKERS_LATEST_JS_VERSION,
                                                   nullptr)) ||
         NS_FAILED(Preferences::UnregisterCallback(LoadJSContextOptions,
                                                   PREF_JS_OPTIONS_PREFIX,
                                                   nullptr)) ||
         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,
                                   PREF_DOM_WINDOW_DUMP_ENABLED,
                                   reinterpret_cast<void *>(WORKERPREF_DUMP))) ||
 #endif
 #ifdef JS_GC_ZEAL
         NS_FAILED(Preferences::UnregisterCallback(
@@ -2297,26 +2288,23 @@ RuntimeService::Observe(nsISupports* aSu
 RuntimeService::WorkerPrefChanged(const char* aPrefName, void* aClosure)
 {
   AssertIsOnMainThread();
 
   uintptr_t tmp = reinterpret_cast<uintptr_t>(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
-  }
 
   // This function should never be registered as a callback for a preference it
   // does not handle.
   MOZ_ASSERT(key != WORKERPREF_COUNT);
 
   RuntimeService* rts = RuntimeService::GetService();
   if (rts) {
     rts->UpdateAllWorkerPreference(key, sDefaultPreferences[key]);
--- a/dom/workers/WorkerPrivate.h
+++ b/dom/workers/WorkerPrivate.h
@@ -988,23 +988,16 @@ public:
   bool
   DumpEnabled() const
   {
     AssertIsOnWorkerThread();
     return mPreferences[WORKERPREF_DUMP];
   }
 
   bool
-  PromiseEnabled() const
-  {
-    AssertIsOnWorkerThread();
-    return mPreferences[WORKERPREF_PROMISE];
-  }
-
-  bool
   OnLine() const
   {
     AssertIsOnWorkerThread();
     return mOnLine;
   }
 
   void
   StopSyncLoop(nsIEventTarget* aSyncLoopTarget, bool aResult);
--- a/dom/workers/Workers.h
+++ b/dom/workers/Workers.h
@@ -160,17 +160,16 @@ struct JSSettings
 
     return false;
   }
 };
 
 enum WorkerPreference
 {
   WORKERPREF_DUMP = 0, // browser.dom.window.dump.enabled
-  WORKERPREF_PROMISE,  // dom.promise.enabled
   WORKERPREF_COUNT
 };
 
 // All of these are implemented in RuntimeService.cpp
 bool
 ResolveWorkerClasses(JSContext* aCx, JS::Handle<JSObject*> aObj, JS::Handle<jsid> aId,
                      unsigned aFlags, JS::MutableHandle<JSObject*> aObjp);
 
--- a/dom/workers/test/test_promise.html
+++ b/dom/workers/test/test_promise.html
@@ -31,14 +31,14 @@
       ok(false, "Worker had an error: " + event.data);
       SimpleTest.finish();
     };
 
     worker.postMessage(true);
   }
 
   SimpleTest.waitForExplicitFinish();
-  SpecialPowers.pushPrefEnv({"set": [["dom.promise.enabled", true]]}, runTest);
+  runTest();
 </script>
 </pre>
 </body>
 </html>
 
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -1867,23 +1867,16 @@ pref("editor.positioning.offset",       
 
 pref("dom.use_watchdog", true);
 pref("dom.max_chrome_script_run_time", 20);
 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
 // resolved.
 pref("hangmonitor.timeout", 0);
 
 pref("plugins.load_appdir_plugins", false);
 // If true, plugins will be click to play