Merge m-c to fx-team. a=merge
authorRyan VanderMeulen <ryanvm@gmail.com>
Wed, 22 Jul 2015 16:49:04 -0400
changeset 254170 69193199b90f4113e90c47144725f95ebeb07b8b
parent 254169 7c03f6f2656b113934fa1b75d0f9fe00d097a83b (current diff)
parent 254150 8650fe82f1cd776535f7c87adb3aa406daf215ed (diff)
child 254171 2608b66c234580d4f084e51f3bc361a3c1d4c74e
push id29093
push usercbook@mozilla.com
push dateThu, 23 Jul 2015 09:53:14 +0000
treeherdermozilla-central@1f77b78797d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone42.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
Merge m-c to fx-team. a=merge
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -622,17 +622,19 @@ pref("app.update.socket.retryTimeout", 3
 // Note: Offline errors will always retry when the network comes online.
 pref("app.update.socket.maxErrors", 20);
 
 // Enable update logging for now, to diagnose growing pains in the
 // field.
 pref("app.update.log", true);
 
 // SystemUpdate API
+#ifdef MOZ_WIDGET_GONK
 pref("dom.system_update.active", "@mozilla.org/updates/update-prompt;1");
+#endif
 #else
 // Explicitly disable the shutdown watchdog.  It's enabled by default.
 // When the updater is disabled, we want to know about shutdown hangs.
 pref("shutdown.watchdog.timeoutSecs", -1);
 #endif
 
 // Allow webapps update checking
 pref("webapps.update.enabled", true);
--- a/b2g/components/AboutServiceWorkers.jsm
+++ b/b2g/components/AboutServiceWorkers.jsm
@@ -14,17 +14,17 @@ Cu.import("resource://gre/modules/XPCOMU
 XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
                                   "resource://gre/modules/SystemAppProxy.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gServiceWorkerManager",
                                   "@mozilla.org/serviceworkers/manager;1",
                                   "nsIServiceWorkerManager");
 
 function debug(aMsg) {
-  // dump("AboutServiceWorkers - " + aMsg + "\n");
+  dump("AboutServiceWorkers - " + aMsg + "\n");
 }
 
 function serializeServiceWorkerInfo(aServiceWorkerInfo) {
   if (!aServiceWorkerInfo) {
     throw new Error("Invalid service worker information");
   }
 
   let result = {};
new file mode 100644
--- /dev/null
+++ b/b2g/components/test/mochitest/app/client.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Test app for bug 1171917</title>
+    <script type="application/javascript;version=1.7">
+
+function onLoad() {
+  navigator.serviceWorker.ready.then(() => {
+    parent.postMessage({status: "callback", data: "ready"}, "*");
+  });
+}
+
+    </script>
+  </head>
+  <body onload="onLoad()">
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/b2g/components/test/mochitest/app/index.html
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Test app for bug 1171917</title>
+    <script type="application/javascript;version=1.7">
+
+function ok(aCondition, aMessage) {
+  if (aCondition) {
+    alert("OK: " + aMessage);
+  } else {
+    alert("KO: " + aMessage);
+  }
+}
+
+function done() {
+  alert("DONE");
+}
+
+function testFrame(src) {
+  return new Promise((resolve) => {
+    var iframe = document.createElement("iframe");
+    iframe.src = src;
+    window.onmessage = function(e) {
+      if (e.data.status == "callback") {
+        window.onmessage = null;
+        var result = e.data.data;
+        document.body.removeChild(iframe);
+        iframe.src = "about:blank";
+        iframe = null;
+        resolve(result);
+      }
+    };
+    document.body.appendChild(iframe);
+  });
+}
+
+function registerServiceWorker() {
+  return navigator.serviceWorker.register("sw.sjs", {scope: "."});
+}
+
+function runTests() {
+  var lastSeenVersion;
+  return Promise.resolve()
+    .then(() => {
+      // Check whether the service worker is already registered and save its
+      // version.
+      return navigator.serviceWorker.getRegistration(".").then((swr) => {
+        if (!swr) {
+          lastSeenVersion = 0;
+          return registerServiceWorker();
+        }
+        return testFrame("version.html").then((body) => {
+          lastSeenVersion = parseInt(body);
+          return Promise.resolve();
+        });
+      });
+    })
+    .then(() => {
+      // Wait until the service worker starts controlling the client.
+      return testFrame("client.html");
+    })
+    .then(() => {
+      return new Promise((resolve) => {
+        testFrame("wait_for_update.html").then(() => {
+          // Fetch current version. It should be greater than the last seen version.
+          testFrame("version.html").then((body) => {
+            var currentVersion = parseInt(body);
+            ok(lastSeenVersion < currentVersion, "New service worker version seen");
+            resolve();
+          });
+        });
+      });
+    })
+    .then(done)
+    .catch((e) => {
+      dump("Unexpected error " + e);
+    });
+}
+
+    </script>
+  </head>
+  <body onload="runTests()">
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/b2g/components/test/mochitest/app/manifest.webapp
@@ -0,0 +1,5 @@
+{
+  "name": "App",
+  "launch_path": "/index.html",
+  "description": "Test app for bug 1171917"
+}
new file mode 100644
--- /dev/null
+++ b/b2g/components/test/mochitest/app/manifest.webapp^headers^
@@ -0,0 +1,1 @@
+Content-Type: application/manifest+json
new file mode 100644
--- /dev/null
+++ b/b2g/components/test/mochitest/app/sw.sjs
@@ -0,0 +1,28 @@
+// The update process does not complete unless the service worker script changes.
+// The service worker script is a server-side JS file which allows us to get a
+// slightly different service worker script file each time the file is fetched.
+// Everytime there is either a registration or an update the script will be
+// fetched and a slightly different version of the script will be returned.
+
+function handleRequest(request, response) {
+  var stateName = request.scheme + "counter";
+  if (!getState(stateName)) {
+    setState(stateName, "1");
+  } else {
+    // Make sure that we pass a string value to setState!
+    setState(stateName, "" + (parseInt(getState(stateName)) + 1));
+  }
+  response.setHeader("Content-Type", "application/javascript", false);
+  response.write(getScript(stateName));
+}
+
+function getScript(stateName) {
+  return "oninstall = function(evt) {" +
+           "evt.waitUntil(self.skipWaiting());" +
+         "}; " +
+         "onfetch = function(evt) {" +
+           "if (evt.request.url.indexOf('get-sw-version') > -1) {" +
+             "evt.respondWith(new Response('" + getState(stateName) + "'));" +
+           "}" +
+         "};";
+}
new file mode 100644
--- /dev/null
+++ b/b2g/components/test/mochitest/app/version.html
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Test app for bug 1171917</title>
+    <script type="application/javascript;version=1.7">
+
+function onLoad() {
+  fetch("get-sw-version").then(function(r) {
+    return r.text();
+  }).then(function(body) {
+    parent.postMessage({status: "callback", data: body}, "*");
+  });
+}
+
+    </script>
+  </head>
+  <body onload="onLoad()">
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/b2g/components/test/mochitest/app/wait_for_update.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Test app for bug 1171917</title>
+    <script type="application/javascript;version=1.7">
+
+function update() {
+  alert("UPDATE");
+}
+
+function onLoad() {
+  navigator.serviceWorker.getRegistration(".").then(function(swr) {
+    swr.onupdatefound = function() {
+      swr.onupdatefound = null;
+      parent.postMessage({status: "callback", data: "done"}, "*");
+    };
+    update();
+  });
+}
+
+    </script>
+  </head>
+  <body onload="onLoad()">
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/b2g/components/test/mochitest/chrome.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+skip-if = toolkit != "gonk"
+support-files =
+  app/*
+
+[test_aboutserviceworkers.html]
new file mode 100644
--- /dev/null
+++ b/b2g/components/test/mochitest/test_aboutserviceworkers.html
@@ -0,0 +1,278 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1171917
+
+The tests being added here are about testing the logic underneath the
+about:serviceworkers panel in the settings app. That logic is a B2G dedicate
+component.
+The component let us update and unregister a Service Worker Registration. It
+communicates with content through content/chrome events. We mock them so we can
+send messages for updating/unregistering a particular Service Worker
+Registration.
+
+These tests install an app and the app registers a service worker. Through the
+component described above we update the corresponding Service Worker
+Registration, we test that the Service Worker gets updated and
+then we unregister it.
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1171917</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+  <script type="application/javascript;version=1.7">
+    
+const ASW_CHROME_EVENT = "mozAboutServiceWorkersChromeEvent";
+const ASW_CONTENT_EVENT = "mozAboutServiceWorkersContentEvent";
+
+const { utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "AboutServiceWorkers",
+  "resource://gre/modules/AboutServiceWorkers.jsm");
+
+SimpleTest.waitForExplicitFinish();
+
+const gOrigin = "http://test/chrome/b2g/components/test/mochitest/app";
+const appManifestURL = gOrigin + "/manifest.webapp";
+let gApp;
+
+const ORIGINAL_INIT = AboutServiceWorkers.init;
+const ORIGINAL_SENDRESULT = AboutServiceWorkers.sendResult;
+const ORIGINAL_SENDERROR = AboutServiceWorkers.sendError;
+
+function debug(aMsg) {
+  dump("test_aboutserviceworkers.html - " + aMsg + "\n");
+}
+
+function mockInit() {
+  window.addEventListener(ASW_CONTENT_EVENT, AboutServiceWorkers);
+}
+
+function mockSendResult(aId, aResult) {
+  let result = {
+    detail: {
+      id: aId,
+      result: aResult
+    }
+  };
+  debug("mockSendResult, " + JSON.stringify(result));
+  let event = new CustomEvent(ASW_CHROME_EVENT, result);
+  window.dispatchEvent(event);
+}
+
+function mockSendError(aId, aError) {
+  let error = {
+    detail: {
+      id: aId,
+      error: aError
+    }
+  };
+  debug("mockSendError, " + JSON.stringify(error));
+  let event = new CustomEvent(ASW_CHROME_EVENT, error);
+  window.dispatchEvent(event);
+}
+
+function attachMocks() {
+  AboutServiceWorkers.init = mockInit;
+  AboutServiceWorkers.sendResult = mockSendResult;
+  AboutServiceWorkers.sendError = mockSendError;
+  return Promise.resolve();
+}
+
+function restoreMocks() {
+  AboutServiceWorkers.init = ORIGINAL_INIT;
+  AboutServiceWorkers.sendResult = ORIGINAL_SENDRESULT;
+  AboutServiceWorkers.sendError = ORIGINAL_SENDERROR;
+  return Promise.resolve();
+}
+
+function sendContentEvent(detail) {
+  let event = new CustomEvent(ASW_CONTENT_EVENT, {
+    detail: detail
+  });
+  window.dispatchEvent(event);
+}
+
+function chromeRequest(request) {
+  if (!request) {
+    return Promise.reject("InternalErrorMissingEventDetail");
+  }
+
+  return new Promise((resolve, reject) => {
+    let id = request.id;
+    window.addEventListener(ASW_CHROME_EVENT,
+                            function onChromeEvent(event) {
+      window.removeEventListener(ASW_CHROME_EVENT, onChromeEvent);
+      let message = event.detail;
+      if (!message || !message.id || message.id != id) {
+        return reject('InternalErrorWrongChromeEvent');
+      }
+
+      if (message.error) {
+        reject(message.error);
+      } else if (message.result) {
+        resolve(message.result);
+      }
+    });
+
+    sendContentEvent(request);
+  });
+}
+
+function uninstallApp() {
+  return new Promise((resolve, reject) => {
+    if (!gApp) {
+      return reject();
+    }
+    let req = navigator.mozApps.mgmt.uninstall(gApp);
+    req.onsuccess = resolve;
+    req.onerror = reject;
+  });
+}
+
+function update() {
+  return Promise.resolve()
+    .then(() => {
+      return chromeRequest({id: "0", name: "init"});
+    })
+    .then((result) => {
+      return chromeRequest({
+        id: "1",
+        name: "update",
+        principal: result.registrations[0].principal,
+        scope: result.registrations[0].scope
+      });
+    });
+}
+
+function testApp() {
+  if (!gApp) {
+    ok(false, "No test application to launch");
+    return Promise.reject();
+  }
+  return new Promise((resolve, reject) => {
+    let iframe = document.createElement("iframe");
+    let domParent = document.getElementById("container");
+    iframe.setAttribute("mozbrowser", "true");
+    iframe.setAttribute("mozapp", gApp.manifestURL);
+    iframe.addEventListener("mozbrowsershowmodalprompt", function listener(e) {
+      let message = e.detail.message;
+      if (/KO/.exec(message)) {
+        ok(false, "Message from app: " + message);
+      } else if (/OK/.exec(message)) {
+        ok(true, "Message from app: " + message);
+      } else if (/UPDATE/.exec(message)) {
+        ok(true, "Message from app: " + message);
+        update();
+      } else if (/DONE/.exec(message)) {
+        ok(true, "Message from app: " + message);
+        iframe.src = "about:blank";
+        domParent.removeChild(iframe);
+        iframe = null;
+        resolve();
+      }
+    }, false);
+    domParent.appendChild(iframe);
+    ok(true, "origin " +  gOrigin + gApp.manifest.launch_path);
+    SpecialPowers.wrap(iframe.contentWindow).location =
+      gOrigin + gApp.manifest.launch_path;
+  });
+}
+
+function installApp() {
+  return new Promise((resolve, reject) => {
+    let req = navigator.mozApps.install(appManifestURL);
+    req.onsuccess = function() {
+      gApp = req.result;
+      is(req.result.manifestURL, appManifestURL, "app installed");
+      if (req.result.installState == "installed") {
+        is(req.result.installState, "installed", "app downloaded");
+        resolve()
+      } else {
+        req.result.ondownloadapplied = function() {
+          is(req.result.installState, "installed", "app downloaded");
+          resolve();
+        }
+      }
+    }
+    req.onerror = reject;
+  });
+}
+
+function setup() {
+  info("Setting up");
+  return new Promise((resolve, reject) => {
+    SpecialPowers.setAllAppsLaunchable(true);
+    SpecialPowers.pushPrefEnv({"set": [
+      ["dom.mozBrowserFramesEnabled", true],
+      ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+      ["dom.serviceWorkers.enabled", true],
+      ["dom.serviceWorkers.testing.enabled", true],
+      ["dom.serviceWorkers.interception.enabled", true]
+    ]}, () => {
+      SpecialPowers.pushPermissions([
+        { "type": "webapps-manage", "allow": 1, "context": document },
+        { "type": "browser", "allow": 1, "context": document },
+        { "type": "embed-apps", "allow": 1, "context": document }
+      ], () => {
+        SpecialPowers.autoConfirmAppInstall(() => {
+          SpecialPowers.autoConfirmAppUninstall(resolve);
+        });
+      });
+    });
+  });
+}
+
+function cleanUp() {
+  restoreMocks();
+  SimpleTest.finish();
+}
+
+function go() {
+  setup()
+    .then(attachMocks)
+    .then(() => {
+      AboutServiceWorkers.init();
+      return Promise.resolve();
+    })
+    .then(installApp)
+    .then(testApp)
+    .then(() => {
+      return chromeRequest({id: "2", name: "init"});
+    })
+    .then((result) => {
+      return chromeRequest({
+        id: "3",
+        name: "unregister",
+        principal: result.registrations[0].principal,
+        scope: result.registrations[0].scope
+      });
+    })
+    .then(() => {
+      return chromeRequest({id: "4", name: "init"});
+    })
+    .then((result) => {
+      ok(result.registrations && result.registrations.length === 0,
+         "Service worker registration was successfuly unregistered");
+    })
+    .then(uninstallApp)
+    .then(cleanUp)
+    .catch((e) => {
+      ok(false, "Unexpected error " + e);
+      cleanUp();
+    });
+}
+  </script>
+</head>
+<body onload="go()">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1171917">Mozilla Bug 1171917</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+</pre>
+<div id="container"></div>
+</body>
+</html>
--- a/b2g/components/test/moz.build
+++ b/b2g/components/test/moz.build
@@ -1,8 +1,9 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
 MOCHITEST_MANIFESTS += ['mochitest/mochitest.ini']
+MOCHITEST_CHROME_MANIFESTS += ['mochitest/chrome.ini']
--- a/b2g/config/aries/sources.xml
+++ b/b2g/config/aries/sources.xml
@@ -10,25 +10,25 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b57aef5b7f52c40f88ee4c069ff722404e8e8521"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="f04fdbfa1943dddeab8ecd1299a76ab56e590d00"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="9f45c1988fe72749f0659409e6e3320fabf7b79a"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="657894b4a1dc0a926117f4812e0940229f9f676f"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
-  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="11b6bfa7620f31b9c2bc2e537b66233daf5e192f"/>
+  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="1b587ca868ee75758959c2470a9c35a21299377f"/>
   <!-- Stock Android things -->
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" revision="95bb5b66b3ec5769c3de8d3f25d681787418e7d2"/>
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" revision="ebdad82e61c16772f6cd47e9f11936bf6ebe9aa0"/>
   <project groups="linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" path="prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" revision="8b880805d454664b3eed11d0f053cdeafa1ff06e"/>
   <project groups="linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7" path="prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7" revision="a1e239a0bb5cd1d69680bf1075883aa9a7bf2429"/>
   <project groups="linux,x86" name="platform/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.7" path="prebuilts/gcc/linux-x86/x86/i686-linux-android-4.7" revision="c7931763d41be602407ed9d71e2c0292c6597e00"/>
   <project groups="linux,x86" name="platform/prebuilts/python/linux-x86/2.7.5" path="prebuilts/python/linux-x86/2.7.5" revision="a32003194f707f66a2d8cdb913ed1869f1926c5d"/>
   <project name="device/common" path="device/common" revision="96d4d2006c4fcb2f19a3fa47ab10cb409faa017b"/>
@@ -117,41 +117,41 @@
   <project name="platform/system/security" path="system/security" revision="ee8068b9e7bfb2770635062fc9c2035be2142bd8"/>
   <project name="platform/system/vold" path="system/vold" revision="42fa2a0f14f965970a4b629a176bbd2666edf017"/>
   <project name="platform/external/curl" path="external/curl" revision="e68addd988448959ea8157c5de637346b4180c33"/>
   <project name="platform/external/icu4c" path="external/icu4c" revision="d3ec7428eb276db43b7ed0544e09344a6014806c"/>
   <project name="platform/hardware/libhardware_legacy" path="hardware/libhardware_legacy" revision="76c4bf4bc430a1b8317f2f21ef735867733e50cc"/>
   <project name="platform/system/media" path="system/media" revision="c1332c21c608f4932a6d7e83450411cde53315ef"/>
   <default remote="caf" revision="LNX.LA.3.5.2.1.1" sync-j="4"/>
   <!-- Platform common things -->
-  <project name="device-shinano-common" path="device/sony/shinano-common" remote="b2g" revision="6698c2a6aa4115f00b1f25fec32f10b2c5c2f454"/>
+  <project name="device-shinano-common" path="device/sony/shinano-common" remote="b2g" revision="24763a010cda411db9e24d8eb3dac2982e12f0de"/>
   <project name="device/generic/armv7-a-neon" path="device/generic/armv7-a-neon" revision="1bb28abbc215f45220620af5cd60a8ac1be93722"/>
   <project name="device/qcom/common" path="device/qcom/common" revision="2501e5940ba69ece7654ff85611c76ae5bda299c"/>
   <project name="codeaurora_kernel_msm" path="kernel" remote="b2g" revision="d620691cad7aee780018e98159ff03bf99840317"/>
   <project name="platform/external/bluetooth/bluedroid" path="external/bluetooth/bluedroid" revision="d61fc97258c8b0c362430dd2eb195dcc4d266f14"/>
   <project name="init_sh" path="external/init_sh" remote="b2g" revision="3bdd26e092db9c47c5beb04b4809a35f8f767b8a"/>
   <project name="platform/external/libnfc-nci" path="external/libnfc-nci" revision="0a01977f34d6e86fe23d6c0ec75e96ba988bbebb"/>
   <project name="platform_external_libnfc-pn547" path="external/libnfc-pn547" remote="b2g" revision="5bb999b84b8adc14f6bea004d523ba258dea8188"/>
-  <project name="timekeep" path="external/timekeep" remote="b2g" revision="58e9fd70a62d2c0ebf9bc2bd99439dcc5be8cad8"/>
+  <project name="timekeep" path="external/timekeep" remote="b2g" revision="4cbb0abc00681f116f043584661307b5c4855a31"/>
   <project name="platform/external/wpa_supplicant_8" path="external/wpa_supplicant_8" revision="5b71e40213f650459e95d35b6f14af7e88d8ab62"/>
   <project name="platform_frameworks_av" path="frameworks/av" remote="b2g" revision="a920312eb6299b6cc11f7136254c4b0ba7a663be"/>
   <project name="platform/frameworks/base" path="frameworks/base" revision="da8e6bc53c8bc669da0bb627904d08aa293f2497"/>
   <project name="platform/frameworks/native" path="frameworks/native" revision="a46a9f1ac0ed5662d614c277cbb14eb3f332f365"/>
   <project name="platform/hardware/libhardware" path="hardware/libhardware" revision="7196881a0e9dd7bfbbcf0af64c8064e70f0fa094"/>
   <project name="platform/hardware/broadcom/wlan" path="hardware/broadcom/wlan" revision="15a9b66de9b7d84c7ea63df3a834f095bca9e493"/>
   <project name="platform/hardware/qcom/audio" path="hardware/qcom/audio" revision="8d7676dfb68ee0cd069affedd5d1e97316a184ba"/>
   <project name="platform/hardware/qcom/camera" path="hardware/qcom/camera" revision="2a1ded216a91bf62a72b1640cf01ab4998f37028"/>
-  <project name="hardware_qcom_display" path="hardware/qcom/display" remote="b2g" revision="37293646f6f0cbfd4fb631536984e056bef0fd2a"/>
+  <project name="hardware_qcom_display" path="hardware/qcom/display" remote="b2g" revision="4a83e04c3fecffbcab75cd59bad2ae5f342778b7"/>
   <project name="platform/hardware/qcom/gps" path="hardware/qcom/gps" revision="9883ea57b0668d8f60dba025d4522dfa69a1fbfa"/>
   <project name="platform/hardware/qcom/media" path="hardware/qcom/media" revision="a558dc844bf5144fc38603fd8f4df8d9557052a5"/>
   <project name="platform/hardware/qcom/wlan" path="hardware/qcom/wlan" revision="57ee1320ed7b4a1a1274d8f3f6c177cd6b9becb2"/>
   <project name="platform/hardware/ril" path="hardware/ril" revision="12b1977cc704b35f2e9db2bb423fa405348bc2f3"/>
   <project name="platform/system/bluetooth" path="system/bluetooth" revision="985bf15264d865fe7b9c5b45f61c451cbaafa43d"/>
   <project name="platform/system/core" path="system/core" revision="42839aedcf70bf6bc92a3b7ea4a5cc9bf9aef3f9"/>
   <project name="platform_system_nfcd" path="system/nfcd" remote="b2g" revision="5f4b68c799927b6e078f987b12722c3a6ccd4a45"/>
   <project name="platform/system/qcom" path="system/qcom" revision="63e3f6f176caad587d42bba4c16b66d953fb23c2"/>
   <project name="platform/vendor/qcom/copper" path="device/qcom/msm8974" revision="ec7bc1a26610922156d7d412b4d3de6b4adb93da"/>
   <project name="vendor_broadcom_wlan" path="vendor/broadcom/wlan" remote="b2g" revision="114b9491a8a919687da4e22fbd89fab511d6d8d7"/>
   <!-- Shinano specific things -->
-  <project name="device-shinano" path="device/sony/shinano" remote="b2g" revision="afb93dac826346fdeaab6f8ce5dd70eaaaec676d"/>
+  <project name="device-shinano" path="device/sony/leo" remote="b2g" revision="653f7e1f093b948e40262fcb3c665c2b4976df74"/>
   <!-- Aries specific things -->
   <project name="device-aries" path="device/sony/aries" remote="b2g" revision="2916e2368074b5383c80bf5a0fba3fc83ba310bd"/>
 </manifest>
--- a/b2g/config/dolphin/sources.xml
+++ b/b2g/config/dolphin/sources.xml
@@ -10,25 +10,25 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b57aef5b7f52c40f88ee4c069ff722404e8e8521"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="f04fdbfa1943dddeab8ecd1299a76ab56e590d00"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="9f45c1988fe72749f0659409e6e3320fabf7b79a"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="657894b4a1dc0a926117f4812e0940229f9f676f"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
-  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="11b6bfa7620f31b9c2bc2e537b66233daf5e192f"/>
+  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="1b587ca868ee75758959c2470a9c35a21299377f"/>
   <!-- Stock Android things -->
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" revision="95bb5b66b3ec5769c3de8d3f25d681787418e7d2"/>
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" revision="ebdad82e61c16772f6cd47e9f11936bf6ebe9aa0"/>
   <project groups="linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" path="prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" revision="8b880805d454664b3eed11d0f053cdeafa1ff06e"/>
   <project groups="linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7" path="prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7" revision="a1e239a0bb5cd1d69680bf1075883aa9a7bf2429"/>
   <project groups="linux,x86" name="platform/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.7" path="prebuilts/gcc/linux-x86/x86/i686-linux-android-4.7" revision="c7931763d41be602407ed9d71e2c0292c6597e00"/>
   <project groups="linux,x86" name="platform/prebuilts/python/linux-x86/2.7.5" path="prebuilts/python/linux-x86/2.7.5" revision="83760d213fb3bec7b4117d266fcfbf6fe2ba14ab"/>
   <project name="device/common" path="device/common" revision="6a2995683de147791e516aae2ccb31fdfbe2ad30"/>
--- a/b2g/config/emulator-ics/sources.xml
+++ b/b2g/config/emulator-ics/sources.xml
@@ -14,17 +14,17 @@
   <!--original fetch url was git://github.com/apitrace/-->
   <remote fetch="https://git.mozilla.org/external/apitrace" name="apitrace"/>
   <default remote="caf" revision="refs/tags/android-4.0.4_r2.1" sync-j="4"/>
   <!-- Gonk specific things and forks -->
   <project name="platform_build" path="build" remote="b2g" revision="173b3104bfcbd23fc9dccd4b0035fc49aae3d444">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
-  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="b57aef5b7f52c40f88ee4c069ff722404e8e8521"/>
+  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="f04fdbfa1943dddeab8ecd1299a76ab56e590d00"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="9f45c1988fe72749f0659409e6e3320fabf7b79a"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="8bc59310552179f9a8bc6cdd0188e2475df52fb7"/>
   <project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="9d0e5057ee5404a31ec1bf76131cb11336a7c3b6"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="657894b4a1dc0a926117f4812e0940229f9f676f"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="34ea6163f9f0e0122fb0bb03607eccdca31ced7a"/>
   <!-- Stock Android things -->
   <project name="platform/abi/cpp" path="abi/cpp" revision="dd924f92906085b831bf1cbbc7484d3c043d613c"/>
--- a/b2g/config/emulator-jb/sources.xml
+++ b/b2g/config/emulator-jb/sources.xml
@@ -12,20 +12,20 @@
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="4efd19d199ae52656604f794c5a77518400220fd">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b57aef5b7f52c40f88ee4c069ff722404e8e8521"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="f04fdbfa1943dddeab8ecd1299a76ab56e590d00"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="9f45c1988fe72749f0659409e6e3320fabf7b79a"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="657894b4a1dc0a926117f4812e0940229f9f676f"/>
-  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="11b6bfa7620f31b9c2bc2e537b66233daf5e192f"/>
+  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="1b587ca868ee75758959c2470a9c35a21299377f"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <!-- Stock Android things -->
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.1" path="prebuilts/clang/linux-x86/3.1" revision="5c45f43419d5582949284eee9cef0c43d866e03b"/>
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.2" path="prebuilts/clang/linux-x86/3.2" revision="3748b4168e7bd8d46457d4b6786003bc6a5223ce"/>
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" revision="9025e50b9d29b3cabbbb21e1dd94d0d13121a17e"/>
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" revision="b89fda71fcd0fa0cf969310e75be3ea33e048b44"/>
   <project groups="linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" path="prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" revision="2e7d5348f35575870b3c7e567a9a9f6d66f8d6c5"/>
--- a/b2g/config/emulator-kk/sources.xml
+++ b/b2g/config/emulator-kk/sources.xml
@@ -10,25 +10,25 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b57aef5b7f52c40f88ee4c069ff722404e8e8521"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="f04fdbfa1943dddeab8ecd1299a76ab56e590d00"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="9f45c1988fe72749f0659409e6e3320fabf7b79a"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="657894b4a1dc0a926117f4812e0940229f9f676f"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
-  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="11b6bfa7620f31b9c2bc2e537b66233daf5e192f"/>
+  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="1b587ca868ee75758959c2470a9c35a21299377f"/>
   <!-- Stock Android things -->
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" revision="f92a936f2aa97526d4593386754bdbf02db07a12"/>
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" revision="6e47ff2790f5656b5b074407829ceecf3e6188c4"/>
   <project groups="linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" path="prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" revision="1950e4760fa14688b83cdbb5acaa1af9f82ef434"/>
   <project groups="linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7" path="prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7" revision="ac6eb97a37035c09fb5ede0852f0881e9aadf9ad"/>
   <project groups="linux,x86" name="platform/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.7" path="prebuilts/gcc/linux-x86/x86/i686-linux-android-4.7" revision="737f591c5f95477148d26602c7be56cbea0cdeb9"/>
   <project groups="linux,x86" name="platform/prebuilts/python/linux-x86/2.7.5" path="prebuilts/python/linux-x86/2.7.5" revision="51da9b1981be481b92a59a826d4d78dc73d0989a"/>
   <project name="device/common" path="device/common" revision="798a3664597e6041985feab9aef42e98d458bc3d"/>
--- a/b2g/config/emulator-l/sources.xml
+++ b/b2g/config/emulator-l/sources.xml
@@ -10,25 +10,25 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="61e82f99bb8bc78d52b5717e9a2481ec7267fa33">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b57aef5b7f52c40f88ee4c069ff722404e8e8521"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="f04fdbfa1943dddeab8ecd1299a76ab56e590d00"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="9f45c1988fe72749f0659409e6e3320fabf7b79a"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="657894b4a1dc0a926117f4812e0940229f9f676f"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
-  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="11b6bfa7620f31b9c2bc2e537b66233daf5e192f"/>
+  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="1b587ca868ee75758959c2470a9c35a21299377f"/>
   <!-- Stock Android things -->
   <project groups="pdk,linux" name="platform/prebuilts/clang/linux-x86/host/3.5" path="prebuilts/clang/linux-x86/host/3.5" revision="ffc05a232799fe8fcb3e47b7440b52b1fb4244c0"/>
   <project groups="pdk,linux,arm" name="platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.8" path="prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.8" revision="337e0ef5e40f02a1ae59b90db0548976c70a7226"/>
   <project groups="pdk,linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8" path="prebuilts/gcc/linux-x86/arm/arm-eabi-4.8" revision="8af5ff6f5dced9eb5a8127459df6c75d24342204"/>
   <project groups="pdk,linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8" path="prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8" revision="30915518fa7ea07166efedc191a4f40aef516fe7"/>
   <project groups="pdk,linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6" revision="96eee58e3389fb05a835310d6a06a6ba4486097a"/>
   <project groups="pdk,linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.8" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.8" revision="7c8a46698171aa2e0be09edb43d15a6acf832770"/>
   <project groups="pdk,linux,x86" name="platform/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.8" path="prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.8" revision="24b2038be8a636fd4a5d21f0abae1e466b07bcf7"/>
--- a/b2g/config/emulator/sources.xml
+++ b/b2g/config/emulator/sources.xml
@@ -14,17 +14,17 @@
   <!--original fetch url was git://github.com/apitrace/-->
   <remote fetch="https://git.mozilla.org/external/apitrace" name="apitrace"/>
   <default remote="caf" revision="refs/tags/android-4.0.4_r2.1" sync-j="4"/>
   <!-- Gonk specific things and forks -->
   <project name="platform_build" path="build" remote="b2g" revision="173b3104bfcbd23fc9dccd4b0035fc49aae3d444">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
-  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="b57aef5b7f52c40f88ee4c069ff722404e8e8521"/>
+  <project name="gaia.git" path="gaia" remote="mozillaorg" revision="f04fdbfa1943dddeab8ecd1299a76ab56e590d00"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="9f45c1988fe72749f0659409e6e3320fabf7b79a"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="8bc59310552179f9a8bc6cdd0188e2475df52fb7"/>
   <project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="9d0e5057ee5404a31ec1bf76131cb11336a7c3b6"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="657894b4a1dc0a926117f4812e0940229f9f676f"/>
   <project name="apitrace" path="external/apitrace" remote="apitrace" revision="34ea6163f9f0e0122fb0bb03607eccdca31ced7a"/>
   <!-- Stock Android things -->
   <project name="platform/abi/cpp" path="abi/cpp" revision="dd924f92906085b831bf1cbbc7484d3c043d613c"/>
--- a/b2g/config/flame-kk/sources.xml
+++ b/b2g/config/flame-kk/sources.xml
@@ -10,25 +10,25 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="e862ab9177af664f00b4522e2350f4cb13866d73">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b57aef5b7f52c40f88ee4c069ff722404e8e8521"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="f04fdbfa1943dddeab8ecd1299a76ab56e590d00"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="9f45c1988fe72749f0659409e6e3320fabf7b79a"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="657894b4a1dc0a926117f4812e0940229f9f676f"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
-  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="11b6bfa7620f31b9c2bc2e537b66233daf5e192f"/>
+  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="1b587ca868ee75758959c2470a9c35a21299377f"/>
   <!-- Stock Android things -->
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" revision="95bb5b66b3ec5769c3de8d3f25d681787418e7d2"/>
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" revision="ebdad82e61c16772f6cd47e9f11936bf6ebe9aa0"/>
   <project groups="linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" path="prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" revision="8b880805d454664b3eed11d0f053cdeafa1ff06e"/>
   <project groups="linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7" path="prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7" revision="a1e239a0bb5cd1d69680bf1075883aa9a7bf2429"/>
   <project groups="linux,x86" name="platform/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.7" path="prebuilts/gcc/linux-x86/x86/i686-linux-android-4.7" revision="c7931763d41be602407ed9d71e2c0292c6597e00"/>
   <project groups="linux,x86" name="platform/prebuilts/python/linux-x86/2.7.5" path="prebuilts/python/linux-x86/2.7.5" revision="a32003194f707f66a2d8cdb913ed1869f1926c5d"/>
   <project name="device/common" path="device/common" revision="96d4d2006c4fcb2f19a3fa47ab10cb409faa017b"/>
--- a/b2g/config/gaia.json
+++ b/b2g/config/gaia.json
@@ -1,9 +1,9 @@
 {
     "git": {
-        "git_revision": "b57aef5b7f52c40f88ee4c069ff722404e8e8521", 
+        "git_revision": "f04fdbfa1943dddeab8ecd1299a76ab56e590d00", 
         "remote": "https://git.mozilla.org/releases/gaia.git", 
         "branch": ""
     }, 
-    "revision": "ad5aad4baee0e1e3f4bd2f7c6c67c7d97a13a31b", 
+    "revision": "01d6b677af341b70496c9ae304bd07b2697f9410", 
     "repo_path": "integration/gaia-central"
 }
--- a/b2g/config/nexus-4/sources.xml
+++ b/b2g/config/nexus-4/sources.xml
@@ -12,20 +12,20 @@
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="4efd19d199ae52656604f794c5a77518400220fd">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b57aef5b7f52c40f88ee4c069ff722404e8e8521"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="f04fdbfa1943dddeab8ecd1299a76ab56e590d00"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="9f45c1988fe72749f0659409e6e3320fabf7b79a"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="657894b4a1dc0a926117f4812e0940229f9f676f"/>
-  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="11b6bfa7620f31b9c2bc2e537b66233daf5e192f"/>
+  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="1b587ca868ee75758959c2470a9c35a21299377f"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
   <!-- Stock Android things -->
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.1" path="prebuilts/clang/linux-x86/3.1" revision="5c45f43419d5582949284eee9cef0c43d866e03b"/>
   <project groups="linux" name="platform/prebuilts/clang/linux-x86/3.2" path="prebuilts/clang/linux-x86/3.2" revision="3748b4168e7bd8d46457d4b6786003bc6a5223ce"/>
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" revision="9025e50b9d29b3cabbbb21e1dd94d0d13121a17e"/>
   <project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" revision="b89fda71fcd0fa0cf969310e75be3ea33e048b44"/>
   <project groups="linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" path="prebuilts/gcc/linux-x86/arm/arm-eabi-4.7" revision="2e7d5348f35575870b3c7e567a9a9f6d66f8d6c5"/>
--- a/b2g/config/nexus-5-l/sources.xml
+++ b/b2g/config/nexus-5-l/sources.xml
@@ -10,25 +10,25 @@
   <!--original fetch url was git://codeaurora.org/-->
   <remote fetch="https://git.mozilla.org/external/caf" name="caf"/>
   <!--original fetch url was https://git.mozilla.org/releases-->
   <remote fetch="https://git.mozilla.org/releases" name="mozillaorg"/>
   <!-- B2G specific things. -->
   <project name="platform_build" path="build" remote="b2g" revision="61e82f99bb8bc78d52b5717e9a2481ec7267fa33">
     <copyfile dest="Makefile" src="core/root.mk"/>
   </project>
-  <project name="gaia" path="gaia" remote="mozillaorg" revision="b57aef5b7f52c40f88ee4c069ff722404e8e8521"/>
+  <project name="gaia" path="gaia" remote="mozillaorg" revision="f04fdbfa1943dddeab8ecd1299a76ab56e590d00"/>
   <project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
   <project name="gonk-misc" path="gonk-misc" remote="b2g" revision="9f45c1988fe72749f0659409e6e3320fabf7b79a"/>
   <project name="librecovery" path="librecovery" remote="b2g" revision="1b3591a50ed352fc6ddb77462b7b35d0bfa555a3"/>
   <project name="moztt" path="external/moztt" remote="b2g" revision="657894b4a1dc0a926117f4812e0940229f9f676f"/>
   <project name="rilproxy" path="rilproxy" remote="b2g" revision="5ef30994f4778b4052e58a4383dbe7890048c87e"/>
   <project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
   <project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
-  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="11b6bfa7620f31b9c2bc2e537b66233daf5e192f"/>
+  <project name="apitrace" path="external/apitrace" remote="apitrace" revision="1b587ca868ee75758959c2470a9c35a21299377f"/>
   <!-- Stock Android things -->
   <project groups="pdk,linux" name="platform/prebuilts/clang/linux-x86/host/3.5" path="prebuilts/clang/linux-x86/host/3.5" revision="ffc05a232799fe8fcb3e47b7440b52b1fb4244c0"/>
   <project groups="pdk,linux,arm" name="platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.8" path="prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.8" revision="337e0ef5e40f02a1ae59b90db0548976c70a7226"/>
   <project groups="pdk,linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8" path="prebuilts/gcc/linux-x86/arm/arm-eabi-4.8" revision="8af5ff6f5dced9eb5a8127459df6c75d24342204"/>
   <project groups="pdk,linux,arm" name="platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8" path="prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8" revision="30915518fa7ea07166efedc191a4f40aef516fe7"/>
   <project groups="pdk,linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6" revision="96eee58e3389fb05a835310d6a06a6ba4486097a"/>
   <project groups="pdk,linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.8" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.8" revision="7c8a46698171aa2e0be09edb43d15a6acf832770"/>
   <project groups="pdk,linux,x86" name="platform/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.8" path="prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.8" revision="24b2038be8a636fd4a5d21f0abae1e466b07bcf7"/>
--- a/browser/base/content/test/plugins/browser.ini
+++ b/browser/base/content/test/plugins/browser.ini
@@ -50,17 +50,16 @@ support-files =
 [browser_clearplugindata.js]
 [browser_CTP_context_menu.js]
 skip-if = toolkit == "gtk2" || toolkit == "gtk3"   # fails intermittently on Linux (bug 909342)
 [browser_CTP_crashreporting.js]
 skip-if = !crashreporter
 [browser_CTP_data_urls.js]
 [browser_CTP_drag_drop.js]
 [browser_CTP_hide_overlay.js]
-skip-if = true # Bug 1160788
 [browser_CTP_iframe.js]
 skip-if = os == 'linux' || os == 'mac' # Bug 984821
 [browser_CTP_multi_allow.js]
 [browser_CTP_nonplugins.js]
 [browser_CTP_notificationBar.js]
 [browser_CTP_outsideScrollArea.js]
 [browser_CTP_remove_navigate.js]
 [browser_CTP_resize.js]
--- a/dom/bluetooth/bluetooth2/BluetoothAdapter.cpp
+++ b/dom/bluetooth/bluetooth2/BluetoothAdapter.cpp
@@ -504,21 +504,16 @@ BluetoothAdapter::Notify(const Bluetooth
                NS_ConvertUTF16toUTF8(aData.name()).get());
   }
 }
 
 void
 BluetoothAdapter::SetDiscoveryHandleInUse(
   BluetoothDiscoveryHandle* aDiscoveryHandle)
 {
-  // Stop discovery handle in use from listening to "DeviceFound" signal
-  if (mDiscoveryHandleInUse) {
-    mDiscoveryHandleInUse->DisconnectFromOwner();
-  }
-
   mDiscoveryHandleInUse = aDiscoveryHandle;
 }
 
 void
 BluetoothAdapter::AppendLeScanHandle(
   BluetoothDiscoveryHandle* aDiscoveryHandle)
 {
   mLeScanHandleArray.AppendElement(aDiscoveryHandle);
--- a/dom/bluetooth/bluetooth2/BluetoothDiscoveryHandle.cpp
+++ b/dom/bluetooth/bluetooth2/BluetoothDiscoveryHandle.cpp
@@ -38,22 +38,16 @@ BluetoothDiscoveryHandle::BluetoothDisco
 {
   MOZ_ASSERT(aWindow);
 }
 
 BluetoothDiscoveryHandle::~BluetoothDiscoveryHandle()
 {
 }
 
-void
-BluetoothDiscoveryHandle::DisconnectFromOwner()
-{
-  DOMEventTargetHelper::DisconnectFromOwner();
-}
-
 // static
 already_AddRefed<BluetoothDiscoveryHandle>
 BluetoothDiscoveryHandle::Create(nsPIDOMWindow* aWindow)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aWindow);
 
   nsRefPtr<BluetoothDiscoveryHandle> handle =
--- a/dom/bluetooth/bluetooth2/BluetoothDiscoveryHandle.h
+++ b/dom/bluetooth/bluetooth2/BluetoothDiscoveryHandle.h
@@ -42,18 +42,16 @@ public:
   void GetLeScanUuid(nsString& aLeScanUuid) const
   {
     aLeScanUuid = mLeScanUuid;
   }
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
-  virtual void DisconnectFromOwner() override;
-
 private:
   BluetoothDiscoveryHandle(nsPIDOMWindow* aWindow);
 
   BluetoothDiscoveryHandle(nsPIDOMWindow* aWindow,
                            const nsTArray<nsString>& aServiceUuids,
                            const nsAString& aLeScanUuid);
 
   ~BluetoothDiscoveryHandle();
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -7207,18 +7207,22 @@ HTMLInputElement::SetFilePickerFiltersFr
       filterMask = nsIFilePicker::filterAudio;
       filterBundle->GetStringFromName(MOZ_UTF16("audioFilter"),
                                       getter_Copies(extensionListStr));
     } else if (token.EqualsLiteral("video/*")) {
       filterMask = nsIFilePicker::filterVideo;
       filterBundle->GetStringFromName(MOZ_UTF16("videoFilter"),
                                       getter_Copies(extensionListStr));
     } else if (token.First() == '.') {
+      if (token.FindChar(';') >= 0  || token.FindChar('*') >= 0) {
+        // Ignore this filter as it contains reserved characters
+        continue;
+      }
       extensionListStr = NS_LITERAL_STRING("*") + token;
-      filterName = extensionListStr + NS_LITERAL_STRING("; ");
+      filterName = extensionListStr;
       atLeastOneFileExtensionFilter = true;
     } else {
       //... if no image/audio/video filter is found, check mime types filters
       nsCOMPtr<nsIMIMEInfo> mimeInfo;
       if (NS_FAILED(mimeService->GetFromTypeAndExtension(
                       NS_ConvertUTF16toUTF8(token),
                       EmptyCString(), // No extension
                       getter_AddRefs(mimeInfo))) ||
@@ -7286,17 +7290,24 @@ HTMLInputElement::SetFilePickerFiltersFr
     const nsFilePickerFilter& filterToCheck = filtersCopy[i];
     if (filterToCheck.mFilterMask) {
       continue;
     }
     for (uint32_t j = 0; j < filtersCopy.Length(); ++j) {
       if (i == j) {
         continue;
       }
-      if (FindInReadable(filterToCheck.mFilter, filtersCopy[j].mFilter)) {
+      // Check if this filter's extension list is a substring of the other one.
+      // e.g. if filters are "*.jpeg" and "*.jpeg; *.jpg" the first one should
+      // be removed.
+      // Add an extra "; " to be sure the check will work and avoid cases like
+      // "*.xls" being a subtring of "*.xslx" while those are two differents
+      // filters and none should be removed.
+      if (FindInReadable(filterToCheck.mFilter + NS_LITERAL_STRING(";"),
+                         filtersCopy[j].mFilter + NS_LITERAL_STRING(";"))) {
         // We already have a similar, less restrictive filter (i.e.
         // filterToCheck extensionList is just a subset of another filter
         // extension list): remove this one
         filters.RemoveElement(filterToCheck);
       }
     }
   }
 
--- a/dom/html/test/forms/test_input_file_picker.html
+++ b/dom/html/test/forms/test_input_file_picker.html
@@ -26,17 +26,26 @@
   <input id='j' type='file' accept="audio/*, audio/*, audio/*">
   <input id='k' type="file" accept="image/gif,image/png">
   <input id='l' type="file" accept="image/*,image/gif,image/png">
   <input id='m' type="file" accept="image/gif,image/gif">
   <input id='n' type="file" accept="">
   <input id='o' type="file" accept=".test">
   <input id='p' type="file" accept="image/gif,.csv">
   <input id='q' type="file" accept="image/gif,.gif">
+  <input id='r' type="file" accept=".prefix,.prefixPlusSomething">
+  <input id='s' type="file" accept=".xls,.xlsx">
+  <input id='t' type="file" accept=".mp3,.wav,.flac">
+  <input id='u' type="file" accept=".xls, .xlsx">
+  <input id='v' type="file" accept=".xlsx,  .xls">
+  <input id='w' type="file" accept=".xlsx;  .xls">
+  <input id='x' type="file" accept=".xls,  .xlsx">
+  <input id='y' type="file" accept=".xlsx, .xls">
   <input id='z' type='file' accept="i/am,a,pathological,;,,,,test/case">
+  <input id='A' type="file" accept=".xlsx, .xls*">
   <input id='mix-ref' type="file" accept="image/jpeg">
   <input id='mix' type="file" accept="image/jpeg,.jpg">
   <input id='hidden' hidden type='file'>
   <input id='untrusted-click' type='file'>
   <input id='prevent-default' type='file'>
   <input id='prevent-default-false' type='file'>
   <input id='right-click' type='file'>
   <input id='middle-click' type='file'>
@@ -86,17 +95,26 @@ var testData = [["a", 1, MockFilePicker.
                 ["j", 1, MockFilePicker.filterAudio, 1],
                 ["k", 3, "*.gif; *.png", 1],
                 ["l", 4, imageExtensionList + "; " + "*.gif; *.png", 1],
                 ["m", 1, "*.gif", 1],
                 ["n", 0, undefined, 0],
                 ["o", 1, "*.test", 1],
                 ["p", 3, "*.gif; *.csv", 1],
                 ["q", 1, "*.gif", 1],
+                ["r", 3, "*.prefix; *.prefixPlusSomething", 1],
+                ["s", 3, "*.xls; *.xlsx", 1],
+                ["t", 4, "*.mp3; *.wav; *.flac", 1],
+                ["u", 3, "*.xls; *.xlsx", 1],
+                ["v", 3, "*.xlsx; *.xls", 1],
+                ["w", 0, undefined, 0],
+                ["x", 3, "*.xls; *.xlsx", 1],
+                ["y", 3, "*.xlsx; *.xls", 1],
                 ["z", 0, undefined, 0],
+                ["A", 1, "*.xlsx", 1],
                 // Note: mix and mix-ref tests extension lists are checked differently: see SimpleTest.executeSoon below
                 ["mix-ref", undefined, undefined, undefined],
                 ["mix", 1, undefined, 1],
                 ["hidden", 0, undefined, 0],
                 ["untrusted-click", 0, undefined, 0],
                 ["prevent-default", 0, undefined, 0, true],
                 ["prevent-default-false", 0, undefined, 0, true],
                 ["right-click", 0, undefined, 0, true],
--- a/dom/media/AudioSink.cpp
+++ b/dom/media/AudioSink.cpp
@@ -81,29 +81,26 @@ AudioSink::HasUnplayedFrames()
 {
   AssertCurrentThreadInMonitor();
   // Experimentation suggests that GetPositionInFrames() is zero-indexed,
   // so we need to add 1 here before comparing it to mWritten.
   return mAudioStream && mAudioStream->GetPositionInFrames() + 1 < mWritten;
 }
 
 void
-AudioSink::PrepareToShutdown()
+AudioSink::Shutdown()
 {
   AssertCurrentThreadInMonitor();
   mStopAudioThread = true;
   if (mAudioStream) {
     mAudioStream->Cancel();
   }
   GetReentrantMonitor().NotifyAll();
-}
 
-void
-AudioSink::Shutdown()
-{
+  ReentrantMonitorAutoExit exit(GetReentrantMonitor());
   mThread->Shutdown();
   mThread = nullptr;
   if (mAudioStream) {
     mAudioStream->Shutdown();
     mAudioStream = nullptr;
   }
 }
 
--- a/dom/media/AudioSink.h
+++ b/dom/media/AudioSink.h
@@ -32,22 +32,18 @@ public:
 
   // Thread-safe. Can be called on any thread.
   int64_t GetEndTime() const;
 
   // Check whether we've pushed more frames to the audio hardware than it has
   // played.
   bool HasUnplayedFrames();
 
-  // Tell the AudioSink to stop processing and initiate shutdown.  Must be
-  // called with the decoder monitor held.
-  void PrepareToShutdown();
-
-  // Shut down the AudioSink's resources.  The decoder monitor must not be
-  // held during this call, as it may block processing thread event queues.
+  // Shut down the AudioSink's resources.
+  // Must be called with the decoder monitor held.
   void Shutdown();
 
   void SetVolume(double aVolume);
   void SetPlaybackRate(double aPlaybackRate);
   void SetPreservesPitch(bool aPreservesPitch);
 
   void SetPlaying(bool aPlaying);
 
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -650,35 +650,16 @@ void MediaDecoder::QueueMetadata(int64_t
                                  nsAutoPtr<MediaInfo> aInfo,
                                  nsAutoPtr<MetadataTags> aTags)
 {
   MOZ_ASSERT(OnDecodeTaskQueue());
   GetReentrantMonitor().AssertCurrentThreadIn();
   mDecoderStateMachine->QueueMetadata(aPublishTime, aInfo, aTags);
 }
 
-bool
-MediaDecoder::IsExpectingMoreData()
-{
-  ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
-
-  // If there's no resource, we're probably just getting set up.
-  if (!mResource) {
-    return true;
-  }
-
-  // If we've downloaded anything, we're not waiting for anything.
-  if (mResource->IsDataCachedToEndOfResource(mDecoderPosition)) {
-    return false;
-  }
-
-  // Otherwise, we should be getting data unless the stream is suspended.
-  return !mResource->IsSuspended();
-}
-
 void MediaDecoder::MetadataLoaded(nsAutoPtr<MediaInfo> aInfo,
                                   nsAutoPtr<MetadataTags> aTags,
                                   MediaDecoderEventVisibility aEventVisibility)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (mShuttingDown) {
     return;
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -617,23 +617,16 @@ public:
   // owner's audio track list, and implies to video tracks respectively.
   // Call on the main thread only.
   void ConstructMediaTracks();
 
   // Removes all audio tracks and video tracks that are previously added into
   // the track list. Call on the main thread only.
   virtual void RemoveMediaTracks() override;
 
-  // Returns true if the this decoder is expecting any more data to arrive
-  // sometime in the not-too-distant future, either from the network or from
-  // an appendBuffer call on a MediaSource element.
-  //
-  // Acquires the monitor. Call from any thread.
-  virtual bool IsExpectingMoreData();
-
   // Called when the video has completed playing.
   // Call on the main thread only.
   void PlaybackEnded();
 
   void OnSeekRejected()
   {
     MOZ_ASSERT(NS_IsMainThread());
     mSeekRequest.Complete();
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1277,19 +1277,16 @@ void MediaDecoderStateMachine::Shutdown(
 
   // Once we've entered the shutdown state here there's no going back.
   ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
 
   // Change state before issuing shutdown request to threads so those
   // threads can start exiting cleanly during the Shutdown call.
   ScheduleStateMachine();
   SetState(DECODER_STATE_SHUTDOWN);
-  if (mAudioSink) {
-    mAudioSink->PrepareToShutdown();
-  }
 
   mQueuedSeek.RejectIfExists(__func__);
   mPendingSeek.RejectIfExists(__func__);
   mCurrentSeek.RejectIfExists(__func__);
 
   if (IsPlaying()) {
     StopPlayback();
   }
@@ -1468,21 +1465,17 @@ MediaDecoderStateMachine::Seek(SeekTarge
 
 void MediaDecoderStateMachine::StopAudioThread()
 {
   MOZ_ASSERT(OnTaskQueue());
   AssertCurrentThreadInMonitor();
 
   if (mAudioSink) {
     DECODER_LOG("Shutdown audio thread");
-    mAudioSink->PrepareToShutdown();
-    {
-      ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor());
-      mAudioSink->Shutdown();
-    }
+    mAudioSink->Shutdown();
     mAudioSink = nullptr;
   }
   mAudioSinkPromise.DisconnectIfExists();
 }
 
 nsresult
 MediaDecoderStateMachine::EnqueueDecodeFirstFrameTask()
 {
@@ -2369,17 +2362,17 @@ nsresult MediaDecoderStateMachine::RunSt
       // downloaded a reasonable amount of data inside our buffering time.
       if (mReader->UseBufferingHeuristics()) {
         TimeDuration elapsed = now - mBufferingStart;
         bool isLiveStream = resource->IsLiveStream();
         if ((isLiveStream || !mDecoder->CanPlayThrough()) &&
               elapsed < TimeDuration::FromSeconds(mBufferingWait * mPlaybackRate) &&
               (mQuickBuffering ? HasLowDecodedData(mQuickBufferingLowDataThresholdUsecs)
                                : HasLowUndecodedData(mBufferingWait * USECS_PER_S)) &&
-              mDecoder->IsExpectingMoreData())
+              mResource->IsExpectingMoreData())
         {
           DECODER_LOG("Buffering: wait %ds, timeout in %.3lfs %s",
                       mBufferingWait, mBufferingWait - elapsed.ToSeconds(),
                       (mQuickBuffering ? "(quick exit)" : ""));
           ScheduleStateMachineIn(USECS_PER_S);
           return NS_OK;
         }
       } else if (OutOfDecodedAudio() || OutOfDecodedVideo()) {
@@ -2729,17 +2722,17 @@ void MediaDecoderStateMachine::UpdateRen
   }
 
   RenderVideoFrames(sVideoQueueSendToCompositorSize, clockTime, nowTime);
 
   // Check to see if we don't have enough data to play up to the next frame.
   // If we don't, switch to buffering mode.
   if (mState == DECODER_STATE_DECODING &&
       mPlayState == MediaDecoder::PLAY_STATE_PLAYING &&
-      mDecoder->IsExpectingMoreData()) {
+      mResource->IsExpectingMoreData()) {
     bool shouldBuffer;
     if (mReader->UseBufferingHeuristics()) {
       shouldBuffer = HasLowDecodedData(remainingTime + EXHAUSTED_DATA_MARGIN_USECS) &&
                      (JustExitedQuickBuffering() || HasLowUndecodedData());
     } else {
       MOZ_ASSERT(mReader->IsWaitForDataSupported());
       shouldBuffer = (OutOfDecodedAudio() && mAudioWaitRequest.Exists()) ||
                      (OutOfDecodedVideo() && mVideoWaitRequest.Exists());
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -397,16 +397,25 @@ public:
   // or -1 if there is no such cached data.
   virtual int64_t GetNextCachedData(int64_t aOffset) = 0;
   // Returns the end of the bytes starting at the given offset
   // which are in cache.
   virtual int64_t GetCachedDataEnd(int64_t aOffset) = 0;
   // Returns true if all the data from aOffset to the end of the stream
   // is in cache. If the end of the stream is not known, we return false.
   virtual bool IsDataCachedToEndOfResource(int64_t aOffset) = 0;
+  // Returns true if we are expecting any more data to arrive
+  // sometime in the not-too-distant future, either from the network or from
+  // an appendBuffer call on a MediaSource element.
+  virtual bool IsExpectingMoreData()
+  {
+    // MediaDecoder::mDecoderPosition is roughly the same as Tell() which
+    // returns a position updated by latest Read() or ReadAt().
+    return !IsDataCachedToEndOfResource(Tell()) && !IsSuspended();
+  }
   // Returns true if this stream is suspended by the cache because the
   // cache is full. If true then the decoder should try to start consuming
   // data, otherwise we may not be able to make progress.
   // MediaDecoder::NotifySuspendedStatusChanged is called when this
   // changes.
   // For resources using the media cache, this returns true only when all
   // streams for the same resource are all suspended.
   virtual bool IsSuspendedByCache() = 0;
--- a/dom/media/gmp-plugin/gmp-test-output-protection.h
+++ b/dom/media/gmp-plugin/gmp-test-output-protection.h
@@ -44,17 +44,17 @@ static BOOL CALLBACK EnumDisplayMonitors
 
   ULONG numVideoOutputs = 0;
   IOPMVideoOutput** opmVideoOutputArray = nullptr;
   HRESULT hr = sOPMGetVideoOutputsFromHMONITORProc(hMonitor,
                                                    OPM_VOS_OPM_SEMANTICS,
                                                    &numVideoOutputs,
                                                    &opmVideoOutputArray);
   if (S_OK != hr) {
-    if (0x8007001f != hr && 0x80070032 != hr) {
+    if (0x8007001f != hr && 0x80070032 != hr && 0xc02625e5 != hr) {
       char msg[100];
       sprintf(msg, "FAIL OPMGetVideoOutputsFromHMONITOR call failed: HRESULT=0x%08x", hr);
       failureMsgs->push_back(msg);
     }
     return true;
   }
 
   for (ULONG i = 0; i < numVideoOutputs; ++i) {
--- a/dom/media/mediasource/MediaSourceDecoder.cpp
+++ b/dom/media/mediasource/MediaSourceDecoder.cpp
@@ -210,22 +210,16 @@ MediaSourceDecoder::Ended(bool aEnded)
   static_cast<MediaSourceResource*>(GetResource())->SetEnded(aEnded);
   if (!mIsUsingFormatReader) {
     GetReader()->Ended(aEnded);
   }
   mEnded = true;
   mon.NotifyAll();
 }
 
-bool
-MediaSourceDecoder::IsExpectingMoreData()
-{
-  return !mEnded;
-}
-
 void
 MediaSourceDecoder::SetInitialDuration(int64_t aDuration)
 {
   MOZ_ASSERT(NS_IsMainThread());
   // Only use the decoded duration if one wasn't already
   // set.
   ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
   if (!mMediaSource || !IsNaN(ExplicitDuration())) {
--- a/dom/media/mediasource/MediaSourceDecoder.h
+++ b/dom/media/mediasource/MediaSourceDecoder.h
@@ -60,17 +60,16 @@ public:
 
   already_AddRefed<SourceBufferDecoder> CreateSubDecoder(const nsACString& aType,
                                                          int64_t aTimestampOffset /* microseconds */);
   void AddTrackBuffer(TrackBuffer* aTrackBuffer);
   void RemoveTrackBuffer(TrackBuffer* aTrackBuffer);
   void OnTrackBufferConfigured(TrackBuffer* aTrackBuffer, const MediaInfo& aInfo);
 
   void Ended(bool aEnded);
-  bool IsExpectingMoreData() override;
 
   // Return the duration of the video in seconds.
   virtual double GetDuration() override;
 
   void SetInitialDuration(int64_t aDuration);
   void SetMediaSourceDuration(double aDuration, MSRangeRemovalAction aAction);
   double GetMediaSourceDuration();
 
--- a/dom/media/mediasource/MediaSourceResource.h
+++ b/dom/media/mediasource/MediaSourceResource.h
@@ -72,16 +72,22 @@ public:
     return !mEnded;
   }
   void SetEnded(bool aEnded)
   {
     MonitorAutoLock mon(mMonitor);
     mEnded = aEnded;
   }
 
+  virtual bool IsExpectingMoreData() override
+  {
+    MonitorAutoLock mon(mMonitor);
+    return !mEnded;
+  }
+
 private:
   virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
   {
     size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
     size += mType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
 
     return size;
   }
--- a/dom/settings/SettingsRequestManager.jsm
+++ b/dom/settings/SettingsRequestManager.jsm
@@ -49,18 +49,22 @@ const kAllSettingsReadPermission       =
 const kAllSettingsWritePermission      = "settings" + kSettingsWriteSuffix;
 // Any application with settings permissions, be it for all settings
 // or a single one, will need to be able to access the settings API.
 // The settings-api permission allows an app to see the mozSettings
 // API in order to create locks and queue tasks. Whether these tasks
 // will be allowed depends on the exact permissions the app has.
 const kSomeSettingsReadPermission      = "settings-api" + kSettingsReadSuffix;
 const kSomeSettingsWritePermission     = "settings-api" + kSettingsWriteSuffix;
+
 // Time, in seconds, to consider the API is starting to jam
-const kSoftLockupDelta                 = 30;
+let kSoftLockupDelta = 30;
+try {
+  kSoftLockupDelta = Services.prefs.getIntPref("dom.mozSettings.softLockupDelta");
+} catch (ex) { }
 
 XPCOMUtils.defineLazyServiceGetter(this, "mrm",
                                    "@mozilla.org/memory-reporter-manager;1",
                                    "nsIMemoryReporterManager");
 XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
                                    "@mozilla.org/parentprocessmessagemanager;1",
                                    "nsIMessageBroadcaster");
 XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
--- a/dom/storage/DOMStorageManager.cpp
+++ b/dom/storage/DOMStorageManager.cpp
@@ -467,105 +467,74 @@ DOMStorageManager::GetLocalStorageForPri
 {
   if (mType != LocalStorage) {
     return NS_ERROR_UNEXPECTED;
   }
 
   return CreateStorage(nullptr, aPrincipal, aDocumentURI, aPrivate, aRetval);
 }
 
-namespace {
-
-class ClearCacheEnumeratorData
+void
+DOMStorageManager::ClearCaches(uint32_t aUnloadFlags,
+                               const nsACString& aKeyPrefix)
 {
-public:
-  explicit ClearCacheEnumeratorData(uint32_t aFlags)
-    : mUnloadFlags(aFlags)
-  {}
-
-  uint32_t mUnloadFlags;
-  nsCString mKeyPrefix;
-};
+  for (auto iter = mCaches.Iter(); !iter.Done(); iter.Next()) {
+    DOMStorageCache* cache = iter.Get()->cache();
+    nsCString& key = const_cast<nsCString&>(cache->Scope());
 
-} // namespace
-
-PLDHashOperator
-DOMStorageManager::ClearCacheEnumerator(DOMStorageCacheHashKey* aEntry, void* aClosure)
-{
-  DOMStorageCache* cache = aEntry->cache();
-  nsCString& key = const_cast<nsCString&>(cache->Scope());
-
-  ClearCacheEnumeratorData* data = static_cast<ClearCacheEnumeratorData*>(aClosure);
-
-  if (data->mKeyPrefix.IsEmpty() || StringBeginsWith(key, data->mKeyPrefix)) {
-    cache->UnloadItems(data->mUnloadFlags);
+    if (aKeyPrefix.IsEmpty() || StringBeginsWith(key, aKeyPrefix)) {
+      cache->UnloadItems(aUnloadFlags);
+    }
   }
-
-  return PL_DHASH_NEXT;
 }
 
 nsresult
 DOMStorageManager::Observe(const char* aTopic, const nsACString& aScopePrefix)
 {
   // Clear everything, caches + database
   if (!strcmp(aTopic, "cookie-cleared")) {
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadComplete);
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadComplete, EmptyCString());
     return NS_OK;
   }
 
   // Clear from caches everything that has been stored
   // while in session-only mode
   if (!strcmp(aTopic, "session-only-cleared")) {
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadSession);
-    data.mKeyPrefix = aScopePrefix;
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadSession, aScopePrefix);
     return NS_OK;
   }
 
   // Clear everything (including so and pb data) from caches and database
   // for the gived domain and subdomains.
   if (!strcmp(aTopic, "domain-data-cleared")) {
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadComplete);
-    data.mKeyPrefix = aScopePrefix;
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadComplete, aScopePrefix);
     return NS_OK;
   }
 
   // Clear all private-browsing caches
   if (!strcmp(aTopic, "private-browsing-data-cleared")) {
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadPrivate);
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadPrivate, EmptyCString());
     return NS_OK;
   }
 
   // Clear localStorage data beloging to an app.
   if (!strcmp(aTopic, "app-data-cleared")) {
 
     // sessionStorage is expected to stay
     if (mType == SessionStorage) {
       return NS_OK;
     }
 
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadComplete);
-    data.mKeyPrefix = aScopePrefix;
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadComplete, aScopePrefix);
     return NS_OK;
   }
 
   if (!strcmp(aTopic, "profile-change")) {
     // For case caches are still referenced - clear them completely
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadComplete);
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadComplete, EmptyCString());
     mCaches.Clear();
     return NS_OK;
   }
 
   if (!strcmp(aTopic, "low-disk-space")) {
     if (mType == LocalStorage) {
       mLowDiskSpace = true;
     }
@@ -583,18 +552,17 @@ DOMStorageManager::Observe(const char* a
 
 #ifdef DOM_STORAGE_TESTS
   if (!strcmp(aTopic, "test-reload")) {
     if (mType != LocalStorage) {
       return NS_OK;
     }
 
     // This immediately completely reloads all caches from the database.
-    ClearCacheEnumeratorData data(DOMStorageCache::kTestReload);
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
+    ClearCaches(DOMStorageCache::kTestReload, EmptyCString());
     return NS_OK;
   }
 
   if (!strcmp(aTopic, "test-flushed")) {
     if (!XRE_IsParentProcess()) {
       nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
       if (obs) {
         obs->NotifyObservers(nullptr, "domstorage-test-flushed", nullptr);
--- a/dom/storage/DOMStorageManager.h
+++ b/dom/storage/DOMStorageManager.h
@@ -94,18 +94,17 @@ private:
   const DOMStorage::StorageType mType;
 
   // If mLowDiskSpace is true it indicates a low device storage situation and
   // so no localStorage writes are allowed. sessionStorage writes are still
   // allowed.
   bool mLowDiskSpace;
   bool IsLowDiskSpace() const { return mLowDiskSpace; };
 
-  static PLDHashOperator ClearCacheEnumerator(DOMStorageCacheHashKey* aCache,
-                                              void* aClosure);
+  void ClearCaches(uint32_t aUnloadFlags, const nsACString& aKeyPrefix);
 
 protected:
   // Keeps usage cache objects for eTLD+1 scopes we have touched.
   nsDataHashtable<nsCStringHashKey, nsRefPtr<DOMStorageUsage> > mUsages;
 
   friend class DOMStorageCache;
   // Releases cache since it is no longer referrered by any DOMStorage object.
   virtual void DropCache(DOMStorageCache* aCache);
--- a/gfx/layers/composite/TiledContentHost.cpp
+++ b/gfx/layers/composite/TiledContentHost.cpp
@@ -291,16 +291,17 @@ TiledLayerBufferComposite::UseTiles(cons
     const TexturedTileDescriptor& texturedDesc = tileDesc.get_TexturedTileDescriptor();
 
     const TileLock& ipcLock = texturedDesc.sharedLock();
     if (!GetCopyOnWriteLock(ipcLock, tile, aAllocator)) {
       return false;
     }
 
     tile.mTextureHost = TextureHost::AsTextureHost(texturedDesc.textureParent());
+    tile.mTextureHost->SetCompositor(aCompositor);
 
     if (texturedDesc.textureOnWhite().type() == MaybeTexture::TPTextureParent) {
       tile.mTextureHostOnWhite =
         TextureHost::AsTextureHost(texturedDesc.textureOnWhite().get_PTextureParent());
     }
 
     tile.mTilePosition = newTiles.TilePosition(i);
 
--- a/js/src/asmjs/AsmJSValidate.cpp
+++ b/js/src/asmjs/AsmJSValidate.cpp
@@ -8492,27 +8492,27 @@ CheckComparison(FunctionBuilder& f, Pars
         !(lhsType.isDouble() && rhsType.isDouble()) &&
         !(lhsType.isFloat() && rhsType.isFloat()))
     {
         return f.failf(comp, "arguments to a comparison must both be signed, unsigned, floats or doubles; "
                        "%s and %s are given", lhsType.toChars(), rhsType.toChars());
     }
 
     I32 stmt;
-    if (lhsType.isSigned()) {
+    if (lhsType.isSigned() && rhsType.isSigned()) {
         switch (comp->getOp()) {
           case JSOP_EQ: stmt = I32::EqI32;  break;
           case JSOP_NE: stmt = I32::NeI32;  break;
           case JSOP_LT: stmt = I32::SLtI32; break;
           case JSOP_LE: stmt = I32::SLeI32; break;
           case JSOP_GT: stmt = I32::SGtI32; break;
           case JSOP_GE: stmt = I32::SGeI32; break;
           default: MOZ_CRASH("unexpected comparison op");
         }
-    } else if (lhsType.isUnsigned()) {
+    } else if (lhsType.isUnsigned() && rhsType.isUnsigned()) {
         switch (comp->getOp()) {
           case JSOP_EQ: stmt = I32::EqI32;  break;
           case JSOP_NE: stmt = I32::NeI32;  break;
           case JSOP_LT: stmt = I32::ULtI32; break;
           case JSOP_LE: stmt = I32::ULeI32; break;
           case JSOP_GT: stmt = I32::UGtI32; break;
           case JSOP_GE: stmt = I32::UGeI32; break;
           default: MOZ_CRASH("unexpected comparison op");
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -2646,16 +2646,42 @@ SetGCCallback(JSContext* cx, unsigned ar
         JS_ReportError(cx, "Unknown GC callback action");
         return false;
     }
 
     args.rval().setUndefined();
     return true;
 }
 
+static bool
+SetARMHwCapFlags(JSContext* cx, unsigned argc, Value* vp)
+{
+    CallArgs args = CallArgsFromVp(argc, vp);
+
+    if (args.length() != 1) {
+        JS_ReportError(cx, "Wrong number of arguments");
+        return false;
+    }
+
+    RootedString flagsListString(cx, JS::ToString(cx, args.get(0)));
+    if (!flagsListString)
+        return false;
+
+#if defined(JS_CODEGEN_ARM)
+    JSAutoByteString flagsList(cx, flagsListString);
+    if (!flagsList)
+        return false;
+
+    jit::ParseARMHwCapFlags(flagsList.ptr());
+#endif
+
+    args.rval().setUndefined();
+    return true;
+}
+
 static const JSFunctionSpecWithHelp TestingFunctions[] = {
     JS_FN_HELP("gc", ::GC, 0, 0,
 "gc([obj] | 'compartment' [, 'shrinking'])",
 "  Run the garbage collector. When obj is given, GC only its compartment.\n"
 "  If 'compartment' is given, GC any compartments that were scheduled for\n"
 "  GC via schedulegc.\n"
 "  If 'shrinking' is passed as the optional second argument, perform a\n"
 "  shrinking GC rather than a normal GC."),
@@ -3076,16 +3102,21 @@ gc::ZealModeHelpText),
 "  suitable for use in allocation tooling tests.\n"),
 
     JS_FN_HELP("setGCCallback", SetGCCallback, 1, 0,
 "setGCCallback({action:\"...\", options...})",
 "  Set the GC callback. action may be:\n"
 "    'minorGC' - run a nursery collection\n"
 "    'majorGC' - run a major collection, nesting up to a given 'depth'\n"),
 
+    JS_FN_HELP("setARMHwCapFlags", SetARMHwCapFlags, 1, 0,
+"setARMHwCapFlags(\"flag1,flag2 flag3\")",
+"  On non-ARM, no-op. On ARM, set the hardware capabilities. The list of \n"
+"  flags is available by calling this function with \"help\" as the flag's name"),
+
     JS_FS_HELP_END
 };
 
 static const JSPropertySpec TestingProperties[] = {
     JS_PSG("timesAccessed", TimesAccessed, 0),
     JS_PS_END
 };
 
--- a/js/src/jit-test/tests/asm.js/testAtomic-effect.js
+++ b/js/src/jit-test/tests/asm.js/testAtomic-effect.js
@@ -1,50 +1,49 @@
 // |jit-test| test-also-noasmjs
 if (!this.Atomics)
     quit();
 
-function m(stdlib, ffi, heap)
-{
+load(libdir + "asm.js");
+
+var code = `
     "use asm";
 
     var HEAP32 = new stdlib.SharedInt32Array(heap);
     var add = stdlib.Atomics.add;
     var load = stdlib.Atomics.load;
     var _emscripten_asm_const_int=ffi._emscripten_asm_const_int;
 
     // Regression test for bug 1154858 - Atomics.add for effect did
     // not get compiled properly because of an assembler bug.  This
     // kernel is derived from the large test case in that bug.
 
     function add_sharedEv(i1) {
-	i1 = i1 | 0;
-	var i2 = 0;
-	var xx = 0;
-	i2 = i1 + 4 | 0;
-	i1 = load(HEAP32, i2 >> 2) | 0;
-	_emscripten_asm_const_int(7, i2 | 0, i1 | 0) | 0;
-	add(HEAP32, i2 >> 2, 1) | 0;
-	_emscripten_asm_const_int(8, i2 | 0, load(HEAP32, i2 >> 2) | 0, i1 + 1 | 0) | 0;
-	return xx|0;
+        i1 = i1 | 0;
+        var i2 = 0;
+        var xx = 0;
+        i2 = i1 + 4 | 0;
+        i1 = load(HEAP32, i2 >> 2) | 0;
+        _emscripten_asm_const_int(7, i2 | 0, i1 | 0) | 0;
+        add(HEAP32, i2 >> 2, 1) | 0;
+        _emscripten_asm_const_int(8, i2 | 0, load(HEAP32, i2 >> 2) | 0, i1 + 1 | 0) | 0;
+        return xx|0;
     }
 
     return {add_sharedEv:add_sharedEv};
-}
-
-if (isAsmJSCompilationAvailable())
-    assertEq(isAsmJSModule(m), true);
+`;
 
 var x;
 
 var sab = new SharedArrayBuffer(65536);
 var ffi =
     { _emscripten_asm_const_int:
-      function (...rest) {
-	  //print("OUT: " + rest.join(" "));
-	  if (rest[0] == 8)
-	      x = rest[2];
-      }
+        function (...rest) {
+            //print("OUT: " + rest.join(" "));
+            if (rest[0] == 8)
+                x = rest[2];
+        }
     };
-var {add_sharedEv} = m(this, ffi, sab);
+var m = asmCompile('stdlib', 'ffi', 'heap', code);
+var {add_sharedEv} = asmLink(m, this, ffi, sab);
 add_sharedEv(13812);
 
 assertEq(x, 1);
--- a/js/src/jit-test/tests/asm.js/testAtomics.js
+++ b/js/src/jit-test/tests/asm.js/testAtomics.js
@@ -1,264 +1,262 @@
 // |jit-test| test-also-noasmjs
 if (!this.SharedArrayBuffer || !this.SharedInt32Array || !this.Atomics)
     quit();
 
 // The code duplication below is very far from elegant but provides
 // flexibility that comes in handy several places.
 
-function loadModule_int32(stdlib, foreign, heap) {
-    "use asm";
+load(libdir + "asm.js");
 
+var loadModule_int32_code =
+    USE_ASM + `
     var atomic_fence = stdlib.Atomics.fence;
     var atomic_load = stdlib.Atomics.load;
     var atomic_store = stdlib.Atomics.store;
     var atomic_cmpxchg = stdlib.Atomics.compareExchange;
     var atomic_exchange = stdlib.Atomics.exchange;
     var atomic_add = stdlib.Atomics.add;
     var atomic_sub = stdlib.Atomics.sub;
     var atomic_and = stdlib.Atomics.and;
     var atomic_or = stdlib.Atomics.or;
     var atomic_xor = stdlib.Atomics.xor;
 
     var i32a = new stdlib.SharedInt32Array(heap);
 
     function do_fence() {
-	atomic_fence();
+        atomic_fence();
     }
 
     // Load element 0
     function do_load() {
-	var v = 0;
-	v = atomic_load(i32a, 0)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_load(i32a, 0)|0;
+        return v|0;
     }
 
     // Load element i
     function do_load_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_load(i32a, i>>2)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_load(i32a, i>>2)|0;
+        return v|0;
     }
 
     // Store 37 in element 0
     function do_store() {
-	var v = 0;
-	v = atomic_store(i32a, 0, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_store(i32a, 0, 37)|0;
+        return v|0;
     }
 
     // Store 37 in element i
     function do_store_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_store(i32a, i>>2, 37)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_store(i32a, i>>2, 37)|0;
+        return v|0;
     }
 
     // Exchange 37 into element 200
     function do_xchg() {
-	var v = 0;
-	v = atomic_exchange(i32a, 200, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_exchange(i32a, 200, 37)|0;
+        return v|0;
     }
 
     // Exchange 42 into element i
     function do_xchg_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_exchange(i32a, i>>2, 42)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_exchange(i32a, i>>2, 42)|0;
+        return v|0;
     }
 
     // Exchange 1+2 into element 200.  This is not called; all we're
     // checking is that the compilation succeeds, since 1+2 has type
     // "intish" (asm.js spec "AdditiveExpression") and this should be
     // allowed.
     function do_xchg_intish() {
-	var v = 0;
-	v = atomic_exchange(i32a, 200, 1+2)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_exchange(i32a, 200, 1+2)|0;
+        return v|0;
     }
 
     // Add 37 to element 10
     function do_add() {
-	var v = 0;
-	v = atomic_add(i32a, 10, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_add(i32a, 10, 37)|0;
+        return v|0;
     }
 
     // Add 37 to element i
     function do_add_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_add(i32a, i>>2, 37)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_add(i32a, i>>2, 37)|0;
+        return v|0;
     }
 
     // As for do_xchg_intish, above.  Given the structure of the
     // compiler, this covers all the binops.
     function do_add_intish() {
-	var v = 0;
-	v = atomic_add(i32a, 10, 1+2)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_add(i32a, 10, 1+2)|0;
+        return v|0;
     }
 
     // Subtract 148 from element 20
     function do_sub() {
-	var v = 0;
-	v = atomic_sub(i32a, 20, 148)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_sub(i32a, 20, 148)|0;
+        return v|0;
     }
 
     // Subtract 148 from element i
     function do_sub_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_sub(i32a, i>>2, 148)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_sub(i32a, i>>2, 148)|0;
+        return v|0;
     }
 
     // AND 0x33333333 into element 30
     function do_and() {
-	var v = 0;
-	v = atomic_and(i32a, 30, 0x33333333)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_and(i32a, 30, 0x33333333)|0;
+        return v|0;
     }
 
     // AND 0x33333333 into element i
     function do_and_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_and(i32a, i>>2, 0x33333333)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_and(i32a, i>>2, 0x33333333)|0;
+        return v|0;
     }
 
     // OR 0x33333333 into element 40
     function do_or() {
-	var v = 0;
-	v = atomic_or(i32a, 40, 0x33333333)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_or(i32a, 40, 0x33333333)|0;
+        return v|0;
     }
 
     // OR 0x33333333 into element i
     function do_or_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_or(i32a, i>>2, 0x33333333)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_or(i32a, i>>2, 0x33333333)|0;
+        return v|0;
     }
 
     // XOR 0x33333333 into element 50
     function do_xor() {
-	var v = 0;
-	v = atomic_xor(i32a, 50, 0x33333333)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_xor(i32a, 50, 0x33333333)|0;
+        return v|0;
     }
 
     // XOR 0x33333333 into element i
     function do_xor_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_xor(i32a, i>>2, 0x33333333)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_xor(i32a, i>>2, 0x33333333)|0;
+        return v|0;
     }
 
     // CAS element 100: 0 -> -1
     function do_cas1() {
-	var v = 0;
-	v = atomic_cmpxchg(i32a, 100, 0, -1)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_cmpxchg(i32a, 100, 0, -1)|0;
+        return v|0;
     }
 
     // As for do_xchg_intish, above.  Will not be called, is here just
     // to test that the compiler allows intish arguments.
     function do_cas_intish() {
-	var v = 0;
-	v = atomic_cmpxchg(i32a, 100, 1+2, 2+3)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_cmpxchg(i32a, 100, 1+2, 2+3)|0;
+        return v|0;
     }
 
     // CAS element 100: -1 -> 0x5A5A5A5A
     function do_cas2() {
-	var v = 0;
-	v = atomic_cmpxchg(i32a, 100, -1, 0x5A5A5A5A)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_cmpxchg(i32a, 100, -1, 0x5A5A5A5A)|0;
+        return v|0;
     }
 
     // CAS element i: 0 -> -1
     function do_cas1_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i32a, i>>2, 0, -1)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i32a, i>>2, 0, -1)|0;
+        return v|0;
     }
 
     // CAS element i: -1 -> 0x5A5A5A5A
     function do_cas2_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i32a, i>>2, -1, 0x5A5A5A5A)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i32a, i>>2, -1, 0x5A5A5A5A)|0;
+        return v|0;
     }
 
     return { fence: do_fence,
-	     load: do_load,
-	     load_i: do_load_i,
-	     store: do_store,
-	     store_i: do_store_i,
-	     xchg: do_xchg,
-	     xchg_i: do_xchg_i,
-	     xchg_intish: do_xchg_intish,
-	     add: do_add,
-	     add_i: do_add_i,
-	     add_intish: do_add_intish,
-	     sub: do_sub,
-	     sub_i: do_sub_i,
-	     and: do_and,
-	     and_i: do_and_i,
-	     or: do_or,
-	     or_i: do_or_i,
-	     xor: do_xor,
-	     xor_i: do_xor_i,
-	     cas1: do_cas1,
-	     cas2: do_cas2,
-	     cas_intish: do_cas_intish,
-	     cas1_i: do_cas1_i,
-	     cas2_i: do_cas2_i };
-}
+        load: do_load,
+        load_i: do_load_i,
+        store: do_store,
+        store_i: do_store_i,
+        xchg: do_xchg,
+        xchg_i: do_xchg_i,
+        xchg_intish: do_xchg_intish,
+        add: do_add,
+        add_i: do_add_i,
+        add_intish: do_add_intish,
+        sub: do_sub,
+        sub_i: do_sub_i,
+        and: do_and,
+        and_i: do_and_i,
+        or: do_or,
+        or_i: do_or_i,
+        xor: do_xor,
+        xor_i: do_xor_i,
+        cas1: do_cas1,
+        cas2: do_cas2,
+        cas_intish: do_cas_intish,
+        cas1_i: do_cas1_i,
+        cas2_i: do_cas2_i };
+`;
 
-if (isAsmJSCompilationAvailable())
-    assertEq(isAsmJSModule(loadModule_int32), true);
+var loadModule_int32 = asmCompile('stdlib', 'foreign', 'heap', loadModule_int32_code);
 
 // Test that compilation fails without a coercion on the return value.
 // The module is never created, we use it only for its effect.
 
-function loadModule_int32_return_xchg(stdlib, foreign, heap) {
-    "use asm";
-
+var loadModule_int32_return_xchg_code =
+    USE_ASM + `
     var atomic_exchange = stdlib.Atomics.exchange;
     var i32a = new stdlib.SharedInt32Array(heap);
 
     function do_xchg() {
-	var v = 0;
-	v = atomic_exchange(i32a, 200, 37); // Should not be allowed without |0 at the end
-	return v|0;
+        var v = 0;
+        v = atomic_exchange(i32a, 200, 37); // Should not be allowed without |0 at the end
+        return v|0;
     }
 
     return { xchg: do_xchg }
-}
+`;
 
-if (isAsmJSCompilationAvailable())
-    assertEq(isAsmJSModule(loadModule_int32_return_xchg), false);
+assertAsmTypeFail('stdlib', 'foreign', 'heap', loadModule_int32_return_xchg_code);
 
 function test_int32(heap) {
     var i32a = new SharedInt32Array(heap);
-    var i32m = loadModule_int32(this, {}, heap);
+    var i32m = asmLink(loadModule_int32, this, {}, heap);
 
     var size = SharedInt32Array.BYTES_PER_ELEMENT;
 
     i32m.fence();
 
     i32a[0] = 12345;
     assertEq(i32m.load(), 12345);
     assertEq(i32m.load_i(size*0), 12345);
@@ -325,206 +323,204 @@ function test_int32(heap) {
 
     assertEq(i32m.or_i(oob), 0);
     assertEq(i32m.xor_i(oob), 0);
     assertEq(i32m.and_i(oob), 0);
     assertEq(i32m.add_i(oob), 0);
     assertEq(i32m.sub_i(oob), 0);
 }
 
-function loadModule_uint32(stdlib, foreign, heap) {
-    "use asm";
-
+var loadModule_uint32_code =
+    USE_ASM + `
     var atomic_fence = stdlib.Atomics.fence;
     var atomic_load = stdlib.Atomics.load;
     var atomic_store = stdlib.Atomics.store;
     var atomic_cmpxchg = stdlib.Atomics.compareExchange;
     var atomic_exchange = stdlib.Atomics.exchange;
     var atomic_add = stdlib.Atomics.add;
     var atomic_sub = stdlib.Atomics.sub;
     var atomic_and = stdlib.Atomics.and;
     var atomic_or = stdlib.Atomics.or;
     var atomic_xor = stdlib.Atomics.xor;
 
     var i32a = new stdlib.SharedUint32Array(heap);
 
     // Load element 0
     function do_load() {
-	var v = 0;
-	v = atomic_load(i32a, 0)|0;
-	return +(v>>>0);
+        var v = 0;
+        v = atomic_load(i32a, 0)|0;
+        return +(v>>>0);
     }
 
     // Load element i
     function do_load_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_load(i32a, i>>2)|0;
-	return +(v>>>0);
+        i = i|0;
+        var v = 0;
+        v = atomic_load(i32a, i>>2)|0;
+        return +(v>>>0);
     }
 
     // Store 37 in element 0
     function do_store() {
-	var v = 0;
-	v = atomic_store(i32a, 0, 37)|0;
-	return +(v>>>0);
+        var v = 0;
+        v = atomic_store(i32a, 0, 37)|0;
+        return +(v>>>0);
     }
 
     // Store 37 in element i
     function do_store_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_store(i32a, i>>2, 37)|0;
-	return +(v>>>0);
+        i = i|0;
+        var v = 0;
+        v = atomic_store(i32a, i>>2, 37)|0;
+        return +(v>>>0);
     }
 
     // Exchange 37 into element 200
     function do_xchg() {
-	var v = 0;
-	v = atomic_exchange(i32a, 200, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_exchange(i32a, 200, 37)|0;
+        return v|0;
     }
 
     // Exchange 42 into element i
     function do_xchg_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_exchange(i32a, i>>2, 42)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_exchange(i32a, i>>2, 42)|0;
+        return v|0;
     }
 
     // Add 37 to element 10
     function do_add() {
-	var v = 0;
-	v = atomic_add(i32a, 10, 37)|0;
-	return +(v>>>0);
+        var v = 0;
+        v = atomic_add(i32a, 10, 37)|0;
+        return +(v>>>0);
     }
 
     // Add 37 to element i
     function do_add_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_add(i32a, i>>2, 37)|0;
-	return +(v>>>0);
+        i = i|0;
+        var v = 0;
+        v = atomic_add(i32a, i>>2, 37)|0;
+        return +(v>>>0);
     }
 
     // Subtract 148 from element 20
     function do_sub() {
-	var v = 0;
-	v = atomic_sub(i32a, 20, 148)|0;
-	return +(v>>>0);
+        var v = 0;
+        v = atomic_sub(i32a, 20, 148)|0;
+        return +(v>>>0);
     }
 
     // Subtract 148 from element i
     function do_sub_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_sub(i32a, i>>2, 148)|0;
-	return +(v>>>0);
+        i = i|0;
+        var v = 0;
+        v = atomic_sub(i32a, i>>2, 148)|0;
+        return +(v>>>0);
     }
 
     // AND 0x33333333 into element 30
     function do_and() {
-	var v = 0;
-	v = atomic_and(i32a, 30, 0x33333333)|0;
-	return +(v>>>0);
+        var v = 0;
+        v = atomic_and(i32a, 30, 0x33333333)|0;
+        return +(v>>>0);
     }
 
     // AND 0x33333333 into element i
     function do_and_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_and(i32a, i>>2, 0x33333333)|0;
-	return +(v>>>0);
+        i = i|0;
+        var v = 0;
+        v = atomic_and(i32a, i>>2, 0x33333333)|0;
+        return +(v>>>0);
     }
 
     // OR 0x33333333 into element 40
     function do_or() {
-	var v = 0;
-	v = atomic_or(i32a, 40, 0x33333333)|0;
-	return +(v>>>0);
+        var v = 0;
+        v = atomic_or(i32a, 40, 0x33333333)|0;
+        return +(v>>>0);
     }
 
     // OR 0x33333333 into element i
     function do_or_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_or(i32a, i>>2, 0x33333333)|0;
-	return +(v>>>0);
+        i = i|0;
+        var v = 0;
+        v = atomic_or(i32a, i>>2, 0x33333333)|0;
+        return +(v>>>0);
     }
 
     // XOR 0x33333333 into element 50
     function do_xor() {
-	var v = 0;
-	v = atomic_xor(i32a, 50, 0x33333333)|0;
-	return +(v>>>0);
+        var v = 0;
+        v = atomic_xor(i32a, 50, 0x33333333)|0;
+        return +(v>>>0);
     }
 
     // XOR 0x33333333 into element i
     function do_xor_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_xor(i32a, i>>2, 0x33333333)|0;
-	return +(v>>>0);
+        i = i|0;
+        var v = 0;
+        v = atomic_xor(i32a, i>>2, 0x33333333)|0;
+        return +(v>>>0);
     }
 
     // CAS element 100: 0 -> -1
     function do_cas1() {
-	var v = 0;
-	v = atomic_cmpxchg(i32a, 100, 0, -1)|0;
-	return +(v>>>0);
+        var v = 0;
+        v = atomic_cmpxchg(i32a, 100, 0, -1)|0;
+        return +(v>>>0);
     }
 
     // CAS element 100: -1 -> 0x5A5A5A5A
     function do_cas2() {
-	var v = 0;
-	v = atomic_cmpxchg(i32a, 100, -1, 0x5A5A5A5A)|0;
-	return +(v>>>0);
+        var v = 0;
+        v = atomic_cmpxchg(i32a, 100, -1, 0x5A5A5A5A)|0;
+        return +(v>>>0);
     }
 
     // CAS element i: 0 -> -1
     function do_cas1_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i32a, i>>2, 0, -1)|0;
-	return +(v>>>0);
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i32a, i>>2, 0, -1)|0;
+        return +(v>>>0);
     }
 
     // CAS element i: -1 -> 0x5A5A5A5A
     function do_cas2_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i32a, i>>2, -1, 0x5A5A5A5A)|0;
-	return +(v>>>0);
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i32a, i>>2, -1, 0x5A5A5A5A)|0;
+        return +(v>>>0);
     }
 
     return { load: do_load,
-	     load_i: do_load_i,
-	     store: do_store,
-	     store_i: do_store_i,
-	     xchg: do_xchg,
-	     xchg_i: do_xchg_i,
-	     add: do_add,
-	     add_i: do_add_i,
-	     sub: do_sub,
-	     sub_i: do_sub_i,
-	     and: do_and,
-	     and_i: do_and_i,
-	     or: do_or,
-	     or_i: do_or_i,
-	     xor: do_xor,
-	     xor_i: do_xor_i,
-	     cas1: do_cas1,
-	     cas2: do_cas2,
-	     cas1_i: do_cas1_i,
-	     cas2_i: do_cas2_i };
-}
+        load_i: do_load_i,
+        store: do_store,
+        store_i: do_store_i,
+        xchg: do_xchg,
+        xchg_i: do_xchg_i,
+        add: do_add,
+        add_i: do_add_i,
+        sub: do_sub,
+        sub_i: do_sub_i,
+        and: do_and,
+        and_i: do_and_i,
+        or: do_or,
+        or_i: do_or_i,
+        xor: do_xor,
+        xor_i: do_xor_i,
+        cas1: do_cas1,
+        cas2: do_cas2,
+        cas1_i: do_cas1_i,
+        cas2_i: do_cas2_i };
+`;
 
-if (isAsmJSCompilationAvailable())
-    assertEq(isAsmJSModule(loadModule_uint32), true);
+var loadModule_uint32 = asmCompile('stdlib', 'foreign', 'heap', loadModule_uint32_code);
 
 function test_uint32(heap) {
     var i32a = new SharedUint32Array(heap);
     var i32m = loadModule_uint32(this, {}, heap);
 
     var size = SharedUint32Array.BYTES_PER_ELEMENT;
 
     i32a[0] = 12345;
@@ -593,211 +589,209 @@ function test_uint32(heap) {
 
     assertEq(i32m.or_i(oob), 0);
     assertEq(i32m.xor_i(oob), 0);
     assertEq(i32m.and_i(oob), 0);
     assertEq(i32m.add_i(oob), 0);
     assertEq(i32m.sub_i(oob), 0);
 }
 
-function loadModule_int16(stdlib, foreign, heap) {
-    "use asm";
-
+var loadModule_int16_code =
+    USE_ASM + `
     var atomic_fence = stdlib.Atomics.fence;
     var atomic_load = stdlib.Atomics.load;
     var atomic_store = stdlib.Atomics.store;
     var atomic_cmpxchg = stdlib.Atomics.compareExchange;
     var atomic_exchange = stdlib.Atomics.exchange;
     var atomic_add = stdlib.Atomics.add;
     var atomic_sub = stdlib.Atomics.sub;
     var atomic_and = stdlib.Atomics.and;
     var atomic_or = stdlib.Atomics.or;
     var atomic_xor = stdlib.Atomics.xor;
 
     var i16a = new stdlib.SharedInt16Array(heap);
 
     function do_fence() {
-	atomic_fence();
+        atomic_fence();
     }
 
     // Load element 0
     function do_load() {
-	var v = 0;
-	v = atomic_load(i16a, 0)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_load(i16a, 0)|0;
+        return v|0;
     }
 
     // Load element i
     function do_load_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_load(i16a, i>>1)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_load(i16a, i>>1)|0;
+        return v|0;
     }
 
     // Store 37 in element 0
     function do_store() {
-	var v = 0;
-	v = atomic_store(i16a, 0, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_store(i16a, 0, 37)|0;
+        return v|0;
     }
 
     // Store 37 in element i
     function do_store_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_store(i16a, i>>1, 37)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_store(i16a, i>>1, 37)|0;
+        return v|0;
     }
 
     // Exchange 37 into element 200
     function do_xchg() {
-	var v = 0;
-	v = atomic_exchange(i16a, 200, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_exchange(i16a, 200, 37)|0;
+        return v|0;
     }
 
     // Exchange 42 into element i
     function do_xchg_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_exchange(i16a, i>>1, 42)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_exchange(i16a, i>>1, 42)|0;
+        return v|0;
     }
 
     // Add 37 to element 10
     function do_add() {
-	var v = 0;
-	v = atomic_add(i16a, 10, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_add(i16a, 10, 37)|0;
+        return v|0;
     }
 
     // Add 37 to element i
     function do_add_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_add(i16a, i>>1, 37)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_add(i16a, i>>1, 37)|0;
+        return v|0;
     }
 
     // Subtract 148 from element 20
     function do_sub() {
-	var v = 0;
-	v = atomic_sub(i16a, 20, 148)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_sub(i16a, 20, 148)|0;
+        return v|0;
     }
 
     // Subtract 148 from element i
     function do_sub_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_sub(i16a, i>>1, 148)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_sub(i16a, i>>1, 148)|0;
+        return v|0;
     }
 
     // AND 0x3333 into element 30
     function do_and() {
-	var v = 0;
-	v = atomic_and(i16a, 30, 0x3333)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_and(i16a, 30, 0x3333)|0;
+        return v|0;
     }
 
     // AND 0x3333 into element i
     function do_and_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_and(i16a, i>>1, 0x3333)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_and(i16a, i>>1, 0x3333)|0;
+        return v|0;
     }
 
     // OR 0x3333 into element 40
     function do_or() {
-	var v = 0;
-	v = atomic_or(i16a, 40, 0x3333)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_or(i16a, 40, 0x3333)|0;
+        return v|0;
     }
 
     // OR 0x3333 into element i
     function do_or_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_or(i16a, i>>1, 0x3333)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_or(i16a, i>>1, 0x3333)|0;
+        return v|0;
     }
 
     // XOR 0x3333 into element 50
     function do_xor() {
-	var v = 0;
-	v = atomic_xor(i16a, 50, 0x3333)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_xor(i16a, 50, 0x3333)|0;
+        return v|0;
     }
 
     // XOR 0x3333 into element i
     function do_xor_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_xor(i16a, i>>1, 0x3333)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_xor(i16a, i>>1, 0x3333)|0;
+        return v|0;
     }
 
     // CAS element 100: 0 -> -1
     function do_cas1() {
-	var v = 0;
-	v = atomic_cmpxchg(i16a, 100, 0, -1)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_cmpxchg(i16a, 100, 0, -1)|0;
+        return v|0;
     }
 
     // CAS element 100: -1 -> 0x5A5A
     function do_cas2() {
-	var v = 0;
-	v = atomic_cmpxchg(i16a, 100, -1, 0x5A5A)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_cmpxchg(i16a, 100, -1, 0x5A5A)|0;
+        return v|0;
     }
 
     // CAS element i: 0 -> -1
     function do_cas1_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i16a, i>>1, 0, -1)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i16a, i>>1, 0, -1)|0;
+        return v|0;
     }
 
     // CAS element i: -1 -> 0x5A5A
     function do_cas2_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i16a, i>>1, -1, 0x5A5A)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i16a, i>>1, -1, 0x5A5A)|0;
+        return v|0;
     }
 
     return { fence: do_fence,
-	     load: do_load,
-	     load_i: do_load_i,
-	     store: do_store,
-	     store_i: do_store_i,
-	     xchg: do_xchg,
-	     xchg_i: do_xchg_i,
-	     add: do_add,
-	     add_i: do_add_i,
-	     sub: do_sub,
-	     sub_i: do_sub_i,
-	     and: do_and,
-	     and_i: do_and_i,
-	     or: do_or,
-	     or_i: do_or_i,
-	     xor: do_xor,
-	     xor_i: do_xor_i,
-	     cas1: do_cas1,
-	     cas2: do_cas2,
-	     cas1_i: do_cas1_i,
-	     cas2_i: do_cas2_i };
-}
+        load: do_load,
+        load_i: do_load_i,
+        store: do_store,
+        store_i: do_store_i,
+        xchg: do_xchg,
+        xchg_i: do_xchg_i,
+        add: do_add,
+        add_i: do_add_i,
+        sub: do_sub,
+        sub_i: do_sub_i,
+        and: do_and,
+        and_i: do_and_i,
+        or: do_or,
+        or_i: do_or_i,
+        xor: do_xor,
+        xor_i: do_xor_i,
+        cas1: do_cas1,
+        cas2: do_cas2,
+        cas1_i: do_cas1_i,
+        cas2_i: do_cas2_i };
+`
 
-if (isAsmJSCompilationAvailable())
-    assertEq(isAsmJSModule(loadModule_int16), true);
+var loadModule_int16 = asmCompile('stdlib', 'foreign', 'heap', loadModule_int16_code);
 
 function test_int16(heap) {
     var i16a = new SharedInt16Array(heap);
     var i16m = loadModule_int16(this, {}, heap);
 
     var size = SharedInt16Array.BYTES_PER_ELEMENT;
 
     i16m.fence();
@@ -876,205 +870,203 @@ function test_int16(heap) {
 
     assertEq(i16m.or_i(oob), 0);
     assertEq(i16m.xor_i(oob), 0);
     assertEq(i16m.and_i(oob), 0);
     assertEq(i16m.add_i(oob), 0);
     assertEq(i16m.sub_i(oob), 0);
 }
 
-function loadModule_uint16(stdlib, foreign, heap) {
-    "use asm";
-
+var loadModule_uint16_code =
+    USE_ASM + `
     var atomic_load = stdlib.Atomics.load;
     var atomic_store = stdlib.Atomics.store;
     var atomic_cmpxchg = stdlib.Atomics.compareExchange;
     var atomic_exchange = stdlib.Atomics.exchange;
     var atomic_add = stdlib.Atomics.add;
     var atomic_sub = stdlib.Atomics.sub;
     var atomic_and = stdlib.Atomics.and;
     var atomic_or = stdlib.Atomics.or;
     var atomic_xor = stdlib.Atomics.xor;
 
     var i16a = new stdlib.SharedUint16Array(heap);
 
     // Load element 0
     function do_load() {
-	var v = 0;
-	v = atomic_load(i16a, 0)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_load(i16a, 0)|0;
+        return v|0;
     }
 
     // Load element i
     function do_load_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_load(i16a, i>>1)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_load(i16a, i>>1)|0;
+        return v|0;
     }
 
     // Store 37 in element 0
     function do_store() {
-	var v = 0;
-	v = atomic_store(i16a, 0, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_store(i16a, 0, 37)|0;
+        return v|0;
     }
 
     // Store 37 in element i
     function do_store_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_store(i16a, i>>1, 37)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_store(i16a, i>>1, 37)|0;
+        return v|0;
     }
 
     // Exchange 37 into element 200
     function do_xchg() {
-	var v = 0;
-	v = atomic_exchange(i16a, 200, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_exchange(i16a, 200, 37)|0;
+        return v|0;
     }
 
     // Exchange 42 into element i
     function do_xchg_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_exchange(i16a, i>>1, 42)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_exchange(i16a, i>>1, 42)|0;
+        return v|0;
     }
 
     // Add 37 to element 10
     function do_add() {
-	var v = 0;
-	v = atomic_add(i16a, 10, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_add(i16a, 10, 37)|0;
+        return v|0;
     }
 
     // Add 37 to element i
     function do_add_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_add(i16a, i>>1, 37)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_add(i16a, i>>1, 37)|0;
+        return v|0;
     }
 
     // Subtract 148 from element 20
     function do_sub() {
-	var v = 0;
-	v = atomic_sub(i16a, 20, 148)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_sub(i16a, 20, 148)|0;
+        return v|0;
     }
 
     // Subtract 148 from element i
     function do_sub_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_sub(i16a, i>>1, 148)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_sub(i16a, i>>1, 148)|0;
+        return v|0;
     }
 
     // AND 0x3333 into element 30
     function do_and() {
-	var v = 0;
-	v = atomic_and(i16a, 30, 0x3333)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_and(i16a, 30, 0x3333)|0;
+        return v|0;
     }
 
     // AND 0x3333 into element i
     function do_and_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_and(i16a, i>>1, 0x3333)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_and(i16a, i>>1, 0x3333)|0;
+        return v|0;
     }
 
     // OR 0x3333 into element 40
     function do_or() {
-	var v = 0;
-	v = atomic_or(i16a, 40, 0x3333)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_or(i16a, 40, 0x3333)|0;
+        return v|0;
     }
 
     // OR 0x3333 into element i
     function do_or_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_or(i16a, i>>1, 0x3333)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_or(i16a, i>>1, 0x3333)|0;
+        return v|0;
     }
 
     // XOR 0x3333 into element 50
     function do_xor() {
-	var v = 0;
-	v = atomic_xor(i16a, 50, 0x3333)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_xor(i16a, 50, 0x3333)|0;
+        return v|0;
     }
 
     // XOR 0x3333 into element i
     function do_xor_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_xor(i16a, i>>1, 0x3333)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_xor(i16a, i>>1, 0x3333)|0;
+        return v|0;
     }
 
     // CAS element 100: 0 -> -1
     function do_cas1() {
-	var v = 0;
-	v = atomic_cmpxchg(i16a, 100, 0, -1)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_cmpxchg(i16a, 100, 0, -1)|0;
+        return v|0;
     }
 
     // CAS element 100: -1 -> 0x5A5A
     function do_cas2() {
-	var v = 0;
-	v = atomic_cmpxchg(i16a, 100, -1, 0x5A5A)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_cmpxchg(i16a, 100, -1, 0x5A5A)|0;
+        return v|0;
     }
 
     // CAS element i: 0 -> -1
     function do_cas1_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i16a, i>>1, 0, -1)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i16a, i>>1, 0, -1)|0;
+        return v|0;
     }
 
     // CAS element i: -1 -> 0x5A5A
     function do_cas2_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i16a, i>>1, -1, 0x5A5A)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i16a, i>>1, -1, 0x5A5A)|0;
+        return v|0;
     }
 
     return { load: do_load,
-	     load_i: do_load_i,
-	     store: do_store,
-	     store_i: do_store_i,
-	     xchg: do_xchg,
-	     xchg_i: do_xchg_i,
-	     add: do_add,
-	     add_i: do_add_i,
-	     sub: do_sub,
-	     sub_i: do_sub_i,
-	     and: do_and,
-	     and_i: do_and_i,
-	     or: do_or,
-	     or_i: do_or_i,
-	     xor: do_xor,
-	     xor_i: do_xor_i,
-	     cas1: do_cas1,
-	     cas2: do_cas2,
-	     cas1_i: do_cas1_i,
-	     cas2_i: do_cas2_i };
-}
+        load_i: do_load_i,
+        store: do_store,
+        store_i: do_store_i,
+        xchg: do_xchg,
+        xchg_i: do_xchg_i,
+        add: do_add,
+        add_i: do_add_i,
+        sub: do_sub,
+        sub_i: do_sub_i,
+        and: do_and,
+        and_i: do_and_i,
+        or: do_or,
+        or_i: do_or_i,
+        xor: do_xor,
+        xor_i: do_xor_i,
+        cas1: do_cas1,
+        cas2: do_cas2,
+        cas1_i: do_cas1_i,
+        cas2_i: do_cas2_i };
+`
 
-if (isAsmJSCompilationAvailable())
-    assertEq(isAsmJSModule(loadModule_uint16), true);
+var loadModule_uint16 = asmCompile('stdlib', 'foreign', 'heap', loadModule_uint16_code);
 
 function test_uint16(heap) {
     var i16a = new SharedUint16Array(heap);
     var i16m = loadModule_uint16(this, {}, heap);
 
     var size = SharedUint16Array.BYTES_PER_ELEMENT;
 
     i16a[0] = 12345;
@@ -1151,205 +1143,203 @@ function test_uint16(heap) {
 
     assertEq(i16m.or_i(oob), 0);
     assertEq(i16m.xor_i(oob), 0);
     assertEq(i16m.and_i(oob), 0);
     assertEq(i16m.add_i(oob), 0);
     assertEq(i16m.sub_i(oob), 0);
 }
 
-function loadModule_int8(stdlib, foreign, heap) {
-    "use asm";
-
+var loadModule_int8_code =
+    USE_ASM + `
     var atomic_load = stdlib.Atomics.load;
     var atomic_store = stdlib.Atomics.store;
     var atomic_cmpxchg = stdlib.Atomics.compareExchange;
     var atomic_exchange = stdlib.Atomics.exchange;
     var atomic_add = stdlib.Atomics.add;
     var atomic_sub = stdlib.Atomics.sub;
     var atomic_and = stdlib.Atomics.and;
     var atomic_or = stdlib.Atomics.or;
     var atomic_xor = stdlib.Atomics.xor;
 
     var i8a = new stdlib.SharedInt8Array(heap);
 
     // Load element 0
     function do_load() {
-	var v = 0;
-	v = atomic_load(i8a, 0)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_load(i8a, 0)|0;
+        return v|0;
     }
 
     // Load element i
     function do_load_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_load(i8a, i)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_load(i8a, i)|0;
+        return v|0;
     }
 
     // Store 37 in element 0
     function do_store() {
-	var v = 0;
-	v = atomic_store(i8a, 0, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_store(i8a, 0, 37)|0;
+        return v|0;
     }
 
     // Store 37 in element i
     function do_store_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_store(i8a, i, 37)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_store(i8a, i, 37)|0;
+        return v|0;
     }
 
     // Exchange 37 into element 200
     function do_xchg() {
-	var v = 0;
-	v = atomic_exchange(i8a, 200, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_exchange(i8a, 200, 37)|0;
+        return v|0;
     }
 
     // Exchange 42 into element i
     function do_xchg_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_exchange(i8a, i, 42)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_exchange(i8a, i, 42)|0;
+        return v|0;
     }
 
     // Add 37 to element 10
     function do_add() {
-	var v = 0;
-	v = atomic_add(i8a, 10, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_add(i8a, 10, 37)|0;
+        return v|0;
     }
 
     // Add 37 to element i
     function do_add_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_add(i8a, i, 37)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_add(i8a, i, 37)|0;
+        return v|0;
     }
 
     // Subtract 108 from element 20
     function do_sub() {
-	var v = 0;
-	v = atomic_sub(i8a, 20, 108)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_sub(i8a, 20, 108)|0;
+        return v|0;
     }
 
     // Subtract 108 from element i
     function do_sub_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_sub(i8a, i, 108)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_sub(i8a, i, 108)|0;
+        return v|0;
     }
 
     // AND 0x33 into element 30
     function do_and() {
-	var v = 0;
-	v = atomic_and(i8a, 30, 0x33)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_and(i8a, 30, 0x33)|0;
+        return v|0;
     }
 
     // AND 0x33 into element i
     function do_and_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_and(i8a, i, 0x33)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_and(i8a, i, 0x33)|0;
+        return v|0;
     }
 
     // OR 0x33 into element 40
     function do_or() {
-	var v = 0;
-	v = atomic_or(i8a, 40, 0x33)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_or(i8a, 40, 0x33)|0;
+        return v|0;
     }
 
     // OR 0x33 into element i
     function do_or_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_or(i8a, i, 0x33)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_or(i8a, i, 0x33)|0;
+        return v|0;
     }
 
     // XOR 0x33 into element 50
     function do_xor() {
-	var v = 0;
-	v = atomic_xor(i8a, 50, 0x33)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_xor(i8a, 50, 0x33)|0;
+        return v|0;
     }
 
     // XOR 0x33 into element i
     function do_xor_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_xor(i8a, i, 0x33)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_xor(i8a, i, 0x33)|0;
+        return v|0;
     }
 
     // CAS element 100: 0 -> -1
     function do_cas1() {
-	var v = 0;
-	v = atomic_cmpxchg(i8a, 100, 0, -1)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_cmpxchg(i8a, 100, 0, -1)|0;
+        return v|0;
     }
 
     // CAS element 100: -1 -> 0x5A
     function do_cas2() {
-	var v = 0;
-	v = atomic_cmpxchg(i8a, 100, -1, 0x5A)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_cmpxchg(i8a, 100, -1, 0x5A)|0;
+        return v|0;
     }
 
     // CAS element i: 0 -> -1
     function do_cas1_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i8a, i, 0, -1)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i8a, i, 0, -1)|0;
+        return v|0;
     }
 
     // CAS element i: -1 -> 0x5A
     function do_cas2_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i8a, i, -1, 0x5A)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i8a, i, -1, 0x5A)|0;
+        return v|0;
     }
 
     return { load: do_load,
-	     load_i: do_load_i,
-	     store: do_store,
-	     store_i: do_store_i,
-	     xchg: do_xchg,
-	     xchg_i: do_xchg_i,
-	     add: do_add,
-	     add_i: do_add_i,
-	     sub: do_sub,
-	     sub_i: do_sub_i,
-	     and: do_and,
-	     and_i: do_and_i,
-	     or: do_or,
-	     or_i: do_or_i,
-	     xor: do_xor,
-	     xor_i: do_xor_i,
-	     cas1: do_cas1,
-	     cas2: do_cas2,
-	     cas1_i: do_cas1_i,
-	     cas2_i: do_cas2_i };
-}
+        load_i: do_load_i,
+        store: do_store,
+        store_i: do_store_i,
+        xchg: do_xchg,
+        xchg_i: do_xchg_i,
+        add: do_add,
+        add_i: do_add_i,
+        sub: do_sub,
+        sub_i: do_sub_i,
+        and: do_and,
+        and_i: do_and_i,
+        or: do_or,
+        or_i: do_or_i,
+        xor: do_xor,
+        xor_i: do_xor_i,
+        cas1: do_cas1,
+        cas2: do_cas2,
+        cas1_i: do_cas1_i,
+        cas2_i: do_cas2_i };
+`
 
-if (isAsmJSCompilationAvailable())
-    assertEq(isAsmJSModule(loadModule_int8), true);
+var loadModule_int8 = asmCompile('stdlib', 'foreign', 'heap', loadModule_int8_code);
 
 function test_int8(heap) {
     var i8a = new SharedInt8Array(heap);
     var i8m = loadModule_int8(this, {}, heap);
 
     for ( var i=0 ; i < i8a.length ; i++ )
 	i8a[i] = 0;
 
@@ -1419,205 +1409,203 @@ function test_int8(heap) {
 
     assertEq(i8m.or_i(oob), 0);
     assertEq(i8m.xor_i(oob), 0);
     assertEq(i8m.and_i(oob), 0);
     assertEq(i8m.add_i(oob), 0);
     assertEq(i8m.sub_i(oob), 0);
 }
 
-function loadModule_uint8(stdlib, foreign, heap) {
-    "use asm";
-
+var loadModule_uint8_code =
+    USE_ASM + `
     var atomic_load = stdlib.Atomics.load;
     var atomic_store = stdlib.Atomics.store;
     var atomic_cmpxchg = stdlib.Atomics.compareExchange;
     var atomic_exchange = stdlib.Atomics.exchange;
     var atomic_add = stdlib.Atomics.add;
     var atomic_sub = stdlib.Atomics.sub;
     var atomic_and = stdlib.Atomics.and;
     var atomic_or = stdlib.Atomics.or;
     var atomic_xor = stdlib.Atomics.xor;
 
     var i8a = new stdlib.SharedUint8Array(heap);
 
     // Load element 0
     function do_load() {
-	var v = 0;
-	v = atomic_load(i8a, 0)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_load(i8a, 0)|0;
+        return v|0;
     }
 
     // Load element i
     function do_load_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_load(i8a, i)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_load(i8a, i)|0;
+        return v|0;
     }
 
     // Store 37 in element 0
     function do_store() {
-	var v = 0;
-	v = atomic_store(i8a, 0, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_store(i8a, 0, 37)|0;
+        return v|0;
     }
 
     // Store 37 in element i
     function do_store_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_store(i8a, i, 37)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_store(i8a, i, 37)|0;
+        return v|0;
     }
 
     // Exchange 37 into element 200
     function do_xchg() {
-	var v = 0;
-	v = atomic_exchange(i8a, 200, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_exchange(i8a, 200, 37)|0;
+        return v|0;
     }
 
     // Exchange 42 into element i
     function do_xchg_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_exchange(i8a, i, 42)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_exchange(i8a, i, 42)|0;
+        return v|0;
     }
 
     // Add 37 to element 10
     function do_add() {
-	var v = 0;
-	v = atomic_add(i8a, 10, 37)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_add(i8a, 10, 37)|0;
+        return v|0;
     }
 
     // Add 37 to element i
     function do_add_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_add(i8a, i, 37)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_add(i8a, i, 37)|0;
+        return v|0;
     }
 
     // Subtract 108 from element 20
     function do_sub() {
-	var v = 0;
-	v = atomic_sub(i8a, 20, 108)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_sub(i8a, 20, 108)|0;
+        return v|0;
     }
 
     // Subtract 108 from element i
     function do_sub_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_sub(i8a, i, 108)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_sub(i8a, i, 108)|0;
+        return v|0;
     }
 
     // AND 0x33 into element 30
     function do_and() {
-	var v = 0;
-	v = atomic_and(i8a, 30, 0x33)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_and(i8a, 30, 0x33)|0;
+        return v|0;
     }
 
     // AND 0x33 into element i
     function do_and_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_and(i8a, i, 0x33)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_and(i8a, i, 0x33)|0;
+        return v|0;
     }
 
     // OR 0x33 into element 40
     function do_or() {
-	var v = 0;
-	v = atomic_or(i8a, 40, 0x33)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_or(i8a, 40, 0x33)|0;
+        return v|0;
     }
 
     // OR 0x33 into element i
     function do_or_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_or(i8a, i, 0x33)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_or(i8a, i, 0x33)|0;
+        return v|0;
     }
 
     // XOR 0x33 into element 50
     function do_xor() {
-	var v = 0;
-	v = atomic_xor(i8a, 50, 0x33)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_xor(i8a, 50, 0x33)|0;
+        return v|0;
     }
 
     // XOR 0x33 into element i
     function do_xor_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_xor(i8a, i, 0x33)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_xor(i8a, i, 0x33)|0;
+        return v|0;
     }
 
     // CAS element 100: 0 -> -1
     function do_cas1() {
-	var v = 0;
-	v = atomic_cmpxchg(i8a, 100, 0, -1)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_cmpxchg(i8a, 100, 0, -1)|0;
+        return v|0;
     }
 
     // CAS element 100: -1 -> 0x5A
     function do_cas2() {
-	var v = 0;
-	v = atomic_cmpxchg(i8a, 100, -1, 0x5A)|0;
-	return v|0;
+        var v = 0;
+        v = atomic_cmpxchg(i8a, 100, -1, 0x5A)|0;
+        return v|0;
     }
 
     // CAS element i: 0 -> -1
     function do_cas1_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i8a, i, 0, -1)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i8a, i, 0, -1)|0;
+        return v|0;
     }
 
     // CAS element i: -1 -> 0x5A
     function do_cas2_i(i) {
-	i = i|0;
-	var v = 0;
-	v = atomic_cmpxchg(i8a, i, -1, 0x5A)|0;
-	return v|0;
+        i = i|0;
+        var v = 0;
+        v = atomic_cmpxchg(i8a, i, -1, 0x5A)|0;
+        return v|0;
     }
 
     return { load: do_load,
-	     load_i: do_load_i,
-	     store: do_store,
-	     store_i: do_store_i,
-	     xchg: do_xchg,
-	     xchg_i: do_xchg_i,
-	     add: do_add,
-	     add_i: do_add_i,
-	     sub: do_sub,
-	     sub_i: do_sub_i,
-	     and: do_and,
-	     and_i: do_and_i,
-	     or: do_or,
-	     or_i: do_or_i,
-	     xor: do_xor,
-	     xor_i: do_xor_i,
-	     cas1: do_cas1,
-	     cas2: do_cas2,
-	     cas1_i: do_cas1_i,
-	     cas2_i: do_cas2_i };
-}
+        load_i: do_load_i,
+        store: do_store,
+        store_i: do_store_i,
+        xchg: do_xchg,
+        xchg_i: do_xchg_i,
+        add: do_add,
+        add_i: do_add_i,
+        sub: do_sub,
+        sub_i: do_sub_i,
+        and: do_and,
+        and_i: do_and_i,
+        or: do_or,
+        or_i: do_or_i,
+        xor: do_xor,
+        xor_i: do_xor_i,
+        cas1: do_cas1,
+        cas2: do_cas2,
+        cas1_i: do_cas1_i,
+        cas2_i: do_cas2_i };
+`
 
-if (isAsmJSCompilationAvailable())
-    assertEq(isAsmJSModule(loadModule_uint8), true);
+var loadModule_uint8 = asmCompile('stdlib', 'foreign', 'heap', loadModule_uint8_code);
 
 function test_uint8(heap) {
     var i8a = new SharedUint8Array(heap);
     var i8m = loadModule_uint8(this, {}, heap);
 
     for ( var i=0 ; i < i8a.length ; i++ )
 	i8a[i] = 0;
 
@@ -1697,70 +1685,68 @@ function test_uint8(heap) {
 
     assertEq(i8m.or_i(oob), 0);
     assertEq(i8m.xor_i(oob), 0);
     assertEq(i8m.and_i(oob), 0);
     assertEq(i8m.add_i(oob), 0);
     assertEq(i8m.sub_i(oob), 0);
 }
 
-function loadModule_misc(stdlib, foreign, heap) {
-    "use asm";
-
+var loadModule_misc_code =
+    USE_ASM + `
     var atomic_isLockFree = stdlib.Atomics.isLockFree;
 
     function ilf1() {
-	return atomic_isLockFree(1)|0;
+        return atomic_isLockFree(1)|0;
     }
 
     function ilf2() {
-	return atomic_isLockFree(2)|0;
+        return atomic_isLockFree(2)|0;
     }
 
     function ilf3() {
-	return atomic_isLockFree(3)|0;
+        return atomic_isLockFree(3)|0;
     }
 
     function ilf4() {
-	return atomic_isLockFree(4)|0;
+        return atomic_isLockFree(4)|0;
     }
 
     function ilf5() {
-	return atomic_isLockFree(5)|0;
+        return atomic_isLockFree(5)|0;
     }
 
     function ilf6() {
-	return atomic_isLockFree(6)|0;
+        return atomic_isLockFree(6)|0;
     }
 
     function ilf7() {
-	return atomic_isLockFree(7)|0;
+        return atomic_isLockFree(7)|0;
     }
 
     function ilf8() {
-	return atomic_isLockFree(8)|0;
+        return atomic_isLockFree(8)|0;
     }
 
     function ilf9() {
-	return atomic_isLockFree(9)|0;
+        return atomic_isLockFree(9)|0;
     }
 
     return { ilf1: ilf1,
-	     ilf2: ilf2,
-	     ilf3: ilf3,
-	     ilf4: ilf4,
-	     ilf5: ilf5,
-	     ilf6: ilf6,
-	     ilf7: ilf7,
-	     ilf8: ilf8,
-	     ilf9: ilf9 };
-}
+        ilf2: ilf2,
+        ilf3: ilf3,
+        ilf4: ilf4,
+        ilf5: ilf5,
+        ilf6: ilf6,
+        ilf7: ilf7,
+        ilf8: ilf8,
+        ilf9: ilf9 };
+`
 
-if (isAsmJSCompilationAvailable())
-    assertEq(isAsmJSModule(loadModule_misc), true);
+var loadModule_misc = asmCompile('stdlib', 'foreign', 'heap', loadModule_misc_code);
 
 function test_misc(heap) {
     var misc = loadModule_misc(this, {}, heap);
 
     assertEq(misc.ilf1(), 1);
     assertEq(misc.ilf2(), 1);
     assertEq(misc.ilf3(), 0);
     assertEq(misc.ilf4(), 1);
@@ -1778,8 +1764,25 @@ var heap = new SharedArrayBuffer(65536);
 
 test_int8(heap);
 test_uint8(heap);
 test_int16(heap);
 test_uint16(heap);
 test_int32(heap);
 test_uint32(heap);
 test_misc(heap);
+
+// Test that ARM callouts compile.
+setARMHwCapFlags('vfp');
+
+asmCompile('stdlib', 'ffi', 'heap',
+    USE_ASM + `
+    var atomic_exchange = stdlib.Atomics.exchange;
+    var i8a = new stdlib.SharedInt8Array(heap);
+
+    function do_xchg() {
+        var v = 0;
+        v = atomic_exchange(i8a, 200, 37) | 0;
+        return v|0;
+    }
+
+    return { xchg: do_xchg }
+`);
--- a/js/src/jit-test/tests/asm.js/testExpressions.js
+++ b/js/src/jit-test/tests/asm.js/testExpressions.js
@@ -257,16 +257,19 @@ assertEq(asmLink(asmCompile(USE_ASM + "f
 assertEq(asmLink(asmCompile(USE_ASM + "function f() { return (3 / 2)|0 } return f"))(), 1);
 assertEq(asmLink(asmCompile(USE_ASM + "function f() { return (4 % 2)|0 } return f"))(), 0);
 assertEq(asmLink(asmCompile(USE_ASM + "function f() { return (3 % 2)|0 } return f"))(), 1);
 
 assertAsmTypeFail(USE_ASM + "function f() { var i=42,j=1.1; return +(i?i:j) } return f");
 assertEq(asmLink(asmCompile(USE_ASM + "function f() { var i=42,j=1.1; return +(i?+(i|0):j) } return f"))(), 42);
 assertEq(asmLink(asmCompile(USE_ASM + "function f() { var i=42,j=1; return (i?i:j)|0 } return f"))(), 42);
 
+assertEq(asmLink(asmCompile(USE_ASM + "function f() { return (0 > (-(~~1) >>> 0)) | 0; } return f"))(), 0);
+assertEq(asmLink(asmCompile(USE_ASM + "function f() { return 0 < 4294967294 | 0; } return f"))(), 1);
+
 var f = asmLink(asmCompile(USE_ASM + "function f(i,j) { i=i|0;j=j|0; return ((i|0)>(j|0)?(i+10)|0:(j+100)|0)|0 } return f"));
 assertEq(f(2, 4), 104);
 assertEq(f(-2, -4), 8);
 
 var f = asmLink(asmCompile(USE_ASM + "function f(i,j,k) { i=i|0;j=j|0;k=k|0; return ((i|0)>(j|0) ? (i|0)>(k|0) ? i : k : (j|0)>(k|0) ? j : k)|0 } return f"));
 assertEq(f(1,2,3), 3);
 assertEq(f(1,3,2), 3);
 assertEq(f(2,1,3), 3);
--- a/js/src/jit/BytecodeAnalysis.cpp
+++ b/js/src/jit/BytecodeAnalysis.cpp
@@ -40,18 +40,20 @@ struct CatchFinallyRange
 };
 
 bool
 BytecodeAnalysis::init(TempAllocator& alloc, GSNCache& gsn)
 {
     if (!infos_.growByUninitialized(script_->length()))
         return false;
 
-    // We need a scope chain if any of the bindings are aliased.
-    usesScopeChain_ = script_->hasAnyAliasedBindings();
+    // We need a scope chain if the function is heavyweight.
+    usesScopeChain_ = (script_->functionDelazifying() &&
+                       script_->functionDelazifying()->isHeavyweight());
+    MOZ_ASSERT_IF(script_->hasAnyAliasedBindings(), usesScopeChain_);
 
     jsbytecode* end = script_->codeEnd();
 
     // Clear all BytecodeInfo.
     mozilla::PodZero(infos_.begin(), infos_.length());
     infos_[0].init(/*stackDepth=*/0);
 
     Vector<CatchFinallyRange, 0, JitAllocPolicy> catchFinallyRanges(alloc);
--- a/js/src/jit/CodeGenerator.cpp
+++ b/js/src/jit/CodeGenerator.cpp
@@ -1003,23 +1003,20 @@ static const VMFunction CloneRegExpObjec
 
 void
 CodeGenerator::visitRegExp(LRegExp* lir)
 {
     pushArg(ImmGCPtr(lir->mir()->source()));
     callVM(CloneRegExpObjectInfo, lir);
 }
 
-// The maximum number of pairs we can handle when executing RegExps inline.
-static const size_t RegExpMaxPairCount = 6;
-
 // Amount of space to reserve on the stack when executing RegExps inline.
 static const size_t RegExpReservedStack = sizeof(irregexp::InputOutputData)
                                         + sizeof(MatchPairs)
-                                        + RegExpMaxPairCount * sizeof(MatchPair);
+                                        + RegExpObject::MaxPairCount * sizeof(MatchPair);
 
 static size_t
 RegExpPairsVectorStartOffset(size_t inputOutputDataStartOffset)
 {
     return inputOutputDataStartOffset + sizeof(irregexp::InputOutputData) + sizeof(MatchPairs);
 }
 
 static Address
@@ -1088,17 +1085,17 @@ PrepareAndExecuteRegExp(JSContext* cx, M
 
     // Don't handle RegExps which read and write to lastIndex.
     masm.branchTest32(Assembler::NonZero, Address(temp1, RegExpShared::offsetOfFlags()),
                       Imm32(StickyFlag | GlobalFlag), failure);
 
     if (mode == RegExpShared::Normal) {
         // Don't handle RegExps with excessive parens.
         masm.load32(Address(temp1, RegExpShared::offsetOfParenCount()), temp2);
-        masm.branch32(Assembler::AboveOrEqual, temp2, Imm32(RegExpMaxPairCount), failure);
+        masm.branch32(Assembler::AboveOrEqual, temp2, Imm32(RegExpObject::MaxPairCount), failure);
 
         // Fill in the paren count in the MatchPairs on the stack.
         masm.add32(Imm32(1), temp2);
         masm.store32(temp2, pairCountAddress);
     }
 
     // Load the code pointer for the type of input string we have, and compute
     // the input start/end pointers in the InputOutputData.
@@ -1337,17 +1334,17 @@ JitCompartment::generateRegExpExecStub(J
     Register temp4 = regs.takeAny();
 
     ArrayObject* templateObject = cx->compartment()->regExps.getOrCreateMatchResultTemplateObject(cx);
     if (!templateObject)
         return nullptr;
 
     // The template object should have enough space for the maximum number of
     // pairs this stub can handle.
-    MOZ_ASSERT(ObjectElements::VALUES_PER_HEADER + RegExpMaxPairCount ==
+    MOZ_ASSERT(ObjectElements::VALUES_PER_HEADER + RegExpObject::MaxPairCount ==
                gc::GetGCKindSlots(templateObject->asTenured().getAllocKind()));
 
     MacroAssembler masm(cx);
 
     // The InputOutputData is placed above the return address on the stack.
     size_t inputOutputDataStartOffset = sizeof(void*);
 
     Label notFound, oolEntry;
--- a/js/src/jit/arm/Architecture-arm.cpp
+++ b/js/src/jit/arm/Architecture-arm.cpp
@@ -45,17 +45,17 @@ namespace jit {
 // Parse the Linux kernel cpuinfo features. This is also used to parse the
 // override features which has some extensions: 'armv7', 'align' and 'hardfp'.
 static uint32_t
 ParseARMCpuFeatures(const char* features, bool override = false)
 {
     uint32_t flags = 0;
 
     for (;;) {
-        char  ch = *features;
+        char ch = *features;
         if (!ch) {
             // End of string.
             break;
         }
         if (ch == ' ' || ch == ',') {
             // Skip separator characters.
             features++;
             continue;
--- a/js/src/vm/RegExpObject.cpp
+++ b/js/src/vm/RegExpObject.cpp
@@ -820,17 +820,18 @@ RegExpCompartment::~RegExpCompartment()
 }
 
 ArrayObject*
 RegExpCompartment::createMatchResultTemplateObject(JSContext* cx)
 {
     MOZ_ASSERT(!matchResultTemplateObject_);
 
     /* Create template array object */
-    RootedArrayObject templateObject(cx, NewDenseUnallocatedArray(cx, 0, nullptr, TenuredObject));
+    RootedArrayObject templateObject(cx, NewDenseUnallocatedArray(cx, RegExpObject::MaxPairCount,
+                                     nullptr, TenuredObject));
     if (!templateObject)
         return matchResultTemplateObject_; // = nullptr
 
     // Create a new group for the template.
     Rooted<TaggedProto> proto(cx, templateObject->getTaggedProto());
     ObjectGroup* group = ObjectGroupCompartment::makeGroup(cx, templateObject->getClass(), proto);
     if (!group)
         return matchResultTemplateObject_; // = nullptr
--- a/js/src/vm/RegExpObject.h
+++ b/js/src/vm/RegExpObject.h
@@ -355,16 +355,20 @@ class RegExpObject : public NativeObject
     static const unsigned STICKY_FLAG_SLOT         = 5;
 
   public:
     static const unsigned RESERVED_SLOTS = 6;
     static const unsigned PRIVATE_SLOT = 7;
 
     static const Class class_;
 
+    // The maximum number of pairs a MatchResult can have, without having to
+    // allocate a bigger MatchResult.
+    static const size_t MaxPairCount = 14;
+
     /*
      * Note: The regexp statics flags are OR'd into the provided flags,
      * so this function is really meant for object creation during code
      * execution, as opposed to during something like XDR.
      */
     static RegExpObject*
     create(ExclusiveContext* cx, RegExpStatics* res, const char16_t* chars, size_t length,
            RegExpFlag flags, frontend::TokenStream* ts, LifoAlloc& alloc);
--- a/netwerk/cache2/CacheFileMetadata.cpp
+++ b/netwerk/cache2/CacheFileMetadata.cpp
@@ -27,16 +27,19 @@ namespace net {
 
 // Most of the cache entries fit into one chunk due to current chunk size. Make
 // sure to tweak this value if kChunkSize is going to change.
 #define kInitialHashArraySize 1
 
 // Initial elements buffer size.
 #define kInitialBufSize 64
 
+// Max size of elements in bytes.
+#define kMaxElementsSize 64*1024
+
 #define kCacheEntryVersion 1
 
 #define NOW_SECONDS() (uint32_t(PR_Now() / PR_USEC_PER_SEC))
 
 NS_IMPL_ISUPPORTS(CacheFileMetadata, CacheFileIOListener)
 
 CacheFileMetadata::CacheFileMetadata(CacheFileHandle *aHandle, const nsACString &aKey)
   : CacheMemoryConsumer(NORMAL)
@@ -231,34 +234,46 @@ CacheFileMetadata::ReadMetadata(CacheFil
     InitEmptyMetadata();
     aListener->OnMetadataRead(NS_OK);
     return NS_OK;
   }
 
   return NS_OK;
 }
 
+uint32_t
+CacheFileMetadata::CalcMetadataSize(uint32_t aElementsSize, uint32_t aHashCount)
+{
+  return sizeof(uint32_t) +                         // hash of the metadata
+         aHashCount * sizeof(CacheHash::Hash16_t) + // array of chunk hashes
+         sizeof(CacheFileMetadataHeader) +          // metadata header
+         mKey.Length() + 1 +                        // key with trailing null
+         aElementsSize +                            // elements
+         sizeof(uint32_t);                          // offset
+}
+
 nsresult
 CacheFileMetadata::WriteMetadata(uint32_t aOffset,
                                  CacheFileMetadataListener *aListener)
 {
   LOG(("CacheFileMetadata::WriteMetadata() [this=%p, offset=%d, listener=%p]",
        this, aOffset, aListener));
 
   MOZ_ASSERT(!mListener);
   MOZ_ASSERT(!mWriteBuf);
 
   nsresult rv;
 
   mIsDirty = false;
 
-  mWriteBuf = static_cast<char *>(moz_xmalloc(sizeof(uint32_t) +
-                mHashCount * sizeof(CacheHash::Hash16_t) +
-                sizeof(CacheFileMetadataHeader) + mKey.Length() + 1 +
-                mElementsSize + sizeof(uint32_t)));
+  mWriteBuf = static_cast<char *>(malloc(CalcMetadataSize(mElementsSize,
+                                                          mHashCount)));
+  if (!mWriteBuf) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
   char *p = mWriteBuf + sizeof(uint32_t);
   memcpy(p, mHashArray, mHashCount * sizeof(CacheHash::Hash16_t));
   p += mHashCount * sizeof(CacheHash::Hash16_t);
   mMetaHdr.WriteToBuf(p);
   p += sizeof(CacheFileMetadataHeader);
   memcpy(p, mKey.get(), mKey.Length());
   p += mKey.Length();
@@ -401,16 +416,18 @@ CacheFileMetadata::GetElement(const char
 nsresult
 CacheFileMetadata::SetElement(const char *aKey, const char *aValue)
 {
   LOG(("CacheFileMetadata::SetElement() [this=%p, key=%s, value=%p]",
        this, aKey, aValue));
 
   MarkDirty();
 
+  nsresult rv;
+
   const uint32_t keySize = strlen(aKey) + 1;
   char *pos = const_cast<char *>(GetElement(aKey));
 
   if (!aValue) {
     // No value means remove the key/value pair completely, if existing
     if (pos) {
       uint32_t oldValueSize = strlen(pos) + 1;
       uint32_t offset = pos - mBuf;
@@ -426,25 +443,31 @@ CacheFileMetadata::SetElement(const char
   uint32_t newSize = mElementsSize + valueSize;
   if (pos) {
     const uint32_t oldValueSize = strlen(pos) + 1;
     const uint32_t offset = pos - mBuf;
     const uint32_t remainder = mElementsSize - (offset + oldValueSize);
 
     // Update the value in place
     newSize -= oldValueSize;
-    EnsureBuffer(newSize);
+    rv = EnsureBuffer(newSize);
+    if (NS_FAILED(rv)) {
+      return rv;
+    }
 
     // Move the remainder to the right place
     pos = mBuf + offset;
     memmove(pos + valueSize, pos + oldValueSize, remainder);
   } else {
     // allocate new meta data element
     newSize += keySize;
-    EnsureBuffer(newSize);
+    rv = EnsureBuffer(newSize);
+    if (NS_FAILED(rv)) {
+      return rv;
+    }
 
     // Add after last element
     pos = mBuf + mElementsSize;
     memcpy(pos, aKey, keySize);
     pos += keySize;
   }
 
   // Update value
@@ -660,26 +683,41 @@ CacheFileMetadata::OnDataRead(CacheFileH
   uint32_t realOffset = NetworkEndian::readUint32(mBuf + mBufSize -
                                                   sizeof(uint32_t));
 
   int64_t size = mHandle->FileSize();
   MOZ_ASSERT(size != -1);
 
   if (realOffset >= size) {
     LOG(("CacheFileMetadata::OnDataRead() - Invalid realOffset, creating "
-         "empty metadata. [this=%p, realOffset=%d, size=%lld]", this,
+         "empty metadata. [this=%p, realOffset=%u, size=%lld]", this,
          realOffset, size));
 
     InitEmptyMetadata();
 
     mListener.swap(listener);
     listener->OnMetadataRead(NS_OK);
     return NS_OK;
   }
 
+  uint32_t maxHashCount = size / kChunkSize;
+  uint32_t maxMetadataSize = CalcMetadataSize(kMaxElementsSize, maxHashCount);
+  if (size - realOffset > maxMetadataSize) {
+    LOG(("CacheFileMetadata::OnDataRead() - Invalid realOffset, metadata would "
+         "be too big, creating empty metadata. [this=%p, realOffset=%u, "
+         "maxMetadataSize=%u, size=%lld]", this, realOffset, maxMetadataSize,
+         size));
+
+    InitEmptyMetadata();
+
+    mListener.swap(listener);
+    listener->OnMetadataRead(NS_OK);
+    return NS_OK;
+  }
+
   uint32_t usedOffset = size - mBufSize;
 
   if (realOffset < usedOffset) {
     uint32_t missing = usedOffset - realOffset;
     // we need to read more data
     char *newBuf = static_cast<char *>(realloc(mBuf, mBufSize + missing));
     if (!newBuf) {
       LOG(("CacheFileMetadata::OnDataRead() - Error allocating %d more bytes "
@@ -927,19 +965,23 @@ CacheFileMetadata::CheckElements(const c
       LOG(("CacheFileMetadata::CheckElements() - Elements are malformed. "
            "[this=%p]", this));
       return NS_ERROR_FILE_CORRUPTED;
     }
   }
   return NS_OK;
 }
 
-void
+nsresult
 CacheFileMetadata::EnsureBuffer(uint32_t aSize)
 {
+  if (aSize > kMaxElementsSize) {
+    return NS_ERROR_FAILURE;
+  }
+
   if (mBufSize < aSize) {
     if (mAllocExactSize) {
       // If this is not the only allocation, use power of two for following
       // allocations.
       mAllocExactSize = false;
     } else {
       // find smallest power of 2 greater than or equal to aSize
       --aSize;
@@ -950,21 +992,27 @@ CacheFileMetadata::EnsureBuffer(uint32_t
       aSize |= aSize >> 16;
       ++aSize;
     }
 
     if (aSize < kInitialBufSize) {
       aSize = kInitialBufSize;
     }
 
+    char *newBuf = static_cast<char *>(realloc(mBuf, aSize));
+    if (!newBuf) {
+      return NS_ERROR_OUT_OF_MEMORY;
+    }
     mBufSize = aSize;
-    mBuf = static_cast<char *>(moz_xrealloc(mBuf, mBufSize));
+    mBuf = newBuf;
 
     DoMemoryReport(MemoryUsage());
   }
+
+  return NS_OK;
 }
 
 nsresult
 CacheFileMetadata::ParseKey(const nsACString &aKey)
 {
   nsCOMPtr<nsILoadContextInfo> info = CacheFileUtils::ParseKey(aKey);
   NS_ENSURE_TRUE(info, NS_ERROR_FAILURE);
 
--- a/netwerk/cache2/CacheFileMetadata.h
+++ b/netwerk/cache2/CacheFileMetadata.h
@@ -116,16 +116,17 @@ public:
                     const nsACString &aKey);
   CacheFileMetadata();
 
   void SetHandle(CacheFileHandle *aHandle);
 
   nsresult GetKey(nsACString &_retval);
 
   nsresult ReadMetadata(CacheFileMetadataListener *aListener);
+  uint32_t CalcMetadataSize(uint32_t aElementsSize, uint32_t aHashCount);
   nsresult WriteMetadata(uint32_t aOffset,
                          CacheFileMetadataListener *aListener);
   nsresult SyncReadMetadata(nsIFile *aFile);
 
   bool     IsAnonymous() { return mAnonymous; }
   bool     IsInBrowser() { return mInBrowser; }
   uint32_t AppId()       { return mAppId; }
 
@@ -166,17 +167,17 @@ public:
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
 
 private:
   virtual ~CacheFileMetadata();
 
   void     InitEmptyMetadata();
   nsresult ParseMetadata(uint32_t aMetaOffset, uint32_t aBufOffset, bool aHaveKey);
   nsresult CheckElements(const char *aBuf, uint32_t aSize);
-  void     EnsureBuffer(uint32_t aSize);
+  nsresult EnsureBuffer(uint32_t aSize);
   nsresult ParseKey(const nsACString &aKey);
 
   nsRefPtr<CacheFileHandle>           mHandle;
   nsCString                           mKey;
   CacheHash::Hash16_t                *mHashArray;
   uint32_t                            mHashArraySize;
   uint32_t                            mHashCount;
   int64_t                             mOffset;
--- a/netwerk/cache2/CacheFileOutputStream.cpp
+++ b/netwerk/cache2/CacheFileOutputStream.cpp
@@ -98,16 +98,28 @@ CacheFileOutputStream::Write(const char 
     LOG(("CacheFileOutputStream::Write() - Entry is too big, failing and "
          "dooming the entry. [this=%p]", this));
 
     mFile->DoomLocked(nullptr);
     CloseWithStatusLocked(NS_ERROR_FILE_TOO_BIG);
     return NS_ERROR_FILE_TOO_BIG;
   }
 
+  // We use 64-bit offset when accessing the file, unfortunatelly we use 32-bit
+  // metadata offset, so we cannot handle data bigger than 4GB.
+  if (mPos + aCount > PR_UINT32_MAX) {
+    LOG(("CacheFileOutputStream::Write() - Entry's size exceeds 4GB while it "
+         "isn't too big according to CacheObserver::EntryIsTooBig(). Failing "
+         "and dooming the entry. [this=%p]", this));
+
+    mFile->DoomLocked(nullptr);
+    CloseWithStatusLocked(NS_ERROR_FILE_TOO_BIG);
+    return NS_ERROR_FILE_TOO_BIG;
+  }
+
   *_retval = aCount;
 
   while (aCount) {
     EnsureCorrectChunk(false);
     if (NS_FAILED(mStatus)) {
       return mStatus;
     }
 
--- a/netwerk/cache2/CacheObserver.cpp
+++ b/netwerk/cache2/CacheObserver.cpp
@@ -60,21 +60,21 @@ static uint32_t const kDefaultDiskFreeSp
 uint32_t CacheObserver::sDiskFreeSpaceHardLimit = kDefaultDiskFreeSpaceHardLimit;
 
 static bool const kDefaultSmartCacheSizeEnabled = false;
 bool CacheObserver::sSmartCacheSizeEnabled = kDefaultSmartCacheSizeEnabled;
 
 static uint32_t const kDefaultPreloadChunkCount = 4;
 uint32_t CacheObserver::sPreloadChunkCount = kDefaultPreloadChunkCount;
 
-static uint32_t const kDefaultMaxMemoryEntrySize = 4 * 1024; // 4 MB
-uint32_t CacheObserver::sMaxMemoryEntrySize = kDefaultMaxMemoryEntrySize;
+static int32_t const kDefaultMaxMemoryEntrySize = 4 * 1024; // 4 MB
+int32_t CacheObserver::sMaxMemoryEntrySize = kDefaultMaxMemoryEntrySize;
 
-static uint32_t const kDefaultMaxDiskEntrySize = 50 * 1024; // 50 MB
-uint32_t CacheObserver::sMaxDiskEntrySize = kDefaultMaxDiskEntrySize;
+static int32_t const kDefaultMaxDiskEntrySize = 50 * 1024; // 50 MB
+int32_t CacheObserver::sMaxDiskEntrySize = kDefaultMaxDiskEntrySize;
 
 static uint32_t const kDefaultMaxDiskChunksMemoryUsage = 10 * 1024; // 10MB
 uint32_t CacheObserver::sMaxDiskChunksMemoryUsage = kDefaultMaxDiskChunksMemoryUsage;
 
 static uint32_t const kDefaultMaxDiskPriorityChunksMemoryUsage = 10 * 1024; // 10MB
 uint32_t CacheObserver::sMaxDiskPriorityChunksMemoryUsage = kDefaultMaxDiskPriorityChunksMemoryUsage;
 
 static uint32_t const kDefaultCompressionLevel = 1;
@@ -165,19 +165,19 @@ CacheObserver::AttachToPreferences()
   mozilla::Preferences::AddUintVarCache(
     &sDiskFreeSpaceSoftLimit, "browser.cache.disk.free_space_soft_limit", kDefaultDiskFreeSpaceSoftLimit);
   mozilla::Preferences::AddUintVarCache(
     &sDiskFreeSpaceHardLimit, "browser.cache.disk.free_space_hard_limit", kDefaultDiskFreeSpaceHardLimit);
 
   mozilla::Preferences::AddUintVarCache(
     &sPreloadChunkCount, "browser.cache.disk.preload_chunk_count", kDefaultPreloadChunkCount);
 
-  mozilla::Preferences::AddUintVarCache(
+  mozilla::Preferences::AddIntVarCache(
     &sMaxDiskEntrySize, "browser.cache.disk.max_entry_size", kDefaultMaxDiskEntrySize);
-  mozilla::Preferences::AddUintVarCache(
+  mozilla::Preferences::AddIntVarCache(
     &sMaxMemoryEntrySize, "browser.cache.memory.max_entry_size", kDefaultMaxMemoryEntrySize);
 
   mozilla::Preferences::AddUintVarCache(
     &sMaxDiskChunksMemoryUsage, "browser.cache.disk.max_chunks_memory_usage", kDefaultMaxDiskChunksMemoryUsage);
   mozilla::Preferences::AddUintVarCache(
     &sMaxDiskPriorityChunksMemoryUsage, "browser.cache.disk.max_priority_chunks_memory_usage", kDefaultMaxDiskPriorityChunksMemoryUsage);
 
   // http://mxr.mozilla.org/mozilla-central/source/netwerk/cache/nsCacheEntryDescriptor.cpp#367
@@ -467,19 +467,22 @@ CacheStorageEvictHelper::ClearStorage(bo
 }
 
 } // namespace
 
 // static
 bool const CacheObserver::EntryIsTooBig(int64_t aSize, bool aUsingDisk)
 {
   // If custom limit is set, check it.
-  int64_t preferredLimit = aUsingDisk
-    ? static_cast<int64_t>(sMaxDiskEntrySize) << 10
-    : static_cast<int64_t>(sMaxMemoryEntrySize) << 10;
+  int64_t preferredLimit = aUsingDisk ? sMaxDiskEntrySize : sMaxMemoryEntrySize;
+
+  // do not convert to bytes when the limit is -1, which means no limit
+  if (preferredLimit > 0) {
+    preferredLimit <<= 10;
+  }
 
   if (preferredLimit != -1 && aSize > preferredLimit)
     return true;
 
   // Otherwise (or when in the custom limit), check limit based on the global
   // limit.  It's 1/8 (>> 3) of the respective capacity.
   int64_t derivedLimit = aUsingDisk
     ? (static_cast<int64_t>(DiskCacheCapacity() >> 3))
--- a/netwerk/cache2/CacheObserver.h
+++ b/netwerk/cache2/CacheObserver.h
@@ -85,18 +85,18 @@ private:
   static uint32_t sMetadataMemoryLimit;
   static int32_t sMemoryCacheCapacity;
   static int32_t sAutoMemoryCacheCapacity;
   static uint32_t sDiskCacheCapacity;
   static uint32_t sDiskFreeSpaceSoftLimit;
   static uint32_t sDiskFreeSpaceHardLimit;
   static bool sSmartCacheSizeEnabled;
   static uint32_t sPreloadChunkCount;
-  static uint32_t sMaxMemoryEntrySize;
-  static uint32_t sMaxDiskEntrySize;
+  static int32_t sMaxMemoryEntrySize;
+  static int32_t sMaxDiskEntrySize;
   static uint32_t sMaxDiskChunksMemoryUsage;
   static uint32_t sMaxDiskPriorityChunksMemoryUsage;
   static uint32_t sCompressionLevel;
   static float sHalfLifeHours;
   static int32_t sHalfLifeExperiment;
   static bool sSanitizeOnShutdown;
   static bool sClearCacheOnShutdown;
   static bool sCacheFSReported;
--- a/security/manager/ssl/IntolerantFallbackList.inc
+++ b/security/manager/ssl/IntolerantFallbackList.inc
@@ -14,17 +14,16 @@ static const char* const kIntolerantFall
   "aa.com.do", // bug 1141604
   "aa.com.pe", // bug 1141604
   "aa.com.ve", // bug 1141604
   "aacoprod.aacounty.org",
   "aavacations.com", // bug 1141604
   "access.boekhuis.nl", // bug 1151580
   "account.61.com.tw",
   "acs.sia.eu", // RC4
-  "actiononline.stpete.org",
   "adman.you.gr",
   "adminweb.uthscsa.edu",
   "airportwifi.com", // bug 1116891
   "allbankonline.in", // bug 1156441
   "allyours.virginmedia.com", // bug 1129887
   "altitude.aircanada.com", // bug 1143325
   "american-airlines.co.kr", // bug 1141604
   "american-airlines.nl", // bug 1141604
@@ -42,20 +41,20 @@ static const char* const kIntolerantFall
   "americanairlines.hu", // bug 1141604
   "americanairlines.ie", // bug 1141604
   "americanairlines.in", // bug 1141604
   "americanairlines.jp", // bug 1141604
   "amss.mobilicity.ca",
   "ap.meitetsuunyu.co.jp",
   "apply.hkbn.net", // bug 1138451
   "apps.amerch.com",
-  "apps.fpcu.org",
   "apps.sasken.com",
   "apps.state.or.us", // bug 1130472
   "appsrv.restat.com",
+  "arcgames.com", // bug 1182932
   "ascii.jp",
   "asko.fi", // bug 1158584
   "b2b.feib.com.tw",
   "baybloorradio.com", // bug 1173661
   "beehive.miit.ru",
   "bettertrades.com",
   "bgw.wangyin.com", // bug 1145521
   "bianmin.chinapay.com", // bug 1137983
@@ -65,119 +64,106 @@ static const char* const kIntolerantFall
   "blogwatcher.co.jp",
   "bonds.euronext.com", // bug 1136091
   "books.wwnorton.com", // bug 1116891
   "bredbandsbolaget.se", // bug 1158755
   "bursar.ou.edu",
   "buttons.verticalresponse.com",
   "c2g.jupiter.fl.us",
   "canadaca.geotrust.com", // bug 1137677
+  "car2go.com", // bug 1185080
   "cbsfnotes1.blood.org.tw",
   "central.acadiau.ca", // bug 1152377
   "cherry.de", // bug 1141521
   "civilization.com", // bug 1156004
-  "click2gov.sanangelotexas.us",
   "clientes.chilectra.cl",
   "club.guosen.com.cn",
   "coagov.aurora-il.org",
   "codem.codemasters.com",
   "commerce.cashnet.com", // bug 1164009
   "comune.milano.it",
   "corporbank.nbcb.com.cn",
   "crm.et2008.com",
   "crossroads.schneider.com",
   "cs.tokai-tv.com",
   "cualerts.dupaco.com", // bug 1116892
   "customers.logistafrance.fr", // bug 1153951
   "cwu.edu",
   "dbank.hxb.com.cn",
   "dealer.autobytel.com",
-  "dealer.autoc-one.jp",
   "dheb.delavska-hranilnica.si",
   "digibet.com",
   "digitalsecurity.intel.com", // bug 1148744
   "dream-prize.com",
   "dwwsyw.bjgjj.gov.cn",
   "eatm.scsb.com.tw",
   "eb.bankcomm.com.hk", // bug 1141742
   "ebank-public.hzbank.com.cn",
   "ebank.hxb.com.cn",
   "ebank.hzbank.com.cn",
   "ebank.rcbcy.com", // bug 1146755
   "ebanking.ocbcwhhk.com", // bug 1141746
   "ebill2.virginmedia.com", // bug 1129887
   "ebpp.airtel.lk",
   "ebspay.boc.cn", // bug 1155567
   "ec-line.cn",
-  "ecams.geico.com", // bug 1138613
   "echo.com",
   "echotrak.com",
   "ecom.morethangourmet.com",
   "ecourses.uthscsa.edu",
-  "egov.leaguecity.com",
   "egov.town-menasha.com", // bug 1157536
   "emaildvla.direct.gov.uk", // bug 1116891
-  "embroiderydesignsplus.com",
   "epicreg.com",
   "eremit.sbising.com",
-  "escrowrefills.com",
   "eservices.palomar.edu",
   "essentialsupplies.com",
   "event.kasite.net",
   "extranet.eurocontrol.int",
   "ez.cityofchesapeake.net",
   "ezpay.com.tw",
   "fallback.test", // Used by gtest
   "fastcheck.sita.aero", // bug 1174974
   "fastlane.echo.com",
   "fhsaa.org",
   "fibi-online.co.il", // bug 1165580
   "finance.car.com",
   "friends.freshandeasy.com",
   "fubar.com",
   "gateway.halton.gov.uk",
   "gbe-bund.de",
-  "geico.com", // bug 1138613
   "gestionesytramites.madrid.org",
   "giftcertificates.com",
-  "hbk.bb.com.br", // bug 1135966
   "hercle.com",
   "hpshop.gr",
   "ibusiness.shacombank.com.hk", // bug 1141989
   "identity.virginmedia.com", // bug 1129887
   "ifund.allianzglobalinvestors.com.tw",
   "ig1.i-grasp.com", // bug 1167894
   "ig4.i-grasp.com", // bug 1167894
   "ihr.suburbanpropane.com",
   "images.bankofthewest.com", // bug 1127204
   "inside.i-med.ac.at",
   "its.bocmacau.com",
   "jbclick.jaxbchfl.net", // bug 1158465
   "jifenpay.com",
   "jst.doded.mil", // bug 1152627
-  "juror.fairfaxcounty.gov",
   "keirin.jp",
   "kjp.keinet.ne.jp",
   "kjp.oo.kawai-juku.ac.jp",
-  "learn.ou.edu",
-  "learn.swosu.edu",
   "lewisham.gov.uk",
   "lm-order.de",
   "login.chicagopolice.org",
   "login.ermis.gov.gr",
   "m.e-hon.ne.jp",
-  "macif.fr", // bug 1167893
+  "m.safari.cwu.edu", // bug 1143035
   "mail.izhnet.ru",
   "map.infonavit.org.mx",
-  "marketday.com", // bug 1092998
-  "matkahuolto.fi", // bug 1174957
   "mchrono.com",
   "mecsumai.com",
   "member.edenredticket.com",
-  "mercernet.fr", // bug 1147649
   "merchant.edenredticket.com",
   "meta-ehealth.com",
   "mobile.aa.com", // bug 1141604
   "mobile.dream-prize.com",
   "mon-ulb.ulb.ac.be",
   "my-csprd.ea.cwu.edu", // bug 1143035
   "my-csrenprd.ea.cwu.edu", // bug 1143035
   "my-fsprd.ea.cwu.edu", // bug 1143035
@@ -188,113 +174,97 @@ static const char* const kIntolerantFall
   "my.cwu.edu", // bug 1143035
   "my.if.com", // bug 1173592
   "my.kyivstar.ua",
   "my.miit.ru",
   "myaccount.allstate.com", // bug 1143031
   "myaccount3.westnet.com.au", // bug 1157139
   "mybank.nbcb.com.cn",
   "myhancock.hancockcollege.edu",
-  "myntc.ntc.edu",
   "myuws.uws.edu.au",
   "mywebreservations.com",
   "na.aiononline.com", // bug 1139782
   "national.virginmedia.com", // bug 1129887
   "nbank.hxb.com.cn",
   "netbanking.yesbank.co.in", // bug 1146090
   "niche.endsleigh.co.uk",
   "nmsmp.alsok.co.jp",
   "no1.nipponrentacar.co.jp",
   "obos1.obos.no",
   "officials.fhsaa.org",
   "online.newindia.co.in",
   "online.sainsburysbank.co.uk",
   "openwebosproject.org", // bug 1151990
-  "opi.emersonclimate.com",
   "opus.pinellascounty.org",
   "owa.byui.edu",
   "ozone.ou.edu",
   "parents.ou.edu",
   "partnerweb.vmware.com", // bug 1142187
-  "paslists.com", // for port 9211, bug 1155712
   "payment.condor.com", // bug 1152347
   "payment.safepass.cn",
   "payments.virginmedia.com", // bug 1129887
   "poezd.rw.by",
   "portal.eztec.com.br",
   "portal.questonline.gr",
   "portal.uem.es",
   "profiles.uthscsa.edu",
   "publicacionesoficiales.boe.es",
   "publicjobs.ie",
   "publicrecords.com",
   "racenet.codemasters.com", // bug 1163716
+  "rapidscansecure.com", // bug 1177212
   "recoup.com",
   "registration.o2.co.uk",
   "regonline.com", // bug 1139783
   "renewals.cipd.co.uk",
   "repair.kuroneko-kadendr.jp", // bug 1128366
   "repairmb.kuroneko-kadendr.jp", // bug 1128366
   "reputation.com",
   "research-report.uws.edu.au",
   "reservations.usairways.com", // bug 1165400
-  "rezstream.net",
   "rietumu.lv",
-  "rotr.com",
   "roxyaffiliates.com",
   "sales.newchinalife.com",
   "sbank.hxb.com.cn",
   "sboseweb.mcpsweb.org",
-  "school.keystoneschoolonline.com",
   "secure-checkout.t-mobile.com", // bug 1133648
   "secure.bg-mania.jp",
   "secure.crbonline.gov.uk", // bug 1166644
   "secure.fortisbc.com",
   "secure.ncsoft.com", // bug 1139782
   "secure.smartcart.com",
-  "secure2.i-doxs.net", // bug 1140876
-  "secure3.i-doxs.net", // bug 1140876
-  "secure4.i-doxs.net", // bug 1140876
-  "secure6.i-doxs.net", // bug 1140876
-  "secure7.i-doxs.net", // bug 1140876
-  "secure8.i-doxs.net", // bug 1140876
   "secureonline.dwp.gov.uk",
   "sems.hrd.ccsd.net",
-  "service.autoc-one.jp",
   "services.apvma.gov.au",
   "services.geotrust.com", // bug 1137677
   "servizionline.infogroup.it",
-  "shop.autoc-one.jp",
   "shop.kagome.co.jp",
   "shop.nanairo.coop", // bug 1128318
   "shop.wildstar-online.com", // bug 1139782
-  "sisweb.ucd.ie",
   "slovanet.sk",
   "smartcart.com",
-  "smarticon.geotrust.com", // bug 1137677
   "socialclub.rockstargames.com", // bug 1138673
   "soeasy.sodexo.be", // bug 1117157
   "ss2.sfcollege.edu",
   "ss5.sfcollege.edu",
   "ssb.okbu.edu", // for port 8910, bug 1153749
   "sso.acadiau.ca", // bug 1152377
   "starbucks.com", // bug 1167190
   "stenhouse.com",
   "store.moxa.com",
   "svrch13.sugarlandtx.gov",
+  "swdownloads.blackberry.com", // bug 1182997
   "syzygy.co.uk",
   "tarjetacencosud.cl",
   "tele2.hr",
   "tienda.boe.es",
   "tiendas.mediamarkt.es",
-  "trueblue.jetblue.com",
   "uralsg.megafon.ru", // bug 1153168
   "usacycling.org", // bug 1163791
   "userdoor.com",
-  "uslugi.beeline.am",
   "utradehub.or.kr",
   "vod.skyperfectv.co.jp",
   "watch.sportsnet.ca", // bug 1144769
   "web.asta.org",
   "webapps.ou.edu",
   "webatm.landbank.com.tw",
   "webmail.iyte.edu.tr",
   "websiti.cnbv.gob.mx",
@@ -335,16 +305,17 @@ static const char* const kIntolerantFall
   "www.americanairlines.ie", // bug 1141604
   "www.americanairlines.in", // bug 1141604
   "www.americanairlines.it", // bug 1141604
   "www.americanairlines.jp", // bug 1141604
   "www.amica.com", // bug 1139563
   "www.ancelutil.com.uy",
   "www.animate-onlineshop.jp", // bug 1126652
   "www.apeasternpower.com",
+  "www.arcgames.com", // bug 1182932
   "www.asko.fi", // bug 1158584
   "www.auroragov.org",
   "www.bancocredichile.cl",
   "www.bankcomm.com.hk", // bug 1141742
   "www.bankhapoalim.co.il", // bug 1138231
   "www.bauschonline.com",
   "www.baybloorradio.com", // bug 1173661
   "www.bbsfonline.com",
@@ -357,20 +328,20 @@ static const char* const kIntolerantFall
   "www.boostmobilesales.com", // bug 1112178
   "www.borsaitaliana.it",
   "www.bottegaverde.es",
   "www.bottegaverde.it",
   "www.bottegaverde.pt",
   "www.bredbandsbolaget.se", // bug 1158755
   "www.businessdirect.bt.com",
   "www.cafedumonde.jp",
+  "www.car2go.com", // bug 1185080
   "www.careers.asio.gov.au",
   "www.cherry.de", // bug 1141521
   "www.chinapay.com", // bug 1137983
-  "www.cihi.ca",
   "www.cipd.co.uk",
   "www.civilization.com", // bug 1156004
   "www.club-animate.jp",
   "www.codan.dk",
   "www.contraloria.cl",
   "www.credem.it",
   "www.crediscotia.com.mx",
   "www.creditagricole.info",
@@ -384,117 +355,97 @@ static const char* const kIntolerantFall
   "www.digibet.com",
   "www.drcsurveys.com",
   "www.dream-prize.com",
   "www.duskin.co.jp",
   "www.duskin.jp",
   "www.ec-line.cn",
   "www.echo.com",
   "www.echotrak.com",
-  "www.embroiderydesignsplus.com",
   "www.epicreg.com",
   "www.ermis.gov.gr",
   "www.esadealumni.net",
   "www.esavingsaccount.co.uk",
   "www.escrowrefills.com",
   "www.essentialsupplies.com",
-  "www.euronext.com", // bug 1136091
   "www.everyd.com",
   "www.ezpay.com.tw",
   "www.fhsaa.org",
   "www.fibi-online.co.il", // bug 1165580
   "www.fj96336.com",
   "www.fontainebleau.com",
   "www.foundersc.com",
   "www.fubar.com",
-  "www.fundsupermart.co.in",
   "www.gamers-onlineshop.jp", // bug 1126654
   "www.gbe-bund.de",
   "www.giftcertificates.com",
-  "www.golfersland.net",
   "www.gtja.com",
-  "www.hankyu-club.com",
   "www.haynes.co.uk",
   "www.hercle.com",
   "www.hn.10086.cn",
-  "www.hotel-story.ne.jp",
   "www.hpshop.gr",
   "www.hsbank.cc",
   "www.hx168.com.cn",
   "www.ingramentertainment.com",
   "www.interpark.com",
   "www.isracard.co.il", // bug 1165582
   "www.jaf.or.jp",
   "www.jifenpay.com",
   "www.kasite.net",
   "www.khan.co.kr",
-  "www.komatsu-kenki.co.jp",
-  "www.komatsu.co.jp",
-  "www.komatsu.com",
   "www.kredodirect.com.ua", // bug 1095507
   "www.law888.com.tw",
   "www.lewisham.gov.uk",
   "www.lib.cwu.edu",
   "www.libraryvideo.com",
   "www.lm-order.de",
   "www.londonstockexchange.com",
-  "www.macif.fr", // bug 1167893
-  "www.marketday.com", // bug 1092998
-  "www.matkahuolto.fi", // bug 1174957
   "www.matkahuolto.info",
   "www.matrics.or.jp",
   "www.mchrono.com",
   "www.mecsumai.com",
-  "www.mercatoneuno.com",
-  "www.mercernet.fr", // bug 1147649
   "www.meta-ehealth.com",
   "www.misterdonut.jp",
-  "www.mizuno.jp",
-  "www.monclick.it",
   "www.mp2.aeroport.fr",
   "www.mpay.co.th",
   "www.mtsindia.in", // RC4
   "www.my.airdo.jp", // bug 1129773
   "www.myagent.gov.ab.ca", // bug 1152827
   "www.mynpcdata.net",
   "www.mywebreservations.com",
   "www.ncsoft.com", // bug 1139782
   "www.nec-nexs.com",
   "www.newchinalife.com",
   "www.nishi.or.jp",
   "www.ocbcwhhk.com", // bug 1141746
   "www.openwebosproject.org", // bug 1151990
-  "www.paslists.com", // for port 9211, bug 1155712
   "www.pen-kanagawa.ed.jp",
   "www.polla.cl",
   "www.publicjobs.ie",
   "www.publicrecords.com",
   "www.pwcrecruiting.com",
+  "www.rapidscansecure.com", // bug 1177212
   "www.razorgator.com",
   "www.recoup.com",
   "www.regonline.com", // bug 1139783
   "www.renaultcredit.com.ar",
   "www.reputation.com",
-  "www.rezstream.net",
   "www.rietumu.lv",
   "www.rimac.com.pe",
   "www.riversendtrading.com",
-  "www.rotr.com",
   "www.roxyaffiliates.com",
   "www.s-book.net",
   "www.safepass.cn",
   "www.session.ne.jp",
-  "www.shacombank.com.hk", // bug 1141989
   "www.shacomsecurities.com.hk", // bug 1141989
   "www.shop.bt.com",
   "www.slovanet.sk",
   "www.smartcart.com",
   "www.smartoffice.jp",
   "www.sokamocka.com",
-  "www.sports-nakama.com",
   "www.starbucks.com", // bug 1167190
   "www.stenhouse.com",
   "www.sunderland.gov.uk",
   "www.syzygy.co.uk",
   "www.tarjetacencosud.cl",
   "www.tealife.co.jp",
   "www.tele2.hr",
   "www.tetsudo.com",
@@ -510,22 +461,18 @@ static const char* const kIntolerantFall
   "www.wavecable.com",
   "www.wingarc.com",
   "www.yakult.co.kr",
   "www.zenfolio.com",
   "www.zoominfo.com",
   "www1.aeroplan.com", // bug 1137543
   "www1.isracard.co.il", // bug 1165582
   "www2.aeroplan.com", // bug 1137543
-  "www2.bancobrasil.com.br", // bug 1135966
   "www2.wou.edu",
-  "www28.bb.com.br", // bug 1135966
   "www3.aeroplan.com", // bug 1137543
   "www3.ibac.co.jp",
   "www3.taiheiyo-ferry.co.jp",
   "www4.aeroplan.com", // bug 1137543
-  "www41.bb.com.br", // bug 1135966
-  "www73.bb.com.br", // bug 1135966
   "wwws.kadokawa.co.jp",
   "xyk.cebbank.com", // bug 1145524
   "zenfolio.com",
   "zoominfo.com",
 };
--- a/security/manager/ssl/nsNSSIOLayer.cpp
+++ b/security/manager/ssl/nsNSSIOLayer.cpp
@@ -1732,17 +1732,16 @@ struct FallbackListComparator
 
 private:
   const char* mTarget;
 };
 
 static const char* const kFallbackWildcardList[] =
 {
   ".kuronekoyamato.co.jp", // bug 1128366
-  ".userstorage.mega.co.nz", // bug 1133496
   ".wildcard.test",
 };
 
 bool
 nsSSLIOLayerHelpers::isInsecureFallbackSite(const nsACString& hostname)
 {
   size_t match;
   if (mUseStaticFallbackList) {
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -2989,18 +2989,26 @@ private:
 
 NS_IMPL_ISUPPORTS0(FullscreenTransitionData)
 
 /* virtual */ bool
 nsWindow::PrepareForFullscreenTransition(nsISupports** aData)
 {
   FullscreenTransitionInitData initData;
   nsCOMPtr<nsIScreen> screen = GetWidgetScreen();
-  screen->GetRectDisplayPix(&initData.mBounds.x, &initData.mBounds.y,
-                            &initData.mBounds.width, &initData.mBounds.height);
+  int32_t x, y, width, height;
+  screen->GetRectDisplayPix(&x, &y, &width, &height);
+  MOZ_ASSERT(BoundsUseDisplayPixels(),
+             "Should only be called on top-level window");
+  CSSToLayoutDeviceScale scale = GetDefaultScale();
+  initData.mBounds.x = NSToIntRound(x * scale.scale);
+  initData.mBounds.y = NSToIntRound(y * scale.scale);
+  initData.mBounds.width = NSToIntRound(width * scale.scale);
+  initData.mBounds.height = NSToIntRound(height * scale.scale);
+
   // Create a semaphore for synchronizing the window handle which will
   // be created by the transition thread and used by the main thread for
   // posting the transition messages.
   initData.mSemaphore = ::CreateSemaphore(nullptr, 0, 1, nullptr);
   if (initData.mSemaphore) {
     initData.mThread = ::CreateThread(
       nullptr, 0, FullscreenTransitionThreadProc, &initData, 0, nullptr);
     if (initData.mThread) {