Skip to content

Commit c31bd13

Browse files
committed
Move capturedNameSerializedIds and capturedNamePointers into a union since they cannot be used at the same time
A few other small cleanups
1 parent ab1d30d commit c31bd13

5 files changed

Lines changed: 27 additions & 22 deletions

File tree

bin/ch/ch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ HRESULT CreateParserStateAndRunScript(const char* fileName, LPCSTR fileContents,
681681

682682
if (false)
683683
{
684-
ErrorRunFinalize:
684+
ErrorRunFinalize:
685685
if (fileContentsFinalizeCallback != nullptr)
686686
{
687687
fileContentsFinalizeCallback((void*)fileContents);

lib/Parser/Parse.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,24 @@ struct DeferredFunctionStub
147147
// capturedNamePointers is not nullptr.
148148
Field(uint) capturedNameCount;
149149

150-
// After the parser memory is cleaned-up, we no longer have access to
151-
// the IdentPtrs allocated from the Parser arena. We keep a list of
152-
// ids into the string table deserialized from the parser state cache.
153-
// This list is Recycler-allocated.
154-
Field(int *) capturedNameSerializedIds;
155-
156-
// The set of names which are captured by this function.
157-
// A function captures a name when it references a name not defined within
158-
// the function.
159-
// A function also captures all names captured by nested functions.
160-
// The IdentPtrs in this set and the set itself are allocated from Parser
161-
// arena memory.
162-
Field(IdentPtrSet *) capturedNamePointers;
150+
// Note: We only need to access either the list of serialized ids or the
151+
// set of IdentPtr captured names so these are in a union.
152+
union
153+
{
154+
// After the parser memory is cleaned-up, we no longer have access to
155+
// the IdentPtrs allocated from the Parser arena. We keep a list of
156+
// ids into the string table deserialized from the parser state cache.
157+
// This list is Recycler-allocated.
158+
Field(int *) capturedNameSerializedIds;
159+
160+
// The set of names which are captured by this function.
161+
// A function captures a name when it references a name not defined within
162+
// the function.
163+
// A function also captures all names captured by nested functions.
164+
// The IdentPtrs in this set and the set itself are allocated from Parser
165+
// arena memory.
166+
Field(IdentPtrSet *) capturedNamePointers;
167+
};
163168

164169
// List of deferred stubs for further nested functions.
165170
// Length of this list is equal to nestedCount.

lib/Parser/ParseFlags.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ enum
1616
fscrDynamicCode = 1 << 5, // The code is being generated dynamically (eval, new Function, etc.)
1717
// Unused = 1 << 6,
1818
fscrNoImplicitHandlers = 1 << 7, // same as Opt NoConnect at start of block
19-
// Unused = 1 << 8,
19+
fscrCreateParserState = 1 << 8, // The parser should expose parser state information on the parse nodes.
20+
// This parser state includes the set of names which are captured by each function
21+
// and is stored in ParseNodeFnc::capturedNames.
2022

2123
#if DEBUG
2224
fscrEnforceJSON = 1 << 9, // used together with fscrReturnExpression
@@ -49,8 +51,5 @@ enum
4951
fscrIsModuleCode = 1 << 26, // Current code should be parsed as a module body
5052

5153
fscrDeferredFncIsMethod = 1 << 27,
52-
fscrCreateParserState = 1 << 28, // The parser should expose parser state information on the parse nodes.
53-
// This parser state includes the set of names which are captured by each function
54-
// and is stored in ParseNodeFnc::capturedNames.
55-
fscrAll = (1 << 29) - 1
54+
fscrAll = (1 << 28) - 1
5655
};

lib/Runtime/ByteCode/ByteCodeSerializer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2321,14 +2321,16 @@ class ByteCodeBufferBuilder
23212321

23222322
HRESULT AddDeferredStubs(BufferBuilderList & builder, DeferredFunctionStub* deferredStubs, uint stubsCount, bool recursive)
23232323
{
2324+
AssertOrFailFast(!(deferredStubs == nullptr && stubsCount > 0));
2325+
23242326
if (deferredStubs == nullptr || stubsCount == 0)
23252327
{
23262328
return S_OK;
23272329
}
23282330

23292331
for (uint i = 0; i < stubsCount; i++)
23302332
{
2331-
DeferredFunctionStub* currentStub = &(deferredStubs[i]);
2333+
DeferredFunctionStub* currentStub = deferredStubs + i;
23322334

23332335
PrependUInt32(builder, _u("Character Min"), currentStub->ichMin);
23342336
PrependUInt32(builder, _u("Function flags"), currentStub->fncFlags);

lib/Runtime/Language/SimpleDataCacheWrapper.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,8 @@ namespace Js
156156

157157
HRESULT SimpleDataCacheWrapper::OpenReadStream()
158158
{
159-
HRESULT hr = E_FAIL;
160-
161159
#ifdef ENABLE_WININET_PROFILE_DATA_CACHE
160+
HRESULT hr = E_FAIL;
162161
Assert(this->dataCache != nullptr);
163162
Assert(this->inStream == nullptr);
164163
IFFAILRET(this->dataCache->GetReadDataStream(&this->inStream));

0 commit comments

Comments
 (0)