Bug 1544882 - Move XDR of ScriptSource::data and a couple related values into its own standalone function, for simplicity/to reduce complexity when SS::data is XDR'd using variant-matching code. r=arai
authorJeff Walden <jwalden@mit.edu>
Tue, 16 Apr 2019 15:27:44 -0700
changeset 530446 641a364dcb54ae09689e73d7b8e1d30f12fa7705
parent 530445 a1d55f09d0239319f35ab3bfcf29d69d5d7fd7f5
child 530447 808585ce159839b9b1babe1f90be0120c79298ca
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1544882
milestone68.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 1544882 - Move XDR of ScriptSource::data and a couple related values into its own standalone function, for simplicity/to reduce complexity when SS::data is XDR'd using variant-matching code. r=arai Differential Revision: https://phabricator.services.mozilla.com/D28923
js/src/vm/JSScript.cpp
js/src/vm/JSScript.h
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -2587,41 +2587,17 @@ XDRResult ScriptSource::xdrUncompressedS
   SourceEncoder<char16_t> encoder(xdr, this, uncompressedLength);
   return encoder.encode();
 }
 
 }  // namespace js
 
 template <XDRMode mode>
 /* static */
-XDRResult ScriptSource::XDR(XDRState<mode>* xdr,
-                            const mozilla::Maybe<JS::CompileOptions>& options,
-                            MutableHandle<ScriptSourceHolder> holder) {
-  JSContext* cx = xdr->cx();
-  ScriptSource* ss = nullptr;
-
-  if (mode == XDR_ENCODE) {
-    ss = holder.get().get();
-  } else {
-    // Allocate a new ScriptSource and root it with the holder.
-    ss = cx->new_<ScriptSource>();
-    if (!ss) {
-      return xdr->fail(JS::TranscodeResult_Throw);
-    }
-    holder.get().reset(ss);
-
-    // We use this CompileOptions only to initialize the ScriptSourceObject.
-    // Most CompileOptions fields aren't used by ScriptSourceObject, and those
-    // that are (element; elementAttributeName) aren't preserved by XDR. So
-    // this can be simple.
-    if (!ss->initFromOptions(cx, *options)) {
-      return xdr->fail(JS::TranscodeResult_Throw);
-    }
-  }
-
+XDRResult ScriptSource::xdrDataMember(XDRState<mode>* xdr, ScriptSource* ss) {
   uint8_t hasSource = ss->hasSourceText();
   MOZ_TRY(xdr->codeUint8(&hasSource));
 
   uint8_t hasBinSource = ss->hasBinASTSource();
   MOZ_TRY(xdr->codeUint8(&hasBinSource));
 
   uint8_t retrievable = ss->sourceRetrievable_;
   MOZ_TRY(xdr->codeUint8(&retrievable));
@@ -2780,16 +2756,48 @@ XDRResult ScriptSource::XDR(XDRState<mod
 #else
       // No BinAST, no BinASTMetadata
       MOZ_ASSERT(mode != XDR_ENCODE);
       return xdr->fail(JS::TranscodeResult_Throw);
 #endif  // JS_BUILD_BINAST
     }
   }
 
+  return Ok();
+}
+
+template <XDRMode mode>
+/* static */
+XDRResult ScriptSource::XDR(XDRState<mode>* xdr,
+                            const mozilla::Maybe<JS::CompileOptions>& options,
+                            MutableHandle<ScriptSourceHolder> holder) {
+  JSContext* cx = xdr->cx();
+  ScriptSource* ss = nullptr;
+
+  if (mode == XDR_ENCODE) {
+    ss = holder.get().get();
+  } else {
+    // Allocate a new ScriptSource and root it with the holder.
+    ss = cx->new_<ScriptSource>();
+    if (!ss) {
+      return xdr->fail(JS::TranscodeResult_Throw);
+    }
+    holder.get().reset(ss);
+
+    // We use this CompileOptions only to initialize the ScriptSourceObject.
+    // Most CompileOptions fields aren't used by ScriptSourceObject, and those
+    // that are (element; elementAttributeName) aren't preserved by XDR. So
+    // this can be simple.
+    if (!ss->initFromOptions(cx, *options)) {
+      return xdr->fail(JS::TranscodeResult_Throw);
+    }
+  }
+
+  MOZ_TRY(xdrDataMember(xdr, ss));
+
   uint8_t haveSourceMap = ss->hasSourceMapURL();
   MOZ_TRY(xdr->codeUint8(&haveSourceMap));
 
   if (haveSourceMap) {
     UniqueTwoByteChars& sourceMapURL(ss->sourceMapURL_);
     uint32_t sourceMapURLLen =
         (mode == XDR_DECODE) ? 0 : js_strlen(sourceMapURL.get());
     MOZ_TRY(xdr->codeUint32(&sourceMapURLLen));
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -1144,16 +1144,22 @@ class ScriptSource {
 
   const mozilla::TimeStamp parseEnded() const { return parseEnded_; }
   // Inform `this` source that it has been fully parsed.
   void recordParseEnded() {
     MOZ_ASSERT(parseEnded_.IsNull());
     parseEnded_ = ReallyNow();
   }
 
+ private:
+  template <XDRMode mode>
+  static MOZ_MUST_USE XDRResult xdrDataMember(XDRState<mode>* xdr,
+                                              ScriptSource* ss);
+
+ public:
   template <XDRMode mode>
   static MOZ_MUST_USE XDRResult
   XDR(XDRState<mode>* xdr, const mozilla::Maybe<JS::CompileOptions>& options,
       MutableHandle<ScriptSourceHolder> ss);
 
   void trace(JSTracer* trc);
 };