Bug 1515801 - Make subscripts have lazy source, and change the source-hook to hint UTF-8 rather than offer no charset hint so that lazy-source for them will work correctly. r=kmag
authorJeff Walden <jwalden@mit.edu>
Wed, 26 Dec 2018 14:37:42 -0600
changeset 509048 894e36ecd784
parent 509047 6686393af7c7
child 509066 eaa7b9f96c8e
child 509096 e2ba0eeb80c7
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1515801
milestone66.0a1
first release with
nightly linux32
894e36ecd784 / 66.0a1 / 20181227092648 / files
nightly linux64
894e36ecd784 / 66.0a1 / 20181227092648 / files
nightly mac
894e36ecd784 / 66.0a1 / 20181227092648 / files
nightly win32
894e36ecd784 / 66.0a1 / 20181227092648 / files
nightly win64
894e36ecd784 / 66.0a1 / 20181227092648 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1515801 - Make subscripts have lazy source, and change the source-hook to hint UTF-8 rather than offer no charset hint so that lazy-source for them will work correctly. r=kmag
js/xpconnect/loader/mozJSSubScriptLoader.cpp
js/xpconnect/src/XPCJSRuntime.cpp
--- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -127,16 +127,26 @@ static void ReportError(JSContext* cx, c
 }
 
 static bool PrepareScript(nsIURI* uri, JSContext* cx, bool wantGlobalScript,
                           const char* uriStr, const char* buf, int64_t len,
                           bool wantReturnValue, MutableHandleScript script) {
   JS::CompileOptions options(cx);
   options.setFileAndLine(uriStr, 1).setNoScriptRval(!wantReturnValue);
 
+  // This presumes that no one else might be compiling a script for this
+  // (URL, syntactic-or-not) key *not* using UTF-8.  Seeing as JS source can
+  // only be compiled as UTF-8 or UTF-16 now -- there isn't a JSAPI function to
+  // compile Latin-1 now -- this presumption seems relatively safe.
+  //
+  // This also presumes that lazy parsing is disabled, for the sake of the
+  // startup cache.  If lazy parsing is ever enabled for pertinent scripts that
+  // pass through here, we may need to disable lazy source for them.
+  options.setSourceIsLazy(true);
+
   if (wantGlobalScript) {
     return JS::CompileUtf8(cx, options, buf, len, script);
   }
   return JS::CompileUtf8ForNonSyntacticScope(cx, options, buf, len, script);
 }
 
 static bool EvalScript(JSContext* cx, HandleObject targetObj,
                        HandleObject loadScope, MutableHandleValue retval,
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -2847,17 +2847,17 @@ static nsresult ReadSourceFromFilename(J
     if (NS_FAILED(rv)) {
       return rv;
     }
     MOZ_ASSERT(bytesRead > 0, "stream promised more bytes before EOF");
     ptr += bytesRead;
   }
 
   rv = ScriptLoader::ConvertToUTF16(scriptChannel, buf.get(), rawLen,
-                                    EmptyString(), nullptr, *src, *len);
+                                    NS_LITERAL_STRING("UTF-8"), nullptr, *src, *len);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!*src) {
     return NS_ERROR_FAILURE;
   }
 
   // Historically this method used JS_malloc() which updates the GC memory
   // accounting.  Since ConvertToUTF16() now uses js_malloc() instead we