Bug 795104 - Sources with a custom charset can't be lazily loaded. r=bz
authorBenjamin Peterson <benjamin@python.org>
Tue, 20 Nov 2012 11:30:03 -0600
changeset 113796 75821787b3439313b43547d8016b68e2e3f299ff
parent 113795 19c1fef93710c212064f8dc0ae1a96151561b4c5
child 113797 30e3ecf54ab207bf9c7bd313b9278ca2a288170c
push id23890
push userryanvm@gmail.com
push dateWed, 21 Nov 2012 02:43:32 +0000
treeherdermozilla-central@4f19e7fd8bea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs795104
milestone20.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 795104 - Sources with a custom charset can't be lazily loaded. r=bz
js/xpconnect/loader/mozJSSubScriptLoader.cpp
js/xpconnect/tests/chrome/Makefile.in
js/xpconnect/tests/chrome/test_chrometoSource.xul
js/xpconnect/tests/chrome/utf8_subscript.js
--- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -114,31 +114,33 @@ mozJSSubScriptLoader::ReadScript(nsIURI 
         return rv;
 
     /* set our own error reporter so we can report any bad things as catchable
      * exceptions, including the source/line number */
     er = JS_SetErrorReporter(cx, mozJSLoaderErrorReporter);
 
     JS::CompileOptions options(cx);
     options.setPrincipals(nsJSPrincipals::get(principal))
-           .setFileAndLine(uriStr, 1)
-           .setSourcePolicy(JS::CompileOptions::LAZY_SOURCE);
+           .setFileAndLine(uriStr, 1);
     js::RootedObject target_obj_root(cx, target_obj);
     if (!charset.IsVoid()) {
         nsString script;
         rv = nsScriptLoader::ConvertToUTF16(nullptr, reinterpret_cast<const uint8_t*>(buf.get()), len,
                                             charset, nullptr, script);
 
         if (NS_FAILED(rv)) {
             return ReportError(cx, LOAD_ERROR_BADCHARSET);
         }
 
         *scriptp = JS::Compile(cx, target_obj_root, options,
                                reinterpret_cast<const jschar*>(script.get()), script.Length());
     } else {
+        // We only use LAZY_SOURCE when no special encoding is specified because
+        // the lazy source loader doesn't know the encoding.
+        options.setSourcePolicy(JS::CompileOptions::LAZY_SOURCE);
         *scriptp = JS::Compile(cx, target_obj_root, options, buf.get(), len);
     }
 
     /* repent for our evil deeds */
     JS_SetErrorReporter(cx, er);
 
     return NS_OK;
 }
--- a/js/xpconnect/tests/chrome/Makefile.in
+++ b/js/xpconnect/tests/chrome/Makefile.in
@@ -45,16 +45,17 @@ MOCHITEST_CHROME_FILES = \
 		test_bug793433.xul \
 		test_bug795275.xul \
 		test_bug799348.xul \
 		test_bug801241.xul \
 		test_APIExposer.xul \
 		test_chrometoSource.xul \
 		outoflinexulscript.js \
 		subscript.js \
+		utf8_subscript.js \
 		test_cows.xul \
 		test_documentdomain.xul \
 		test_doublewrappedcompartments.xul \
 		test_evalInSandbox.xul \
 		file_evalInSandbox.html \
 		test_exnstack.xul \
 		test_expandosharing.xul \
 		file_expandosharing.jsm \
--- a/js/xpconnect/tests/chrome/test_chrometoSource.xul
+++ b/js/xpconnect/tests/chrome/test_chrometoSource.xul
@@ -37,14 +37,20 @@ isnot(src.indexOf("return"), -1, "JSM sh
 var ns = {};
 Services.scriptloader.loadSubScript("resource://gre/modules/NetUtil.jsm", ns);
 src = ns.NetUtil.asyncFetch.toSource();
 isnot(src.indexOf("return"), -1, "subscript should have source");
 
 var base = /.*\//.exec(window.location.href)[0];
 var reg = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIChromeRegistry);
 var resolvedBase = reg.convertChromeURL(NetUtil.newURI(base)).spec;
+
 ns = {};
 Services.scriptloader.loadSubScript(resolvedBase + "subscript.js", ns);
 src = ns.NetUtil.asyncFetch.toSource();
 isnot(src.indexOf("return"), -1, "subscript of a subscript should have source");
+
+ns = {};
+Services.scriptloader.loadSubScript(resolvedBase + "utf8_subscript.js", ns, "UTF-8");
+src = ns.f.toSource();
+isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source");
   ]]></script>
 </window>
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/chrome/utf8_subscript.js
@@ -0,0 +1,3 @@
+// -*- coding: utf-8 -*-
+var str = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢";
+function f() { return 42; }