Bug 1492937 - Make mozIJSSubScriptLoader.loadSubScriptWithOptions interpret script data only as UTF-8, without any way to use another charset. r=kmag
authorJeff Walden <jwalden@mit.edu>
Sat, 08 Dec 2018 18:14:27 -0500
changeset 450187 31eb07ce57ae7a1bc56282fd6a46dfdcffcdae01
parent 450186 4a369344f15d93cb6750ad882fac7a1919714ce1
child 450188 4933066fd34964dab0f7bb04614a8d6baa9d3136
push id35191
push userccoroiu@mozilla.com
push dateWed, 12 Dec 2018 05:12:41 +0000
treeherdermozilla-central@e27e7c02c708 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1492937
milestone66.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 1492937 - Make mozIJSSubScriptLoader.loadSubScriptWithOptions interpret script data only as UTF-8, without any way to use another charset. r=kmag
js/xpconnect/idl/mozIJSSubScriptLoader.idl
js/xpconnect/loader/mozJSSubScriptLoader.cpp
js/xpconnect/tests/chrome/test_chrometoSource.xul
--- a/js/xpconnect/idl/mozIJSSubScriptLoader.idl
+++ b/js/xpconnect/idl/mozIJSSubScriptLoader.idl
@@ -28,20 +28,19 @@ interface mozIJSSubScriptLoader : nsISup
      */
     [implicit_jscontext]
     jsval loadSubScript(in AString url, [optional] in jsval obj, [optional] in AString charset);
 
     /**
      * This method should only be called from JS!
      * In JS, the signature looks like:
      * rv = loadSubScript (url, optionsObject)
-     * @param url the url of the sub-script, it MUST be either a file:,
-     *            resource:, blob:, or chrome: url, and MUST be local.
+     * @param url the url of the UTF-8-encoded sub-script, which MUST be either
+     *            a file:, resource:, blob:, or chrome: url, and MUST be local.
      * @param optionsObject an object with parameters. Valid parameters are:
-     *                      - charset: specifying the character encoding of the file (default: ASCII)
      *                      - target:  an object to evaluate onto (default: global object of the caller)
      *                      - ignoreCache: if set to true, will bypass the cache for reading the file.
      *                      - async: if set to true, the script will be loaded
      *                        asynchronously, and a Promise is returned which
      *                        resolves to its result when execution is complete.
      *                      - wantReturnValue: If true, the script will return
      *                        the value of the last statement that it evaluated.
      *                        This option disables most optimizations in the
--- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -51,17 +51,17 @@ class MOZ_STACK_CLASS LoadSubScriptOptio
       : OptionsBase(cx, options),
         target(cx),
         charset(VoidString()),
         ignoreCache(false),
         async(false),
         wantReturnValue(false) {}
 
   virtual bool Parse() override {
-    return ParseObject("target", &target) && ParseString("charset", charset) &&
+    return ParseObject("target", &target) &&
            ParseBoolean("ignoreCache", &ignoreCache) &&
            ParseBoolean("async", &async) &&
            ParseBoolean("wantReturnValue", &wantReturnValue);
   }
 
   RootedObject target;
   nsString charset;
   bool ignoreCache;
@@ -552,16 +552,18 @@ mozJSSubScriptLoader::LoadSubScriptWithO
                                                MutableHandleValue retval) {
   if (!optionsVal.isObject()) {
     return NS_ERROR_INVALID_ARG;
   }
   LoadSubScriptOptions options(cx, &optionsVal.toObject());
   if (!options.Parse()) {
     return NS_ERROR_INVALID_ARG;
   }
+
+  options.charset.AssignLiteral("UTF-8");
   return DoLoadSubScriptWithOptions(url, options, cx, retval);
 }
 
 nsresult mozJSSubScriptLoader::DoLoadSubScriptWithOptions(
     const nsAString& url, LoadSubScriptOptions& options, JSContext* cx,
     MutableHandleValue retval) {
   nsresult rv = NS_OK;
   RootedObject targetObj(cx);
--- a/js/xpconnect/tests/chrome/test_chrometoSource.xul
+++ b/js/xpconnect/tests/chrome/test_chrometoSource.xul
@@ -47,17 +47,17 @@ isnot(src.indexOf("return"), -1, "subscr
 
 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");
 
 ns = {};
 Services.scriptloader.loadSubScriptWithOptions(resolvedBase + "utf8_subscript.js",
-                                               {target: ns, charset: "UTF-8", ignoreCache: true});
+                                               {target: ns, ignoreCache: true});
 src = ns.f.toSource();
 isnot(src.indexOf("return 42;"), -1, "encoded subscript should have correct source");
 
 ns = {};
 let b = new Blob([
   "var Exported = 17;"
 ]);
 var blobUrl = URL.createObjectURL(b);