Bug 799917 - Make document.characterSet always lowercase; r=bz,f=hsivonen,smontagu
authorAryeh Gregor <ayg@aryeh.name>
Sun, 14 Oct 2012 10:13:19 +0200
changeset 118867 ba1ece534b748b22e68597b7ef4ba237ba17b143
parent 118866 eaa7aff9f43c4d065c47f99dacbe30d8a0accdc4
child 118868 c1bbabd184b33ec21cba783c64760937cffe975f
push id273
push userlsblakk@mozilla.com
push dateThu, 14 Feb 2013 23:19:38 +0000
treeherdermozilla-release@c5e807a3f8b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs799917
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 799917 - Make document.characterSet always lowercase; r=bz,f=hsivonen,smontagu
content/base/src/nsDocument.cpp
content/base/test/test_XHRSendData.html
content/base/test/test_bug431701.html
content/html/content/test/test_bug615595.html
content/html/document/test/test_bug255820.html
content/html/document/test/test_bug380383.html
extensions/universalchardet/tests/CharsetDetectionTests.js
extensions/universalchardet/tests/test_bug306272.html
extensions/universalchardet/tests/test_bug426271-euc-jp.html
extensions/universalchardet/tests/test_bug426271-utf-8.html
extensions/universalchardet/tests/test_bug431054-japanese.html
extensions/universalchardet/tests/test_bug488426.html
extensions/universalchardet/tests/test_bug620106.html
extensions/universalchardet/tests/test_bug631751be.html
extensions/universalchardet/tests/test_bug631751le.html
extensions/universalchardet/tests/test_bug638318.html
extensions/universalchardet/tests/test_bug9357.html
js/xpconnect/tests/mochitest/test_bug393269.html
parser/htmlparser/tests/mochitest/test_bug102699.html
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -4935,16 +4935,17 @@ nsDocument::EnableStyleSheetsForSetInter
   }
   EndUpdate(UPDATE_STYLE);
 }
 
 NS_IMETHODIMP
 nsDocument::GetCharacterSet(nsAString& aCharacterSet)
 {
   CopyASCIItoUTF16(GetDocumentCharacterSet(), aCharacterSet);
+  ToLowerCase(aCharacterSet);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocument::ImportNode(nsIDOMNode* aImportedNode,
                        bool aDeep,
                        uint8_t aArgc,
                        nsIDOMNode** aResult)
--- a/content/base/test/test_XHRSendData.html
+++ b/content/base/test/test_XHRSendData.html
@@ -25,17 +25,17 @@ var gen = runTests();
 function continueTest() { gen.next(); }
 
 function runTests() {
 
 xhr = new XMLHttpRequest();
 xhr.open("GET", "file_XHRSendData_doc.xml", false);
 xhr.send();
 testDoc1 = xhr.responseXML;
-is(testDoc1.inputEncoding, "ISO-8859-1", "wrong encoding");
+is(testDoc1.inputEncoding, "iso-8859-1", "wrong encoding");
 
 testDoc2 = document.implementation.createDocument("", "", null);
 testDoc2.appendChild(testDoc2.createComment(" doc 2 "));
 testDoc2.appendChild(testDoc2.createElement("res"));
 testDoc2.documentElement.appendChild(testDoc2.createTextNode("text"));
 is(testDoc2.inputEncoding, null, "wrong encoding");
 
 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
@@ -116,27 +116,27 @@ tests = [{ body: null,
          },
          { body: "hi",
            contentType: "foo/bar; charset=uTf-8",
            resBody: "hi",
            resContentType: "foo/bar; charset=uTf-8",
          },
          { body: testDoc1,
            resBody: "<!-- comment -->\n<out>hi</out>",
-           resContentType: "application/xml; charset=ISO-8859-1",
+           resContentType: "application/xml; charset=iso-8859-1",
          },
          { body: testDoc1,
            contentType: "foo/bar",
            resBody: "<!-- comment -->\n<out>hi</out>",
-           resContentType: "foo/bar; charset=ISO-8859-1",
+           resContentType: "foo/bar; charset=iso-8859-1",
          },
          { body: testDoc1,
            contentType: "foo/bar; charset=ascii; baz=bin",
            resBody: "<!-- comment -->\n<out>hi</out>",
-           resContentType: "foo/bar; charset=ISO-8859-1; baz=bin",
+           resContentType: "foo/bar; charset=iso-8859-1; baz=bin",
          },
          { body: testDoc1,
            contentType: "foo/bar; charset=IsO-8859-1",
            resBody: "<!-- comment -->\n<out>hi</out>",
            resContentType: "foo/bar; charset=IsO-8859-1",
          },
          { body: testDoc2,
            resBody: "<!-- doc 2 -->\n<res>text</res>",
--- a/content/base/test/test_bug431701.html
+++ b/content/base/test/test_bug431701.html
@@ -57,27 +57,27 @@ function xhrDoc(idx) {
     return xhr.responseXML;
   };
 }
 
 // Each row has the document getter function, then the characterSet,
 // inputEncoding expected for that document.
 
 var tests = [
- [ frameDoc("one"), "ISO-8859-1", "ISO-8859-1" ],
- [ frameDoc("two"), "UTF-8", "UTF-8" ],
- [ frameDoc("three"), "ISO-8859-1", "ISO-8859-1" ],
- [ frameDoc("four"), "UTF-8", "UTF-8" ],
- [ frameDoc("five"), "UTF-8", "UTF-8" ],
- [ frameDoc("six"), "UTF-8", "UTF-8" ],
- [ frameDoc("seven"), "ISO-8859-1", "ISO-8859-1" ],
- [ createDoc, "UTF-8", null ],
- [ xhrDoc(4), "UTF-8", "UTF-8" ],
- [ xhrDoc(5), "UTF-8", "UTF-8" ],
- [ xhrDoc(6), "ISO-8859-1", "ISO-8859-1" ],
+ [ frameDoc("one"), "iso-8859-1", "iso-8859-1" ],
+ [ frameDoc("two"), "utf-8", "utf-8" ],
+ [ frameDoc("three"), "iso-8859-1", "iso-8859-1" ],
+ [ frameDoc("four"), "utf-8", "utf-8" ],
+ [ frameDoc("five"), "utf-8", "utf-8" ],
+ [ frameDoc("six"), "utf-8", "utf-8" ],
+ [ frameDoc("seven"), "iso-8859-1", "iso-8859-1" ],
+ [ createDoc, "utf-8", null ],
+ [ xhrDoc(4), "utf-8", "utf-8" ],
+ [ xhrDoc(5), "utf-8", "utf-8" ],
+ [ xhrDoc(6), "iso-8859-1", "iso-8859-1" ],
 ];
 
 function doTest(idx) {
   var [docGetter, expectedCharacterSet,
        expectedInputEncoding] = tests[idx];
   var doc = docGetter();
 
   // Have to be careful here to catch null vs ""
index 3acaad9e0c25cbb16dd60fcbe6facf1c4aa8ef1f..f0b4f1fa527b112a4666854f77c73258064ce9da
GIT binary patch
literal 2692
zc$~df+iuf95S{0I#nu9vqGGE;AZQaRpsjdlMWq%Yo~o_w5JTcvvC~peznMP(&dl!G
z>%^r6A!ON^z08@jvu9`X<0lPhjrQm*y{1$8K*zLCir&CJqC<K?J&cd3qA5*mYmFY^
z=}B)z1(mc-5uS5e&`0`88D>sMQwX0~t39JRW<>B9!@i_5>l0FpZ$`U#6B^P}+M*|T
zp5yIFG{++aP9iOZXMhMPIB3{0Mm6wD=^0W0<cdb{eFnSns1Tz9pA>zk_?BoX%wukf
zUI`!7VlV(>-^(GDh&e}pAqW*+!Ad2vhE-s8h8bFXXOsiw6IvH|ea`^CC0em~awNm4
zgnfcJQ$b2=uHC&MuuJ$GZp+VVZr;K3pw7)e_N3v|tdZA{)8|_;6h>0a=KfN0F%f3G
zW2s%GpCMl57g<e=S>4RXf;qZ#UaC454l}a4iCW4TKy@?NSGJ{vn-*=lwXrf;v%L0T
ziOc`dJ@3m=3+HBaYP*sGV+JX}H$%KaJg>YHVD{DMeG1#0ps{3RNb5ES>m51q+kqEp
zBrT1#IHhxM4(kMbSvSWRWxuelByB#16DzHdQ|oJGz19kI%7HYs{fV3{E&Y6|Ch#>Q
zn!dy0{^$?ljAca$TKP(>vnBnXb)fT3xV*OeGxX0bnvZ*PPOJJ{`o2!hg|&E(FFdbU
zvR}yxTxD@*aa9xB!i7CjZ$C@~gX~l_7v2pwbIt-g{;%pFqxCTQ5RbZJZB{Zn63_0s
zc!@Y%yAK3qA4+nJOfRb;latw}4cZYTEjl=a2V48#YBJgfmj$dw>FlHEo6Q~L^x-kX
zjD_r2ZtIcJjyWSKtP|PsP53nT)D~72SPqPK4_HPC8&X4Z@HUJTva4?4((tK7*`@IC
z_3>WTo=8Os1>4`H&6SFL`P=znT_Z#JH7bi?^*znF%IEK)UlmrP{{3@X4ce_M$Pn*+
z{Qr53?@MSRr3W1+e%QM4HafTlh{lz40rW&}4K3PHlKHvhB^FJ)$V%>*gqH7DW$y}y
zbZ${5qGncBB4=$@kF~k&c-*?r#i&F1Jo{QsK%>8r)n5rN=fKJ29GLmn`0aK6doWdM
O?$xaJog4Z8DSrX&YNiGN
--- a/content/html/document/test/test_bug255820.html
+++ b/content/html/document/test/test_bug255820.html
@@ -20,17 +20,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 255820 **/
 SimpleTest.waitForExplicitFinish();
 
-is(document.characterSet, "UTF-8",
+is(document.characterSet, "utf-8",
    "Unexpected character set for our document");
 
 var testsLeft = 4;
 
 function testFinished() {
   --testsLeft;
   if (testsLeft == 0) {
     SimpleTest.finish();
@@ -58,64 +58,64 @@ function f3Continue() {
   is(doc.defaultView.getComputedStyle(doc.body, "").color, "rgb(0, 180, 0)",
      "Wrong color before reload");
   $("f3").
     setAttribute("onload",
                  'var doc = this.contentDocument; ' + 
                  'is(doc.defaultView.getComputedStyle(doc.body, "").color, ' +
                  '   "rgb(0, 180, 0)",' +
                  '   "Wrong color after reload");' +
-                 "charsetTestFinished('f1', this.contentDocument, 'UTF-8')");
+                 "charsetTestFinished('f1', this.contentDocument, 'utf-8')");
   $("f3").contentWindow.location.reload();
 }
 
 function runTest() {
   var doc = $("f1").contentDocument;
-  is(doc.characterSet, "UTF-8",
+  is(doc.characterSet, "utf-8",
      "Unexpected initial character set for first frame");
   doc.open();
   doc.write('<html></html>');
   doc.close();
-  is(doc.characterSet, "UTF-8",
+  is(doc.characterSet, "utf-8",
      "Unexpected character set for first frame after write");
   $("f1").
     setAttribute("onload",
-                 "charsetTestFinished('f1', this.contentDocument, 'UTF-8')");
+                 "charsetTestFinished('f1', this.contentDocument, 'utf-8')");
   $("f1").contentWindow.location.reload();
 
   doc = $("f2").contentDocument;
-  is(doc.characterSet, "UTF-8",
+  is(doc.characterSet, "utf-8",
      "Unexpected initial character set for second frame");
   doc.open();
   var str = '<html><head>';
   str += '<script src="data:application/javascript,"><'+'/script>';
   str += '<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">';
   str += '</head><body>';
   str += '</body></html>';
   doc.write(str);
   doc.close();
-  is(doc.characterSet, "UTF-8",
+  is(doc.characterSet, "utf-8",
      "Unexpected character set for second frame after write");
   $("f2").
     setAttribute("onload",
-      "charsetTestFinished('f2', this.contentDocument, 'UTF-8');" +
+      "charsetTestFinished('f2', this.contentDocument, 'utf-8');" +
       "f2Continue()");
 
   doc = $("f3").contentDocument;
-  is(doc.characterSet, "UTF-8",
+  is(doc.characterSet, "utf-8",
      "Unexpected initial character set for first frame");
   doc.open();
   var str = '<html><head>';
   str += '<style>body { color: rgb(255, 0, 0) }</style>';
   str += '<link type="text/css" rel="stylesheet" href="data:text/css, body { color: rgb(0, 180, 0) }">';
   str += '</head><body>';
   str += '</body></html>';
   doc.write(str);
   doc.close();
-  is(doc.characterSet, "UTF-8",
+  is(doc.characterSet, "utf-8",
      "Unexpected character set for first frame after write");
   $("f3").setAttribute("onload", "f3Continue()");
 }
 
 addLoadEvent(runTest);
 </script>
 </pre>
 </body>
--- a/content/html/document/test/test_bug380383.html
+++ b/content/html/document/test/test_bug380383.html
@@ -16,21 +16,21 @@ https://bugzilla.mozilla.org/show_bug.cg
   <iframe id="f2" name="f2"></iframe>
 </p>
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
   /** Test for Bug 380383 **/
-  is($("f1").contentDocument.characterSet, "UTF-8",
+  is($("f1").contentDocument.characterSet, "utf-8",
      "Unexpected charset for f1");
 
   function runTest() {
-    is($("f2").contentDocument.characterSet, "UTF-8",
+    is($("f2").contentDocument.characterSet, "utf-8",
        "Unexpected charset for f2");
   }
      
   addLoadEvent(runTest);
   addLoadEvent(SimpleTest.finish);
   SimpleTest.waitForExplicitFinish();
 </script>
 </pre>
--- a/extensions/universalchardet/tests/CharsetDetectionTests.js
+++ b/extensions/universalchardet/tests/CharsetDetectionTests.js
@@ -44,19 +44,19 @@ function InitDetectorTests()
     gTestIndex = 0;
     $("testframe").onload = DoDetectionTest;
 
     if (gExpectedCharset == "default") {
         try {
             gExpectedCharset = prefService
                 .getComplexValue("intl.charset.default",
                                  Ci.nsIPrefLocalizedString)
-                .data;
+                .data.toLowerCase();
         } catch (e) {
-            gExpectedCharset = "ISO-8859-8";
+            gExpectedCharset = "iso-8859-8";
         }
     }
 
     // Get the local directory. This needs to be a file: URI because chrome:
     // URIs are always UTF-8 (bug 617339) and we are testing decoding from other
     // charsets.
     var jar = getJar(getRootDirectory(window.location.href));
     var dir = jar ?
--- a/extensions/universalchardet/tests/test_bug306272.html
+++ b/extensions/universalchardet/tests/test_bug306272.html
@@ -17,17 +17,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <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 306272 **/
 CharsetDetectionTests("bug306272_text.html",
-		      "UTF-8",
+		      "utf-8",
 		      new Array("ja_parallel_state_machine",
 				"zh_parallel_state_machine",
 				"zhtw_parallel_state_machine",
 				"zhcn_parallel_state_machine",
 				"cjk_parallel_state_machine",
 				"universal_charset_detector"));
 </script>
 </pre>
--- a/extensions/universalchardet/tests/test_bug426271-euc-jp.html
+++ b/extensions/universalchardet/tests/test_bug426271-euc-jp.html
@@ -17,17 +17,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <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 426271 **/
 CharsetDetectionTests("bug426271_text-euc-jp.html",
-		      "EUC-JP",
+		      "euc-jp",
 		      new Array("ja_parallel_state_machine",
 				"cjk_parallel_state_machine",
 				"universal_charset_detector"));
 </script>
 </pre>
 </body>
 </html>
 
--- a/extensions/universalchardet/tests/test_bug426271-utf-8.html
+++ b/extensions/universalchardet/tests/test_bug426271-utf-8.html
@@ -17,17 +17,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <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 426271 **/
 CharsetDetectionTests("bug426271_text-utf-8.html",
-		      "UTF-8",
+		      "utf-8",
 		      new Array("ja_parallel_state_machine",
 				"zhtw_parallel_state_machine",
 				"zhcn_parallel_state_machine",
 				"zh_parallel_state_machine",
 				"cjk_parallel_state_machine",
 				"universal_charset_detector"));
 </script>
 </pre>
--- a/extensions/universalchardet/tests/test_bug431054-japanese.html
+++ b/extensions/universalchardet/tests/test_bug431054-japanese.html
@@ -17,14 +17,14 @@ https://bugzilla.mozilla.org/show_bug.cg
 <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 431054 **/
 CharsetDetectionTests("bug431054_text.html",
-		      "EUC-JP",
+		      "euc-jp",
 		      new Array("ja_parallel_state_machine"));
 </script>
 </pre>
 </body>
 </html>
--- a/extensions/universalchardet/tests/test_bug488426.html
+++ b/extensions/universalchardet/tests/test_bug488426.html
@@ -17,14 +17,14 @@ https://bugzilla.mozilla.org/show_bug.cg
 <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 488426 **/
 CharsetDetectionTests("bug488426_text.html",
-		      "TIS-620",
+		      "tis-620",
 		      new Array("universal_charset_detector"));
 </script>
 </pre>
 </body>
 </html>
--- a/extensions/universalchardet/tests/test_bug620106.html
+++ b/extensions/universalchardet/tests/test_bug620106.html
@@ -17,14 +17,14 @@ https://bugzilla.mozilla.org/show_bug.cg
 <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 620106 **/
 CharsetDetectionTests("bug620106_text.html",
-		      "EUC-JP",
+		      "euc-jp",
 		      new Array("universal_charset_detector"));
 </script>
 </pre>
 </body>
 </html>
--- a/extensions/universalchardet/tests/test_bug631751be.html
+++ b/extensions/universalchardet/tests/test_bug631751be.html
@@ -18,14 +18,14 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">  
 </div>
 <iframe id="testframe"></iframe>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 /** Test for Bug 631751 **/
 /* Note! This test uses the chardet test harness but doesn't test chardet! */
 CharsetDetectionTests("bug631751be_text.html",
-		      "UTF-16BE",
+		      "utf-16be",
 		      new Array(""));
 </script>
 </pre>
 </body>
 </html>
--- a/extensions/universalchardet/tests/test_bug631751le.html
+++ b/extensions/universalchardet/tests/test_bug631751le.html
@@ -18,14 +18,14 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">  
 </div>
 <iframe id="testframe"></iframe>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 /** Test for Bug 631751 **/
 /* Note! This test uses the chardet test harness but doesn't test chardet! */
 CharsetDetectionTests("bug631751le_text.html",
-		      "UTF-16LE",
+		      "utf-16le",
 		      new Array(""));
 </script>
 </pre>
 </body>
 </html>
--- a/extensions/universalchardet/tests/test_bug638318.html
+++ b/extensions/universalchardet/tests/test_bug638318.html
@@ -18,14 +18,14 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">  
 </div>
 <iframe id="testframe"></iframe>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 /** Test for Bug 638318 **/
 /* Note! This test uses the chardet test harness but doesn't test chardet! */
 CharsetDetectionTests("bug638318_text.html",
-		      "ISO-8859-1",
+		      "iso-8859-1",
 		      new Array(""));
 </script>
 </pre>
 </body>
 </html>
--- a/extensions/universalchardet/tests/test_bug9357.html
+++ b/extensions/universalchardet/tests/test_bug9357.html
@@ -17,17 +17,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <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",
+		      "euc-kr",
 		      new Array("ko_parallel_state_machine",
 				"cjk_parallel_state_machine",
 				"universal_charset_detector"));
 </script>
 </pre>
 </body>
 </html>
 
--- a/js/xpconnect/tests/mochitest/test_bug393269.html
+++ b/js/xpconnect/tests/mochitest/test_bug393269.html
@@ -11,31 +11,31 @@ https://bugzilla.mozilla.org/show_bug.cg
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=393269">Mozilla Bug 393269</a>
 <iframe id="ifr"></iframe>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 (function () {
     /** Test for Bug 393269 **/
     var doc = $("ifr").contentDocument;
-    is("UTF-8", doc.characterSet, "control, getting a property");
+    is("utf-8", doc.characterSet, "control, getting a property");
     doc.open();
     try {
-        is("UTF-8", doc.characterSet,
+        is("utf-8", doc.characterSet,
            "can get a property after 1 document.open")
     } catch (e) {
         fail("Shouldn't have thrown: " + e);
         return;
     } finally {
         doc.close();
     }
 
     doc.open();
     try {
-        is("UTF-8", doc.characterSet,
+        is("utf-8", doc.characterSet,
            "can get a property after 2 document.opens")
     } catch (e) {
         fail("Shouldn't have thrown: " + e);
     } finally {
         doc.close();
     }
 })();
 </script>
--- a/parser/htmlparser/tests/mochitest/test_bug102699.html
+++ b/parser/htmlparser/tests/mochitest/test_bug102699.html
@@ -41,17 +41,17 @@ var d = p.parseFromString(
 '<noscript><div></div></noscript>"', "text/html");
 
 is(d.createElement("div").tagName, "DIV", "The created document should have HTML nature.");
 
 is(d.getElementsByTagName("div").length, 1, "There should be one div.");
 
 is(d.contentType, "text/html", "contentType should be text/html");
 
-is(d.characterSet, "UTF-8", "Expected the <meta> to be ignored.");
+is(d.characterSet, "utf-8", "Expected the <meta> to be ignored.");
 
 is(d.compatMode, "BackCompat", "Should be in the quirks mode.");
 
 var scripts = d.getElementsByTagName("script");
 is(scripts.length, 4, "Unexpected number of scripts.");
 while (scripts.length) {
   // These should not run when moved to another doc
   document.body.appendChild(scripts[0]);