Bug 1525924 - Part 2: Factor out WithScope::XDR r=jandem
authorTed Campbell <tcampbell@mozilla.com>
Mon, 11 Feb 2019 14:54:32 +0000
changeset 458510 582ab25b0a61b628050813edc1b1eb7f7ddc58a1
parent 458509 34b6c82e60ce095721ac81a523aca36ccba59fa5
child 458511 496594078fd3b0c8c300913b43eb5421b0b4d6d0
push id35536
push userbtara@mozilla.com
push dateMon, 11 Feb 2019 21:54:04 +0000
treeherdermozilla-central@6d8e6f960446 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1525924
milestone67.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 1525924 - Part 2: Factor out WithScope::XDR r=jandem Differential Revision: https://phabricator.services.mozilla.com/D19006
js/src/vm/JSScript.cpp
js/src/vm/Scope.cpp
js/src/vm/Scope.h
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -719,22 +719,17 @@ XDRResult js::XDRScript(XDRState<mode>* 
         case ScopeKind::Lexical:
         case ScopeKind::SimpleCatch:
         case ScopeKind::Catch:
         case ScopeKind::NamedLambda:
         case ScopeKind::StrictNamedLambda:
           MOZ_TRY(LexicalScope::XDR(xdr, scopeKind, enclosing, &scope));
           break;
         case ScopeKind::With:
-          if (mode == XDR_DECODE) {
-            scope = WithScope::create(cx, enclosing);
-            if (!scope) {
-              return xdr->fail(JS::TranscodeResult_Throw);
-            }
-          }
+          MOZ_TRY(WithScope::XDR(xdr, enclosing, &scope));
           break;
         case ScopeKind::Eval:
         case ScopeKind::StrictEval:
           MOZ_TRY(EvalScope::XDR(xdr, scopeKind, enclosing, &scope));
           break;
         case ScopeKind::Global:
         case ScopeKind::NonSyntactic:
           MOZ_TRY(GlobalScope::XDR(xdr, scopeKind, &scope));
--- a/js/src/vm/Scope.cpp
+++ b/js/src/vm/Scope.cpp
@@ -1015,16 +1015,42 @@ template
                      MutableHandleScope scope);
 
 /* static */ WithScope* WithScope::create(JSContext* cx,
                                           HandleScope enclosing) {
   Scope* scope = Scope::create(cx, ScopeKind::With, enclosing, nullptr);
   return static_cast<WithScope*>(scope);
 }
 
+template <XDRMode mode>
+/* static */ XDRResult WithScope::XDR(XDRState<mode>* xdr,
+                                      HandleScope enclosing,
+                                      MutableHandleScope scope) {
+  JSContext* cx = xdr->cx();
+
+  if (mode == XDR_DECODE) {
+    scope.set(create(cx, enclosing));
+    if (!scope) {
+      return xdr->fail(JS::TranscodeResult_Throw);
+    }
+  }
+
+  return Ok();
+}
+
+template
+    /* static */ XDRResult
+    WithScope::XDR(XDRState<XDR_ENCODE>* xdr, HandleScope enclosing,
+                   MutableHandleScope scope);
+
+template
+    /* static */ XDRResult
+    WithScope::XDR(XDRState<XDR_DECODE>* xdr, HandleScope enclosing,
+                   MutableHandleScope scope);
+
 static const uint32_t EvalScopeEnvShapeFlags =
     BaseShape::QUALIFIED_VAROBJ | BaseShape::DELEGATE;
 
 /* static */ EvalScope* EvalScope::create(JSContext* cx, ScopeKind scopeKind,
                                           Handle<Data*> dataArg,
                                           HandleScope enclosing) {
   // The data that's passed in is from the frontend and is LifoAlloc'd.
   // Copy it now that we're creating a permanent VM scope.
--- a/js/src/vm/Scope.h
+++ b/js/src/vm/Scope.h
@@ -768,16 +768,20 @@ inline bool Scope::is<GlobalScope>() con
 //
 // Corresponds to a WithEnvironmentObject on the environment chain.
 class WithScope : public Scope {
   friend class Scope;
   static const ScopeKind classScopeKind_ = ScopeKind::With;
 
  public:
   static WithScope* create(JSContext* cx, HandleScope enclosing);
+
+  template <XDRMode mode>
+  static XDRResult XDR(XDRState<mode>* xdr, HandleScope enclosing,
+                       MutableHandleScope scope);
 };
 
 //
 // Scope of an eval. Holds var bindings. There are 2 kinds of EvalScopes.
 //
 // StrictEval
 //   A strict eval. Corresponds to a VarEnvironmentObject, where its var
 //   bindings lives.