Skip to content

Commit 7eb3570

Browse files
committed
Add named constant flags for ScopeInfo serialization
1 parent bc09b35 commit 7eb3570

File tree

1 file changed

+59
-31
lines changed

1 file changed

+59
-31
lines changed

lib/Runtime/ByteCode/ByteCodeSerializer.cpp

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,29 @@ enum FunctionFlags
230230
ffIsClassMember = 0x2000000,
231231
};
232232

233+
enum ScopeInfoFlags : byte
234+
{
235+
sifNone = 0x0,
236+
sifIsDynamic = 0x1,
237+
sifIsObject = 0x2,
238+
sifMustInstantiate = 0x4,
239+
sifIsCached = 0x8,
240+
sifHasLocalInClosure = 0x10,
241+
sifIsGeneratorFunctionBody = 0x20,
242+
sifIsAsyncFunctionBody = 0x40,
243+
};
244+
245+
enum SymbolInfoFlags : byte
246+
{
247+
syifNone = 0x0,
248+
syifHasFuncAssignment = 0x1,
249+
syifIsBlockVariable = 0x2,
250+
syifIsConst = 0x4,
251+
syifIsFuncExpr = 0x8,
252+
syifIsModuleExportStorage = 0x10,
253+
syifIsModuleImport = 0x20,
254+
};
255+
233256
// Kinds of constant
234257
enum ConstantType : byte
235258
{
@@ -2353,30 +2376,32 @@ class ByteCodeBufferBuilder
23532376
}
23542377
PrependUInt32(builder, _u("ScopeInfo FunctionInfo relative id"), relativeFunctionId);
23552378

2356-
BYTE flags = (scopeInfo->isDynamic ? 0x1 : 0)
2357-
| (scopeInfo->isObject ? 0x2 : 0)
2358-
| (scopeInfo->mustInstantiate ? 0x4 : 0)
2359-
| (scopeInfo->isCached ? 0x8 : 0)
2360-
| (scopeInfo->hasLocalInClosure ? 0x10 : 0)
2361-
| (scopeInfo->isGeneratorFunctionBody ? 0x20 : 0)
2362-
| (scopeInfo->isAsyncFunctionBody ? 0x40 : 0);
2379+
ScopeInfoFlags scopeInfoFlags = (ScopeInfoFlags)
2380+
( (scopeInfo->isDynamic ? sifIsDynamic : sifNone)
2381+
| (scopeInfo->isObject ? sifIsObject : sifNone)
2382+
| (scopeInfo->mustInstantiate ? sifMustInstantiate : sifNone)
2383+
| (scopeInfo->isCached ? sifIsCached : sifNone)
2384+
| (scopeInfo->hasLocalInClosure ? sifHasLocalInClosure : sifNone)
2385+
| (scopeInfo->isGeneratorFunctionBody ? sifIsGeneratorFunctionBody : sifNone)
2386+
| (scopeInfo->isAsyncFunctionBody ? sifIsAsyncFunctionBody : sifNone));
23632387

2364-
PrependByte(builder, _u("ScopeInfo flags"), flags);
2388+
PrependByte(builder, _u("ScopeInfo flags"), scopeInfoFlags);
23652389
PrependInt32(builder, _u("ScopeInfo scope type"), scopeInfo->scopeType);
23662390
PrependInt32(builder, _u("ScopeInfo scope id"), scopeInfo->scopeId);
23672391

23682392
for (int i = 0; i < scopeInfo->symbolCount; i++)
23692393
{
23702394
ScopeInfo::SymbolInfo* sym = scopeInfo->symbols + i;
23712395

2372-
flags = (sym->hasFuncAssignment ? 0x1 : 0)
2373-
| (sym->isBlockVariable ? 0x2 : 0)
2374-
| (sym->isConst ? 0x4 : 0)
2375-
| (sym->isFuncExpr ? 0x8 : 0)
2376-
| (sym->isModuleExportStorage ? 0x10 : 0)
2377-
| (sym->isModuleImport ? 0x20 : 0);
2396+
SymbolInfoFlags symbolInfoFlags = (SymbolInfoFlags)
2397+
( (sym->hasFuncAssignment ? syifHasFuncAssignment : syifNone)
2398+
| (sym->isBlockVariable ? syifIsBlockVariable : syifNone)
2399+
| (sym->isConst ? syifIsConst : syifNone)
2400+
| (sym->isFuncExpr ? syifIsFuncExpr : syifNone)
2401+
| (sym->isModuleExportStorage ? syifIsModuleExportStorage : syifNone)
2402+
| (sym->isModuleImport ? syifIsModuleImport : syifNone));
23782403

2379-
PrependByte(builder, _u("SymbolInfo flags"), flags);
2404+
PrependByte(builder, _u("SymbolInfo flags"), symbolInfoFlags);
23802405
PrependByte(builder, _u("SymbolInfo symbol type"), (BYTE)sym->symbolType);
23812406

23822407
PropertyId symPropertyId = sym->propertyId;
@@ -4273,15 +4298,15 @@ class ByteCodeBufferReader
42734298

42744299
*scopeInfo = RecyclerNewPlusZ(scriptContext->GetRecycler(), symbolCount * sizeof(ScopeInfo::SymbolInfo), ScopeInfo, functionInfo, symbolCount);
42754300

4276-
BYTE flags;
4277-
current = ReadByte(current, &flags);
4278-
(*scopeInfo)->isDynamic = (flags & 0x1) != 0;
4279-
(*scopeInfo)->isObject = (flags & 0x2) != 0;
4280-
(*scopeInfo)->mustInstantiate = (flags & 0x4) != 0;
4281-
(*scopeInfo)->isCached = (flags & 0x8) != 0;
4282-
(*scopeInfo)->hasLocalInClosure = (flags & 0x10) != 0;
4283-
(*scopeInfo)->isGeneratorFunctionBody = (flags & 0x20) != 0;
4284-
(*scopeInfo)->isAsyncFunctionBody = (flags & 0x40) != 0;
4301+
ScopeInfoFlags scopeInfoFlags;
4302+
current = ReadByte(current, (byte*)&scopeInfoFlags);
4303+
(*scopeInfo)->isDynamic = (scopeInfoFlags & sifIsDynamic) != 0;
4304+
(*scopeInfo)->isObject = (scopeInfoFlags & sifIsObject) != 0;
4305+
(*scopeInfo)->mustInstantiate = (scopeInfoFlags & sifMustInstantiate) != 0;
4306+
(*scopeInfo)->isCached = (scopeInfoFlags & sifIsCached) != 0;
4307+
(*scopeInfo)->hasLocalInClosure = (scopeInfoFlags & sifHasLocalInClosure) != 0;
4308+
(*scopeInfo)->isGeneratorFunctionBody = (scopeInfoFlags & sifIsGeneratorFunctionBody) != 0;
4309+
(*scopeInfo)->isAsyncFunctionBody = (scopeInfoFlags & sifIsAsyncFunctionBody) != 0;
42854310
(*scopeInfo)->areNamesCached = false;
42864311

42874312
int scopeType;
@@ -4294,13 +4319,14 @@ class ByteCodeBufferReader
42944319
{
42954320
ScopeInfo::SymbolInfo* sym = (*scopeInfo)->symbols + i;
42964321

4297-
current = ReadByte(current, &flags);
4298-
sym->hasFuncAssignment = (flags & 0x1) != 0;
4299-
sym->isBlockVariable = (flags & 0x2) != 0;
4300-
sym->isConst = (flags & 0x4) != 0;
4301-
sym->isFuncExpr = (flags & 0x8) != 0;
4302-
sym->isModuleExportStorage = (flags & 0x10) != 0;
4303-
sym->isModuleImport = (flags & 0x20) != 0;
4322+
SymbolInfoFlags symbolInfoFlags;
4323+
current = ReadByte(current, (byte*)&symbolInfoFlags);
4324+
sym->hasFuncAssignment = (symbolInfoFlags & syifHasFuncAssignment) != 0;
4325+
sym->isBlockVariable = (symbolInfoFlags & syifIsBlockVariable) != 0;
4326+
sym->isConst = (symbolInfoFlags & syifIsConst) != 0;
4327+
sym->isFuncExpr = (symbolInfoFlags & syifIsFuncExpr) != 0;
4328+
sym->isModuleExportStorage = (symbolInfoFlags & syifIsModuleExportStorage) != 0;
4329+
sym->isModuleImport = (symbolInfoFlags & syifIsModuleImport) != 0;
43044330

43054331
current = ReadByte(current, (BYTE*)&sym->symbolType);
43064332

@@ -4596,6 +4622,8 @@ class ByteCodeBufferReader
45964622

45974623
};
45984624

4625+
// This constructor is for allocating a ByteCodeCache without a reader (ie: before the bytecode buffer is generated).
4626+
// SetReader() should be called before using the cache.
45994627
ByteCodeCache::ByteCodeCache(ScriptContext * scriptContext, int builtInPropertyCount)
46004628
: reader(nullptr), propertyCount(0), builtInPropertyCount(builtInPropertyCount), raw(nullptr), propertyIds(nullptr), localFunctionIdToFunctionInfoMap(nullptr)
46014629
{

0 commit comments

Comments
 (0)