WIP: Moving BINJS:Scope to its own field draft
authorDavid Teller <dteller@mozilla.com>
Mon, 24 Jul 2017 17:30:04 +0200
changeset 641330 8ad72c5790321039eccc4955d0ee0b576abab8d6
parent 641329 441913de1c0d4ba019721a88ffea31902e864441
child 641331 4dd2ecb8c3b33519ed48f02ae3fab9dee8deb298
push id72504
push userdteller@mozilla.com
push dateSun, 06 Aug 2017 22:28:40 +0000
milestone57.0a1
WIP: Moving BINJS:Scope to its own field MozReview-Commit-ID: 6eBBavyGamh
js/src/frontend/BinSource.cpp
--- a/js/src/frontend/BinSource.cpp
+++ b/js/src/frontend/BinSource.cpp
@@ -32,29 +32,41 @@ NewEmptyBindingData(JSContext* cx, LifoA
     }
     PodZero(bindings);
     return bindings;
 }
 
 struct ScopeData MOZ_STACK_CLASS {
 public:
     ScopeData(JSContext* cx)
-      : letNames(cx, Names(cx))
-      , constNames(cx, Names(cx))
-      , varNames(cx, Names(cx))
-      , capturedNames(cx, NameBag(cx))
+      : letNames(cx)
+      , constNames(cx)
+      , varNames(cx)
+      , capturedNames(cx)
     { }
     bool isSome() const {
-        return hasDirectEval.isSome();
+        if (hasDirectEval.isSome()) {
+            MOZ_ASSERT(letNames.isSome());
+            MOZ_ASSERT(constNames.isSome());
+            MOZ_ASSERT(varNames.isSome());
+            MOZ_ASSERT(capturedNames.isSome());
+            return true;
+        } else {
+            MOZ_ASSERT(!letNames.isSome());
+            MOZ_ASSERT(!constNames.isSome());
+            MOZ_ASSERT(!varNames.isSome());
+            MOZ_ASSERT(!capturedNames.isSome());
+            return false;
+        }
     }
     Maybe<bool> hasDirectEval;
-    Rooted<Names> letNames;
-    Rooted<Names> constNames;
-    Rooted<Names> varNames;
-    Rooted<NameBag> capturedNames;
+    Rooted<Maybe<Names>> letNames;
+    Rooted<Maybe<Names>> constNames;
+    Rooted<Maybe<Names>> varNames;
+    Rooted<Maybe<NameBag>> capturedNames;
 };
 
 const std::string BINJS_SCOPE = "BINJS:Scope";
 const std::string BINJS_VAR_NAME = "BINJS:VarDeclaredNames";
 const std::string BINJS_LET_NAME = "BINJS:LetDeclaredNames";
 const std::string BINJS_CONST_NAME = "BINJS:ConstDeclaredNames";
 const std::string BINJS_CAPTURED_NAME = "BINJS:CapturedNames";
 const std::string BINJS_DIRECT_EVAL = "BINJS:HasDirectEval";
@@ -245,40 +257,40 @@ ASTReader::parseBlockStatementAux(Simple
     if (!body || !scope.isSome()) {
         // FIXME: Once we have headers + header validation, this error check
         // should become an assertion.
         return this->raiseError();
     }
 
     // Probably not a good idea.
     UniquePtr<LexicalScope::Data> bindings(
-        NewEmptyBindingData<LexicalScope>(this->cx, this->alloc, scope.letNames.length() + scope.constNames.length())
+        NewEmptyBindingData<LexicalScope>(this->cx, this->alloc, scope.letNames->length() + scope.constNames->length())
     );
     if (!bindings) {
         return this->raiseError();
     }
 
     BindingName* cursor = bindings->names;
-    for (auto& name: scope.letNames) {
+    for (auto& name: *scope.letNames.get()) {
         JS::Rooted<JSAtom*> atom(cx, AtomizeString(this->cx, name));
-        bool isCaptured = scope.capturedNames.has(name);
+        bool isCaptured = scope.capturedNames->has(name);
         BindingName binding(atom, isCaptured);
         PodCopy(cursor, &binding, 1); // FIXME: Why does this work?
         cursor++;
         bindings->length++;
     }
-    for (auto& name: scope.constNames) {
+    for (auto& name: *scope.constNames.get()) {
         JS::Rooted<JSAtom*> atom(cx, AtomizeString(this->cx, name));
-        bool isCaptured = scope.capturedNames.has(name);
+        bool isCaptured = scope.capturedNames->has(name);
         BindingName binding(atom, isCaptured);
         PodCopy(cursor, &binding, 1); // FIXME: Why does this work?
         cursor++;
         bindings->length++;
     }
-    bindings->constStart = scope.letNames.length();
+    bindings->constStart = scope.letNames->length();
 
     UniquePtr<ParseNode> result(new_<LexicalScopeNode>(bindings.release(), body.release()));
     out = Move(result);
     // FIXME: Validate capturedNames, etc.
     return true;
 }
 
 bool