Przeglądaj źródła

Move capturedNameSerializedIds and capturedNamePointers into a union since they cannot be used at the same time

A few other small cleanups
Taylor Woll 7 lat temu
rodzic
commit
c31bd13fe7

+ 1 - 1
bin/ch/ch.cpp

@@ -681,7 +681,7 @@ HRESULT CreateParserStateAndRunScript(const char* fileName, LPCSTR fileContents,
 
     if (false)
     {
-    ErrorRunFinalize:
+ErrorRunFinalize:
         if (fileContentsFinalizeCallback != nullptr)
         {
             fileContentsFinalizeCallback((void*)fileContents);

+ 18 - 13
lib/Parser/Parse.h

@@ -147,19 +147,24 @@ struct DeferredFunctionStub
     // capturedNamePointers is not nullptr.
     Field(uint) capturedNameCount;
 
-    // After the parser memory is cleaned-up, we no longer have access to
-    // the IdentPtrs allocated from the Parser arena. We keep a list of
-    // ids into the string table deserialized from the parser state cache.
-    // This list is Recycler-allocated.
-    Field(int *) capturedNameSerializedIds;
-
-    // The set of names which are captured by this function.
-    // A function captures a name when it references a name not defined within
-    // the function.
-    // A function also captures all names captured by nested functions.
-    // The IdentPtrs in this set and the set itself are allocated from Parser
-    // arena memory.
-    Field(IdentPtrSet *) capturedNamePointers;
+    // Note: We only need to access either the list of serialized ids or the
+    //       set of IdentPtr captured names so these are in a union.
+    union
+    {
+        // After the parser memory is cleaned-up, we no longer have access to
+        // the IdentPtrs allocated from the Parser arena. We keep a list of
+        // ids into the string table deserialized from the parser state cache.
+        // This list is Recycler-allocated.
+        Field(int *) capturedNameSerializedIds;
+
+        // The set of names which are captured by this function.
+        // A function captures a name when it references a name not defined within
+        // the function.
+        // A function also captures all names captured by nested functions.
+        // The IdentPtrs in this set and the set itself are allocated from Parser
+        // arena memory.
+        Field(IdentPtrSet *) capturedNamePointers;
+    };
 
     // List of deferred stubs for further nested functions.
     // Length of this list is equal to nestedCount.

+ 4 - 5
lib/Parser/ParseFlags.h

@@ -16,7 +16,9 @@ enum
     fscrDynamicCode = 1 << 5,   // The code is being generated dynamically (eval, new Function, etc.)
     // Unused = 1 << 6,
     fscrNoImplicitHandlers = 1 << 7,   // same as Opt NoConnect at start of block
-    // Unused = 1 << 8,
+    fscrCreateParserState = 1 << 8, // The parser should expose parser state information on the parse nodes.
+                                    // This parser state includes the set of names which are captured by each function
+                                    // and is stored in ParseNodeFnc::capturedNames.
 
 #if DEBUG
     fscrEnforceJSON = 1 << 9,  // used together with fscrReturnExpression
@@ -49,8 +51,5 @@ enum
     fscrIsModuleCode = 1 << 26, // Current code should be parsed as a module body
 
     fscrDeferredFncIsMethod = 1 << 27,
-    fscrCreateParserState = 1 << 28, // The parser should expose parser state information on the parse nodes.
-                                     // This parser state includes the set of names which are captured by each function
-                                     // and is stored in ParseNodeFnc::capturedNames.
-    fscrAll = (1 << 29) - 1
+    fscrAll = (1 << 28) - 1
 };

+ 3 - 1
lib/Runtime/ByteCode/ByteCodeSerializer.cpp

@@ -2321,6 +2321,8 @@ public:
 
     HRESULT AddDeferredStubs(BufferBuilderList & builder, DeferredFunctionStub* deferredStubs, uint stubsCount, bool recursive)
     {
+        AssertOrFailFast(!(deferredStubs == nullptr && stubsCount > 0));
+
         if (deferredStubs == nullptr || stubsCount == 0)
         {
             return S_OK;
@@ -2328,7 +2330,7 @@ public:
 
         for (uint i = 0; i < stubsCount; i++)
         {
-            DeferredFunctionStub* currentStub = &(deferredStubs[i]);
+            DeferredFunctionStub* currentStub = deferredStubs + i;
 
             PrependUInt32(builder, _u("Character Min"), currentStub->ichMin);
             PrependUInt32(builder, _u("Function flags"), currentStub->fncFlags);

+ 1 - 2
lib/Runtime/Language/SimpleDataCacheWrapper.cpp

@@ -156,9 +156,8 @@ namespace Js
 
     HRESULT SimpleDataCacheWrapper::OpenReadStream()
     {
-        HRESULT hr = E_FAIL;
-
 #ifdef ENABLE_WININET_PROFILE_DATA_CACHE
+        HRESULT hr = E_FAIL;
         Assert(this->dataCache != nullptr);
         Assert(this->inStream == nullptr);
         IFFAILRET(this->dataCache->GetReadDataStream(&this->inStream));