project
stringclasses 633
values | commit_id
stringlengths 7
81
| target
int64 0
1
| func
stringlengths 5
484k
| cwe
stringclasses 131
values | big_vul_idx
float64 0
189k
⌀ | idx
int64 0
522k
| hash
stringlengths 34
39
| size
float64 1
24k
⌀ | message
stringlengths 0
11.5k
⌀ | dataset
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::PopDynamicBlock()
{
int blockId = GetCurrentDynamicBlockId();
if (GetCurrentBlock()->sxBlock.blockId != blockId || blockId == -1)
{
return;
}
Assert(m_currentDynamicBlock);
for (BlockInfoStack *blockInfo = m_currentBlockInfo; blockInfo; blockInfo = blockInfo->pBlockInfoOuter)
{
for (ParseNodePtr pnodeDecl = blockInfo->pnodeBlock->sxBlock.pnodeLexVars;
pnodeDecl;
pnodeDecl = pnodeDecl->sxVar.pnodeNext)
{
this->SetPidRefsInScopeDynamic(pnodeDecl->sxVar.pid, blockId);
}
}
m_currentDynamicBlock = m_currentDynamicBlock->prev;
}
|
CWE-119
| null | 517,574 |
241680341181491592186535700102095693091
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::EnsureStackAvailable()
{
if (!m_scriptContext->GetThreadContext()->IsStackAvailable(Js::Constants::MinStackCompile))
{
Error(ERRnoMemory);
}
}
|
CWE-119
| null | 517,575 |
34860016207546465021929313024118695509
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNode* Parser::GetCurrentBlock()
{
return m_currentBlockInfo != nullptr ? m_currentBlockInfo->pnodeBlock : nullptr;
}
|
CWE-119
| null | 517,576 |
308327836701435114721378852063399638211
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::Error(HRESULT hr, ParseNodePtr pnode)
{
if (pnode && pnode->ichLim)
{
Error(hr, pnode->ichMin, pnode->ichLim);
}
else
{
Error(hr);
}
}
|
CWE-119
| null | 517,577 |
111418577523572144604703747099329905521
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::InitNode(OpCode nop,ParseNodePtr pnode) {
pnode->nop = nop;
pnode->grfpn = PNodeFlags::fpnNone;
pnode->location = NoRegister;
pnode->emitLabels = false;
pnode->isUsed = true;
pnode->notEscapedUse = false;
pnode->isInList = false;
pnode->isCallApplyTargetLoad = false;
}
|
CWE-119
| null | 517,578 |
202413927700589099853692078557185567580
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::ValidateSourceElementList()
{
ParseStmtList<false>(nullptr, nullptr, SM_NotUsed, true);
}
|
CWE-119
| null | 517,579 |
248147991782902047664023605445554633743
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::WaitForBackgroundJobs(BackgroundParser *bgp, CompileScriptException *pse)
{
// The scan of the script is done, but there may be unfinished background jobs in the queue.
// Enlist the main thread to help with those.
BackgroundParseItem *item;
if (!*bgp->GetPendingBackgroundItemsPtr())
{
// We're done.
return;
}
// Save parser state, since we'll need to restore it in order to bind references correctly later.
this->m_isInBackground = true;
this->SetCurrBackgroundParseItem(nullptr);
uint blockIdSave = this->m_nextBlockId;
uint functionIdSave = *this->m_nextFunctionId;
StmtNest *pstmtSave = this->m_pstmtCur;
if (!bgp->Processor()->ProcessesInBackground())
{
// No background thread. Just walk the jobs with no locking and process them.
for (item = bgp->GetNextUnprocessedItem(); item; item = bgp->GetNextUnprocessedItem())
{
bgp->Processor()->RemoveJob(item);
bool succeeded = bgp->Process(item, this, pse);
bgp->JobProcessed(item, succeeded);
}
Assert(!*bgp->GetPendingBackgroundItemsPtr());
}
else
{
// Background threads. We need to have the critical section in order to:
// - Check for unprocessed jobs;
// - Remove jobs from the processor queue;
// - Do JobsProcessed work (such as removing jobs from the BackgroundParser's unprocessed list).
CriticalSection *pcs = static_cast<JsUtil::BackgroundJobProcessor*>(bgp->Processor())->GetCriticalSection();
pcs->Enter();
for (;;)
{
// Grab a job (in lock)
item = bgp->GetNextUnprocessedItem();
if (item == nullptr)
{
break;
}
bgp->Processor()->RemoveJob(item);
pcs->Leave();
// Process job (if there is one) (outside lock)
bool succeeded = bgp->Process(item, this, pse);
pcs->Enter();
bgp->JobProcessed(item, succeeded);
}
pcs->Leave();
// Wait for the background threads to finish jobs they're already processing (if any).
// TODO: Replace with a proper semaphore.
while(*bgp->GetPendingBackgroundItemsPtr());
}
Assert(!*bgp->GetPendingBackgroundItemsPtr());
// Restore parser state.
this->m_pstmtCur = pstmtSave;
this->m_isInBackground = false;
this->m_nextBlockId = blockIdSave;
*this->m_nextFunctionId = functionIdSave;
}
|
CWE-119
| null | 517,580 |
168405355909716340641156733947910976264
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::ParseStmtList(ParseNodePtr *ppnodeList, ParseNodePtr **pppnodeLast, StrictModeEnvironment smEnvironment, const bool isSourceElementList, bool* strictModeOn)
{
BOOL doneDirectives = !isSourceElementList; // directives may only exist in a SourceElementList, not a StatementList
BOOL seenDirectiveContainingOctal = false; // Have we seen an octal directive before a use strict directive?
BOOL old_UseStrictMode = m_fUseStrictMode;
ParseNodePtr pnodeStmt;
ParseNodePtr *lastNodeRef = nullptr;
if (buildAST)
{
AssertMem(ppnodeList);
AssertMemN(pppnodeLast);
*ppnodeList = nullptr;
}
if(CONFIG_FLAG(ForceStrictMode))
{
m_fUseStrictMode = TRUE;
}
for (;;)
{
switch (m_token.tk)
{
case tkCASE:
case tkDEFAULT:
case tkRCurly:
case tkEOF:
if (buildAST && nullptr != pppnodeLast)
{
*pppnodeLast = lastNodeRef;
}
if (!buildAST)
{
m_fUseStrictMode = old_UseStrictMode;
}
return;
}
if (doneDirectives == FALSE)
{
bool isOctalInString = false;
bool isUseStrictDirective = false;
bool isUseAsmDirective = false;
if (smEnvironment != SM_NotUsed && CheckForDirective(&isUseStrictDirective, &isUseAsmDirective, &isOctalInString))
{
// Ignore "use asm" statement when not building the AST
isUseAsmDirective &= buildAST;
if (isUseStrictDirective)
{
// Functions with non-simple parameter list cannot be made strict mode
if (GetCurrentFunctionNode()->sxFnc.HasNonSimpleParameterList())
{
Error(ERRNonSimpleParamListInStrictMode);
}
if (seenDirectiveContainingOctal)
{
// Directives seen before a "use strict" cannot contain an octal.
Error(ERRES5NoOctal);
}
if (!buildAST)
{
// Turning on strict mode in deferred code.
m_fUseStrictMode = TRUE;
if (!m_inDeferredNestedFunc)
{
// Top-level deferred function, so there's a parse node
Assert(m_currentNodeFunc != nullptr);
m_currentNodeFunc->sxFnc.SetStrictMode();
}
else if (strictModeOn)
{
// This turns on strict mode in a deferred function, we need to go back
// and re-check duplicated formals.
*strictModeOn = true;
}
}
else
{
if (smEnvironment == SM_OnGlobalCode)
{
// Turning on strict mode at the top level
m_fUseStrictMode = TRUE;
}
else
{
// i.e. smEnvironment == SM_OnFunctionCode
Assert(m_currentNodeFunc != nullptr);
m_currentNodeFunc->sxFnc.SetStrictMode();
}
}
}
else if (isUseAsmDirective)
{
if (smEnvironment != SM_OnGlobalCode) //Top level use asm doesn't mean anything.
{
// i.e. smEnvironment == SM_OnFunctionCode
Assert(m_currentNodeFunc != nullptr);
m_currentNodeFunc->sxFnc.SetAsmjsMode();
m_currentNodeFunc->sxFnc.SetCanBeDeferred(false);
m_InAsmMode = true;
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(AsmJSFunction, m_scriptContext);
}
}
else if (isOctalInString)
{
seenDirectiveContainingOctal = TRUE;
}
}
else
{
// The first time we see anything other than a directive we can have no more directives.
doneDirectives = TRUE;
}
}
if (nullptr != (pnodeStmt = ParseStatement<buildAST>()))
{
if (buildAST)
{
AddToNodeList(ppnodeList, &lastNodeRef, pnodeStmt);
}
}
}
}
|
CWE-119
| null | 517,581 |
7092829180292950778479661634405386859
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
Js::PropertyId PnPid::PropertyIdFromNameNode() const
{
Js::PropertyId propertyId;
Symbol *sym = this->sym;
if (sym)
{
propertyId = sym->GetPosition();
}
else
{
propertyId = this->pid->GetPropertyId();
}
return propertyId;
}
|
CWE-119
| null | 517,582 |
158399521457606642739132719333247535110
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateIntNode(int32 lw)
{
ParseNodePtr pnode = CreateNode(knopInt);
pnode->sxInt.lw = lw;
return pnode;
}
|
CWE-119
| null | 517,583 |
324607568892580495489501794668973247443
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateProgNodeWithScanner(bool isModuleSource)
{
ParseNodePtr pnodeProg;
if (isModuleSource)
{
pnodeProg = CreateNodeWithScanner<knopModule>();
// knopModule is not actually handled anywhere since we would need to handle it everywhere we could
// have knopProg and it would be treated exactly the same except for import/export statements.
// We are only using it as a way to get the correct size for PnModule.
// Consider: Should we add a flag to PnProg which is false but set to true in PnModule?
// If we do, it can't be a virtual method since the parse nodes are all in a union.
pnodeProg->nop = knopProg;
}
else
{
pnodeProg = CreateNodeWithScanner<knopProg>();
}
return pnodeProg;
}
|
CWE-119
| null | 517,584 |
64221612624522670547133336138991986821
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
BlockInfoStack* Parser::GetCurrentBlockInfo()
{
return m_currentBlockInfo;
}
|
CWE-119
| null | 517,585 |
220105325842821918715043937905128685480
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateNodeWithScanner(charcount_t ichMin)
{
Assert(m_pscan != nullptr);
return CreateNodeT<nop>(ichMin, m_pscan->IchLimTok());
}
|
CWE-119
| null | 517,586 |
254825108000896173426485381616231409032
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
LPCOLESTR Parser::ConstructNameHint(ParseNodePtr pNode, uint32* fullNameHintLength, uint32 *pShortNameOffset)
{
Assert(pNode != nullptr);
Assert(pNode->nop == knopDot || pNode->nop == knopIndex);
LPCOLESTR leftNode = nullptr;
if (pNode->sxBin.pnode1->nop == knopDot || pNode->sxBin.pnode1->nop == knopIndex)
{
leftNode = ConstructNameHint(pNode->sxBin.pnode1, fullNameHintLength, pShortNameOffset);
}
else if (pNode->sxBin.pnode1->nop == knopName)
{
leftNode = pNode->sxBin.pnode1->sxPid.pid->Psz();
*fullNameHintLength = pNode->sxBin.pnode1->sxPid.pid->Cch();
*pShortNameOffset = 0;
}
if (pNode->nop == knopIndex)
{
return FormatPropertyString(
leftNode ? leftNode : Js::Constants::AnonymousFunction, // e.g. f()[0] = function () {}
pNode->sxBin.pnode2, fullNameHintLength, pShortNameOffset);
}
Assert(pNode->sxBin.pnode2->nop == knopDot || pNode->sxBin.pnode2->nop == knopName);
LPCOLESTR rightNode = nullptr;
bool wrapWithBrackets = false;
if (pNode->sxBin.pnode2->nop == knopDot)
{
rightNode = ConstructNameHint(pNode->sxBin.pnode2, fullNameHintLength, pShortNameOffset);
}
else
{
rightNode = pNode->sxBin.pnode2->sxPid.pid->Psz();
wrapWithBrackets = PNodeFlags::fpnIndexOperator == (pNode->grfpn & PNodeFlags::fpnIndexOperator);
}
Assert(rightNode != nullptr);
return AppendNameHints(leftNode, rightNode, fullNameHintLength, pShortNameOffset, false, wrapWithBrackets);
}
|
CWE-119
| null | 517,587 |
101247377600237119906730867154694575961
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
LPCOLESTR Parser::AppendNameHints(LPCOLESTR left, IdentPtr right, uint32 *pNameLength, uint32 *pShortNameOffset, bool ignoreAddDotWithSpace, bool wrapInBrackets)
{
uint32 leftLen = (left == nullptr) ? 0 : (uint32) wcslen(left);
if (pShortNameOffset != nullptr)
{
*pShortNameOffset = 0;
}
Assert(leftLen <= ULONG_MAX); // name hints should not exceed ULONG_MAX characters
if (left == nullptr || (leftLen == 0 && !wrapInBrackets))
{
if (right != nullptr)
{
*pNameLength = right->Cch();
return right->Psz();
}
return nullptr;
}
if (right == nullptr)
{
*pNameLength = leftLen;
return left;
}
uint32 rightLen = right->Cch();
return AppendNameHints(left, leftLen, right->Psz(), rightLen, pNameLength, pShortNameOffset, ignoreAddDotWithSpace, wrapInBrackets);
}
|
CWE-119
| null | 517,588 |
8897247355650545135916298200786848864
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
BlockInfoStack* Parser::GetCurrentFunctionBlockInfo()
{
return m_currentBlockInfo->pBlockInfoFunction;
}
|
CWE-119
| null | 517,589 |
102422849112299085172613459112608360229
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
Symbol *PnFnc::GetFuncSymbol()
{
if (pnodeName &&
pnodeName->nop == knopVarDecl)
{
return pnodeName->sxVar.sym;
}
return nullptr;
}
|
CWE-119
| null | 517,590 |
179740432204166156233174448523338085529
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ConvertObjectToObjectPattern(ParseNodePtr pnodeMemberList)
{
charcount_t ichMin = m_pscan->IchMinTok();
charcount_t ichLim = m_pscan->IchLimTok();
ParseNodePtr pnodeMemberNodeList = nullptr;
if (pnodeMemberList != nullptr && pnodeMemberList->nop == knopObject)
{
ichMin = pnodeMemberList->ichMin;
ichLim = pnodeMemberList->ichLim;
pnodeMemberList = pnodeMemberList->sxUni.pnode1;
}
ForEachItemInList(pnodeMemberList, [&](ParseNodePtr item) {
ParseNodePtr memberNode = ConvertMemberToMemberPattern(item);
AppendToList(&pnodeMemberNodeList, memberNode);
});
return CreateUniNode(knopObjectPattern, pnodeMemberNodeList, ichMin, ichLim);
}
|
CWE-119
| null | 517,591 |
86244405356287952151528755402138706840
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::AddToNodeList(ParseNode ** ppnodeList, ParseNode *** pppnodeLast,
ParseNode * pnodeAdd)
{
Assert(!this->m_deferringAST);
if (nullptr == *pppnodeLast)
{
// should be an empty list
Assert(nullptr == *ppnodeList);
*ppnodeList = pnodeAdd;
*pppnodeLast = ppnodeList;
}
else
{
//
AssertNodeMem(*ppnodeList);
AssertNodeMem(**pppnodeLast);
ParseNode *pnodeT = CreateBinNode(knopList, **pppnodeLast, pnodeAdd);
**pppnodeLast = pnodeT;
*pppnodeLast = &pnodeT->sxBin.pnode2;
}
}
|
CWE-119
| null | 517,592 |
91374504412401745759858945334077175073
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseBlock(ParseNodePtr pnodeLabel, LabelId* pLabelId)
{
ParseNodePtr pnodeBlock = nullptr;
ParseNodePtr *ppnodeScopeSave = nullptr;
ParseNodePtr *ppnodeExprScopeSave = nullptr;
pnodeBlock = StartParseBlock<buildAST>(PnodeBlockType::Regular, ScopeType_Block, pnodeLabel, pLabelId);
BlockInfoStack* outerBlockInfo = m_currentBlockInfo->pBlockInfoOuter;
if (outerBlockInfo != nullptr && outerBlockInfo->pnodeBlock != nullptr
&& outerBlockInfo->pnodeBlock->sxBlock.scope != nullptr
&& outerBlockInfo->pnodeBlock->sxBlock.scope->GetScopeType() == ScopeType_CatchParamPattern)
{
// If we are parsing the catch block then destructured params can have let declrations. Let's add them to the new block.
for (ParseNodePtr pnode = m_currentBlockInfo->pBlockInfoOuter->pnodeBlock->sxBlock.pnodeLexVars; pnode; pnode = pnode->sxVar.pnodeNext)
{
PidRefStack* ref = PushPidRef(pnode->sxVar.sym->GetPid());
ref->SetSym(pnode->sxVar.sym);
}
}
ChkCurTok(tkLCurly, ERRnoLcurly);
ParseNodePtr * ppnodeList = nullptr;
if (buildAST)
{
PushFuncBlockScope(pnodeBlock, &ppnodeScopeSave, &ppnodeExprScopeSave);
ppnodeList = &pnodeBlock->sxBlock.pnodeStmt;
}
ParseStmtList<buildAST>(ppnodeList);
if (buildAST)
{
PopFuncBlockScope(ppnodeScopeSave, ppnodeExprScopeSave);
}
FinishParseBlock(pnodeBlock);
ChkCurTok(tkRCurly, ERRnoRcurly);
return pnodeBlock;
}
|
CWE-119
| null | 517,593 |
331501638888595200725418265463819005565
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::ParseTopLevelDeferredFunc(ParseNodePtr pnodeFnc, ParseNodePtr pnodeFncParent, LPCOLESTR pNameHint)
{
// Parse a function body that is a transition point from building AST to doing fast syntax check.
pnodeFnc->sxFnc.pnodeVars = nullptr;
pnodeFnc->sxFnc.pnodeBody = nullptr;
this->m_deferringAST = TRUE;
// Put the scanner into "no hashing" mode.
BYTE deferFlags = m_pscan->SetDeferredParse(TRUE);
m_pscan->Scan();
ChkCurTok(tkLCurly, ERRnoLcurly);
ParseNodePtr *ppnodeVarSave = m_ppnodeVar;
m_ppnodeVar = &pnodeFnc->sxFnc.pnodeVars;
if (pnodeFncParent != nullptr
&& m_currDeferredStub != nullptr
// We don't create stubs for function bodies in parameter scope.
&& pnodeFnc->sxFnc.pnodeScopes->sxBlock.blockType != PnodeBlockType::Parameter)
{
// We've already parsed this function body for syntax errors on the initial parse of the script.
// We have information that allows us to skip it, so do so.
DeferredFunctionStub *stub = m_currDeferredStub + (pnodeFncParent->sxFnc.nestedCount - 1);
Assert(pnodeFnc->ichMin == stub->ichMin);
if (stub->fncFlags & kFunctionCallsEval)
{
this->MarkEvalCaller();
}
if (stub->fncFlags & kFunctionChildCallsEval)
{
pnodeFnc->sxFnc.SetChildCallsEval(true);
}
if (stub->fncFlags & kFunctionHasWithStmt)
{
pnodeFnc->sxFnc.SetHasWithStmt(true);
}
PHASE_PRINT_TRACE1(
Js::SkipNestedDeferredPhase,
_u("Skipping nested deferred function %d. %s: %d...%d\n"),
pnodeFnc->sxFnc.functionId, GetFunctionName(pnodeFnc, pNameHint), pnodeFnc->ichMin, stub->restorePoint.m_ichMinTok);
m_pscan->SeekTo(stub->restorePoint, m_nextFunctionId);
pnodeFnc->sxFnc.nestedCount = stub->nestedCount;
pnodeFnc->sxFnc.deferredStub = stub->deferredStubs;
if (stub->fncFlags & kFunctionStrictMode)
{
pnodeFnc->sxFnc.SetStrictMode(true);
}
}
else
{
ParseStmtList<false>(nullptr, nullptr, SM_DeferredParse, true /* isSourceElementList */);
}
pnodeFnc->ichLim = m_pscan->IchLimTok();
pnodeFnc->sxFnc.cbLim = m_pscan->IecpLimTok();
m_ppnodeVar = ppnodeVarSave;
// Restore the scanner's default hashing mode.
// Do this before we consume the next token.
m_pscan->SetDeferredParseFlags(deferFlags);
ChkCurTokNoScan(tkRCurly, ERRnoRcurly);
#if DBG
pnodeFnc->sxFnc.deferredParseNextFunctionId = *this->m_nextFunctionId;
#endif
this->m_deferringAST = FALSE;
}
|
CWE-119
| null | 517,594 |
83933536302402097502296692238641489923
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
AutoParsingSuperRestrictionStateRestorer(Parser* parser) : m_parser(parser)
{
AssertMsg(this->m_parser != nullptr, "This just should not happen");
this->m_originalParsingSuperRestrictionState = this->m_parser->m_parsingSuperRestrictionState;
}
|
CWE-119
| null | 517,595 |
750606699344653011601786634628657968
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::CaptureContext(ParseContext *parseContext) const
{
parseContext->pszSrc = m_pscan->PchBase();
parseContext->length = this->m_originalLength;
parseContext->characterOffset = m_pscan->IchMinTok();
parseContext->offset = parseContext->characterOffset + m_pscan->m_cMultiUnits;
parseContext->grfscr = this->m_grfscr;
parseContext->lineNumber = m_pscan->LineCur();
parseContext->pnodeProg = this->m_currentNodeProg;
parseContext->fromExternal = m_pscan->IsFromExternalSource();
parseContext->strictMode = this->IsStrictMode();
parseContext->sourceContextInfo = this->m_sourceContextInfo;
parseContext->currentBlockInfo = this->m_currentBlockInfo;
parseContext->nextBlockId = this->m_nextBlockId;
}
|
CWE-119
| null | 517,596 |
31437027571146899553350726248003607627
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::PrepareForBackgroundParse()
{
m_pscan->PrepareForBackgroundParse(m_scriptContext);
}
|
CWE-119
| null | 517,597 |
94735860629864155575457668533833996542
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateNodeWithScanner()
{
Assert(m_pscan != nullptr);
return CreateNodeWithScanner<nop>(m_pscan->IchMinTok());
}
|
CWE-119
| null | 517,598 |
90153720390033732726484210953889313895
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::AddVarDeclNode(IdentPtr pid, ParseNodePtr pnodeFnc)
{
AnalysisAssert(pnodeFnc);
ParseNodePtr *const ppnodeVarSave = m_ppnodeVar;
m_ppnodeVar = &pnodeFnc->sxFnc.pnodeVars;
while (*m_ppnodeVar != nullptr)
{
m_ppnodeVar = &(*m_ppnodeVar)->sxVar.pnodeNext;
}
ParseNodePtr pnode = CreateVarDeclNode(pid, STUnknown, false, 0, /* checkReDecl = */ false);
m_ppnodeVar = ppnodeVarSave;
return pnode;
}
|
CWE-119
| null | 517,599 |
34807405084284548960062131608250072541
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::RemovePrevPidRef(IdentPtr pid, PidRefStack *ref)
{
PidRefStack *prevRef = pid->RemovePrevPidRef(ref);
Assert(prevRef);
if (prevRef->GetSym() == nullptr)
{
AllocatorDelete(ArenaAllocator, &m_nodeAllocator, prevRef);
}
}
|
CWE-119
| null | 517,600 |
230090312894715852429335660541783541892
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void PrintFormalsWIndent(ParseNode *pnodeArgs, int indentAmt)
{
for (ParseNode *pnode = pnodeArgs; pnode != nullptr; pnode = pnode->GetFormalNext())
{
PrintPnodeWIndent(pnode->nop == knopParamPattern ? pnode->sxParamPattern.pnode1 : pnode, indentAmt);
}
}
|
CWE-119
| null | 517,601 |
39397288509115660814584667633848414805
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
bool Parser::IsImportOrExportStatementValidHere()
{
ParseNodePtr curFunc = GetCurrentFunctionNode();
// Import must be located in the top scope of the module body.
return curFunc->nop == knopFncDecl
&& curFunc->sxFnc.IsModule()
&& this->m_currentBlockInfo->pnodeBlock == curFunc->sxFnc.pnodeBodyScope
&& (this->m_grfscr & fscrEvalCode) != fscrEvalCode
&& this->m_tryCatchOrFinallyDepth == 0;
}
|
CWE-119
| null | 517,602 |
302638204060367445284898500431156234981
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::ThrowNewTargetSyntaxErrForGlobalScope()
{
if (GetCurrentNonLambdaFunctionNode() != nullptr)
{
return;
}
if ((this->m_grfscr & fscrEval) != 0)
{
Js::JavascriptFunction * caller = nullptr;
if (Js::JavascriptStackWalker::GetCaller(&caller, m_scriptContext))
{
Js::FunctionBody * callerBody = caller->GetFunctionBody();
Assert(callerBody);
if (!callerBody->GetIsGlobalFunc() && !(callerBody->IsLambda() && callerBody->GetEnclosedByGlobalFunc()))
{
return;
}
}
}
Error(ERRInvalidNewTarget);
}
|
CWE-119
| null | 517,603 |
131927288033640188631820225295895564987
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateBinNode(OpCode nop, ParseNodePtr pnode1, ParseNodePtr pnode2)
{
Assert(!this->m_deferringAST);
charcount_t ichMin;
charcount_t ichLim;
if (nullptr == pnode1)
{
// no ops
Assert(nullptr == pnode2);
ichMin = m_pscan->IchMinTok();
ichLim = m_pscan->IchLimTok();
}
else
{
if (nullptr == pnode2)
{
// 1 op
ichMin = pnode1->ichMin;
ichLim = pnode1->ichLim;
}
else
{
// 2 ops
ichMin = pnode1->ichMin;
ichLim = pnode2->ichLim;
if (nop != knopDot && nop != knopIndex)
{
this->CheckArguments(pnode2);
}
}
if (nop != knopDot && nop != knopIndex)
{
this->CheckArguments(pnode1);
}
}
return CreateBinNode(nop, pnode1, pnode2, ichMin, ichLim);
}
|
CWE-119
| null | 517,604 |
57217140076829017774681064478924833995
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseTerm(BOOL fAllowCall,
LPCOLESTR pNameHint,
uint32 *pHintLength,
uint32 *pShortNameOffset,
_Inout_opt_ IdentToken* pToken /*= nullptr*/,
bool fUnaryOrParen /*= false*/,
_Out_opt_ BOOL* pfCanAssign /*= nullptr*/,
_Inout_opt_ BOOL* pfLikelyPattern /*= nullptr*/,
_Out_opt_ bool* pfIsDotOrIndex /*= nullptr*/,
_Inout_opt_ charcount_t *plastRParen /*= nullptr*/)
{
ParseNodePtr pnode = nullptr;
PidRefStack *savedTopAsyncRef = nullptr;
charcount_t ichMin = 0;
size_t iecpMin = 0;
size_t iuMin;
IdentToken term;
BOOL fInNew = FALSE;
BOOL fCanAssign = TRUE;
bool isAsyncExpr = false;
bool isLambdaExpr = false;
Assert(pToken == nullptr || pToken->tk == tkNone); // Must be empty initially
if (this->IsBackgroundParser())
{
PROBE_STACK_NO_DISPOSE(m_scriptContext, Js::Constants::MinStackParseOneTerm);
}
else
{
PROBE_STACK(m_scriptContext, Js::Constants::MinStackParseOneTerm);
}
switch (m_token.tk)
{
case tkID:
{
PidRefStack *ref = nullptr;
IdentPtr pid = m_token.GetIdentifier(m_phtbl);
charcount_t ichLim = m_pscan->IchLimTok();
size_t iecpLim = m_pscan->IecpLimTok();
ichMin = m_pscan->IchMinTok();
iecpMin = m_pscan->IecpMinTok();
if (pid == wellKnownPropertyPids.async &&
m_scriptContext->GetConfig()->IsES7AsyncAndAwaitEnabled())
{
isAsyncExpr = true;
}
bool previousAwaitIsKeyword = m_pscan->SetAwaitIsKeyword(isAsyncExpr);
m_pscan->Scan();
m_pscan->SetAwaitIsKeyword(previousAwaitIsKeyword);
// We search for an Async expression (a function declaration or an async lambda expression)
if (isAsyncExpr && !m_pscan->FHadNewLine())
{
if (m_token.tk == tkFUNCTION)
{
goto LFunction;
}
else if (m_token.tk == tkID || m_token.tk == tkAWAIT)
{
isLambdaExpr = true;
goto LFunction;
}
else if (m_token.tk == tkLParen)
{
// This is potentially an async arrow function. Save the state of the async references
// in case it needs to be restored. (Note that the case of a single parameter with no ()'s
// is detected upstream and need not be handled here.)
savedTopAsyncRef = pid->GetTopRef();
}
}
// Don't push a reference if this is a single lambda parameter, because we'll reparse with
// a correct function ID.
if (m_token.tk != tkDArrow)
{
ref = this->PushPidRef(pid);
}
if (buildAST)
{
pnode = CreateNameNode(pid);
pnode->ichMin = ichMin;
pnode->ichLim = ichLim;
pnode->sxPid.SetSymRef(ref);
}
else
{
// Remember the identifier start and end in case it turns out to be a statement label.
term.tk = tkID;
term.pid = pid; // Record the identifier for detection of eval
term.ichMin = static_cast<charcount_t>(iecpMin);
term.ichLim = static_cast<charcount_t>(iecpLim);
}
CheckArgumentsUse(pid, GetCurrentFunctionNode());
break;
}
case tkTHIS:
if (buildAST)
{
pnode = CreateNodeWithScanner<knopThis>();
}
fCanAssign = FALSE;
m_pscan->Scan();
break;
case tkLParen:
{
ichMin = m_pscan->IchMinTok();
iuMin = m_pscan->IecpMinTok();
m_pscan->Scan();
if (m_token.tk == tkRParen)
{
// Empty parens can only be legal as an empty parameter list to a lambda declaration.
// We're in a lambda if the next token is =>.
fAllowCall = FALSE;
m_pscan->Scan();
// If the token after the right paren is not => or if there was a newline between () and => this is a syntax error
if (!m_doingFastScan && (m_token.tk != tkDArrow || m_pscan->FHadNewLine()))
{
Error(ERRsyntax);
}
if (buildAST)
{
pnode = CreateNodeWithScanner<knopEmpty>();
}
break;
}
// Advance the block ID here in case this parenthetical expression turns out to be a lambda parameter list.
// That way the pid ref stacks will be created in their correct final form, and we can simply fix
// up function ID's.
uint saveNextBlockId = m_nextBlockId;
uint saveCurrBlockId = GetCurrentBlock()->sxBlock.blockId;
GetCurrentBlock()->sxBlock.blockId = m_nextBlockId++;
this->m_parenDepth++;
pnode = ParseExpr<buildAST>(koplNo, &fCanAssign, TRUE, FALSE, nullptr, nullptr /*nameLength*/, nullptr /*pShortNameOffset*/, &term, true, nullptr, plastRParen);
this->m_parenDepth--;
if (buildAST && plastRParen)
{
*plastRParen = m_pscan->IchLimTok();
}
ChkCurTok(tkRParen, ERRnoRparen);
GetCurrentBlock()->sxBlock.blockId = saveCurrBlockId;
if (m_token.tk == tkDArrow)
{
// We're going to rewind and reinterpret the expression as a parameter list.
// Put back the original next-block-ID so the existing pid ref stacks will be correct.
m_nextBlockId = saveNextBlockId;
}
// Emit a deferred ... error if one was parsed.
if (m_deferEllipsisError && m_token.tk != tkDArrow)
{
m_pscan->SeekTo(m_EllipsisErrLoc);
Error(ERRInvalidSpreadUse);
}
else
{
m_deferEllipsisError = false;
}
break;
}
case tkIntCon:
if (IsStrictMode() && m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
if (buildAST)
{
pnode = CreateIntNodeWithScanner(m_token.GetLong());
}
fCanAssign = FALSE;
m_pscan->Scan();
break;
case tkFltCon:
if (IsStrictMode() && m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
if (buildAST)
{
pnode = CreateNodeWithScanner<knopFlt>();
pnode->sxFlt.dbl = m_token.GetDouble();
pnode->sxFlt.maybeInt = m_token.GetDoubleMayBeInt();
}
fCanAssign = FALSE;
m_pscan->Scan();
break;
case tkStrCon:
if (IsStrictMode() && m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
if (buildAST)
{
pnode = CreateStrNodeWithScanner(m_token.GetStr());
}
else
{
// Subtract the string literal length from the total char count for the purpose
// of deciding whether to defer parsing and byte code generation.
this->ReduceDeferredScriptLength(m_pscan->IchLimTok() - m_pscan->IchMinTok());
}
fCanAssign = FALSE;
m_pscan->Scan();
break;
case tkTRUE:
if (buildAST)
{
pnode = CreateNodeWithScanner<knopTrue>();
}
fCanAssign = FALSE;
m_pscan->Scan();
break;
case tkFALSE:
if (buildAST)
{
pnode = CreateNodeWithScanner<knopFalse>();
}
fCanAssign = FALSE;
m_pscan->Scan();
break;
case tkNULL:
if (buildAST)
{
pnode = CreateNodeWithScanner<knopNull>();
}
fCanAssign = FALSE;
m_pscan->Scan();
break;
case tkDiv:
case tkAsgDiv:
pnode = ParseRegExp<buildAST>();
fCanAssign = FALSE;
m_pscan->Scan();
break;
case tkNEW:
{
ichMin = m_pscan->IchMinTok();
m_pscan->Scan();
if (m_token.tk == tkDot && m_scriptContext->GetConfig()->IsES6ClassAndExtendsEnabled())
{
pnode = ParseMetaProperty<buildAST>(tkNEW, ichMin, &fCanAssign);
m_pscan->Scan();
}
else
{
ParseNodePtr pnodeExpr = ParseTerm<buildAST>(FALSE, pNameHint, pHintLength, pShortNameOffset);
if (buildAST)
{
pnode = CreateCallNode(knopNew, pnodeExpr, nullptr);
pnode->ichMin = ichMin;
}
fInNew = TRUE;
fCanAssign = FALSE;
}
break;
}
case tkLBrack:
{
ichMin = m_pscan->IchMinTok();
m_pscan->Scan();
pnode = ParseArrayLiteral<buildAST>();
if (buildAST)
{
pnode->ichMin = ichMin;
pnode->ichLim = m_pscan->IchLimTok();
}
if (this->m_arrayDepth == 0)
{
Assert(m_pscan->IchLimTok() - ichMin > m_funcInArray);
this->ReduceDeferredScriptLength(m_pscan->IchLimTok() - ichMin - this->m_funcInArray);
this->m_funcInArray = 0;
this->m_funcInArrayDepth = 0;
}
ChkCurTok(tkRBrack, ERRnoRbrack);
if (!IsES6DestructuringEnabled())
{
fCanAssign = FALSE;
}
else if (pfLikelyPattern != nullptr && !IsPostFixOperators())
{
*pfLikelyPattern = TRUE;
}
break;
}
case tkLCurly:
{
ichMin = m_pscan->IchMinTok();
m_pscan->ScanForcingPid();
ParseNodePtr pnodeMemberList = ParseMemberList<buildAST>(pNameHint, pHintLength);
if (buildAST)
{
pnode = CreateUniNode(knopObject, pnodeMemberList);
pnode->ichMin = ichMin;
pnode->ichLim = m_pscan->IchLimTok();
}
ChkCurTok(tkRCurly, ERRnoRcurly);
if (!IsES6DestructuringEnabled())
{
fCanAssign = FALSE;
}
else if (pfLikelyPattern != nullptr && !IsPostFixOperators())
{
*pfLikelyPattern = TRUE;
}
break;
}
case tkFUNCTION:
{
LFunction :
if (m_grfscr & fscrDeferredFncExpression)
{
// The top-level deferred function body was defined by a function expression whose parsing was deferred. We are now
// parsing it, so unset the flag so that any nested functions are parsed normally. This flag is only applicable the
// first time we see it.
//
// Normally, deferred functions will be parsed in ParseStatement upon encountering the 'function' token. The first
// token of the source code of the function may not a 'function' token though, so we still need to reset this flag
// for the first function we parse. This can happen in compat modes, for instance, for a function expression enclosed
// in parentheses, where the legacy behavior was to include the parentheses in the function's source code.
m_grfscr &= ~fscrDeferredFncExpression;
}
ushort flags = fFncNoFlgs;
if (isLambdaExpr)
{
flags |= fFncLambda;
}
if (isAsyncExpr)
{
flags |= fFncAsync;
}
pnode = ParseFncDecl<buildAST>(flags, pNameHint, false, true, fUnaryOrParen);
if (isAsyncExpr)
{
pnode->sxFnc.cbMin = iecpMin;
pnode->ichMin = ichMin;
}
fCanAssign = FALSE;
break;
}
case tkCLASS:
if (m_scriptContext->GetConfig()->IsES6ClassAndExtendsEnabled())
{
pnode = ParseClassDecl<buildAST>(FALSE, pNameHint, pHintLength, pShortNameOffset);
}
else
{
goto LUnknown;
}
fCanAssign = FALSE;
break;
case tkStrTmplBasic:
case tkStrTmplBegin:
pnode = ParseStringTemplateDecl<buildAST>(nullptr);
fCanAssign = FALSE;
break;
case tkSUPER:
if (m_scriptContext->GetConfig()->IsES6ClassAndExtendsEnabled())
{
pnode = ParseSuper<buildAST>(pnode, !!fAllowCall);
}
else
{
goto LUnknown;
}
break;
case tkCASE:
{
if (!m_doingFastScan)
{
goto LUnknown;
}
ParseNodePtr pnodeUnused;
pnode = ParseCase<buildAST>(&pnodeUnused);
break;
}
case tkELSE:
if (!m_doingFastScan)
{
goto LUnknown;
}
m_pscan->Scan();
ParseStatement<buildAST>();
break;
default:
LUnknown :
Error(ERRsyntax);
break;
}
pnode = ParsePostfixOperators<buildAST>(pnode, fAllowCall, fInNew, isAsyncExpr, &fCanAssign, &term, pfIsDotOrIndex);
if (savedTopAsyncRef != nullptr &&
this->m_token.tk == tkDArrow)
{
// This is an async arrow function; we're going to back up and reparse it.
// Make sure we don't leave behind a bogus reference to the 'async' identifier.
for (IdentPtr pid = wellKnownPropertyPids.async; pid->GetTopRef() != savedTopAsyncRef;)
{
Assert(pid->GetTopRef() != nullptr);
pid->RemovePrevPidRef(nullptr);
}
}
// Pass back identifier if requested
if (pToken && term.tk == tkID)
{
*pToken = term;
}
if (pfCanAssign)
{
*pfCanAssign = fCanAssign;
}
return pnode;
}
|
CWE-119
| null | 517,605 |
211994494161440665520626017502737097979
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateDummyFuncNode(bool fDeclaration)
{
// Create a dummy node and make it look like the current function declaration.
// Do this in situations where we want to parse statements without impacting
// the state of the "real" AST.
ParseNodePtr pnodeFnc = CreateNode(knopFncDecl);
pnodeFnc->sxFnc.ClearFlags();
pnodeFnc->sxFnc.SetDeclaration(fDeclaration);
pnodeFnc->sxFnc.astSize = 0;
pnodeFnc->sxFnc.pnodeName = nullptr;
pnodeFnc->sxFnc.pnodeScopes = nullptr;
pnodeFnc->sxFnc.pnodeRest = nullptr;
pnodeFnc->sxFnc.pid = nullptr;
pnodeFnc->sxFnc.hint = nullptr;
pnodeFnc->sxFnc.hintOffset = 0;
pnodeFnc->sxFnc.hintLength = 0;
pnodeFnc->sxFnc.isNameIdentifierRef = true;
pnodeFnc->sxFnc.nestedFuncEscapes = false;
pnodeFnc->sxFnc.pnodeNext = nullptr;
pnodeFnc->sxFnc.pnodeParams = nullptr;
pnodeFnc->sxFnc.pnodeVars = nullptr;
pnodeFnc->sxFnc.funcInfo = nullptr;
pnodeFnc->sxFnc.deferredStub = nullptr;
pnodeFnc->sxFnc.nestedCount = 0;
pnodeFnc->sxFnc.SetNested(m_currentNodeFunc != nullptr); // If there is a current function, then we're a nested function.
pnodeFnc->sxFnc.SetStrictMode(IsStrictMode()); // Inherit current strict mode -- may be overridden by the function itself if it contains a strict mode directive.
pnodeFnc->sxFnc.firstDefaultArg = 0;
m_pCurrentAstSize = &pnodeFnc->sxFnc.astSize;
m_currentNodeFunc = pnodeFnc;
m_pnestedCount = &pnodeFnc->sxFnc.nestedCount;
return pnodeFnc;
}
|
CWE-119
| null | 517,606 |
283647463457479112703138811914580407811
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::CheckStrictModeEvalArgumentsUsage(IdentPtr pid, ParseNodePtr pnode)
{
if (pid != nullptr)
{
// In strict mode, 'eval' / 'arguments' cannot be assigned to.
if ( pid == wellKnownPropertyPids.eval)
{
Error(ERREvalUsage, pnode);
}
if (pid == wellKnownPropertyPids.arguments)
{
Error(ERRArgsUsage, pnode);
}
}
}
|
CWE-119
| null | 517,607 |
181559295891358404059605935416979143489
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseStringTemplateDecl(ParseNodePtr pnodeTagFnc)
{
ParseNodePtr pnodeStringLiterals = nullptr;
ParseNodePtr* lastStringLiteralNodeRef = nullptr;
ParseNodePtr pnodeRawStringLiterals = nullptr;
ParseNodePtr* lastRawStringLiteralNodeRef = nullptr;
ParseNodePtr pnodeSubstitutionExpressions = nullptr;
ParseNodePtr* lastSubstitutionExpressionNodeRef = nullptr;
ParseNodePtr pnodeTagFncArgs = nullptr;
ParseNodePtr* lastTagFncArgNodeRef = nullptr;
ParseNodePtr stringLiteral = nullptr;
ParseNodePtr stringLiteralRaw = nullptr;
ParseNodePtr pnodeStringTemplate = nullptr;
bool templateClosed = false;
const bool isTagged = pnodeTagFnc != nullptr;
uint16 stringConstantCount = 0;
charcount_t ichMin = 0;
Assert(m_token.tk == tkStrTmplBasic || m_token.tk == tkStrTmplBegin);
if (buildAST)
{
pnodeStringTemplate = CreateNode(knopStrTemplate);
pnodeStringTemplate->sxStrTemplate.countStringLiterals = 0;
pnodeStringTemplate->sxStrTemplate.isTaggedTemplate = isTagged ? TRUE : FALSE;
// If this is a tagged string template, we need to start building the arg list for the call
if (isTagged)
{
ichMin = pnodeTagFnc->ichMin;
AddToNodeListEscapedUse(&pnodeTagFncArgs, &lastTagFncArgNodeRef, pnodeStringTemplate);
}
}
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(StringTemplates, m_scriptContext);
OUTPUT_TRACE_DEBUGONLY(
Js::StringTemplateParsePhase,
_u("Starting to parse a string template (%s)...\n\tis tagged = %s\n"),
GetParseType(),
isTagged ? _u("true") : _u("false (Raw and cooked strings will not differ!)"));
// String template grammar
// `...` Simple string template
// `...${ String template beginning
// }...${ String template middle
// }...` String template end
while (!templateClosed)
{
// First, extract the string constant part - we always have one
if (IsStrictMode() && m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
// We are not able to pass more than a ushort worth of arguments to the tag
// so use that as a logical limit on the number of string constant pieces.
if (stringConstantCount >= USHRT_MAX)
{
Error(ERRnoMemory);
}
// Keep track of the string literal count (must be the same for raw strings)
// We use this in code gen so we don't need to count the string literals list
stringConstantCount++;
// If we are not creating parse nodes, there is no need to create strings
if (buildAST)
{
stringLiteral = CreateStrNodeWithScanner(m_token.GetStr());
AddToNodeList(&pnodeStringLiterals, &lastStringLiteralNodeRef, stringLiteral);
// We only need to collect a raw string when we are going to pass the string template to a tag
if (isTagged)
{
// Make the scanner create a PID for the raw string constant for the preceding scan
IdentPtr pid = m_pscan->GetSecondaryBufferAsPid();
stringLiteralRaw = CreateStrNodeWithScanner(pid);
// Should have gotten a raw string literal above
AddToNodeList(&pnodeRawStringLiterals, &lastRawStringLiteralNodeRef, stringLiteralRaw);
}
else
{
#if DBG
// Assign the raw string for debug tracing below
stringLiteralRaw = stringLiteral;
#endif
}
OUTPUT_TRACE_DEBUGONLY(
Js::StringTemplateParsePhase,
_u("Parsed string constant: \n\tcooked = \"%s\" \n\traw = \"%s\" \n\tdiffer = %d\n"),
stringLiteral->sxPid.pid->Psz(),
stringLiteralRaw->sxPid.pid->Psz(),
stringLiteral->sxPid.pid->Psz() == stringLiteralRaw->sxPid.pid->Psz() ? 0 : 1);
}
switch (m_token.tk)
{
case tkStrTmplEnd:
case tkStrTmplBasic:
// We do not need to parse an expression for either the end or basic string template tokens
templateClosed = true;
break;
case tkStrTmplBegin:
case tkStrTmplMid:
{
// In the middle or begin string template token case, we need to parse an expression next
m_pscan->Scan();
// Parse the contents of the curly braces as an expression
ParseNodePtr expression = ParseExpr<buildAST>(0);
// After parsing expression, scan should leave us with an RCurly token.
// Use the NoScan version so we do not automatically perform a scan - we need to
// set the scan state before next scan but we don't want to set that state if
// the token is not as expected since we'll error in that case.
ChkCurTokNoScan(tkRCurly, ERRnoRcurly);
// Notify the scanner that it should scan for a middle or end string template token
m_pscan->SetScanState(Scanner_t::ScanState::ScanStateStringTemplateMiddleOrEnd);
m_pscan->Scan();
if (buildAST)
{
// If we are going to call the tag function, add this expression into the list of args
if (isTagged)
{
AddToNodeListEscapedUse(&pnodeTagFncArgs, &lastTagFncArgNodeRef, expression);
}
else
{
// Otherwise add it to the substitution expression list
// TODO: Store the arguments and substitution expressions in a single list?
AddToNodeList(&pnodeSubstitutionExpressions, &lastSubstitutionExpressionNodeRef, expression);
}
}
if (!(m_token.tk == tkStrTmplMid || m_token.tk == tkStrTmplEnd))
{
// Scan with ScanState ScanStateStringTemplateMiddleOrEnd should only return
// tkStrTmpMid/End unless it is EOF or tkScanError
Assert(m_token.tk == tkEOF || m_token.tk == tkScanError);
Error(ERRsyntax);
}
OUTPUT_TRACE_DEBUGONLY(Js::StringTemplateParsePhase, _u("Parsed expression\n"));
}
break;
default:
Assert(false);
break;
}
}
if (buildAST)
{
pnodeStringTemplate->sxStrTemplate.pnodeStringLiterals = pnodeStringLiterals;
pnodeStringTemplate->sxStrTemplate.pnodeStringRawLiterals = pnodeRawStringLiterals;
pnodeStringTemplate->sxStrTemplate.pnodeSubstitutionExpressions = pnodeSubstitutionExpressions;
pnodeStringTemplate->sxStrTemplate.countStringLiterals = stringConstantCount;
// We should still have the last string literal.
// Use the char offset of the end of that constant as the end of the string template.
pnodeStringTemplate->ichLim = stringLiteral->ichLim;
// If this is a tagged template, we now have the argument list and can construct a call node
if (isTagged)
{
// Return the call node here and let the byte code generator Emit the string template automagically
pnodeStringTemplate = CreateCallNode(knopCall, pnodeTagFnc, pnodeTagFncArgs, ichMin, pnodeStringTemplate->ichLim);
// We need to set the arg count explicitly
pnodeStringTemplate->sxCall.argCount = stringConstantCount;
}
}
m_pscan->Scan();
return pnodeStringTemplate;
}
|
CWE-119
| null | 517,608 |
49032619246867887105807222546230619474
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::BindPidRefs(BlockInfoStack *blockInfo, uint maxBlockId)
{
// We need to bind all assignments in order to emit assignment to 'const' error
int blockId = blockInfo->pnodeBlock->sxBlock.blockId;
Scope *scope = blockInfo->pnodeBlock->sxBlock.scope;
if (scope)
{
auto bindPidRefs = [blockId, maxBlockId, this](Symbol *sym)
{
ParseNodePtr pnode = sym->GetDecl();
IdentPtr pid;
#if PROFILE_DICTIONARY
int depth = 0;
#endif
Assert(pnode);
switch (pnode->nop)
{
case knopVarDecl:
case knopLetDecl:
case knopConstDecl:
pid = pnode->sxVar.pid;
if (backgroundPidRef)
{
pid = this->m_pscan->m_phtbl->FindExistingPid(pid->Psz(), pid->Psz() + pid->Cch(), pid->Cch(), pid->Hash(), nullptr, nullptr
#if PROFILE_DICTIONARY
, depth
#endif
);
if (pid == nullptr)
{
break;
}
}
this->BindPidRefsInScope(pid, sym, blockId, maxBlockId);
break;
case knopName:
pid = pnode->sxPid.pid;
if (backgroundPidRef)
{
pid = this->m_pscan->m_phtbl->FindExistingPid(pid->Psz(), pid->Psz() + pid->Cch(), pid->Cch(), pid->Hash(), nullptr, nullptr
#if PROFILE_DICTIONARY
, depth
#endif
);
if (pid == nullptr)
{
break;
}
}
this->BindPidRefsInScope(pid, sym, blockId, maxBlockId);
break;
default:
Assert(0);
break;
}
};
scope->ForEachSymbol(bindPidRefs);
}
}
|
CWE-119
| null | 517,609 |
105768909588175859915619212732131659353
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseMemberList(LPCOLESTR pNameHint, uint32* pNameHintLength, tokens declarationType)
{
ParseNodePtr pnodeArg = nullptr;
ParseNodePtr pnodeName = nullptr;
ParseNodePtr pnodeList = nullptr;
ParseNodePtr *lastNodeRef = nullptr;
LPCOLESTR pFullNameHint = nullptr; // A calculated full name
uint32 fullNameHintLength = pNameHintLength ? *pNameHintLength : 0;
uint32 shortNameOffset = 0;
bool isProtoDeclared = false;
// we get declaration tkLCurly - when the possible object pattern found under the expression.
bool isObjectPattern = (declarationType == tkVAR || declarationType == tkLET || declarationType == tkCONST || declarationType == tkLCurly) && IsES6DestructuringEnabled();
// Check for an empty list
if (tkRCurly == m_token.tk)
{
return nullptr;
}
ArenaAllocator tempAllocator(_u("MemberNames"), m_nodeAllocator.GetPageAllocator(), Parser::OutOfMemory);
bool hasDeferredInitError = false;
for (;;)
{
bool isComputedName = false;
#if DEBUG
if((m_grfscr & fscrEnforceJSON) && (tkStrCon != m_token.tk || !(m_pscan->IsDoubleQuoteOnLastTkStrCon())))
{
Error(ERRsyntax);
}
#endif
bool isAsyncMethod = false;
charcount_t ichMin = 0;
size_t iecpMin = 0;
if (m_token.tk == tkID && m_token.GetIdentifier(m_phtbl) == wellKnownPropertyPids.async && m_scriptContext->GetConfig()->IsES7AsyncAndAwaitEnabled())
{
RestorePoint parsedAsync;
m_pscan->Capture(&parsedAsync);
ichMin = m_pscan->IchMinTok();
iecpMin = m_pscan->IecpMinTok();
m_pscan->ScanForcingPid();
if (m_token.tk == tkLParen || m_token.tk == tkColon || m_token.tk == tkRCurly || m_pscan->FHadNewLine())
{
m_pscan->SeekTo(parsedAsync);
}
else
{
isAsyncMethod = true;
}
}
bool isGenerator = m_scriptContext->GetConfig()->IsES6GeneratorsEnabled() &&
m_token.tk == tkStar;
ushort fncDeclFlags = fFncNoName | fFncMethod;
if (isGenerator)
{
if (isAsyncMethod)
{
Error(ERRsyntax);
}
m_pscan->ScanForcingPid();
fncDeclFlags |= fFncGenerator;
}
IdentPtr pidHint = nullptr; // A name scoped to current expression
Token tkHint = m_token;
charcount_t idHintIchMin = static_cast<charcount_t>(m_pscan->IecpMinTok());
charcount_t idHintIchLim = static_cast< charcount_t >(m_pscan->IecpLimTok());
bool wrapInBrackets = false;
switch (m_token.tk)
{
default:
if (!m_token.IsReservedWord())
{
Error(ERRnoMemberIdent);
}
// allow reserved words
wrapInBrackets = true;
// fall-through
case tkID:
pidHint = m_token.GetIdentifier(m_phtbl);
if (buildAST)
{
pnodeName = CreateStrNodeWithScanner(pidHint);
}
break;
case tkStrCon:
if (IsStrictMode() && m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
wrapInBrackets = true;
pidHint = m_token.GetStr();
if (buildAST)
{
pnodeName = CreateStrNodeWithScanner(pidHint);
}
break;
case tkIntCon:
// Object initializers with numeric labels allowed in JS6
if (IsStrictMode() && m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
pidHint = m_pscan->PidFromLong(m_token.GetLong());
if (buildAST)
{
pnodeName = CreateStrNodeWithScanner(pidHint);
}
break;
case tkFltCon:
if (IsStrictMode() && m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
pidHint = m_pscan->PidFromDbl(m_token.GetDouble());
if (buildAST)
{
pnodeName = CreateStrNodeWithScanner(pidHint);
}
wrapInBrackets = true;
break;
case tkLBrack:
// Computed property name: [expr] : value
if (!m_scriptContext->GetConfig()->IsES6ObjectLiteralsEnabled())
{
Error(ERRnoMemberIdent);
}
ParseComputedName<buildAST>(&pnodeName, &pNameHint, &pFullNameHint, &fullNameHintLength, &shortNameOffset);
isComputedName = true;
break;
}
if (pFullNameHint == nullptr)
{
if (CONFIG_FLAG(UseFullName))
{
pFullNameHint = AppendNameHints(pNameHint, pidHint, &fullNameHintLength, &shortNameOffset, false, wrapInBrackets);
}
else
{
pFullNameHint = pidHint? pidHint->Psz() : nullptr;
fullNameHintLength = pidHint ? pidHint->Cch() : 0;
shortNameOffset = 0;
}
}
RestorePoint atPid;
m_pscan->Capture(&atPid);
m_pscan->ScanForcingPid();
if (isGenerator && m_token.tk != tkLParen)
{
Error(ERRnoLparen);
}
if (tkColon == m_token.tk)
{
// It is a syntax error is the production of the form __proto__ : <> occurs more than once. From B.3.1 in spec.
// Note that previous scan is important because only after that we can determine we have a variable.
if (!isComputedName && pidHint == wellKnownPropertyPids.__proto__)
{
if (isProtoDeclared)
{
Error(ERRsyntax);
}
else
{
isProtoDeclared = true;
}
}
m_pscan->Scan();
ParseNodePtr pnodeExpr = nullptr;
if (isObjectPattern)
{
if (m_token.tk == tkEllipsis)
{
Error(ERRUnexpectedEllipsis);
}
pnodeExpr = ParseDestructuredVarDecl<buildAST>(declarationType, declarationType != tkLCurly, nullptr/* *hasSeenRest*/, false /*topLevel*/, false /*allowEmptyExpression*/);
if (m_token.tk != tkComma && m_token.tk != tkRCurly)
{
if (m_token.IsOperator())
{
Error(ERRDestructNoOper);
}
Error(ERRsyntax);
}
}
else
{
pnodeExpr = ParseExpr<buildAST>(koplCma, nullptr, TRUE, FALSE, pFullNameHint, &fullNameHintLength, &shortNameOffset);
}
#if DEBUG
if((m_grfscr & fscrEnforceJSON) && !IsJSONValid(pnodeExpr))
{
Error(ERRsyntax);
}
#endif
if (buildAST)
{
pnodeArg = CreateBinNode(isObjectPattern ? knopObjectPatternMember : knopMember, pnodeName, pnodeExpr);
if (pnodeArg->sxBin.pnode1->nop == knopStr)
{
pnodeArg->sxBin.pnode1->sxPid.pid->PromoteAssignmentState();
}
}
}
else if (m_token.tk == tkLParen && m_scriptContext->GetConfig()->IsES6ObjectLiteralsEnabled())
{
if (isObjectPattern)
{
Error(ERRInvalidAssignmentTarget);
}
// Shorthand syntax: foo() {} -> foo: function() {}
// Rewind to the PID and parse a function expression.
m_pscan->SeekTo(atPid);
this->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
ParseNodePtr pnodeFunc = ParseFncDecl<buildAST>(fncDeclFlags | (isAsyncMethod ? fFncAsync : fFncNoFlgs), pFullNameHint,
/*needsPIDOnRCurlyScan*/ false, /*resetParsingSuperRestrictionState*/ false);
if (isAsyncMethod)
{
pnodeFunc->sxFnc.cbMin = iecpMin;
pnodeFunc->ichMin = ichMin;
}
if (buildAST)
{
pnodeArg = CreateBinNode(knopMember, pnodeName, pnodeFunc);
}
}
else if (nullptr != pidHint) //Its either tkID/tkStrCon/tkFloatCon/tkIntCon
{
Assert(pidHint->Psz() != nullptr);
if ((pidHint == wellKnownPropertyPids.get || pidHint == wellKnownPropertyPids.set) &&
// get/set are only pseudo keywords when they are identifiers (i.e. not strings)
tkHint.tk == tkID && NextTokenIsPropertyNameStart())
{
if (isObjectPattern)
{
Error(ERRInvalidAssignmentTarget);
}
LPCOLESTR pNameGetOrSet = nullptr;
OpCode op = pidHint == wellKnownPropertyPids.get ? knopGetMember : knopSetMember;
pnodeArg = ParseMemberGetSet<buildAST>(op, &pNameGetOrSet);
if (CONFIG_FLAG(UseFullName) && buildAST && pnodeArg->sxBin.pnode2->nop == knopFncDecl)
{
if (m_scriptContext->GetConfig()->IsES6FunctionNameEnabled())
{
// displays as "get object.funcname" or "set object.funcname"
uint32 getOrSetOffset = 0;
LPCOLESTR intermediateHint = AppendNameHints(pNameHint, pNameGetOrSet, &fullNameHintLength, &shortNameOffset);
pFullNameHint = AppendNameHints(pidHint, intermediateHint, &fullNameHintLength, &getOrSetOffset, true);
shortNameOffset += getOrSetOffset;
}
else
{
// displays as "object.funcname.get" or "object.funcname.set"
LPCOLESTR intermediateHint = AppendNameHints(pNameGetOrSet, pidHint, &fullNameHintLength, &shortNameOffset);
pFullNameHint = AppendNameHints(pNameHint, intermediateHint, &fullNameHintLength, &shortNameOffset);
}
}
}
else if ((m_token.tk == tkRCurly || m_token.tk == tkComma || m_token.tk == tkAsg) && m_scriptContext->GetConfig()->IsES6ObjectLiteralsEnabled())
{
// Shorthand {foo} -> {foo:foo} syntax.
// {foo = <initializer>} supported only when on object pattern rules are being applied
if (tkHint.tk != tkID)
{
Assert(tkHint.IsReservedWord()
|| tkHint.tk == tkIntCon || tkHint.tk == tkFltCon || tkHint.tk == tkStrCon);
// All keywords are banned in non-strict mode.
// Future reserved words are banned in strict mode.
if (IsStrictMode() || !tkHint.IsFutureReservedWord(true))
{
IdentifierExpectedError(tkHint);
}
}
if (buildAST)
{
CheckArgumentsUse(pidHint, GetCurrentFunctionNode());
}
bool couldBeObjectPattern = !isObjectPattern && m_token.tk == tkAsg;
if (couldBeObjectPattern)
{
declarationType = tkLCurly;
isObjectPattern = true;
// This may be an error but we are deferring for favouring destructuring.
hasDeferredInitError = true;
}
ParseNodePtr pnodeIdent = nullptr;
if (isObjectPattern)
{
m_pscan->SeekTo(atPid);
pnodeIdent = ParseDestructuredVarDecl<buildAST>(declarationType, declarationType != tkLCurly, nullptr/* *hasSeenRest*/, false /*topLevel*/, false /*allowEmptyExpression*/);
if (m_token.tk != tkComma && m_token.tk != tkRCurly)
{
if (m_token.IsOperator())
{
Error(ERRDestructNoOper);
}
Error(ERRsyntax);
}
}
else
{
// Add a reference to the hinted name so we can bind it properly.
PidRefStack *ref = PushPidRef(pidHint);
if (buildAST)
{
pnodeIdent = CreateNameNode(pidHint, idHintIchMin, idHintIchLim);
pnodeIdent->sxPid.SetSymRef(ref);
}
}
if (buildAST)
{
pnodeArg = CreateBinNode(isObjectPattern && !couldBeObjectPattern ? knopObjectPatternMember : knopMemberShort, pnodeName, pnodeIdent);
}
}
else
{
Error(ERRnoColon);
}
}
else
{
Error(ERRnoColon);
}
if (buildAST)
{
Assert(pnodeArg->sxBin.pnode2 != nullptr);
if (pnodeArg->sxBin.pnode2->nop == knopFncDecl)
{
Assert(fullNameHintLength >= shortNameOffset);
pnodeArg->sxBin.pnode2->sxFnc.hint = pFullNameHint;
pnodeArg->sxBin.pnode2->sxFnc.hintLength = fullNameHintLength;
pnodeArg->sxBin.pnode2->sxFnc.hintOffset = shortNameOffset;
}
AddToNodeListEscapedUse(&pnodeList, &lastNodeRef, pnodeArg);
}
pidHint = nullptr;
pFullNameHint = nullptr;
if (tkComma != m_token.tk)
{
break;
}
m_pscan->ScanForcingPid();
if (tkRCurly == m_token.tk)
{
break;
}
}
m_hasDeferredShorthandInitError = m_hasDeferredShorthandInitError || hasDeferredInitError;
if (buildAST)
{
AssertMem(lastNodeRef);
AssertNodeMem(*lastNodeRef);
pnodeList->ichLim = (*lastNodeRef)->ichLim;
}
return pnodeList;
}
|
CWE-119
| null | 517,610 |
99579041162303795304111195428843857492
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::ParseNamedImportOrExportClause(ModuleImportOrExportEntryList* importOrExportEntryList, bool isExportClause)
{
Assert(m_token.tk == tkLCurly);
Assert(importOrExportEntryList != nullptr);
m_pscan->Scan();
while (m_token.tk != tkRCurly && m_token.tk != tkEOF)
{
tokens firstToken = m_token.tk;
if (!(m_token.IsIdentifier() || m_token.IsReservedWord()))
{
Error(ERRsyntax);
}
IdentPtr identifierName = m_token.GetIdentifier(m_phtbl);
IdentPtr identifierAs = identifierName;
m_pscan->Scan();
if (m_token.tk == tkID)
{
// We have the pattern "IdentifierName as"
if (wellKnownPropertyPids.as != m_token.GetIdentifier(m_phtbl))
{
Error(ERRsyntax);
}
m_pscan->Scan();
// If we are parsing an import statement, the token after 'as' must be a BindingIdentifier.
if (!isExportClause)
{
ChkCurTokNoScan(tkID, ERRsyntax);
}
if (!(m_token.IsIdentifier() || m_token.IsReservedWord()))
{
Error(ERRsyntax);
}
identifierAs = m_token.GetIdentifier(m_phtbl);
// Scan to the next token.
m_pscan->Scan();
}
else if (!isExportClause && firstToken != tkID)
{
// If we are parsing an import statement and this ImportSpecifier clause did not have
// 'as ImportedBinding' at the end of it, identifierName must be a BindingIdentifier.
Error(ERRsyntax);
}
if (m_token.tk == tkComma)
{
// Consume a trailing comma
m_pscan->Scan();
}
if (buildAST)
{
// The name we will use 'as' this import/export is a binding identifier in import statements.
if (!isExportClause)
{
CreateModuleImportDeclNode(identifierAs);
AddModuleImportOrExportEntry(importOrExportEntryList, identifierName, identifierAs, nullptr, nullptr);
}
else
{
identifierName->SetIsModuleExport();
AddModuleImportOrExportEntry(importOrExportEntryList, nullptr, identifierName, identifierAs, nullptr);
}
}
}
// Final token in a named import or export clause must be a '}'
ChkCurTokNoScan(tkRCurly, ERRsyntax);
}
|
CWE-119
| null | 517,611 |
323502798981651368958278674987245140458
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseArrayLiteral()
{
ParseNodePtr pnode = nullptr;
bool arrayOfTaggedInts = false;
bool arrayOfInts = false;
bool arrayOfNumbers = false;
bool hasMissingValues = false;
uint count = 0;
uint spreadCount = 0;
ParseNodePtr pnode1 = ParseArrayList<buildAST>(&arrayOfTaggedInts, &arrayOfInts, &arrayOfNumbers, &hasMissingValues, &count, &spreadCount);
if (buildAST)
{
pnode = CreateNodeWithScanner<knopArray>();
pnode->sxArrLit.pnode1 = pnode1;
pnode->sxArrLit.arrayOfTaggedInts = arrayOfTaggedInts;
pnode->sxArrLit.arrayOfInts = arrayOfInts;
pnode->sxArrLit.arrayOfNumbers = arrayOfNumbers;
pnode->sxArrLit.hasMissingValues = hasMissingValues;
pnode->sxArrLit.count = count;
pnode->sxArrLit.spreadCount = spreadCount;
if (pnode->sxArrLit.pnode1)
{
this->CheckArguments(pnode->sxArrLit.pnode1);
}
}
return pnode;
}
|
CWE-119
| null | 517,612 |
262827147776858618685882101041635795969
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
Symbol* Parser::AddDeclForPid(ParseNodePtr pnode, IdentPtr pid, SymbolType symbolType, bool errorOnRedecl, bool *isRedecl)
{
Assert(pnode->IsVarLetOrConst());
PidRefStack *refForUse = nullptr, *refForDecl = nullptr;
if (isRedecl)
{
*isRedecl = false;
}
BlockInfoStack *blockInfo;
bool fBlockScope = false;
if (pnode->nop != knopVarDecl || symbolType == STFunction)
{
Assert(m_pstmtCur);
if (m_pstmtCur->GetNop() != knopBlock)
{
// Let/const declared in a bare statement context.
Error(ERRDeclOutOfStmt);
}
if (m_pstmtCur->pstmtOuter && m_pstmtCur->pstmtOuter->GetNop() == knopSwitch)
{
// Let/const declared inside a switch block (requiring conservative use-before-decl check).
pnode->sxVar.isSwitchStmtDecl = true;
}
fBlockScope = pnode->nop != knopVarDecl ||
(
!GetCurrentBlockInfo()->pnodeBlock->sxBlock.scope ||
GetCurrentBlockInfo()->pnodeBlock->sxBlock.scope->GetScopeType() != ScopeType_GlobalEvalBlock
);
}
if (fBlockScope)
{
blockInfo = GetCurrentBlockInfo();
}
else
{
blockInfo = GetCurrentFunctionBlockInfo();
}
// If we are creating an 'arguments' Sym at function block scope, create it in
// the parameter scope instead. That way, if we need to reuse the Sym for the
// actual arguments object at the end of the function, we don't need to move it
// into the parameter scope.
if (pid == wellKnownPropertyPids.arguments
&& pnode->nop == knopVarDecl
&& blockInfo->pnodeBlock->sxBlock.blockType == PnodeBlockType::Function
&& blockInfo->pBlockInfoOuter != nullptr
&& blockInfo->pBlockInfoOuter->pnodeBlock->sxBlock.blockType == PnodeBlockType::Parameter
&& blockInfo->pnodeBlock->sxBlock.scope->GetScopeType() != ScopeType_FuncExpr
&& blockInfo->pBlockInfoOuter->pnodeBlock->sxBlock.scope->GetCanMergeWithBodyScope())
{
blockInfo = blockInfo->pBlockInfoOuter;
}
refForDecl = this->FindOrAddPidRef(pid, blockInfo->pnodeBlock->sxBlock.blockId, GetCurrentFunctionNode()->sxFnc.functionId);
if (refForDecl == nullptr)
{
Error(ERRnoMemory);
}
if (refForDecl->funcId != GetCurrentFunctionNode()->sxFnc.functionId)
{
// Fix up the function id, which is incorrect if we're reparsing lambda parameters
Assert(this->m_reparsingLambdaParams);
refForDecl->funcId = GetCurrentFunctionNode()->sxFnc.functionId;
}
if (blockInfo == GetCurrentBlockInfo())
{
refForUse = refForDecl;
}
else
{
refForUse = this->PushPidRef(pid);
}
pnode->sxVar.symRef = refForUse->GetSymRef();
Symbol *sym = refForDecl->GetSym();
if (sym != nullptr)
{
if (isRedecl)
{
*isRedecl = true;
}
// Multiple declarations in the same scope. 3 possibilities: error, existing one wins, new one wins.
switch (pnode->nop)
{
case knopLetDecl:
case knopConstDecl:
if (!sym->GetDecl()->sxVar.isBlockScopeFncDeclVar)
{
Assert(errorOnRedecl);
// Redeclaration error.
Error(ERRRedeclaration);
}
else
{
// (New) let/const hides the (old) var
sym->SetSymbolType(symbolType);
sym->SetDecl(pnode);
}
break;
case knopVarDecl:
if (m_currentScope->GetScopeType() == ScopeType_Parameter)
{
// If this is a parameter list, mark the scope to indicate that it has duplicate definition.
// If later this turns out to be a non-simple param list (like function f(a, a, c = 1) {}) then it is a SyntaxError to have duplicate formals.
m_currentScope->SetHasDuplicateFormals();
}
if (sym->GetDecl() == nullptr)
{
Assert(symbolType == STFunction);
sym->SetDecl(pnode);
break;
}
switch (sym->GetDecl()->nop)
{
case knopLetDecl:
case knopConstDecl:
// Destructuring made possible to have the formals to be the let bind. But that shouldn't throw the error.
if (errorOnRedecl && (!IsES6DestructuringEnabled() || sym->GetSymbolType() != STFormal))
{
Error(ERRRedeclaration);
}
// If !errorOnRedecl, (old) let/const hides the (new) var, so do nothing.
break;
case knopVarDecl:
// Legal redeclaration. Who wins?
if (errorOnRedecl || sym->GetDecl()->sxVar.isBlockScopeFncDeclVar)
{
if (symbolType == STFormal ||
(symbolType == STFunction && sym->GetSymbolType() != STFormal) ||
sym->GetSymbolType() == STVariable)
{
// New decl wins.
sym->SetSymbolType(symbolType);
sym->SetDecl(pnode);
}
}
break;
}
break;
}
}
else
{
Scope *scope = blockInfo->pnodeBlock->sxBlock.scope;
if (scope == nullptr)
{
Assert(blockInfo->pnodeBlock->sxBlock.blockType == PnodeBlockType::Regular);
scope = Anew(&m_nodeAllocator, Scope, &m_nodeAllocator, ScopeType_Block);
if (this->IsCurBlockInLoop())
{
scope->SetIsBlockInLoop();
}
blockInfo->pnodeBlock->sxBlock.scope = scope;
PushScope(scope);
}
if (scope->GetScopeType() == ScopeType_GlobalEvalBlock)
{
Assert(fBlockScope);
Assert(scope->GetEnclosingScope() == m_currentNodeProg->sxProg.scope);
// Check for same-named decl in Global scope.
PidRefStack *pidRefOld = pid->GetPidRefForScopeId(0);
if (pidRefOld && pidRefOld->GetSym())
{
Error(ERRRedeclaration);
}
}
else if (scope->GetScopeType() == ScopeType_Global && (this->m_grfscr & fscrEvalCode) &&
!(m_functionBody && m_functionBody->GetScopeInfo()))
{
// Check for same-named decl in GlobalEvalBlock scope. Note that this is not necessary
// if we're compiling a deferred nested function and the global scope was restored from cached info,
// because in that case we don't need a GlobalEvalScope.
Assert(!fBlockScope || (this->m_grfscr & fscrConsoleScopeEval) == fscrConsoleScopeEval);
PidRefStack *pidRefOld = pid->GetPidRefForScopeId(1);
if (pidRefOld && pidRefOld->GetSym())
{
Error(ERRRedeclaration);
}
}
if ((scope->GetScopeType() == ScopeType_FunctionBody || scope->GetScopeType() == ScopeType_Parameter) && symbolType != STFunction)
{
ParseNodePtr pnodeFnc = GetCurrentFunctionNode();
AnalysisAssert(pnodeFnc);
if (pnodeFnc->sxFnc.pnodeName &&
pnodeFnc->sxFnc.pnodeName->nop == knopVarDecl &&
pnodeFnc->sxFnc.pnodeName->sxVar.pid == pid)
{
// Named function expression has its name hidden by a local declaration.
// This is important to know if we don't know whether nested deferred functions refer to it,
// because if the name has a non-local reference then we have to create a scope object.
m_currentNodeFunc->sxFnc.SetNameIsHidden();
}
}
if (!sym)
{
const char16 *name = reinterpret_cast<const char16*>(pid->Psz());
int nameLength = pid->Cch();
SymbolName const symName(name, nameLength);
Assert(!scope->FindLocalSymbol(symName));
sym = Anew(&m_nodeAllocator, Symbol, symName, pnode, symbolType);
scope->AddNewSymbol(sym);
sym->SetPid(pid);
}
refForDecl->SetSym(sym);
}
return sym;
}
|
CWE-119
| null | 517,613 |
16595299563899322429470930513129180511
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::ReduceDeferredScriptLength(size_t chars)
{
// If we're in deferred mode, subtract the given char count from the total length,
// and see if this puts us under the deferral threshold.
if ((m_grfscr & fscrDeferFncParse) &&
(
PHASE_OFF1(Js::DeferEventHandlersPhase) ||
(m_grfscr & fscrGlobalCode)
)
)
{
if (m_length > chars)
{
m_length -= chars;
}
else
{
m_length = 0;
}
if (m_length < Parser::GetDeferralThreshold(this->m_sourceContextInfo->IsSourceProfileLoaded()))
{
// Stop deferring.
m_grfscr &= ~fscrDeferFncParse;
m_stoppedDeferredParse = TRUE;
}
}
}
|
CWE-119
| null | 517,614 |
236289941544708123081144643826453781972
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseDestructuredInitializer(ParseNodePtr lhsNode,
bool isDecl,
bool topLevel,
DestructuringInitializerContext initializerContext,
bool allowIn,
BOOL *forInOfOkay,
BOOL *nativeForOkay)
{
m_pscan->Scan();
if (topLevel && nativeForOkay == nullptr)
{
if (initializerContext != DIC_ForceErrorOnInitializer && m_token.tk != tkAsg)
{
// e.g. var {x};
Error(ERRDestructInit);
}
else if (initializerContext == DIC_ForceErrorOnInitializer && m_token.tk == tkAsg)
{
// e.g. catch([x] = [0])
Error(ERRDestructNotInit);
}
}
if (m_token.tk != tkAsg || initializerContext == DIC_ShouldNotParseInitializer)
{
if (topLevel && nativeForOkay != nullptr)
{
// Native loop should have destructuring initializer
*nativeForOkay = FALSE;
}
return lhsNode;
}
if (forInOfOkay)
{
*forInOfOkay = FALSE;
}
m_pscan->Scan();
bool alreadyHasInitError = m_hasDeferredShorthandInitError;
ParseNodePtr pnodeDefault = ParseExpr<buildAST>(koplCma, nullptr, allowIn);
if (m_hasDeferredShorthandInitError && !alreadyHasInitError)
{
Error(ERRnoColon);
}
ParseNodePtr pnodeDestructAsg = nullptr;
if (buildAST)
{
Assert(lhsNode != nullptr);
pnodeDestructAsg = CreateNodeWithScanner<knopAsg>();
pnodeDestructAsg->sxBin.pnode1 = lhsNode;
pnodeDestructAsg->sxBin.pnode2 = pnodeDefault;
pnodeDestructAsg->ichMin = lhsNode->ichMin;
pnodeDestructAsg->ichLim = pnodeDefault->ichLim;
}
return pnodeDestructAsg;
}
|
CWE-119
| null | 517,615 |
46516120863401873707041849458313756515
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::SetCurrentStatement(StmtNest *stmt)
{
m_pstmtCur = stmt;
}
|
CWE-119
| null | 517,616 |
292485146605998222638721457045974005292
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::PopScope(Scope *scope)
{
Assert(scope == m_currentScope);
m_currentScope = scope->GetEnclosingScope();
scope->SetEnclosingScope(nullptr);
}
|
CWE-119
| null | 517,617 |
143705433493355726446545247976366220670
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::GenerateModuleFunctionWrapper()
{
ParseNodePtr pnodeFnc = ParseFncDecl<buildAST>(fFncModule, nullptr, false, true, true);
ParseNodePtr callNode = CreateCallNode(knopCall, pnodeFnc, nullptr);
return callNode;
}
|
CWE-119
| null | 517,618 |
10303101392403669535363519283590066143
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
bool Parser::CheckForDirective(bool* pIsUseStrict, bool *pIsUseAsm, bool* pIsOctalInString)
{
// A directive is a string constant followed by a statement terminating token
if (m_token.tk != tkStrCon)
return false;
// Careful, need to check for octal before calling m_pscan->Scan()
// because Scan() clears the "had octal" flag on the scanner and
// m_pscan->Restore() does not restore this flag.
if (pIsOctalInString != nullptr)
{
*pIsOctalInString = m_pscan->IsOctOrLeadingZeroOnLastTKNumber();
}
Ident* pidDirective = m_token.GetStr();
RestorePoint start;
m_pscan->Capture(&start);
m_pscan->Scan();
bool isDirective = true;
switch (m_token.tk)
{
case tkSColon:
case tkEOF:
case tkLCurly:
case tkRCurly:
break;
default:
if (!m_pscan->FHadNewLine())
{
isDirective = false;
}
break;
}
if (isDirective)
{
if (pIsUseStrict != nullptr)
{
*pIsUseStrict = CheckStrictModeStrPid(pidDirective);
}
if (pIsUseAsm != nullptr)
{
*pIsUseAsm = CheckAsmjsModeStrPid(pidDirective);
}
}
m_pscan->SeekTo(start);
return isDirective;
}
|
CWE-119
| null | 517,619 |
49608355249600317448871308308696566351
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseTryCatchFinally()
{
this->m_tryCatchOrFinallyDepth++;
ParseNodePtr pnodeT = ParseTry<buildAST>();
ParseNodePtr pnodeTC = nullptr;
StmtNest stmt;
bool hasCatch = false;
if (tkCATCH == m_token.tk)
{
hasCatch = true;
if (buildAST)
{
pnodeTC = CreateNodeWithScanner<knopTryCatch>();
pnodeT->sxStmt.pnodeOuter = pnodeTC;
pnodeTC->sxTryCatch.pnodeTry = pnodeT;
}
PushStmt<buildAST>(&stmt, pnodeTC, knopTryCatch, nullptr, nullptr);
ParseNodePtr pnodeCatch = ParseCatch<buildAST>();
if (buildAST)
{
pnodeTC->sxTryCatch.pnodeCatch = pnodeCatch;
}
PopStmt(&stmt);
}
if (tkFINALLY != m_token.tk)
{
if (!hasCatch)
{
Error(ERRnoCatch);
}
Assert(!buildAST || pnodeTC);
return pnodeTC;
}
ParseNodePtr pnodeTF = nullptr;
if (buildAST)
{
pnodeTF = CreateNode(knopTryFinally);
}
PushStmt<buildAST>(&stmt, pnodeTF, knopTryFinally, nullptr, nullptr);
ParseNodePtr pnodeFinally = ParseFinally<buildAST>();
if (buildAST)
{
if (!hasCatch)
{
pnodeTF->sxTryFinally.pnodeTry = pnodeT;
pnodeT->sxStmt.pnodeOuter = pnodeTF;
}
else
{
pnodeTF->sxTryFinally.pnodeTry = CreateNode(knopTry);
pnodeTF->sxTryFinally.pnodeTry->sxStmt.pnodeOuter = pnodeTF;
pnodeTF->sxTryFinally.pnodeTry->sxTry.pnodeBody = pnodeTC;
pnodeTC->sxStmt.pnodeOuter = pnodeTF->sxTryFinally.pnodeTry;
}
pnodeTF->sxTryFinally.pnodeFinally = pnodeFinally;
}
PopStmt(&stmt);
this->m_tryCatchOrFinallyDepth--;
return pnodeTF;
}
|
CWE-119
| null | 517,620 |
258564482312435573300164829389171541061
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
DeferredFunctionStub * BuildDeferredStubTree(ParseNode *pnodeFnc, Recycler *recycler)
{
Assert(pnodeFnc->nop == knopFncDecl);
uint nestedCount = pnodeFnc->sxFnc.nestedCount;
if (nestedCount == 0)
{
return nullptr;
}
if (pnodeFnc->sxFnc.deferredStub)
{
return pnodeFnc->sxFnc.deferredStub;
}
DeferredFunctionStub *deferredStubs = RecyclerNewArray(recycler, DeferredFunctionStub, nestedCount);
uint i = 0;
ParseNode *pnodeBlock = pnodeFnc->sxFnc.pnodeBodyScope;
Assert(pnodeBlock != nullptr
&& pnodeBlock->nop == knopBlock
&& (pnodeBlock->sxBlock.blockType == PnodeBlockType::Function
|| pnodeBlock->sxBlock.blockType == PnodeBlockType::Parameter));
for (ParseNode *pnodeChild = pnodeBlock->sxBlock.pnodeScopes; pnodeChild != nullptr;)
{
if (pnodeChild->nop != knopFncDecl)
{
// We only expect to find a function body block in a parameter scope block.
Assert(pnodeChild->nop == knopBlock
&& (pnodeBlock->sxBlock.blockType == PnodeBlockType::Parameter
|| pnodeChild->sxBlock.blockType == PnodeBlockType::Function));
pnodeChild = pnodeChild->sxBlock.pnodeNext;
continue;
}
AssertOrFailFast(i < nestedCount);
if (pnodeChild->sxFnc.pnodeBody != nullptr)
{
// Anomalous case of a non-deferred function nested within a deferred one.
// Work around by discarding the stub tree.
return nullptr;
}
if (pnodeChild->sxFnc.IsGeneratedDefault())
{
++i;
pnodeChild = pnodeChild->sxFnc.pnodeNext;
continue;
}
AnalysisAssertOrFailFast(i < nestedCount);
deferredStubs[i].fncFlags = pnodeChild->sxFnc.fncFlags;
deferredStubs[i].nestedCount = pnodeChild->sxFnc.nestedCount;
deferredStubs[i].restorePoint = *pnodeChild->sxFnc.pRestorePoint;
deferredStubs[i].deferredStubs = BuildDeferredStubTree(pnodeChild, recycler);
deferredStubs[i].ichMin = pnodeChild->ichMin;
++i;
pnodeChild = pnodeChild->sxFnc.pnodeNext;
}
return deferredStubs;
}
|
CWE-119
| null | 517,621 |
188155922053669009294313061747050790462
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ModuleImportOrExportEntryList* Parser::GetModuleIndirectExportEntryList()
{
return m_currentNodeProg->sxModule.indirectExportEntries;
}
|
CWE-119
| null | 517,622 |
33242849601885406462710864257110721719
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::CaptureState(ParserState *state)
{
Assert(state != nullptr);
state->m_funcInArraySave = m_funcInArray;
state->m_funcInArrayDepthSave = m_funcInArrayDepth;
state->m_nestedCountSave = *m_pnestedCount;
state->m_ppnodeScopeSave = m_ppnodeScope;
state->m_ppnodeExprScopeSave = m_ppnodeExprScope;
state->m_pCurrentAstSizeSave = m_pCurrentAstSize;
state->m_nextBlockId = m_nextBlockId;
Assert(state->m_ppnodeScopeSave == nullptr || *state->m_ppnodeScopeSave == nullptr);
Assert(state->m_ppnodeExprScopeSave == nullptr || *state->m_ppnodeExprScopeSave == nullptr);
#if DEBUG
state->m_currentBlockInfo = m_currentBlockInfo;
#endif
}
|
CWE-119
| null | 517,623 |
25506671943983102559090143542604424136
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
LabelId* Parser::CreateLabelId(IdentToken* pToken)
{
LabelId* pLabelId;
pLabelId = (LabelId*)m_nodeAllocator.Alloc(sizeof(LabelId));
if (NULL == pLabelId)
Error(ERRnoMemory);
pLabelId->pid = pToken->pid;
pLabelId->next = NULL;
return pLabelId;
}
|
CWE-119
| null | 517,624 |
197281592417343026169809788520499686822
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
LPCOLESTR Parser::AppendNameHints(IdentPtr left, LPCOLESTR right, uint32 *pNameLength, uint32 *pShortNameOffset, bool ignoreAddDotWithSpace, bool wrapInBrackets)
{
uint32 rightLen = (right == nullptr) ? 0 : (uint32) wcslen(right);
if (pShortNameOffset != nullptr)
{
*pShortNameOffset = 0;
}
Assert(rightLen <= ULONG_MAX); // name hints should not exceed ULONG_MAX characters
if (left == nullptr && !wrapInBrackets)
{
*pNameLength = rightLen;
return right;
}
LPCOLESTR leftStr = _u("");
uint32 leftLen = 0;
if (left != nullptr) // if wrapInBrackets is true
{
leftStr = left->Psz();
leftLen = left->Cch();
}
if (rightLen == 0 && !wrapInBrackets)
{
*pNameLength = leftLen;
return left->Psz();
}
return AppendNameHints(leftStr, leftLen, right, rightLen, pNameLength, pShortNameOffset, ignoreAddDotWithSpace, wrapInBrackets);
}
|
CWE-119
| null | 517,625 |
140570526263359083163409430617805735562
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::FinishFncNode(ParseNodePtr pnodeFnc)
{
AnalysisAssert(pnodeFnc);
// Finish the AST for a function that was deferred earlier, but which we decided
// to finish after the fact.
// We assume that the name(s) and arg(s) have already got parse nodes, so
// we just have to do the function body.
// Save the current next function Id, and resume from the old one.
Js::LocalFunctionId * nextFunctionIdSave = m_nextFunctionId;
Js::LocalFunctionId tempNextFunctionId = pnodeFnc->sxFnc.functionId + 1;
this->m_nextFunctionId = &tempNextFunctionId;
ParseNodePtr pnodeFncSave = m_currentNodeFunc;
uint *pnestedCountSave = m_pnestedCount;
int32* pAstSizeSave = m_pCurrentAstSize;
m_currentNodeFunc = pnodeFnc;
m_pCurrentAstSize = & (pnodeFnc->sxFnc.astSize);
pnodeFnc->sxFnc.nestedCount = 0;
m_pnestedCount = &pnodeFnc->sxFnc.nestedCount;
// Cue up the parser to the start of the function body.
if (pnodeFnc->sxFnc.pnodeName)
{
// Skip the name(s).
m_pscan->SetCurrentCharacter(pnodeFnc->sxFnc.pnodeName->ichLim, pnodeFnc->sxFnc.lineNumber);
}
else
{
m_pscan->SetCurrentCharacter(pnodeFnc->ichMin, pnodeFnc->sxFnc.lineNumber);
if (pnodeFnc->sxFnc.IsAccessor())
{
// Getter/setter. The node text starts with the name, so eat that.
m_pscan->ScanNoKeywords();
}
else
{
// Anonymous function. Skip any leading "("'s and "function".
for (;;)
{
m_pscan->Scan();
if (m_token.GetIdentifier(m_phtbl) == wellKnownPropertyPids.async)
{
Assert(pnodeFnc->sxFnc.IsAsync());
continue;
}
if (m_token.tk == tkFUNCTION)
{
break;
}
Assert(m_token.tk == tkLParen || m_token.tk == tkStar);
}
}
}
// switch scanner to treat 'yield' as keyword in generator functions
// or as an identifier in non-generator functions
bool fPreviousYieldIsKeyword = m_pscan->SetYieldIsKeyword(pnodeFnc && pnodeFnc->sxFnc.IsGenerator());
bool fPreviousAwaitIsKeyword = m_pscan->SetAwaitIsKeyword(pnodeFnc && pnodeFnc->sxFnc.IsAsync());
// Skip the arg list.
m_pscan->ScanNoKeywords();
if (m_token.tk == tkStar)
{
Assert(pnodeFnc->sxFnc.IsGenerator());
m_pscan->ScanNoKeywords();
}
Assert(m_token.tk == tkLParen);
m_pscan->ScanNoKeywords();
if (m_token.tk != tkRParen)
{
for (;;)
{
if (m_token.tk == tkEllipsis)
{
m_pscan->ScanNoKeywords();
}
if (m_token.tk == tkID)
{
m_pscan->ScanNoKeywords();
if (m_token.tk == tkAsg)
{
// Eat the default expression
m_pscan->Scan();
ParseExpr<false>(koplCma);
}
}
else if (IsPossiblePatternStart())
{
ParseDestructuredLiteralWithScopeSave(tkLET, false/*isDecl*/, false /*topLevel*/);
}
else
{
AssertMsg(false, "Unexpected identifier prefix while fast-scanning formals");
}
if (m_token.tk != tkComma)
{
break;
}
m_pscan->ScanNoKeywords();
if (m_token.tk == tkRParen && m_scriptContext->GetConfig()->IsES7TrailingCommaEnabled())
{
break;
}
}
}
if (m_token.tk == tkRParen) // This might be false due to a lambda => token.
{
m_pscan->Scan();
}
// Finish the function body.
{
// Note that in IE8- modes, surrounding parentheses are considered part of function body. e.g. "( function x(){} )".
// We lose that context here since we start from middle of function body. So save and restore source range info.
ParseNodePtr* lastNodeRef = NULL;
const charcount_t ichLim = pnodeFnc->ichLim;
const size_t cbLim = pnodeFnc->sxFnc.cbLim;
this->FinishFncDecl(pnodeFnc, NULL, lastNodeRef);
#if DBG
// The pnode extent may not match the original extent.
// We expect this to happen only when there are trailing ")"'s.
// Consume them and make sure that's all we've got.
if (pnodeFnc->ichLim != ichLim)
{
Assert(pnodeFnc->ichLim < ichLim);
m_pscan->SetCurrentCharacter(pnodeFnc->ichLim);
while (m_pscan->IchLimTok() != ichLim)
{
m_pscan->ScanNoKeywords();
Assert(m_token.tk == tkRParen);
}
}
#endif
pnodeFnc->ichLim = ichLim;
pnodeFnc->sxFnc.cbLim = cbLim;
}
m_currentNodeFunc = pnodeFncSave;
m_pCurrentAstSize = pAstSizeSave;
m_pnestedCount = pnestedCountSave;
Assert(m_pnestedCount);
Assert(tempNextFunctionId == pnodeFnc->sxFnc.deferredParseNextFunctionId);
this->m_nextFunctionId = nextFunctionIdSave;
m_pscan->SetYieldIsKeyword(fPreviousYieldIsKeyword);
m_pscan->SetAwaitIsKeyword(fPreviousAwaitIsKeyword);
}
|
CWE-119
| null | 517,626 |
16870405246322525002148132101392841805
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr PnFnc::GetParamScope() const
{
if (this->pnodeScopes == nullptr)
{
return nullptr;
}
Assert(this->pnodeScopes->nop == knopBlock &&
this->pnodeScopes->sxBlock.pnodeNext == nullptr);
return this->pnodeScopes->sxBlock.pnodeScopes;
}
|
CWE-119
| null | 517,627 |
103176798663440961173521750906476188968
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::Error(HRESULT hr)
{
Assert(FAILED(hr));
m_err.Throw(hr);
}
|
CWE-119
| null | 517,628 |
38595640353788136122812671292235632740
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
BlockInfoStack *Parser::PushBlockInfo(ParseNodePtr pnodeBlock)
{
BlockInfoStack *newBlockInfo = (BlockInfoStack *)m_nodeAllocator.Alloc(sizeof(BlockInfoStack));
Assert(nullptr != newBlockInfo);
newBlockInfo->pnodeBlock = pnodeBlock;
newBlockInfo->pBlockInfoOuter = m_currentBlockInfo;
newBlockInfo->m_ppnodeLex = &pnodeBlock->sxBlock.pnodeLexVars;
if (pnodeBlock->sxBlock.blockType != PnodeBlockType::Regular)
{
newBlockInfo->pBlockInfoFunction = newBlockInfo;
}
else
{
Assert(m_currentBlockInfo);
newBlockInfo->pBlockInfoFunction = m_currentBlockInfo->pBlockInfoFunction;
}
m_currentBlockInfo = newBlockInfo;
return newBlockInfo;
}
|
CWE-119
| null | 517,629 |
106543278435848812596500297688769429774
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseRegExp()
{
ParseNodePtr pnode = nullptr;
if (buildAST || m_doingFastScan)
{
m_pscan->RescanRegExp();
BOOL saveDeferringAST = this->m_deferringAST;
if (m_doingFastScan)
{
this->m_deferringAST = false;
}
pnode = CreateNodeWithScanner<knopRegExp>();
pnode->sxPid.regexPattern = m_token.GetRegex();
if (m_doingFastScan)
{
this->m_deferringAST = saveDeferringAST;
this->AddFastScannedRegExpNode(pnode);
if (!buildAST)
{
pnode = nullptr;
}
}
#if ENABLE_BACKGROUND_PARSING
else if (this->IsBackgroundParser())
{
Assert(pnode->sxPid.regexPattern == nullptr);
this->AddBackgroundRegExpNode(pnode);
}
#endif
}
else
{
m_pscan->RescanRegExpNoAST();
}
Assert(m_token.tk == tkRegExp);
return pnode;
}
|
CWE-119
| null | 517,630 |
147673488737859313365521846411348562148
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::SetPidRefsInScopeDynamic(IdentPtr pid, int blockId)
{
PidRefStack *ref = pid->GetTopRef();
while (ref && ref->GetScopeId() >= blockId)
{
ref->SetDynamicBinding();
ref = ref->prev;
}
}
|
CWE-119
| null | 517,631 |
144181028322352083359720739055828639727
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseClassDecl(BOOL isDeclaration, LPCOLESTR pNameHint, uint32 *pHintLength, uint32 *pShortNameOffset)
{
bool hasConstructor = false;
bool hasExtends = false;
IdentPtr name = nullptr;
ParseNodePtr pnodeName = nullptr;
ParseNodePtr pnodeConstructor = nullptr;
ParseNodePtr pnodeExtends = nullptr;
ParseNodePtr pnodeMembers = nullptr;
ParseNodePtr *lastMemberNodeRef = nullptr;
ParseNodePtr pnodeStaticMembers = nullptr;
ParseNodePtr *lastStaticMemberNodeRef = nullptr;
uint32 nameHintLength = pHintLength ? *pHintLength : 0;
uint32 nameHintOffset = pShortNameOffset ? *pShortNameOffset : 0;
ArenaAllocator tempAllocator(_u("ClassMemberNames"), m_nodeAllocator.GetPageAllocator(), Parser::OutOfMemory);
ParseNodePtr pnodeClass = nullptr;
if (buildAST)
{
pnodeClass = CreateNode(knopClassDecl);
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(Class, m_scriptContext);
}
m_pscan->Scan();
if (m_token.tk == tkID)
{
name = m_token.GetIdentifier(m_phtbl);
m_pscan->Scan();
}
else if (isDeclaration)
{
IdentifierExpectedError(m_token);
}
if (isDeclaration && name == wellKnownPropertyPids.arguments && GetCurrentBlockInfo()->pnodeBlock->sxBlock.blockType == Function)
{
GetCurrentFunctionNode()->grfpn |= PNodeFlags::fpnArguments_overriddenByDecl;
}
BOOL strictSave = m_fUseStrictMode;
m_fUseStrictMode = TRUE;
ParseNodePtr pnodeDeclName = nullptr;
if (isDeclaration)
{
pnodeDeclName = CreateBlockScopedDeclNode(name, knopLetDecl);
}
ParseNodePtr *ppnodeScopeSave = nullptr;
ParseNodePtr *ppnodeExprScopeSave = nullptr;
ParseNodePtr pnodeBlock = StartParseBlock<buildAST>(PnodeBlockType::Regular, ScopeType_Block);
if (buildAST)
{
PushFuncBlockScope(pnodeBlock, &ppnodeScopeSave, &ppnodeExprScopeSave);
pnodeClass->sxClass.pnodeBlock = pnodeBlock;
}
if (name)
{
pnodeName = CreateBlockScopedDeclNode(name, knopConstDecl);
}
if (m_token.tk == tkEXTENDS)
{
m_pscan->Scan();
pnodeExtends = ParseExpr<buildAST>();
hasExtends = true;
}
if (m_token.tk != tkLCurly)
{
Error(ERRnoLcurly);
}
OUTPUT_TRACE_DEBUGONLY(Js::ES6VerboseFlag, _u("Parsing class (%s) : %s\n"), GetParseType(), name ? name->Psz() : _u("anonymous class"));
RestorePoint beginClass;
m_pscan->Capture(&beginClass);
m_pscan->ScanForcingPid();
IdentPtr pClassNamePid = pnodeName ? pnodeName->sxVar.pid : nullptr;
for (;;)
{
if (m_token.tk == tkSColon)
{
m_pscan->ScanForcingPid();
continue;
}
if (m_token.tk == tkRCurly)
{
break;
}
bool isStatic = m_token.tk == tkSTATIC;
if (isStatic)
{
m_pscan->ScanForcingPid();
}
ushort fncDeclFlags = fFncNoName | fFncMethod | fFncClassMember;
charcount_t ichMin = 0;
size_t iecpMin = 0;
ParseNodePtr pnodeMemberName = nullptr;
IdentPtr pidHint = nullptr;
IdentPtr memberPid = nullptr;
LPCOLESTR pMemberNameHint = nullptr;
uint32 memberNameHintLength = 0;
uint32 memberNameOffset = 0;
bool isComputedName = false;
bool isAsyncMethod = false;
if (m_token.tk == tkID && m_token.GetIdentifier(m_phtbl) == wellKnownPropertyPids.async && m_scriptContext->GetConfig()->IsES7AsyncAndAwaitEnabled())
{
RestorePoint parsedAsync;
m_pscan->Capture(&parsedAsync);
ichMin = m_pscan->IchMinTok();
iecpMin = m_pscan->IecpMinTok();
m_pscan->Scan();
if (m_token.tk == tkLParen || m_pscan->FHadNewLine())
{
m_pscan->SeekTo(parsedAsync);
}
else
{
isAsyncMethod = true;
}
}
bool isGenerator = m_scriptContext->GetConfig()->IsES6GeneratorsEnabled() &&
m_token.tk == tkStar;
if (isGenerator)
{
fncDeclFlags |= fFncGenerator;
m_pscan->ScanForcingPid();
}
if (m_token.tk == tkLBrack && m_scriptContext->GetConfig()->IsES6ObjectLiteralsEnabled())
{
// Computed member name: [expr] () { }
LPCOLESTR emptyHint = nullptr;
ParseComputedName<buildAST>(&pnodeMemberName, &emptyHint, &pMemberNameHint, &memberNameHintLength, &memberNameOffset);
isComputedName = true;
}
else // not computed name
{
memberPid = this->ParseClassPropertyName(&pidHint);
if (pidHint)
{
pMemberNameHint = pidHint->Psz();
memberNameHintLength = pidHint->Cch();
}
}
if (buildAST && memberPid)
{
pnodeMemberName = CreateStrNodeWithScanner(memberPid);
}
if (!isStatic && memberPid == wellKnownPropertyPids.constructor)
{
if (hasConstructor || isAsyncMethod)
{
Error(ERRsyntax);
}
hasConstructor = true;
LPCOLESTR pConstructorName = nullptr;
uint32 constructorNameLength = 0;
uint32 constructorShortNameHintOffset = 0;
if (pnodeName && pnodeName->sxVar.pid)
{
pConstructorName = pnodeName->sxVar.pid->Psz();
constructorNameLength = pnodeName->sxVar.pid->Cch();
}
else
{
pConstructorName = pNameHint;
constructorNameLength = nameHintLength;
constructorShortNameHintOffset = nameHintOffset;
}
{
AutoParsingSuperRestrictionStateRestorer restorer(this);
this->m_parsingSuperRestrictionState = hasExtends ? ParsingSuperRestrictionState_SuperCallAndPropertyAllowed : ParsingSuperRestrictionState_SuperPropertyAllowed;
pnodeConstructor = ParseFncDecl<buildAST>(fncDeclFlags, pConstructorName, /* needsPIDOnRCurlyScan */ true, /* resetParsingSuperRestrictionState = */false);
}
if (pnodeConstructor->sxFnc.IsGenerator())
{
Error(ERRConstructorCannotBeGenerator);
}
Assert(constructorNameLength >= constructorShortNameHintOffset);
// The constructor function will get the same name as class.
pnodeConstructor->sxFnc.hint = pConstructorName;
pnodeConstructor->sxFnc.hintLength = constructorNameLength;
pnodeConstructor->sxFnc.hintOffset = constructorShortNameHintOffset;
pnodeConstructor->sxFnc.pid = pnodeName && pnodeName->sxVar.pid ? pnodeName->sxVar.pid : wellKnownPropertyPids.constructor;
pnodeConstructor->sxFnc.SetIsClassConstructor(TRUE);
pnodeConstructor->sxFnc.SetHasNonThisStmt();
pnodeConstructor->sxFnc.SetIsBaseClassConstructor(pnodeExtends == nullptr);
}
else
{
ParseNodePtr pnodeMember = nullptr;
bool isMemberNamedGetOrSet = false;
RestorePoint beginMethodName;
m_pscan->Capture(&beginMethodName);
if (memberPid == wellKnownPropertyPids.get || memberPid == wellKnownPropertyPids.set)
{
m_pscan->ScanForcingPid();
}
if (m_token.tk == tkLParen)
{
m_pscan->SeekTo(beginMethodName);
isMemberNamedGetOrSet = true;
}
if ((memberPid == wellKnownPropertyPids.get || memberPid == wellKnownPropertyPids.set) && !isMemberNamedGetOrSet)
{
bool isGetter = (memberPid == wellKnownPropertyPids.get);
if (m_token.tk == tkLBrack && m_scriptContext->GetConfig()->IsES6ObjectLiteralsEnabled())
{
// Computed get/set member name: get|set [expr] () { }
LPCOLESTR emptyHint = nullptr;
ParseComputedName<buildAST>(&pnodeMemberName, &emptyHint, &pMemberNameHint, &memberNameHintLength, &memberNameOffset);
isComputedName = true;
}
else // not computed name
{
memberPid = this->ParseClassPropertyName(&pidHint);
}
if ((isStatic ? (memberPid == wellKnownPropertyPids.prototype) : (memberPid == wellKnownPropertyPids.constructor)) || isAsyncMethod)
{
Error(ERRsyntax);
}
if (buildAST && memberPid && !isComputedName)
{
pnodeMemberName = CreateStrNodeWithScanner(memberPid);
}
ParseNodePtr pnodeFnc = nullptr;
{
AutoParsingSuperRestrictionStateRestorer restorer(this);
this->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
pnodeFnc = ParseFncDecl<buildAST>(fncDeclFlags | (isGetter ? fFncNoArg : fFncOneArg),
pidHint ? pidHint->Psz() : nullptr, /* needsPIDOnRCurlyScan */ true,
/* resetParsingSuperRestrictionState */false);
}
pnodeFnc->sxFnc.SetIsStaticMember(isStatic);
if (buildAST)
{
pnodeFnc->sxFnc.SetIsAccessor();
pnodeMember = CreateBinNode(isGetter ? knopGetMember : knopSetMember, pnodeMemberName, pnodeFnc);
pMemberNameHint = ConstructFinalHintNode(pClassNamePid, pidHint,
isGetter ? wellKnownPropertyPids.get : wellKnownPropertyPids.set, isStatic,
&memberNameHintLength, &memberNameOffset, isComputedName, pMemberNameHint);
}
}
else
{
if (isStatic && (memberPid == wellKnownPropertyPids.prototype))
{
Error(ERRsyntax);
}
ParseNodePtr pnodeFnc = nullptr;
{
AutoParsingSuperRestrictionStateRestorer restorer(this);
this->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
if (isAsyncMethod)
{
fncDeclFlags |= fFncAsync;
}
pnodeFnc = ParseFncDecl<buildAST>(fncDeclFlags, pidHint ? pidHint->Psz() : nullptr, /* needsPIDOnRCurlyScan */ true, /* resetParsingSuperRestrictionState */false);
if (isAsyncMethod)
{
pnodeFnc->sxFnc.cbMin = iecpMin;
pnodeFnc->ichMin = ichMin;
}
}
pnodeFnc->sxFnc.SetIsStaticMember(isStatic);
if (buildAST)
{
pnodeMember = CreateBinNode(knopMember, pnodeMemberName, pnodeFnc);
pMemberNameHint = ConstructFinalHintNode(pClassNamePid, pidHint, nullptr /*pgetset*/, isStatic, &memberNameHintLength, &memberNameOffset, isComputedName, pMemberNameHint);
}
}
if (buildAST)
{
Assert(memberNameHintLength >= memberNameOffset);
pnodeMember->sxBin.pnode2->sxFnc.hint = pMemberNameHint; // Fully qualified name
pnodeMember->sxBin.pnode2->sxFnc.hintLength = memberNameHintLength;
pnodeMember->sxBin.pnode2->sxFnc.hintOffset = memberNameOffset;
pnodeMember->sxBin.pnode2->sxFnc.pid = memberPid; // Short name
AddToNodeList(isStatic ? &pnodeStaticMembers : &pnodeMembers, isStatic ? &lastStaticMemberNodeRef : &lastMemberNodeRef, pnodeMember);
}
}
}
if (buildAST)
{
pnodeClass->ichLim = m_pscan->IchLimTok();
}
if (!hasConstructor)
{
OUTPUT_TRACE_DEBUGONLY(Js::ES6VerboseFlag, _u("Generating constructor (%s) : %s\n"), GetParseType(), name ? name->Psz() : _u("anonymous class"));
RestorePoint endClass;
m_pscan->Capture(&endClass);
m_pscan->SeekTo(beginClass);
pnodeConstructor = GenerateEmptyConstructor<buildAST>(pnodeExtends != nullptr);
if (buildAST)
{
if (pClassNamePid)
{
pnodeConstructor->sxFnc.hint = pClassNamePid->Psz();
pnodeConstructor->sxFnc.hintLength = pClassNamePid->Cch();
pnodeConstructor->sxFnc.hintOffset = 0;
}
else
{
Assert(nameHintLength >= nameHintOffset);
pnodeConstructor->sxFnc.hint = pNameHint;
pnodeConstructor->sxFnc.hintLength = nameHintLength;
pnodeConstructor->sxFnc.hintOffset = nameHintOffset;
}
pnodeConstructor->sxFnc.pid = pClassNamePid;
}
m_pscan->SeekTo(endClass);
}
if (buildAST)
{
pnodeConstructor->sxFnc.cbMin = pnodeClass->ichMin;
pnodeConstructor->sxFnc.cbLim = pnodeClass->ichLim;
pnodeConstructor->ichMin = pnodeClass->ichMin;
pnodeConstructor->ichLim = pnodeClass->ichLim;
PopFuncBlockScope(ppnodeScopeSave, ppnodeExprScopeSave);
pnodeClass->sxClass.pnodeDeclName = pnodeDeclName;
pnodeClass->sxClass.pnodeName = pnodeName;
pnodeClass->sxClass.pnodeConstructor = pnodeConstructor;
pnodeClass->sxClass.pnodeExtends = pnodeExtends;
pnodeClass->sxClass.pnodeMembers = pnodeMembers;
pnodeClass->sxClass.pnodeStaticMembers = pnodeStaticMembers;
pnodeClass->sxClass.isDefaultModuleExport = false;
}
FinishParseBlock(pnodeBlock);
m_fUseStrictMode = strictSave;
m_pscan->Scan();
return pnodeClass;
}
|
CWE-119
| null | 517,632 |
177008825728697882023754318724668426867
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::InitPids()
{
AssertMemN(m_phtbl);
wellKnownPropertyPids.arguments = m_phtbl->PidHashNameLen(g_ssym_arguments.sz, g_ssym_arguments.cch);
wellKnownPropertyPids.async = m_phtbl->PidHashNameLen(g_ssym_async.sz, g_ssym_async.cch);
wellKnownPropertyPids.eval = m_phtbl->PidHashNameLen(g_ssym_eval.sz, g_ssym_eval.cch);
wellKnownPropertyPids.get = m_phtbl->PidHashNameLen(g_ssym_get.sz, g_ssym_get.cch);
wellKnownPropertyPids.set = m_phtbl->PidHashNameLen(g_ssym_set.sz, g_ssym_set.cch);
wellKnownPropertyPids.let = m_phtbl->PidHashNameLen(g_ssym_let.sz, g_ssym_let.cch);
wellKnownPropertyPids.constructor = m_phtbl->PidHashNameLen(g_ssym_constructor.sz, g_ssym_constructor.cch);
wellKnownPropertyPids.prototype = m_phtbl->PidHashNameLen(g_ssym_prototype.sz, g_ssym_prototype.cch);
wellKnownPropertyPids.__proto__ = m_phtbl->PidHashNameLen(_u("__proto__"), sizeof("__proto__") - 1);
wellKnownPropertyPids.of = m_phtbl->PidHashNameLen(_u("of"), sizeof("of") - 1);
wellKnownPropertyPids.target = m_phtbl->PidHashNameLen(_u("target"), sizeof("target") - 1);
wellKnownPropertyPids.as = m_phtbl->PidHashNameLen(_u("as"), sizeof("as") - 1);
wellKnownPropertyPids.from = m_phtbl->PidHashNameLen(_u("from"), sizeof("from") - 1);
wellKnownPropertyPids._default = m_phtbl->PidHashNameLen(_u("default"), sizeof("default") - 1);
wellKnownPropertyPids._starDefaultStar = m_phtbl->PidHashNameLen(_u("*default*"), sizeof("*default*") - 1);
wellKnownPropertyPids._star = m_phtbl->PidHashNameLen(_u("*"), sizeof("*") - 1);
}
|
CWE-119
| null | 517,633 |
250345554463455506897875285398990329779
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void PrintScopesWIndent(ParseNode *pnode,int indentAmt) {
ParseNode *scope = nullptr;
bool firstOnly = false;
switch(pnode->nop)
{
case knopProg:
case knopFncDecl: scope = pnode->sxFnc.pnodeScopes; break;
case knopBlock: scope = pnode->sxBlock.pnodeScopes; break;
case knopCatch: scope = pnode->sxCatch.pnodeScopes; break;
case knopWith: scope = pnode->sxWith.pnodeScopes; break;
case knopSwitch: scope = pnode->sxSwitch.pnodeBlock; firstOnly = true; break;
case knopFor: scope = pnode->sxFor.pnodeBlock; firstOnly = true; break;
case knopForIn: scope = pnode->sxForInOrForOf.pnodeBlock; firstOnly = true; break;
case knopForOf: scope = pnode->sxForInOrForOf.pnodeBlock; firstOnly = true; break;
}
if (scope) {
Output::Print(_u("[%4d, %4d): "), scope->ichMin, scope->ichLim);
Indent(indentAmt);
Output::Print(_u("Scopes: "));
ParseNode *next = nullptr;
ParseNode *syntheticBlock = nullptr;
while (scope) {
switch (scope->nop) {
case knopFncDecl: Output::Print(_u("knopFncDecl")); next = scope->sxFnc.pnodeNext; break;
case knopBlock: Output::Print(_u("knopBlock")); PrintBlockType(scope->sxBlock.blockType); next = scope->sxBlock.pnodeNext; break;
case knopCatch: Output::Print(_u("knopCatch")); next = scope->sxCatch.pnodeNext; break;
case knopWith: Output::Print(_u("knopWith")); next = scope->sxWith.pnodeNext; break;
default: Output::Print(_u("unknown")); break;
}
if (firstOnly) {
next = nullptr;
syntheticBlock = scope;
}
if (scope->grfpn & fpnSyntheticNode) {
Output::Print(_u(" synthetic"));
if (scope->nop == knopBlock)
syntheticBlock = scope;
}
Output::Print(_u(" (%d-%d)"), scope->ichMin, scope->ichLim);
if (next) Output::Print(_u(", "));
scope = next;
}
Output::Print(_u("\n"));
if (syntheticBlock || firstOnly) {
PrintScopesWIndent(syntheticBlock, indentAmt + INDENT_SIZE);
}
}
}
|
CWE-119
| null | 517,634 |
199748304940745771150512934035659634692
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateModuleImportDeclNode(IdentPtr localName)
{
ParseNodePtr declNode = CreateBlockScopedDeclNode(localName, knopConstDecl);
Symbol* sym = declNode->sxVar.sym;
sym->SetIsModuleExportStorage(true);
sym->SetIsModuleImport(true);
return declNode;
}
|
CWE-119
| null | 517,635 |
242083195466054141049044749660942488800
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateStrNodeWithScanner(IdentPtr pid)
{
Assert(!this->m_deferringAST);
ParseNodePtr pnode = CreateNodeWithScanner<knopStr>();
pnode->sxPid.pid=pid;
pnode->grfpn |= PNodeFlags::fpnCanFlattenConcatExpr;
return pnode;
}
|
CWE-119
| null | 517,636 |
55722340246009331846114889947014389570
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::StartParseBlock(PnodeBlockType blockType, ScopeType scopeType, ParseNodePtr pnodeLabel, LabelId* pLabelId)
{
Scope *scope = nullptr;
// Block scopes are created lazily when we discover block-scoped content.
if (scopeType != ScopeType_Unknown && scopeType != ScopeType_Block)
{
scope = Anew(&m_nodeAllocator, Scope, &m_nodeAllocator, scopeType);
PushScope(scope);
}
return StartParseBlockHelper<buildAST>(blockType, scope, pnodeLabel, pLabelId);
}
|
CWE-119
| null | 517,637 |
323787454250548930974344097803999989621
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
bool Parser::FncDeclAllowedWithoutContext(ushort flags)
{
// Statement context required for strict mode, async functions, and generators.
// Note that generators aren't detected yet when this method is called; they're checked elsewhere.
return !IsStrictMode() && !(flags & fFncAsync);
}
|
CWE-119
| null | 517,638 |
23939064856797919019928033548468083358
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::StartParseBlockWithCapacity(PnodeBlockType blockType, ScopeType scopeType, int capacity)
{
Scope *scope = nullptr;
// Block scopes are created lazily when we discover block-scoped content.
if (scopeType != ScopeType_Unknown && scopeType != ScopeType_Block)
{
scope = Anew(&m_nodeAllocator, Scope, &m_nodeAllocator, scopeType, capacity);
PushScope(scope);
}
return StartParseBlockHelper<buildAST>(blockType, scope, nullptr, nullptr);
}
|
CWE-119
| null | 517,639 |
193079209926513919664164299681682715722
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateTempRef(ParseNode* tempNode)
{
ParseNodePtr pnode = CreateUniNode(knopTempRef, tempNode);
return pnode;
}
|
CWE-119
| null | 517,640 |
294071976260190812553275605677518421356
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseDestructuredVarDecl(tokens declarationType, bool isDecl, bool *hasSeenRest, bool topLevel/* = true*/, bool allowEmptyExpression/* = true*/)
{
ParseNodePtr pnodeElem = nullptr;
int parenCount = 0;
bool seenRest = false;
// Save the Block ID prior to the increments, so we can restore it back.
int originalCurrentBlockId = GetCurrentBlock()->sxBlock.blockId;
// Eat the left parentheses only when its not a declaration. This will make sure we throw syntax errors early.
if (!isDecl)
{
while (m_token.tk == tkLParen)
{
m_pscan->Scan();
++parenCount;
// Match the block increment we do upon entering parenthetical expressions
// so that the block ID's will match on reparsing of parameters.
GetCurrentBlock()->sxBlock.blockId = m_nextBlockId++;
}
}
if (m_token.tk == tkEllipsis)
{
// As per ES 2015 : Rest can have left-hand-side-expression when on assignment expression, but under declaration only binding identifier is allowed
// But spec is going to change for this one to allow LHS-expression both on expression and declaration - so making that happen early.
seenRest = true;
m_pscan->Scan();
// Eat the left parentheses only when its not a declaration. This will make sure we throw syntax errors early.
if (!isDecl)
{
while (m_token.tk == tkLParen)
{
m_pscan->Scan();
++parenCount;
// Match the block increment we do upon entering parenthetical expressions
// so that the block ID's will match on reparsing of parameters.
GetCurrentBlock()->sxBlock.blockId = m_nextBlockId++;
}
}
if (m_token.tk != tkID && m_token.tk != tkSUPER && m_token.tk != tkLCurly && m_token.tk != tkLBrack)
{
if (isDecl)
{
Error(ERRnoIdent);
}
else
{
Error(ERRInvalidAssignmentTarget);
}
}
}
if (IsPossiblePatternStart())
{
// Go recursively
pnodeElem = ParseDestructuredLiteral<buildAST>(declarationType, isDecl, false /*topLevel*/, seenRest ? DIC_ShouldNotParseInitializer : DIC_None);
if (!isDecl)
{
BOOL fCanAssign;
IdentToken token;
// Look for postfix operator
pnodeElem = ParsePostfixOperators<buildAST>(pnodeElem, TRUE, FALSE, FALSE, &fCanAssign, &token);
}
}
else if (m_token.tk == tkSUPER || m_token.tk == tkID)
{
if (isDecl)
{
charcount_t ichMin = m_pscan->IchMinTok();
pnodeElem = ParseVariableDeclaration<buildAST>(declarationType, ichMin
,/* fAllowIn */false, /* pfForInOk */nullptr, /* singleDefOnly */true, /* allowInit */!seenRest, false /*topLevelParse*/);
}
else
{
BOOL fCanAssign;
IdentToken token;
// We aren't declaring anything, so scan the ID reference manually.
pnodeElem = ParseTerm<buildAST>(/* fAllowCall */ m_token.tk != tkSUPER, nullptr /*pNameHint*/, nullptr /*pHintLength*/, nullptr /*pShortNameOffset*/, &token, false,
&fCanAssign);
// In this destructuring case we can force error here as we cannot assign.
if (!fCanAssign)
{
Error(ERRInvalidAssignmentTarget);
}
if (buildAST)
{
if (IsStrictMode() && pnodeElem != nullptr && pnodeElem->nop == knopName)
{
CheckStrictModeEvalArgumentsUsage(pnodeElem->sxPid.pid);
}
}
else
{
if (IsStrictMode() && token.tk == tkID)
{
CheckStrictModeEvalArgumentsUsage(token.pid);
}
token.tk = tkNone;
}
}
}
else if (!((m_token.tk == tkComma || m_token.tk == tkRBrack || m_token.tk == tkRCurly) && allowEmptyExpression))
{
if (m_token.IsOperator())
{
Error(ERRDestructNoOper);
}
Error(ERRDestructIDRef);
}
// Swallow RParens before a default expression, if any.
// We eat the left parentheses only when its not a declaration. This will make sure we throw syntax errors early. We need to do the same for right parentheses.
if (!isDecl)
{
while (m_token.tk == tkRParen)
{
m_pscan->Scan();
--parenCount;
}
}
if (hasSeenRest != nullptr)
{
*hasSeenRest = seenRest;
}
if (m_token.tk == tkAsg)
{
// Parse the initializer.
if (seenRest)
{
Error(ERRRestWithDefault);
}
m_pscan->Scan();
bool alreadyHasInitError = m_hasDeferredShorthandInitError;
ParseNodePtr pnodeInit = ParseExpr<buildAST>(koplCma);
if (m_hasDeferredShorthandInitError && !alreadyHasInitError)
{
Error(ERRnoColon);
}
if (buildAST)
{
pnodeElem = CreateBinNode(knopAsg, pnodeElem, pnodeInit);
}
}
if (buildAST && seenRest)
{
ParseNodePtr pnodeRest = CreateNodeWithScanner<knopEllipsis>();
pnodeRest->sxUni.pnode1 = pnodeElem;
pnodeElem = pnodeRest;
}
// We eat the left parentheses only when its not a declaration. This will make sure we throw syntax errors early. We need to do the same for right parentheses.
if (!isDecl)
{
while (m_token.tk == tkRParen)
{
m_pscan->Scan();
--parenCount;
}
// Restore the Block ID of the current block after the parsing of destructured variable declarations and initializers.
GetCurrentBlock()->sxBlock.blockId = originalCurrentBlockId;
}
if (!(m_token.tk == tkComma || m_token.tk == tkRBrack || m_token.tk == tkRCurly))
{
if (m_token.IsOperator())
{
Error(ERRDestructNoOper);
}
Error(ERRsyntax);
}
if (parenCount != 0)
{
Error(ERRnoRparen);
}
return pnodeElem;
}
|
CWE-119
| null | 517,641 |
193092041278217608471882415410048111845
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Indent(int indentAmt) {
for (int i=0;i<indentAmt;i++) {
Output::Print(_u(" "));
}
}
|
CWE-119
| null | 517,642 |
154342406737549142065154157562763076124
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::ParseExpressionLambdaBody(ParseNodePtr pnodeLambda)
{
ParseNodePtr *lastNodeRef = nullptr;
// The lambda body is a single expression, the result of which is the return value.
ParseNodePtr pnodeRet = nullptr;
if (buildAST)
{
pnodeRet = CreateNodeWithScanner<knopReturn>();
pnodeRet->grfpn |= PNodeFlags::fpnSyntheticNode;
pnodeLambda->sxFnc.pnodeScopes->sxBlock.pnodeStmt = pnodeRet;
}
IdentToken token;
charcount_t lastRParen = 0;
ParseNodePtr result = ParseExpr<buildAST>(koplAsg, nullptr, TRUE, FALSE, nullptr, nullptr, nullptr, &token, false, nullptr, &lastRParen);
this->MarkEscapingRef(result, &token);
if (buildAST)
{
pnodeRet->sxReturn.pnodeExpr = result;
pnodeRet->ichMin = pnodeRet->sxReturn.pnodeExpr->ichMin;
pnodeRet->ichLim = pnodeRet->sxReturn.pnodeExpr->ichLim;
// Pushing a statement node with PushStmt<>() normally does this initialization
// but do it here manually since we know there is no outer statement node.
pnodeRet->sxStmt.grfnop = 0;
pnodeRet->sxStmt.pnodeOuter = nullptr;
pnodeLambda->ichLim = max(pnodeRet->ichLim, lastRParen);
pnodeLambda->sxFnc.cbLim = m_pscan->IecpLimTokPrevious();
pnodeLambda->sxFnc.pnodeScopes->ichLim = pnodeRet->ichLim;
pnodeLambda->sxFnc.pnodeBody = nullptr;
AddToNodeList(&pnodeLambda->sxFnc.pnodeBody, &lastNodeRef, pnodeLambda->sxFnc.pnodeScopes);
// Append an EndCode node.
ParseNodePtr end = CreateNodeWithScanner<knopEndCode>(pnodeRet->ichLim);
end->ichLim = end->ichMin; // make end code zero width at the immediate end of lambda body
AddToNodeList(&pnodeLambda->sxFnc.pnodeBody, &lastNodeRef, end);
// Lambda's do not have arguments binding
pnodeLambda->sxFnc.SetHasReferenceableBuiltInArguments(false);
}
}
|
CWE-119
| null | 517,643 |
12585298902440699895822971162061249377
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseMemberGetSet(OpCode nop, LPCOLESTR* ppNameHint)
{
ParseNodePtr pnodeName = nullptr;
Assert(nop == knopGetMember || nop == knopSetMember);
AssertMem(ppNameHint);
IdentPtr pid = nullptr;
bool isComputedName = false;
*ppNameHint=nullptr;
switch(m_token.tk)
{
default:
if (!m_token.IsReservedWord())
{
Error(ERRnoMemberIdent);
}
// fall through
case tkID:
pid = m_token.GetIdentifier(m_phtbl);
*ppNameHint = pid->Psz();
if (buildAST)
{
pnodeName = CreateStrNodeWithScanner(pid);
}
break;
case tkStrCon:
if (IsStrictMode() && m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
pid = m_token.GetStr();
*ppNameHint = pid->Psz();
if (buildAST)
{
pnodeName = CreateStrNodeWithScanner(pid);
}
break;
case tkIntCon:
if (IsStrictMode() && m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
pid = m_pscan->PidFromLong(m_token.GetLong());
if (buildAST)
{
pnodeName = CreateStrNodeWithScanner(pid);
}
break;
case tkFltCon:
if (IsStrictMode() && m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
pid = m_pscan->PidFromDbl(m_token.GetDouble());
if (buildAST)
{
pnodeName = CreateStrNodeWithScanner(pid);
}
break;
case tkLBrack:
// Computed property name: get|set [expr] () { }
if (!m_scriptContext->GetConfig()->IsES6ObjectLiteralsEnabled())
{
Error(ERRnoMemberIdent);
}
LPCOLESTR emptyHint = nullptr;
uint32 offset = 0;
ParseComputedName<buildAST>(&pnodeName, &emptyHint, ppNameHint, &offset);
isComputedName = true;
break;
}
MemberType memberType;
ushort flags = fFncMethod | fFncNoName;
if (nop == knopGetMember)
{
memberType = MemberTypeGetter;
flags |= fFncNoArg;
}
else
{
Assert(nop == knopSetMember);
memberType = MemberTypeSetter;
flags |= fFncOneArg;
}
this->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
ParseNodePtr pnodeFnc = ParseFncDecl<buildAST>(flags, *ppNameHint,
/*needsPIDOnRCurlyScan*/ false, /*resetParsingSuperRestrictionState*/ false);
if (buildAST)
{
pnodeFnc->sxFnc.SetIsAccessor();
return CreateBinNode(nop, pnodeName, pnodeFnc);
}
else
{
return nullptr;
}
}
|
CWE-119
| null | 517,644 |
171994979920135613742234880161888943865
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::PopStmt(StmtNest *pStmt)
{
Assert(pStmt == m_pstmtCur);
SetCurrentStatement(m_pstmtCur->pstmtOuter);
}
|
CWE-119
| null | 517,645 |
139793899354688222900699867190665638948
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateVarDeclNode(IdentPtr pid, SymbolType symbolType, bool autoArgumentsObject, ParseNodePtr pnodeFnc, bool errorOnRedecl, bool *isRedecl)
{
ParseNodePtr pnode = CreateDeclNode(knopVarDecl, pid, symbolType, errorOnRedecl, isRedecl);
// Append the variable to the end of the current variable list.
AssertMem(m_ppnodeVar);
pnode->sxVar.pnodeNext = *m_ppnodeVar;
*m_ppnodeVar = pnode;
if (nullptr != pid)
{
// this is not a temp - make sure temps go after this node
AssertMem(pid);
m_ppnodeVar = &pnode->sxVar.pnodeNext;
CheckPidIsValid(pid, autoArgumentsObject);
}
return pnode;
}
|
CWE-119
| null | 517,646 |
9215850483494174948690858860126037503
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::CheckArgumentsUse(IdentPtr pid, ParseNodePtr pnodeFnc)
{
if (pid == wellKnownPropertyPids.arguments)
{
if (pnodeFnc != nullptr && pnodeFnc != m_currentNodeProg)
{
pnodeFnc->sxFnc.SetUsesArguments(TRUE);
}
else
{
m_UsesArgumentsAtGlobal = true;
}
}
}
|
CWE-119
| null | 517,647 |
70282633162084959395912997769770255461
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::FinishParseBlock(ParseNode *pnodeBlock, bool needScanRCurly)
{
Assert(m_currentBlockInfo != nullptr && pnodeBlock == m_currentBlockInfo->pnodeBlock);
if (needScanRCurly)
{
// Only update the ichLim if we were expecting an RCurly. If there is an
// expression body without a necessary RCurly, the correct ichLim will
// have been set already.
pnodeBlock->ichLim = m_pscan->IchLimTok();
}
BindPidRefs<false>(GetCurrentBlockInfo(), m_nextBlockId - 1);
PopStmt(&m_currentBlockInfo->pstmt);
PopBlockInfo();
Scope *scope = pnodeBlock->sxBlock.scope;
if (scope)
{
PopScope(scope);
}
}
|
CWE-119
| null | 517,648 |
20297856144879875911538369697111822842
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::CheckArguments(ParseNodePtr pnode)
{
if (m_currentNodeFunc && this->NodeIsIdent(pnode, wellKnownPropertyPids.arguments))
{
m_currentNodeFunc->sxFnc.SetHasHeapArguments();
}
}
|
CWE-119
| null | 517,649 |
242232633540634781458760616594286265444
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
BOOL Parser::IsConstantInArrayLiteral(ParseNodePtr pnode)
{
if (pnode->nop == knopInt && !Js::TaggedInt::IsOverflow(pnode->sxInt.lw))
{
return TRUE;
}
return FALSE;
}
|
CWE-119
| null | 517,650 |
113021625259369979783526008507648571790
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
PidRefStack* Parser::FindOrAddPidRef(IdentPtr pid, int scopeId, Js::LocalFunctionId funcId)
{
PidRefStack *ref = pid->FindOrAddPidRef(&m_nodeAllocator, scopeId, funcId);
if (ref == NULL)
{
Error(ERRnoMemory);
}
return ref;
}
|
CWE-119
| null | 517,651 |
251990937931188470823077107540889327307
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
bool Parser::ScanAheadToFunctionEnd(uint count)
{
bool found = false;
uint curlyDepth = 0;
RestorePoint funcStart;
m_pscan->Capture(&funcStart);
for (uint i = 0; i < count; i++)
{
switch (m_token.tk)
{
case tkStrTmplBegin:
case tkStrTmplMid:
case tkStrTmplEnd:
case tkDiv:
case tkAsgDiv:
case tkScanError:
case tkEOF:
goto LEnd;
case tkLCurly:
UInt32Math::Inc(curlyDepth, Parser::OutOfMemory);
break;
case tkRCurly:
if (curlyDepth == 1)
{
found = true;
goto LEnd;
}
if (curlyDepth == 0)
{
goto LEnd;
}
curlyDepth--;
break;
}
m_pscan->ScanAhead();
}
LEnd:
m_pscan->SeekTo(funcStart);
return found;
}
|
CWE-119
| null | 517,652 |
26220090728389336515280646908735200984
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::FinishScopeInfo(Js::ParseableFunctionInfo *functionBody)
{
if (!functionBody)
{
return;
}
Js::ScopeInfo* scopeInfo = functionBody->GetScopeInfo();
if (!scopeInfo)
{
return;
}
if (this->IsBackgroundParser())
{
PROBE_STACK_NO_DISPOSE(m_scriptContext, Js::Constants::MinStackByteCodeVisitor);
}
else
{
PROBE_STACK(m_scriptContext, Js::Constants::MinStackByteCodeVisitor);
}
int scopeId = scopeInfo->GetScopeId();
scopeInfo->GetScope()->ForEachSymbol([this, scopeId](Symbol *sym)
{
this->BindPidRefsInScope(sym->GetPid(), sym, scopeId);
});
PopScope(scopeInfo->GetScope());
PopStmt(&m_currentBlockInfo->pstmt);
PopBlockInfo();
Js::ScopeInfo *paramScopeInfo = scopeInfo->GetParamScopeInfo();
if (paramScopeInfo)
{
scopeId = paramScopeInfo->GetScopeId();
paramScopeInfo->GetScope()->ForEachSymbol([this, scopeId](Symbol *sym)
{
this->BindPidRefsInScope(sym->GetPid(), sym, scopeId);
});
PopScope(paramScopeInfo->GetScope());
PopStmt(&m_currentBlockInfo->pstmt);
PopBlockInfo();
}
Js::ScopeInfo *funcExprScopeInfo = scopeInfo->GetFuncExprScopeInfo();
if (funcExprScopeInfo)
{
scopeId = funcExprScopeInfo->GetScopeId();
funcExprScopeInfo->GetScope()->ForEachSymbol([this, scopeId](Symbol *sym)
{
this->BindPidRefsInScope(sym->GetPid(), sym, scopeId);
});
PopScope(funcExprScopeInfo->GetScope());
PopStmt(&m_currentBlockInfo->pstmt);
PopBlockInfo();
}
FinishScopeInfo(scopeInfo->GetParent());
}
|
CWE-119
| null | 517,653 |
228753211039622016992521150558841669122
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
IdentPtr Parser::ParseClassPropertyName(IdentPtr * pidHint)
{
if (m_token.tk == tkID || m_token.tk == tkStrCon || m_token.IsReservedWord())
{
IdentPtr pid;
if (m_token.tk == tkStrCon)
{
if (m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
pid = m_token.GetStr();
}
else
{
pid = m_token.GetIdentifier(m_phtbl);
}
*pidHint = pid;
return pid;
}
else if (m_token.tk == tkIntCon)
{
if (m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
return m_pscan->PidFromLong(m_token.GetLong());
}
else if (m_token.tk == tkFltCon)
{
if (m_pscan->IsOctOrLeadingZeroOnLastTKNumber())
{
Error(ERRES5NoOctal);
}
return m_pscan->PidFromDbl(m_token.GetDouble());
}
Error(ERRnoMemberIdent);
}
|
CWE-119
| null | 517,654 |
308623224153443673386866313282539255622
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateUniNode(OpCode nop, ParseNodePtr pnode1)
{
Assert(!this->m_deferringAST);
DebugOnly(VerifyNodeSize(nop, kcbPnUni));
ParseNodePtr pnode = (ParseNodePtr)m_nodeAllocator.Alloc(kcbPnUni);
Assert(m_pCurrentAstSize != nullptr);
*m_pCurrentAstSize += kcbPnUni;
InitNode(nop, pnode);
pnode->sxUni.pnode1 = pnode1;
if (nullptr == pnode1)
{
// no ops
pnode->ichMin = m_pscan->IchMinTok();
pnode->ichLim = m_pscan->IchLimTok();
}
else
{
// 1 op
pnode->ichMin = pnode1->ichMin;
pnode->ichLim = pnode1->ichLim;
this->CheckArguments(pnode);
}
return pnode;
}
|
CWE-119
| null | 517,655 |
138191670430951420587914920377775387654
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::MarkEscapingRef(ParseNodePtr pnode, IdentToken *pToken)
{
if (m_currentNodeFunc == nullptr)
{
return;
}
if (pnode && pnode->nop == knopFncDecl)
{
this->SetNestedFuncEscapes();
}
else if (pToken->pid)
{
PidRefStack *pidRef = pToken->pid->GetTopRef();
if (pidRef->sym)
{
if (pidRef->sym->GetSymbolType() == STFunction)
{
this->SetNestedFuncEscapes();
}
}
else
{
pidRef->isEscape = true;
}
}
}
|
CWE-119
| null | 517,656 |
78934674345960152902945783901616195858
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::ParseFinally()
{
ParseNodePtr pnode = nullptr;
StmtNest stmt;
Assert(tkFINALLY == m_token.tk);
if (buildAST)
{
pnode = CreateNode(knopFinally);
}
m_pscan->Scan();
if (tkLCurly != m_token.tk)
{
Error(ERRnoLcurly);
}
PushStmt<buildAST>(&stmt, pnode, knopFinally, nullptr, nullptr);
ParseNodePtr pnodeBody = ParseStatement<buildAST>();
if (buildAST)
{
pnode->sxFinally.pnodeBody = pnodeBody;
if (!pnode->sxFinally.pnodeBody)
// Will only occur due to error correction.
pnode->sxFinally.pnodeBody = CreateNodeWithScanner<knopEmpty>();
else
pnode->ichLim = pnode->sxFinally.pnodeBody->ichLim;
}
PopStmt(&stmt);
return pnode;
}
|
CWE-119
| null | 517,657 |
255942949597513511522357663869131185030
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::RestoreContext(ParseContext *const parseContext)
{
m_sourceContextInfo = parseContext->sourceContextInfo;
m_currentBlockInfo = parseContext->currentBlockInfo;
m_nextBlockId = parseContext->nextBlockId;
m_grfscr = parseContext->grfscr;
m_length = parseContext->length;
m_pscan->SetText(parseContext->pszSrc, parseContext->offset, parseContext->length, parseContext->characterOffset, parseContext->grfscr, parseContext->lineNumber);
m_currentNodeProg = parseContext->pnodeProg;
m_fUseStrictMode = parseContext->strictMode;
}
|
CWE-119
| null | 517,658 |
8706129012404957895431690317526042969
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void PrintBlockType(PnodeBlockType type)
{
switch (type)
{
case Global:
Output::Print(_u("(Global)"));
break;
case Function:
Output::Print(_u("(Function)"));
break;
case Regular:
Output::Print(_u("(Regular)"));
break;
case Parameter:
Output::Print(_u("(Parameter)"));
break;
default:
Output::Print(_u("(unknown blocktype)"));
break;
}
}
|
CWE-119
| null | 517,659 |
301039998808085108765271451000440099883
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::ParseNestedDeferredFunc(ParseNodePtr pnodeFnc, bool fLambda, bool *pNeedScanRCurly, bool *pStrictModeTurnedOn)
{
// Parse a function nested inside another deferred function.
size_t lengthBeforeBody = this->GetSourceLength();
if (m_token.tk != tkLCurly && fLambda)
{
ParseExpressionLambdaBody<false>(pnodeFnc);
*pNeedScanRCurly = false;
}
else
{
ChkCurTok(tkLCurly, ERRnoLcurly);
bool* detectStrictModeOn = IsStrictMode() ? nullptr : pStrictModeTurnedOn;
m_ppnodeVar = &m_currentNodeDeferredFunc->sxFnc.pnodeVars;
ParseStmtList<false>(nullptr, nullptr, SM_DeferredParse, true /* isSourceElementList */, detectStrictModeOn);
ChkCurTokNoScan(tkRCurly, ERRnoRcurly);
}
pnodeFnc->ichLim = m_pscan->IchLimTok();
pnodeFnc->sxFnc.cbLim = m_pscan->IecpLimTok();
if (*pStrictModeTurnedOn)
{
pnodeFnc->sxFnc.SetStrictMode(true);
}
if (!PHASE_OFF1(Js::SkipNestedDeferredPhase))
{
// Record the end of the function and the function ID increment that happens inside the function.
// Byte code gen will use this to build stub information to allow us to skip this function when the
// enclosing function is fully parsed.
RestorePoint *restorePoint = Anew(&m_nodeAllocator, RestorePoint);
m_pscan->Capture(restorePoint,
*m_nextFunctionId - pnodeFnc->sxFnc.functionId - 1,
lengthBeforeBody - this->GetSourceLength());
pnodeFnc->sxFnc.pRestorePoint = restorePoint;
}
}
|
CWE-119
| null | 517,660 |
298262685405585297821223231186669588713
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::AddVarDeclToBlock(ParseNode *pnode)
{
Assert(pnode->nop == knopConstDecl || pnode->nop == knopLetDecl);
// Maintain a combined list of let and const declarations to keep
// track of declaration order.
AssertMem(m_currentBlockInfo->m_ppnodeLex);
*m_currentBlockInfo->m_ppnodeLex = pnode;
m_currentBlockInfo->m_ppnodeLex = &pnode->sxVar.pnodeNext;
pnode->sxVar.pnodeNext = nullptr;
}
|
CWE-119
| null | 517,661 |
230093647373844293478242840202562754147
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
ParseNodePtr Parser::CreateAsyncSpawnGenerator()
{
ParseNodePtr pnodeFncGenerator = nullptr;
pnodeFncGenerator = CreateDummyFuncNode(false);
pnodeFncGenerator->sxFnc.functionId = (*m_nextFunctionId)++;
pnodeFncGenerator->sxFnc.cbMin = m_pscan->IecpMinTok();
pnodeFncGenerator->sxFnc.cbLim = m_pscan->IecpLimTok();
pnodeFncGenerator->sxFnc.lineNumber = m_pscan->LineCur();
pnodeFncGenerator->sxFnc.columnNumber = CalculateFunctionColumnNumber();
pnodeFncGenerator->sxFnc.SetNested(m_currentNodeFunc != nullptr);
pnodeFncGenerator->sxFnc.SetStrictMode(IsStrictMode());
pnodeFncGenerator->sxFnc.SetIsGenerator();
pnodeFncGenerator->sxFnc.SetIsLambda();
pnodeFncGenerator->sxFnc.scope = nullptr;
AppendFunctionToScopeList(false, pnodeFncGenerator);
return pnodeFncGenerator;
}
|
CWE-119
| null | 517,662 |
323728542041276576895885114450794497205
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void PnPid::SetSymRef(PidRefStack *ref)
{
Assert(symRef == nullptr);
this->symRef = ref->GetSymRef();
}
|
CWE-119
| null | 517,663 |
319782013898598167197037090421788000106
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::AddBackgroundParseItem(BackgroundParseItem *const item)
{
if (currBackgroundParseItem == nullptr)
{
backgroundParseItems = item;
}
else
{
currBackgroundParseItem->SetNext(item);
}
currBackgroundParseItem = item;
}
|
CWE-119
| null | 517,664 |
229322261204850353465266520402342198130
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::PrepareScanner(bool fromExternal)
{
// NOTE: HashTbl and Scanner are currently allocated from the CRT heap. If we want to allocate them from the
// parser arena, then we also need to change the way the HashTbl allocates PID's from its underlying
// allocator (which also currently uses the CRT heap). This is not trivial, because we still need to support
// heap allocation for the colorizer interface.
// create the hash table and init PID members
if (nullptr == (m_phtbl = HashTbl::Create(HASH_TABLE_SIZE, &m_err)))
Error(ERRnoMemory);
InitPids();
// create the scanner
if (nullptr == (m_pscan = Scanner_t::Create(this, m_phtbl, &m_token, &m_err, m_scriptContext)))
Error(ERRnoMemory);
if (fromExternal)
m_pscan->FromExternalSource();
}
|
CWE-119
| null | 517,665 |
10562261345141233750251315934419627805
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::BindPidRefsInScope(IdentPtr pid, Symbol *sym, int blockId, uint maxBlockId)
{
PidRefStack *ref, *nextRef, *lastRef = nullptr;
Js::LocalFunctionId funcId = GetCurrentFunctionNode()->sxFnc.functionId;
Assert(sym);
if (pid->GetIsModuleExport())
{
sym->SetIsModuleExportStorage(true);
}
bool hasFuncAssignment = sym->GetHasFuncAssignment();
bool doesEscape = false;
for (ref = pid->GetTopRef(); ref && ref->GetScopeId() >= blockId; ref = nextRef)
{
// Fix up sym* on PID ref.
Assert(!ref->GetSym() || ref->GetSym() == sym);
nextRef = ref->prev;
Assert(ref->GetScopeId() >= 0);
if ((uint)ref->GetScopeId() > maxBlockId)
{
lastRef = ref;
continue;
}
ref->SetSym(sym);
this->RemovePrevPidRef(pid, lastRef);
if (ref->IsAssignment())
{
sym->PromoteAssignmentState();
if (m_currentNodeFunc && sym->GetIsFormal())
{
m_currentNodeFunc->sxFnc.SetHasAnyWriteToFormals(true);
}
}
if (ref->GetFuncScopeId() != funcId && !sym->GetIsGlobal() && !sym->GetIsModuleExportStorage())
{
Assert(ref->GetFuncScopeId() > funcId);
sym->SetHasNonLocalReference();
}
if (ref->IsFuncAssignment())
{
hasFuncAssignment = true;
}
if (ref->IsEscape())
{
doesEscape = true;
}
if (m_currentNodeFunc && doesEscape && hasFuncAssignment)
{
if (m_sourceContextInfo ?
!PHASE_OFF_RAW(Js::DisableStackFuncOnDeferredEscapePhase, m_sourceContextInfo->sourceContextId, m_currentNodeFunc->sxFnc.functionId) :
!PHASE_OFF1(Js::DisableStackFuncOnDeferredEscapePhase))
{
m_currentNodeFunc->sxFnc.SetNestedFuncEscapes();
}
}
if (ref->GetScopeId() == blockId)
{
break;
}
}
}
|
CWE-119
| null | 517,666 |
337191254868600743626618268195221186486
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::CheckPidIsValid(IdentPtr pid, bool autoArgumentsObject)
{
if (IsStrictMode())
{
// in strict mode, variable named 'eval' cannot be created
if (pid == wellKnownPropertyPids.eval)
{
Error(ERREvalUsage);
}
else if (pid == wellKnownPropertyPids.arguments && !autoArgumentsObject)
{
Error(ERRArgsUsage);
}
}
}
|
CWE-119
| null | 517,667 |
100898688942998395356383672247243596296
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
bool Parser::ParseFncNames(ParseNodePtr pnodeFnc, ParseNodePtr pnodeFncParent, ushort flags, ParseNodePtr **pLastNodeRef)
{
BOOL fDeclaration = flags & fFncDeclaration;
BOOL fIsAsync = flags & fFncAsync;
ParseNodePtr pnodeT;
charcount_t ichMinNames, ichLimNames;
// Get the names to bind to.
/*
* KaushiS [5/15/08]:
* ECMAScript defines a FunctionExpression as follows:
*
* "function" [Identifier] ( [FormalParameterList] ) { FunctionBody }
*
* The function name being optional is omitted by most real world
* code that uses a FunctionExpression to define a function. This however
* is problematic for tools because there isn't a function name that
* the runtime can provide.
*
* To fix this (primarily for the profiler), I'm adding simple, static
* name inferencing logic to the parser. When it encounters the following
* productions
*
* "var" Identifier "=" FunctionExpression
* "var" IdentifierA.IdentifierB...Identifier "=" FunctionExpression
* Identifier = FunctionExpression
* "{" Identifier: FunctionExpression "}"
*
* it associates Identifier with the function created by the
* FunctionExpression. This identifier is *not* the function's name. It
* is ignored by the runtime and is only an additional piece of information
* about the function (function name hint) that tools could opt to
* surface.
*/
m_pscan->Scan();
// If generators are enabled then we are in a recent enough version
// that deferred parsing will create a parse node for pnodeFnc and
// it is safe to assume it is not null.
if (flags & fFncGenerator)
{
Assert(m_scriptContext->GetConfig()->IsES6GeneratorsEnabled());
pnodeFnc->sxFnc.SetIsGenerator();
}
else if (m_scriptContext->GetConfig()->IsES6GeneratorsEnabled() &&
m_token.tk == tkStar &&
!(flags & fFncClassMember))
{
if (!fDeclaration)
{
bool fPreviousYieldIsKeyword = m_pscan->SetYieldIsKeyword(!fDeclaration);
m_pscan->Scan();
m_pscan->SetYieldIsKeyword(fPreviousYieldIsKeyword);
}
else
{
m_pscan->Scan();
}
pnodeFnc->sxFnc.SetIsGenerator();
}
if (fIsAsync)
{
if (pnodeFnc->sxFnc.IsGenerator())
{
Error(ERRsyntax);
}
pnodeFnc->sxFnc.SetIsAsync();
}
if (pnodeFnc)
{
pnodeFnc->sxFnc.pnodeName = nullptr;
}
if ((m_token.tk != tkID || flags & fFncNoName)
&& (IsStrictMode() || (pnodeFnc && pnodeFnc->sxFnc.IsGenerator()) || m_token.tk != tkYIELD || fDeclaration)) // Function expressions can have the name yield even inside generator functions
{
if (fDeclaration ||
m_token.IsReservedWord()) // For example: var x = (function break(){});
{
IdentifierExpectedError(m_token);
}
return false;
}
ichMinNames = m_pscan->IchMinTok();
Assert(m_token.tk == tkID || (m_token.tk == tkYIELD && !fDeclaration));
if (IsStrictMode())
{
CheckStrictModeEvalArgumentsUsage(m_token.GetIdentifier(m_phtbl));
}
Token tokenBase = m_token;
charcount_t ichMinBase = m_pscan->IchMinTok();
charcount_t ichLimBase = m_pscan->IchLimTok();
m_pscan->Scan();
IdentPtr pidBase = tokenBase.GetIdentifier(m_phtbl);
pnodeT = CreateDeclNode(knopVarDecl, pidBase, STFunction);
pnodeT->ichMin = ichMinBase;
pnodeT->ichLim = ichLimBase;
if (fDeclaration &&
pnodeFncParent &&
pnodeFncParent->sxFnc.pnodeName &&
pnodeFncParent->sxFnc.pnodeName->nop == knopVarDecl &&
pnodeFncParent->sxFnc.pnodeName->sxVar.pid == pidBase)
{
pnodeFncParent->sxFnc.SetNameIsHidden();
}
if (buildAST)
{
AnalysisAssert(pnodeFnc);
ichLimNames = pnodeT->ichLim;
AddToNodeList(&pnodeFnc->sxFnc.pnodeName, pLastNodeRef, pnodeT);
pnodeFnc->sxFnc.pnodeName->ichMin = ichMinNames;
pnodeFnc->sxFnc.pnodeName->ichLim = ichLimNames;
if (knopVarDecl == pnodeFnc->sxFnc.pnodeName->nop)
{
// Only one name (the common case).
pnodeFnc->sxFnc.pid = pnodeFnc->sxFnc.pnodeName->sxVar.pid;
}
else
{
// Multiple names. Turn the source into an IdentPtr.
pnodeFnc->sxFnc.pid = m_phtbl->PidHashNameLen(
m_pscan->PchBase() + ichMinNames,
m_pscan->AdjustedLast(),
ichLimNames - ichMinNames);
}
}
return true;
}
|
CWE-119
| null | 517,668 |
326403180727992395901201036937395459694
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
HRESULT Parser::ParseFunctionInBackground(ParseNodePtr pnodeFnc, ParseContext *parseContext, bool topLevelDeferred, CompileScriptException *pse)
{
m_functionBody = nullptr;
m_parseType = ParseType_Upfront;
HRESULT hr = S_OK;
SmartFPUControl smartFpuControl;
uint nextFunctionId = pnodeFnc->sxFnc.functionId + 1;
this->RestoreContext(parseContext);
DebugOnly( m_err.fInited = TRUE; )
m_nextFunctionId = &nextFunctionId;
m_deferringAST = topLevelDeferred;
m_inDeferredNestedFunc = false;
m_scopeCountNoAst = 0;
SetCurrentStatement(nullptr);
pnodeFnc->sxFnc.pnodeVars = nullptr;
pnodeFnc->sxFnc.pnodeParams = nullptr;
pnodeFnc->sxFnc.pnodeBody = nullptr;
pnodeFnc->sxFnc.nestedCount = 0;
ParseNodePtr pnodeParentFnc = GetCurrentFunctionNode();
m_currentNodeFunc = pnodeFnc;
m_currentNodeDeferredFunc = nullptr;
m_ppnodeScope = nullptr;
m_ppnodeExprScope = nullptr;
m_pnestedCount = &pnodeFnc->sxFnc.nestedCount;
m_pCurrentAstSize = &pnodeFnc->sxFnc.astSize;
ParseNodePtr pnodeBlock = StartParseBlock<true>(PnodeBlockType::Function, ScopeType_FunctionBody);
pnodeFnc->sxFnc.pnodeScopes = pnodeBlock;
m_ppnodeScope = &pnodeBlock->sxBlock.pnodeScopes;
uint uDeferSave = m_grfscr & fscrDeferFncParse;
try
{
m_pscan->Scan();
m_ppnodeVar = &pnodeFnc->sxFnc.pnodeParams;
this->ParseFncFormals<true>(pnodeFnc, pnodeParentFnc, fFncNoFlgs);
if (m_token.tk == tkRParen)
{
m_pscan->Scan();
}
ChkCurTok(tkLCurly, ERRnoLcurly);
m_ppnodeVar = &pnodeFnc->sxFnc.pnodeVars;
// Put the scanner into "no hashing" mode.
BYTE deferFlags = m_pscan->SetDeferredParse(topLevelDeferred);
// Process a sequence of statements/declarations
if (topLevelDeferred)
{
ParseStmtList<false>(nullptr, nullptr, SM_DeferredParse, true);
}
else
{
ParseNodePtr *lastNodeRef = nullptr;
ParseStmtList<true>(&pnodeFnc->sxFnc.pnodeBody, &lastNodeRef, SM_OnFunctionCode, true);
AddArgumentsNodeToVars(pnodeFnc);
// Append an EndCode node.
AddToNodeList(&pnodeFnc->sxFnc.pnodeBody, &lastNodeRef, CreateNodeWithScanner<knopEndCode>());
}
// Restore the scanner's default hashing mode.
m_pscan->SetDeferredParseFlags(deferFlags);
#if DBG
pnodeFnc->sxFnc.deferredParseNextFunctionId = *this->m_nextFunctionId;
#endif
this->m_deferringAST = FALSE;
// Append block as body of pnodeProg
FinishParseBlock(pnodeBlock);
}
catch(ParseExceptionObject& e)
{
m_err.m_hr = e.GetError();
hr = pse->ProcessError( m_pscan, m_err.m_hr, nullptr);
}
if (IsStrictMode())
{
pnodeFnc->sxFnc.SetStrictMode();
}
if (topLevelDeferred)
{
pnodeFnc->sxFnc.pnodeVars = nullptr;
}
m_grfscr |= uDeferSave;
Assert(nullptr == *m_ppnodeScope);
return hr;
}
|
CWE-119
| null | 517,669 |
305465059599452594470836029508066597672
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::FinishParseFncExprScope(ParseNodePtr pnodeFnc, ParseNodePtr pnodeFncExprScope)
{
int fncExprScopeId = pnodeFncExprScope->sxBlock.blockId;
ParseNodePtr pnodeName = pnodeFnc->sxFnc.pnodeName;
if (pnodeName)
{
Assert(pnodeName->nop == knopVarDecl);
BindPidRefsInScope(pnodeName->sxVar.pid, pnodeName->sxVar.sym, fncExprScopeId);
}
FinishParseBlock(pnodeFncExprScope);
}
|
CWE-119
| null | 517,670 |
180216769957580000455529792337391628801
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
void Parser::UpdateOrCheckForDuplicateInFormals(IdentPtr pid, SList<IdentPtr> *formals)
{
bool isStrictMode = IsStrictMode();
if (isStrictMode)
{
CheckStrictModeEvalArgumentsUsage(pid);
}
if (formals->Has(pid))
{
if (isStrictMode)
{
Error(ERRES5ArgSame);
}
else
{
Error(ERRFormalSame);
}
}
else
{
formals->Prepend(pid);
}
}
|
CWE-119
| null | 517,671 |
236606538714944293717488928614010871551
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
BOOL Parser::PnodeLabelNoAST(IdentToken* pToken, LabelId* pLabelIdList)
{
StmtNest* pStmt;
LabelId* pLabelId;
// Look in the label stack.
for (pStmt = m_pstmtCur; pStmt != nullptr; pStmt = pStmt->pstmtOuter)
{
for (pLabelId = pStmt->pLabelId; pLabelId != nullptr; pLabelId = pLabelId->next)
{
if (pLabelId->pid == pToken->pid)
return TRUE;
}
}
// Also look in the pnodeLabels list.
for (pLabelId = pLabelIdList; pLabelId != nullptr; pLabelId = pLabelId->next)
{
if (pLabelId->pid == pToken->pid)
return TRUE;
}
return FALSE;
}
|
CWE-119
| null | 517,672 |
200321652002083468393309978770496775506
| null | null |
other
|
ChakraCore
|
402f3d967c0a905ec5b9ca9c240783d3f2c15724
| 0 |
bool Parser::CheckAsmjsModeStrPid(IdentPtr pid)
{
#ifdef ASMJS_PLAT
if (!CONFIG_FLAG_RELEASE(Asmjs))
{
return false;
}
bool isAsmCandidate = (pid != nullptr &&
AutoSystemInfo::Data.SSE2Available() &&
pid->Cch() == 7 &&
!m_pscan->IsEscapeOnLastTkStrCon() &&
wcsncmp(pid->Psz(), _u("use asm"), 10) == 0);
if (isAsmCandidate && m_scriptContext->IsScriptContextInDebugMode())
{
// We would like to report this to debugger - they may choose to disable debugging.
// TODO : localization of the string?
m_scriptContext->RaiseMessageToDebugger(DEIT_ASMJS_IN_DEBUGGING, _u("AsmJs initialization error - AsmJs disabled due to script debugger"), !m_sourceContextInfo->IsDynamic() ? m_sourceContextInfo->url : nullptr);
return false;
}
return isAsmCandidate && !(m_grfscr & fscrNoAsmJs);
#else
return false;
#endif
}
|
CWE-119
| null | 517,673 |
311285600005552401062581010234795971771
| null | null |
other
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.