trunk sync scalable_gc_free_lists_378918
authorIgor Bukanov <igor@mir2.org>
Tue, 24 Jun 2008 09:52:20 +0200
branchscalable_gc_free_lists_378918
changeset 15490 0f084c7ce4df395c47e79fcd79cef094ecb8de15
parent 15489 faa43f41e777b01e3195d1e2df0d0670e39e06ca (current diff)
parent 15485 9756a45384e63429723dafb1604452995a4d33b1 (diff)
child 15491 a1309018611f0a52aba37f74e2da0ed851597cd7
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.1a1pre
trunk sync
content/xul/document/src/nsElementMap.cpp
content/xul/document/src/nsElementMap.h
js/src/fdlibm/Makefile.in
js/src/fdlibm/Makefile.ref
js/src/fdlibm/e_acos.c
js/src/fdlibm/e_acosh.c
js/src/fdlibm/e_asin.c
js/src/fdlibm/e_atan2.c
js/src/fdlibm/e_atanh.c
js/src/fdlibm/e_cosh.c
js/src/fdlibm/e_exp.c
js/src/fdlibm/e_fmod.c
js/src/fdlibm/e_gamma.c
js/src/fdlibm/e_gamma_r.c
js/src/fdlibm/e_hypot.c
js/src/fdlibm/e_j0.c
js/src/fdlibm/e_j1.c
js/src/fdlibm/e_jn.c
js/src/fdlibm/e_lgamma.c
js/src/fdlibm/e_lgamma_r.c
js/src/fdlibm/e_log.c
js/src/fdlibm/e_log10.c
js/src/fdlibm/e_pow.c
js/src/fdlibm/e_rem_pio2.c
js/src/fdlibm/e_remainder.c
js/src/fdlibm/e_scalb.c
js/src/fdlibm/e_sinh.c
js/src/fdlibm/e_sqrt.c
js/src/fdlibm/fdlibm.h
js/src/fdlibm/fdlibm.mak
js/src/fdlibm/fdlibm.mdp
js/src/fdlibm/k_cos.c
js/src/fdlibm/k_rem_pio2.c
js/src/fdlibm/k_sin.c
js/src/fdlibm/k_standard.c
js/src/fdlibm/k_tan.c
js/src/fdlibm/s_asinh.c
js/src/fdlibm/s_atan.c
js/src/fdlibm/s_cbrt.c
js/src/fdlibm/s_ceil.c
js/src/fdlibm/s_copysign.c
js/src/fdlibm/s_cos.c
js/src/fdlibm/s_erf.c
js/src/fdlibm/s_expm1.c
js/src/fdlibm/s_fabs.c
js/src/fdlibm/s_finite.c
js/src/fdlibm/s_floor.c
js/src/fdlibm/s_frexp.c
js/src/fdlibm/s_ilogb.c
js/src/fdlibm/s_isnan.c
js/src/fdlibm/s_ldexp.c
js/src/fdlibm/s_lib_version.c
js/src/fdlibm/s_log1p.c
js/src/fdlibm/s_logb.c
js/src/fdlibm/s_matherr.c
js/src/fdlibm/s_modf.c
js/src/fdlibm/s_nextafter.c
js/src/fdlibm/s_rint.c
js/src/fdlibm/s_scalbn.c
js/src/fdlibm/s_signgam.c
js/src/fdlibm/s_significand.c
js/src/fdlibm/s_sin.c
js/src/fdlibm/s_tan.c
js/src/fdlibm/s_tanh.c
js/src/fdlibm/w_acos.c
js/src/fdlibm/w_acosh.c
js/src/fdlibm/w_asin.c
js/src/fdlibm/w_atan2.c
js/src/fdlibm/w_atanh.c
js/src/fdlibm/w_cosh.c
js/src/fdlibm/w_exp.c
js/src/fdlibm/w_fmod.c
js/src/fdlibm/w_gamma.c
js/src/fdlibm/w_gamma_r.c
js/src/fdlibm/w_hypot.c
js/src/fdlibm/w_j0.c
js/src/fdlibm/w_j1.c
js/src/fdlibm/w_jn.c
js/src/fdlibm/w_lgamma.c
js/src/fdlibm/w_lgamma_r.c
js/src/fdlibm/w_log.c
js/src/fdlibm/w_log10.c
js/src/fdlibm/w_pow.c
js/src/fdlibm/w_remainder.c
js/src/fdlibm/w_scalb.c
js/src/fdlibm/w_sinh.c
js/src/fdlibm/w_sqrt.c
js/src/jsgc.cpp
memory/jemalloc/tree.h
--- a/accessible/src/html/nsHTMLLinkAccessible.cpp
+++ b/accessible/src/html/nsHTMLLinkAccessible.cpp
@@ -61,17 +61,26 @@ NS_IMETHODIMP
 nsHTMLLinkAccessible::GetName(nsAString& aName)
 { 
   aName.Truncate();
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-  return AppendFlatStringFromSubtree(content, &aName);
+  nsresult rv = AppendFlatStringFromSubtree(content, &aName);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (aName.IsEmpty()) {
+    // Probably an image without alt or title inside, try to get the name on
+    // the link by usual way.
+    return GetHTMLName(aName, PR_FALSE);
+  }
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLLinkAccessible::GetRole(PRUint32 *aRole)
 {
   NS_ENSURE_ARG_POINTER(aRole);
 
   *aRole = nsIAccessibleRole::ROLE_LINK;
@@ -97,19 +106,24 @@ nsHTMLLinkAccessible::GetState(PRUint32 
     *aState |= nsIAccessibleStates::STATE_SELECTABLE;
   }
 
   nsCOMPtr<nsILink> link = do_QueryInterface(mDOMNode);
   NS_ENSURE_STATE(link);
 
   nsLinkState linkState;
   link->GetLinkState(linkState);
-  if (linkState == eLinkState_NotLink) {
-    // This is a named anchor, not a link with also a name attribute. bail out.
-    return NS_OK;
+  if (linkState == eLinkState_NotLink || linkState == eLinkState_Unknown) {
+    // This is a either named anchor (a link with also a name attribute) or
+    // it doesn't have any attributes. Check if 'click' event handler is
+    // registered, otherwise bail out.
+    PRBool isOnclick = nsAccUtils::HasListener(content,
+                                               NS_LITERAL_STRING("click"));
+    if (!isOnclick)
+      return NS_OK;
   }
 
   *aState |= nsIAccessibleStates::STATE_LINKED;
 
   if (linkState == eLinkState_Visited)
     *aState |= nsIAccessibleStates::STATE_TRAVERSED;
 
   return NS_OK;
@@ -133,35 +147,45 @@ nsHTMLLinkAccessible::GetValue(nsAString
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLLinkAccessible::GetNumActions(PRUint8 *aNumActions)
 {
   NS_ENSURE_ARG_POINTER(aNumActions);
 
+  if (!IsLinked())
+    return nsHyperTextAccessible::GetNumActions(aNumActions);
+
   *aNumActions = 1;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLLinkAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
 {
+  aName.Truncate();
+
+  if (!IsLinked())
+    return nsHyperTextAccessible::GetActionName(aIndex, aName);
+
   // Action 0 (default action): Jump to link
-  aName.Truncate();
   if (aIndex != eAction_Jump)
     return NS_ERROR_INVALID_ARG;
 
   aName.AssignLiteral("jump");
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLLinkAccessible::DoAction(PRUint8 aIndex)
 {
+  if (!IsLinked())
+    return nsHyperTextAccessible::DoAction(aIndex);
+
   // Action 0 (default action): Jump to link
   if (aIndex != eAction_Jump)
     return NS_ERROR_INVALID_ARG;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
@@ -180,8 +204,25 @@ nsHTMLLinkAccessible::GetURI(PRInt32 aIn
   if (aIndex != 0)
     return NS_ERROR_INVALID_ARG;
 
   nsCOMPtr<nsILink> link(do_QueryInterface(mDOMNode));
   NS_ENSURE_STATE(link);
 
   return link->GetHrefURI(aURI);
 }
+
+////////////////////////////////////////////////////////////////////////////////
+// Protected members
+
+PRBool
+nsHTMLLinkAccessible::IsLinked()
+{
+  nsCOMPtr<nsILink> link(do_QueryInterface(mDOMNode));
+  if (!link)
+    return PR_FALSE;
+
+  nsLinkState linkState;
+  nsresult rv = link->GetLinkState(linkState);
+
+  return NS_SUCCEEDED(rv) && linkState != eLinkState_NotLink &&
+         linkState != eLinkState_Unknown;
+}
--- a/accessible/src/html/nsHTMLLinkAccessible.h
+++ b/accessible/src/html/nsHTMLLinkAccessible.h
@@ -59,11 +59,16 @@ public:
   NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
   NS_IMETHOD DoAction(PRUint8 aIndex);
 
   // nsIAccessibleHyperLink
   NS_IMETHOD GetURI(PRInt32 aIndex, nsIURI **aURI);
 
 protected:
   enum { eAction_Jump = 0 };
+
+  /**
+   * Returns true if the link has href attribute.
+   */
+  PRBool IsLinked();
 };
 
 #endif  
--- a/accessible/tests/mochitest/test_nsIAccessibleHyperLink.html
+++ b/accessible/tests/mochitest/test_nsIAccessibleHyperLink.html
@@ -6,16 +6,18 @@ https://bugzilla.mozilla.org/show_bug.cg
 <head>
   <title>nsIHyperLinkAccessible chrome tests</title>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
 
   <script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
 
   <script type="application/javascript">
+    var gAccRetrieval = null;
+
     function testThis(aID, aAcc, aRole, aAnchors, aName, aValid, aStartIndex,
                       aEndIndex)
     {
       is(aAcc.finalRole, aRole, "Wrong role for ID " + aID + "!");
       is(aAcc.anchorCount, aAnchors, "Wrong number of anchors for ID "
                                       + aID + "!");
       is(aAcc.getAnchor(0).name, aName, "Wrong name for ID "
                                         + aID + "!");
@@ -31,28 +33,56 @@ https://bugzilla.mozilla.org/show_bug.cg
     {
       is(aAcc.selected, aSelectedBefore,
          "Wrong selected state before focus for ID " + aID + "!");
       document.getElementById(aID).focus();
       is(aAcc.selected, aSelectedAfter,
          "Wrong seleccted state after focus for ID " + aID + "!");
     }
 
-    function testStates(aID, aAcc, aState, aExtraState, aAbsentState)
+    function testStates(aID, aAcc, aState, aExtraState, aAbsentState,
+                        aShowStateDebugFlag)
     {
       var state = {}, extraState = {};
       aAcc.getFinalState(state, extraState);
+
+      if (aShowStateDebugFlag) {
+        var list = gAccRetrieval.getStringStates(state.value, 0);
+
+        var str = "";
+        for (var i = 0; i < list.length; i++)
+          str += list.item(i) + "\n";
+
+        alert(str);
+      }
+
       is(state.value & aState, aState, "Wrong state bits for ID " + aID + "!");
       is(extraState.value & aExtraState, aExtraState, 
          "Wrong extra state bits for ID " + aID + "!");
       if (aAbsentState != 0)
         is(state.value & aAbsentState, 0, "state bits should not be present in ID "
            + aID + "!");
     }
-      
+
+    function testAction(aId, aAcc, aActionName)
+    {
+      var numActions = aActionName ? 1 : 0;
+      is(aAcc.numActions, numActions,
+         "Wrong actions number for ID " + aId);
+      try {
+        is(aAcc.getActionName(0), aActionName,
+           "Wrong action name for ID " + aId);
+      } catch (e) {
+        if (numActions)
+          ok(false, "Exception on action name getting for ID " + aId);
+        else
+          ok(true, "Correct action name for ID " + aId);
+      }
+    }
+
     function doTest()
     {
       // Mapping needed state flags for easier handling.
       const state_focusable = 
             Components.interfaces.nsIAccessibleStates.STATE_FOCUSABLE;
       const state_focused = 
             Components.interfaces.nsIAccessibleStates.STATE_FOCUSED;
       const state_selectable = 
@@ -66,25 +96,25 @@ https://bugzilla.mozilla.org/show_bug.cg
             Components.interfaces.nsIAccessibleStates.EXT_STATE_MULTI_LINE;
       const ext_state_horizontal = 
             Components.interfaces.nsIAccessibleStates.EXT_STATE_HORIZONTAL;
       const ext_state_required = 
             Components.interfaces.nsIAccessibleStates.STATE_REQUIRED;
       const ext_state_invalid = 
             Components.interfaces.nsIAccessibleStates.STATE_INVALID;
 
-      var accService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
-                       getService(Components.interfaces.nsIAccessibleRetrieval);
+      gAccRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
+                      getService(Components.interfaces.nsIAccessibleRetrieval);
 
       //////////////////////////////////////////////////////////////////////////
       // normal hyperlink
       var normalHyperlinkElement = document.getElementById("NormalHyperlink");
       var normalHyperlinkAcc;
       try {
-        normalHyperlinkAcc = accService.getAccessibleFor(normalHyperlinkElement).
+        normalHyperlinkAcc = gAccRetrieval.getAccessibleFor(normalHyperlinkElement).
               QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
       } catch(e) {
         ok(normalHyperlinkAcc, "no interface for normal hyperlink!");
       }
       testThis("NormalHyperlink", normalHyperlinkAcc,
                Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
                "Mozilla Foundation", true, 18, 19);
       is(normalHyperlinkAcc.getURI(0).spec, "http://www.mozilla.org/", 
@@ -97,40 +127,41 @@ https://bugzilla.mozilla.org/show_bug.cg
                  (state_focusable | state_focused | state_linked),
                  (ext_state_horizontal), (0));
 
       //////////////////////////////////////////////////////////////////////////
       // ARIA hyperlink
       var ariaHyperlinkElement = document.getElementById("AriaHyperlink");
       var ariaHyperlinkAcc;
       try {
-        ariaHyperlinkAcc = accService.getAccessibleFor(ariaHyperlinkElement).
+        ariaHyperlinkAcc = gAccRetrieval.getAccessibleFor(ariaHyperlinkElement).
             QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
       } catch(e) {
         ok(ariaHyperlinkAcc, "no interface for ARIA Hyperlink!");
       }
       testThis("AriaHyperlink", ariaHyperlinkAcc,
                Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
                "Mozilla Foundation Home", true, 32, 33);
       testStates("AriaHyperlink", ariaHyperlinkAcc,
                  (state_focusable | state_linked),
                  (ext_state_horizontal), (0));
       testFocus("AriaHyperlink", ariaHyperlinkAcc, false, true);
       testStates("AriaHyperlink", ariaHyperlinkAcc,
                  (state_focusable | state_focused | state_linked),
                  (ext_state_horizontal), (0));
+      testAction("AriaHyperlink", ariaHyperlinkAcc, "click");
 
       //////////////////////////////////////////////////////////////////////////
       // ARIA hyperlink with status invalid
       var invalidAriaHyperlinkElement =
           document.getElementById("InvalidAriaHyperlink");
       var invalidAriaHyperlinkAcc;
       try {
         invalidAriaHyperlinkAcc =
-               accService.getAccessibleFor(invalidAriaHyperlinkElement).
+               gAccRetrieval.getAccessibleFor(invalidAriaHyperlinkElement).
                QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
       } catch(e) {
         ok(invalidAriaHyperlinkAcc, "no interface for invalid ARIA hyperlink!");
       }
       is(invalidAriaHyperlinkAcc.valid, false, "Should not be valid!");
       testStates("InvalidAriaHyperlink", invalidAriaHyperlinkAcc,
                  (state_linked),
                  (ext_state_horizontal), (state_focusable));
@@ -139,17 +170,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 
       //////////////////////////////////////////////////////////////////////////
       // image map and its link children
       var imageMapHyperlinkElement =
           document.getElementById("imgmap");
       var imageMapHyperlinkAcc;
       try {
         imageMapHyperlinkAcc =
-             accService.getAccessibleFor(imageMapHyperlinkElement).
+             gAccRetrieval.getAccessibleFor(imageMapHyperlinkElement).
               QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
       } catch(e) {
         ok(imageMapHyperlinkAcc, "no Image Map interface!");
       }
       testThis("imgmap", imageMapHyperlinkAcc,
                Components.interfaces.nsIAccessibleRole.ROLE_IMAGE_MAP, 2, 
                "b", true, 83, 84);
       is(imageMapHyperlinkAcc.getURI(0).spec,
@@ -197,92 +228,212 @@ https://bugzilla.mozilla.org/show_bug.cg
                  (0), (0));
 
       //////////////////////////////////////////////////////////////////////////
       // empty hyperlink
       var emptyLinkElement = document.getElementById("emptyLink");
       var EmptyHLAcc;
       try {
         EmptyHLAcc =
-             accService.getAccessibleFor(emptyLinkElement).
+             gAccRetrieval.getAccessibleFor(emptyLinkElement).
              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
       } catch (e) {
         ok(EmptyHLAcc, "no interface for empty link!");
       }
       testThis("emptyLink", EmptyHLAcc,
                Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
-               "", true, 98, 99);
+               null, true, 98, 99);
       testStates("emptyLink", EmptyHLAcc,
                  (state_focusable | state_linked),
                  (ext_state_horizontal), (0));
+      testAction("emptyLink", EmptyHLAcc, "jump");
 
       //////////////////////////////////////////////////////////////////////////
       // normal hyperlink with embedded span
       var hyperlinkElementWithSpan = document.getElementById("LinkWithSpan");
       var hyperlinkWithSpanAcc;
       try {
         hyperlinkWithSpanAcc =
-              accService.getAccessibleFor(hyperlinkElementWithSpan).
+              gAccRetrieval.getAccessibleFor(hyperlinkElementWithSpan).
               QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
       } catch(e) {
         ok(hyperlinkWithSpanAcc, "no interface for hyperlink with span!");
       }
       testThis("LinkWithSpan", hyperlinkWithSpanAcc,
                Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
                "Heise Online", true, 124, 125);
       is(hyperlinkWithSpanAcc.getURI(0).spec, "http://www.heise.de/", 
          "URI wrong for hyperlinkElementWithSpan!");
       testStates("LinkWithSpan", hyperlinkWithSpanAcc,
                  (state_focusable | state_linked),
                  (ext_state_horizontal), (0));
       testFocus("LinkWithSpan", hyperlinkWithSpanAcc, false, true);
       testStates("LinkWithSpan", hyperlinkWithSpanAcc,
                  (state_focusable | state_focused | state_linked),
                  (ext_state_horizontal), (0));
+      testAction("LinkWithSpan", hyperlinkWithSpanAcc, "jump");
 
       //////////////////////////////////////////////////////////////////////////
       // Named anchor, should never have state_linked
       var namedAnchorElement = document.getElementById("namedAnchor");
       var namedAnchorAcc;
       try {
-        namedAnchorAcc = accService.getAccessibleFor(namedAnchorElement).
+        namedAnchorAcc = gAccRetrieval.getAccessibleFor(namedAnchorElement).
               QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
       } catch(e) {
         ok(namedAnchorAcc, "no interface for named anchor!");
       }
       testThis("namedAnchor", namedAnchorAcc,
                Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
                "This should never be of state_linked", true, 202, 203);
       testStates("namedAnchor", namedAnchorAcc,
                  (state_selectable),
                  (ext_state_horizontal), (state_focusable | state_linked));
+      testAction("namedAnchor", namedAnchorAcc, "");
+
+      //////////////////////////////////////////////////////////////////////////
+      // No link (hasn't any attribute), should never have state_linked
+      var noLinkElement = document.getElementById("noLink");
+      var noLinkAcc;
+      try {
+        noLinkAcc = gAccRetrieval.getAccessibleFor(noLinkElement).
+              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(noLinkAcc, "no interface for named anchor!");
+      }
+      testThis("noLink", noLinkAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
+               "This should never be of state_linked", true, 262, 263);
+      testStates("noLink", noLinkAcc,
+                 0,
+                 (ext_state_horizontal), (state_focusable | state_linked));
+      testAction("noLink", noLinkAcc, "");
+
+      //////////////////////////////////////////////////////////////////////////
+      // Link with registered 'click' event, should have state_linked
+      var linkWithClickElement = document.getElementById("linkWithClick");
+      var linkWithClickAcc;
+      try {
+        linkWithClickAcc = gAccRetrieval.getAccessibleFor(linkWithClickElement).
+              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(linkWithClickAcc, "no interface for named anchor!");
+      }
+      testThis("linkWithClick", linkWithClickAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
+               "This should have state_linked", true, 301, 302);
+      testStates("linkWithClick", linkWithClickAcc,
+                 (state_linked),
+                 (ext_state_horizontal), 0);
+      testAction("linkWithClick", linkWithClickAcc, "click");
 
       //////////////////////////////////////////////////////////////////////////
       // Maps to group links (bug 431615).
       var linksMapElement = document.getElementById("linksmap");
       var linksMapAcc;
       try {
-        linksMapAcc = accService.getAccessibleFor(linksMapElement);
+        linksMapAcc = gAccRetrieval.getAccessibleFor(linksMapElement);
       } catch(e) { }
-    
+
       ok(linksMapAcc, "no accessible for map grouping links!");
+
+      //////////////////////////////////////////////////////////////////////////
+      // Link with title attribute, no name from the subtree (bug 438325).
+      var id = "linkWithTitleNoNameFromSubtree";
+      var linkElement = document.getElementById(id);
+      var linkAcc;
+      try {
+        linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
+              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(linkAcc, "no interface for link with ID " + id + "!");
+      }
+      testThis(id, linkAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
+               "Link with title", true, 354, 355);
+      testStates(id, linkAcc,
+                 (state_linked),
+                 (ext_state_horizontal), 0);
+      testAction(id, linkAcc, "jump");
+
+      //////////////////////////////////////////////////////////////////////////
+      // Link with title attribute, name from the subtree - onsreen name
+      // (bug 438325).
+      id = "linkWithTitleNameFromSubtree";
+      linkElement = document.getElementById(id);
+      linkAcc;
+      try {
+        linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
+              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(linkAcc, "no interface for link with ID " + id + "!");
+      }
+      testThis(id, linkAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
+               "the name from subtree", true, 403, 404);
+      testStates(id, linkAcc,
+                 (state_linked),
+                 (ext_state_horizontal), 0);
+      testAction(id, linkAcc, "jump");
+
+      //////////////////////////////////////////////////////////////////////////
+      // Link with title attribute, name from the nested html:img (bug 438325).
+      id = "linkWithTitleNameFromImg";
+      linkElement = document.getElementById(id);
+      linkAcc;
+      try {
+        linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
+              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(linkAcc, "no interface for link with ID " + id + "!");
+      }
+      testThis(id, linkAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
+               "The title for link", true, 458, 459);
+      testStates(id, linkAcc,
+                 (state_linked),
+                 (ext_state_horizontal), 0);
+      testAction(id, linkAcc, "jump");
+
+      //////////////////////////////////////////////////////////////////////////
+      // Link with label, no name from the subtree (bug 438325).
+      id = "linkWithLabelNoNameFromSubtree";
+      linkElement = document.getElementById(id);
+      linkAcc;
+      try {
+        linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
+              QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
+      } catch(e) {
+        ok(linkAcc, "no interface for link with ID " + id + "!");
+      }
+      testThis(id, linkAcc,
+               Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1, 
+               "Link with label and nested image:", true, 462, 463);
+      testStates(id, linkAcc,
+                 (state_linked),
+                 (ext_state_horizontal), 0);
+      testAction(id, linkAcc, "jump");
+
+      //////////////////////////////////////////////////////////////////////////
+      //
       SimpleTest.finish();
     }
 
     SimpleTest.waitForExplicitFinish();
     addLoadEvent(doTest);
   </script>
 </head>
 <body>
 
   <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=418368">Mozilla Bug 418368</a>
   <p id="display"></p>
   <div id="content" style="display: none"></div>
   <pre id="test">
   </pre>
+
   <br>Simple link:<br>
   <a id="NormalHyperlink" href="http://www.mozilla.org">Mozilla Foundation</a>
   <br>ARIA link:<br>
   <span id="AriaHyperlink" role="link"
          onclick="window.open('http://www.mozilla.org/');"
          tabindex="0">Mozilla Foundation Home</span>
   <br>Invalid, non-focusable hyperlink:<br>
   <span id="InvalidAriaHyperlink" role="link" aria-invalid="true"
@@ -297,23 +448,48 @@ https://bugzilla.mozilla.org/show_bug.cg
           coords="0,0,13,14"
           alt="a"
           shape="rect"></area>
   </map>
   <img width="447" id="imgmap"
        height="15"
        usemap="#atoz_map"
        src="http://www.bbc.co.uk/radio4/images/letters.gif"></img>
+
   <br>Empty link:<br>
   <a id="emptyLink" href=""><img src=""></img></a>
+
   <br>Link with embedded span<br>
   <a id="LinkWithSpan" href="http://www.heise.de/"><span lang="de">Heise Online</span></a>
+
   <br>Named anchor, must not have "linked" state for it to be exposed correctly:<br>
   <a id="namedAnchor" name="named_anchor">This should never be of state_linked</a>
 
+  <br>Link having no attributes, must not have "linked" state:</br>
+  <a id="noLink">This should never be of state_linked</a>
+
+  <br>Link with registered 'click' event: </br>
+  <a id="linkWithClick" onclick="var clicked = true;">This should have state_linked</a>
+
+  <br>Link with title attribute (no name from subtree): </br>
+  <a id="linkWithTitleNoNameFromSubtree" href="http://www.heise.de/"
+     title="Link with title"><img src=""/></a>
+
+  <br>Link with title attribute (name from subtree): </br>
+  <a id="linkWithTitleNameFromSubtree" href="http://www.heise.de/"
+     title="Link with title">the name from subtree</a>
+
+  <br>Link with title attribute (name from nested image): </br>
+  <a id="linkWithTitleNameFromImg" href="http://www.heise.de/"
+     title="Link with title"><img src="" alt="The title for link"/></a>
+
+  <br><label for="linkWithLabelNoNameFromSubtree">Link with label and nested image: </label></br>
+  <a id="linkWithLabelNoNameFromSubtree"
+     href="http://www.heise.de/"><img src=""/></a>
+
   <br>Map that is used to group links (www.w3.org/TR/WCAG10-HTML-TECHS/#group-bypass),
    also see the bug 431615:<br>
   <map id="linksmap" title="Site navigation">
     <ul>
       <li><a href="http://mozilla.org">About the project</a></li>
       <li><a href="http://mozilla.org">Sites and sounds</a></li>
     </ul>
   </map>
--- a/browser/branding/unofficial/locales/jar.mn
+++ b/browser/branding/unofficial/locales/jar.mn
@@ -1,6 +1,7 @@
 #filter substitution
 
 @AB_CD@.jar:
 % locale branding @AB_CD@ %locale/branding/
-  locale/branding/brand.dtd        (%brand.dtd)
-* locale/branding/brand.properties (%brand.properties)
+# Gran Paradiso branding only exists in en-US
+  locale/branding/brand.dtd        (en-US/brand.dtd)
+* locale/branding/brand.properties (en-US/brand.properties)
--- a/config/Makefile.in
+++ b/config/Makefile.in
@@ -161,11 +161,12 @@ check-preprocessor::
 	@$(EXIT_ON_ERROR) \
 	for test in $(PYUNITS); do \
 	  $(PYTHON) $(srcdir)/tests/$$test ; \
 	done
 
 check-jar-mn::
 	make -C tests/src-simple check-jar
 	make -C tests/src-simple check-flat
+	make -C tests/src-simple check-flat USE_EXTENSION_MANIFEST=1
 ifneq ($(OS_ARCH), WINNT)
 	make -C tests/src-simple check-symlink
 endif
new file mode 100644
--- /dev/null
+++ b/config/tests/chrome.manifest.flat
@@ -0,0 +1,4 @@
+content test chrome/test/one xpcnativewrappers=no
+locale ab-X-stuff chrome/test/three
+overlay chrome://one/file.xml chrome://two/otherfile.xml
+skin test classic chrome/test/one
--- a/config/tests/src-simple/Makefile.in
+++ b/config/tests/src-simple/Makefile.in
@@ -47,21 +47,24 @@ include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/config.mk
 
 XPI_NAME = test_jar_mn
 
 DEFINES += \
 	-DAB_CD=ab-X-stuff \
 	$(NULL)
 
+MY_MANIFEST = $(if $(USE_EXTENSION_MANIFEST), $(FINAL_TARGET)/chrome.manifest, $(FINAL_TARGET)/chrome/test.manifest)
+REF_MANIFEST = $(if $(USE_EXTENSION_MANIFEST),chrome.manifest,test.manifest)
+
 check-%::
 	if test -d $(FINAL_TARGET); then rm -rf $(FINAL_TARGET); fi;
 	make realchrome MOZ_CHROME_FILE_FORMAT=$*
 	@echo "Comparing manifests..."
-	@if ! sort $(FINAL_TARGET)/chrome/test.manifest | diff -u $(srcdir)/../test.manifest.$* - ; then \
+	@if ! sort $(MY_MANIFEST) | diff -u $(srcdir)/../$(REF_MANIFEST).$* - ; then \
 	  echo "FAIL: different content in manifest!" ; \
 	fi
 	@if [ $* == "jar" ]; then \
 	  $(UNZIP) -d $(FINAL_TARGET)/chrome/test $(FINAL_TARGET)/chrome/test.jar; \
 	fi
 	@echo "Comparing packages..."
 	@if ! diff -ur $(srcdir)/../ref-simple $(FINAL_TARGET)/chrome/test ; then\
 	  echo "FAIL: different content in jar!" ; \
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -1206,16 +1206,22 @@ public:
   static void HidePopupsInDocument(nsIDocument* aDocument);
 
   /**
    * Return true if aURI is a local file URI (i.e. file://).
    */
   static PRBool URIIsLocalFile(nsIURI *aURI);
 
   /**
+   * If aContent is an HTML element with a DOM level 0 'name', then
+   * return the name. Otherwise return null.
+   */
+  static nsIAtom* IsNamedItem(nsIContent* aContent);
+
+  /**
    * Get the application manifest URI for this context.  The manifest URI
    * is specified in the manifest= attribute of the root element of the
    * toplevel window.
    *
    * @param aWindow The context to check.
    * @param aURI The manifest URI.
    */
   static void GetOfflineAppManifest(nsIDOMWindow *aWindow, nsIURI **aURI);
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -146,16 +146,18 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_
 #include "nsIDOMNSUIEvent.h"
 #include "nsIDOMNSEvent.h"
 #include "nsIPrivateDOMEvent.h"
 #include "nsXULPopupManager.h"
 #include "nsIPermissionManager.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIRunnable.h"
 #include "nsDOMJSUtils.h"
+#include "nsGenericHTMLElement.h"
+#include "nsAttrValue.h"
 
 #ifdef IBMBIDI
 #include "nsIBidiKeyboard.h"
 #endif
 #include "nsCycleCollectionParticipant.h"
 
 // for ReportToConsole
 #include "nsIStringBundle.h"
@@ -4288,8 +4290,37 @@ nsContentUtils::URIIsLocalFile(nsIURI *a
 }
 
 /* static */
 void
 nsAutoGCRoot::Shutdown()
 {
   NS_IF_RELEASE(sJSRuntimeService);
 }
+
+nsIAtom*
+nsContentUtils::IsNamedItem(nsIContent* aContent)
+{
+  // Only the content types reflected in Level 0 with a NAME
+  // attribute are registered. Images, layers and forms always get
+  // reflected up to the document. Applets and embeds only go
+  // to the closest container (which could be a form).
+  nsGenericHTMLElement* elm = nsGenericHTMLElement::FromContent(aContent);
+  if (!elm) {
+    return nsnull;
+  }
+
+  nsIAtom* tag = elm->Tag();
+  if (tag != nsGkAtoms::img    &&
+      tag != nsGkAtoms::form   &&
+      tag != nsGkAtoms::applet &&
+      tag != nsGkAtoms::embed  &&
+      tag != nsGkAtoms::object) {
+    return nsnull;
+  }
+
+  const nsAttrValue* val = elm->GetParsedAttr(nsGkAtoms::name);
+  if (val && val->Type() == nsAttrValue::eAtom) {
+    return val->GetAtomValue();
+  }
+
+  return nsnull;
+}
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -283,16 +283,162 @@ nsUint32ToContentHashEntry::VisitContent
   }
 
   nsIContent* v = GetContent();
   if (v) {
     aVisitor->Visit(v);
   }
 }
 
+#define ID_NOT_IN_DOCUMENT ((nsIContent *)2)
+#define NAME_NOT_VALID ((nsBaseContentList*)1)
+
+nsIdentifierMapEntry::~nsIdentifierMapEntry()
+{
+  if (mNameContentList && mNameContentList != NAME_NOT_VALID) {
+    NS_RELEASE(mNameContentList);
+  }
+}
+
+void
+nsIdentifierMapEntry::Traverse(nsCycleCollectionTraversalCallback* aCallback)
+{
+  if (mNameContentList != NAME_NOT_VALID)
+    aCallback->NoteXPCOMChild(mNameContentList);
+
+  aCallback->NoteXPCOMChild(static_cast<nsIDOMNodeList*>(mDocAllList));
+}
+
+void
+nsIdentifierMapEntry::SetInvalidName()
+{
+  mNameContentList = NAME_NOT_VALID;
+}
+
+PRBool
+nsIdentifierMapEntry::IsInvalidName()
+{
+  return mNameContentList == NAME_NOT_VALID;
+}
+
+nsresult
+nsIdentifierMapEntry::CreateNameContentList()
+{
+  mNameContentList = new nsBaseContentList();
+  NS_ENSURE_TRUE(mNameContentList, NS_ERROR_OUT_OF_MEMORY);
+  NS_ADDREF(mNameContentList);
+  return NS_OK;
+}
+
+nsIContent*
+nsIdentifierMapEntry::GetIdContent(PRBool* aNotInDocument)
+{
+  nsIContent* c = static_cast<nsIContent*>(mIdContentList.SafeElementAt(0));
+  if (aNotInDocument) {
+    *aNotInDocument = c == ID_NOT_IN_DOCUMENT;
+  }
+  return c != ID_NOT_IN_DOCUMENT ? c : nsnull;
+}
+
+void
+nsIdentifierMapEntry::AppendAllIdContent(nsCOMArray<nsIContent>* aElements)
+{
+  for (PRInt32 i = 0; i < mIdContentList.Count(); ++i) {
+    aElements->AppendObject(static_cast<nsIContent*>(mIdContentList[i]));
+  }
+}
+
+PRBool
+nsIdentifierMapEntry::AddIdContent(nsIContent* aContent)
+{
+  NS_PRECONDITION(aContent, "Must have content");
+  NS_PRECONDITION(mIdContentList.IndexOf(nsnull) < 0,
+                  "Why is null in our list?");
+  NS_PRECONDITION(aContent != ID_NOT_IN_DOCUMENT,
+                  "Bogus content pointer");
+
+  if (mIdContentList.SafeElementAt(0) == ID_NOT_IN_DOCUMENT) {
+    NS_ASSERTION(mIdContentList.Count() == 1, "Bogus count");
+    mIdContentList.ReplaceElementAt(aContent, 0);
+    return PR_TRUE;
+  }
+
+  // Common case
+  if (mIdContentList.Count() == 0) {
+    return mIdContentList.AppendElement(aContent) != nsnull;
+  }
+
+  // We seem to have multiple content nodes for the same id, or we're doing our
+  // top-down registration when the id table is going live.  Search for the
+  // right place to insert the content.
+  PRInt32 start = 0;
+  PRInt32 end = mIdContentList.Count();
+  do {
+    NS_ASSERTION(start < end, "Bogus start/end");
+    
+    PRInt32 cur = (start + end) / 2;
+    NS_ASSERTION(cur >= start && cur < end, "What happened here?");
+
+    nsIContent* curContent = static_cast<nsIContent*>(mIdContentList[cur]);
+    if (curContent == aContent) {
+      // Already in the list, so already in the right spot.  Get out of here.
+      return PR_TRUE;
+    }
+
+    if (nsContentUtils::PositionIsBefore(aContent, curContent)) {
+      end = cur;
+    } else {
+      start = cur + 1;
+    }
+  } while (start != end);
+  
+  return mIdContentList.InsertElementAt(aContent, start);
+}
+
+PRBool
+nsIdentifierMapEntry::RemoveIdContent(nsIContent* aContent)
+{
+  // XXXbz should this ever Compact() I guess when all the content is gone
+  // we'll just get cleaned up in the natural order of things...
+  return mIdContentList.RemoveElement(aContent) &&
+    mIdContentList.Count() == 0 && !mNameContentList;
+}
+
+void
+nsIdentifierMapEntry::FlagIDNotInDocument()
+{
+  NS_ASSERTION(mIdContentList.Count() == 0,
+               "Flagging ID not in document when we have content?");
+  // Note that if this fails that's OK; this is just an optimization
+  mIdContentList.AppendElement(ID_NOT_IN_DOCUMENT);
+}
+
+void
+nsIdentifierMapEntry::AddNameContent(nsIContent* aContent)
+{
+  if (!mNameContentList || mNameContentList == NAME_NOT_VALID)
+    return;
+
+  // NOTE: this indexof is absolutely needed, since we don't flush
+  // content notifications when we do document.foo resolution.  So
+  // aContent may be in our list already and just now getting notified
+  // for!
+  if (mNameContentList->IndexOf(aContent, PR_FALSE) < 0) {
+    mNameContentList->AppendElement(aContent);
+  }
+}
+
+void
+nsIdentifierMapEntry::RemoveNameContent(nsIContent* aContent)
+{
+  if (mNameContentList && mNameContentList != NAME_NOT_VALID) {
+    mNameContentList->RemoveElement(aContent);
+  }
+}
+
 // Helper structs for the content->subdoc map
 
 class SubDocMapEntry : public PLDHashEntryHdr
 {
 public:
   // Both of these are strong references
   nsIContent *mKey; // must be first, to look like PLDHashEntryStub
   nsIDocument *mSubDocument;
@@ -1007,31 +1153,42 @@ class LinkMapTraversalVisitor : public n
 public:
   nsCycleCollectionTraversalCallback *mCb;
   virtual void Visit(nsIContent* aContent)
   {
     mCb->NoteXPCOMChild(aContent);
   }
 };
 
-PLDHashOperator PR_CALLBACK
+PR_STATIC_CALLBACK(PLDHashOperator)
 LinkMapTraverser(nsUint32ToContentHashEntry* aEntry, void* userArg)
 {
   LinkMapTraversalVisitor visitor;
   visitor.mCb = static_cast<nsCycleCollectionTraversalCallback*>(userArg);
   NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*visitor.mCb, "mLinkMap entry");
   aEntry->VisitContent(&visitor);
   return PL_DHASH_NEXT;
 }
 
+PR_STATIC_CALLBACK(PLDHashOperator)
+IdentifierMapEntryTraverse(nsIdentifierMapEntry *aEntry, void *aArg)
+{
+  nsCycleCollectionTraversalCallback *cb =
+    static_cast<nsCycleCollectionTraversalCallback*>(aArg);
+  aEntry->Traverse(cb);
+  return PL_DHASH_NEXT;
+}
+
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocument)
   if (nsCCUncollectableMarker::InGeneration(tmp->GetMarkedCCGeneration())) {
     return NS_OK;
   }
 
+  tmp->mIdentifierMap.EnumerateEntries(IdentifierMapEntryTraverse, &cb);
+
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNodeInfo)
 
   // Traverse the mChildren nsAttrAndChildArray.
   for (PRInt32 indx = PRInt32(tmp->mChildren.ChildCount()); indx > 0; --indx) {
     NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mChildren[i]");
     cb.NoteXPCOMChild(tmp->mChildren.ChildAt(indx - 1));
   }
 
@@ -1122,16 +1279,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 nsresult
 nsDocument::Init()
 {
   if (mCSSLoader || mNodeInfoManager || mScriptLoader) {
     return NS_ERROR_ALREADY_INITIALIZED;
   }
 
+  mIdentifierMap.Init();
   mLinkMap.Init();
   mRadioGroups.Init();
 
   // Force initialization.
   nsINode::nsSlots* slots = GetSlots();
   NS_ENSURE_TRUE(slots,NS_ERROR_OUT_OF_MEMORY);
 
   // Prepend self as mutation-observer whether we need it or not (some
@@ -1216,16 +1374,17 @@ nsDocument::ResetToURI(nsIURI *aURI, nsI
   if (gDocumentLeakPRLog && PR_LOG_TEST(gDocumentLeakPRLog, PR_LOG_DEBUG)) {
     nsCAutoString spec;
     aURI->GetSpec(spec);
     PR_LogPrint("DOCUMENT %p ResetToURI %s", this, spec.get());
   }
 #endif
 
   mDocumentTitle.SetIsVoid(PR_TRUE);
+  mIdentifierMap.Clear();
 
   SetPrincipal(nsnull);
   mSecurityInfo = nsnull;
 
   mDocumentLoadGroup = nsnull;
 
   // Delete references to sub-documents and kill the subdocument map,
   // if any. It holds strong references
@@ -1525,16 +1684,195 @@ nsDocument::GetLastModified(nsAString& a
     // If we for whatever reason failed to find the last modified time
     // (or even the current time), fall back to what NS4.x returned.
     aLastModified.Assign(NS_LITERAL_STRING("01/01/1970 00:00:00"));
   }
 
   return NS_OK;
 }
 
+void
+nsDocument::UpdateNameTableEntry(nsIContent *aContent)
+{
+  if (!mIsRegularHTML)
+    return;
+
+  nsIAtom* name = nsContentUtils::IsNamedItem(aContent);
+  if (!name)
+    return;
+
+  nsIdentifierMapEntry *entry = mIdentifierMap.GetEntry(name);
+  if (!entry) {
+    // We're not tracking the elements with this name
+    return;
+  }
+
+  entry->AddNameContent(aContent);
+}
+
+void
+nsDocument::RemoveFromNameTable(nsIContent *aContent)
+{
+  if (!mIsRegularHTML)
+    return;
+
+  nsIAtom* name = nsContentUtils::IsNamedItem(aContent);
+  if (!name)
+    return;
+
+  nsIdentifierMapEntry *entry = mIdentifierMap.GetEntry(name);
+  if (!entry) {
+    // We're not tracking the elements with this name
+    return;
+  }
+
+  entry->RemoveNameContent(aContent);
+}
+
+void
+nsDocument::UpdateIdTableEntry(nsIContent *aContent)
+{
+  nsIAtom* id = aContent->GetID();
+  if (!id)
+    return;
+
+  PRBool liveTable = IdTableIsLive();
+  nsIdentifierMapEntry *entry =
+    liveTable ? mIdentifierMap.PutEntry(id) : mIdentifierMap.GetEntry(id);
+
+  if (entry) {
+    entry->AddIdContent(aContent);
+  }
+}
+
+void
+nsDocument::RemoveFromIdTable(nsIContent *aContent)
+{
+  nsIAtom* id = aContent->GetID();
+  if (!id)
+    return;
+
+  nsIdentifierMapEntry *entry = mIdentifierMap.GetEntry(id);
+  if (!entry)
+    return;
+
+  if (entry->RemoveIdContent(aContent)) {
+    mIdentifierMap.RemoveEntry(id);
+  }
+}
+
+void
+nsDocument::UnregisterNamedItems(nsIContent *aContent)
+{
+  if (aContent->IsNodeOfType(nsINode::eTEXT)) {
+    // Text nodes are not named items nor can they have children.
+    return;
+  }
+
+  RemoveFromNameTable(aContent);
+  RemoveFromIdTable(aContent);
+
+  PRUint32 i, count = aContent->GetChildCount();
+  for (i = 0; i < count; ++i) {
+    UnregisterNamedItems(aContent->GetChildAt(i));
+  }
+}
+
+void
+nsDocument::RegisterNamedItems(nsIContent *aContent)
+{
+  if (aContent->IsNodeOfType(nsINode::eTEXT)) {
+    // Text nodes are not named items nor can they have children.
+    return;
+  }
+
+  UpdateNameTableEntry(aContent);
+  UpdateIdTableEntry(aContent);
+
+  PRUint32 i, count = aContent->GetChildCount();
+  for (i = 0; i < count; ++i) {
+    RegisterNamedItems(aContent->GetChildAt(i));
+  }
+}
+
+void
+nsDocument::ContentAppended(nsIDocument* aDocument,
+                            nsIContent* aContainer,
+                            PRInt32 aNewIndexInContainer)
+{
+  NS_ASSERTION(aDocument == this, "unexpected doc");
+
+  PRUint32 count = aContainer->GetChildCount();
+  for (PRUint32 i = aNewIndexInContainer; i < count; ++i) {
+    RegisterNamedItems(aContainer->GetChildAt(i));
+  }
+}
+
+void
+nsDocument::ContentInserted(nsIDocument* aDocument,
+                            nsIContent* aContainer,
+                            nsIContent* aContent,
+                            PRInt32 aIndexInContainer)
+{
+  NS_ASSERTION(aDocument == this, "unexpected doc");
+
+  NS_ABORT_IF_FALSE(aContent, "Null content!");
+
+  RegisterNamedItems(aContent);
+}
+
+void
+nsDocument::ContentRemoved(nsIDocument* aDocument,
+                           nsIContent* aContainer,
+                           nsIContent* aChild,
+                           PRInt32 aIndexInContainer)
+{
+  NS_ASSERTION(aDocument == this, "unexpected doc");
+
+  NS_ABORT_IF_FALSE(aChild, "Null content!");
+
+  UnregisterNamedItems(aChild);
+}
+
+void
+nsDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
+                                nsIAtom* aAttribute)
+{
+  NS_ABORT_IF_FALSE(aContent, "Null content!");
+  NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
+
+  if (aNameSpaceID != kNameSpaceID_None)
+    return;
+  if (aAttribute == nsGkAtoms::name) {
+    RemoveFromNameTable(aContent);
+  } else if (aAttribute == aContent->GetIDAttributeName()) {
+    RemoveFromIdTable(aContent);
+  }
+}
+
+void
+nsDocument::AttributeChanged(nsIDocument* aDocument,
+                             nsIContent* aContent, PRInt32 aNameSpaceID,
+                             nsIAtom* aAttribute, PRInt32 aModType,
+                             PRUint32 aStateMask)
+{
+  NS_ASSERTION(aDocument == this, "unexpected doc");
+
+  NS_ABORT_IF_FALSE(aContent, "Null content!");
+  NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
+
+  if (aNameSpaceID != kNameSpaceID_None)
+    return;
+  if (aAttribute == nsGkAtoms::name) {
+    UpdateNameTableEntry(aContent);
+  } else if (aAttribute == aContent->GetIDAttributeName()) {
+    UpdateIdTableEntry(aContent);
+  }
+}
+
 nsIPrincipal*
 nsDocument::GetPrincipal()
 {
   return NodePrincipal();
 }
 
 void
 nsDocument::SetPrincipal(nsIPrincipal *aNewPrincipal)
@@ -2772,16 +3110,116 @@ nsDocument::CheckGetElementByIdArg(const
         EmptyString(), 0, 0,
         nsIScriptError::warningFlag,
         "DOM");
     return PR_FALSE;
   }
   return PR_TRUE;
 }
 
+NS_IMETHODIMP
+nsDocument::GetElementById(const nsAString& aElementId,
+                           nsIDOMElement** aReturn)
+{
+  NS_ENSURE_ARG_POINTER(aReturn);
+  *aReturn = nsnull;
+
+  nsCOMPtr<nsIAtom> idAtom(do_GetAtom(aElementId));
+  NS_ENSURE_TRUE(idAtom, NS_ERROR_OUT_OF_MEMORY);
+
+  // We don't have to flush before we do the initial hashtable lookup, since if
+  // the id is already in the hashtable it couldn't have been removed without
+  // us being notified (all removals notify immediately, as far as I can tell).
+  // So do the lookup first.
+  nsIdentifierMapEntry *entry = mIdentifierMap.PutEntry(idAtom);
+  NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
+
+  PRBool isNotInDocument;
+  nsIContent *e = entry->GetIdContent(&isNotInDocument);
+
+  if (!e) {
+    // Now we have to flush.  It could be that we have a cached "not in
+    // document" or know nothing about this ID yet but more content has been
+    // added to the document since.  Note that we have to flush notifications,
+    // so that the entry will get updated properly.
+    
+    // Make sure to stash away the current generation so we can check whether
+    // the table changes when we flush.
+    PRUint32 generation = mIdentifierMap.GetGeneration();
+  
+    FlushPendingNotifications(Flush_ContentAndNotify);
+
+    if (generation != mIdentifierMap.GetGeneration()) {
+      // Table changed, so the entry pointer is no longer valid; look up the
+      // entry again, adding if necessary (the adding may be necessary in case
+      // the flush actually deleted entries).
+      entry = mIdentifierMap.PutEntry(idAtom);
+      NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
+    }
+
+    // We could now have a new entry, or the entry could have been
+    // updated, so update e to point to the current entry's
+    // mIdContent.
+    e = entry->GetIdContent(&isNotInDocument);
+  }
+
+  if (isNotInDocument) {
+    // We've looked for this id before and we didn't find it, so it
+    // won't be in the document now either (since the
+    // mIdentifierMap is live for entries in the table)
+
+    return NS_OK;
+  }
+
+  if (!e) {
+    // If IdTableIsLive(), no need to look for the element in the document,
+    // since we're fully maintaining our table's state as the DOM mutates.
+    nsIContent* root = GetRootContent();
+    if (!IdTableIsLive()) {
+      if (IdTableShouldBecomeLive()) {
+        // Just make sure our table is up to date and call this method again
+        // to look up in the hashtable.
+        if (root) {
+          RegisterNamedItems(root);
+        }
+        return GetElementById(aElementId, aReturn);
+      }
+
+      if (root && CheckGetElementByIdArg(aElementId)) {
+        e = nsContentUtils::MatchElementId(root, idAtom);
+      }
+    }
+
+    if (!e) {
+#ifdef DEBUG
+      // No reason to call MatchElementId if !IdTableIsLive, since
+      // we'd have done just that already
+      if (IdTableIsLive() && root && !aElementId.IsEmpty()) {
+        nsIContent* eDebug =
+          nsContentUtils::MatchElementId(root, idAtom);
+        NS_ASSERTION(!eDebug,
+                     "We got null for |e| but MatchElementId found something?");
+      }
+#endif
+      // There is no element with the given id in the document, cache
+      // the fact that it's not in the document
+      entry->FlagIDNotInDocument();
+
+      return NS_OK;
+    }
+
+    // We found an element with a matching id, store that in the hash
+    if (NS_UNLIKELY(!entry->AddIdContent(e))) {
+      return NS_ERROR_OUT_OF_MEMORY;
+    }
+  }
+
+  return CallQueryInterface(e, aReturn);
+}
+
 void
 nsDocument::DispatchContentLoadedEvents()
 {
   // If you add early returns from this method, make sure you're
   // calling UnblockOnload properly.
   
   // Fire a DOM event notifying listeners that this document has been
   // loaded (excluding images and other loads initiated by this
@@ -2880,23 +3318,16 @@ void
 nsDocument::ContentStatesChanged(nsIContent* aContent1, nsIContent* aContent2,
                                  PRInt32 aStateMask)
 {
   NS_DOCUMENT_NOTIFY_OBSERVERS(ContentStatesChanged,
                                (this, aContent1, aContent2, aStateMask));
 }
 
 void
-nsDocument::AttributeWillChange(nsIContent* aChild, PRInt32 aNameSpaceID,
-                                nsIAtom* aAttribute)
-{
-  NS_ASSERTION(aChild, "Null child!");
-}
-
-void
 nsDocument::StyleRuleChanged(nsIStyleSheet* aStyleSheet,
                              nsIStyleRule* aOldStyleRule,
                              nsIStyleRule* aNewStyleRule)
 {
   NS_DOCUMENT_NOTIFY_OBSERVERS(StyleRuleChanged,
                                (this, aStyleSheet,
                                 aOldStyleRule, aNewStyleRule));
 }
@@ -3212,24 +3643,16 @@ nsDocument::GetElementsByTagNameNS(const
   NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
 
   // transfer ref to aReturn
   *aReturn = list;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDocument::GetElementById(const nsAString & elementId,
-                           nsIDOMElement **_retval)
-{
-  // Should be implemented by subclass
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
 nsDocument::GetAsync(PRBool *aAsync)
 {
   NS_ERROR("nsDocument::GetAsync() should be overriden by subclass!");
 
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -85,16 +85,17 @@
 #include "nsIScriptEventManager.h"
 #include "nsILayoutHistoryState.h"
 #include "nsIRequest.h"
 #include "nsILoadGroup.h"
 #include "nsTObserverArray.h"
 #include "nsStubMutationObserver.h"
 #include "nsIChannel.h"
 #include "nsCycleCollectionParticipant.h"
+#include "nsContentList.h"
 
 // Put these here so all document impls get them automatically
 #include "nsHTMLStyleSheet.h"
 #include "nsIHTMLCSSStyleSheet.h"
 
 #include "nsStyleSet.h"
 #include "nsXMLEventsManager.h"
 #include "pldhash.h"
@@ -205,16 +206,82 @@ class nsUint32ToContentHashEntry : publi
     void Destroy();
 
   private:
     const PRUint32 mValue;
     /** A hash or nsIContent ptr, depending on the lower bit (0=hash, 1=ptr) */
     void* mValOrHash;
 };
 
+/**
+ * Right now our identifier map entries contain information for 'name'
+ * and 'id' mappings of a given string. This is so that
+ * nsHTMLDocument::ResolveName only has to do one hash lookup instead
+ * of two. It's not clear whether this still matters for performance.
+ * 
+ * We also store the document.all result list here. This is mainly so that
+ * when all elements with the given ID are removed and we remove
+ * the ID's nsIdentifierMapEntry, the document.all result is released too.
+ * Perhaps the document.all results should have their own hashtable
+ * in nsHTMLDocument.
+ */
+class nsIdentifierMapEntry : public nsISupportsHashKey
+{
+public:
+  nsIdentifierMapEntry(const nsISupports* aKey) :
+    nsISupportsHashKey(aKey), mNameContentList(nsnull)
+  {
+  }
+  nsIdentifierMapEntry(const nsIdentifierMapEntry& aOther) :
+    nsISupportsHashKey(GetKey())
+  {
+    NS_ERROR("Should never be called");
+  }
+  ~nsIdentifierMapEntry();
+
+  void SetInvalidName();
+  PRBool IsInvalidName();
+  void AddNameContent(nsIContent* aContent);
+  void RemoveNameContent(nsIContent* aContent);
+  PRBool HasNameContentList() {
+    return mNameContentList != nsnull;
+  }
+  nsBaseContentList* GetNameContentList() {
+    return mNameContentList;
+  }
+  nsresult CreateNameContentList();
+
+  /**
+   * Returns the element if we know the element associated with this
+   * id. Otherwise returns null.
+   * @param aIsNotInDocument if non-null, we set the output to true
+   * if we know for sure the element is not in the document.
+   */
+  nsIContent* GetIdContent(PRBool* aIsNotInDocument = nsnull);
+  void AppendAllIdContent(nsCOMArray<nsIContent>* aElements);
+  PRBool AddIdContent(nsIContent* aContent);
+  /**
+   * @return true if this map entry should be removed
+   */
+  PRBool RemoveIdContent(nsIContent* aContent);
+  void FlagIDNotInDocument();
+
+  void Traverse(nsCycleCollectionTraversalCallback* aCallback);
+
+  void SetDocAllList(nsContentList* aContentList) { mDocAllList = aContentList; }
+  nsContentList* GetDocAllList() { return mDocAllList; }
+
+private:
+  // The single element ID_NOT_IN_DOCUMENT, or empty to indicate we
+  // don't know what element(s) have this key as an ID
+  nsSmallVoidArray mIdContentList;
+  // NAME_NOT_VALID if this id cannot be used as a 'name'
+  nsBaseContentList *mNameContentList;
+  nsRefPtr<nsContentList> mDocAllList;
+};
 
 class nsDocHeaderData
 {
 public:
   nsDocHeaderData(nsIAtom* aField, const nsAString& aData)
     : mField(aField), mData(aData), mNext(nsnull)
   {
   }
@@ -607,16 +674,22 @@ public:
   NS_DECL_NSIDOMEVENTTARGET
 
   // nsIDOM3EventTarget
   NS_DECL_NSIDOM3EVENTTARGET
 
   // nsIDOMNSEventTarget
   NS_DECL_NSIDOMNSEVENTTARGET
 
+  // nsIMutationObserver
+  NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
+  NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
+  NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
+  NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
+
   // nsIScriptObjectPrincipal
   virtual nsIPrincipal* GetPrincipal();
 
   virtual nsresult Init();
   
   virtual nsresult AddXMLEventsContent(nsIContent * aXMLEventsElement);
 
   virtual nsresult CreateElem(nsIAtom *aName, nsIAtom *aPrefix,
@@ -660,16 +733,23 @@ public:
    * Utility method for getElementsByClassName.  aRootNode is the node (either
    * document or element), which getElementsByClassName was called on.
    */
   static nsresult GetElementsByClassNameHelper(nsINode* aRootNode,
                                                const nsAString& aClasses,
                                                nsIDOMNodeList** aReturn);
 protected:
 
+  void RegisterNamedItems(nsIContent *aContent);
+  void UnregisterNamedItems(nsIContent *aContent);
+  void UpdateNameTableEntry(nsIContent *aContent);
+  void UpdateIdTableEntry(nsIContent *aContent);
+  void RemoveFromNameTable(nsIContent *aContent);
+  void RemoveFromIdTable(nsIContent *aContent);
+
   /**
    * Check that aId is not empty and log a message to the console
    * service if it is.
    * @returns PR_TRUE if aId looks correct, PR_FALSE otherwise.
    */
   static PRBool CheckGetElementByIdArg(const nsAString& aId);
 
   void DispatchContentLoadedEvents();
@@ -767,40 +847,68 @@ protected:
   // is a weak reference to avoid leaks due to circular references.
   nsWeakPtr mScopeObject;
 
   nsCOMPtr<nsIEventListenerManager> mListenerManager;
   nsCOMPtr<nsIDOMStyleSheetList> mDOMStyleSheets;
   nsRefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
   nsRefPtr<nsScriptLoader> mScriptLoader;
   nsDocHeaderData* mHeaderData;
+  /* mIdentifierMap works as follows for IDs:
+   * 1) Attribute changes affect the table immediately (removing and adding
+   *    entries as needed).
+   * 2) Removals from the DOM affect the table immediately
+   * 3) Additions to the DOM always update existing entries, but only add new
+   *    ones if IdTableIsLive() is true.
+   */
+  nsTHashtable<nsIdentifierMapEntry> mIdentifierMap;
 
   nsClassHashtable<nsStringHashKey, nsRadioGroupStruct> mRadioGroups;
 
   // True if the document has been detached from its content viewer.
   PRPackedBool mIsGoingAway:1;
   // True if our content viewer has been removed from the docshell
   // (it may still be displayed, but in zombie state). Form control data
   // has been saved.
   PRPackedBool mRemovedFromDocShell:1;
   // True if the document is being destroyed.
   PRPackedBool mInDestructor:1;
   // True if the document "page" is not hidden
   PRPackedBool mVisible:1;
   // True if document has ever had script handling object.
   PRPackedBool mHasHadScriptHandlingObject:1;
+  // True if this is a regular (non-XHTML) HTML document
+  // XXXbz should this be reset if someone manually calls
+  // SetContentType() on this document?
+  PRPackedBool mIsRegularHTML:1;
 
   PRPackedBool mHasWarnedAboutBoxObjects:1;
 
   PRPackedBool mDelayFrameLoaderInitialization:1;
 
   PRUint8 mXMLDeclarationBits;
 
   PRUint8 mDefaultElementType;
 
+  PRBool IdTableIsLive() const {
+    // live if we've had over 63 misses
+    return (mIdMissCount & 0x40) != 0;
+  }
+  void SetIdTableLive() {
+    mIdMissCount = 0x40;
+  }
+  PRBool IdTableShouldBecomeLive() {
+    NS_ASSERTION(!IdTableIsLive(),
+                 "Shouldn't be called if table is already live!");
+    ++mIdMissCount;
+    return IdTableIsLive();
+  }
+
+  PRUint8 mIdMissCount;
+
   nsInterfaceHashtable<nsVoidPtrHashKey, nsPIBoxObject> *mBoxObjectTable;
   nsInterfaceHashtable<nsVoidPtrHashKey, nsISupports> *mContentWrapperHash;
 
   // The channel that got passed to StartDocumentLoad(), if any
   nsCOMPtr<nsIChannel> mChannel;
   nsRefPtr<nsHTMLStyleSheet> mAttrStyleSheet;
   nsCOMPtr<nsIHTMLCSSStyleSheet> mStyleAttrStyleSheet;
   nsRefPtr<nsXMLEventsManager> mXMLEventsManager;
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -2227,62 +2227,85 @@ nsGenericElement::UnbindFromTree(PRBool 
 
 nsresult
 nsGenericElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
 {
   return nsGenericElement::doPreHandleEvent(this, aVisitor);
 }
 
 static nsIContent*
-FindFirstNonNativeAnonymousAncestor(nsIContent* aContent)
+FindNativeAnonymousSubtreeOwner(nsIContent* aContent)
 {
-  while (aContent && aContent->IsNativeAnonymous()) {
-    aContent = aContent->GetParent();
+  if (aContent->IsInNativeAnonymousSubtree()) {
+    PRBool isNativeAnon = PR_FALSE;
+    while (aContent && !isNativeAnon) {
+      isNativeAnon = aContent->IsNativeAnonymous();
+      aContent = aContent->GetParent();
+    }
   }
   return aContent;
 }
 
 nsresult
 nsGenericElement::doPreHandleEvent(nsIContent* aContent,
                                    nsEventChainPreVisitor& aVisitor)
 {
   //FIXME! Document how this event retargeting works, Bug 329124.
   aVisitor.mCanHandle = PR_TRUE;
 
   // Don't propagate mouseover and mouseout events when mouse is moving
   // inside native anonymous content.
   PRBool isAnonForEvents = aContent->IsNativeAnonymous();
-  if (aVisitor.mEvent->message == NS_MOUSE_ENTER_SYNTH ||
-      aVisitor.mEvent->message == NS_MOUSE_EXIT_SYNTH) {
+  if ((aVisitor.mEvent->message == NS_MOUSE_ENTER_SYNTH ||
+       aVisitor.mEvent->message == NS_MOUSE_EXIT_SYNTH) &&
+      // This is an optimization - try to stop event propagation when
+      // event has just possibly been retargeted.
+      static_cast<nsISupports*>(aContent) == aVisitor.mEvent->target) {
      nsCOMPtr<nsIContent> relatedTarget =
        do_QueryInterface(static_cast<nsMouseEvent*>
                                     (aVisitor.mEvent)->relatedTarget);
     if (relatedTarget &&
         relatedTarget->GetOwnerDoc() == aContent->GetOwnerDoc()) {
 
       // If current target is anonymous for events or we know that related
       // target is descendant of an element which is anonymous for events,
       // we may want to stop event propagation.
       // If aContent is the original target, aVisitor.mRelatedTargetIsInAnon
       // must be updated.
       if (isAnonForEvents || aVisitor.mRelatedTargetIsInAnon ||
           (aVisitor.mEvent->originalTarget == aContent &&
            (aVisitor.mRelatedTargetIsInAnon =
             relatedTarget->IsInNativeAnonymousSubtree()))) {
-        nsIContent* nonAnon = FindFirstNonNativeAnonymousAncestor(aContent);
-        if (nonAnon) {
-          nsIContent* nonAnonRelated =
-            FindFirstNonNativeAnonymousAncestor(relatedTarget);
-          if (nonAnonRelated) {
-            if (nonAnon == nonAnonRelated ||
-                nsContentUtils::ContentIsDescendantOf(nonAnonRelated, nonAnon)) {
-              aVisitor.mParentTarget = nsnull;
-              // Event should not propagate to non-anon content.
-              aVisitor.mCanHandle = isAnonForEvents;
-              return NS_OK;
+        nsIContent* anonOwner = FindNativeAnonymousSubtreeOwner(aContent);
+        if (anonOwner) {
+          nsIContent* anonOwnerRelated =
+            FindNativeAnonymousSubtreeOwner(relatedTarget);
+          if (anonOwnerRelated) {
+            // Note, anonOwnerRelated may still be inside some other
+            // native anonymous subtree. The case where anonOwner is still
+            // inside native anonymous subtree will be handled when event
+            // propagates up in the DOM tree.
+            while (anonOwner != anonOwnerRelated &&
+                   anonOwnerRelated->IsInNativeAnonymousSubtree()) {
+              anonOwnerRelated = FindNativeAnonymousSubtreeOwner(anonOwnerRelated);
+            }
+            if (anonOwner == anonOwnerRelated) {
+              nsCOMPtr<nsIContent> target =
+                do_QueryInterface(aVisitor.mEvent->originalTarget);
+              // Because XBL and native anon content both do event re-targeting,
+              // static_cast<nsISupports*>(aContent) == aVisitor.mEvent->target
+              // optimization may not always work. So be paranoid and make
+              // sure we never stop event propagation when we shouldn't!
+              if (relatedTarget->FindFirstNonNativeAnonymous() ==
+                  target->FindFirstNonNativeAnonymous()) {
+                aVisitor.mParentTarget = nsnull;
+                // Event should not propagate to non-anon content.
+                aVisitor.mCanHandle = isAnonForEvents;
+                return NS_OK;
+              }
             }
           }
         }
       }
     }
   }
 
   nsCOMPtr<nsIContent> parent = aContent->GetParent();
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -153,26 +153,16 @@ static PRBool gPlugDetector = PR_FALSE;
 #include "prtime.h"
 
 // Find/Search Includes
 const PRInt32 kForward  = 0;
 const PRInt32 kBackward = 1;
 
 //#define DEBUG_charset
 
-// Entries in an nsSmallVoidArray must not have the low bit set, so
-// can't use "1" for ID_NOT_IN_DOCUMENT.  "2" should be a perfectly
-// reasonable value, though -- no real nsIContent* will be equal to 2.
-#define ID_NOT_IN_DOCUMENT ((nsIContent *)2)
-#define NAME_NOT_VALID ((nsBaseContentList*)1)
-
-// Returns the name atom of aContent, if the content is a named item
-// and has a name atom.
-static nsIAtom* IsNamedItem(nsIContent* aContent);
-
 static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
 
 PRUint32       nsHTMLDocument::gWyciwygSessionCnt = 0;
 
 // this function will return false if the command is not recognized
 // inCommandID will be converted as necessary for internal operations
 // inParam will be converted as necessary for internal operations
 // outParam will be Empty if no parameter is needed or if returning a boolean
@@ -224,190 +214,33 @@ NS_NewHTMLDocument(nsIDocument** aInstan
     NS_RELEASE(doc);
   }
 
   *aInstancePtrResult = doc;
 
   return rv;
 }
 
-class IdAndNameMapEntry : public PLDHashEntryHdr
-{
-public:
-  IdAndNameMapEntry(nsIAtom* aKey) :
-    mKey(aKey), mNameContentList(nsnull), mIdContentList()
-  {
-  }
-
-  ~IdAndNameMapEntry()
-  {
-    if (mNameContentList && mNameContentList != NAME_NOT_VALID) {
-      NS_RELEASE(mNameContentList);
-    }
-  }
-
-  nsIContent* GetIdContent() {
-    return static_cast<nsIContent*>(mIdContentList.SafeElementAt(0));
-  }
-
-  PRBool AddIdContent(nsIContent* aContent);
-
-  PRBool RemoveIdContent(nsIContent* aContent) {
-    // XXXbz should this ever Compact() I guess when all the content is gone
-    // we'll just get cleaned up in the natural order of things...
-    return mIdContentList.RemoveElement(aContent) &&
-      mIdContentList.Count() == 0;
-  }
-
-  void FlagIDNotInDocument() {
-    NS_ASSERTION(mIdContentList.Count() == 0,
-                 "Flagging ID not in document when we have content?");
-    // Note that if this fails that's OK; this is just an optimization
-    mIdContentList.AppendElement(ID_NOT_IN_DOCUMENT);
-  }
-
-  nsCOMPtr<nsIAtom> mKey;
-  nsBaseContentList *mNameContentList;
-  nsRefPtr<nsContentList> mDocAllList;
-private:
-  nsSmallVoidArray mIdContentList;
-};
-
-PRBool
-IdAndNameMapEntry::AddIdContent(nsIContent* aContent)
-{
-  NS_PRECONDITION(aContent, "Must have content");
-  NS_PRECONDITION(mIdContentList.IndexOf(nsnull) == -1,
-                  "Why is null in our list?");
-  NS_PRECONDITION(aContent != ID_NOT_IN_DOCUMENT,
-                  "Bogus content pointer");
-
-  if (GetIdContent() == ID_NOT_IN_DOCUMENT) {
-    NS_ASSERTION(mIdContentList.Count() == 1, "Bogus count");
-    return mIdContentList.ReplaceElementAt(aContent, 0);
-  }
-
-  // Common case
-  if (mIdContentList.Count() == 0) {
-    return mIdContentList.AppendElement(aContent);
-  }
-
-  // We seem to have multiple content nodes for the same id, or we're doing our
-  // top-down registration when the id table is going live.  Search for the
-  // right place to insert the content.
-  PRInt32 start = 0;
-  PRInt32 end = mIdContentList.Count();
-  do {
-    NS_ASSERTION(start < end, "Bogus start/end");
-    
-    PRInt32 cur = (start + end) / 2;
-    NS_ASSERTION(cur >= start && cur < end, "What happened here?");
-
-    nsIContent* curContent = static_cast<nsIContent*>(mIdContentList[cur]);
-    if (curContent == aContent) {
-      // Already in the list, so already in the right spot.  Get out of here.
-      return PR_TRUE;
-    }
-
-    if (nsContentUtils::PositionIsBefore(aContent, curContent)) {
-      end = cur;
-    } else {
-      start = cur + 1;
-    }
-  } while (start != end);
-  
-  return mIdContentList.InsertElementAt(aContent, start);
-}
-
-
-PR_STATIC_CALLBACK(PLDHashNumber)
-IdAndNameHashHashKey(PLDHashTable *table, const void *key)
-{
-  // Our key is an nsIAtom*, so just shift it and use that as the hash.
-  return NS_PTR_TO_INT32(key) >> 2;
-}
-
-PR_STATIC_CALLBACK(PRBool)
-IdAndNameHashMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *entry,
-                        const void *key)
-{
-  const IdAndNameMapEntry *e =
-    static_cast<const IdAndNameMapEntry *>(entry);
-  const nsIAtom *atom = static_cast<const nsIAtom *>(key);
-
-  return atom == e->mKey;
-}
-
-PR_STATIC_CALLBACK(void)
-IdAndNameHashClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
-{
-  IdAndNameMapEntry *e = static_cast<IdAndNameMapEntry *>(entry);
-
-  // An entry is being cleared, let the entry do its own cleanup.
-  e->~IdAndNameMapEntry();
-}
-
-PR_STATIC_CALLBACK(PRBool)
-IdAndNameHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
-                       const void *key)
-{
-  nsIAtom *atom = const_cast<nsIAtom *>
-                            (static_cast<const nsIAtom*>(key));
-
-  // Inititlize the entry with placement new
-  new (entry) IdAndNameMapEntry(atom);
-  return PR_TRUE;
-}
-
   // NOTE! nsDocument::operator new() zeroes out all members, so don't
   // bother initializing members to 0.
 
 nsHTMLDocument::nsHTMLDocument()
-  : nsDocument("text/html"),
-    mDefaultNamespaceID(kNameSpaceID_None)
+  : nsDocument("text/html")
 {
-
   // NOTE! nsDocument::operator new() zeroes out all members, so don't
   // bother initializing members to 0.
 
+  mIsRegularHTML = PR_TRUE;
   mDefaultElementType = kNameSpaceID_XHTML;
   mCompatMode = eCompatibility_NavQuirks;
 }
 
-nsHTMLDocument::~nsHTMLDocument()
-{
-  if (mIdAndNameHashTable.ops) {
-    PL_DHashTableFinish(&mIdAndNameHashTable);
-  }
-}
-
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLDocument)
 
-PR_STATIC_CALLBACK(PLDHashOperator)
-IdAndNameMapEntryTraverse(PLDHashTable *table, PLDHashEntryHdr *hdr,
-                          PRUint32 number, void *arg)
-{
-  nsCycleCollectionTraversalCallback *cb =
-    static_cast<nsCycleCollectionTraversalCallback*>(arg);
-  IdAndNameMapEntry *entry = static_cast<IdAndNameMapEntry*>(hdr);
-
-  if (entry->mNameContentList != NAME_NOT_VALID)
-    cb->NoteXPCOMChild(entry->mNameContentList);
-
-  cb->NoteXPCOMChild(static_cast<nsIDOMNodeList*>(entry->mDocAllList));
-
-  return PL_DHASH_NEXT;
-}
-
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLDocument, nsDocument)
-  if (tmp->mIdAndNameHashTable.ops) {
-    PL_DHashTableEnumerate(&tmp->mIdAndNameHashTable,
-                           IdAndNameMapEntryTraverse,
-                           &cb);
-  }
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mImageMaps)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mImages)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mApplets)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEmbeds)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLinks)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAnchors)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFragmentParser)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mForms, nsIDOMNodeList)
@@ -437,38 +270,17 @@ nsHTMLDocument::Init()
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Now reset the case-sensitivity of the CSSLoader, since we default
   // to being HTML, not XHTML.  Also, reset the compatibility mode to
   // match our compat mode.
   CSSLoader()->SetCaseSensitive(IsXHTML());
   CSSLoader()->SetCompatibilityMode(mCompatMode);
 
-  static PLDHashTableOps hash_table_ops =
-  {
-    PL_DHashAllocTable,
-    PL_DHashFreeTable,
-    IdAndNameHashHashKey,
-    IdAndNameHashMatchEntry,
-    PL_DHashMoveEntryStub,
-    IdAndNameHashClearEntry,
-    PL_DHashFinalizeStub,
-    IdAndNameHashInitEntry
-  };
-
-  PRBool ok = PL_DHashTableInit(&mIdAndNameHashTable, &hash_table_ops, nsnull,
-                                sizeof(IdAndNameMapEntry), 16);
-  if (!ok) {
-    mIdAndNameHashTable.ops = nsnull;
-
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  PrePopulateHashTables();
-
+  PrePopulateIdentifierMap();
   return NS_OK;
 }
 
 
 void
 nsHTMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
 {
   nsDocument::Reset(aChannel, aLoadGroup);
@@ -481,18 +293,17 @@ nsHTMLDocument::Reset(nsIChannel* aChann
 void
 nsHTMLDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup,
                            nsIPrincipal* aPrincipal)
 {
   mLoadFlags = nsIRequest::LOAD_NORMAL;
 
   nsDocument::ResetToURI(aURI, aLoadGroup, aPrincipal);
 
-  InvalidateHashTables();
-  PrePopulateHashTables();
+  PrePopulateIdentifierMap();
 
   mImages = nsnull;
   mApplets = nsnull;
   mEmbeds = nsnull;
   mLinks = nsnull;
   mAnchors = nsnull;
 
   mImageMaps.Clear();
@@ -841,23 +652,23 @@ nsHTMLDocument::StartDocumentLoad(const 
 {
   nsCAutoString contentType;
   aChannel->GetContentType(contentType);
 
   if (contentType.Equals("application/xhtml+xml") &&
       (!aCommand || nsCRT::strcmp(aCommand, "view-source") != 0)) {
     // We're parsing XHTML as XML, remember that.
 
-    mDefaultNamespaceID = kNameSpaceID_XHTML;
+    mIsRegularHTML = PR_FALSE;
     mCompatMode = eCompatibility_FullStandards;
   }
 #ifdef DEBUG
   else {
-    NS_ASSERTION(mDefaultNamespaceID == kNameSpaceID_None,
-                 "Hey, someone forgot to reset mDefaultNamespaceID!!!");
+    NS_ASSERTION(mIsRegularHTML,
+                 "Hey, someone forgot to reset mIsRegularHTML!!!");
   }
 #endif
 
   CSSLoader()->SetCaseSensitive(IsXHTML());
   CSSLoader()->SetCompatibilityMode(mCompatMode);
   
   PRBool needsParser = PR_TRUE;
   if (aCommand)
@@ -1346,111 +1157,16 @@ nsHTMLDocument::SetCompatibilityMode(nsC
   if (shell) {
     nsPresContext *pc = shell->GetPresContext();
     if (pc) {
       pc->CompatibilityModeChanged();
     }
   }
 }
 
-void
-nsHTMLDocument::ContentAppended(nsIDocument* aDocument,
-                                nsIContent* aContainer,
-                                PRInt32 aNewIndexInContainer)
-{
-  NS_ASSERTION(aDocument == this, "unexpected doc");
-
-  PRUint32 count = aContainer->GetChildCount();
-  for (PRUint32 i = aNewIndexInContainer; i < count; ++i) {
-    RegisterNamedItems(aContainer->GetChildAt(i));
-  }
-}
-
-void
-nsHTMLDocument::ContentInserted(nsIDocument* aDocument,
-                                nsIContent* aContainer,
-                                nsIContent* aContent,
-                                PRInt32 aIndexInContainer)
-{
-  NS_ASSERTION(aDocument == this, "unexpected doc");
-
-  NS_ABORT_IF_FALSE(aContent, "Null content!");
-
-  RegisterNamedItems(aContent);
-}
-
-void
-nsHTMLDocument::ContentRemoved(nsIDocument* aDocument,
-                               nsIContent* aContainer,
-                               nsIContent* aChild,
-                               PRInt32 aIndexInContainer)
-{
-  NS_ASSERTION(aDocument == this, "unexpected doc");
-
-  NS_ABORT_IF_FALSE(aChild, "Null content!");
-
-  UnregisterNamedItems(aChild);
-}
-
-void
-nsHTMLDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
-                                    nsIAtom* aAttribute)
-{
-  NS_ABORT_IF_FALSE(aContent, "Null content!");
-  NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
-
-  if (!IsXHTML() && aAttribute == nsGkAtoms::name &&
-      aNameSpaceID == kNameSpaceID_None) {
-    nsIAtom* name = IsNamedItem(aContent);
-    if (name) {
-      nsresult rv = RemoveFromNameTable(name, aContent);
-
-      if (NS_FAILED(rv)) {
-        return;
-      }
-    }
-  } else if (aAttribute == aContent->GetIDAttributeName() &&
-             aNameSpaceID == kNameSpaceID_None) {
-    nsresult rv = RemoveFromIdTable(aContent);
-
-    if (NS_FAILED(rv)) {
-      return;
-    }
-  }
-
-  nsDocument::AttributeWillChange(aContent, aNameSpaceID, aAttribute);
-}
-
-void
-nsHTMLDocument::AttributeChanged(nsIDocument* aDocument,
-                                 nsIContent* aContent, PRInt32 aNameSpaceID,
-                                 nsIAtom* aAttribute, PRInt32 aModType,
-                                 PRUint32 aStateMask)
-{
-  NS_ASSERTION(aDocument == this, "unexpected doc");
-
-  NS_ABORT_IF_FALSE(aContent, "Null content!");
-  NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
-
-  if (!IsXHTML() && aAttribute == nsGkAtoms::name &&
-      aNameSpaceID == kNameSpaceID_None) {
-
-    nsIAtom* name = IsNamedItem(aContent);
-    if (name) {
-      UpdateNameTableEntry(name, aContent);
-    }
-  } else if (aAttribute == aContent->GetIDAttributeName() &&
-             aNameSpaceID == kNameSpaceID_None) {
-    nsIAtom* id = aContent->GetID();
-    if (id) {
-      UpdateIdTableEntry(id, aContent);
-    }
-  }
-}
-
 PRBool
 nsHTMLDocument::IsCaseSensitive()
 {
   return IsXHTML();
 }
 
 //
 // nsIDOMDocument interface implementation
@@ -1858,34 +1574,34 @@ nsHTMLDocument::SetBody(nsIDOMHTMLElemen
 
   return rootElem->AppendChild(aBody, getter_AddRefs(tmp));
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::GetImages(nsIDOMHTMLCollection** aImages)
 {
   if (!mImages) {
-    mImages = new nsContentList(this, nsGkAtoms::img, mDefaultNamespaceID);
+    mImages = new nsContentList(this, nsGkAtoms::img, GetDefaultNamespaceID());
     if (!mImages) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
 
   *aImages = mImages;
   NS_ADDREF(*aImages);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::GetApplets(nsIDOMHTMLCollection** aApplets)
 {
   if (!mApplets) {
     mApplets = new nsContentList(this, nsGkAtoms::applet,
-                                 mDefaultNamespaceID);
+                                 GetDefaultNamespaceID());
     if (!mApplets) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
 
   *aApplets = mApplets;
   NS_ADDREF(*aApplets);
 
@@ -2561,121 +2277,16 @@ nsHTMLDocument::Write()
 
 NS_IMETHODIMP
 nsHTMLDocument::Writeln()
 {
   return ScriptWriteCommon(PR_TRUE);
 }
 
 NS_IMETHODIMP
-nsHTMLDocument::GetElementById(const nsAString& aElementId,
-                               nsIDOMElement** aReturn)
-{
-  NS_ENSURE_ARG_POINTER(aReturn);
-  *aReturn = nsnull;
-
-  nsCOMPtr<nsIAtom> idAtom(do_GetAtom(aElementId));
-  NS_ENSURE_TRUE(idAtom, NS_ERROR_OUT_OF_MEMORY);
-
-  // We don't have to flush before we do the initial hashtable lookup, since if
-  // the id is already in the hashtable it couldn't have been removed without
-  // us being notified (all removals notify immediately, as far as I can tell).
-  // So do the lookup first.
-  IdAndNameMapEntry *entry =
-    static_cast<IdAndNameMapEntry *>
-               (PL_DHashTableOperate(&mIdAndNameHashTable, idAtom,
-                                        PL_DHASH_ADD));
-  NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
-
-  nsIContent *e = entry->GetIdContent();
-
-  if (!e || e == ID_NOT_IN_DOCUMENT) {
-    // Now we have to flush.  It could be that we have a cached "not in
-    // document" or know nothing about this ID yet but more content has been
-    // added to the document since.  Note that we have to flush notifications,
-    // so that the entry will get updated properly.
-    
-    // Make sure to stash away the current generation so we can check whether
-    // the table changes when we flush.
-    PRUint32 generation = mIdAndNameHashTable.generation;
-  
-    FlushPendingNotifications(Flush_ContentAndNotify);
-
-    if (generation != mIdAndNameHashTable.generation) {
-      // Table changed, so the entry pointer is no longer valid; look up the
-      // entry again, adding if necessary (the adding may be necessary in case
-      // the flush actually deleted entries).
-      entry =
-        static_cast<IdAndNameMapEntry *>
-                   (PL_DHashTableOperate(&mIdAndNameHashTable, idAtom,
-                                            PL_DHASH_ADD));
-      NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
-    }
-
-    // We could now have a new entry, or the entry could have been
-    // updated, so update e to point to the current entry's
-    // mIdContent.
-    e = entry->GetIdContent();
-  }
-
-  if (e == ID_NOT_IN_DOCUMENT) {
-    // We've looked for this id before and we didn't find it, so it
-    // won't be in the document now either (since the
-    // mIdAndNameHashTable is live for entries in the table)
-
-    return NS_OK;
-  }
-
-  if (!e) {
-    // If IdTableIsLive(), no need to look for the element in the document,
-    // since we're fully maintaining our table's state as the DOM mutates.
-    nsIContent* root = GetRootContent();
-    if (!IdTableIsLive()) {
-      if (IdTableShouldBecomeLive()) {
-        // Just make sure our table is up to date and call this method again
-        // to look up in the hashtable.
-        if (root) {
-          RegisterNamedItems(root);
-        }
-        return GetElementById(aElementId, aReturn);
-      }
-
-      if (root && CheckGetElementByIdArg(aElementId)) {
-        e = nsContentUtils::MatchElementId(root, idAtom);
-      }
-    }
-
-    if (!e) {
-#ifdef DEBUG
-      // No reason to call MatchElementId if !IdTableIsLive, since
-      // we'd have done just that already
-      if (IdTableIsLive() && root && !aElementId.IsEmpty()) {
-        nsIContent* eDebug =
-          nsContentUtils::MatchElementId(root, idAtom);
-        NS_ASSERTION(!eDebug,
-                     "We got null for |e| but MatchElementId found something?");
-      }
-#endif
-      // There is no element with the given id in the document, cache
-      // the fact that it's not in the document
-      entry->FlagIDNotInDocument();
-
-      return NS_OK;
-    }
-
-    // We found an element with a matching id, store that in the hash
-    if (NS_UNLIKELY(!entry->AddIdContent(e))) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-  }
-
-  return CallQueryInterface(e, aReturn);
-}
-
-NS_IMETHODIMP
 nsHTMLDocument::ImportNode(nsIDOMNode* aImportedNode,
                            PRBool aDeep,
                            nsIDOMNode** aReturn)
 {
   return nsDocument::ImportNode(aImportedNode, aDeep, aReturn);
 }
 
 NS_IMETHODIMP
@@ -2695,16 +2306,23 @@ nsHTMLDocument::GetElementsByTagNameNS(c
 
   if (!IsXHTML()) {
     ToLowerCase(tmp); // HTML elements are lower case internally.
   }
 
   return nsDocument::GetElementsByTagNameNS(aNamespaceURI, tmp, aReturn);
 }
 
+NS_IMETHODIMP
+nsHTMLDocument::GetElementById(const nsAString& aElementId,
+                               nsIDOMElement** aReturn)
+{
+  return nsDocument::GetElementById(aElementId, aReturn);
+}
+
 PRBool
 nsHTMLDocument::MatchNameAttribute(nsIContent* aContent, PRInt32 aNamespaceID,
                                    nsIAtom* aAtom, void* aData)
 {
   NS_PRECONDITION(aContent, "Must have content node to work with!");
   nsString* elementName = static_cast<nsString*>(aData);
   return aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
                                *elementName, eCaseMatters);
@@ -2993,17 +2611,17 @@ nsHTMLDocument::SetFgColor(const nsAStri
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds)
 {
   if (!mEmbeds) {
-    mEmbeds = new nsContentList(this, nsGkAtoms::embed, mDefaultNamespaceID);
+    mEmbeds = new nsContentList(this, nsGkAtoms::embed, GetDefaultNamespaceID());
     if (!mEmbeds) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
 
   *aEmbeds = mEmbeds;
   NS_ADDREF(*aEmbeds);
 
@@ -3097,398 +2715,112 @@ nsHTMLDocument::GetCompatMode(nsAString&
 NS_IMETHODIMP
 nsHTMLDocument::GetPlugins(nsIDOMHTMLCollection** aPlugins)
 {
   *aPlugins = nsnull;
 
   return GetEmbeds(aPlugins);
 }
 
-PR_STATIC_CALLBACK(PLDHashOperator)
-IdAndNameMapEntryRemoveCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
-                                PRUint32 number, void *arg)
-{
-  return PL_DHASH_REMOVE;
-}
-
-
-void
-nsHTMLDocument::InvalidateHashTables()
-{
-  PL_DHashTableEnumerate(&mIdAndNameHashTable, IdAndNameMapEntryRemoveCallback,
-                         nsnull);
-}
-
-static nsresult
-ReserveNameInHash(const char* aName, PLDHashTable *aHash)
-{
-  nsCOMPtr<nsIAtom> atom(do_GetAtom(aName));
-  NS_ENSURE_TRUE(atom, NS_ERROR_OUT_OF_MEMORY);
-  
-  IdAndNameMapEntry *entry =
-    static_cast<IdAndNameMapEntry *>
-               (PL_DHashTableOperate(aHash, atom, PL_DHASH_ADD));
-
-  NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
-
-  entry->mNameContentList = NAME_NOT_VALID;
-
-  return NS_OK;
-}
-
-// Pre-fill the name hash with names that are likely to be resolved in
-// this document to avoid walking the tree looking for elements with
-// these names.
-
-nsresult
-nsHTMLDocument::PrePopulateHashTables()
-{
-  nsresult rv = NS_OK;
-
-  rv = ReserveNameInHash("write", &mIdAndNameHashTable);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = ReserveNameInHash("writeln", &mIdAndNameHashTable);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = ReserveNameInHash("open", &mIdAndNameHashTable);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = ReserveNameInHash("close", &mIdAndNameHashTable);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = ReserveNameInHash("forms", &mIdAndNameHashTable);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = ReserveNameInHash("elements", &mIdAndNameHashTable);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = ReserveNameInHash("characterSet", &mIdAndNameHashTable);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = ReserveNameInHash("nodeType", &mIdAndNameHashTable);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = ReserveNameInHash("parentNode", &mIdAndNameHashTable);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = ReserveNameInHash("cookie", &mIdAndNameHashTable);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return rv;
-}
-
-static nsIAtom*
-IsNamedItem(nsIContent* aContent)
-{
-  // Only the content types reflected in Level 0 with a NAME
-  // attribute are registered. Images, layers and forms always get
-  // reflected up to the document. Applets and embeds only go
-  // to the closest container (which could be a form).
-  nsGenericHTMLElement* elm = nsGenericHTMLElement::FromContent(aContent);
-  if (!elm) {
-    return nsnull;
-  }
-
-  nsIAtom* tag = elm->Tag();
-  if (tag != nsGkAtoms::img    &&
-      tag != nsGkAtoms::form   &&
-      tag != nsGkAtoms::applet &&
-      tag != nsGkAtoms::embed  &&
-      tag != nsGkAtoms::object) {
-    return nsnull;
-  }
-
-  const nsAttrValue* val = elm->GetParsedAttr(nsGkAtoms::name);
-  if (val && val->Type() == nsAttrValue::eAtom) {
-    return val->GetAtomValue();
-  }
-
-  return nsnull;
-}
-
-nsresult
-nsHTMLDocument::UpdateNameTableEntry(nsIAtom* aName,
-                                     nsIContent *aContent)
-{
-  NS_ASSERTION(!IsXHTML(), 
-  "nsHTMLDocument::UpdateNameTableEntry Don't call me on an XHTML document!!!");
-
-  IdAndNameMapEntry *entry =
-    static_cast<IdAndNameMapEntry *>
-               (PL_DHashTableOperate(&mIdAndNameHashTable, aName,
-                                        PL_DHASH_LOOKUP));
-
-  if (PL_DHASH_ENTRY_IS_FREE(entry)) {
-    return NS_OK;
-  }
-
-  nsBaseContentList *list = entry->mNameContentList;
-
-  if (!list || list == NAME_NOT_VALID) {
-    return NS_OK;
-  }
-
-  // NOTE: this indexof is absolutely needed, since we don't flush
-  // content notifications when we do document.foo resolution.  So
-  // aContent may be in our list already and just now getting notified
-  // for!
-  if (list->IndexOf(aContent, PR_FALSE) < 0) {
-    list->AppendElement(aContent);
-  }
-
-  return NS_OK;
-}
-
-nsresult
-nsHTMLDocument::UpdateIdTableEntry(nsIAtom* aId, nsIContent *aContent)
-{
-  PRBool liveTable = IdTableIsLive();
-  PLDHashOperator op = liveTable ? PL_DHASH_ADD : PL_DHASH_LOOKUP;
-  IdAndNameMapEntry *entry =
-    static_cast<IdAndNameMapEntry *>
-               (PL_DHashTableOperate(&mIdAndNameHashTable, aId,
-                                        op));
-
-  NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
-
-  if (PL_DHASH_ENTRY_IS_BUSY(entry) &&
-      NS_UNLIKELY(!entry->AddIdContent(aContent))) {
-    // failed to update...
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  return NS_OK;
-}
-
-nsresult
-nsHTMLDocument::RemoveFromNameTable(nsIAtom* aName, nsIContent *aContent)
-{
-  NS_ASSERTION(!IsXHTML(), 
-  "nsHTMLDocument::RemoveFromNameTable Don't call me on an XHTML document!!!");
-
-  IdAndNameMapEntry *entry =
-    static_cast<IdAndNameMapEntry *>
-               (PL_DHashTableOperate(&mIdAndNameHashTable, aName,
-                                        PL_DHASH_LOOKUP));
-
-  if (PL_DHASH_ENTRY_IS_BUSY(entry) && entry->mNameContentList &&
-      entry->mNameContentList != NAME_NOT_VALID) {
-    entry->mNameContentList->RemoveElement(aContent);
-  }
-
-  return NS_OK;
-}
-
-nsresult
-nsHTMLDocument::RemoveFromIdTable(nsIContent *aContent)
-{
-  nsIAtom* id = aContent->GetID();
-
-  if (!id) {
-    return NS_OK;
-  }
-
-  IdAndNameMapEntry *entry =
-    static_cast<IdAndNameMapEntry *>
-               (PL_DHashTableOperate(&mIdAndNameHashTable, id,
-                                        PL_DHASH_LOOKUP));
-
-  if (PL_DHASH_ENTRY_IS_FREE(entry)) {
-    return NS_OK;
-  }
-
-  if (entry->RemoveIdContent(aContent)) {
-    PL_DHashTableRawRemove(&mIdAndNameHashTable, entry);
-  }
-
-  return NS_OK;
-}
-
-nsresult
-nsHTMLDocument::UnregisterNamedItems(nsIContent *aContent)
-{
-  if (aContent->IsNodeOfType(nsINode::eTEXT)) {
-    // Text nodes are not named items nor can they have children.
-    return NS_OK;
-  }
-
-  nsresult rv = NS_OK;
-
-  if (!IsXHTML()) {
-    nsIAtom* name = IsNamedItem(aContent);
-    if (name) {
-      rv = RemoveFromNameTable(name, aContent);
-
-      if (NS_FAILED(rv)) {
-        return rv;
-      }
-    }
-  }
-
-  rv = RemoveFromIdTable(aContent);
-
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  PRUint32 i, count = aContent->GetChildCount();
-
-  for (i = 0; i < count; ++i) {
-    UnregisterNamedItems(aContent->GetChildAt(i));
-  }
-
-  return NS_OK;
-}
-
-nsresult
-nsHTMLDocument::RegisterNamedItems(nsIContent *aContent)
-{
-  if (aContent->IsNodeOfType(nsINode::eTEXT)) {
-    // Text nodes are not named items nor can they have children.
-    return NS_OK;
-  }
-
-  if (!IsXHTML()) {
-    nsIAtom* name = IsNamedItem(aContent);
-    if (name) {
-      UpdateNameTableEntry(name, aContent);
-    }
-  }
-
-  nsIAtom* id = aContent->GetID();
-  if (id) {
-    nsresult rv = UpdateIdTableEntry(id, aContent);
-      
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-
-  PRUint32 i, count = aContent->GetChildCount();
-
-  for (i = 0; i < count; ++i) {
-    RegisterNamedItems(aContent->GetChildAt(i));
-  }
-
-  return NS_OK;
-}
-
 static void
 FindNamedItems(nsIAtom* aName, nsIContent *aContent,
-               IdAndNameMapEntry& aEntry, PRBool aIsXHTML)
+               nsIdentifierMapEntry* aEntry)
 {
-  NS_ASSERTION(aEntry.mNameContentList,
+  NS_ASSERTION(aEntry->HasNameContentList(),
                "Entry w/o content list passed to FindNamedItems()!");
-  NS_ASSERTION(aEntry.mNameContentList != NAME_NOT_VALID,
+  NS_ASSERTION(!aEntry->IsInvalidName(),
                "Entry that should never have a list passed to FindNamedItems()!");
 
   if (aContent->IsNodeOfType(nsINode::eTEXT)) {
     // Text nodes are not named items nor can they have children.
     return;
   }
 
-  nsAutoString value;
-
-  if (!aIsXHTML && aName == IsNamedItem(aContent)) {
-    aEntry.mNameContentList->AppendElement(aContent);
+  if (aName == nsContentUtils::IsNamedItem(aContent)) {
+    aEntry->AddNameContent(aContent);
   }
 
-  if (!aEntry.GetIdContent() &&
+  if (!aEntry->GetIdContent() &&
       // Maybe this node has the right id?
       aName == aContent->GetID()) {
-    aEntry.AddIdContent(aContent);
+    aEntry->AddIdContent(aContent);
   }
 
   PRUint32 i, count = aContent->GetChildCount();
-
   for (i = 0; i < count; ++i) {
-    FindNamedItems(aName, aContent->GetChildAt(i), aEntry, aIsXHTML);
+    FindNamedItems(aName, aContent->GetChildAt(i), aEntry);
   }
 }
 
 nsresult
 nsHTMLDocument::ResolveName(const nsAString& aName,
                             nsIDOMHTMLFormElement *aForm,
                             nsISupports **aResult)
 {
   *aResult = nsnull;
 
-  if (IsXHTML()) {
-    // We don't dynamically resolve names on XHTML documents.
-
+  if (!mIsRegularHTML) {
+    // We don't dynamically resolve names on non-HTML documents.
     return NS_OK;
   }
 
   nsCOMPtr<nsIAtom> name(do_GetAtom(aName));
 
   // We have built a table and cache the named items. The table will
   // be updated as content is added and removed.
-
-  IdAndNameMapEntry *entry =
-    static_cast<IdAndNameMapEntry *>
-               (PL_DHashTableOperate(&mIdAndNameHashTable, name,
-                                     PL_DHASH_ADD));
+  nsIdentifierMapEntry *entry = mIdentifierMap.PutEntry(name);
   NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
 
-  if (entry->mNameContentList == NAME_NOT_VALID) {
+  if (entry->IsInvalidName()) {
     // There won't be any named items by this name -- it's reserved
     return NS_OK;
   }
 
   // Now we know we _might_ have items.  Before looking at
   // entry->mNameContentList, make sure to flush out content (see
   // bug 69826).
   // This is a perf killer while the document is loading!
 
   // Make sure to stash away the current generation so we can check whether the
   // table changes when we flush.
-  PRUint32 generation = mIdAndNameHashTable.generation;
+  PRUint32 generation = mIdentifierMap.GetGeneration();
   
   // If we already have an entry->mNameContentList, we need to flush out
   // notifications too, so that it will get updated properly.
-  FlushPendingNotifications(entry->mNameContentList ?
+  FlushPendingNotifications(entry->HasNameContentList() ?
                             Flush_ContentAndNotify : Flush_Content);
 
-  if (generation != mIdAndNameHashTable.generation) {
+  if (generation != mIdentifierMap.GetGeneration()) {
     // Table changed, so the entry pointer is no longer valid; look up the
     // entry again, adding if necessary (the adding may be necessary in case
     // the flush actually deleted entries).
-    entry =
-      static_cast<IdAndNameMapEntry *>
-                 (PL_DHashTableOperate(&mIdAndNameHashTable, name,
-                                       PL_DHASH_ADD));
+    entry = mIdentifierMap.PutEntry(name);
     NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
   }
-    
-
-  nsBaseContentList *list = entry->mNameContentList;
-
-  if (!list) {
+
+  if (!entry->HasNameContentList()) {
 #ifdef DEBUG_jst
     {
       printf ("nsHTMLDocument name cache miss for name '%s'\n",
               NS_ConvertUTF16toUTF8(aName).get());
     }
 #endif
 
-    list = new nsBaseContentList();
-    NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
-
-    entry->mNameContentList = list;
-    NS_ADDREF(entry->mNameContentList);
+    nsresult rv = entry->CreateNameContentList();
+    if (NS_FAILED(rv))
+      return rv;
 
     nsIContent* root = GetRootContent();
     if (root && !aName.IsEmpty()) {
-      // We'll never get here if !IsXHTML(), so we can just pass
-      // PR_FALSE to FindNamedItems().
-      FindNamedItems(name, root, *entry, PR_FALSE);
+      FindNamedItems(name, root, entry);
     }
   }
 
+  nsBaseContentList *list = entry->GetNameContentList();
+
   PRUint32 length;
   list->GetLength(&length);
 
   if (length > 0) {
     if (length == 1) {
       // Only one element in the list, return the element instead of
       // returning the list
 
@@ -3547,63 +2879,89 @@ nsHTMLDocument::ResolveName(const nsAStr
 
   // No named items were found, see if there's one registerd by id for
   // aName. If we get this far, FindNamedItems() will have been called
   // for aName, so we're guaranteed that if there is an element with
   // the id aName, it'll be entry's IdContent.
 
   nsIContent *e = entry->GetIdContent();
 
-  if (e && e != ID_NOT_IN_DOCUMENT && e->IsNodeOfType(nsINode::eHTML)) {
+  if (e && e->IsNodeOfType(nsINode::eHTML)) {
     nsIAtom *tag = e->Tag();
 
     if ((tag == nsGkAtoms::embed  ||
          tag == nsGkAtoms::img    ||
          tag == nsGkAtoms::object ||
          tag == nsGkAtoms::applet) &&
         (!aForm || nsContentUtils::BelongsInForm(aForm, e))) {
       NS_ADDREF(*aResult = e);
     }
   }
 
   return NS_OK;
 }
 
+// Pre-fill the name hash with names that are likely to be resolved in
+// this document to avoid walking the tree looking for elements with
+// these names.
+
+nsresult
+nsHTMLDocument::PrePopulateIdentifierMap()
+{
+  static const char names[][13] = {
+    "write", "writeln", "open", "close", "forms", "elements",
+    "characterSet", "nodeType", "parentNode", "cookie"
+  };
+
+  for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(names); ++i) {
+    nsCOMPtr<nsIAtom> atom(do_GetAtom(names[i]));
+    NS_ENSURE_TRUE(atom, NS_ERROR_OUT_OF_MEMORY);
+  
+    nsIdentifierMapEntry* entry = mIdentifierMap.PutEntry(atom);
+    NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
+
+    entry->SetInvalidName();
+  }
+
+  return NS_OK;
+}
+
 //----------------------------
 
 /* virtual */ nsIContent*
 nsHTMLDocument::GetBodyContentExternal()
 {
   return GetBodyContent();
 }
 
 nsIContent*
+nsHTMLDocument::GetHtmlContent()
+{
+  nsIContent* rootContent = GetRootContent();
+  if (rootContent && rootContent->Tag() == nsGkAtoms::html &&
+      rootContent->IsNodeOfType(nsINode::eHTML))
+    return rootContent;
+  return nsnull;
+}
+
+nsIContent*
 nsHTMLDocument::GetBodyContent()
 {
-  // Loop backwards because any non-elements, such as doctypes and PIs
-  // are likely to appear before the root element.
-  PRUint32 i;
-  for (i = mChildren.ChildCount(); i > 0; --i) {
-    nsIContent* html = mChildren.ChildAt(i - 1);
-    if (html->Tag() == nsGkAtoms::html &&
-        html->IsNodeOfType(nsINode::eHTML)) {
-
-      // Look for body inside html
-      for (i = html->GetChildCount(); i > 0; --i) {
-        nsIContent* body = html->GetChildAt(i - 1);
-        if (body->Tag() == nsGkAtoms::body &&
-            body->IsNodeOfType(nsINode::eHTML)) {
-          return body;
-        }
-      }
-
-      break;
-    }
+  nsIContent* html = GetHtmlContent();
+  if (!html)
+    return nsnull;
+
+  // Look for body inside html. This needs to run forwards to find
+  // the first body element.
+  for (PRUint32 i = 0; i < html->GetChildCount(); ++i) {
+    nsIContent* body = html->GetChildAt(i);
+    if (body->Tag() == nsGkAtoms::body &&
+        body->IsNodeOfType(nsINode::eHTML))
+      return body;
   }
-
   return nsnull;
 }
 
 // forms related stuff
 
 NS_IMETHODIMP
 nsHTMLDocument::GetForms(nsIDOMHTMLCollection** aForms)
 {
@@ -3614,17 +2972,17 @@ nsHTMLDocument::GetForms(nsIDOMHTMLColle
   NS_ADDREF(*aForms = forms);
   return NS_OK;
 }
 
 nsContentList*
 nsHTMLDocument::GetForms()
 {
   if (!mForms)
-    mForms = new nsContentList(this, nsGkAtoms::form, mDefaultNamespaceID);
+    mForms = new nsContentList(this, nsGkAtoms::form, GetDefaultNamespaceID());
 
   return mForms;
 }
 
 static PRBool MatchFormControls(nsIContent* aContent, PRInt32 aNamespaceID,
                                 nsIAtom* aAtom, void* aData)
 {
   return aContent->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL);
@@ -3846,52 +3204,48 @@ DocAllResultMatch(nsIContent* aContent, 
 }
 
 
 nsresult
 nsHTMLDocument::GetDocumentAllResult(const nsAString& aID, nsISupports** aResult)
 {
   *aResult = nsnull;
 
-  PLDHashOperator op = IdTableIsLive() ? PL_DHASH_LOOKUP : PL_DHASH_ADD;
-
   nsCOMPtr<nsIAtom> id = do_GetAtom(aID);
-  IdAndNameMapEntry *entry =
-    static_cast<IdAndNameMapEntry *>
-               (PL_DHashTableOperate(&mIdAndNameHashTable, id, op));
-  NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
-
-  // If we did a lookup and it failed, there are no items with this id
-  if (PL_DHASH_ENTRY_IS_FREE(entry)) {
-    NS_ASSERTION(IdTableIsLive(), "should have gotten a busy entry");
-
-    return NS_OK;
+  nsIdentifierMapEntry *entry;
+  if (IdTableIsLive()) {
+    entry = mIdentifierMap.GetEntry(id);
+    // If we did a lookup and it failed, there are no items with this id
+    if (!entry)
+      return NS_OK;
+  } else {
+    entry = mIdentifierMap.PutEntry(id);
+    NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
   }
 
   nsIContent* root = GetRootContent();
   if (!root) {
     return NS_OK;
   }
 
-  if (!entry->mDocAllList) {
-    entry->mDocAllList = new nsContentList(root, DocAllResultMatch,
-                                           nsnull, nsnull, PR_TRUE, id);
-    NS_ENSURE_TRUE(entry->mDocAllList, NS_ERROR_OUT_OF_MEMORY);
+  nsRefPtr<nsContentList> docAllList = entry->GetDocAllList();
+  if (!docAllList) {
+    docAllList = new nsContentList(root, DocAllResultMatch,
+                                   nsnull, nsnull, PR_TRUE, id);
+    NS_ENSURE_TRUE(docAllList, NS_ERROR_OUT_OF_MEMORY);
+    entry->SetDocAllList(docAllList);
   }
 
-  nsRefPtr<nsContentList> docAllList = entry->mDocAllList;
-
   // Check if there are more than 1 entries. Do this by getting the second one
   // rather than the length since getting the length always requires walking
   // the entire document.
 
   nsIContent* cont = docAllList->Item(1, PR_TRUE);
   if (cont) {
     NS_ADDREF(*aResult = static_cast<nsIDOMNodeList*>(docAllList));
-
     return NS_OK;
   }
 
   // There's only 0 or 1 items. Return the first one or null.
   NS_IF_ADDREF(*aResult = docAllList->Item(0, PR_TRUE));
 
   return NS_OK;
 }
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -69,17 +69,16 @@ class nsICacheEntryDescriptor;
 
 class nsHTMLDocument : public nsDocument,
                        public nsIHTMLDocument,
                        public nsIDOMHTMLDocument,
                        public nsIDOMNSHTMLDocument
 {
 public:
   nsHTMLDocument();
-  virtual ~nsHTMLDocument();
   virtual nsresult Init();
 
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
 
   NS_IMETHOD_(nsrefcnt) AddRef(void);
   NS_IMETHOD_(nsrefcnt) Release(void);
 
   virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
@@ -118,28 +117,18 @@ public:
 
   virtual PRBool GetIsFrameset() { return mIsFrameset; }
   virtual void SetIsFrameset(PRBool aFrameset) { mIsFrameset = aFrameset; }
 
   virtual NS_HIDDEN_(nsContentList*) GetForms();
  
   virtual NS_HIDDEN_(nsContentList*) GetFormControls();
  
-  virtual void AttributeWillChange(nsIContent* aChild,
-                                   PRInt32 aNameSpaceID,
-                                   nsIAtom* aAttribute);
-
   virtual PRBool IsCaseSensitive();
 
-  // nsIMutationObserver
-  NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
-  NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
-  NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
-  NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
-
   // nsIDOMDocument interface
   NS_DECL_NSIDOMDOCUMENT
 
   // nsIDOM3Document interface
   NS_IMETHOD GetXmlEncoding(nsAString& aXmlVersion);
   NS_IMETHOD GetXmlStandalone(PRBool *aXmlStandalone);
   NS_IMETHOD SetXmlStandalone(PRBool aXmlStandalone);
   NS_IMETHOD GetXmlVersion(nsAString& aXmlVersion);
@@ -173,30 +162,30 @@ public:
                                nsIDOMNodeList **_retval);
   virtual nsresult GetDocumentAllResult(const nsAString& aID,
                                         nsISupports** aResult);
 
   // nsIDOMNSHTMLDocument interface
   NS_DECL_NSIDOMNSHTMLDOCUMENT
 
   virtual nsresult ResolveName(const nsAString& aName,
-                         nsIDOMHTMLFormElement *aForm,
-                         nsISupports **aResult);
+                               nsIDOMHTMLFormElement *aForm,
+                               nsISupports **aResult);
 
   virtual void ScriptLoading(nsIScriptElement *aScript);
   virtual void ScriptExecuted(nsIScriptElement *aScript);
 
   virtual void AddedForm();
   virtual void RemovedForm();
   virtual PRInt32 GetNumFormsSynchronous();
   virtual void TearingDownEditor(nsIEditor *aEditor);
 
   PRBool IsXHTML()
   {
-    return mDefaultNamespaceID == kNameSpaceID_XHTML;
+    return !mIsRegularHTML;
   }
 
 #ifdef DEBUG
   virtual nsresult CreateElem(nsIAtom *aName, nsIAtom *aPrefix,
                               PRInt32 aNamespaceID,
                               PRBool aDocumentDefaultType,
                               nsIContent** aResult);
 #endif
@@ -222,54 +211,51 @@ public:
   }
 
   virtual nsresult SetEditingState(EditingState aState);
 
 protected:
   nsresult GetBodySize(PRInt32* aWidth,
                        PRInt32* aHeight);
 
-  nsresult RegisterNamedItems(nsIContent *aContent);
-  nsresult UnregisterNamedItems(nsIContent *aContent);
-  nsresult UpdateNameTableEntry(nsIAtom* aName, nsIContent *aContent);
-  nsresult UpdateIdTableEntry(nsIAtom* aId, nsIContent *aContent);
-  nsresult RemoveFromNameTable(nsIAtom* aName, nsIContent *aContent);
-  nsresult RemoveFromIdTable(nsIContent *aContent);
-
-  void InvalidateHashTables();
-  nsresult PrePopulateHashTables();
+  nsresult PrePopulateIdentifierMap();
 
   nsIContent *MatchId(nsIContent *aContent, const nsAString& aId);
 
   static PRBool MatchLinks(nsIContent *aContent, PRInt32 aNamespaceID,
                            nsIAtom* aAtom, void* aData);
   static PRBool MatchAnchors(nsIContent *aContent, PRInt32 aNamespaceID,
                              nsIAtom* aAtom, void* aData);
   static PRBool MatchNameAttribute(nsIContent* aContent, PRInt32 aNamespaceID,
                                    nsIAtom* aAtom, void* aData);
 
   static void DocumentWriteTerminationFunc(nsISupports *aRef);
 
+  // Get the root <html> element, or return null if there isn't one (e.g.
+  // if the root isn't <html>)
+  nsIContent* GetHtmlContent();
+  // Get the canonical <body> element, or return null if there isn't one (e.g.
+  // if the root isn't <html> or if the <body> isn't there)
   nsIContent* GetBodyContent();
 
   void GetDomainURI(nsIURI **uri);
 
   nsresult WriteCommon(const nsAString& aText,
                        PRBool aNewlineTerminate);
   nsresult ScriptWriteCommon(PRBool aNewlineTerminate);
   nsresult OpenCommon(const nsACString& aContentType, PRBool aReplace);
 
   nsresult CreateAndAddWyciwygChannel(void);
   nsresult RemoveWyciwygChannel(void);
 
   void *GenerateParserKey(void);
 
-  PRInt32 GetDefaultNamespaceID() const
+  virtual PRInt32 GetDefaultNamespaceID() const
   {
-    return mDefaultNamespaceID;
+    return mIsRegularHTML ? kNameSpaceID_None : kNameSpaceID_XHTML;
   }
 
   nsCOMArray<nsIDOMHTMLMapElement> mImageMaps;
 
   nsCOMPtr<nsIDOMHTMLCollection> mImages;
   nsCOMPtr<nsIDOMHTMLCollection> mApplets;
   nsCOMPtr<nsIDOMHTMLCollection> mEmbeds;
   nsCOMPtr<nsIDOMHTMLCollection> mLinks;
@@ -337,39 +323,16 @@ protected:
 
   // Load flags of the document's channel
   PRUint32 mLoadFlags;
 
   PRPackedBool mIsFrameset;
 
   PRPackedBool mTooDeepWriteRecursion;
 
-  PRBool IdTableIsLive() const {
-    // live if we've had over 63 misses
-    return (mIdMissCount & 0x40) != 0;
-  }
-
-  PRBool IdTableShouldBecomeLive() {
-    NS_ASSERTION(!IdTableIsLive(),
-                 "Shouldn't be called if table is already live!");
-    ++mIdMissCount;
-    return IdTableIsLive();
-  }
-
-  PRUint8 mIdMissCount;
-
-  /* mIdAndNameHashTable works as follows for IDs:
-   * 1) Attribute changes affect the table immediately (removing and adding
-   *    entries as needed).
-   * 2) Removals from the DOM affect the table immediately
-   * 3) Additions to the DOM always update existing entries, but only add new
-   *    ones if IdTableIsLive() is true.
-   */
-  PLDHashTable mIdAndNameHashTable;
-
   nsCOMPtr<nsIWyciwygChannel> mWyciwygChannel;
 
   /* Midas implementation */
   nsresult   GetMidasCommandManager(nsICommandManager** aCommandManager);
 
   nsCOMPtr<nsICommandManager> mMidasCommandManager;
 
   nsresult TurnEditingOff();
@@ -377,19 +340,13 @@ protected:
 
   PRUint32 mContentEditableCount;
   EditingState mEditingState;
 
   nsresult   DoClipboardSecurityCheck(PRBool aPaste);
   static jsval       sCutCopyInternal_id;
   static jsval       sPasteInternal_id;
 
-  // kNameSpaceID_None for good ol' HTML documents, and
-  // kNameSpaceID_XHTML for spiffy new XHTML documents.
-  // XXXbz should this be reset if someone manually calls
-  // SetContentType() on this document?
-  PRInt32 mDefaultNamespaceID;
-
   // Parser used for constructing document fragments.
   nsCOMPtr<nsIParser> mFragmentParser;
 };
 
 #endif /* nsHTMLDocument_h___ */
--- a/content/xml/document/src/nsXMLDocument.cpp
+++ b/content/xml/document/src/nsXMLDocument.cpp
@@ -558,46 +558,16 @@ nsXMLDocument::EndLoad()
 NS_IMETHODIMP    
 nsXMLDocument::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
 {
   return nsNodeUtils::CloneNodeImpl(this, aDeep, aReturn);
 }
  
 // nsIDOMDocument interface
 
-NS_IMETHODIMP
-nsXMLDocument::GetElementById(const nsAString& aElementId,
-                              nsIDOMElement** aReturn)
-{
-  NS_ENSURE_ARG_POINTER(aReturn);
-  *aReturn = nsnull;
-
-  if (!CheckGetElementByIdArg(aElementId))
-    return NS_OK;
-
-  // If we tried to load a document and something went wrong, we might not have
-  // root content. This can happen when you do document.load() and the document
-  // to load is not XML, for example.
-  nsIContent* root = GetRootContent();
-  if (!root)
-    return NS_OK;
-
-  // XXX For now, we do a brute force search of the content tree.
-  // We should come up with a more efficient solution.
-  // Note that content is *not* refcounted here, so do *not* release it!
-  nsIContent *content =
-    nsContentUtils::MatchElementId(root, aElementId);
-
-  if (!content) {
-    return NS_OK;
-  }
-
-  return CallQueryInterface(content, aReturn);
-}
-
 nsresult
 nsXMLDocument::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
 {
   NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
                "Can't import this document into another document!");
 
   PRBool hasHadScriptObject = PR_TRUE;
   nsIScriptGlobalObject* scriptObject =
--- a/content/xml/document/src/nsXMLDocument.h
+++ b/content/xml/document/src/nsXMLDocument.h
@@ -73,20 +73,16 @@ public:
                                      PRBool aReset = PR_TRUE,
                                      nsIContentSink* aSink = nsnull);
 
   virtual void EndLoad();
 
   // nsIDOMNode interface
   NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn);
 
-  // nsIDOMDocument interface
-  NS_IMETHOD GetElementById(const nsAString& aElementId,
-                            nsIDOMElement** aReturn);
-
   // nsIInterfaceRequestor
   NS_DECL_NSIINTERFACEREQUESTOR
 
   // nsIHTTPEventSink
   NS_DECL_NSICHANNELEVENTSINK
 
   // nsIDOMXMLDocument
   NS_DECL_NSIDOMXMLDOCUMENT
--- a/content/xul/document/public/nsIXULDocument.h
+++ b/content/xul/document/public/nsIXULDocument.h
@@ -42,20 +42,20 @@
 #include "nsString.h"
 #include "nsCOMArray.h"
 
 class nsIXULTemplateBuilder;
 class nsIContent;
 class nsIScriptGlobalObjectOwner;
 
 
-// {57314526-f749-4cf0-b6b6-3723eba21480}
+// {AF676EDD-1FB9-4C75-9B1F-CB4E02E1C779}
 #define NS_IXULDOCUMENT_IID \
-{ 0x57314526, 0xf749, 0x4cf0, \
-  { 0xb6, 0xb6, 0x37, 0x23, 0xeb, 0xa2, 0x14, 0x80 } }
+{ 0xaf676edd, 0x1fb9, 0x4c75, \
+  { 0x9b, 0x1f, 0xcb, 0x4e, 0x02, 0xe1, 0xc7, 0x79 } }
 
 
 /*
  * An XUL-specific extension to nsIDocument. Includes methods for
  * setting the root resource of the document content model, a factory
  * method for constructing the children of a node, etc.
  */
 class nsIXULDocument : public nsISupports
@@ -64,26 +64,21 @@ public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXULDOCUMENT_IID)
 
   // The resource-to-element map is a one-to-many mapping of RDF
   // resources to content elements.
 
   /**
    * Add an entry to the ID-to-element map.
    */
-  NS_IMETHOD AddElementForID(const nsAString& aID, nsIContent* aElement) = 0;
+  NS_IMETHOD AddElementForID(nsIContent* aElement) = 0;
 
   /**
-   * Remove an entry from the ID-to-element map.
-   */
-  NS_IMETHOD RemoveElementForID(const nsAString& aID, nsIContent* aElement) = 0;
-
-  /**
-   * Get the elements for a particular resource in the resource-to-element
-   * map. The nsCOMArray will be truncated and filled in with
+   * Get the elements for a particular resource --- all elements whose 'id'
+   * or 'ref' is aID. The nsCOMArray will be truncated and filled in with
    * nsIContent pointers.
    */
   NS_IMETHOD GetElementsForID(const nsAString& aID, nsCOMArray<nsIContent>& aElements) = 0;
 
   /**
    * Get the nsIScriptGlobalObjectOwner for this document.
    */
   NS_IMETHOD GetScriptGlobalObjectOwner(nsIScriptGlobalObjectOwner** aGlobalOwner) = 0;
--- a/content/xul/document/src/Makefile.in
+++ b/content/xul/document/src/Makefile.in
@@ -72,17 +72,16 @@ REQUIRES	= xpcom \
 		  appshell \
 		  util \
 		  $(NULL)
 
 CPPSRCS		= nsXULControllers.cpp
 
 ifdef MOZ_XUL
 CPPSRCS		+= \
-		nsElementMap.cpp \
 		nsXULCommandDispatcher.cpp \
 		nsXULContentSink.cpp \
 		nsXULDocument.cpp \
 		nsXULPrototypeCache.cpp \
 		nsXULPrototypeDocument.cpp \
 		$(NULL)
 endif
 
deleted file mode 100644
--- a/content/xul/document/src/nsElementMap.cpp
+++ /dev/null
@@ -1,431 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Chris Waterson <waterson@netscape.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/*
-
-   Maps IDs to elements.
-
-
-   To turn on logging for this module, set:
-
-     NS_PR_LOG_MODULES nsElementMap:5
-
- */
-
-#include "nsCOMPtr.h"
-#include "nsCRT.h"
-#include "nsElementMap.h"
-#include "nsString.h"
-#include "nsIAtom.h"
-#include "nsReadableUtils.h"
-#include "prlog.h"
-#include "prbit.h"
-
-#ifdef PR_LOGGING
-static PRLogModuleInfo* gMapLog;
-#endif
-
-static void* PR_CALLBACK AllocTable(void* aPool, PRSize aSize)
-{
-    return new char[aSize];
-}
-
-static void PR_CALLBACK FreeTable(void* aPool, void* aItem)
-{
-    delete[] static_cast<char*>(aItem);
-}
-
-static PLHashEntry* PR_CALLBACK AllocEntry(void* aPool, const void* aKey)
-{
-    nsFixedSizeAllocator* pool = static_cast<nsFixedSizeAllocator*>(aPool);
-    PLHashEntry* entry = static_cast<PLHashEntry*>(pool->Alloc(sizeof(PLHashEntry)));
-    return entry;
-}
-
-static void PR_CALLBACK FreeEntry(void* aPool, PLHashEntry* aEntry, PRUintn aFlag) 
-{
-    nsFixedSizeAllocator* pool = static_cast<nsFixedSizeAllocator*>(aPool);
-    if (aFlag == HT_FREE_ENTRY)
-        pool->Free(aEntry, sizeof(PLHashEntry));
-}
-
-PLHashAllocOps nsElementMap::gAllocOps = {
-    AllocTable, FreeTable, AllocEntry, FreeEntry };
-
-
-nsElementMap::nsElementMap()
-{
-    MOZ_COUNT_CTOR(nsElementMap);
-
-    // Create a table for mapping IDs to elements in the content tree.
-    static const size_t kBucketSizes[] = {
-        sizeof(PLHashEntry), sizeof(ContentListItem)
-    };
-
-    static const PRInt32 kNumBuckets = sizeof(kBucketSizes) / sizeof(size_t);
-
-    static const PRInt32 kInitialNumElements = 64;
-
-    // Per news://news.mozilla.org/39BEC105.5090206%40netscape.com
-    static const PRInt32 kInitialPoolSize = 512;
-
-    mPool.Init("nsElementMap", kBucketSizes, kNumBuckets, kInitialPoolSize);
-
-    mMap = PL_NewHashTable(kInitialNumElements,
-                           Hash,
-                           Compare,
-                           PL_CompareValues,
-                           &gAllocOps,
-                           &mPool);
-
-    NS_ASSERTION(mMap != nsnull, "could not create hash table for resources");
-
-#ifdef PR_LOGGING
-    if (! gMapLog)
-        gMapLog = PR_NewLogModule("nsElementMap");
-
-
-    PR_LOG(gMapLog, PR_LOG_NOTICE,
-           ("xulelemap(%p) created", this));
-#endif
-}
-
-nsElementMap::~nsElementMap()
-{
-    MOZ_COUNT_DTOR(nsElementMap);
-
-    if (mMap) {
-        PL_HashTableEnumerateEntries(mMap, ReleaseContentList, this);
-        PL_HashTableDestroy(mMap);
-    }
-
-    PR_LOG(gMapLog, PR_LOG_NOTICE,
-           ("xulelemap(%p) destroyed", this));
-}
-
-
-PRIntn
-nsElementMap::ReleaseContentList(PLHashEntry* aHashEntry, PRIntn aIndex, void* aClosure)
-{
-    nsElementMap* self = static_cast<nsElementMap*>(aClosure);
-
-    PRUnichar* id =
-        reinterpret_cast<PRUnichar*>(const_cast<void*>(aHashEntry->key));
-
-    nsMemory::Free(id);
-        
-    ContentListItem* head =
-        reinterpret_cast<ContentListItem*>(aHashEntry->value);
-
-    while (head) {
-        ContentListItem* doomed = head;
-        head = head->mNext;
-        ContentListItem::Destroy(self->mPool, doomed);
-    }
-
-    return HT_ENUMERATE_NEXT;
-}
-
-
-nsresult
-nsElementMap::Add(const nsAString& aID, nsIContent* aContent)
-{
-    NS_PRECONDITION(mMap != nsnull, "not initialized");
-    if (! mMap)
-        return NS_ERROR_NOT_INITIALIZED;
-
-    const nsPromiseFlatString& flatID = PromiseFlatString(aID);
-    const PRUnichar *id = flatID.get();
-
-    ContentListItem* head =
-        static_cast<ContentListItem*>(PL_HashTableLookup(mMap, id));
-
-    if (! head) {
-        head = ContentListItem::Create(mPool, aContent);
-        if (! head)
-            return NS_ERROR_OUT_OF_MEMORY;
-
-        PRUnichar* key = ToNewUnicode(aID);
-        if (! key)
-            return NS_ERROR_OUT_OF_MEMORY;
-
-        PL_HashTableAdd(mMap, key, head);
-    }
-    else {
-        while (1) {
-            if (head->mContent.get() == aContent) {
-                // This can happen if an element that was created via
-                // frame construction code is then "appended" to the
-                // content model with aNotify == PR_TRUE. If you see
-                // this warning, it's an indication that you're
-                // unnecessarily notifying the frame system, and
-                // potentially causing unnecessary reflow.
-                //NS_ERROR("element was already in the map");
-#ifdef PR_LOGGING
-                if (PR_LOG_TEST(gMapLog, PR_LOG_NOTICE)) {
-                    const char *tagname;
-                    aContent->Tag()->GetUTF8String(&tagname);
-
-                    nsCAutoString aidC; 
-                    aidC.AssignWithConversion(id, aID.Length());
-                    PR_LOG(gMapLog, PR_LOG_NOTICE,
-                           ("xulelemap(%p) dup    %s[%p] <-- %s\n",
-                            this,
-                            tagname,
-                            aContent,
-                            aidC.get()));
-                }
-#endif
-
-                return NS_OK;
-            }
-            if (! head->mNext)
-                break;
-
-            head = head->mNext;
-        }
-
-        head->mNext = nsElementMap::ContentListItem::Create(mPool, aContent);
-        if (! head->mNext)
-            return NS_ERROR_OUT_OF_MEMORY;
-    }
-
-#ifdef PR_LOGGING
-    if (PR_LOG_TEST(gMapLog, PR_LOG_NOTICE)) {
-        const char *tagname;
-        aContent->Tag()->GetUTF8String(&tagname);
-
-        nsCAutoString aidC; 
-        aidC.AssignWithConversion(id, aID.Length());
-        PR_LOG(gMapLog, PR_LOG_NOTICE,
-               ("xulelemap(%p) add    %s[%p] <-- %s\n",
-                this,
-                tagname,
-                aContent,
-                aidC.get()));
-    }
-#endif
-
-    return NS_OK;
-}
-
-
-nsresult
-nsElementMap::Remove(const nsAString& aID, nsIContent* aContent)
-{
-    NS_PRECONDITION(mMap != nsnull, "not initialized");
-    if (! mMap)
-        return NS_ERROR_NOT_INITIALIZED;
-
-    const nsPromiseFlatString& flatID = PromiseFlatString(aID);
-    const PRUnichar *id = flatID.get();
-
-#ifdef PR_LOGGING
-    if (PR_LOG_TEST(gMapLog, PR_LOG_NOTICE)) {
-        const char *tagname;
-        aContent->Tag()->GetUTF8String(&tagname);
-
-        nsCAutoString aidC; 
-        aidC.AssignWithConversion(id);
-        PR_LOG(gMapLog, PR_LOG_NOTICE,
-               ("xulelemap(%p) remove  %s[%p] <-- %s\n",
-                this,
-                tagname,
-                aContent,
-                aidC.get()));
-    }
-#endif
-
-    PLHashEntry** hep = PL_HashTableRawLookup(mMap,
-                                              Hash(id),
-                                              id);
-
-    // XXX Don't comment out this assert: if you get here, something
-    // has gone dreadfully, horribly wrong. Curse. Scream. File a bug
-    // against waterson@netscape.com.
-    NS_ASSERTION(hep != nsnull && *hep != nsnull, "attempt to remove an element that was never added");
-    if (!hep || !*hep)
-        return NS_OK;
-
-    ContentListItem* head = reinterpret_cast<ContentListItem*>((*hep)->value);
-
-    if (head->mContent.get() == aContent) {
-        ContentListItem* next = head->mNext;
-        if (next) {
-            (*hep)->value = next;
-        }
-        else {
-            // It was the last reference in the table
-            PRUnichar* key = reinterpret_cast<PRUnichar*>(const_cast<void*>((*hep)->key));
-            PL_HashTableRawRemove(mMap, hep, *hep);
-            nsMemory::Free(key);
-        }
-        ContentListItem::Destroy(mPool, head);
-    }
-    else {
-        ContentListItem* item = head->mNext;
-        while (item) {
-            if (item->mContent.get() == aContent) {
-                head->mNext = item->mNext;
-                ContentListItem::Destroy(mPool, item);
-                break;
-            }
-            head = item;
-            item = item->mNext;
-        }
-    }
-
-    return NS_OK;
-}
-
-
-
-nsresult
-nsElementMap::Find(const nsAString& aID, nsCOMArray<nsIContent>& aResults)
-{
-    NS_PRECONDITION(mMap != nsnull, "not initialized");
-    if (! mMap)
-        return NS_ERROR_NOT_INITIALIZED;
-
-    aResults.Clear();
-    ContentListItem* item =
-        reinterpret_cast<ContentListItem*>(PL_HashTableLookup(mMap, (const PRUnichar *)PromiseFlatString(aID).get()));
-
-    while (item) {
-        aResults.AppendObject(item->mContent);
-        item = item->mNext;
-    }
-    return NS_OK;
-}
-
-
-nsresult
-nsElementMap::FindFirst(const nsAString& aID, nsIContent** aResult)
-{
-    NS_PRECONDITION(mMap != nsnull, "not initialized");
-    if (! mMap)
-        return NS_ERROR_NOT_INITIALIZED;
-
-    ContentListItem* item =
-        reinterpret_cast<ContentListItem*>(PL_HashTableLookup(mMap, (const PRUnichar *)PromiseFlatString(aID).get()));
-
-    if (item) {
-        *aResult = item->mContent;
-        NS_ADDREF(*aResult);
-    }
-    else {
-        *aResult = nsnull;
-    }
-
-    return NS_OK;
-}
-
-nsresult
-nsElementMap::Enumerate(nsElementMapEnumerator aEnumerator, void* aClosure)
-{
-    EnumerateClosure closure = { this, aEnumerator, aClosure };
-    PL_HashTableEnumerateEntries(mMap, EnumerateImpl, &closure);
-    return NS_OK;
-}
-
-
-PRIntn
-nsElementMap::EnumerateImpl(PLHashEntry* aHashEntry, PRIntn aIndex, void* aClosure)
-{
-    // This routine will be called once for each key in the
-    // hashtable. It will in turn call the enumerator that the user
-    // has passed in via Enumerate() once for each element that's been
-    // mapped to this ID.
-    EnumerateClosure* closure = reinterpret_cast<EnumerateClosure*>(aClosure);
-
-    const PRUnichar* id =
-        reinterpret_cast<const PRUnichar*>(aHashEntry->key);
-
-    // 'link' holds a pointer to the previous element's link field.
-    ContentListItem** link = 
-        reinterpret_cast<ContentListItem**>(&aHashEntry->value);
-
-    ContentListItem* item = *link;
-
-    // Iterate through each content node that's been mapped to this ID
-    while (item) {
-        ContentListItem* current = item;
-        item = item->mNext;
-        PRIntn result = (*closure->mEnumerator)(id, current->mContent, closure->mClosure);
-
-        if (result == HT_ENUMERATE_REMOVE) {
-            // If the user wants to remove the current, then deal.
-            *link = item;
-            ContentListItem::Destroy(closure->mSelf->mPool, current);
-
-            if ((! *link) && (link == reinterpret_cast<ContentListItem**>(&aHashEntry->value))) {
-                // It's the last content node that was mapped to this
-                // ID. Unhash it.
-                PRUnichar* key = const_cast<PRUnichar*>(id);
-                nsMemory::Free(key);
-                return HT_ENUMERATE_REMOVE;
-            }
-        }
-        else {
-            link = &current->mNext;
-        }
-    }
-
-    return HT_ENUMERATE_NEXT;
-}
-
-
-PLHashNumber
-nsElementMap::Hash(const void* aKey)
-{
-    PLHashNumber result = 0;
-    const PRUnichar* s = reinterpret_cast<const PRUnichar*>(aKey);
-    while (*s != nsnull) {
-        result = PR_ROTATE_LEFT32(result, 4) ^ *s;
-        ++s;
-    }
-    return result;
-}
-
-
-PRIntn
-nsElementMap::Compare(const void* aLeft, const void* aRight)
-{
-    return 0 == nsCRT::strcmp(reinterpret_cast<const PRUnichar*>(aLeft),
-                              reinterpret_cast<const PRUnichar*>(aRight));
-}
deleted file mode 100644
--- a/content/xul/document/src/nsElementMap.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK *****
- *
- *
- * This Original Code has been modified by IBM Corporation.
- * Modifications made by IBM described herein are
- * Copyright (c) International Business Machines
- * Corporation, 2000
- *
- * Modifications to Mozilla code or documentation
- * identified per MPL Section 3.3
- *
- * Date         Modified by     Description of modification
- * 03/27/2000   IBM Corp.       Added PR_CALLBACK for Optlink
- *                               use in OS2
- */
-
-/*
-
-   Maintains one-to-many mapping between element IDs and content
-   nodes.
-
- */
-
-#ifndef nsElementMap_h__
-#define nsElementMap_h__
-
-#include "nscore.h"
-#include "nsError.h"
-#include "plhash.h"
-#include "nsIContent.h"
-#include "nsFixedSizeAllocator.h"
-#include "nsCOMArray.h"
-
-class nsString;
-
-class nsElementMap
-{
-protected:
-    PLHashTable* mMap;
-    nsFixedSizeAllocator mPool;
-
-    static PLHashAllocOps gAllocOps;
-
-    class ContentListItem {
-    public:
-        ContentListItem* mNext;
-        nsCOMPtr<nsIContent> mContent;
-
-        static ContentListItem*
-        Create(nsFixedSizeAllocator& aPool, nsIContent* aContent) {
-            void* bytes = aPool.Alloc(sizeof(ContentListItem));
-            return bytes ? new (bytes) ContentListItem(aContent) : nsnull; }
-
-        static void
-        Destroy(nsFixedSizeAllocator& aPool, ContentListItem* aItem) {
-            delete aItem;
-            aPool.Free(aItem, sizeof(*aItem)); }
-
-    protected:
-        static void* operator new(size_t aSize, void* aPtr) CPP_THROW_NEW {
-            return aPtr; }
-
-        static void operator delete(void* aPtr, size_t aSize) {
-            /* do nothing; memory free()'d in Destroy() */ }
-
-        ContentListItem(nsIContent* aContent) : mNext(nsnull), mContent(aContent) {
-            MOZ_COUNT_CTOR(nsElementMap::ContentListItem); }
-
-        ~ContentListItem() {
-            MOZ_COUNT_DTOR(nsElementMap::ContentListItem); }
-    };
-
-    static PLHashNumber PR_CALLBACK
-    Hash(const void* akey);
-
-    static PRIntn PR_CALLBACK
-    Compare(const void* aLeft, const void* aRight);
-
-    static PRIntn PR_CALLBACK
-    ReleaseContentList(PLHashEntry* aHashEntry, PRIntn aIndex, void* aClosure);
-
-public:
-    nsElementMap(void);
-    virtual ~nsElementMap();
-
-    nsresult
-    Add(const nsAString& aID, nsIContent* aContent);
-
-    nsresult
-    Remove(const nsAString& aID, nsIContent* aContent);
-
-    nsresult
-    Find(const nsAString& aID, nsCOMArray<nsIContent>& aResults);
-
-    nsresult
-    FindFirst(const nsAString& aID, nsIContent** aContent);
-
-    typedef PRIntn (*nsElementMapEnumerator)(const PRUnichar* aID,
-                                             nsIContent* aElement,
-                                             void* aClosure);
-
-    nsresult
-    Enumerate(nsElementMapEnumerator aEnumerator, void* aClosure);
-
-private:
-    struct EnumerateClosure {
-        nsElementMap*          mSelf;
-        nsElementMapEnumerator mEnumerator;
-        void*                  mClosure;
-    };
-        
-    static PRIntn PR_CALLBACK
-    EnumerateImpl(PLHashEntry* aHashEntry, PRIntn aIndex, void* aClosure);
-};
-
-
-#endif // nsElementMap_h__
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -51,20 +51,16 @@
 
   1. We do some monkey business in the document observer methods to`
      keep the element map in sync for HTML elements. Why don't we just
      do it for _all_ elements? Well, in the case of XUL elements,
      which may be lazily created during frame construction, the
      document observer methods will never be called because we'll be
      adding the XUL nodes into the content model "quietly".
 
-  2. The "element map" maps an RDF resource to the elements whose 'id'
-     or 'ref' attributes refer to that resource. We re-use the element
-     map to support the HTML-like 'getElementById()' method.
-
 */
 
 // Note the ALPHABETICAL ORDERING
 #include "nsXULDocument.h"
 
 #include "nsDOMError.h"
 #include "nsIBoxObject.h"
 #include "nsIChromeRegistry.h"
@@ -180,16 +176,45 @@ struct BroadcasterMapEntry : public PLDH
     nsSmallVoidArray mListeners;   // [OWNING] of BroadcastListener objects
 };
 
 struct BroadcastListener {
     nsWeakPtr mListener;
     nsCOMPtr<nsIAtom> mAttribute;
 };
 
+nsIContent*
+nsRefMapEntry::GetFirstContent()
+{
+    return static_cast<nsIContent*>(mRefContentList.SafeElementAt(0));
+}
+
+void
+nsRefMapEntry::AppendAll(nsCOMArray<nsIContent>* aElements)
+{
+    for (PRInt32 i = 0; i < mRefContentList.Count(); ++i) {
+        aElements->AppendObject(static_cast<nsIContent*>(mRefContentList[i]));
+    }
+}
+
+PRBool
+nsRefMapEntry::AddContent(nsIContent* aContent)
+{
+    if (mRefContentList.IndexOf(aContent) >= 0)
+        return PR_TRUE;
+    return mRefContentList.AppendElement(aContent);
+}
+
+PRBool
+nsRefMapEntry::RemoveContent(nsIContent* aContent)
+{
+    mRefContentList.RemoveElement(aContent);
+    return mRefContentList.Count() == 0;
+}
+
 //----------------------------------------------------------------------
 //
 // ctors & dtors
 //
 
     // NOTE! nsDocument::operator new() zeroes out all members, so
     // don't bother initializing members to 0.
 
@@ -285,27 +310,16 @@ NS_NewXULDocument(nsIXULDocument** resul
 
 //----------------------------------------------------------------------
 //
 // nsISupports interface
 //
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULDocument)
 
-static PRIntn
-TraverseElement(const PRUnichar* aID, nsIContent* aElement, void* aContext)
-{
-    nsCycleCollectionTraversalCallback *cb =
-        static_cast<nsCycleCollectionTraversalCallback*>(aContext);
-
-    cb->NoteXPCOMChild(aElement);
-
-    return HT_ENUMERATE_NEXT;
-}
-
 static PLDHashOperator PR_CALLBACK
 TraverseTemplateBuilders(nsISupports* aKey, nsIXULTemplateBuilder* aData,
                          void* aContext)
 {
     nsCycleCollectionTraversalCallback *cb =
         static_cast<nsCycleCollectionTraversalCallback*>(aContext);
 
     cb->NoteXPCOMChild(aKey);
@@ -324,18 +338,16 @@ TraverseObservers(nsIURI* aKey, nsIObser
 
     return PL_DHASH_NEXT;
 }
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULDocument, nsXMLDocument)
     // XXX tmp->mForwardReferences?
     // XXX tmp->mContextStack?
 
-    tmp->mElementMap.Enumerate(TraverseElement, &cb);
-
     // An element will only have a template builder as long as it's in the
     // document, so we'll traverse the table here instead of from the element.
     if (tmp->mTemplateBuilderTable)
         tmp->mTemplateBuilderTable->EnumerateRead(TraverseTemplateBuilders, &cb);
         
     NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mCurrentPrototype,
                                                      nsIScriptGlobalObjectOwner)
     NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mMasterPrototype,
@@ -913,37 +925,52 @@ nsXULDocument::ExecuteOnBroadcastHandler
                                         &status);
         }
     }
 
     return NS_OK;
 }
 
 void
+nsXULDocument::AttributeWillChange(nsIContent* aContent, PRInt32 aNameSpaceID,
+                                   nsIAtom* aAttribute)
+{
+    NS_ABORT_IF_FALSE(aContent, "Null content!");
+    NS_PRECONDITION(aAttribute, "Must have an attribute that's changing!");
+
+    // XXXbz check aNameSpaceID, dammit!
+    // See if we need to update our ref map.
+    if (aAttribute == nsGkAtoms::ref ||
+        (aAttribute == nsGkAtoms::id && !aContent->GetIDAttributeName())) {
+        RemoveElementFromRefMap(aContent);
+    }
+    
+    nsXMLDocument::AttributeWillChange(aContent, aNameSpaceID, aAttribute);
+}
+
+void
 nsXULDocument::AttributeChanged(nsIDocument* aDocument,
                                 nsIContent* aElement, PRInt32 aNameSpaceID,
                                 nsIAtom* aAttribute, PRInt32 aModType,
                                 PRUint32 aStateMask)
 {
     NS_ASSERTION(aDocument == this, "unexpected doc");
 
-    nsresult rv;
+    // Do this here so that all the exit paths below don't leave this undone
+    nsXMLDocument::AttributeChanged(aDocument, aElement, aNameSpaceID,
+            aAttribute, aModType, aStateMask);
 
     // XXXbz check aNameSpaceID, dammit!
-    // First see if we need to update our element map.
-    if ((aAttribute == nsGkAtoms::id) || (aAttribute == nsGkAtoms::ref)) {
-
-        rv = mElementMap.Enumerate(RemoveElementsFromMapByContent, aElement);
-        if (NS_FAILED(rv)) return;
-
-        // That'll have removed _both_ the 'ref' and 'id' entries from
-        // the map. So add 'em back now.
-        rv = AddElementToMap(aElement);
-        if (NS_FAILED(rv)) return;
+    // See if we need to update our ref map.
+    if (aAttribute == nsGkAtoms::ref ||
+        (aAttribute == nsGkAtoms::id && !aElement->GetIDAttributeName())) {
+        AddElementToRefMap(aElement);
     }
+    
+    nsresult rv;
 
     // Synchronize broadcast listeners
     if (mBroadcasterMap && CanBroadcast(aNameSpaceID, aAttribute)) {
         nsCOMPtr<nsIDOMElement> domele = do_QueryInterface(aElement);
         BroadcasterMapEntry* entry =
             static_cast<BroadcasterMapEntry*>
                        (PL_DHashTableOperate(mBroadcasterMap, domele.get(),
                                                 PL_DHASH_LOOKUP));
@@ -1008,82 +1035,88 @@ nsXULDocument::AttributeChanged(nsIDocum
 }
 
 void
 nsXULDocument::ContentAppended(nsIDocument* aDocument,
                                nsIContent* aContainer,
                                PRInt32 aNewIndexInContainer)
 {
     NS_ASSERTION(aDocument == this, "unexpected doc");
-
+    
     // Update our element map
     PRUint32 count = aContainer->GetChildCount();
 
     nsresult rv = NS_OK;
     for (PRUint32 i = aNewIndexInContainer; i < count && NS_SUCCEEDED(rv);
          ++i) {
         rv = AddSubtreeToDocument(aContainer->GetChildAt(i));
     }
+
+    nsXMLDocument::ContentAppended(aDocument, aContainer, aNewIndexInContainer);
 }
 
 void
 nsXULDocument::ContentInserted(nsIDocument* aDocument,
                                nsIContent* aContainer,
                                nsIContent* aChild,
                                PRInt32 aIndexInContainer)
 {
     NS_ASSERTION(aDocument == this, "unexpected doc");
 
     AddSubtreeToDocument(aChild);
+
+    nsXMLDocument::ContentInserted(aDocument, aContainer, aChild, aIndexInContainer);
 }
 
 void
 nsXULDocument::ContentRemoved(nsIDocument* aDocument,
                               nsIContent* aContainer,
                               nsIContent* aChild,
                               PRInt32 aIndexInContainer)
 {
     NS_ASSERTION(aDocument == this, "unexpected doc");
 
     RemoveSubtreeFromDocument(aChild);
+
+    nsXMLDocument::ContentRemoved(aDocument, aContainer, aChild, aIndexInContainer);
 }
 
 //----------------------------------------------------------------------
 //
 // nsIXULDocument interface
 //
 
 NS_IMETHODIMP
-nsXULDocument::AddElementForID(const nsAString& aID, nsIContent* aElement)
+nsXULDocument::AddElementForID(nsIContent* aElement)
 {
     NS_PRECONDITION(aElement != nsnull, "null ptr");
     if (! aElement)
         return NS_ERROR_NULL_POINTER;
 
-    mElementMap.Add(aID, aElement);
-    return NS_OK;
-}
-
-
-NS_IMETHODIMP
-nsXULDocument::RemoveElementForID(const nsAString& aID, nsIContent* aElement)
-{
-    NS_PRECONDITION(aElement != nsnull, "null ptr");
-    if (! aElement)
-        return NS_ERROR_NULL_POINTER;
-
-    mElementMap.Remove(aID, aElement);
+    UpdateIdTableEntry(aElement);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULDocument::GetElementsForID(const nsAString& aID,
                                 nsCOMArray<nsIContent>& aElements)
 {
-    mElementMap.Find(aID, aElements);
+    aElements.Clear();
+
+    nsCOMPtr<nsIAtom> atom = do_GetAtom(aID);
+    if (!atom)
+        return NS_ERROR_OUT_OF_MEMORY;
+    nsIdentifierMapEntry *entry = mIdentifierMap.GetEntry(atom);
+    if (entry) {
+        entry->AppendAllIdContent(&aElements);
+    }
+    nsRefMapEntry *refEntry = mRefMap.GetEntry(atom);
+    if (refEntry) {
+        refEntry->AppendAll(&aElements);
+    }
     return NS_OK;
 }
 
 nsresult
 nsXULDocument::AddForwardReference(nsForwardReference* aRef)
 {
     if (mResolutionPhase < aRef->GetPhase()) {
         if (!mForwardReferences.AppendElement(aRef)) {
@@ -1552,38 +1585,46 @@ nsXULDocument::GetElementById(const nsAS
                               nsIDOMElement** aReturn)
 {
     NS_ENSURE_ARG_POINTER(aReturn);
     *aReturn = nsnull;
 
     if (!CheckGetElementByIdArg(aId))
         return NS_OK;
 
-    nsresult rv;
-
-    nsCOMPtr<nsIContent> element;
-    rv = mElementMap.FindFirst(aId, getter_AddRefs(element));
-    if (NS_FAILED(rv)) return rv;
-
-    if (element) {
-        rv = CallQueryInterface(element, aReturn);
+    nsCOMPtr<nsIAtom> atom = do_GetAtom(aId);
+    if (!atom)
+        return NS_ERROR_OUT_OF_MEMORY;
+    nsIdentifierMapEntry *entry = mIdentifierMap.GetEntry(atom);
+    if (entry) {
+        nsIContent* content = entry->GetIdContent();
+        if (content)
+            return CallQueryInterface(content, aReturn);
     }
-
-    return rv;
+    nsRefMapEntry* refEntry = mRefMap.GetEntry(atom);
+    if (refEntry) {
+        NS_ASSERTION(refEntry->GetFirstContent(),
+                     "nsRefMapEntries should have nonempty content lists");
+        return CallQueryInterface(refEntry->GetFirstContent(), aReturn);
+    }
+    return NS_OK;
 }
 
 nsresult
 nsXULDocument::AddElementToDocumentPre(nsIContent* aElement)
 {
     // Do a bunch of work that's necessary when an element gets added
     // to the XUL Document.
     nsresult rv;
 
-    // 1. Add the element to the resource-to-element map
-    rv = AddElementToMap(aElement);
+    // 1. Add the element to the resource-to-element map. Also add it to
+    // the id map, since it seems this can be called when creating
+    // elements from prototypes.
+    UpdateIdTableEntry(aElement);
+    rv = AddElementToRefMap(aElement);
     if (NS_FAILED(rv)) return rv;
 
     // 2. If the element is a 'command updater' (i.e., has a
     // "commandupdater='true'" attribute), then add the element to the
     // document's command dispatcher
     if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::commandupdater,
                               nsGkAtoms::_true, eCaseMatters)) {
         rv = nsXULContentUtils::SetCommandUpdater(this, aElement);
@@ -1694,18 +1735,17 @@ nsXULDocument::RemoveSubtreeFromDocument
 
     while (count-- > 0) {
         rv = RemoveSubtreeFromDocument(aElement->GetChildAt(count));
         if (NS_FAILED(rv))
             return rv;
     }
 
     // 2. Remove the element from the resource-to-element map
-    rv = RemoveElementFromMap(aElement);
-    if (NS_FAILED(rv)) return rv;
+    RemoveElementFromRefMap(aElement);
 
     // 3. If the element is a 'command updater', then remove the
     // element from the document's command dispatcher.
     if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::commandupdater,
                               nsGkAtoms::_true, eCaseMatters)) {
         nsCOMPtr<nsIDOMElement> domelement = do_QueryInterface(aElement);
         NS_ASSERTION(domelement != nsnull, "not a DOM element");
         if (! domelement)
@@ -1758,75 +1798,65 @@ nsXULDocument::GetTemplateBuilderFor(nsI
         mTemplateBuilderTable->Get(aContent, aResult);
     }
     else
         *aResult = nsnull;
 
     return NS_OK;
 }
 
-// Attributes that are used with getElementById() and the
-// resource-to-element map.
-nsIAtom** nsXULDocument::kIdentityAttrs[] =
+static void
+GetRefMapAttribute(nsIContent* aElement, nsAutoString* aValue)
 {
-    &nsGkAtoms::id,
-    &nsGkAtoms::ref,
-    nsnull
-};
+    aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::ref, *aValue);
+    if (aValue->IsEmpty() && !aElement->GetIDAttributeName()) {
+        aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::id, *aValue);
+    }
+}
 
 nsresult
-nsXULDocument::AddElementToMap(nsIContent* aElement)
+nsXULDocument::AddElementToRefMap(nsIContent* aElement)
 {
-    // Look at the element's 'id' and 'ref' attributes, and if set,
-    // add pointers in the resource-to-element map to the element.
-    nsresult rv;
-
-    for (PRInt32 i = 0; kIdentityAttrs[i] != nsnull; ++i) {
-        nsAutoString value;
-        aElement->GetAttr(kNameSpaceID_None, *kIdentityAttrs[i], value);
-        if (!value.IsEmpty()) {
-            rv = mElementMap.Add(value, aElement);
-            if (NS_FAILED(rv)) return rv;
-        }
+    // Look at the element's 'ref' attribute, and if set,
+    // add an entry in the resource-to-element map to the element.
+    nsAutoString value;
+    GetRefMapAttribute(aElement, &value);
+    if (!value.IsEmpty()) {
+        nsCOMPtr<nsIAtom> atom = do_GetAtom(value);
+        if (!atom)
+            return NS_ERROR_OUT_OF_MEMORY;
+        nsRefMapEntry *entry = mRefMap.PutEntry(atom);
+        if (!entry)
+            return NS_ERROR_OUT_OF_MEMORY;
+        if (!entry->AddContent(aElement))
+            return NS_ERROR_OUT_OF_MEMORY;
     }
 
     return NS_OK;
 }
 
-
-nsresult
-nsXULDocument::RemoveElementFromMap(nsIContent* aElement)
+void
+nsXULDocument::RemoveElementFromRefMap(nsIContent* aElement)
 {
     // Remove the element from the resource-to-element map.
-    nsresult rv;
-
-    for (PRInt32 i = 0; kIdentityAttrs[i] != nsnull; ++i) {
-        nsAutoString value;
-        aElement->GetAttr(kNameSpaceID_None, *kIdentityAttrs[i], value);
-        if (!value.IsEmpty()) {
-            rv = mElementMap.Remove(value, aElement);
-            if (NS_FAILED(rv)) return rv;
+    nsAutoString value;
+    GetRefMapAttribute(aElement, &value);
+    if (!value.IsEmpty()) {
+        nsCOMPtr<nsIAtom> atom = do_GetAtom(value);
+        if (!atom)
+            return;
+        nsRefMapEntry *entry = mRefMap.GetEntry(atom);
+        if (!entry)
+            return;
+        if (entry->RemoveContent(aElement)) {
+            mRefMap.RemoveEntry(atom);
         }
     }
-
-    return NS_OK;
 }
 
-
-PRIntn
-nsXULDocument::RemoveElementsFromMapByContent(const PRUnichar* aID,
-                                              nsIContent* aElement,
-                                              void* aClosure)
-{
-    nsIContent* content = reinterpret_cast<nsIContent*>(aClosure);
-    return (aElement == content) ? HT_ENUMERATE_REMOVE : HT_ENUMERATE_NEXT;
-}
-
-
-
 //----------------------------------------------------------------------
 //
 // nsIDOMNode interface
 //
 
 NS_IMETHODIMP
 nsXULDocument::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
 {
@@ -1839,16 +1869,19 @@ nsXULDocument::CloneNode(PRBool aDeep, n
 //----------------------------------------------------------------------
 //
 // Implementation methods
 //
 
 nsresult
 nsXULDocument::Init()
 {
+    SetIdTableLive();
+    mRefMap.Init();
+
     nsresult rv = nsXMLDocument::Init();
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Create our command dispatcher and hook it up.
     mCommandDispatcher = new nsXULCommandDispatcher(this);
     NS_ENSURE_TRUE(mCommandDispatcher, NS_ERROR_OUT_OF_MEMORY);
 
     // this _could_ fail; e.g., if we've tried to grab the local store
@@ -2364,17 +2397,18 @@ nsXULDocument::PrepareToWalk()
         // Add the root element
         rv = CreateElementFromPrototype(proto, getter_AddRefs(root));
         if (NS_FAILED(rv)) return rv;
 
         rv = AppendChildTo(root, PR_FALSE);
         if (NS_FAILED(rv)) return rv;
         
         // Add the root element to the XUL document's ID-to-element map.
-        rv = AddElementToMap(root);
+        UpdateIdTableEntry(root);
+        rv = AddElementToRefMap(root);
         if (NS_FAILED(rv)) return rv;
 
         // Block onload until we've finished building the complete
         // document content model.
         BlockOnload();
     }
 
     // There'd better not be anything on the context stack at this
--- a/content/xul/document/src/nsXULDocument.h
+++ b/content/xul/document/src/nsXULDocument.h
@@ -41,17 +41,16 @@
 #define nsXULDocument_h__
 
 #include "nsCOMPtr.h"
 #include "nsXULPrototypeDocument.h"
 #include "nsXULPrototypeCache.h"
 #include "nsTArray.h"
 
 #include "nsXMLDocument.h"
-#include "nsElementMap.h"
 #include "nsForwardReference.h"
 #include "nsIContent.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIDOMXULCommandDispatcher.h"
 #include "nsIDOMXULDocument.h"
 #include "nsCOMArray.h"
 #include "nsIURI.h"
 #include "nsIXULDocument.h"
@@ -73,16 +72,45 @@ class nsIXULPrototypeScript;
 #include "nsXULElement.h"
 #endif
 #include "nsURIHashKey.h"
 #include "nsInterfaceHashtable.h"
  
 struct JSObject;
 struct PRLogModuleInfo;
 
+class nsRefMapEntry : public nsISupportsHashKey
+{
+public:
+  nsRefMapEntry(const nsISupports* aKey) :
+    nsISupportsHashKey(aKey)
+  {
+  }
+  nsRefMapEntry(const nsRefMapEntry& aOther) :
+    nsISupportsHashKey(GetKey())
+  {
+    NS_ERROR("Should never be called");
+  }
+
+  nsIContent* GetFirstContent();
+  void AppendAll(nsCOMArray<nsIContent>* aElements);
+  /**
+   * @return true if aContent was added, false if we failed due to OOM
+   */
+  PRBool AddContent(nsIContent* aContent);
+  /**
+   * @return true if aContent was removed and it was the last content for
+   * this ref, so this entry should be removed from the map
+   */
+  PRBool RemoveContent(nsIContent* aContent);
+
+private:
+  nsSmallVoidArray mRefContentList;
+};
+
 /**
  * The XUL document class
  */
 class nsXULDocument : public nsXMLDocument,
                       public nsIXULDocument,
                       public nsIDOMXULDocument,
                       public nsIStreamLoaderObserver,
                       public nsICSSLoaderObserver
@@ -113,19 +141,22 @@ public:
     virtual void EndLoad();
 
     // nsIMutationObserver interface
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
     NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
     NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
 
+    virtual void AttributeWillChange(nsIContent* aChild,
+                                     PRInt32 aNameSpaceID,
+                                     nsIAtom* aAttribute);
+
     // nsIXULDocument interface
-    NS_IMETHOD AddElementForID(const nsAString& aID, nsIContent* aElement);
-    NS_IMETHOD RemoveElementForID(const nsAString& aID, nsIContent* aElement);
+    NS_IMETHOD AddElementForID(nsIContent* aElement);
     NS_IMETHOD GetElementsForID(const nsAString& aID,
                                 nsCOMArray<nsIContent>& aElements);
 
     NS_IMETHOD GetScriptGlobalObjectOwner(nsIScriptGlobalObjectOwner** aGlobalOwner);
     NS_IMETHOD AddSubtreeToDocument(nsIContent* aElement);
     NS_IMETHOD RemoveSubtreeFromDocument(nsIContent* aElement);
     NS_IMETHOD SetTemplateBuilderFor(nsIContent* aContent,
                                      nsIXULTemplateBuilder* aBuilder);
@@ -165,28 +196,22 @@ protected:
     // Implementation methods
     friend nsresult
     NS_NewXULDocument(nsIXULDocument** aResult);
 
     nsresult Init(void);
     nsresult StartLayout(void);
 
     nsresult
-    AddElementToMap(nsIContent* aElement);
-
-    nsresult
-    RemoveElementFromMap(nsIContent* aElement);
+    AddElementToRefMap(nsIContent* aElement);
+    void
+    RemoveElementFromRefMap(nsIContent* aElement);
 
     nsresult GetViewportSize(PRInt32* aWidth, PRInt32* aHeight);
 
-    static PRIntn
-    RemoveElementsFromMapByContent(const PRUnichar* aID,
-                                   nsIContent* aElement,
-                                   void* aClosure);
-
     void SetIsPopup(PRBool isPopup) { mIsPopup = isPopup; }
 
     nsresult PrepareToLoad(nsISupports* aContainer,
                            const char* aCommand,
                            nsIChannel* aChannel,
                            nsILoadGroup* aLoadGroup,
                            nsIParser** aResult);
 
@@ -245,17 +270,19 @@ protected:
     // for owning pointers and raw COM interface pointers for weak
     // (ie, non owning) references. If you add any members to this
     // class, please make the ownership explicit (pinkerton, scc).
     // NOTE, THIS IS STILL IN PROGRESS, TALK TO PINK OR SCC BEFORE
     // CHANGING
 
     nsXULDocument*             mNextSrcLoadWaiter;  // [OWNER] but not COMPtr
 
-    nsElementMap               mElementMap;
+    // Tracks elements with a 'ref' attribute, or an 'id' attribute where
+    // the element's namespace has no registered ID attribute name.
+    nsTHashtable<nsRefMapEntry> mRefMap;
     nsCOMPtr<nsIRDFDataSource> mLocalStore;
     PRPackedBool               mIsPopup;
     PRPackedBool               mApplyingPersistedAttrs;
     PRPackedBool               mIsWritingFastLoad;
     PRPackedBool               mDocumentLoaded;
     /**
      * Since ResumeWalk is interruptible, it's possible that last
      * stylesheet finishes loading while the PD walk is still in
--- a/content/xul/document/test/test_bug311681.xul
+++ b/content/xul/document/test/test_bug311681.xul
@@ -42,25 +42,23 @@ https://bugzilla.mozilla.org/show_bug.cg
     // removed.
     var newParent = $("display");
     var node = testNode.cloneNode(true);
     isnot(node, testNode, "Clone should be a different node");
 
     newParent.appendChild(node);
 
     // Check what getElementById returns, no flushing
-    todo(getCont() == node, "Should be getting new node pre-flush 1")
-    is(getCont(), testNode, "XUL does it differently for now");
+    is(getCont(), node, "Should be getting new node pre-flush 1")
     
     // Trigger a layout flush, just in case.
     var itemHeight = newParent.offsetHeight/10;
 
     // Check what getElementById returns now.
-    todo(getCont() == node, "Should be getting new node post-flush 1")
-    is(getCont(), testNode, "XUL does it differently for now");
+    is(getCont(), node, "Should be getting new node post-flush 1")
     
     clear(newParent);
     
     // Check what getElementById returns, no flushing
     is(getCont(), testNode, "Should be getting orig node pre-flush 2");
     
     // Trigger a layout flush, just in case.
     var itemHeight = newParent.offsetHeight/10;
--- a/content/xul/document/test/test_bug403868.xul
+++ b/content/xul/document/test/test_bug403868.xul
@@ -35,29 +35,26 @@ var s2a = createSpan("test1", null);
 is(document.getElementById("test1"), s1a,
    "Appending span with id=test1 doesn't change which one comes first");
 
 var s3a = createSpan("test1", s2a);
 is(document.getElementById("test1"), s1a,
    "Inserting span with id=test1 not at the beginning; doesn't matter");
 
 var s4a = createSpan("test1", s1a);
-todo(document.getElementById("test1") == s4a,
+is(document.getElementById("test1"), s4a,
    "Inserting span with id=test1 at the beginning changes which one is first");
-is(document.getElementById("test1"), s1a, "XUL is confused")
 
 s4a.parentNode.removeChild(s4a);
 is(document.getElementById("test1"), s1a,
    "First-created span with id=test1 is first again");
 
 s1a.parentNode.removeChild(s1a);
-todo(document.getElementById("test1") == s3a,
+is(document.getElementById("test1"), s3a,
    "Third-created span with id=test1 is first now");
-is(document.getElementById("test1"), s2a,
-   "XUL is confused");
 
 // Start the id hashtable
 for (var i = 0; i < 256; ++i) {
   document.getElementById("no-such-id-in-the-document" + i);
 }
 
 var s1b = createSpan("test2", null);
 is(document.getElementById("test2"), s1b,
@@ -67,24 +64,21 @@ var s2b = createSpan("test2", null);
 is(document.getElementById("test2"), s1b,
    "Appending span with id=test2 doesn't change which one comes first");
 
 var s3b = createSpan("test2", s2b);
 is(document.getElementById("test2"), s1b,
    "Inserting span with id=test2 not at the beginning; doesn't matter");
 
 var s4b = createSpan("test2", s1b);
-todo(document.getElementById("test2") == s4b,
+is(document.getElementById("test2"), s4b,
    "Inserting span with id=test2 at the beginning changes which one is first");
-is(document.getElementById("test2"), s1b, "XUL is confused")
 
 s4b.parentNode.removeChild(s4b);
 is(document.getElementById("test2"), s1b,
    "First-created span with id=test2 is first again");
 
 s1b.parentNode.removeChild(s1b);
-todo(document.getElementById("test2") == s3b,
+is(document.getElementById("test2"), s3b,
    "Third-created span with id=test2 is first now");
-is(document.getElementById("test2"), s2b,
-   "XUL is confused");
 
   ]]></script>
 </window>
--- a/content/xul/templates/src/nsXULContentBuilder.cpp
+++ b/content/xul/templates/src/nsXULContentBuilder.cpp
@@ -732,17 +732,17 @@ nsXULContentBuilder::BuildContentFromTem
             if (! aNotify) {
                 // XUL document will watch us, and take care of making
                 // sure that we get added to or removed from the
                 // element map if aNotify is true. If not, we gotta do
                 // it ourselves. Yay.
                 nsCOMPtr<nsIXULDocument> xuldoc =
                     do_QueryInterface(mRoot->GetDocument());
                 if (xuldoc)
-                    xuldoc->AddElementForID(id, realKid);
+                    xuldoc->AddElementForID(realKid);
             }
 
             // Set up the element's 'container' and 'empty' attributes.
             SetContainerAttrs(realKid, aChild, PR_TRUE, PR_FALSE);
         }
         else if (tag == nsGkAtoms::textnode &&
                  nameSpaceID == kNameSpaceID_XUL) {
             // <xul:text value="..."> is replaced by text of the
--- a/db/sqlite3/src/Makefile.in
+++ b/db/sqlite3/src/Makefile.in
@@ -86,17 +86,27 @@ EXPORTS = \
 CSRCS = \
 	sqlite3.c \
 	$(NULL)
 
 # -DSQLITE_SECURE_DELETE=1 will cause SQLITE to 0-fill delete data so we
 # don't have to vacuum to make sure the data is not visible in the file.
 # -DSQLITE_ENABLE_FTS3=1 enables the full-text index module.
 # -DSQLITE_CORE=1 statically links that module into the SQLite library.
-DEFINES = -DSQLITE_SECURE_DELETE=1 -DTHREADSAFE=1 -DSQLITE_CORE=1 -DSQLITE_ENABLE_FTS3=1
+DEFINES = \
+  -DSQLITE_SECURE_DELETE=1 \
+  -DTHREADSAFE=1 \
+  -DSQLITE_CORE=1 \
+  -DSQLITE_ENABLE_FTS3=1 \
+  $(NULL)
+
+# -DSQLITE_ENABLE_LOCKING_STYLE=1 to help with AFP folders
+ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
+DEFINES += -DSQLITE_ENABLE_LOCKING_STYLE=1
+endif
 
 ifeq ($(OS_ARCH),OS2)
 ifdef MOZ_OS2_HIGH_MEMORY
 DEFINES += -DOS2_HIGH_MEMORY
 endif
 endif
 
 include $(topsrcdir)/config/rules.mk
--- a/embedding/browser/gtk/src/EmbedWindow.cpp
+++ b/embedding/browser/gtk/src/EmbedWindow.cpp
@@ -404,16 +404,17 @@ EmbedWindow::OnShowTooltip(PRInt32 aXCoo
   // cursor.
   root_y += 10;
   
   sTipWindow = gtk_window_new(GTK_WINDOW_POPUP);
   gtk_widget_set_app_paintable(sTipWindow, TRUE);
   gtk_window_set_resizable(GTK_WINDOW(sTipWindow), TRUE);
   // needed to get colors + fonts etc correctly
   gtk_widget_set_name(sTipWindow, "gtk-tooltips");
+  gtk_window_set_type_hint(GTK_WINDOW(sTipWindow), GDK_WINDOW_TYPE_HINT_TOOLTIP);
   
   // set up the popup window as a transient of the widget.
   GtkWidget *toplevel_window;
   toplevel_window = gtk_widget_get_toplevel(GTK_WIDGET(mOwner->mOwningWidget));
   if (!GTK_WINDOW(toplevel_window)) {
     NS_ERROR("no gtk window in hierarchy!\n");
     return NS_ERROR_FAILURE;
   }
--- a/extensions/universalchardet/tests/Makefile.in
+++ b/extensions/universalchardet/tests/Makefile.in
@@ -67,16 +67,18 @@ LIBS		+= \
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef MOZ_MOCHITEST
 relativesrcdir = extensions/universalchardet/tests
 
 _TEST_FILES =	\
 		CharsetDetectionTests.js \
+		bug9357_text.html \
+		test_bug9357.html \
 		bug171813_text.html \
 		test_bug171813.html \
 		bug306272_text.html \
 		test_bug306272.html \
 		bug421271_text.html \
 		test_bug421271.html \
 		bug426271_text-euc-jp.html \
 		test_bug426271-euc-jp.html \
new file mode 100644
--- /dev/null
+++ b/extensions/universalchardet/tests/bug9357_text.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>EUC-KR test</title>
+</head>
+<body>
+ <p>요청하신 웹 페이지를 찾을 수 없습니다.<br>찾으시는 웹 페이지가 현재 사용할 수 없거나<br>웹 페이지의 이름이 변경 또는 삭제 되었습니다.<br>이벤트 관련 문의는 고객문의를 이용하시기 바랍니다 </p>
+</body>
+</html>
+
+
+
+
+
+
new file mode 100644
--- /dev/null
+++ b/extensions/universalchardet/tests/test_bug9357.html
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=9357
+-->
+<head>
+  <title>Test for Bug 9357</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="CharsetDetectionTests.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=9357">Mozilla Bug 9357</a>
+<p id="display"></p>
+<div id="content" style="display: none">  
+</div>
+<iframe id="testframe"></iframe>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+/** Test for Bug 9357 **/
+CharsetDetectionTests("bug9357_text.html",
+		      "EUC-KR",
+		      new Array("ko_parallel_state_machine",
+				"cjk_parallel_state_machine",
+				"universal_charset_detector"));
+</script>
+</pre>
+</body>
+</html>
+
--- a/gfx/thebes/src/gfxPangoFonts.cpp
+++ b/gfx/thebes/src/gfxPangoFonts.cpp
@@ -1265,16 +1265,18 @@ SetupClusterBoundaries(gfxTextRun* aText
             aTextRun->SetGlyphs(aUTF16Offset, g.SetComplex(PR_FALSE, PR_TRUE, 0), nsnull);
         }
         ++aUTF16Offset;
         
         gunichar ch = g_utf8_get_char(p);
         NS_ASSERTION(ch != 0, "Shouldn't have NUL in pango_break");
         NS_ASSERTION(!IS_SURROGATE(ch), "Shouldn't have surrogates in UTF8");
         if (ch >= 0x10000) {
+            // set glyph info for the UTF-16 low surrogate
+            aTextRun->SetGlyphs(aUTF16Offset, g.SetComplex(PR_FALSE, PR_FALSE, 0), nsnull);
             ++aUTF16Offset;
         }
         // We produced this utf8 so we don't need to worry about malformed stuff
         p = g_utf8_next_char(p);
         ++attr;
     }
 }
 
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -237,16 +237,20 @@ JSJAVA_CFLAGS	= \
 		-I$(topsrcdir)/sun-java/md-include \
 		-I$(topsrcdir)/sun-java/include \
 		$(JSJAVA_STUBHEADERS)
 
 # Define keyword generator before rules.mk, see bug 323979 comment 50
 
 HOST_SIMPLE_PROGRAMS += host_jskwgen$(HOST_BIN_SUFFIX)
 GARBAGE += jsautokw.h host_jskwgen$(HOST_BIN_SUFFIX)
+
+HOST_SIMPLE_PROGRAMS += host_jsoplengen$(HOST_BIN_SUFFIX)
+GARBAGE += jsautooplen.h host_jsoplengen$(HOST_BIN_SUFFIX)
+
 USE_HOST_CXX = 1
 
 ifdef HAVE_DTRACE
 ifneq ($(OS_ARCH),Darwin)
 DTRACE_PROBE_OBJ = $(LIBRARY_NAME)-dtrace.$(OBJ_SUFFIX)
 endif
 MOZILLA_DTRACE_SRC = $(srcdir)/javascript-trace.d
 endif
@@ -350,16 +354,22 @@ endif # JS_ULTRASPARC_OPTS
 endif
 ifeq ($(OS_RELEASE),4.1)
 LDFLAGS		+= -ldl -lnsl
 else
 LDFLAGS		+= -lposix4 -ldl -lnsl -lsocket
 endif
 endif
 
+ifdef MOZ_MEMORY
+ifeq ($(OS_ARCH),Darwin)
+LDFLAGS += -ljemalloc
+endif
+endif
+
 # Allow building jsinterp.c with special optimization flags
 ifdef INTERP_OPTIMIZER
 jsinterp.$(OBJ_SUFFIX): MODULE_OPTIMIZE_FLAGS=$(INTERP_OPTIMIZER)
 endif
 
 ifeq ($(OS_ARCH),IRIX)
 ifndef GNU_CC
 _COMPILE_CFLAGS  = $(patsubst -O%,-O1,$(COMPILE_CFLAGS))
@@ -440,23 +450,28 @@ ifeq ($(OS_ARCH),WINCE)
 jscpucfg$(HOST_BIN_SUFFIX):
 	echo no need to build jscpucfg $<
 else
 jscpucfg$(HOST_BIN_SUFFIX): jscpucfg.cpp Makefile.in
 	$(HOST_CXX) $(HOST_CXXFLAGS) $(JSCPUCFG_DEFINES) $(DEFINES) $(NSPR_CFLAGS) $(OUTOPTION)$@ $<
 endif
 endif
 
-# Extra dependancies and rules for keyword switch code
-jsscan.$(OBJ_SUFFIX): jsautokw.h jskeyword.tbl
-
+# Extra dependancies and rules for auto-generated headers
 host_jskwgen.$(OBJ_SUFFIX): jsconfig.h jskeyword.tbl
 
 jsautokw.h: host_jskwgen$(HOST_BIN_SUFFIX)
 	./host_jskwgen$(HOST_BIN_SUFFIX) $@
 
+host_jsoplengen.$(OBJ_SUFFIX): jsopcode.tbl
+
+jsautooplen.h: host_jsoplengen$(HOST_BIN_SUFFIX)
+	./host_jsoplengen$(HOST_BIN_SUFFIX) $@
+
+# Force auto-header generation before compiling any source that may use them
+$(CPPSRCS:%.cpp=%.$(OBJ_SUFFIX)): jsautokw.h jsautooplen.h
+
 ifdef HAVE_DTRACE
 javascript-trace.h: $(srcdir)/javascript-trace.d
 	dtrace -h -s $(srcdir)/javascript-trace.d -o javascript-trace.h.in
 	sed 's/if _DTRACE_VERSION/ifdef INCLUDE_MOZILLA_DTRACE/' \
 	    javascript-trace.h.in > javascript-trace.h
 endif
-
--- a/js/src/Makefile.ref
+++ b/js/src/Makefile.ref
@@ -272,49 +272,49 @@ include rules.mk
 
 MOZ_DEPTH = ../..
 include jsconfig.mk
 
 nsinstall-target:
 	cd ../../config; $(MAKE) OBJDIR=$(OBJDIR) OBJDIR_NAME=$(OBJDIR)
 
 #
-# Rules for keyword switch generation
+# Automatic header generation
 #
 
-GARBAGE += $(OBJDIR)/jsautokw.h $(OBJDIR)/jskwgen$(HOST_BIN_SUFFIX)
-GARBAGE += $(OBJDIR)/jskwgen.$(OBJ_SUFFIX)
+AUTO_HEADERS = $(OBJDIR)/jsautokw.h $(OBJDIR)/jsautooplen.h
 
-$(OBJDIR)/jsscan.$(OBJ_SUFFIX): $(OBJDIR)/jsautokw.h jskeyword.tbl
+$(OBJDIR)/jsautokw.h: jskeyword.tbl
 
-$(OBJDIR)/jskwgen.$(OBJ_SUFFIX): jskwgen.cpp jskeyword.tbl
+$(OBJDIR)/jsautooplen.h: jsopcode.tbl
 
-$(OBJDIR)/jsautokw.h: $(OBJDIR)/jskwgen$(HOST_BIN_SUFFIX) jskeyword.tbl
-	$(OBJDIR)/jskwgen$(HOST_BIN_SUFFIX) $@
+GARBAGE += $(AUTO_HEADERS)
+GARBAGE	+= $(AUTO_HEADERS:$(OBJDIR)/jsauto%.h=$(OBJDIR)/js%gen$(HOST_BIN_SUFFIX))
 
 ifdef USE_MSVC
 
-$(OBJDIR)/jskwgen.obj: jskwgen.cpp jskeyword.tbl
+GARBAGE	+= $(AUTO_HEADERS:$(OBJDIR)/jsauto%.h=$(OBJDIR)/js%gen.obj)
+
+$(AUTO_HEADERS): $(OBJDIR)/jsauto%.h: js%gen.cpp
 	@$(MAKE_OBJDIR)
 	$(CXX) -Fo$(OBJDIR)/ -c $(CFLAGS) $<
-
-$(OBJDIR)/jskwgen$(HOST_BIN_SUFFIX): $(OBJDIR)/jskwgen.$(OBJ_SUFFIX)
-	link.exe -out:"$@" $(EXE_LINK_FLAGS) $^
-
+	link.exe -out:"$(OBJDIR)/js$*gen$(HOST_BIN_SUFFIX)" $(EXE_LINK_FLAGS) $(OBJDIR)/js$*gen.obj
+	$(OBJDIR)/js$*gen$(HOST_BIN_SUFFIX) $@
 else
 
-$(OBJDIR)/jskwgen.o: jskwgen.cpp jskeyword.tbl
+$(AUTO_HEADERS): $(OBJDIR)/jsauto%.h: js%gen.cpp
 	@$(MAKE_OBJDIR)
-	$(CXX) -o $@ -c $(CFLAGS) $<
-
-$(OBJDIR)/jskwgen$(HOST_BIN_SUFFIX): $(OBJDIR)/jskwgen.$(OBJ_SUFFIX)
-	$(CXX) -o $@ $(CFLAGS) $(LDFLAGS) $^
+	$(CXX) -o $(OBJDIR)/js$*gen$(HOST_BIN_SUFFIX) $(CFLAGS) $(LDFLAGS) $<
+	$(OBJDIR)/js$*gen$(HOST_BIN_SUFFIX) $@
 
 endif
 
+# force creation of autoheaders before compiling any source that may use them
+$(LIB_OBJS) : $(AUTO_HEADERS)
+
 #
 # JS shell executable
 #
 
 ifdef USE_MSVC
 $(PROGRAM): $(PROG_OBJS) $(LIBRARY)
 	link.exe -out:"$@" $(EXE_LINK_FLAGS) $^
 else
--- a/js/src/SpiderMonkey.rsp
+++ b/js/src/SpiderMonkey.rsp
@@ -1,11 +1,10 @@
 mozilla/js/src/*
 mozilla/js/src/config/*
-mozilla/js/src/fdlibm/*
 mozilla/js/src/liveconnect/*
 mozilla/js/src/liveconnect/_jni/*
 mozilla/js/src/liveconnect/classes/*
 mozilla/js/src/liveconnect/classes/netscape/*
 mozilla/js/src/liveconnect/classes/netscape/javascript/*
 mozilla/js/src/liveconnect/config/*
 mozilla/js/src/liveconnect/macbuild/*
 mozilla/js/src/liveconnect/macbuild/JavaSession/*
--- a/js/src/build.mk
+++ b/js/src/build.mk
@@ -33,11 +33,10 @@
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
 TIERS += js
 
 tier_js_dirs += \
-	js/src/fdlibm \
 	js/src \
 	$(NULL)
deleted file mode 100644
--- a/js/src/fdlibm/Makefile.in
+++ /dev/null
@@ -1,127 +0,0 @@
-#
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is Mozilla Communicator client code, released
-# March 31, 1998.
-#
-# The Initial Developer of the Original Code is
-# Netscape Communications Corporation.
-# Portions created by the Initial Developer are Copyright (C) 1998
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either of the GNU General Public License Version 2 or later (the "GPL"),
-# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-DEPTH		= ../../..
-topsrcdir	= @top_srcdir@
-srcdir		= @srcdir@
-VPATH		= @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE		= js
-LIBRARY_NAME	= fdm
-
-CSRCS		= \
-		e_acos.c \
-		e_asin.c \
-		e_atan2.c \
-		e_exp.c \
-		e_fmod.c \
-		e_log.c \
-		e_pow.c \
-		e_rem_pio2.c \
-		s_scalbn.c \
-		e_sqrt.c \
-		k_cos.c \
-		k_sin.c \
-		k_rem_pio2.c \
-		k_tan.c \
-		s_atan.c \
-		s_ceil.c \
-		s_copysign.c \
-		s_cos.c \
-		s_fabs.c \
-		s_finite.c \
-		s_floor.c \
-		s_isnan.c \
-		s_lib_version.c \
-		s_sin.c \
-		s_tan.c \
-		w_acos.c \
-		w_asin.c \
-		w_atan2.c \
-		w_exp.c \
-		w_fmod.c \
-		w_log.c \
-		w_pow.c \
-		w_sqrt.c \
-		$(NULL)
-
-EXPORTS		= fdlibm.h
-
-# we need to force a static lib for the linking that js/src/Makefile.in wants
-# to do, and we don't really need a shared library ever, so:
-FORCE_STATIC_LIB = 1
-FORCE_USE_PIC = 1
-
-include $(topsrcdir)/config/rules.mk
-
-#
-# Default IEEE libm
-#
-CFLAGS		+= -D_IEEE_LIBM
-
-ifeq ($(OS_ARCH),Linux)
-LDFLAGS		+= -ldl
-endif
-
-ifeq ($(OS_ARCH),OSF1)
-LDFLAGS		+= -lc_r
-endif
-
-ifeq ($(OS_ARCH),SunOS)
-LDFLAGS		+= -lposix4 -ldl -lnsl -lsocket
-ifeq ($(CPU_ARCH),sparc)
-
-ifndef JS_NO_ULTRA
-ULTRA_OPTIONS	:= -xarch=v8plus,-DULTRA_SPARC
-ULTRA_OPTIONSCC	:= -DULTRA_SPARC
-else
-ULTRA_OPTIONS	:= -xarch=v8
-ULTRA_OPTIONSCC	:=
-endif
-
-ifeq ($(shell uname -m),sun4u)
-ASFLAGS		+= -Wa,$(ULTRA_OPTIONS),-P,-L,-D_ASM,-D__STDC__=0 $(ULTRA_OPTIONSCC)
-else
-ASFLAGS		+= -Wa,-xarch=v8,-P,-L,-D_ASM,-D__STDC__=0
-endif
-
-endif
-endif
-
deleted file mode 100644
--- a/js/src/fdlibm/Makefile.ref
+++ /dev/null
@@ -1,192 +0,0 @@
-# -*- Mode: makefile -*-
-#
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is Mozilla Communicator client code, released
-# March 31, 1998.
-#
-# The Initial Developer of the Original Code is
-# Sun Microsystems, Inc.
-# Portions created by the Initial Developer are Copyright (C) 1998
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either of the GNU General Public License Version 2 or later (the "GPL"),
-# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-#
-#  @(#)Makefile 1.4 95/01/18 
-# 
-#  ====================================================
-#  Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
-# 
-#  Developed at SunSoft, a Sun Microsystems, Inc. business.
-#  Permission to use, copy, modify, and distribute this
-#  software is freely granted, provided that this notice 
-#  is preserved.
-#  ====================================================
-# 
-# 
-
-#
-# There are two options in making libm at fdlibm compile time:
-#       _IEEE_LIBM      --- IEEE libm; smaller, and somewhat faster
-#       _MULTI_LIBM     --- Support multi-standard at runtime by 
-#                           imposing wrapper functions defined in 
-#                           fdlibm.h:
-#                               _IEEE_MODE      -- IEEE
-#                               _XOPEN_MODE     -- X/OPEN
-#                               _POSIX_MODE     -- POSIX/ANSI
-#                               _SVID3_MODE     -- SVID
-#
-# Here is how to set up CFLAGS to create the desired libm at 
-# compile time:
-#
-#       CFLAGS = -D_IEEE_LIBM           ... IEEE libm (recommended)
-#       CFLAGS = -D_SVID3_MODE  ... Multi-standard supported
-#                                           libm with SVID as the 
-#                                           default standard
-#       CFLAGS = -D_XOPEN_MODE  ... Multi-standard supported
-#                                           libm with XOPEN as the 
-#                                           default standard
-#       CFLAGS = -D_POSIX_MODE  ... Multi-standard supported
-#                                           libm with POSIX as the 
-#                                           default standard
-#       CFLAGS =                        ... Multi-standard supported
-#                                           libm with IEEE as the 
-#                                           default standard
-# 
-# NOTE: if scalb's second arguement is an int, then one must
-# define _SCALB_INT in CFLAGS. The default prototype of scalb
-# is double scalb(double, double)
-#
-
-DEPTH           = ..
-
-include $(DEPTH)/config.mk
-
-#
-# Default IEEE libm
-#
-CFLAGS          += -DXP_UNIX $(OPTIMIZER) $(OS_CFLAGS) $(DEFINES) $(INCLUDES) \
-		  -DJSFILE $(XCFLAGS) -D_IEEE_LIBM
-
-# Need for jstypes.h and friends
-INCLUDES += -I..
-INCLUDES += -I../$(OBJDIR)
-
-#CC = cc
-
-INCFILES = fdlibm.h
-.INIT: $(INCFILES)
-.KEEP_STATE:
-FDLIBM_CFILES =         \
-	k_standard.c k_rem_pio2.c \
-	k_cos.c k_sin.c k_tan.c \
-	e_acos.c e_acosh.c e_asin.c e_atan2.c \
-	e_atanh.c e_cosh.c e_exp.c e_fmod.c \
-	e_gamma.c e_gamma_r.c e_hypot.c e_j0.c \
-	e_j1.c e_jn.c e_lgamma.c e_lgamma_r.c \
-	e_log.c e_log10.c e_pow.c e_rem_pio2.c e_remainder.c \
-	e_scalb.c e_sinh.c e_sqrt.c \
-	w_acos.c w_acosh.c w_asin.c w_atan2.c \
-	w_atanh.c w_cosh.c w_exp.c w_fmod.c \
-	w_gamma.c w_gamma_r.c w_hypot.c w_j0.c \
-	w_j1.c w_jn.c w_lgamma.c w_lgamma_r.c \
-	w_log.c w_log10.c w_pow.c w_remainder.c \
-	w_scalb.c w_sinh.c w_sqrt.c \
-	s_asinh.c s_atan.c s_cbrt.c s_ceil.c s_copysign.c \
-	s_cos.c s_erf.c s_expm1.c s_fabs.c s_finite.c s_floor.c \
-	s_frexp.c s_ilogb.c s_isnan.c s_ldexp.c s_lib_version.c \
-	s_log1p.c s_logb.c s_matherr.c s_modf.c s_nextafter.c \
-	s_rint.c s_scalbn.c s_signgam.c s_significand.c s_sin.c \
-	s_tan.c s_tanh.c
-
-ifdef USE_MSVC
-FDLIBM_OBJS = $(addprefix $(OBJDIR)/, $(FDLIBM_CFILES:.c=.obj))
-else
-FDLIBM_OBJS = $(addprefix $(OBJDIR)/, $(FDLIBM_CFILES:.c=.o))
-endif
-
-ifdef USE_MSVC
-LIBRARY = $(OBJDIR)/fdlibm.lib
-else
-LIBRARY = $(OBJDIR)/libfdm.a
-endif
-
-define MAKE_OBJDIR
-if test ! -d $(@D); then rm -rf $(@D); mkdir -p $(@D); fi
-endef
-
-all: $(LIBRARY) 
-
-export:
-
-$(OBJDIR)/%: %.c
-	@$(MAKE_OBJDIR)
-	$(CC) -o $@ $(CFLAGS) $*.c $(LDFLAGS)
-
-$(OBJDIR)/%.o: %.c
-	@$(MAKE_OBJDIR)
-	$(CC) -o $@ -c $(CFLAGS) $*.c
-
-$(OBJDIR)/%.o: %.s
-	@$(MAKE_OBJDIR)
-	$(AS) -o $@ $(ASFLAGS) $*.s
-
-# windows only
-$(OBJDIR)/%.obj: %.c
-	@$(MAKE_OBJDIR)
-	$(CC) -Fo$(OBJDIR)/ -c $(CFLAGS) $*.c
-
-ifeq ($(OS_ARCH),OS2)
-$(LIBRARY): $(FDLIBM_OBJS)
-	$(AR) $@ $? $(AR_OS2_SUFFIX)
-	$(RANLIB) $@
-else
-ifdef USE_MSVC
-$(LIBRARY): $(FDLIBM_OBJS)
-	lib.exe /out:"$@" $?
-else
-$(LIBRARY): $(FDLIBM_OBJS)
-	$(AR) rv $@ $?
-	$(RANLIB) $@
-endif
-endif
-
-libfdm.a : $(FDLIBM_OBJS) 
-	$(AR) cru $(OBJDIR)/libfdm.a $(FDLIBM_OBJS)
-	$(RANLIB) $(OBJDIR)/libfdm.a
-
-clean:
-	rm -rf $(FDLIBM_OBJS)
-
-clobber:
-	rm -rf $(FDLIBM_OBJS) $(LIBRARY) $(DEPENDENCIES)
-
-SUFFIXES: .i
-%.i: %.c
-	$(CC) -C -E $(CFLAGS) $< > $*.i
deleted file mode 100644
--- a/js/src/fdlibm/e_acos.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_acos.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* __ieee754_acos(x)
- * Method :                  
- *	acos(x)  = pi/2 - asin(x)
- *	acos(-x) = pi/2 + asin(x)
- * For |x|<=0.5
- *	acos(x) = pi/2 - (x + x*x^2*R(x^2))	(see asin.c)
- * For x>0.5
- * 	acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2)))
- *		= 2asin(sqrt((1-x)/2))  
- *		= 2s + 2s*z*R(z) 	...z=(1-x)/2, s=sqrt(z)
- *		= 2f + (2c + 2s*z*R(z))
- *     where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term
- *     for f so that f+c ~ sqrt(z).
- * For x<-0.5
- *	acos(x) = pi - 2asin(sqrt((1-|x|)/2))
- *		= pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z)
- *
- * Special cases:
- *	if x is NaN, return x itself;
- *	if |x|>1, return NaN with invalid signal.
- *
- * Function needed: sqrt
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double 
-#else
-static double 
-#endif
-one=  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
-pi =  3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
-pio2_hi =  1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
-pio2_lo =  6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
-pS0 =  1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
-pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
-pS2 =  2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
-pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
-pS4 =  7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
-pS5 =  3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
-qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
-qS2 =  2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
-qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
-qS4 =  7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
-
-#ifdef __STDC__
-	double __ieee754_acos(double x)
-#else
-	double __ieee754_acos(x)
-	double x;
-#endif
-{
-        fd_twoints u;
-        double df;
-	double z,p,q,r,w,s,c;
-	int hx,ix;
-        u.d = x;
-	hx = __HI(u);
-	ix = hx&0x7fffffff;
-	if(ix>=0x3ff00000) {	/* |x| >= 1 */
-	    if(((ix-0x3ff00000)|__LO(u))==0) {	/* |x|==1 */
-		if(hx>0) return 0.0;		/* acos(1) = 0  */
-		else return pi+2.0*pio2_lo;	/* acos(-1)= pi */
-	    }
-	    return (x-x)/(x-x);		/* acos(|x|>1) is NaN */
-	}
-	if(ix<0x3fe00000) {	/* |x| < 0.5 */
-	    if(ix<=0x3c600000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/
-	    z = x*x;
-	    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
-	    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
-	    r = p/q;
-	    return pio2_hi - (x - (pio2_lo-x*r));
-	} else  if (hx<0) {		/* x < -0.5 */
-	    z = (one+x)*0.5;
-	    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
-	    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
-	    s = fd_sqrt(z);
-	    r = p/q;
-	    w = r*s-pio2_lo;
-	    return pi - 2.0*(s+w);
-	} else {			/* x > 0.5 */
-	    z = (one-x)*0.5;
-	    s = fd_sqrt(z);
-	    u.d = s;
-	    __LO(u) = 0;
-            df = u.d;
-	    c  = (z-df*df)/(s+df);
-	    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
-	    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
-	    r = p/q;
-	    w = r*s+c;
-	    return 2.0*(df+w);
-	}
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_acosh.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_acosh.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- *
- */
-
-/* __ieee754_acosh(x)
- * Method :
- *	Based on 
- *		acosh(x) = log [ x + sqrt(x*x-1) ]
- *	we have
- *		acosh(x) := log(x)+ln2,	if x is large; else
- *		acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
- *		acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
- *
- * Special cases:
- *	acosh(x) is NaN with signal if x<1.
- *	acosh(NaN) is NaN without signal.
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double 
-#else
-static double 
-#endif
-one	= 1.0,
-ln2	= 6.93147180559945286227e-01;  /* 0x3FE62E42, 0xFEFA39EF */
-
-#ifdef __STDC__
-	double __ieee754_acosh(double x)
-#else
-	double __ieee754_acosh(x)
-	double x;
-#endif
-{	
-        fd_twoints u;
-	double t;
-	int hx;
-        u.d = x;
-	hx = __HI(u);
-	if(hx<0x3ff00000) {		/* x < 1 */
-	    return (x-x)/(x-x);
-	} else if(hx >=0x41b00000) {	/* x > 2**28 */
-	    if(hx >=0x7ff00000) {	/* x is inf of NaN */
-	        return x+x;
-	    } else 
-		return __ieee754_log(x)+ln2;	/* acosh(huge)=log(2x) */
-	} else if(((hx-0x3ff00000)|__LO(u))==0) {
-	    return 0.0;			/* acosh(1) = 0 */
-	} else if (hx > 0x40000000) {	/* 2**28 > x > 2 */
-	    t=x*x;
-	    return __ieee754_log(2.0*x-one/(x+fd_sqrt(t-one)));
-	} else {			/* 1<x<2 */
-	    t = x-one;
-	    return fd_log1p(t+fd_sqrt(2.0*t+t*t));
-	}
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_asin.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_asin.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* __ieee754_asin(x)
- * Method :                  
- *	Since  asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ...
- *	we approximate asin(x) on [0,0.5] by
- *		asin(x) = x + x*x^2*R(x^2)
- *	where
- *		R(x^2) is a rational approximation of (asin(x)-x)/x^3 
- *	and its remez error is bounded by
- *		|(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75)
- *
- *	For x in [0.5,1]
- *		asin(x) = pi/2-2*asin(sqrt((1-x)/2))
- *	Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2;
- *	then for x>0.98
- *		asin(x) = pi/2 - 2*(s+s*z*R(z))
- *			= pio2_hi - (2*(s+s*z*R(z)) - pio2_lo)
- *	For x<=0.98, let pio4_hi = pio2_hi/2, then
- *		f = hi part of s;
- *		c = sqrt(z) - f = (z-f*f)/(s+f) 	...f+c=sqrt(z)
- *	and
- *		asin(x) = pi/2 - 2*(s+s*z*R(z))
- *			= pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo)
- *			= pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))
- *
- * Special cases:
- *	if x is NaN, return x itself;
- *	if |x|>1, return NaN with invalid signal.
- *
- */
-
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double 
-#else
-static double 
-#endif
-one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
-really_big =  1.000e+300,
-pio2_hi =  1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
-pio2_lo =  6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
-pio4_hi =  7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
-	/* coefficient for R(x^2) */
-pS0 =  1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
-pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
-pS2 =  2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
-pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
-pS4 =  7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
-pS5 =  3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
-qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
-qS2 =  2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
-qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
-qS4 =  7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
-
-#ifdef __STDC__
-	double __ieee754_asin(double x)
-#else
-	double __ieee754_asin(x)
-	double x;
-#endif
-{
-        fd_twoints u;
-	double w,t,p,q,c,r,s;
-	int hx,ix;
-        u.d = x;
-	hx = __HI(u);
-        x = u.d;
-	ix = hx&0x7fffffff;
-	if(ix>= 0x3ff00000) {		/* |x|>= 1 */
-	    if(((ix-0x3ff00000)|__LO(u))==0)
-		    /* asin(1)=+-pi/2 with inexact */
-		return x*pio2_hi+x*pio2_lo;	
-	    return (x-x)/(x-x);		/* asin(|x|>1) is NaN */   
-	} else if (ix<0x3fe00000) {	/* |x|<0.5 */
-	    if(ix<0x3e400000) {		/* if |x| < 2**-27 */
-		if(really_big+x>one) return x;/* return x with inexact if x!=0*/
-	    } else 
-		t = x*x;
-		p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
-		q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
-		w = p/q;
-		return x+x*w;
-	}
-	/* 1> |x|>= 0.5 */
-	w = one-fd_fabs(x);
-	t = w*0.5;
-	p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
-	q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
-	s = fd_sqrt(t);
-	if(ix>=0x3FEF3333) { 	/* if |x| > 0.975 */
-	    w = p/q;
-	    t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
-	} else {
-	    u.d  = s;
-	    __LO(u) = 0;
-            w = u.d;
-	    c  = (t-w*w)/(s+w);
-	    r  = p/q;
-	    p  = 2.0*s*r-(pio2_lo-2.0*c);
-	    q  = pio4_hi-2.0*w;
-	    t  = pio4_hi-(p-q);
-	}    
-	if(hx>0) return t; else return -t;    
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_atan2.c
+++ /dev/null
@@ -1,165 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_atan2.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- *
- */
-
-/* __ieee754_atan2(y,x)
- * Method :
- *	1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
- *	2. Reduce x to positive by (if x and y are unexceptional): 
- *		ARG (x+iy) = arctan(y/x)   	   ... if x > 0,
- *		ARG (x+iy) = pi - arctan[y/(-x)]   ... if x < 0,
- *
- * Special cases:
- *
- *	ATAN2((anything), NaN ) is NaN;
- *	ATAN2(NAN , (anything) ) is NaN;
- *	ATAN2(+-0, +(anything but NaN)) is +-0  ;
- *	ATAN2(+-0, -(anything but NaN)) is +-pi ;
- *	ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
- *	ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
- *	ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
- *	ATAN2(+-INF,+INF ) is +-pi/4 ;
- *	ATAN2(+-INF,-INF ) is +-3pi/4;
- *	ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
- *
- * Constants:
- * The hexadecimal values are the intended ones for the following 
- * constants. The decimal values may be used, provided that the 
- * compiler will convert from decimal to binary accurately enough 
- * to produce the hexadecimal values shown.
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double 
-#else
-static double 
-#endif
-tiny  = 1.0e-300,
-zero  = 0.0,
-pi_o_4  = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */
-pi_o_2  = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */
-pi      = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */
-pi_lo   = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
-
-#ifdef __STDC__
-	double __ieee754_atan2(double y, double x)
-#else
-	double __ieee754_atan2(y,x)
-	double  y,x;
-#endif
-{  
-        fd_twoints ux, uy, uz;
-	double z;
-	int k,m,hx,hy,ix,iy;
-	unsigned lx,ly;
-
-        ux.d = x; uy.d = y;
-	hx = __HI(ux); ix = hx&0x7fffffff;
-	lx = __LO(ux);
-	hy = __HI(uy); iy = hy&0x7fffffff;
-	ly = __LO(uy);
-	if(((ix|((lx|-(int)lx)>>31))>0x7ff00000)||
-	   ((iy|((ly|-(int)ly)>>31))>0x7ff00000))	/* x or y is NaN */
-	   return x+y;
-	if(((hx-0x3ff00000)|lx)==0) return fd_atan(y);   /* x=1.0 */
-	m = ((hy>>31)&1)|((hx>>30)&2);	/* 2*sign(x)+sign(y) */
-
-    /* when y = 0 */
-	if((iy|ly)==0) {
-	    switch(m) {
-		case 0: 
-		case 1: return y; 	/* atan(+-0,+anything)=+-0 */
-		case 2: return  pi+tiny;/* atan(+0,-anything) = pi */
-		case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
-	    }
-	}
-    /* when x = 0 */
-	if((ix|lx)==0) return (hy<0)?  -pi_o_2-tiny: pi_o_2+tiny;
-	    
-    /* when x is INF */
-	if(ix==0x7ff00000) {
-	    if(iy==0x7ff00000) {
-		switch(m) {
-		    case 0: return  pi_o_4+tiny;/* atan(+INF,+INF) */
-		    case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
-		    case 2: return  3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
-		    case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
-		}
-	    } else {
-		switch(m) {
-		    case 0: return  zero  ;	/* atan(+...,+INF) */
-		    case 1: return -zero  ;	/* atan(-...,+INF) */
-		    case 2: return  pi+tiny  ;	/* atan(+...,-INF) */
-		    case 3: return -pi-tiny  ;	/* atan(-...,-INF) */
-		}
-	    }
-	}
-    /* when y is INF */
-	if(iy==0x7ff00000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
-
-    /* compute y/x */
-	k = (iy-ix)>>20;
-	if(k > 60) z=pi_o_2+0.5*pi_lo; 	/* |y/x| >  2**60 */
-	else if(hx<0&&k<-60) z=0.0; 	/* |y|/x < -2**60 */
-	else z=fd_atan(fd_fabs(y/x));		/* safe to do y/x */
-	switch (m) {
-	    case 0: return       z  ;	/* atan(+,+) */
-	    case 1: uz.d = z;
-                    __HI(uz) ^= 0x80000000;
-                    z = uz.d;
-		    return       z  ;	/* atan(-,+) */
-	    case 2: return  pi-(z-pi_lo);/* atan(+,-) */
-	    default: /* case 3 */
-	    	    return  (z-pi_lo)-pi;/* atan(-,-) */
-	}
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_atanh.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_atanh.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- *
- */
-
-/* __ieee754_atanh(x)
- * Method :
- *    1.Reduced x to positive by atanh(-x) = -atanh(x)
- *    2.For x>=0.5
- *                  1              2x                          x
- *	atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
- *                  2             1 - x                      1 - x
- *	
- * 	For x<0.5
- *	atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
- *
- * Special cases:
- *	atanh(x) is NaN if |x| > 1 with signal;
- *	atanh(NaN) is that NaN with no signal;
- *	atanh(+-1) is +-INF with signal.
- *
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double one = 1.0, really_big = 1e300;
-#else
-static double one = 1.0, really_big = 1e300;
-#endif
-
-static double zero = 0.0;
-
-#ifdef __STDC__
-	double __ieee754_atanh(double x)
-#else
-	double __ieee754_atanh(x)
-	double x;
-#endif
-{
-	double t;
-	int hx,ix;
-	unsigned lx;
-        fd_twoints u;
-        u.d = x;
-	hx = __HI(u);		/* high word */
-	lx = __LO(u);		/* low word */
-	ix = hx&0x7fffffff;
-	if ((ix|((lx|(-(int)lx))>>31))>0x3ff00000) /* |x|>1 */
-	    return (x-x)/(x-x);
-	if(ix==0x3ff00000) 
-	    return x/zero;
-	if(ix<0x3e300000&&(really_big+x)>zero) return x;	/* x<2**-28 */
-        u.d = x;
-	__HI(u) = ix;		/* x <- |x| */
-        x = u.d;
-	if(ix<0x3fe00000) {		/* x < 0.5 */
-	    t = x+x;
-	    t = 0.5*fd_log1p(t+t*x/(one-x));
-	} else 
-	    t = 0.5*fd_log1p((x+x)/(one-x));
-	if(hx>=0) return t; else return -t;
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_cosh.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_cosh.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* __ieee754_cosh(x)
- * Method : 
- * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
- *	1. Replace x by |x| (cosh(x) = cosh(-x)). 
- *	2. 
- *		                                        [ exp(x) - 1 ]^2 
- *	    0        <= x <= ln2/2  :  cosh(x) := 1 + -------------------
- *			       			           2*exp(x)
- *
- *		                                  exp(x) +  1/exp(x)
- *	    ln2/2    <= x <= 22     :  cosh(x) := -------------------
- *			       			          2
- *	    22       <= x <= lnovft :  cosh(x) := exp(x)/2 
- *	    lnovft   <= x <= ln2ovft:  cosh(x) := exp(x/2)/2 * exp(x/2)
- *	    ln2ovft  <  x	    :  cosh(x) := huge*huge (overflow)
- *
- * Special cases:
- *	cosh(x) is |x| if x is +INF, -INF, or NaN.
- *	only cosh(0)=1 is exact for finite x.
- */
-
-#include "fdlibm.h"
-
-#ifdef _WIN32
-#define huge myhuge
-#endif
-
-#ifdef __STDC__
-static const double one = 1.0, half=0.5, really_big = 1.0e300;
-#else
-static double one = 1.0, half=0.5, really_big = 1.0e300;
-#endif
-
-#ifdef __STDC__
-	double __ieee754_cosh(double x)
-#else
-	double __ieee754_cosh(x)
-	double x;
-#endif
-{	
-        fd_twoints u;
-	double t,w;
-	int ix;
-	unsigned lx;
-        
-    /* High word of |x|. */
-        u.d = x;
-	ix = __HI(u);
-	ix &= 0x7fffffff;
-
-    /* x is INF or NaN */
-	if(ix>=0x7ff00000) return x*x;	
-
-    /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
-	if(ix<0x3fd62e43) {
-	    t = fd_expm1(fd_fabs(x));
-	    w = one+t;
-	    if (ix<0x3c800000) return w;	/* cosh(tiny) = 1 */
-	    return one+(t*t)/(w+w);
-	}
-
-    /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
-	if (ix < 0x40360000) {
-		t = __ieee754_exp(fd_fabs(x));
-		return half*t+half/t;
-	}
-
-    /* |x| in [22, log(maxdouble)] return half*exp(|x|) */
-	if (ix < 0x40862E42)  return half*__ieee754_exp(fd_fabs(x));
-
-    /* |x| in [log(maxdouble), overflowthresold] */
-	lx = *( (((*(unsigned*)&one)>>29)) + (unsigned*)&x);
-	if (ix<0x408633CE || 
-	      (ix==0x408633ce)&&(lx<=(unsigned)0x8fb9f87d)) {
-	    w = __ieee754_exp(half*fd_fabs(x));
-	    t = half*w;
-	    return t*w;
-	}
-
-    /* |x| > overflowthresold, cosh(x) overflow */
-	return really_big*really_big;
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_exp.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_exp.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* __ieee754_exp(x)
- * Returns the exponential of x.
- *
- * Method
- *   1. Argument reduction:
- *      Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658.
- *	Given x, find r and integer k such that
- *
- *               x = k*ln2 + r,  |r| <= 0.5*ln2.  
- *
- *      Here r will be represented as r = hi-lo for better 
- *	accuracy.
- *
- *   2. Approximation of exp(r) by a special rational function on
- *	the interval [0,0.34658]:
- *	Write
- *	    R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ...
- *      We use a special Reme algorithm on [0,0.34658] to generate 
- * 	a polynomial of degree 5 to approximate R. The maximum error 
- *	of this polynomial approximation is bounded by 2**-59. In
- *	other words,
- *	    R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5
- *  	(where z=r*r, and the values of P1 to P5 are listed below)
- *	and
- *	    |                  5          |     -59
- *	    | 2.0+P1*z+...+P5*z   -  R(z) | <= 2 
- *	    |                             |
- *	The computation of exp(r) thus becomes
- *                             2*r
- *		exp(r) = 1 + -------
- *		              R - r
- *                                 r*R1(r)	
- *		       = 1 + r + ----------- (for better accuracy)
- *		                  2 - R1(r)
- *	where
- *			         2       4             10
- *		R1(r) = r - (P1*r  + P2*r  + ... + P5*r   ).
- *	
- *   3. Scale back to obtain exp(x):
- *	From step 1, we have
- *	   exp(x) = 2^k * exp(r)
- *
- * Special cases:
- *	exp(INF) is INF, exp(NaN) is NaN;
- *	exp(-INF) is 0, and
- *	for finite argument, only exp(0)=1 is exact.
- *
- * Accuracy:
- *	according to an error analysis, the error is always less than
- *	1 ulp (unit in the last place).
- *
- * Misc. info.
- *	For IEEE double 
- *	    if x >  7.09782712893383973096e+02 then exp(x) overflow
- *	    if x < -7.45133219101941108420e+02 then exp(x) underflow
- *
- * Constants:
- * The hexadecimal values are the intended ones for the following 
- * constants. The decimal values may be used, provided that the 
- * compiler will convert from decimal to binary accurately enough
- * to produce the hexadecimal values shown.
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double
-#else
-static double
-#endif
-one	= 1.0,
-halF[2]	= {0.5,-0.5,},
-really_big	= 1.0e+300,
-twom1000= 9.33263618503218878990e-302,     /* 2**-1000=0x01700000,0*/
-o_threshold=  7.09782712893383973096e+02,  /* 0x40862E42, 0xFEFA39EF */
-u_threshold= -7.45133219101941108420e+02,  /* 0xc0874910, 0xD52D3051 */
-ln2HI[2]   ={ 6.93147180369123816490e-01,  /* 0x3fe62e42, 0xfee00000 */
-	     -6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */
-ln2LO[2]   ={ 1.90821492927058770002e-10,  /* 0x3dea39ef, 0x35793c76 */
-	     -1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */
-invln2 =  1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */
-P1   =  1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
-P2   = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
-P3   =  6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
-P4   = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
-P5   =  4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
-
-
-#ifdef __STDC__
-	double __ieee754_exp(double x)	/* default IEEE double exp */
-#else
-	double __ieee754_exp(x)	/* default IEEE double exp */
-	double x;
-#endif
-{
-        fd_twoints u;
-	double y,hi,lo,c,t;
-	int k, xsb;
-	unsigned hx;
-
-        u.d = x;
-	hx  = __HI(u);	/* high word of x */
-	xsb = (hx>>31)&1;		/* sign bit of x */
-	hx &= 0x7fffffff;		/* high word of |x| */
-
-    /* filter out non-finite argument */
-	if(hx >= 0x40862E42) {			/* if |x|>=709.78... */
-            if(hx>=0x7ff00000) {
-                u.d = x;
-		if(((hx&0xfffff)|__LO(u))!=0)
-		     return x+x; 		/* NaN */
-		else return (xsb==0)? x:0.0;	/* exp(+-inf)={inf,0} */
-	    }
-	    if(x > o_threshold) return really_big*really_big; /* overflow */
-	    if(x < u_threshold) return twom1000*twom1000; /* underflow */
-	}
-
-    /* argument reduction */
-	if(hx > 0x3fd62e42) {		/* if  |x| > 0.5 ln2 */ 
-	    if(hx < 0x3FF0A2B2) {	/* and |x| < 1.5 ln2 */
-		hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
-	    } else {
-		k  = (int)(invln2*x+halF[xsb]);
-		t  = k;
-		hi = x - t*ln2HI[0];	/* t*ln2HI is exact here */
-		lo = t*ln2LO[0];
-	    }
-	    x  = hi - lo;
-	} 
-	else if(hx < 0x3e300000)  {	/* when |x|<2**-28 */
-	    if(really_big+x>one) return one+x;/* trigger inexact */
-	}
-	else k = 0;
-
-    /* x is now in primary range */
-	t  = x*x;
-	c  = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
-	if(k==0) 	return one-((x*c)/(c-2.0)-x); 
-	else 		y = one-((lo-(x*c)/(2.0-c))-hi);
-	if(k >= -1021) {
-            u.d = y;
-	    __HI(u) += (k<<20);	/* add k to y's exponent */
-            y = u.d;
-	    return y;
-	} else {
-            u.d = y;
-	    __HI(u) += ((k+1000)<<20);/* add k to y's exponent */
-            y = u.d;
-	    return y*twom1000;
-	}
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_fmod.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_fmod.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* 
- * __ieee754_fmod(x,y)
- * Return x mod y in exact arithmetic
- * Method: shift and subtract
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double one = 1.0, Zero[] = {0.0, -0.0,};
-#else
-static double one = 1.0, Zero[] = {0.0, -0.0,};
-#endif
-
-#ifdef __STDC__
-	double __ieee754_fmod(double x, double y)
-#else
-	double __ieee754_fmod(x,y)
-	double x,y ;
-#endif
-{
-        fd_twoints ux, uy;
-	int n,hx,hy,hz,ix,iy,sx,i;
-	unsigned lx,ly,lz;
-
-        ux.d = x; uy.d = y;
-	hx = __HI(ux);		/* high word of x */
-	lx = __LO(ux);		/* low  word of x */
-	hy = __HI(uy);		/* high word of y */
-	ly = __LO(uy);		/* low  word of y */
-	sx = hx&0x80000000;		/* sign of x */
-	hx ^=sx;		/* |x| */
-	hy &= 0x7fffffff;	/* |y| */
-
-    /* purge off exception values */
-	if((hy|ly)==0||(hx>=0x7ff00000)||	/* y=0,or x not finite */
-	  ((hy|((ly|-(int)ly)>>31))>0x7ff00000))	/* or y is NaN */
-	    return (x*y)/(x*y);
-	if(hx<=hy) {
-	    if((hx<hy)||(lx<ly)) return x;	/* |x|<|y| return x */
-	    if(lx==ly) 
-		return Zero[(unsigned)sx>>31];	/* |x|=|y| return x*0*/
-	}
-
-    /* determine ix = ilogb(x) */
-	if(hx<0x00100000) {	/* subnormal x */
-	    if(hx==0) {
-		for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
-	    } else {
-		for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
-	    }
-	} else ix = (hx>>20)-1023;
-
-    /* determine iy = ilogb(y) */
-	if(hy<0x00100000) {	/* subnormal y */
-	    if(hy==0) {
-		for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
-	    } else {
-		for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
-	    }
-	} else iy = (hy>>20)-1023;
-
-    /* set up {hx,lx}, {hy,ly} and align y to x */
-	if(ix >= -1022) 
-	    hx = 0x00100000|(0x000fffff&hx);
-	else {		/* subnormal x, shift x to normal */
-	    n = -1022-ix;
-	    if(n<=31) {
-	        hx = (hx<<n)|(lx>>(32-n));
-	        lx <<= n;
-	    } else {
-		hx = lx<<(n-32);
-		lx = 0;
-	    }
-	}
-	if(iy >= -1022) 
-	    hy = 0x00100000|(0x000fffff&hy);
-	else {		/* subnormal y, shift y to normal */
-	    n = -1022-iy;
-	    if(n<=31) {
-	        hy = (hy<<n)|(ly>>(32-n));
-	        ly <<= n;
-	    } else {
-		hy = ly<<(n-32);
-		ly = 0;
-	    }
-	}
-
-    /* fix point fmod */
-	n = ix - iy;
-	while(n--) {
-	    hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
-	    if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
-	    else {
-	    	if((hz|lz)==0) 		/* return sign(x)*0 */
-		    return Zero[(unsigned)sx>>31];
-	    	hx = hz+hz+(lz>>31); lx = lz+lz;
-	    }
-	}
-	hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
-	if(hz>=0) {hx=hz;lx=lz;}
-
-    /* convert back to floating value and restore the sign */
-	if((hx|lx)==0) 			/* return sign(x)*0 */
-	    return Zero[(unsigned)sx>>31];	
-	while(hx<0x00100000) {		/* normalize x */
-	    hx = hx+hx+(lx>>31); lx = lx+lx;
-	    iy -= 1;
-	}
-	if(iy>= -1022) {	/* normalize output */
-	    hx = ((hx-0x00100000)|((iy+1023)<<20));
-            ux.d = x;
-	    __HI(ux) = hx|sx;
-	    __LO(ux) = lx;
-            x = ux.d;
-	} else {		/* subnormal output */
-	    n = -1022 - iy;
-	    if(n<=20) {
-		lx = (lx>>n)|((unsigned)hx<<(32-n));
-		hx >>= n;
-	    } else if (n<=31) {
-		lx = (hx<<(32-n))|(lx>>n); hx = sx;
-	    } else {
-		lx = hx>>(n-32); hx = sx;
-	    }
-            ux.d = x;
-	    __HI(ux) = hx|sx;
-	    __LO(ux) = lx;
-            x = ux.d;
-	    x *= one;		/* create necessary signal */
-	}
-	return x;		/* exact output */
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_gamma.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_gamma.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- *
- */
-
-/* __ieee754_gamma(x)
- * Return the logarithm of the Gamma function of x.
- *
- * Method: call __ieee754_gamma_r
- */
-
-#include "fdlibm.h"
-
-extern int signgam;
-
-#ifdef __STDC__
-	double __ieee754_gamma(double x)
-#else
-	double __ieee754_gamma(x)
-	double x;
-#endif
-{
-	return __ieee754_gamma_r(x,&signgam);
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_gamma_r.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_gamma_r.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- *
- */
-
-/* __ieee754_gamma_r(x, signgamp)
- * Reentrant version of the logarithm of the Gamma function 
- * with user provide pointer for the sign of Gamma(x). 
- *
- * Method: See __ieee754_lgamma_r
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-	double __ieee754_gamma_r(double x, int *signgamp)
-#else
-	double __ieee754_gamma_r(x,signgamp)
-	double x; int *signgamp;
-#endif
-{
-	return __ieee754_lgamma_r(x,signgamp);
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_hypot.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_hypot.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* __ieee754_hypot(x,y)
- *
- * Method :                  
- *	If (assume round-to-nearest) z=x*x+y*y 
- *	has error less than sqrt(2)/2 ulp, than 
- *	sqrt(z) has error less than 1 ulp (exercise).
- *
- *	So, compute sqrt(x*x+y*y) with some care as 
- *	follows to get the error below 1 ulp:
- *
- *	Assume x>y>0;
- *	(if possible, set rounding to round-to-nearest)
- *	1. if x > 2y  use
- *		x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y
- *	where x1 = x with lower 32 bits cleared, x2 = x-x1; else
- *	2. if x <= 2y use
- *		t1*y1+((x-y)*(x-y)+(t1*y2+t2*y))
- *	where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1, 
- *	y1= y with lower 32 bits chopped, y2 = y-y1.
- *		
- *	NOTE: scaling may be necessary if some argument is too 
- *	      large or too tiny
- *
- * Special cases:
- *	hypot(x,y) is INF if x or y is +INF or -INF; else
- *	hypot(x,y) is NAN if x or y is NAN.
- *
- * Accuracy:
- * 	hypot(x,y) returns sqrt(x^2+y^2) with error less 
- * 	than 1 ulps (units in the last place) 
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-	double __ieee754_hypot(double x, double y)
-#else
-	double __ieee754_hypot(x,y)
-	double x, y;
-#endif
-{
-        fd_twoints ux, uy;
-	double a=x,b=y,t1,t2,y1,y2,w;
-	int j,k,ha,hb;
-        
-        ux.d = x; uy.d = y;
-	ha = __HI(ux)&0x7fffffff;	/* high word of  x */
-	hb = __HI(uy)&0x7fffffff;	/* high word of  y */
-	if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
-        ux.d = a; uy.d = b;
-	__HI(ux) = ha;	/* a <- |a| */
-	__HI(uy) = hb;	/* b <- |b| */
-        a = ux.d; b = uy.d;
-	if((ha-hb)>0x3c00000) {return a+b;} /* x/y > 2**60 */
-	k=0;
-	if(ha > 0x5f300000) {	/* a>2**500 */
-	   if(ha >= 0x7ff00000) {	/* Inf or NaN */
-	       w = a+b;			/* for sNaN */
-               ux.d = a; uy.d = b;
-	       if(((ha&0xfffff)|__LO(ux))==0) w = a;
-	       if(((hb^0x7ff00000)|__LO(uy))==0) w = b;
-	       return w;
-	   }
-	   /* scale a and b by 2**-600 */
-	   ha -= 0x25800000; hb -= 0x25800000;	k += 600;
-           ux.d = a; uy.d = b;
-	   __HI(ux) = ha;
-	   __HI(uy) = hb;
-           a = ux.d; b = uy.d;
-	}
-	if(hb < 0x20b00000) {	/* b < 2**-500 */
-	    if(hb <= 0x000fffff) {	/* subnormal b or 0 */	
-                uy.d = b;
-		if((hb|(__LO(uy)))==0) return a;
-		t1=0;
-                ux.d = t1;
-		__HI(ux) = 0x7fd00000;	/* t1=2^1022 */
-                t1 = ux.d;
-		b *= t1;
-		a *= t1;
-		k -= 1022;
-	    } else {		/* scale a and b by 2^600 */
-	        ha += 0x25800000; 	/* a *= 2^600 */
-		hb += 0x25800000;	/* b *= 2^600 */
-		k -= 600;
-                ux.d = a; uy.d = b;
-	   	__HI(ux) = ha;
-	   	__HI(uy) = hb;
-                a = ux.d; b = uy.d;
-	    }
-	}
-    /* medium size a and b */
-	w = a-b;
-	if (w>b) {
-	    t1 = 0;
-            ux.d = t1;
-	    __HI(ux) = ha;
-            t1 = ux.d;
-	    t2 = a-t1;
-	    w  = fd_sqrt(t1*t1-(b*(-b)-t2*(a+t1)));
-	} else {
-	    a  = a+a;
-	    y1 = 0;
-            ux.d = y1;
-	    __HI(ux) = hb;
-            y1 = ux.d;
-	    y2 = b - y1;
-	    t1 = 0;
-            ux.d = t1;
-	    __HI(ux) = ha+0x00100000;
-            t1 = ux.d;
-	    t2 = a - t1;
-	    w  = fd_sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b)));
-	}
-	if(k!=0) {
-	    t1 = 1.0;
-            ux.d = t1;
-	    __HI(ux) += (k<<20);
-            t1 = ux.d;
-	    return t1*w;
-	} else return w;
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_j0.c
+++ /dev/null
@@ -1,524 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_j0.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* __ieee754_j0(x), __ieee754_y0(x)
- * Bessel function of the first and second kinds of order zero.
- * Method -- j0(x):
- *	1. For tiny x, we use j0(x) = 1 - x^2/4 + x^4/64 - ...
- *	2. Reduce x to |x| since j0(x)=j0(-x),  and
- *	   for x in (0,2)
- *		j0(x) = 1-z/4+ z^2*R0/S0,  where z = x*x;
- *	   (precision:  |j0-1+z/4-z^2R0/S0 |<2**-63.67 )
- *	   for x in (2,inf)
- * 		j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0))
- * 	   where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
- *	   as follow:
- *		cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
- *			= 1/sqrt(2) * (cos(x) + sin(x))
- *		sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/4)
- *			= 1/sqrt(2) * (sin(x) - cos(x))
- * 	   (To avoid cancellation, use
- *		sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
- * 	    to compute the worse one.)
- *	   
- *	3 Special cases
- *		j0(nan)= nan
- *		j0(0) = 1
- *		j0(inf) = 0
- *		
- * Method -- y0(x):
- *	1. For x<2.
- *	   Since 
- *		y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...)
- *	   therefore y0(x)-2/pi*j0(x)*ln(x) is an even function.
- *	   We use the following function to approximate y0,
- *		y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2
- *	   where 
- *		U(z) = u00 + u01*z + ... + u06*z^6
- *		V(z) = 1  + v01*z + ... + v04*z^4
- *	   with absolute approximation error bounded by 2**-72.
- *	   Note: For tiny x, U/V = u0 and j0(x)~1, hence
- *		y0(tiny) = u0 + (2/pi)*ln(tiny), (choose tiny<2**-27)
- *	2. For x>=2.
- * 		y0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)+q0(x)*sin(x0))
- * 	   where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
- *	   by the method mentioned above.
- *	3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0.
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static double pzero(double), qzero(double);
-#else
-static double pzero(), qzero();
-#endif
-
-#ifdef __STDC__
-static const double 
-#else
-static double 
-#endif
-really_big 	= 1e300,
-one	= 1.0,
-invsqrtpi=  5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
-tpi      =  6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
- 		/* R0/S0 on [0, 2.00] */
-R02  =  1.56249999999999947958e-02, /* 0x3F8FFFFF, 0xFFFFFFFD */
-R03  = -1.89979294238854721751e-04, /* 0xBF28E6A5, 0xB61AC6E9 */
-R04  =  1.82954049532700665670e-06, /* 0x3EBEB1D1, 0x0C503919 */
-R05  = -4.61832688532103189199e-09, /* 0xBE33D5E7, 0x73D63FCE */
-S01  =  1.56191029464890010492e-02, /* 0x3F8FFCE8, 0x82C8C2A4 */
-S02  =  1.16926784663337450260e-04, /* 0x3F1EA6D2, 0xDD57DBF4 */
-S03  =  5.13546550207318111446e-07, /* 0x3EA13B54, 0xCE84D5A9 */
-S04  =  1.16614003333790000205e-09; /* 0x3E1408BC, 0xF4745D8F */
-
-static double zero = 0.0;
-
-#ifdef __STDC__
-	double __ieee754_j0(double x) 
-#else
-	double __ieee754_j0(x) 
-	double x;
-#endif
-{
-        fd_twoints un;
-	double z, s,c,ss,cc,r,u,v;
-	int hx,ix;
-
-        un.d = x;
-	hx = __HI(un);
-	ix = hx&0x7fffffff;
-	if(ix>=0x7ff00000) return one/(x*x);
-	x = fd_fabs(x);
-	if(ix >= 0x40000000) {	/* |x| >= 2.0 */
-		s = fd_sin(x);
-		c = fd_cos(x);
-		ss = s-c;
-		cc = s+c;
-		if(ix<0x7fe00000) {  /* make sure x+x not overflow */
-		    z = -fd_cos(x+x);
-		    if ((s*c)<zero) cc = z/ss;
-		    else 	    ss = z/cc;
-		}
-	/*
-	 * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
-	 * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
-	 */
-		if(ix>0x48000000) z = (invsqrtpi*cc)/fd_sqrt(x);
-		else {
-		    u = pzero(x); v = qzero(x);
-		    z = invsqrtpi*(u*cc-v*ss)/fd_sqrt(x);
-		}
-		return z;
-	}
-	if(ix<0x3f200000) {	/* |x| < 2**-13 */
-	    if(really_big+x>one) {	/* raise inexact if x != 0 */
-	        if(ix<0x3e400000) return one;	/* |x|<2**-27 */
-	        else 	      return one - 0.25*x*x;
-	    }
-	}
-	z = x*x;
-	r =  z*(R02+z*(R03+z*(R04+z*R05)));
-	s =  one+z*(S01+z*(S02+z*(S03+z*S04)));
-	if(ix < 0x3FF00000) {	/* |x| < 1.00 */
-	    return one + z*(-0.25+(r/s));
-	} else {
-	    u = 0.5*x;
-	    return((one+u)*(one-u)+z*(r/s));
-	}
-}
-
-#ifdef __STDC__
-static const double
-#else
-static double
-#endif
-u00  = -7.38042951086872317523e-02, /* 0xBFB2E4D6, 0x99CBD01F */
-u01  =  1.76666452509181115538e-01, /* 0x3FC69D01, 0x9DE9E3FC */
-u02  = -1.38185671945596898896e-02, /* 0xBF8C4CE8, 0xB16CFA97 */
-u03  =  3.47453432093683650238e-04, /* 0x3F36C54D, 0x20B29B6B */
-u04  = -3.81407053724364161125e-06, /* 0xBECFFEA7, 0x73D25CAD */
-u05  =  1.95590137035022920206e-08, /* 0x3E550057, 0x3B4EABD4 */
-u06  = -3.98205194132103398453e-11, /* 0xBDC5E43D, 0x693FB3C8 */
-v01  =  1.27304834834123699328e-02, /* 0x3F8A1270, 0x91C9C71A */
-v02  =  7.60068627350353253702e-05, /* 0x3F13ECBB, 0xF578C6C1 */
-v03  =  2.59150851840457805467e-07, /* 0x3E91642D, 0x7FF202FD */
-v04  =  4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */
-
-#ifdef __STDC__
-	double __ieee754_y0(double x) 
-#else
-	double __ieee754_y0(x) 
-	double x;
-#endif
-{
-        fd_twoints un;
-	double z, s,c,ss,cc,u,v;
-	int hx,ix,lx;
-
-        un.d = x;
-        hx = __HI(un);
-        ix = 0x7fffffff&hx;
-        lx = __LO(un);
-    /* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0  */
-	if(ix>=0x7ff00000) return  one/(x+x*x); 
-        if((ix|lx)==0) return -one/zero;
-        if(hx<0) return zero/zero;
-        if(ix >= 0x40000000) {  /* |x| >= 2.0 */
-        /* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))
-         * where x0 = x-pi/4
-         *      Better formula:
-         *              cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
-         *                      =  1/sqrt(2) * (sin(x) + cos(x))
-         *              sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
-         *                      =  1/sqrt(2) * (sin(x) - cos(x))
-         * To avoid cancellation, use
-         *              sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
-         * to compute the worse one.
-         */
-                s = fd_sin(x);
-                c = fd_cos(x);
-                ss = s-c;
-                cc = s+c;
-	/*
-	 * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
-	 * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
-	 */
-                if(ix<0x7fe00000) {  /* make sure x+x not overflow */
-                    z = -fd_cos(x+x);
-                    if ((s*c)<zero) cc = z/ss;
-                    else            ss = z/cc;
-                }
-                if(ix>0x48000000) z = (invsqrtpi*ss)/fd_sqrt(x);
-                else {
-                    u = pzero(x); v = qzero(x);
-                    z = invsqrtpi*(u*ss+v*cc)/fd_sqrt(x);
-                }
-                return z;
-	}
-	if(ix<=0x3e400000) {	/* x < 2**-27 */
-	    return(u00 + tpi*__ieee754_log(x));
-	}
-	z = x*x;
-	u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06)))));
-	v = one+z*(v01+z*(v02+z*(v03+z*v04)));
-	return(u/v + tpi*(__ieee754_j0(x)*__ieee754_log(x)));
-}
-
-/* The asymptotic expansions of pzero is
- *	1 - 9/128 s^2 + 11025/98304 s^4 - ...,	where s = 1/x.
- * For x >= 2, We approximate pzero by
- * 	pzero(x) = 1 + (R/S)
- * where  R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10
- * 	  S = 1 + pS0*s^2 + ... + pS4*s^10
- * and
- *	| pzero(x)-1-R/S | <= 2  ** ( -60.26)
- */
-#ifdef __STDC__
-static const double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
-#else
-static double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
-#endif
-  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
- -7.03124999999900357484e-02, /* 0xBFB1FFFF, 0xFFFFFD32 */
- -8.08167041275349795626e+00, /* 0xC02029D0, 0xB44FA779 */
- -2.57063105679704847262e+02, /* 0xC0701102, 0x7B19E863 */
- -2.48521641009428822144e+03, /* 0xC0A36A6E, 0xCD4DCAFC */
- -5.25304380490729545272e+03, /* 0xC0B4850B, 0x36CC643D */
-};
-#ifdef __STDC__
-static const double pS8[5] = {
-#else
-static double pS8[5] = {
-#endif
-  1.16534364619668181717e+02, /* 0x405D2233, 0x07A96751 */
-  3.83374475364121826715e+03, /* 0x40ADF37D, 0x50596938 */
-  4.05978572648472545552e+04, /* 0x40E3D2BB, 0x6EB6B05F */
-  1.16752972564375915681e+05, /* 0x40FC810F, 0x8F9FA9BD */
-  4.76277284146730962675e+04, /* 0x40E74177, 0x4F2C49DC */
-};
-
-#ifdef __STDC__
-static const double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
-#else
-static double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
-#endif
- -1.14125464691894502584e-11, /* 0xBDA918B1, 0x47E495CC */
- -7.03124940873599280078e-02, /* 0xBFB1FFFF, 0xE69AFBC6 */
- -4.15961064470587782438e+00, /* 0xC010A370, 0xF90C6BBF */
- -6.76747652265167261021e+01, /* 0xC050EB2F, 0x5A7D1783 */
- -3.31231299649172967747e+02, /* 0xC074B3B3, 0x6742CC63 */
- -3.46433388365604912451e+02, /* 0xC075A6EF, 0x28A38BD7 */
-};
-#ifdef __STDC__
-static const double pS5[5] = {
-#else
-static double pS5[5] = {
-#endif
-  6.07539382692300335975e+01, /* 0x404E6081, 0x0C98C5DE */
-  1.05125230595704579173e+03, /* 0x40906D02, 0x5C7E2864 */
-  5.97897094333855784498e+03, /* 0x40B75AF8, 0x8FBE1D60 */
-  9.62544514357774460223e+03, /* 0x40C2CCB8, 0xFA76FA38 */
-  2.40605815922939109441e+03, /* 0x40A2CC1D, 0xC70BE864 */
-};
-
-#ifdef __STDC__
-static const double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
-#else
-static double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
-#endif
- -2.54704601771951915620e-09, /* 0xBE25E103, 0x6FE1AA86 */
- -7.03119616381481654654e-02, /* 0xBFB1FFF6, 0xF7C0E24B */
- -2.40903221549529611423e+00, /* 0xC00345B2, 0xAEA48074 */
- -2.19659774734883086467e+01, /* 0xC035F74A, 0x4CB94E14 */
- -5.80791704701737572236e+01, /* 0xC04D0A22, 0x420A1A45 */
- -3.14479470594888503854e+01, /* 0xC03F72AC, 0xA892D80F */
-};
-#ifdef __STDC__
-static const double pS3[5] = {
-#else
-static double pS3[5] = {
-#endif
-  3.58560338055209726349e+01, /* 0x4041ED92, 0x84077DD3 */
-  3.61513983050303863820e+02, /* 0x40769839, 0x464A7C0E */
-  1.19360783792111533330e+03, /* 0x4092A66E, 0x6D1061D6 */
-  1.12799679856907414432e+03, /* 0x40919FFC, 0xB8C39B7E */
-  1.73580930813335754692e+02, /* 0x4065B296, 0xFC379081 */
-};
-
-#ifdef __STDC__
-static const double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
-#else
-static double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
-#endif
- -8.87534333032526411254e-08, /* 0xBE77D316, 0xE927026D */
- -7.03030995483624743247e-02, /* 0xBFB1FF62, 0x495E1E42 */
- -1.45073846780952986357e+00, /* 0xBFF73639, 0x8A24A843 */
- -7.63569613823527770791e+00, /* 0xC01E8AF3, 0xEDAFA7F3 */
- -1.11931668860356747786e+01, /* 0xC02662E6, 0xC5246303 */
- -3.23364579351335335033e+00, /* 0xC009DE81, 0xAF8FE70F */
-};
-#ifdef __STDC__
-static const double pS2[5] = {
-#else
-static double pS2[5] = {
-#endif
-  2.22202997532088808441e+01, /* 0x40363865, 0x908B5959 */
-  1.36206794218215208048e+02, /* 0x4061069E, 0x0EE8878F */
-  2.70470278658083486789e+02, /* 0x4070E786, 0x42EA079B */
-  1.53875394208320329881e+02, /* 0x40633C03, 0x3AB6FAFF */
-  1.46576176948256193810e+01, /* 0x402D50B3, 0x44391809 */
-};
-
-#ifdef __STDC__
-	static double pzero(double x)
-#else
-	static double pzero(x)
-	double x;
-#endif
-{
-#ifdef __STDC__
-	const double *p,*q;
-#else
-	double *p,*q;
-#endif
-        fd_twoints u;
-	double z,r,s;
-	int ix;
-        u.d = x;
-	ix = 0x7fffffff&__HI(u);
-	if(ix>=0x40200000)     {p = pR8; q= pS8;}
-	else if(ix>=0x40122E8B){p = pR5; q= pS5;}
-	else if(ix>=0x4006DB6D){p = pR3; q= pS3;}
-	else if(ix>=0x40000000){p = pR2; q= pS2;}
-	z = one/(x*x);
-	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
-	s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
-	return one+ r/s;
-}
-		
-
-/* For x >= 8, the asymptotic expansions of qzero is
- *	-1/8 s + 75/1024 s^3 - ..., where s = 1/x.
- * We approximate pzero by
- * 	qzero(x) = s*(-1.25 + (R/S))
- * where  R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10
- * 	  S = 1 + qS0*s^2 + ... + qS5*s^12
- * and
- *	| qzero(x)/s +1.25-R/S | <= 2  ** ( -61.22)
- */
-#ifdef __STDC__
-static const double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
-#else
-static double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
-#endif
-  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
-  7.32421874999935051953e-02, /* 0x3FB2BFFF, 0xFFFFFE2C */
-  1.17682064682252693899e+01, /* 0x40278952, 0x5BB334D6 */
-  5.57673380256401856059e+02, /* 0x40816D63, 0x15301825 */
-  8.85919720756468632317e+03, /* 0x40C14D99, 0x3E18F46D */
-  3.70146267776887834771e+04, /* 0x40E212D4, 0x0E901566 */
-};
-#ifdef __STDC__
-static const double qS8[6] = {
-#else
-static double qS8[6] = {
-#endif
-  1.63776026895689824414e+02, /* 0x406478D5, 0x365B39BC */
-  8.09834494656449805916e+03, /* 0x40BFA258, 0x4E6B0563 */
-  1.42538291419120476348e+05, /* 0x41016652, 0x54D38C3F */
-  8.03309257119514397345e+05, /* 0x412883DA, 0x83A52B43 */
-  8.40501579819060512818e+05, /* 0x4129A66B, 0x28DE0B3D */
- -3.43899293537866615225e+05, /* 0xC114FD6D, 0x2C9530C5 */
-};
-
-#ifdef __STDC__
-static const double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
-#else
-static double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
-#endif
-  1.84085963594515531381e-11, /* 0x3DB43D8F, 0x29CC8CD9 */
-  7.32421766612684765896e-02, /* 0x3FB2BFFF, 0xD172B04C */
-  5.83563508962056953777e+00, /* 0x401757B0, 0xB9953DD3 */
-  1.35111577286449829671e+02, /* 0x4060E392, 0x0A8788E9 */
-  1.02724376596164097464e+03, /* 0x40900CF9, 0x9DC8C481 */
-  1.98997785864605384631e+03, /* 0x409F17E9, 0x53C6E3A6 */
-};
-#ifdef __STDC__
-static const double qS5[6] = {
-#else
-static double qS5[6] = {
-#endif
-  8.27766102236537761883e+01, /* 0x4054B1B3, 0xFB5E1543 */
-  2.07781416421392987104e+03, /* 0x40A03BA0, 0xDA21C0CE */
-  1.88472887785718085070e+04, /* 0x40D267D2, 0x7B591E6D */
-  5.67511122894947329769e+04, /* 0x40EBB5E3, 0x97E02372 */
-  3.59767538425114471465e+04, /* 0x40E19118, 0x1F7A54A0 */
- -5.35434275601944773371e+03, /* 0xC0B4EA57, 0xBEDBC609 */
-};
-
-#ifdef __STDC__
-static const double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
-#else
-static double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
-#endif
-  4.37741014089738620906e-09, /* 0x3E32CD03, 0x6ADECB82 */
-  7.32411180042911447163e-02, /* 0x3FB2BFEE, 0x0E8D0842 */
-  3.34423137516170720929e+00, /* 0x400AC0FC, 0x61149CF5 */
-  4.26218440745412650017e+01, /* 0x40454F98, 0x962DAEDD */
-  1.70808091340565596283e+02, /* 0x406559DB, 0xE25EFD1F */
-  1.66733948696651168575e+02, /* 0x4064D77C, 0x81FA21E0 */
-};
-#ifdef __STDC__
-static const double qS3[6] = {
-#else
-static double qS3[6] = {
-#endif
-  4.87588729724587182091e+01, /* 0x40486122, 0xBFE343A6 */
-  7.09689221056606015736e+02, /* 0x40862D83, 0x86544EB3 */
-  3.70414822620111362994e+03, /* 0x40ACF04B, 0xE44DFC63 */
-  6.46042516752568917582e+03, /* 0x40B93C6C, 0xD7C76A28 */
-  2.51633368920368957333e+03, /* 0x40A3A8AA, 0xD94FB1C0 */
- -1.49247451836156386662e+02, /* 0xC062A7EB, 0x201CF40F */
-};
-
-#ifdef __STDC__
-static const double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
-#else
-static double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
-#endif
-  1.50444444886983272379e-07, /* 0x3E84313B, 0x54F76BDB */
-  7.32234265963079278272e-02, /* 0x3FB2BEC5, 0x3E883E34 */
-  1.99819174093815998816e+00, /* 0x3FFFF897, 0xE727779C */
-  1.44956029347885735348e+01, /* 0x402CFDBF, 0xAAF96FE5 */
-  3.16662317504781540833e+01, /* 0x403FAA8E, 0x29FBDC4A */
-  1.62527075710929267416e+01, /* 0x403040B1, 0x71814BB4 */
-};
-#ifdef __STDC__
-static const double qS2[6] = {
-#else
-static double qS2[6] = {
-#endif
-  3.03655848355219184498e+01, /* 0x403E5D96, 0xF7C07AED */
-  2.69348118608049844624e+02, /* 0x4070D591, 0xE4D14B40 */
-  8.44783757595320139444e+02, /* 0x408A6645, 0x22B3BF22 */
-  8.82935845112488550512e+02, /* 0x408B977C, 0x9C5CC214 */
-  2.12666388511798828631e+02, /* 0x406A9553, 0x0E001365 */
- -5.31095493882666946917e+00, /* 0xC0153E6A, 0xF8B32931 */
-};
-
-#ifdef __STDC__
-	static double qzero(double x)
-#else
-	static double qzero(x)
-	double x;
-#endif
-{
-#ifdef __STDC__
-	const double *p,*q;
-#else
-	double *p,*q;
-#endif
-        fd_twoints u;
-	double s,r,z;
-	int ix;
-        u.d = x;
-	ix = 0x7fffffff&__HI(u);
-	if(ix>=0x40200000)     {p = qR8; q= qS8;}
-	else if(ix>=0x40122E8B){p = qR5; q= qS5;}
-	else if(ix>=0x4006DB6D){p = qR3; q= qS3;}
-	else if(ix>=0x40000000){p = qR2; q= qS2;}
-	z = one/(x*x);
-	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
-	s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
-	return (-.125 + r/s)/x;
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_j1.c
+++ /dev/null
@@ -1,523 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_j1.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* __ieee754_j1(x), __ieee754_y1(x)
- * Bessel function of the first and second kinds of order zero.
- * Method -- j1(x):
- *	1. For tiny x, we use j1(x) = x/2 - x^3/16 + x^5/384 - ...
- *	2. Reduce x to |x| since j1(x)=-j1(-x),  and
- *	   for x in (0,2)
- *		j1(x) = x/2 + x*z*R0/S0,  where z = x*x;
- *	   (precision:  |j1/x - 1/2 - R0/S0 |<2**-61.51 )
- *	   for x in (2,inf)
- * 		j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x1)-q1(x)*sin(x1))
- * 		y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
- * 	   where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
- *	   as follow:
- *		cos(x1) =  cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
- *			=  1/sqrt(2) * (sin(x) - cos(x))
- *		sin(x1) =  sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
- *			= -1/sqrt(2) * (sin(x) + cos(x))
- * 	   (To avoid cancellation, use
- *		sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
- * 	    to compute the worse one.)
- *	   
- *	3 Special cases
- *		j1(nan)= nan
- *		j1(0) = 0
- *		j1(inf) = 0
- *		
- * Method -- y1(x):
- *	1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN 
- *	2. For x<2.
- *	   Since 
- *		y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...)
- *	   therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function.
- *	   We use the following function to approximate y1,
- *		y1(x) = x*U(z)/V(z) + (2/pi)*(j1(x)*ln(x)-1/x), z= x^2
- *	   where for x in [0,2] (abs err less than 2**-65.89)
- *		U(z) = U0[0] + U0[1]*z + ... + U0[4]*z^4
- *		V(z) = 1  + v0[0]*z + ... + v0[4]*z^5
- *	   Note: For tiny x, 1/x dominate y1 and hence
- *		y1(tiny) = -2/pi/tiny, (choose tiny<2**-54)
- *	3. For x>=2.
- * 		y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
- * 	   where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
- *	   by method mentioned above.
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static double pone(double), qone(double);
-#else
-static double pone(), qone();
-#endif
-
-#ifdef __STDC__
-static const double 
-#else
-static double 
-#endif
-really_big    = 1e300,
-one	= 1.0,
-invsqrtpi=  5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
-tpi      =  6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
-	/* R0/S0 on [0,2] */
-r00  = -6.25000000000000000000e-02, /* 0xBFB00000, 0x00000000 */
-r01  =  1.40705666955189706048e-03, /* 0x3F570D9F, 0x98472C61 */
-r02  = -1.59955631084035597520e-05, /* 0xBEF0C5C6, 0xBA169668 */
-r03  =  4.96727999609584448412e-08, /* 0x3E6AAAFA, 0x46CA0BD9 */
-s01  =  1.91537599538363460805e-02, /* 0x3F939D0B, 0x12637E53 */
-s02  =  1.85946785588630915560e-04, /* 0x3F285F56, 0xB9CDF664 */
-s03  =  1.17718464042623683263e-06, /* 0x3EB3BFF8, 0x333F8498 */
-s04  =  5.04636257076217042715e-09, /* 0x3E35AC88, 0xC97DFF2C */
-s05  =  1.23542274426137913908e-11; /* 0x3DAB2ACF, 0xCFB97ED8 */
-
-static double zero    = 0.0;
-
-#ifdef __STDC__
-	double __ieee754_j1(double x) 
-#else
-	double __ieee754_j1(x) 
-	double x;
-#endif
-{
-        fd_twoints un;
-	double z, s,c,ss,cc,r,u,v,y;
-	int hx,ix;
-
-        un.d = x;
-	hx = __HI(un);
-	ix = hx&0x7fffffff;
-	if(ix>=0x7ff00000) return one/x;
-	y = fd_fabs(x);
-	if(ix >= 0x40000000) {	/* |x| >= 2.0 */
-		s = fd_sin(y);
-		c = fd_cos(y);
-		ss = -s-c;
-		cc = s-c;
-		if(ix<0x7fe00000) {  /* make sure y+y not overflow */
-		    z = fd_cos(y+y);
-		    if ((s*c)>zero) cc = z/ss;
-		    else 	    ss = z/cc;
-		}
-	/*
-	 * j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)
-	 * y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)
-	 */
-		if(ix>0x48000000) z = (invsqrtpi*cc)/fd_sqrt(y);
-		else {
-		    u = pone(y); v = qone(y);
-		    z = invsqrtpi*(u*cc-v*ss)/fd_sqrt(y);
-		}
-		if(hx<0) return -z;
-		else  	 return  z;
-	}
-	if(ix<0x3e400000) {	/* |x|<2**-27 */
-	    if(really_big+x>one) return 0.5*x;/* inexact if x!=0 necessary */
-	}
-	z = x*x;
-	r =  z*(r00+z*(r01+z*(r02+z*r03)));
-	s =  one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05))));
-	r *= x;
-	return(x*0.5+r/s);
-}
-
-#ifdef __STDC__
-static const double U0[5] = {
-#else
-static double U0[5] = {
-#endif
- -1.96057090646238940668e-01, /* 0xBFC91866, 0x143CBC8A */
-  5.04438716639811282616e-02, /* 0x3FA9D3C7, 0x76292CD1 */
- -1.91256895875763547298e-03, /* 0xBF5F55E5, 0x4844F50F */
-  2.35252600561610495928e-05, /* 0x3EF8AB03, 0x8FA6B88E */
- -9.19099158039878874504e-08, /* 0xBE78AC00, 0x569105B8 */
-};
-#ifdef __STDC__
-static const double V0[5] = {
-#else
-static double V0[5] = {
-#endif
-  1.99167318236649903973e-02, /* 0x3F94650D, 0x3F4DA9F0 */
-  2.02552581025135171496e-04, /* 0x3F2A8C89, 0x6C257764 */
-  1.35608801097516229404e-06, /* 0x3EB6C05A, 0x894E8CA6 */
-  6.22741452364621501295e-09, /* 0x3E3ABF1D, 0x5BA69A86 */
-  1.66559246207992079114e-11, /* 0x3DB25039, 0xDACA772A */
-};
-
-#ifdef __STDC__
-	double __ieee754_y1(double x) 
-#else
-	double __ieee754_y1(x) 
-	double x;
-#endif
-{
-        fd_twoints un;
-	double z, s,c,ss,cc,u,v;
-	int hx,ix,lx;
-
-        un.d = x;
-        hx = __HI(un);
-        ix = 0x7fffffff&hx;
-        lx = __LO(un);
-    /* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
-	if(ix>=0x7ff00000) return  one/(x+x*x); 
-        if((ix|lx)==0) return -one/zero;
-        if(hx<0) return zero/zero;
-        if(ix >= 0x40000000) {  /* |x| >= 2.0 */
-                s = fd_sin(x);
-                c = fd_cos(x);
-                ss = -s-c;
-                cc = s-c;
-                if(ix<0x7fe00000) {  /* make sure x+x not overflow */
-                    z = fd_cos(x+x);
-                    if ((s*c)>zero) cc = z/ss;
-                    else            ss = z/cc;
-                }
-        /* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))
-         * where x0 = x-3pi/4
-         *      Better formula:
-         *              cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
-         *                      =  1/sqrt(2) * (sin(x) - cos(x))
-         *              sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
-         *                      = -1/sqrt(2) * (cos(x) + sin(x))
-         * To avoid cancellation, use
-         *              sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
-         * to compute the worse one.
-         */
-                if(ix>0x48000000) z = (invsqrtpi*ss)/fd_sqrt(x);
-                else {
-                    u = pone(x); v = qone(x);
-                    z = invsqrtpi*(u*ss+v*cc)/fd_sqrt(x);
-                }
-                return z;
-        } 
-        if(ix<=0x3c900000) {    /* x < 2**-54 */
-            return(-tpi/x);
-        } 
-        z = x*x;
-        u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));
-        v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));
-        return(x*(u/v) + tpi*(__ieee754_j1(x)*__ieee754_log(x)-one/x));
-}
-
-/* For x >= 8, the asymptotic expansions of pone is
- *	1 + 15/128 s^2 - 4725/2^15 s^4 - ...,	where s = 1/x.
- * We approximate pone by
- * 	pone(x) = 1 + (R/S)
- * where  R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
- * 	  S = 1 + ps0*s^2 + ... + ps4*s^10
- * and
- *	| pone(x)-1-R/S | <= 2  ** ( -60.06)
- */
-
-#ifdef __STDC__
-static const double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
-#else
-static double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
-#endif
-  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
-  1.17187499999988647970e-01, /* 0x3FBDFFFF, 0xFFFFFCCE */
-  1.32394806593073575129e+01, /* 0x402A7A9D, 0x357F7FCE */
-  4.12051854307378562225e+02, /* 0x4079C0D4, 0x652EA590 */
-  3.87474538913960532227e+03, /* 0x40AE457D, 0xA3A532CC */
-  7.91447954031891731574e+03, /* 0x40BEEA7A, 0xC32782DD */
-};
-#ifdef __STDC__
-static const double ps8[5] = {
-#else
-static double ps8[5] = {
-#endif
-  1.14207370375678408436e+02, /* 0x405C8D45, 0x8E656CAC */
-  3.65093083420853463394e+03, /* 0x40AC85DC, 0x964D274F */
-  3.69562060269033463555e+04, /* 0x40E20B86, 0x97C5BB7F */
-  9.76027935934950801311e+04, /* 0x40F7D42C, 0xB28F17BB */
-  3.08042720627888811578e+04, /* 0x40DE1511, 0x697A0B2D */
-};
-
-#ifdef __STDC__
-static const double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
-#else
-static double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
-#endif
-  1.31990519556243522749e-11, /* 0x3DAD0667, 0xDAE1CA7D */
-  1.17187493190614097638e-01, /* 0x3FBDFFFF, 0xE2C10043 */
-  6.80275127868432871736e+00, /* 0x401B3604, 0x6E6315E3 */
-  1.08308182990189109773e+02, /* 0x405B13B9, 0x452602ED */
-  5.17636139533199752805e+02, /* 0x40802D16, 0xD052D649 */
-  5.28715201363337541807e+02, /* 0x408085B8, 0xBB7E0CB7 */
-};
-#ifdef __STDC__
-static const double ps5[5] = {
-#else
-static double ps5[5] = {
-#endif
-  5.92805987221131331921e+01, /* 0x404DA3EA, 0xA8AF633D */
-  9.91401418733614377743e+02, /* 0x408EFB36, 0x1B066701 */
-  5.35326695291487976647e+03, /* 0x40B4E944, 0x5706B6FB */
-  7.84469031749551231769e+03, /* 0x40BEA4B0, 0xB8A5BB15 */
-  1.50404688810361062679e+03, /* 0x40978030, 0x036F5E51 */
-};
-
-#ifdef __STDC__
-static const double pr3[6] = {
-#else
-static double pr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
-#endif
-  3.02503916137373618024e-09, /* 0x3E29FC21, 0xA7AD9EDD */
-  1.17186865567253592491e-01, /* 0x3FBDFFF5, 0x5B21D17B */
-  3.93297750033315640650e+00, /* 0x400F76BC, 0xE85EAD8A */
-  3.51194035591636932736e+01, /* 0x40418F48, 0x9DA6D129 */
-  9.10550110750781271918e+01, /* 0x4056C385, 0x4D2C1837 */
-  4.85590685197364919645e+01, /* 0x4048478F, 0x8EA83EE5 */
-};
-#ifdef __STDC__
-static const double ps3[5] = {
-#else
-static double ps3[5] = {
-#endif
-  3.47913095001251519989e+01, /* 0x40416549, 0xA134069C */
-  3.36762458747825746741e+02, /* 0x40750C33, 0x07F1A75F */
-  1.04687139975775130551e+03, /* 0x40905B7C, 0x5037D523 */
-  8.90811346398256432622e+02, /* 0x408BD67D, 0xA32E31E9 */
-  1.03787932439639277504e+02, /* 0x4059F26D, 0x7C2EED53 */
-};
-
-#ifdef __STDC__
-static const double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
-#else
-static double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
-#endif
-  1.07710830106873743082e-07, /* 0x3E7CE9D4, 0xF65544F4 */
-  1.17176219462683348094e-01, /* 0x3FBDFF42, 0xBE760D83 */
-  2.36851496667608785174e+00, /* 0x4002F2B7, 0xF98FAEC0 */
-  1.22426109148261232917e+01, /* 0x40287C37, 0x7F71A964 */
-  1.76939711271687727390e+01, /* 0x4031B1A8, 0x177F8EE2 */
-  5.07352312588818499250e+00, /* 0x40144B49, 0xA574C1FE */
-};
-#ifdef __STDC__
-static const double ps2[5] = {
-#else
-static double ps2[5] = {
-#endif
-  2.14364859363821409488e+01, /* 0x40356FBD, 0x8AD5ECDC */
-  1.25290227168402751090e+02, /* 0x405F5293, 0x14F92CD5 */
-  2.32276469057162813669e+02, /* 0x406D08D8, 0xD5A2DBD9 */
-  1.17679373287147100768e+02, /* 0x405D6B7A, 0xDA1884A9 */
-  8.36463893371618283368e+00, /* 0x4020BAB1, 0xF44E5192 */
-};
-
-#ifdef __STDC__
-	static double pone(double x)
-#else
-	static double pone(x)
-	double x;
-#endif
-{
-#ifdef __STDC__
-	const double *p,*q;
-#else
-	double *p,*q;
-#endif
-        fd_twoints un;
-	double z,r,s;
-        int ix;
-        un.d = x;
-        ix = 0x7fffffff&__HI(un);
-        if(ix>=0x40200000)     {p = pr8; q= ps8;}
-        else if(ix>=0x40122E8B){p = pr5; q= ps5;}
-        else if(ix>=0x4006DB6D){p = pr3; q= ps3;}
-        else if(ix>=0x40000000){p = pr2; q= ps2;}
-        z = one/(x*x);
-        r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
-        s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
-        return one+ r/s;
-}
-		
-
-/* For x >= 8, the asymptotic expansions of qone is
- *	3/8 s - 105/1024 s^3 - ..., where s = 1/x.
- * We approximate pone by
- * 	qone(x) = s*(0.375 + (R/S))
- * where  R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
- * 	  S = 1 + qs1*s^2 + ... + qs6*s^12
- * and
- *	| qone(x)/s -0.375-R/S | <= 2  ** ( -61.13)
- */
-
-#ifdef __STDC__
-static const double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
-#else
-static double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
-#endif
-  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
- -1.02539062499992714161e-01, /* 0xBFBA3FFF, 0xFFFFFDF3 */
- -1.62717534544589987888e+01, /* 0xC0304591, 0xA26779F7 */
- -7.59601722513950107896e+02, /* 0xC087BCD0, 0x53E4B576 */
- -1.18498066702429587167e+04, /* 0xC0C724E7, 0x40F87415 */
- -4.84385124285750353010e+04, /* 0xC0E7A6D0, 0x65D09C6A */
-};
-#ifdef __STDC__
-static const double qs8[6] = {
-#else
-static double qs8[6] = {
-#endif
-  1.61395369700722909556e+02, /* 0x40642CA6, 0xDE5BCDE5 */
-  7.82538599923348465381e+03, /* 0x40BE9162, 0xD0D88419 */
-  1.33875336287249578163e+05, /* 0x4100579A, 0xB0B75E98 */
-  7.19657723683240939863e+05, /* 0x4125F653, 0x72869C19 */
-  6.66601232617776375264e+05, /* 0x412457D2, 0x7719AD5C */
- -2.94490264303834643215e+05, /* 0xC111F969, 0x0EA5AA18 */
-};
-
-#ifdef __STDC__
-static const double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
-#else
-static double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
-#endif
- -2.08979931141764104297e-11, /* 0xBDB6FA43, 0x1AA1A098 */
- -1.02539050241375426231e-01, /* 0xBFBA3FFF, 0xCB597FEF */
- -8.05644828123936029840e+00, /* 0xC0201CE6, 0xCA03AD4B */
- -1.83669607474888380239e+02, /* 0xC066F56D, 0x6CA7B9B0 */
- -1.37319376065508163265e+03, /* 0xC09574C6, 0x6931734F */
- -2.61244440453215656817e+03, /* 0xC0A468E3, 0x88FDA79D */
-};
-#ifdef __STDC__
-static const double qs5[6] = {
-#else
-static double qs5[6] = {
-#endif
-  8.12765501384335777857e+01, /* 0x405451B2, 0xFF5A11B2 */
-  1.99179873460485964642e+03, /* 0x409F1F31, 0xE77BF839 */
-  1.74684851924908907677e+04, /* 0x40D10F1F, 0x0D64CE29 */
-  4.98514270910352279316e+04, /* 0x40E8576D, 0xAABAD197 */
-  2.79480751638918118260e+04, /* 0x40DB4B04, 0xCF7C364B */
- -4.71918354795128470869e+03, /* 0xC0B26F2E, 0xFCFFA004 */
-};
-
-#ifdef __STDC__
-static const double qr3[6] = {
-#else
-static double qr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
-#endif
- -5.07831226461766561369e-09, /* 0xBE35CFA9, 0xD38FC84F */
- -1.02537829820837089745e-01, /* 0xBFBA3FEB, 0x51AEED54 */
- -4.61011581139473403113e+00, /* 0xC01270C2, 0x3302D9FF */
- -5.78472216562783643212e+01, /* 0xC04CEC71, 0xC25D16DA */
- -2.28244540737631695038e+02, /* 0xC06C87D3, 0x4718D55F */
- -2.19210128478909325622e+02, /* 0xC06B66B9, 0x5F5C1BF6 */
-};
-#ifdef __STDC__
-static const double qs3[6] = {
-#else
-static double qs3[6] = {
-#endif
-  4.76651550323729509273e+01, /* 0x4047D523, 0xCCD367E4 */
-  6.73865112676699709482e+02, /* 0x40850EEB, 0xC031EE3E */
-  3.38015286679526343505e+03, /* 0x40AA684E, 0x448E7C9A */
-  5.54772909720722782367e+03, /* 0x40B5ABBA, 0xA61D54A6 */
-  1.90311919338810798763e+03, /* 0x409DBC7A, 0x0DD4DF4B */
- -1.35201191444307340817e+02, /* 0xC060E670, 0x290A311F */
-};
-
-#ifdef __STDC__
-static const double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
-#else
-static double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
-#endif
- -1.78381727510958865572e-07, /* 0xBE87F126, 0x44C626D2 */
- -1.02517042607985553460e-01, /* 0xBFBA3E8E, 0x9148B010 */
- -2.75220568278187460720e+00, /* 0xC0060484, 0x69BB4EDA */
- -1.96636162643703720221e+01, /* 0xC033A9E2, 0xC168907F */
- -4.23253133372830490089e+01, /* 0xC04529A3, 0xDE104AAA */
- -2.13719211703704061733e+01, /* 0xC0355F36, 0x39CF6E52 */
-};
-#ifdef __STDC__
-static const double qs2[6] = {
-#else
-static double qs2[6] = {
-#endif
-  2.95333629060523854548e+01, /* 0x403D888A, 0x78AE64FF */
-  2.52981549982190529136e+02, /* 0x406F9F68, 0xDB821CBA */
-  7.57502834868645436472e+02, /* 0x4087AC05, 0xCE49A0F7 */
-  7.39393205320467245656e+02, /* 0x40871B25, 0x48D4C029 */
-  1.55949003336666123687e+02, /* 0x40637E5E, 0x3C3ED8D4 */
- -4.95949898822628210127e+00, /* 0xC013D686, 0xE71BE86B */
-};
-
-#ifdef __STDC__
-	static double qone(double x)
-#else
-	static double qone(x)
-	double x;
-#endif
-{
-#ifdef __STDC__
-	const double *p,*q;
-#else
-	double *p,*q;
-#endif
-        fd_twoints un;
-	double  s,r,z;
-	int ix;
-        un.d = x;
-	ix = 0x7fffffff&__HI(un);
-	if(ix>=0x40200000)     {p = qr8; q= qs8;}
-	else if(ix>=0x40122E8B){p = qr5; q= qs5;}
-	else if(ix>=0x4006DB6D){p = qr3; q= qs3;}
-	else if(ix>=0x40000000){p = qr2; q= qs2;}
-	z = one/(x*x);
-	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
-	s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
-	return (.375 + r/s)/x;
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_jn.c
+++ /dev/null
@@ -1,315 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_jn.c 1.4 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/*
- * __ieee754_jn(n, x), __ieee754_yn(n, x)
- * floating point Bessel's function of the 1st and 2nd kind
- * of order n
- *          
- * Special cases:
- *	y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
- *	y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
- * Note 2. About jn(n,x), yn(n,x)
- *	For n=0, j0(x) is called,
- *	for n=1, j1(x) is called,
- *	for n<x, forward recursion us used starting
- *	from values of j0(x) and j1(x).
- *	for n>x, a continued fraction approximation to
- *	j(n,x)/j(n-1,x) is evaluated and then backward
- *	recursion is used starting from a supposed value
- *	for j(n,x). The resulting value of j(0,x) is
- *	compared with the actual value to correct the
- *	supposed value of j(n,x).
- *
- *	yn(n,x) is similar in all respects, except
- *	that forward recursion is used for all
- *	values of n>1.
- *	
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double
-#else
-static double
-#endif
-invsqrtpi=  5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
-two   =  2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
-one   =  1.00000000000000000000e+00; /* 0x3FF00000, 0x00000000 */
-
-static double zero  =  0.00000000000000000000e+00;
-
-#ifdef __STDC__
-	double __ieee754_jn(int n, double x)
-#else
-	double __ieee754_jn(n,x)
-	int n; double x;
-#endif
-{
-        fd_twoints u;
-	int i,hx,ix,lx, sgn;
-	double a, b, temp, di;
-	double z, w;
-
-    /* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
-     * Thus, J(-n,x) = J(n,-x)
-     */
-        u.d = x;
-	hx = __HI(u);
-	ix = 0x7fffffff&hx;
-	lx = __LO(u);
-    /* if J(n,NaN) is NaN */
-	if((ix|((unsigned)(lx|-lx))>>31)>0x7ff00000) return x+x;
-	if(n<0){		
-		n = -n;
-		x = -x;
-		hx ^= 0x80000000;
-	}
-	if(n==0) return(__ieee754_j0(x));
-	if(n==1) return(__ieee754_j1(x));
-	sgn = (n&1)&(hx>>31);	/* even n -- 0, odd n -- sign(x) */
-	x = fd_fabs(x);
-	if((ix|lx)==0||ix>=0x7ff00000) 	/* if x is 0 or inf */
-	    b = zero;
-	else if((double)n<=x) {   
-		/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */
-	    if(ix>=0x52D00000) { /* x > 2**302 */
-    /* (x >> n**2) 
-     *	    Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
-     *	    Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
-     *	    Let s=sin(x), c=cos(x), 
-     *		xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
-     *
-     *		   n	sin(xn)*sqt2	cos(xn)*sqt2
-     *		----------------------------------
-     *		   0	 s-c		 c+s
-     *		   1	-s-c 		-c+s
-     *		   2	-s+c		-c-s
-     *		   3	 s+c		 c-s
-     */
-		switch(n&3) {
-		    case 0: temp =  fd_cos(x)+fd_sin(x); break;
-		    case 1: temp = -fd_cos(x)+fd_sin(x); break;
-		    case 2: temp = -fd_cos(x)-fd_sin(x); break;
-		    case 3: temp =  fd_cos(x)-fd_sin(x); break;
-		}
-		b = invsqrtpi*temp/fd_sqrt(x);
-	    } else {	
-	        a = __ieee754_j0(x);
-	        b = __ieee754_j1(x);
-	        for(i=1;i<n;i++){
-		    temp = b;
-		    b = b*((double)(i+i)/x) - a; /* avoid underflow */
-		    a = temp;
-	        }
-	    }
-	} else {
-	    if(ix<0x3e100000) {	/* x < 2**-29 */
-    /* x is tiny, return the first Taylor expansion of J(n,x) 
-     * J(n,x) = 1/n!*(x/2)^n  - ...
-     */
-		if(n>33)	/* underflow */
-		    b = zero;
-		else {
-		    temp = x*0.5; b = temp;
-		    for (a=one,i=2;i<=n;i++) {
-			a *= (double)i;		/* a = n! */
-			b *= temp;		/* b = (x/2)^n */
-		    }
-		    b = b/a;
-		}
-	    } else {
-		/* use backward recurrence */
-		/* 			x      x^2      x^2       
-		 *  J(n,x)/J(n-1,x) =  ----   ------   ------   .....
-		 *			2n  - 2(n+1) - 2(n+2)
-		 *
-		 * 			1      1        1       
-		 *  (for large x)   =  ----  ------   ------   .....
-		 *			2n   2(n+1)   2(n+2)
-		 *			-- - ------ - ------ - 
-		 *			 x     x         x
-		 *
-		 * Let w = 2n/x and h=2/x, then the above quotient
-		 * is equal to the continued fraction:
-		 *		    1
-		 *	= -----------------------
-		 *		       1
-		 *	   w - -----------------
-		 *			  1
-		 * 	        w+h - ---------
-		 *		       w+2h - ...
-		 *
-		 * To determine how many terms needed, let
-		 * Q(0) = w, Q(1) = w(w+h) - 1,
-		 * Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
-		 * When Q(k) > 1e4	good for single 
-		 * When Q(k) > 1e9	good for double 
-		 * When Q(k) > 1e17	good for quadruple 
-		 */
-	    /* determine k */
-		double t,v;
-		double q0,q1,h,tmp; int k,m;
-		w  = (n+n)/(double)x; h = 2.0/(double)x;
-		q0 = w;  z = w+h; q1 = w*z - 1.0; k=1;
-		while(q1<1.0e9) {
-			k += 1; z += h;
-			tmp = z*q1 - q0;
-			q0 = q1;
-			q1 = tmp;
-		}
-		m = n+n;
-		for(t=zero, i = 2*(n+k); i>=m; i -= 2) t = one/(i/x-t);
-		a = t;
-		b = one;
-		/*  estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
-		 *  Hence, if n*(log(2n/x)) > ...
-		 *  single 8.8722839355e+01
-		 *  double 7.09782712893383973096e+02
-		 *  long double 1.1356523406294143949491931077970765006170e+04
-		 *  then recurrent value may overflow and the result is 
-		 *  likely underflow to zero
-		 */
-		tmp = n;
-		v = two/x;
-		tmp = tmp*__ieee754_log(fd_fabs(v*tmp));
-		if(tmp<7.09782712893383973096e+02) {
-	    	    for(i=n-1,di=(double)(i+i);i>0;i--){
-		        temp = b;
-			b *= di;
-			b  = b/x - a;
-		        a = temp;
-			di -= two;
-	     	    }
-		} else {
-	    	    for(i=n-1,di=(double)(i+i);i>0;i--){
-		        temp = b;
-			b *= di;
-			b  = b/x - a;
-		        a = temp;
-			di -= two;
-		    /* scale b to avoid spurious overflow */
-			if(b>1e100) {
-			    a /= b;
-			    t /= b;
-			    b  = one;
-			}
-	     	    }
-		}
-	    	b = (t*__ieee754_j0(x)/b);
-	    }
-	}
-	if(sgn==1) return -b; else return b;
-}
-
-#ifdef __STDC__
-	double __ieee754_yn(int n, double x) 
-#else
-	double __ieee754_yn(n,x) 
-	int n; double x;
-#endif
-{
-        fd_twoints u;
-	int i,hx,ix,lx;
-	int sign;
-	double a, b, temp;
-
-        u.d = x;
-	hx = __HI(u);
-	ix = 0x7fffffff&hx;
-	lx = __LO(u);
-    /* if Y(n,NaN) is NaN */
-	if((ix|((unsigned)(lx|-lx))>>31)>0x7ff00000) return x+x;
-	if((ix|lx)==0) return -one/zero;
-	if(hx<0) return zero/zero;
-	sign = 1;
-	if(n<0){
-		n = -n;
-		sign = 1 - ((n&1)<<1);
-	}
-	if(n==0) return(__ieee754_y0(x));
-	if(n==1) return(sign*__ieee754_y1(x));
-	if(ix==0x7ff00000) return zero;
-	if(ix>=0x52D00000) { /* x > 2**302 */
-    /* (x >> n**2) 
-     *	    Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
-     *	    Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
-     *	    Let s=sin(x), c=cos(x), 
-     *		xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
-     *
-     *		   n	sin(xn)*sqt2	cos(xn)*sqt2
-     *		----------------------------------
-     *		   0	 s-c		 c+s
-     *		   1	-s-c 		-c+s
-     *		   2	-s+c		-c-s
-     *		   3	 s+c		 c-s
-     */
-		switch(n&3) {
-		    case 0: temp =  fd_sin(x)-fd_cos(x); break;
-		    case 1: temp = -fd_sin(x)-fd_cos(x); break;
-		    case 2: temp = -fd_sin(x)+fd_cos(x); break;
-		    case 3: temp =  fd_sin(x)+fd_cos(x); break;
-		}
-		b = invsqrtpi*temp/fd_sqrt(x);
-	} else {
-	    a = __ieee754_y0(x);
-	    b = __ieee754_y1(x);
-	/* quit if b is -inf */
-            u.d = b;
-	    for(i=1;i<n&&(__HI(u) != 0xfff00000);i++){ 
-		temp = b;
-		b = ((double)(i+i)/x)*b - a;
-		a = temp;
-	    }
-	}
-	if(sign>0) return b; else return -b;
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_lgamma.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_lgamma.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- *
- */
-
-/* __ieee754_lgamma(x)
- * Return the logarithm of the Gamma function of x.
- *
- * Method: call __ieee754_lgamma_r
- */
-
-#include "fdlibm.h"
-
-extern int signgam;
-
-#ifdef __STDC__
-	double __ieee754_lgamma(double x)
-#else
-	double __ieee754_lgamma(x)
-	double x;
-#endif
-{
-	return __ieee754_lgamma_r(x,&signgam);
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_lgamma_r.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_lgamma_r.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- *
- */
-
-/* __ieee754_lgamma_r(x, signgamp)
- * Reentrant version of the logarithm of the Gamma function 
- * with user provide pointer for the sign of Gamma(x). 
- *
- * Method:
- *   1. Argument Reduction for 0 < x <= 8
- * 	Since gamma(1+s)=s*gamma(s), for x in [0,8], we may 
- * 	reduce x to a number in [1.5,2.5] by
- * 		lgamma(1+s) = log(s) + lgamma(s)
- *	for example,
- *		lgamma(7.3) = log(6.3) + lgamma(6.3)
- *			    = log(6.3*5.3) + lgamma(5.3)
- *			    = log(6.3*5.3*4.3*3.3*2.3) + lgamma(2.3)
- *   2. Polynomial approximation of lgamma around its
- *	minimun ymin=1.461632144968362245 to maintain monotonicity.
- *	On [ymin-0.23, ymin+0.27] (i.e., [1.23164,1.73163]), use
- *		Let z = x-ymin;
- *		lgamma(x) = -1.214862905358496078218 + z^2*poly(z)
- *	where
- *		poly(z) is a 14 degree polynomial.
- *   2. Rational approximation in the primary interval [2,3]
- *	We use the following approximation:
- *		s = x-2.0;
- *		lgamma(x) = 0.5*s + s*P(s)/Q(s)
- *	with accuracy
- *		|P/Q - (lgamma(x)-0.5s)| < 2**-61.71
- *	Our algorithms are based on the following observation
- *
- *                             zeta(2)-1    2    zeta(3)-1    3
- * lgamma(2+s) = s*(1-Euler) + --------- * s  -  --------- * s  + ...
- *                                 2                 3
- *
- *	where Euler = 0.5771... is the Euler constant, which is very
- *	close to 0.5.
- *
- *   3. For x>=8, we have
- *	lgamma(x)~(x-0.5)log(x)-x+0.5*log(2pi)+1/(12x)-1/(360x**3)+....
- *	(better formula:
- *	   lgamma(x)~(x-0.5)*(log(x)-1)-.5*(log(2pi)-1) + ...)
- *	Let z = 1/x, then we approximation
- *		f(z) = lgamma(x) - (x-0.5)(log(x)-1)
- *	by
- *	  			    3       5             11
- *		w = w0 + w1*z + w2*z  + w3*z  + ... + w6*z
- *	where 
- *		|w - f(z)| < 2**-58.74
- *		
- *   4. For negative x, since (G is gamma function)
- *		-x*G(-x)*G(x) = pi/sin(pi*x),
- * 	we have
- * 		G(x) = pi/(sin(pi*x)*(-x)*G(-x))
- *	since G(-x) is positive, sign(G(x)) = sign(sin(pi*x)) for x<0
- *	Hence, for x<0, signgam = sign(sin(pi*x)) and 
- *		lgamma(x) = log(|Gamma(x)|)
- *			  = log(pi/(|x*sin(pi*x)|)) - lgamma(-x);
- *	Note: one should avoid compute pi*(-x) directly in the 
- *	      computation of sin(pi*(-x)).
- *		
- *   5. Special Cases
- *		lgamma(2+s) ~ s*(1-Euler) for tiny s
- *		lgamma(1)=lgamma(2)=0
- *		lgamma(x) ~ -log(x) for tiny x
- *		lgamma(0) = lgamma(inf) = inf
- *	 	lgamma(-integer) = +-inf
- *	
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double 
-#else
-static double 
-#endif
-two52=  4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-half=  5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
-one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
-pi  =  3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
-a0  =  7.72156649015328655494e-02, /* 0x3FB3C467, 0xE37DB0C8 */
-a1  =  3.22467033424113591611e-01, /* 0x3FD4A34C, 0xC4A60FAD */
-a2  =  6.73523010531292681824e-02, /* 0x3FB13E00, 0x1A5562A7 */
-a3  =  2.05808084325167332806e-02, /* 0x3F951322, 0xAC92547B */
-a4  =  7.38555086081402883957e-03, /* 0x3F7E404F, 0xB68FEFE8 */
-a5  =  2.89051383673415629091e-03, /* 0x3F67ADD8, 0xCCB7926B */
-a6  =  1.19270763183362067845e-03, /* 0x3F538A94, 0x116F3F5D */
-a7  =  5.10069792153511336608e-04, /* 0x3F40B6C6, 0x89B99C00 */
-a8  =  2.20862790713908385557e-04, /* 0x3F2CF2EC, 0xED10E54D */
-a9  =  1.08011567247583939954e-04, /* 0x3F1C5088, 0x987DFB07 */
-a10 =  2.52144565451257326939e-05, /* 0x3EFA7074, 0x428CFA52 */
-a11 =  4.48640949618915160150e-05, /* 0x3F07858E, 0x90A45837 */
-tc  =  1.46163214496836224576e+00, /* 0x3FF762D8, 0x6356BE3F */
-tf  = -1.21486290535849611461e-01, /* 0xBFBF19B9, 0xBCC38A42 */
-/* tt = -(tail of tf) */
-tt  = -3.63867699703950536541e-18, /* 0xBC50C7CA, 0xA48A971F */
-t0  =  4.83836122723810047042e-01, /* 0x3FDEF72B, 0xC8EE38A2 */
-t1  = -1.47587722994593911752e-01, /* 0xBFC2E427, 0x8DC6C509 */
-t2  =  6.46249402391333854778e-02, /* 0x3FB08B42, 0x94D5419B */
-t3  = -3.27885410759859649565e-02, /* 0xBFA0C9A8, 0xDF35B713 */
-t4  =  1.79706750811820387126e-02, /* 0x3F9266E7, 0x970AF9EC */
-t5  = -1.03142241298341437450e-02, /* 0xBF851F9F, 0xBA91EC6A */
-t6  =  6.10053870246291332635e-03, /* 0x3F78FCE0, 0xE370E344 */
-t7  = -3.68452016781138256760e-03, /* 0xBF6E2EFF, 0xB3E914D7 */
-t8  =  2.25964780900612472250e-03, /* 0x3F6282D3, 0x2E15C915 */
-t9  = -1.40346469989232843813e-03, /* 0xBF56FE8E, 0xBF2D1AF1 */
-t10 =  8.81081882437654011382e-04, /* 0x3F4CDF0C, 0xEF61A8E9 */
-t11 = -5.38595305356740546715e-04, /* 0xBF41A610, 0x9C73E0EC */
-t12 =  3.15632070903625950361e-04, /* 0x3F34AF6D, 0x6C0EBBF7 */
-t13 = -3.12754168375120860518e-04, /* 0xBF347F24, 0xECC38C38 */
-t14 =  3.35529192635519073543e-04, /* 0x3F35FD3E, 0xE8C2D3F4 */
-u0  = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */
-u1  =  6.32827064025093366517e-01, /* 0x3FE4401E, 0x8B005DFF */
-u2  =  1.45492250137234768737e+00, /* 0x3FF7475C, 0xD119BD6F */
-u3  =  9.77717527963372745603e-01, /* 0x3FEF4976, 0x44EA8450 */
-u4  =  2.28963728064692451092e-01, /* 0x3FCD4EAE, 0xF6010924 */
-u5  =  1.33810918536787660377e-02, /* 0x3F8B678B, 0xBF2BAB09 */
-v1  =  2.45597793713041134822e+00, /* 0x4003A5D7, 0xC2BD619C */
-v2  =  2.12848976379893395361e+00, /* 0x40010725, 0xA42B18F5 */
-v3  =  7.69285150456672783825e-01, /* 0x3FE89DFB, 0xE45050AF */
-v4  =  1.04222645593369134254e-01, /* 0x3FBAAE55, 0xD6537C88 */
-v5  =  3.21709242282423911810e-03, /* 0x3F6A5ABB, 0x57D0CF61 */
-s0  = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */
-s1  =  2.14982415960608852501e-01, /* 0x3FCB848B, 0x36E20878 */
-s2  =  3.25778796408930981787e-01, /* 0x3FD4D98F, 0x4F139F59 */
-s3  =  1.46350472652464452805e-01, /* 0x3FC2BB9C, 0xBEE5F2F7 */
-s4  =  2.66422703033638609560e-02, /* 0x3F9B481C, 0x7E939961 */
-s5  =  1.84028451407337715652e-03, /* 0x3F5E26B6, 0x7368F239 */
-s6  =  3.19475326584100867617e-05, /* 0x3F00BFEC, 0xDD17E945 */
-r1  =  1.39200533467621045958e+00, /* 0x3FF645A7, 0x62C4AB74 */
-r2  =  7.21935547567138069525e-01, /* 0x3FE71A18, 0x93D3DCDC */
-r3  =  1.71933865632803078993e-01, /* 0x3FC601ED, 0xCCFBDF27 */
-r4  =  1.86459191715652901344e-02, /* 0x3F9317EA, 0x742ED475 */
-r5  =  7.77942496381893596434e-04, /* 0x3F497DDA, 0xCA41A95B */
-r6  =  7.32668430744625636189e-06, /* 0x3EDEBAF7, 0xA5B38140 */
-w0  =  4.18938533204672725052e-01, /* 0x3FDACFE3, 0x90C97D69 */
-w1  =  8.33333333333329678849e-02, /* 0x3FB55555, 0x5555553B */
-w2  = -2.77777777728775536470e-03, /* 0xBF66C16C, 0x16B02E5C */
-w3  =  7.93650558643019558500e-04, /* 0x3F4A019F, 0x98CF38B6 */
-w4  = -5.95187557450339963135e-04, /* 0xBF4380CB, 0x8C0FE741 */
-w5  =  8.36339918996282139126e-04, /* 0x3F4B67BA, 0x4CDAD5D1 */
-w6  = -1.63092934096575273989e-03; /* 0xBF5AB89D, 0x0B9E43E4 */
-
-static double zero=  0.00000000000000000000e+00;
-
-#ifdef __STDC__
-	static double sin_pi(double x)
-#else
-	static double sin_pi(x)
-	double x;
-#endif
-{
-        fd_twoints u;
-	double y,z;
-	int n,ix;
-
-        u.d = x;
-	ix = 0x7fffffff&__HI(u);
-
-	if(ix<0x3fd00000) return __kernel_sin(pi*x,zero,0);
-	y = -x;		/* x is assume negative */
-
-    /*
-     * argument reduction, make sure inexact flag not raised if input
-     * is an integer
-     */
-	z = fd_floor(y);
-	if(z!=y) {				/* inexact anyway */
-	    y  *= 0.5;
-	    y   = 2.0*(y - fd_floor(y));		/* y = |x| mod 2.0 */
-	    n   = (int) (y*4.0);
-	} else {
-            if(ix>=0x43400000) {
-                y = zero; n = 0;                 /* y must be even */
-            } else {
-                if(ix<0x43300000) z = y+two52;	/* exact */
-                u.d = z;
-                n   = __LO(u)&1;        /* lower word of z */
-                y  = n;
-                n<<= 2;
-            }
-        }
-	switch (n) {
-	    case 0:   y =  __kernel_sin(pi*y,zero,0); break;
-	    case 1:   
-	    case 2:   y =  __kernel_cos(pi*(0.5-y),zero); break;
-	    case 3:  
-	    case 4:   y =  __kernel_sin(pi*(one-y),zero,0); break;
-	    case 5:
-	    case 6:   y = -__kernel_cos(pi*(y-1.5),zero); break;
-	    default:  y =  __kernel_sin(pi*(y-2.0),zero,0); break;
-	    }
-	return -y;
-}
-
-
-#ifdef __STDC__
-	double __ieee754_lgamma_r(double x, int *signgamp)
-#else
-	double __ieee754_lgamma_r(x,signgamp)
-	double x; int *signgamp;
-#endif
-{
-        fd_twoints u;
-	double t,y,z,nadj,p,p1,p2,p3,q,r,w;
-	int i,hx,lx,ix;
-
-        u.d = x;
-	hx = __HI(u);
-	lx = __LO(u);
-
-    /* purge off +-inf, NaN, +-0, and negative arguments */
-	*signgamp = 1;
-	ix = hx&0x7fffffff;
-	if(ix>=0x7ff00000) return x*x;
-	if((ix|lx)==0) return one/zero;
-	if(ix<0x3b900000) {	/* |x|<2**-70, return -log(|x|) */
-	    if(hx<0) {
-	        *signgamp = -1;
-	        return -__ieee754_log(-x);
-	    } else return -__ieee754_log(x);
-	}
-	if(hx<0) {
-	    if(ix>=0x43300000) 	/* |x|>=2**52, must be -integer */
-		return one/zero;
-	    t = sin_pi(x);
-	    if(t==zero) return one/zero; /* -integer */
-	    nadj = __ieee754_log(pi/fd_fabs(t*x));
-	    if(t<zero) *signgamp = -1;
-	    x = -x;
-	}
-
-    /* purge off 1 and 2 */
-	if((((ix-0x3ff00000)|lx)==0)||(((ix-0x40000000)|lx)==0)) r = 0;
-    /* for x < 2.0 */
-	else if(ix<0x40000000) {
-	    if(ix<=0x3feccccc) { 	/* lgamma(x) = lgamma(x+1)-log(x) */
-		r = -__ieee754_log(x);
-		if(ix>=0x3FE76944) {y = one-x; i= 0;}
-		else if(ix>=0x3FCDA661) {y= x-(tc-one); i=1;}
-	  	else {y = x; i=2;}
-	    } else {
-	  	r = zero;
-	        if(ix>=0x3FFBB4C3) {y=2.0-x;i=0;} /* [1.7316,2] */
-	        else if(ix>=0x3FF3B4C4) {y=x-tc;i=1;} /* [1.23,1.73] */
-		else {y=x-one;i=2;}
-	    }
-	    switch(i) {
-	      case 0:
-		z = y*y;
-		p1 = a0+z*(a2+z*(a4+z*(a6+z*(a8+z*a10))));
-		p2 = z*(a1+z*(a3+z*(a5+z*(a7+z*(a9+z*a11)))));
-		p  = y*p1+p2;
-		r  += (p-0.5*y); break;
-	      case 1:
-		z = y*y;
-		w = z*y;
-		p1 = t0+w*(t3+w*(t6+w*(t9 +w*t12)));	/* parallel comp */
-		p2 = t1+w*(t4+w*(t7+w*(t10+w*t13)));
-		p3 = t2+w*(t5+w*(t8+w*(t11+w*t14)));
-		p  = z*p1-(tt-w*(p2+y*p3));
-		r += (tf + p); break;
-	      case 2:	
-		p1 = y*(u0+y*(u1+y*(u2+y*(u3+y*(u4+y*u5)))));
-		p2 = one+y*(v1+y*(v2+y*(v3+y*(v4+y*v5))));
-		r += (-0.5*y + p1/p2);
-	    }
-	}
-	else if(ix<0x40200000) { 			/* x < 8.0 */
-	    i = (int)x;
-	    t = zero;
-	    y = x-(double)i;
-	    p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6))))));
-	    q = one+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))));
-	    r = half*y+p/q;
-	    z = one;	/* lgamma(1+s) = log(s) + lgamma(s) */
-	    switch(i) {
-	    case 7: z *= (y+6.0);	/* FALLTHRU */
-	    case 6: z *= (y+5.0);	/* FALLTHRU */
-	    case 5: z *= (y+4.0);	/* FALLTHRU */
-	    case 4: z *= (y+3.0);	/* FALLTHRU */
-	    case 3: z *= (y+2.0);	/* FALLTHRU */
-		    r += __ieee754_log(z); break;
-	    }
-    /* 8.0 <= x < 2**58 */
-	} else if (ix < 0x43900000) {
-	    t = __ieee754_log(x);
-	    z = one/x;
-	    y = z*z;
-	    w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6)))));
-	    r = (x-half)*(t-one)+w;
-	} else 
-    /* 2**58 <= x <= inf */
-	    r =  x*(__ieee754_log(x)-one);
-	if(hx<0) r = nadj - r;
-	return r;
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_log.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_log.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* __ieee754_log(x)
- * Return the logrithm of x
- *
- * Method :                  
- *   1. Argument Reduction: find k and f such that 
- *			x = 2^k * (1+f), 
- *	   where  sqrt(2)/2 < 1+f < sqrt(2) .
- *
- *   2. Approximation of log(1+f).
- *	Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
- *		 = 2s + 2/3 s**3 + 2/5 s**5 + .....,
- *	     	 = 2s + s*R
- *      We use a special Reme algorithm on [0,0.1716] to generate 
- * 	a polynomial of degree 14 to approximate R The maximum error 
- *	of this polynomial approximation is bounded by 2**-58.45. In
- *	other words,
- *		        2      4      6      8      10      12      14
- *	    R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s  +Lg6*s  +Lg7*s
- *  	(the values of Lg1 to Lg7 are listed in the program)
- *	and
- *	    |      2          14          |     -58.45
- *	    | Lg1*s +...+Lg7*s    -  R(z) | <= 2 
- *	    |                             |
- *	Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
- *	In order to guarantee error in log below 1ulp, we compute log
- *	by
- *		log(1+f) = f - s*(f - R)	(if f is not too large)
- *		log(1+f) = f - (hfsq - s*(hfsq+R)).	(better accuracy)
- *	
- *	3. Finally,  log(x) = k*ln2 + log(1+f).  
- *			    = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
- *	   Here ln2 is split into two floating point number: 
- *			ln2_hi + ln2_lo,
- *	   where n*ln2_hi is always exact for |n| < 2000.
- *
- * Special cases:
- *	log(x) is NaN with signal if x < 0 (including -INF) ; 
- *	log(+INF) is +INF; log(0) is -INF with signal;
- *	log(NaN) is that NaN with no signal.
- *
- * Accuracy:
- *	according to an error analysis, the error is always less than
- *	1 ulp (unit in the last place).
- *
- * Constants:
- * The hexadecimal values are the intended ones for the following 
- * constants. The decimal values may be used, provided that the 
- * compiler will convert from decimal to binary accurately enough 
- * to produce the hexadecimal values shown.
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double
-#else
-static double
-#endif
-ln2_hi  =  6.93147180369123816490e-01,	/* 3fe62e42 fee00000 */
-ln2_lo  =  1.90821492927058770002e-10,	/* 3dea39ef 35793c76 */
-two54   =  1.80143985094819840000e+16,  /* 43500000 00000000 */
-Lg1 = 6.666666666666735130e-01,  /* 3FE55555 55555593 */
-Lg2 = 3.999999999940941908e-01,  /* 3FD99999 9997FA04 */
-Lg3 = 2.857142874366239149e-01,  /* 3FD24924 94229359 */
-Lg4 = 2.222219843214978396e-01,  /* 3FCC71C5 1D8E78AF */
-Lg5 = 1.818357216161805012e-01,  /* 3FC74664 96CB03DE */
-Lg6 = 1.531383769920937332e-01,  /* 3FC39A09 D078C69F */
-Lg7 = 1.479819860511658591e-01;  /* 3FC2F112 DF3E5244 */
-
-static double zero   =  0.0;
-
-#ifdef __STDC__
-	double __ieee754_log(double x)
-#else
-	double __ieee754_log(x)
-	double x;
-#endif
-{
-        fd_twoints u;
-	double hfsq,f,s,z,R,w,t1,t2,dk;
-	int k,hx,i,j;
-	unsigned lx;
-
-        u.d = x;
-	hx = __HI(u);		/* high word of x */
-	lx = __LO(u);		/* low  word of x */
-
-	k=0;
-	if (hx < 0x00100000) {			/* x < 2**-1022  */
-	    if (((hx&0x7fffffff)|lx)==0) 
-		return -two54/zero;		/* log(+-0)=-inf */
-	    if (hx<0) return (x-x)/zero;	/* log(-#) = NaN */
-	    k -= 54; x *= two54; /* subnormal number, scale up x */
-            u.d = x;
-	    hx = __HI(u);		/* high word of x */
-	} 
-	if (hx >= 0x7ff00000) return x+x;
-	k += (hx>>20)-1023;
-	hx &= 0x000fffff;
-	i = (hx+0x95f64)&0x100000;
-        u.d = x;
-	__HI(u) = hx|(i^0x3ff00000);	/* normalize x or x/2 */
-        x = u.d;
-	k += (i>>20);
-	f = x-1.0;
-	if((0x000fffff&(2+hx))<3) {	/* |f| < 2**-20 */
-	    if(f==zero) { 
-                if(k==0) return zero; else {dk=(double)k;
-                                            return dk*ln2_hi+dk*ln2_lo;} 
-            }
-	    R = f*f*(0.5-0.33333333333333333*f);
-	    if(k==0) return f-R; else {dk=(double)k;
-	    	     return dk*ln2_hi-((R-dk*ln2_lo)-f);}
-	}
- 	s = f/(2.0+f); 
-	dk = (double)k;
-	z = s*s;
-	i = hx-0x6147a;
-	w = z*z;
-	j = 0x6b851-hx;
-	t1= w*(Lg2+w*(Lg4+w*Lg6)); 
-	t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); 
-	i |= j;
-	R = t2+t1;
-	if(i>0) {
-	    hfsq=0.5*f*f;
-	    if(k==0) return f-(hfsq-s*(hfsq+R)); else
-		     return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f);
-	} else {
-	    if(k==0) return f-s*(f-R); else
-		     return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f);
-	}
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_log10.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_log10.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* __ieee754_log10(x)
- * Return the base 10 logarithm of x
- * 
- * Method :
- *	Let log10_2hi = leading 40 bits of log10(2) and
- *	    log10_2lo = log10(2) - log10_2hi,
- *	    ivln10   = 1/log(10) rounded.
- *	Then
- *		n = ilogb(x), 
- *		if(n<0)  n = n+1;
- *		x = scalbn(x,-n);
- *		log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))
- *
- * Note 1:
- *	To guarantee log10(10**n)=n, where 10**n is normal, the rounding 
- *	mode must set to Round-to-Nearest.
- * Note 2:
- *	[1/log(10)] rounded to 53 bits has error  .198   ulps;
- *	log10 is monotonic at all binary break points.
- *
- * Special cases:
- *	log10(x) is NaN with signal if x < 0; 
- *	log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
- *	log10(NaN) is that NaN with no signal;
- *	log10(10**N) = N  for N=0,1,...,22.
- *
- * Constants:
- * The hexadecimal values are the intended ones for the following constants.
- * The decimal values may be used, provided that the compiler will convert
- * from decimal to binary accurately enough to produce the hexadecimal values
- * shown.
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double
-#else
-static double
-#endif
-two54      =  1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
-ivln10     =  4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
-log10_2hi  =  3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
-log10_2lo  =  3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
-
-static double zero   =  0.0;
-
-#ifdef __STDC__
-	double __ieee754_log10(double x)
-#else
-	double __ieee754_log10(x)
-	double x;
-#endif
-{
-        fd_twoints u;
-	double y,z;
-	int i,k,hx;
-	unsigned lx;
-
-        u.d = x;
-	hx = __HI(u);	/* high word of x */
-	lx = __LO(u);	/* low word of x */
-
-        k=0;
-        if (hx < 0x00100000) {                  /* x < 2**-1022  */
-            if (((hx&0x7fffffff)|lx)==0)
-                return -two54/zero;             /* log(+-0)=-inf */
-            if (hx<0) return (x-x)/zero;        /* log(-#) = NaN */
-            k -= 54; x *= two54; /* subnormal number, scale up x */
-            u.d = x;
-            hx = __HI(u);                /* high word of x */
-        }
-	if (hx >= 0x7ff00000) return x+x;
-	k += (hx>>20)-1023;
-	i  = ((unsigned)k&0x80000000)>>31;
-        hx = (hx&0x000fffff)|((0x3ff-i)<<20);
-        y  = (double)(k+i);
-        u.d = x;
-        __HI(u) = hx;
-        x = u.d;
-	z  = y*log10_2lo + ivln10*__ieee754_log(x);
-	return  z+y*log10_2hi;
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_pow.c
+++ /dev/null
@@ -1,386 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_pow.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* __ieee754_pow(x,y) return x**y
- *
- *		      n
- * Method:  Let x =  2   * (1+f)
- *	1. Compute and return log2(x) in two pieces:
- *		log2(x) = w1 + w2,
- *	   where w1 has 53-24 = 29 bit trailing zeros.
- *	2. Perform y*log2(x) = n+y' by simulating muti-precision 
- *	   arithmetic, where |y'|<=0.5.
- *	3. Return x**y = 2**n*exp(y'*log2)
- *
- * Special cases:
- *	1.  (anything) ** 0  is 1
- *	2.  (anything) ** 1  is itself
- *	3.  (anything) ** NAN is NAN
- *	4.  NAN ** (anything except 0) is NAN
- *	5.  +-(|x| > 1) **  +INF is +INF
- *	6.  +-(|x| > 1) **  -INF is +0
- *	7.  +-(|x| < 1) **  +INF is +0
- *	8.  +-(|x| < 1) **  -INF is +INF
- *	9.  +-1         ** +-INF is NAN
- *	10. +0 ** (+anything except 0, NAN)               is +0
- *	11. -0 ** (+anything except 0, NAN, odd integer)  is +0
- *	12. +0 ** (-anything except 0, NAN)               is +INF
- *	13. -0 ** (-anything except 0, NAN, odd integer)  is +INF
- *	14. -0 ** (odd integer) = -( +0 ** (odd integer) )
- *	15. +INF ** (+anything except 0,NAN) is +INF
- *	16. +INF ** (-anything except 0,NAN) is +0
- *	17. -INF ** (anything)  = -0 ** (-anything)
- *	18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
- *	19. (-anything except 0 and inf) ** (non-integer) is NAN
- *
- * Accuracy:
- *	pow(x,y) returns x**y nearly rounded. In particular
- *			pow(integer,integer)
- *	always returns the correct integer provided it is 
- *	representable.
- *
- * Constants :
- * The hexadecimal values are the intended ones for the following 
- * constants. The decimal values may be used, provided that the 
- * compiler will convert from decimal to binary accurately enough 
- * to produce the hexadecimal values shown.
- */
-
-#include "fdlibm.h"
-
-#if defined(_MSC_VER)
-/* Microsoft Compiler */
-#pragma warning( disable : 4723 ) /* disables potential divide by 0 warning */
-#endif
-
-#ifdef __STDC__
-static const double 
-#else
-static double 
-#endif
-bp[] = {1.0, 1.5,},
-dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
-dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
-zero    =  0.0,
-one	=  1.0,
-two	=  2.0,
-two53	=  9007199254740992.0,	/* 0x43400000, 0x00000000 */
-really_big	=  1.0e300,
-tiny    =  1.0e-300,
-	/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
-L1  =  5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
-L2  =  4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
-L3  =  3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
-L4  =  2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
-L5  =  2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
-L6  =  2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
-P1   =  1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
-P2   = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
-P3   =  6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
-P4   = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
-P5   =  4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */
-lg2  =  6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
-lg2_h  =  6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
-lg2_l  = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
-ovt =  8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
-cp    =  9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
-cp_h  =  9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
-cp_l  = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
-ivln2    =  1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
-ivln2_h  =  1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
-ivln2_l  =  1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
-
-#ifdef __STDC__
-	double __ieee754_pow(double x, double y)
-#else
-	double __ieee754_pow(x,y)
-	double x, y;
-#endif
-{
-        fd_twoints ux, uy, uz;
-        double y1,t1,p_h,t,z,ax;
-	double z_h,z_l,p_l;
-	double t2,r,s,u,v,w;
-	int i,j,k,yisint,n;
-	int hx,hy,ix,iy;
-	unsigned lx,ly;
-
-        ux.d = x; uy.d = y;
-	hx = __HI(ux); lx = __LO(ux);
-	hy = __HI(uy); ly = __LO(uy);
-	ix = hx&0x7fffffff;  iy = hy&0x7fffffff;
-
-    /* y==zero: x**0 = 1 */
-	if((iy|ly)==0) return one; 	
-
-    /* +-NaN return x+y */
-	if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
-	   iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) 
-		return x+y;	
-
-    /* determine if y is an odd int when x < 0
-     * yisint = 0	... y is not an integer
-     * yisint = 1	... y is an odd int
-     * yisint = 2	... y is an even int
-     */
-	yisint  = 0;
-	if(hx<0) {	
-	    if(iy>=0x43400000) yisint = 2; /* even integer y */
-	    else if(iy>=0x3ff00000) {
-		k = (iy>>20)-0x3ff;	   /* exponent */
-		if(k>20) {
-		    j = ly>>(52-k);
-		    if((j<<(52-k))==(int)ly) yisint = 2-(j&1);
-		} else if(ly==0) {
-		    j = iy>>(20-k);
-		    if((j<<(20-k))==iy) yisint = 2-(j&1);
-		}
-	    }		
-	} 
-
-    /* special value of y */
-	if(ly==0) { 	
-	    if (iy==0x7ff00000) {	/* y is +-inf */
-	        if(((ix-0x3ff00000)|lx)==0)
-#ifdef _WIN32
-/* VC++ optimizer reduces y - y to 0 */ 
-                    return y / y;
-#else
-		    return  y - y;	/* inf**+-1 is NaN */
-#endif
-	        else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */
-		    return (hy>=0)? y: zero;
-	        else			/* (|x|<1)**-,+inf = inf,0 */
-		    return (hy<0)?-y: zero;
-	    } 
-	    if(iy==0x3ff00000) {	/* y is  +-1 */
-		if(hy<0) return one/x; else return x;
-	    }
-	    if(hy==0x40000000) return x*x; /* y is  2 */
-	    if(hy==0x3fe00000) {	/* y is  0.5 */
-		if(hx>=0)	/* x >= +0 */
-		return fd_sqrt(x);	
-	    }
-	}
-
-	ax   = fd_fabs(x);
-    /* special value of x */
-	if(lx==0) {
-	    if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
-		z = ax;			/*x is +-0,+-inf,+-1*/
-		if(hy<0) z = one/z;	/* z = (1/|x|) */
-		if(hx<0) {
-		    if(((ix-0x3ff00000)|yisint)==0) {
-			z = (z-z)/(z-z); /* (-1)**non-int is NaN */
-		    } else if(yisint==1) {
-#ifdef HPUX
-                        uz.d = z;
-			__HI(uz) ^= 1<<31; /* some HPUXes cannot negate 0.. */
-                        z = uz.d;
-#else
-			z = -z;		/* (x<0)**odd = -(|x|**odd) */
-#endif
-			}
-		}
-		return z;
-	    }
-	}
-    
-    /* (x<0)**(non-int) is NaN */
-	if((((hx>>31)+1)|yisint)==0) return (x-x)/(x-x);
-
-    /* |y| is really_big */
-	if(iy>0x41e00000) { /* if |y| > 2**31 */
-	    if(iy>0x43f00000){	/* if |y| > 2**64, must o/uflow */
-		if(ix<=0x3fefffff) return (hy<0)? really_big*really_big:tiny*tiny;
-		if(ix>=0x3ff00000) return (hy>0)? really_big*really_big:tiny*tiny;
-	    }
-	/* over/underflow if x is not close to one */
-	    if(ix<0x3fefffff) return (hy<0)? really_big*really_big:tiny*tiny;
-	    if(ix>0x3ff00000) return (hy>0)? really_big*really_big:tiny*tiny;
-	/* now |1-x| is tiny <= 2**-20, suffice to compute 
-	   log(x) by x-x^2/2+x^3/3-x^4/4 */
-	    t = x-1;		/* t has 20 trailing zeros */
-	    w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
-	    u = ivln2_h*t;	/* ivln2_h has 21 sig. bits */
-	    v = t*ivln2_l-w*ivln2;
-	    t1 = u+v;
-            uz.d = t1;
-	    __LO(uz) = 0;
-            t1 = uz.d;
-	    t2 = v-(t1-u);
-	} else {
-	    double s_h,t_h;
-	    double s2,s_l,t_l;
-	    n = 0;
-	/* take care subnormal number */
-	    if(ix<0x00100000) 
-		{ax *= two53; n -= 53; uz.d = ax; ix = __HI(uz); }
-	    n  += ((ix)>>20)-0x3ff;
-	    j  = ix&0x000fffff;
-	/* determine interval */
-	    ix = j|0x3ff00000;		/* normalize ix */
-	    if(j<=0x3988E) k=0;		/* |x|<sqrt(3/2) */
-	    else if(j<0xBB67A) k=1;	/* |x|<sqrt(3)   */
-	    else {k=0;n+=1;ix -= 0x00100000;}
-            uz.d = ax;
-	    __HI(uz) = ix;
-            ax = uz.d;
-
-	/* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
-	    u = ax-bp[k];		/* bp[0]=1.0, bp[1]=1.5 */
-	    v = one/(ax+bp[k]);
-	    s = u*v;
-	    s_h = s;
-            uz.d = s_h;
-	    __LO(uz) = 0;
-            s_h = uz.d;
-	/* t_h=ax+bp[k] High */
-	    t_h = zero;
-            uz.d = t_h;
-	    __HI(uz)=((ix>>1)|0x20000000)+0x00080000+(k<<18); 
-            t_h = uz.d;
-	    t_l = ax - (t_h-bp[k]);
-	    s_l = v*((u-s_h*t_h)-s_h*t_l);
-	/* compute log(ax) */
-	    s2 = s*s;
-	    r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
-	    r += s_l*(s_h+s);
-	    s2  = s_h*s_h;
-	    t_h = 3.0+s2+r;
-            uz.d = t_h;
-	    __LO(uz) = 0;
-            t_h = uz.d;
-	    t_l = r-((t_h-3.0)-s2);
-	/* u+v = s*(1+...) */
-	    u = s_h*t_h;
-	    v = s_l*t_h+t_l*s;
-	/* 2/(3log2)*(s+...) */
-	    p_h = u+v;
-            uz.d = p_h;
-	    __LO(uz) = 0;
-            p_h = uz.d;
-	    p_l = v-(p_h-u);
-	    z_h = cp_h*p_h;		/* cp_h+cp_l = 2/(3*log2) */
-	    z_l = cp_l*p_h+p_l*cp+dp_l[k];
-	/* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
-	    t = (double)n;
-	    t1 = (((z_h+z_l)+dp_h[k])+t);
-            uz.d = t1;
-	    __LO(uz) = 0;
-            t1 = uz.d;
-	    t2 = z_l-(((t1-t)-dp_h[k])-z_h);
-	}
-
-	s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
-	if((((hx>>31)+1)|(yisint-1))==0) s = -one;/* (-ve)**(odd int) */
-
-    /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
-	y1  = y;
-        uy.d = y1;
-	__LO(uy) = 0;
-        y1 = uy.d;
-	p_l = (y-y1)*t1+y*t2;
-	p_h = y1*t1;
-	z = p_l+p_h;
-        uz.d = z;
-	j = __HI(uz);
-	i = __LO(uz);
-
-	if (j>=0x40900000) {				/* z >= 1024 */
-	    if(((j-0x40900000)|i)!=0)			/* if z > 1024 */
-		return s*really_big*really_big;			/* overflow */
-	    else {
-		if(p_l+ovt>z-p_h) return s*really_big*really_big;	/* overflow */
-	    }
-	} else if((j&0x7fffffff)>=0x4090cc00 ) {	/* z <= -1075 */
-	    if(((j-0xc090cc00)|i)!=0) 		/* z < -1075 */
-		return s*tiny*tiny;		/* underflow */
-	    else {
-		if(p_l<=z-p_h) return s*tiny*tiny;	/* underflow */
-	    }
-	}
-    /*
-     * compute 2**(p_h+p_l)
-     */
-	i = j&0x7fffffff;
-	k = (i>>20)-0x3ff;
-	n = 0;
-	if(i>0x3fe00000) {		/* if |z| > 0.5, set n = [z+0.5] */
-	    n = j+(0x00100000>>(k+1));
-	    k = ((n&0x7fffffff)>>20)-0x3ff;	/* new k for n */
-	    t = zero;
-            uz.d = t;
-	    __HI(uz) = (n&~(0x000fffff>>k));
-            t = uz.d;
-	    n = ((n&0x000fffff)|0x00100000)>>(20-k);
-	    if(j<0) n = -n;
-	    p_h -= t;
-	} 
-	t = p_l+p_h;
-        uz.d = t;
-	__LO(uz) = 0;
-        t = uz.d;
-	u = t*lg2_h;
-	v = (p_l-(t-p_h))*lg2+t*lg2_l;
-	z = u+v;
-	w = v-(z-u);
-	t  = z*z;
-	t1  = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
-	r  = (z*t1)/(t1-two)-(w+z*w);
-	z  = one-(r-z);
-        uz.d = z;
-	j  = __HI(uz);
-	j += (n<<20);
-	if((j>>20)<=0) z = fd_scalbn(z,n);	/* subnormal output */
-	else { uz.d = z; __HI(uz) += (n<<20); z = uz.d; }
-	return s*z;
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_rem_pio2.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_rem_pio2.c 1.4 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- *
- */
-
-/* __ieee754_rem_pio2(x,y)
- * 
- * return the remainder of x rem pi/2 in y[0]+y[1] 
- * use __kernel_rem_pio2()
- */
-
-#include "fdlibm.h"
-
-/*
- * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi 
- */
-#ifdef __STDC__
-static const int two_over_pi[] = {
-#else
-static int two_over_pi[] = {
-#endif
-0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, 
-0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, 
-0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, 
-0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, 
-0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, 
-0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, 
-0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, 
-0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, 
-0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, 
-0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, 
-0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, 
-};
-
-#ifdef __STDC__
-static const int npio2_hw[] = {
-#else
-static int npio2_hw[] = {
-#endif
-0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C,
-0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C,
-0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A,
-0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,
-0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB,
-0x404858EB, 0x404921FB,
-};
-
-/*
- * invpio2:  53 bits of 2/pi
- * pio2_1:   first  33 bit of pi/2
- * pio2_1t:  pi/2 - pio2_1
- * pio2_2:   second 33 bit of pi/2
- * pio2_2t:  pi/2 - (pio2_1+pio2_2)
- * pio2_3:   third  33 bit of pi/2
- * pio2_3t:  pi/2 - (pio2_1+pio2_2+pio2_3)
- */
-
-#ifdef __STDC__
-static const double 
-#else
-static double 
-#endif
-zero =  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
-half =  5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
-two24 =  1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
-invpio2 =  6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
-pio2_1  =  1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
-pio2_1t =  6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
-pio2_2  =  6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
-pio2_2t =  2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
-pio2_3  =  2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
-pio2_3t =  8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
-
-#ifdef __STDC__
-	int __ieee754_rem_pio2(double x, double *y)
-#else
-	int __ieee754_rem_pio2(x,y)
-	double x,y[];
-#endif
-{
-        fd_twoints u, ux, uz;
-        double z = 0;
-	double w,t,r,fn;
-	double tx[3];
-	int e0,i,j,nx,n,ix,hx;
-
-        u.d = x;
-	hx = __HI(u);		/* high word of x */
-	ix = hx&0x7fffffff;
-	if(ix<=0x3fe921fb)   /* |x| ~<= pi/4 , no need for reduction */
-	    {y[0] = x; y[1] = 0; return 0;}
-	if(ix<0x4002d97c) {  /* |x| < 3pi/4, special case with n=+-1 */
-	    if(hx>0) { 
-		z = x - pio2_1;
-		if(ix!=0x3ff921fb) { 	/* 33+53 bit pi is good enough */
-		    y[0] = z - pio2_1t;
-		    y[1] = (z-y[0])-pio2_1t;
-		} else {		/* near pi/2, use 33+33+53 bit pi */
-		    z -= pio2_2;
-		    y[0] = z - pio2_2t;
-		    y[1] = (z-y[0])-pio2_2t;
-		}
-		return 1;
-	    } else {	/* negative x */
-		z = x + pio2_1;
-		if(ix!=0x3ff921fb) { 	/* 33+53 bit pi is good enough */
-		    y[0] = z + pio2_1t;
-		    y[1] = (z-y[0])+pio2_1t;
-		} else {		/* near pi/2, use 33+33+53 bit pi */
-		    z += pio2_2;
-		    y[0] = z + pio2_2t;
-		    y[1] = (z-y[0])+pio2_2t;
-		}
-		return -1;
-	    }
-	}
-	if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */
-	    t  = fd_fabs(x);
-	    n  = (int) (t*invpio2+half);
-	    fn = (double)n;
-	    r  = t-fn*pio2_1;
-	    w  = fn*pio2_1t;	/* 1st round good to 85 bit */
-	    if(n<32&&ix!=npio2_hw[n-1]) {	
-		y[0] = r-w;	/* quick check no cancellation */
-	    } else {
-	        j  = ix>>20;
-	        y[0] = r-w;
-                u.d = y[0];
-	        i = j-(((__HI(u))>>20)&0x7ff);
-	        if(i>16) {  /* 2nd iteration needed, good to 118 */
-		    t  = r;
-		    w  = fn*pio2_2;	
-		    r  = t-w;
-		    w  = fn*pio2_2t-((t-r)-w);	
-		    y[0] = r-w;
-                    u.d = y[0];
-		    i = j-(((__HI(u))>>20)&0x7ff);
-		    if(i>49)  {	/* 3rd iteration need, 151 bits acc */
-		    	t  = r;	/* will cover all possible cases */
-		    	w  = fn*pio2_3;	
-		    	r  = t-w;
-		    	w  = fn*pio2_3t-((t-r)-w);	
-		    	y[0] = r-w;
-		    }
-		}
-	    }
-	    y[1] = (r-y[0])-w;
-	    if(hx<0) 	{y[0] = -y[0]; y[1] = -y[1]; return -n;}
-	    else	 return n;
-	}
-    /* 
-     * all other (large) arguments
-     */
-	if(ix>=0x7ff00000) {		/* x is inf or NaN */
-	    y[0]=y[1]=x-x; return 0;
-	}
-    /* set z = scalbn(|x|,ilogb(x)-23) */
-        ux.d = x; uz.d = z;
-	__LO(uz) = __LO(ux);
-        z = uz.d;
-	e0 	= (ix>>20)-1046;	/* e0 = ilogb(z)-23; */
-        uz.d = z;
-	__HI(uz) = ix - (e0<<20);
-        z = uz.d;
-	for(i=0;i<2;i++) {
-		tx[i] = (double)((int)(z));
-		z     = (z-tx[i])*two24;
-	}
-	tx[2] = z;
-	nx = 3;
-	while(tx[nx-1]==zero) nx--;	/* skip zero term */
-	n  =  __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);
-	if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
-	return n;
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_remainder.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_remainder.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/* __ieee754_remainder(x,p)
- * Return :                  
- * 	returns  x REM p  =  x - [x/p]*p as if in infinite 
- * 	precise arithmetic, where [x/p] is the (infinite bit) 
- *	integer nearest x/p (in half way case choose the even one).
- * Method : 
- *	Based on fmod() return x-[x/p]chopped*p exactlp.
- */
-
-#include "fdlibm.h"
-
-#ifdef __STDC__
-static const double zero = 0.0;
-#else
-static double zero = 0.0;
-#endif
-
-
-#ifdef __STDC__
-	double __ieee754_remainder(double x, double p)
-#else
-	double __ieee754_remainder(x,p)
-	double x,p;
-#endif
-{
-        fd_twoints u;
-	int hx,hp;
-	unsigned sx,lx,lp;
-	double p_half;
-
-        u.d = x;
-	hx = __HI(u);		/* high word of x */
-	lx = __LO(u);		/* low  word of x */
-        u.d = p;
-	hp = __HI(u);		/* high word of p */
-	lp = __LO(u);		/* low  word of p */
-	sx = hx&0x80000000;
-	hp &= 0x7fffffff;
-	hx &= 0x7fffffff;
-
-    /* purge off exception values */
-	if((hp|lp)==0) return (x*p)/(x*p); 	/* p = 0 */
-	if((hx>=0x7ff00000)||			/* x not finite */
-	  ((hp>=0x7ff00000)&&			/* p is NaN */
-	  (((hp-0x7ff00000)|lp)!=0)))
-	    return (x*p)/(x*p);
-
-
-	if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p);	/* now x < 2p */
-	if (((hx-hp)|(lx-lp))==0) return zero*x;
-	x  = fd_fabs(x);
-	p  = fd_fabs(p);
-	if (hp<0x00200000) {
-	    if(x+x>p) {
-		x-=p;
-		if(x+x>=p) x -= p;
-	    }
-	} else {
-	    p_half = 0.5*p;
-	    if(x>p_half) {
-		x-=p;
-		if(x>=p_half) x -= p;
-	    }
-	}
-        u.d = x;
-	__HI(u) ^= sx;
-        x = u.d;
-	return x;
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_scalb.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_scalb.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice 
- * is preserved.
- * ====================================================
- */
-
-/*
- * __ieee754_scalb(x, fn) is provide for
- * passing various standard test suite. One 
- * should use scalbn() instead.
- */
-
-#include "fdlibm.h"
-
-#ifdef _SCALB_INT
-#ifdef __STDC__
-	double __ieee754_scalb(double x, int fn)
-#else
-	double __ieee754_scalb(x,fn)
-	double x; int fn;
-#endif
-#else
-#ifdef __STDC__
-	double __ieee754_scalb(double x, double fn)
-#else
-	double __ieee754_scalb(x,fn)
-	double x, fn;
-#endif
-#endif
-{
-#ifdef _SCALB_INT
-	return fd_scalbn(x,fn);
-#else
-	if (fd_isnan(x)||fd_isnan(fn)) return x*fn;
-	if (!fd_finite(fn)) {
-	    if(fn>0.0) return x*fn;
-	    else       return x/(-fn);
-	}
-	if (fd_rint(fn)!=fn) return (fn-fn)/(fn-fn);
-	if ( fn > 65000.0) return fd_scalbn(x, 65000);
-	if (-fn > 65000.0) return fd_scalbn(x,-65000);
-	return fd_scalbn(x,(int)fn);
-#endif
-}
deleted file mode 100644
--- a/js/src/fdlibm/e_sinh.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Communicator client code, released
- * March 31, 1998.
- *
- * The Initial Developer of the Original Code is
- * Sun Microsystems, Inc.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* @(#)e_sinh.c 1.3 95/01/18 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this</