Bug 1732923 - Part 1: Remove options parameter from JS::EncodeStencil. r=tcampbell
authorTooru Fujisawa <arai_a@mac.com>
Thu, 21 Oct 2021 00:14:21 +0000
changeset 596519 4ac758a5e4c32de0d900a74be358053671569300
parent 596518 3738556dd3402fa124af3b12825f2b2b2a828c4f
child 596520 485f2dbca6577f88403ceff979b6ffa2a8f72b9f
push id38900
push usernfay@mozilla.com
push dateThu, 21 Oct 2021 09:36:31 +0000
treeherdermozilla-central@f12b7ea34395 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1732923
milestone95.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 1732923 - Part 1: Remove options parameter from JS::EncodeStencil. r=tcampbell Depends on D120201 Differential Revision: https://phabricator.services.mozilla.com/D128342
dom/xul/nsXULElement.cpp
js/public/experimental/JSStencil.h
js/src/frontend/Stencil.cpp
js/src/jsapi-tests/testStencil.cpp
js/xpconnect/loader/ScriptPreloader.cpp
js/xpconnect/loader/mozJSComponentLoader.cpp
js/xpconnect/loader/mozJSLoaderUtils.cpp
js/xpconnect/loader/mozJSLoaderUtils.h
js/xpconnect/loader/mozJSSubScriptLoader.cpp
--- a/dom/xul/nsXULElement.cpp
+++ b/dom/xul/nsXULElement.cpp
@@ -1573,21 +1573,20 @@ nsXULPrototypeScript::nsXULPrototypeScri
     : nsXULPrototypeNode(eType_Script),
       mLineNo(aLineNo),
       mSrcLoading(false),
       mOutOfLine(true),
       mSrcLoadWaiters(nullptr),
       mStencil(nullptr) {}
 
 static nsresult WriteStencil(nsIObjectOutputStream* aStream, JSContext* aCx,
-                             const JS::ReadOnlyCompileOptions& aOptions,
                              JS::Stencil* aStencil) {
   JS::TranscodeBuffer buffer;
   JS::TranscodeResult code;
-  code = JS::EncodeStencil(aCx, aOptions, aStencil, buffer);
+  code = JS::EncodeStencil(aCx, aStencil, buffer);
 
   if (code != JS::TranscodeResult::Ok) {
     if (code == JS::TranscodeResult::Throw) {
       JS_ClearPendingException(aCx);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     MOZ_ASSERT(IsTranscodeFailureResult(code));
@@ -1684,20 +1683,17 @@ nsresult nsXULPrototypeScript::Serialize
   rv = aStream->Write32(mLineNo);
   if (NS_FAILED(rv)) return rv;
   rv = aStream->Write32(0);  // See bug 1418294.
   if (NS_FAILED(rv)) return rv;
 
   JSContext* cx = jsapi.cx();
   MOZ_ASSERT(xpc::CompilationScope() == JS::CurrentGlobalOrNull(cx));
 
-  JS::CompileOptions options(cx);
-  FillCompileOptions(options);
-
-  return WriteStencil(aStream, cx, options, mStencil);
+  return WriteStencil(aStream, cx, mStencil);
 }
 
 nsresult nsXULPrototypeScript::SerializeOutOfLine(
     nsIObjectOutputStream* aStream, nsXULPrototypeDocument* aProtoDoc) {
   if (!mSrcURI->SchemeIs("chrome"))
     // Don't cache scripts that don't come from chrome uris.
     return NS_ERROR_NOT_IMPLEMENTED;
 
--- a/js/public/experimental/JSStencil.h
+++ b/js/public/experimental/JSStencil.h
@@ -91,19 +91,19 @@ extern JS_PUBLIC_API bool StencilIsBorro
 extern JS_PUBLIC_API bool StencilCanLazilyParse(Stencil* stencil);
 
 // Instantiate a module Stencil and return the associated object. Inside the
 // engine this is a js::ModuleObject.
 extern JS_PUBLIC_API JSObject* InstantiateModuleStencil(
     JSContext* cx, const InstantiateOptions& options, Stencil* stencil);
 
 // Serialize the Stencil into the transcode buffer.
-extern JS_PUBLIC_API TranscodeResult
-EncodeStencil(JSContext* cx, const JS::ReadOnlyCompileOptions& options,
-              Stencil* stencil, TranscodeBuffer& buffer);
+extern JS_PUBLIC_API TranscodeResult EncodeStencil(JSContext* cx,
+                                                   Stencil* stencil,
+                                                   TranscodeBuffer& buffer);
 
 // Deserialize data and create a new Stencil.
 extern JS_PUBLIC_API TranscodeResult
 DecodeStencil(JSContext* cx, const ReadOnlyCompileOptions& options,
               const TranscodeRange& range, Stencil** stencilOut);
 
 extern JS_PUBLIC_API size_t SizeOfStencil(Stencil* stencil,
                                           mozilla::MallocSizeOf mallocSizeOf);
--- a/js/src/frontend/Stencil.cpp
+++ b/js/src/frontend/Stencil.cpp
@@ -4086,19 +4086,17 @@ JSObject* JS::InstantiateModuleStencil(J
   Rooted<CompilationGCOutput> gcOutput(cx);
   if (!InstantiateStencils(cx, input.get(), *stencil, gcOutput.get())) {
     return nullptr;
   }
 
   return gcOutput.get().module;
 }
 
-JS::TranscodeResult JS::EncodeStencil(JSContext* cx,
-                                      const JS::ReadOnlyCompileOptions& options,
-                                      JS::Stencil* stencil,
+JS::TranscodeResult JS::EncodeStencil(JSContext* cx, JS::Stencil* stencil,
                                       TranscodeBuffer& buffer) {
   XDRStencilEncoder encoder(cx, buffer);
   XDRResult res = encoder.codeStencil(*stencil);
   if (res.isErr()) {
     return res.unwrapErr();
   }
   return TranscodeResult::Ok;
 }
--- a/js/src/jsapi-tests/testStencil.cpp
+++ b/js/src/jsapi-tests/testStencil.cpp
@@ -208,17 +208,17 @@ BEGIN_TEST(testStencil_Transcode) {
     CHECK(srcBuf.init(cx, chars, strlen(chars), JS::SourceOwnership::Borrowed));
 
     JS::CompileOptions options(cx);
     RefPtr<JS::Stencil> stencil =
         JS::CompileGlobalScriptToStencil(cx, options, srcBuf);
     CHECK(stencil);
 
     // Encode Stencil to XDR
-    JS::TranscodeResult res = JS::EncodeStencil(cx, options, stencil, buffer);
+    JS::TranscodeResult res = JS::EncodeStencil(cx, stencil, buffer);
     CHECK(res == JS::TranscodeResult::Ok);
     CHECK(!buffer.empty());
 
     // Instantiate and Run
     JS::InstantiateOptions instantiateOptions(options);
     JS::RootedScript script(
         cx, JS::InstantiateGlobalStencil(cx, instantiateOptions, stencil));
     JS::RootedValue rval(cx);
@@ -286,17 +286,17 @@ BEGIN_TEST(testStencil_TranscodeBorrowin
     CHECK(srcBuf.init(cx, chars, strlen(chars), JS::SourceOwnership::Borrowed));
 
     JS::CompileOptions options(cx);
     RefPtr<JS::Stencil> stencil =
         JS::CompileGlobalScriptToStencil(cx, options, srcBuf);
     CHECK(stencil);
 
     // Encode Stencil to XDR
-    JS::TranscodeResult res = JS::EncodeStencil(cx, options, stencil, buffer);
+    JS::TranscodeResult res = JS::EncodeStencil(cx, stencil, buffer);
     CHECK(res == JS::TranscodeResult::Ok);
     CHECK(!buffer.empty());
   }
 
   JS::RootedScript script(cx);
   {
     JS::TranscodeRange range(buffer.begin(), buffer.length());
     JS::CompileOptions options(cx);
--- a/js/xpconnect/loader/ScriptPreloader.cpp
+++ b/js/xpconnect/loader/ScriptPreloader.cpp
@@ -1158,21 +1158,17 @@ ScriptPreloader::CachedStencil::CachedSt
   mProcessTypes = {};
 }
 
 bool ScriptPreloader::CachedStencil::XDREncode(JSContext* cx) {
   auto cleanup = MakeScopeExit([&]() { MaybeDropStencil(); });
 
   mXDRData.construct<JS::TranscodeBuffer>();
 
-  JS::CompileOptions compileOptions(cx);
-  FillCompileOptionsForCachedStencil(compileOptions);
-
-  JS::TranscodeResult code =
-      JS::EncodeStencil(cx, compileOptions, mStencil, Buffer());
+  JS::TranscodeResult code = JS::EncodeStencil(cx, mStencil, Buffer());
   if (code == JS::TranscodeResult::Ok) {
     mXDRRange.emplace(Buffer().begin(), Buffer().length());
     mSize = Range().length();
     return true;
   }
   mXDRData.destroy();
   JS_ClearPendingException(cx);
   return false;
--- a/js/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/xpconnect/loader/mozJSComponentLoader.cpp
@@ -840,17 +840,17 @@ nsresult mozJSComponentLoader::ObjectFor
 
   // Write to startup cache only when we didn't have any cache for the script
   // and compiled it.
   if (storeIntoStartupCache) {
     MOZ_ASSERT(options.sourceIsLazy);
     MOZ_ASSERT(stencil);
 
     // We successfully compiled the script, so cache it.
-    rv = WriteCachedStencil(cache, cachePath, cx, options, stencil);
+    rv = WriteCachedStencil(cache, cachePath, cx, stencil);
 
     // Don't treat failure to write as fatal, since we might be working
     // with a read-only cache.
     if (NS_SUCCEEDED(rv)) {
       LOG(("Successfully wrote to cache\n"));
     } else {
       LOG(("Failed to write to cache\n"));
     }
--- a/js/xpconnect/loader/mozJSLoaderUtils.cpp
+++ b/js/xpconnect/loader/mozJSLoaderUtils.cpp
@@ -44,20 +44,19 @@ nsresult ReadCachedStencil(StartupCache*
   }
 
   JS::TranscodeRange range(AsBytes(Span(buf, len)));
   JS::TranscodeResult code = JS::DecodeStencil(cx, options, range, stencilOut);
   return HandleTranscodeResult(cx, code);
 }
 
 nsresult WriteCachedStencil(StartupCache* cache, nsACString& uri, JSContext* cx,
-                            const JS::ReadOnlyCompileOptions& options,
                             JS::Stencil* stencil) {
   JS::TranscodeBuffer buffer;
-  JS::TranscodeResult code = JS::EncodeStencil(cx, options, stencil, buffer);
+  JS::TranscodeResult code = JS::EncodeStencil(cx, stencil, buffer);
   if (code != JS::TranscodeResult::Ok) {
     return HandleTranscodeResult(cx, code);
   }
 
   size_t size = buffer.length();
   if (size > UINT32_MAX) {
     return NS_ERROR_FAILURE;
   }
--- a/js/xpconnect/loader/mozJSLoaderUtils.h
+++ b/js/xpconnect/loader/mozJSLoaderUtils.h
@@ -20,12 +20,11 @@ class StartupCache;
 
 nsresult ReadCachedStencil(mozilla::scache::StartupCache* cache,
                            nsACString& uri, JSContext* cx,
                            const JS::ReadOnlyCompileOptions& options,
                            JS::Stencil** stencilOut);
 
 nsresult WriteCachedStencil(mozilla::scache::StartupCache* cache,
                             nsACString& uri, JSContext* cx,
-                            const JS::ReadOnlyCompileOptions& options,
                             JS::Stencil* stencil);
 
 #endif /* mozJSLoaderUtils_h */
--- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -193,18 +193,17 @@ static bool EvalStencil(JSContext* cx, H
 
     nsCString uriStr;
     if (storeIntoPreloadCache && NS_SUCCEEDED(uri->GetSpec(uriStr))) {
       ScriptPreloader::GetSingleton().NoteStencil(uriStr, cachePath, stencil);
     }
 
     if (storeIntoStartupCache) {
       JSAutoRealm ar(cx, script);
-      WriteCachedStencil(StartupCache::GetSingleton(), cachePath, cx, options,
-                         stencil);
+      WriteCachedStencil(StartupCache::GetSingleton(), cachePath, cx, stencil);
     }
   }
 
   return true;
 }
 
 bool mozJSSubScriptLoader::ReadStencil(
     JS::Stencil** stencilOut, nsIURI* uri, JSContext* cx,