Bug 1615728 - Create SourceExtent struct for JSScript r=djvj
authorMatthew Gaudet <mgaudet@mozilla.com>
Wed, 19 Feb 2020 23:02:35 +0000
changeset 514673 430371b4b906010e5f2e142f280f105f8230612c
parent 514672 475d4bba396c0a163910d22c90c557e3cf9b97ec
child 514674 1130f972ab5cabf0e1908506b78c89c6e06dd8df
push id37140
push usermalexandru@mozilla.com
push dateThu, 20 Feb 2020 09:35:08 +0000
treeherdermozilla-central@b532be9d2719 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdjvj
bugs1615728
milestone75.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 1615728 - Create SourceExtent struct for JSScript r=djvj Differential Revision: https://phabricator.services.mozilla.com/D63270
js/src/vm/JSScript.cpp
js/src/vm/JSScript.h
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -1393,22 +1393,22 @@ template XDRResult js::XDRLazyScript(XDR
                                      MutableHandle<LazyScript*>);
 
 void JSScript::setDefaultClassConstructorSpan(
     js::ScriptSourceObject* sourceObject, uint32_t start, uint32_t end,
     unsigned line, unsigned column) {
   MOZ_ASSERT(compartment() == sourceObject->compartment());
   MOZ_ASSERT(isDefaultClassConstructor());
   sourceObject_ = sourceObject;
-  toStringStart_ = start;
-  toStringEnd_ = end;
-  sourceStart_ = start;
-  sourceEnd_ = end;
-  lineno_ = line;
-  column_ = column;
+  extent_.toStringStart = start;
+  extent_.toStringEnd = end;
+  extent_.sourceStart = start;
+  extent_.sourceEnd = end;
+  extent_.lineno = line;
+  extent_.column = column;
   // Since this script has been changed to point into the user's source, we
   // can clear its self-hosted flag, allowing Debugger to see it.
   clearFlag(ImmutableFlags::SelfHosted);
 }
 
 bool JSScript::initScriptCounts(JSContext* cx) {
   MOZ_ASSERT(!hasScriptCounts());
 
@@ -4464,18 +4464,18 @@ bool JSScript::fullyInitFromStencil(JSCo
   // to neuter the script. Various things that iterate raw scripts in a GC arena
   // use the presense of this data to detect if initialization is complete.
   auto scriptDataGuard =
       mozilla::MakeScopeExit([&] { script->freeSharedData(); });
 
   /* The counts of indexed things must be checked during code generation. */
   MOZ_ASSERT(stencil.natoms <= INDEX_LIMIT);
   MOZ_ASSERT(stencil.ngcthings <= INDEX_LIMIT);
-  MOZ_ASSERT(script->lineno_ == stencil.lineno);
-  MOZ_ASSERT(script->column_ == stencil.column);
+  MOZ_ASSERT(script->extent_.lineno == stencil.lineno);
+  MOZ_ASSERT(script->extent_.column == stencil.column);
 
   // Initialize script flags from BytecodeEmitter
   script->setFlag(ImmutableFlags::Strict, stencil.strict);
   script->setFlag(ImmutableFlags::BindingsAccessedDynamically,
                   stencil.bindingsAccessedDynamically);
   script->setFlag(ImmutableFlags::HasCallSiteObj, stencil.hasCallSiteObj);
   script->setFlag(ImmutableFlags::IsForEval, stencil.isForEval);
   script->setFlag(ImmutableFlags::IsModule, stencil.isModule);
--- a/js/src/vm/JSScript.h
+++ b/js/src/vm/JSScript.h
@@ -1999,24 +1999,26 @@ class BaseScript : public gc::TenuredCel
   //   class C { constructor() { this.field = 42; } }
   //   ^         ^                                 ^ ^
   //   |         |                                 | `---------`
   //   |         sourceStart_                      sourceEnd_  |
   //   |                                                       |
   //   toStringStart_                                          toStringEnd_
   //
   // NOTE: These are counted in Code Units from the start of the script source.
-  uint32_t sourceStart_ = 0;
-  uint32_t sourceEnd_ = 0;
-  uint32_t toStringStart_ = 0;
-  uint32_t toStringEnd_ = 0;
-
-  // Line and column of |sourceStart_| position.
-  uint32_t lineno_ = 0;
-  uint32_t column_ = 0;  // Count of Code Points
+  struct SourceExtent {
+    uint32_t sourceStart = 0;
+    uint32_t sourceEnd = 0;
+    uint32_t toStringStart = 0;
+    uint32_t toStringEnd = 0;
+
+    // Line and column of |sourceStart_| position.
+    uint32_t lineno = 0;
+    uint32_t column = 0;  // Count of Code Points
+  } extent_;
 
   // See ImmutableFlags / MutableFlags below for definitions. These are stored
   // as uint32_t instead of bitfields to make it more predictable to access
   // from JIT code.
   uint32_t immutableFlags_ = 0;
   uint32_t mutableFlags_ = 0;
 
   ScriptWarmUpData warmUpData_ = {};
@@ -2042,22 +2044,18 @@ class BaseScript : public gc::TenuredCel
 
   BaseScript(uint8_t* stubEntry, JSObject* functionOrGlobal,
              ScriptSourceObject* sourceObject, uint32_t sourceStart,
              uint32_t sourceEnd, uint32_t toStringStart, uint32_t toStringEnd,
              uint32_t lineno, uint32_t column)
       : jitCodeRaw_(stubEntry),
         functionOrGlobal_(functionOrGlobal),
         sourceObject_(sourceObject),
-        sourceStart_(sourceStart),
-        sourceEnd_(sourceEnd),
-        toStringStart_(toStringStart),
-        toStringEnd_(toStringEnd),
-        lineno_(lineno),
-        column_(column) {
+        extent_{sourceStart, sourceEnd, toStringStart,
+                toStringEnd, lineno,    column} {
     MOZ_ASSERT(functionOrGlobal->compartment() == sourceObject->compartment());
     MOZ_ASSERT(toStringStart <= sourceStart);
     MOZ_ASSERT(sourceStart <= sourceEnd);
     MOZ_ASSERT(sourceEnd <= toStringEnd);
   }
 
  public:
   // Immutable flags should not be modified after this script has been
@@ -2260,21 +2258,23 @@ class BaseScript : public gc::TenuredCel
 
   const char* filename() const { return scriptSource()->filename(); }
   const char* maybeForwardedFilename() const {
     return maybeForwardedScriptSource()->filename();
   }
 
   bool isBinAST() const { return scriptSource()->hasBinASTSource(); }
 
-  uint32_t sourceStart() const { return sourceStart_; }
-  uint32_t sourceEnd() const { return sourceEnd_; }
-  uint32_t sourceLength() const { return sourceEnd_ - sourceStart_; }
-  uint32_t toStringStart() const { return toStringStart_; }
-  uint32_t toStringEnd() const { return toStringEnd_; }
+  uint32_t sourceStart() const { return extent_.sourceStart; }
+  uint32_t sourceEnd() const { return extent_.sourceEnd; }
+  uint32_t sourceLength() const {
+    return extent_.sourceEnd - extent_.sourceStart;
+  }
+  uint32_t toStringStart() const { return extent_.toStringStart; }
+  uint32_t toStringEnd() const { return extent_.toStringEnd; }
 
   MOZ_MUST_USE bool appendSourceDataForToString(JSContext* cx,
                                                 js::StringBuffer& buf);
 
 #if defined(JS_BUILD_BINAST)
   // Set the position of the function in the source code.
   //
   // BinAST file format can put lazy functions after the entire tree,
@@ -2283,33 +2283,33 @@ class BaseScript : public gc::TenuredCel
   // function part, this function is called to set those positions to
   // correct value.
   void setPositions(uint32_t sourceStart, uint32_t sourceEnd,
                     uint32_t toStringStart, uint32_t toStringEnd) {
     MOZ_ASSERT(toStringStart <= sourceStart);
     MOZ_ASSERT(sourceStart <= sourceEnd);
     MOZ_ASSERT(sourceEnd <= toStringEnd);
 
-    sourceStart_ = sourceStart;
-    sourceEnd_ = sourceEnd;
-    toStringStart_ = toStringStart;
-    toStringEnd_ = toStringEnd;
+    extent_.sourceStart = sourceStart;
+    extent_.sourceEnd = sourceEnd;
+    extent_.toStringStart = toStringStart;
+    extent_.toStringEnd = toStringEnd;
   }
 
-  void setColumn(uint32_t column) { column_ = column; }
+  void setColumn(uint32_t column) { extent_.column = column; }
 #endif
 
   void setToStringEnd(uint32_t toStringEnd) {
-    MOZ_ASSERT(toStringStart_ <= toStringEnd);
-    MOZ_ASSERT(toStringEnd_ >= sourceEnd_);
-    toStringEnd_ = toStringEnd;
+    MOZ_ASSERT(extent_.toStringStart <= toStringEnd);
+    MOZ_ASSERT(extent_.toStringEnd >= extent_.sourceEnd);
+    extent_.toStringEnd = toStringEnd;
   }
 
-  uint32_t lineno() const { return lineno_; }
-  uint32_t column() const { return column_; }
+  uint32_t lineno() const { return extent_.lineno; }
+  uint32_t column() const { return extent_.column; }
 
   // ImmutableFlags accessors.
   MOZ_MUST_USE bool hasFlag(ImmutableFlags flag) const {
     return immutableFlags_ & uint32_t(flag);
   }
   uint32_t immutableFlags() const { return immutableFlags_; }
 
  protected: