ByteCodeGenerator.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #if defined(_M_ARM32_OR_ARM64) || defined(_M_X64)
  6. const int32 AstBytecodeRatioEstimate = 4;
  7. #else
  8. const int32 AstBytecodeRatioEstimate = 5;
  9. #endif
  10. class ByteCodeGenerator
  11. {
  12. private:
  13. Js::ScriptContext* scriptContext;
  14. ArenaAllocator *alloc;
  15. uint32 flags;
  16. Js::PropertyRecordList* propertyRecords;
  17. SList<FuncInfo*> *funcInfoStack;
  18. ParseNode *currentBlock;
  19. ParseNode *currentTopStatement;
  20. Scope *currentScope;
  21. Scope *globalScope; // the global members will be in this scope
  22. Js::ScopeInfo* parentScopeInfo;
  23. Js::ByteCodeWriter m_writer;
  24. // pointer to the root function wrapper that will be invoked by the caller
  25. Js::ParseableFunctionInfo * pRootFunc;
  26. SList<FuncInfo*> * funcInfosToFinalize;
  27. int32 maxAstSize;
  28. uint16 envDepth;
  29. uint sourceIndex;
  30. uint dynamicScopeCount;
  31. uint loopDepth;
  32. uint16 m_callSiteId;
  33. bool isBinding;
  34. bool trackEnvDepth;
  35. bool funcEscapes;
  36. bool inPrologue;
  37. bool inDestructuredPattern;
  38. Parser* parser; // currently active parser (used for AST transformation)
  39. Js::Utf8SourceInfo *m_utf8SourceInfo;
  40. // The stack walker won't be able to find the current function being defer parse, pass in
  41. // The address so we can patch it up if it is a stack function and we need to box it.
  42. Js::ScriptFunction ** functionRef;
  43. public:
  44. // This points to the current function body which can be reused when parsing a subtree (called due to deferred parsing logic).
  45. Js::FunctionBody * pCurrentFunction;
  46. bool InDestructuredPattern() const { return inDestructuredPattern; }
  47. void SetInDestructuredPattern(bool in) { inDestructuredPattern = in; }
  48. bool InPrologue() const { return inPrologue; }
  49. void SetInPrologue(bool val) { inPrologue = val; }
  50. Parser* GetParser() { return parser; }
  51. Js::ParseableFunctionInfo * GetRootFunc(){return pRootFunc;}
  52. void SetRootFuncInfo(FuncInfo* funcInfo);
  53. // Treat the return value register like a constant register so that the byte code writer maps it to the bottom
  54. // of the register range.
  55. static const Js::RegSlot ReturnRegister = REGSLOT_TO_CONSTREG(Js::FunctionBody::ReturnValueRegSlot);
  56. static const Js::RegSlot RootObjectRegister = REGSLOT_TO_CONSTREG(Js::FunctionBody::RootObjectRegSlot);
  57. static const unsigned int DefaultArraySize = 0; // This __must__ be '0' so that "(new Array()).length == 0"
  58. static const unsigned int MinArgumentsForCallOptimization = 16;
  59. bool forceNoNative;
  60. ByteCodeGenerator(Js::ScriptContext* scriptContext, Js::ScopeInfo* parentScopeInfo);
  61. #if DBG_DUMP
  62. bool Trace() const
  63. {
  64. return Js::Configuration::Global.flags.Trace.IsEnabled(Js::ByteCodePhase);
  65. }
  66. #else
  67. bool Trace() const
  68. {
  69. return false;
  70. }
  71. #endif
  72. Js::ScriptContext* GetScriptContext() { return scriptContext; }
  73. Scope *GetCurrentScope() const { return currentScope; }
  74. void SetCurrentBlock(ParseNode *pnode) { currentBlock = pnode; }
  75. ParseNode *GetCurrentBlock() const { return currentBlock; }
  76. void SetCurrentTopStatement(ParseNode *pnode) { currentTopStatement = pnode; }
  77. ParseNode *GetCurrentTopStatement() const { return currentTopStatement; }
  78. Js::ModuleID GetModuleID() const
  79. {
  80. return m_utf8SourceInfo->GetSrcInfo()->moduleID;
  81. }
  82. void SetFlags(uint32 grfscr)
  83. {
  84. flags = grfscr;
  85. }
  86. uint32 GetFlags(void)
  87. {
  88. return flags;
  89. }
  90. bool IsConsoleScopeEval(void)
  91. {
  92. return (flags & fscrConsoleScopeEval) == fscrConsoleScopeEval;
  93. }
  94. bool IsModuleCode()
  95. {
  96. return (flags & fscrIsModuleCode) == fscrIsModuleCode;
  97. }
  98. bool IsBinding() const {
  99. return isBinding;
  100. }
  101. Js::ByteCodeWriter *Writer() {
  102. return &m_writer;
  103. }
  104. ArenaAllocator *GetAllocator() {
  105. return alloc;
  106. }
  107. Js::PropertyRecordList* EnsurePropertyRecordList()
  108. {
  109. if (this->propertyRecords == nullptr)
  110. {
  111. Recycler* recycler = this->scriptContext->GetRecycler();
  112. this->propertyRecords = RecyclerNew(recycler, Js::PropertyRecordList, recycler);
  113. }
  114. return this->propertyRecords;
  115. }
  116. bool IsEvalWithNoParentScopeInfo()
  117. {
  118. return (flags & fscrEvalCode) && !HasParentScopeInfo();
  119. }
  120. Js::ProfileId GetNextCallSiteId(Js::OpCode op)
  121. {
  122. if (m_writer.ShouldIncrementCallSiteId(op))
  123. {
  124. if (m_callSiteId != Js::Constants::NoProfileId)
  125. {
  126. return m_callSiteId++;
  127. }
  128. }
  129. return m_callSiteId;
  130. }
  131. Js::ProfileId GetCurrentCallSiteId() { return m_callSiteId; }
  132. Js::RegSlot NextVarRegister();
  133. Js::RegSlot NextConstRegister();
  134. FuncInfo *TopFuncInfo() const;
  135. void EnterLoop();
  136. void ExitLoop() { loopDepth--; }
  137. BOOL IsInLoop() const { return loopDepth > 0; }
  138. // TODO: per-function register assignment for env and global symbols
  139. void AssignRegister(Symbol *sym);
  140. void AddTargetStmt(ParseNode *pnodeStmt);
  141. Js::RegSlot AssignNullConstRegister();
  142. Js::RegSlot AssignUndefinedConstRegister();
  143. Js::RegSlot AssignTrueConstRegister();
  144. Js::RegSlot AssignFalseConstRegister();
  145. Js::RegSlot AssignThisConstRegister();
  146. void SetNeedEnvRegister();
  147. void AssignFrameObjRegister();
  148. void AssignFrameSlotsRegister();
  149. void AssignParamSlotsRegister();
  150. void AssignFrameDisplayRegister();
  151. void ProcessCapturedSym(Symbol *sym);
  152. void ProcessScopeWithCapturedSym(Scope *scope);
  153. void InitScopeSlotArray(FuncInfo * funcInfo);
  154. void FinalizeRegisters(FuncInfo * funcInfo, Js::FunctionBody * byteCodeFunction);
  155. void SetClosureRegisters(FuncInfo * funcInfo, Js::FunctionBody * byteCodeFunction);
  156. void SetHasTry(bool has);
  157. void SetHasFinally(bool has);
  158. void SetNumberOfInArgs(Js::ArgSlot argCount);
  159. Js::RegSlot EnregisterConstant(unsigned int constant);
  160. Js::RegSlot EnregisterStringConstant(IdentPtr pid);
  161. Js::RegSlot EnregisterDoubleConstant(double d);
  162. Js::RegSlot EnregisterStringTemplateCallsiteConstant(ParseNode* pnode);
  163. static Js::JavascriptArray* BuildArrayFromStringList(ParseNode* stringNodeList, uint arrayLength, Js::ScriptContext* scriptContext);
  164. bool HasParentScopeInfo() const
  165. {
  166. return this->parentScopeInfo != nullptr;
  167. }
  168. Js::RegSlot EmitLdObjProto(Js::OpCode op, Js::RegSlot objReg, FuncInfo *funcInfo)
  169. {
  170. // LdHomeObjProto protoReg, objReg
  171. // LdFuncObjProto protoReg, objReg
  172. Js::RegSlot protoReg = funcInfo->AcquireTmpRegister();
  173. this->Writer()->Reg2(op, protoReg, objReg);
  174. funcInfo->ReleaseTmpRegister(protoReg);
  175. return protoReg;
  176. }
  177. void RestoreScopeInfo(Js::ScopeInfo *scopeInfo, FuncInfo * func);
  178. void RestoreOneScope(Js::ScopeInfo * scopeInfo, FuncInfo * func);
  179. FuncInfo *StartBindGlobalStatements(ParseNode *pnode);
  180. void AssignPropertyId(Symbol *sym, Js::ParseableFunctionInfo* functionInfo);
  181. void AssignPropertyId(IdentPtr pid);
  182. void ProcessCapturedSyms(ParseNode *pnodeFnc);
  183. void RecordAllIntConstants(FuncInfo * funcInfo);
  184. void RecordAllStrConstants(FuncInfo * funcInfo);
  185. void RecordAllStringTemplateCallsiteConstants(FuncInfo* funcInfo);
  186. // For now, this just assigns field ids for the current script.
  187. // Later, we will combine this information with the global field ID map.
  188. // This temporary code will not work if a global member is accessed both with and without a LHS.
  189. void AssignPropertyIds(Js::ParseableFunctionInfo* functionInfo);
  190. void MapCacheIdsToPropertyIds(FuncInfo *funcInfo);
  191. void MapReferencedPropertyIds(FuncInfo *funcInfo);
  192. FuncInfo *StartBindFunction(const char16 *name, uint nameLength, uint shortNameOffset, bool* pfuncExprWithName, ParseNode *pnode, Js::ParseableFunctionInfo * reuseNestedFunc);
  193. void EndBindFunction(bool funcExprWithName);
  194. void StartBindCatch(ParseNode *pnode);
  195. // Block scopes related functions
  196. template<class Fn> void IterateBlockScopedVariables(ParseNode *pnodeBlock, Fn fn);
  197. void InitBlockScopedContent(ParseNode *pnodeBlock, Js::DebuggerScope *debuggerScope, FuncInfo *funcInfo);
  198. Js::DebuggerScope* RecordStartScopeObject(ParseNode *pnodeBlock, Js::DiagExtraScopesType scopeType, Js::RegSlot scopeLocation = Js::Constants::NoRegister, int* index = nullptr);
  199. void RecordEndScopeObject(ParseNode *pnodeBlock);
  200. void EndBindCatch();
  201. void StartEmitFunction(ParseNode *pnodeFnc);
  202. void EndEmitFunction(ParseNode *pnodeFnc);
  203. void StartEmitBlock(ParseNode *pnodeBlock);
  204. void EndEmitBlock(ParseNode *pnodeBlock);
  205. void StartEmitCatch(ParseNode *pnodeCatch);
  206. void EndEmitCatch(ParseNode *pnodeCatch);
  207. void StartEmitWith(ParseNode *pnodeWith);
  208. void EndEmitWith(ParseNode *pnodeWith);
  209. void EnsureFncScopeSlots(ParseNode *pnode, FuncInfo *funcInfo);
  210. void EnsureLetConstScopeSlots(ParseNode *pnodeBlock, FuncInfo *funcInfo);
  211. bool EnsureSymbolModuleSlots(Symbol* sym, FuncInfo* funcInfo);
  212. void EmitAssignmentToDefaultModuleExport(ParseNode* pnode, FuncInfo* funcInfo);
  213. void EmitModuleExportAccess(Symbol* sym, Js::OpCode opcode, Js::RegSlot location, FuncInfo* funcInfo);
  214. void PushScope(Scope *innerScope);
  215. void PopScope();
  216. void PushBlock(ParseNode *pnode);
  217. void PopBlock();
  218. void PushFuncInfo(char16 const * location, FuncInfo* funcInfo);
  219. void PopFuncInfo(char16 const * location);
  220. Js::RegSlot PrependLocalScopes(Js::RegSlot evalEnv, Js::RegSlot tempLoc, FuncInfo *funcInfo);
  221. Symbol *FindSymbol(Symbol **symRef, IdentPtr pid, bool forReference = false);
  222. Symbol *AddSymbolToScope(Scope *scope, const char16 *key, int keyLength, ParseNode *varDecl, SymbolType symbolType);
  223. Symbol *AddSymbolToFunctionScope(const char16 *key, int keyLength, ParseNode *varDecl, SymbolType symbolType);
  224. void FuncEscapes(Scope *scope);
  225. void EmitTopLevelStatement(ParseNode *stmt, FuncInfo *funcInfo, BOOL fReturnValue);
  226. void EmitInvertedLoop(ParseNode* outerLoop,ParseNode* invertedLoop,FuncInfo* funcInfo);
  227. void DefineFunctions(FuncInfo *funcInfoParent);
  228. Js::RegSlot DefineOneFunction(ParseNode *pnodeFnc, FuncInfo *funcInfoParent, bool generateAssignment=true, Js::RegSlot regEnv = Js::Constants::NoRegister, Js::RegSlot frameDisplayTemp = Js::Constants::NoRegister);
  229. void DefineCachedFunctions(FuncInfo *funcInfoParent);
  230. void DefineUncachedFunctions(FuncInfo *funcInfoParent);
  231. void DefineUserVars(FuncInfo *funcInfo);
  232. void InitBlockScopedNonTemps(ParseNode *pnode, FuncInfo *funcInfo);
  233. // temporarily load all constants and special registers in a single block
  234. void LoadAllConstants(FuncInfo *funcInfo);
  235. void LoadHeapArguments(FuncInfo *funcInfo);
  236. void LoadUncachedHeapArguments(FuncInfo *funcInfo);
  237. void LoadCachedHeapArguments(FuncInfo *funcInfo);
  238. void LoadThisObject(FuncInfo *funcInfo, bool thisLoadedFromParams = false);
  239. void EmitThis(FuncInfo *funcInfo, Js::RegSlot lhsLocation, Js::RegSlot fromRegister);
  240. void LoadNewTargetObject(FuncInfo *funcInfo);
  241. void LoadSuperObject(FuncInfo *funcInfo);
  242. void LoadSuperConstructorObject(FuncInfo *funcInfo);
  243. void EmitSuperCall(FuncInfo* funcInfo, ParseNode* pnode, BOOL fReturnValue);
  244. void EmitClassConstructorEndCode(FuncInfo *funcInfo);
  245. void EmitBaseClassConstructorThisObject(FuncInfo *funcInfo);
  246. // TODO: home the 'this' argument
  247. void EmitLoadFormalIntoRegister(ParseNode *pnodeFormal, Js::RegSlot pos, FuncInfo *funcInfo);
  248. void HomeArguments(FuncInfo *funcInfo);
  249. void EnsureNoRedeclarations(ParseNode *pnodeBlock, FuncInfo *funcInfo);
  250. void DefineLabels(FuncInfo *funcInfo);
  251. void EmitProgram(ParseNode *pnodeProg);
  252. void EmitScopeList(ParseNode *pnode, ParseNode *breakOnBodyScopeNode = nullptr);
  253. void EmitDefaultArgs(FuncInfo *funcInfo, ParseNode *pnode);
  254. void EmitOneFunction(ParseNode *pnode);
  255. void EmitGlobalFncDeclInit(Js::RegSlot rhsLocation, Js::PropertyId propertyId, FuncInfo * funcInfo);
  256. void EmitLocalPropInit(Js::RegSlot rhsLocation, Symbol *sym, FuncInfo *funcInfo);
  257. void EmitPropStore(Js::RegSlot rhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo, bool isLet = false, bool isConst = false, bool isFncDeclVar = false, bool skipUseBeforeDeclarationCheck = false);
  258. void EmitPropLoad(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo, bool skipUseBeforeDeclarationCheck = false);
  259. void EmitPropDelete(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo);
  260. void EmitPropTypeof(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo);
  261. void EmitTypeOfFld(FuncInfo * funcInfo, Js::PropertyId propertyId, Js::RegSlot value, Js::RegSlot instance, Js::OpCode op1);
  262. bool ShouldLoadConstThis(FuncInfo* funcInfo);
  263. void EmitPropLoadThis(Js::RegSlot lhsLocation, ParseNode *pnode, FuncInfo *funcInfo, bool chkUndecl);
  264. void EmitPropStoreForSpecialSymbol(Js::RegSlot rhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo, bool init);
  265. void EmitLoadInstance(Symbol *sym, IdentPtr pid, Js::RegSlot *pThisLocation, Js::RegSlot *pTargetLocation, FuncInfo *funcInfo);
  266. void EmitGlobalBody(FuncInfo *funcInfo);
  267. void EmitFunctionBody(FuncInfo *funcInfo);
  268. void EmitAsmFunctionBody(FuncInfo *funcInfo);
  269. void EmitScopeObjectInit(FuncInfo *funcInfo);
  270. void EmitPatchableRootProperty(Js::OpCode opcode, Js::RegSlot regSlot, Js::PropertyId propertyId, bool isLoadMethod, bool isStore, FuncInfo *funcInfo);
  271. struct TryScopeRecord;
  272. JsUtil::DoublyLinkedList<TryScopeRecord> tryScopeRecordsList;
  273. void EmitLeaveOpCodesBeforeYield();
  274. void EmitTryBlockHeadersAfterYield();
  275. void InvalidateCachedOuterScopes(FuncInfo *funcInfo);
  276. bool InDynamicScope() const { return dynamicScopeCount != 0; }
  277. Scope * FindScopeForSym(Scope *symScope, Scope *scope, Js::PropertyId *envIndex, FuncInfo *funcInfo) const;
  278. static Js::OpCode GetStFldOpCode(bool isStrictMode, bool isRoot, bool isLetDecl, bool isConstDecl, bool isClassMemberInit)
  279. {
  280. return isClassMemberInit ? Js::OpCode::InitClassMember :
  281. isConstDecl ? (isRoot ? Js::OpCode::InitRootConstFld : Js::OpCode::InitConstFld) :
  282. isLetDecl ? (isRoot ? Js::OpCode::InitRootLetFld : Js::OpCode::InitLetFld) :
  283. isStrictMode ? (isRoot ? Js::OpCode::StRootFldStrict : Js::OpCode::StFldStrict) :
  284. isRoot ? Js::OpCode::StRootFld : Js::OpCode::StFld;
  285. }
  286. static Js::OpCode GetStFldOpCode(FuncInfo* funcInfo, bool isRoot, bool isLetDecl, bool isConstDecl, bool isClassMemberInit);
  287. static Js::OpCode GetScopedStFldOpCode(bool isStrictMode, bool isConsoleScope = false)
  288. {
  289. return isStrictMode ?
  290. (isConsoleScope ? Js::OpCode::ConsoleScopedStFldStrict : Js::OpCode::ScopedStFldStrict) :
  291. (isConsoleScope ? Js::OpCode::ConsoleScopedStFld : Js::OpCode::ScopedStFld);
  292. }
  293. static Js::OpCode GetScopedStFldOpCode(FuncInfo* funcInfo, bool isConsoleScopeLetConst = false);
  294. static Js::OpCode GetStElemIOpCode(bool isStrictMode)
  295. {
  296. return isStrictMode ? Js::OpCode::StElemI_A_Strict : Js::OpCode::StElemI_A;
  297. }
  298. static Js::OpCode GetStElemIOpCode(FuncInfo* funcInfo);
  299. bool DoJitLoopBodies(FuncInfo *funcInfo) const;
  300. static void Generate(__in ParseNode *pnode, uint32 grfscr, __in ByteCodeGenerator* byteCodeGenerator, __inout Js::ParseableFunctionInfo ** ppRootFunc, __in uint sourceIndex, __in bool forceNoNative, __in Parser* parser, Js::ScriptFunction ** functionRef);
  301. void Begin(
  302. __in ArenaAllocator *alloc,
  303. __in uint32 grfscr,
  304. __in Js::ParseableFunctionInfo* pRootFunc);
  305. void SetCurrentSourceIndex(uint sourceIndex) { this->sourceIndex = sourceIndex; }
  306. uint GetCurrentSourceIndex() { return sourceIndex; }
  307. static bool IsFalse(ParseNode* node);
  308. static bool IsThis(ParseNode* pnode);
  309. static bool IsSuper(ParseNode* pnode);
  310. void StartStatement(ParseNode* node);
  311. void EndStatement(ParseNode* node);
  312. void StartSubexpression(ParseNode* node);
  313. void EndSubexpression(ParseNode* node);
  314. bool IsES6DestructuringEnabled() const;
  315. bool IsES6ForLoopSemanticsEnabled() const;
  316. // Debugger methods.
  317. bool IsInDebugMode() const;
  318. bool IsInNonDebugMode() const;
  319. bool ShouldTrackDebuggerMetadata() const;
  320. void TrackRegisterPropertyForDebugger(Js::DebuggerScope *debuggerScope, Symbol *symbol, FuncInfo *funcInfo, Js::DebuggerScopePropertyFlags flags = Js::DebuggerScopePropertyFlags_None, bool isFunctionDeclaration = false);
  321. void TrackActivationObjectPropertyForDebugger(Js::DebuggerScope *debuggerScope, Symbol *symbol, Js::DebuggerScopePropertyFlags flags = Js::DebuggerScopePropertyFlags_None, bool isFunctionDeclaration = false);
  322. void TrackSlotArrayPropertyForDebugger(Js::DebuggerScope *debuggerScope, Symbol* symbol, Js::PropertyId propertyId, Js::DebuggerScopePropertyFlags flags = Js::DebuggerScopePropertyFlags_None, bool isFunctionDeclaration = false);
  323. void TrackFunctionDeclarationPropertyForDebugger(Symbol *functionDeclarationSymbol, FuncInfo *funcInfoParent);
  324. void UpdateDebuggerPropertyInitializationOffset(Js::RegSlot location, Js::PropertyId propertyId, bool shouldConsumeRegister = true);
  325. void PopulateFormalsScope(uint beginOffset, FuncInfo *funcInfo, ParseNode *pnode);
  326. void InsertPropertyToDebuggerScope(FuncInfo* funcInfo, Js::DebuggerScope* debuggerScope, Symbol* sym);
  327. FuncInfo *FindEnclosingNonLambda();
  328. bool CanStackNestedFunc(FuncInfo * funcInfo, bool trace = false);
  329. void CheckDeferParseHasMaybeEscapedNestedFunc();
  330. bool NeedObjectAsFunctionScope(FuncInfo * funcInfo, ParseNode * pnodeFnc) const;
  331. bool HasInterleavingDynamicScope(Symbol * sym) const;
  332. Js::FunctionBody *EnsureFakeGlobalFuncForUndefer(ParseNode *pnode);
  333. Js::FunctionBody *MakeGlobalFunctionBody(ParseNode *pnode);
  334. bool NeedScopeObjectForArguments(FuncInfo *funcInfo, ParseNode *pnodeFnc) const;
  335. void AddFuncInfoToFinalizationSet(FuncInfo *funcInfo);
  336. void FinalizeFuncInfos();
  337. void CheckFncDeclScopeSlot(ParseNode *pnodeFnc, FuncInfo *funcInfo);
  338. void EnsureFncDeclScopeSlot(ParseNode *pnodeFnc, FuncInfo *funcInfo);
  339. Js::OpCode GetStSlotOp(Scope *scope, int envIndex, Js::RegSlot scopeLocation, bool chkBlockVar, FuncInfo *funcInfo);
  340. Js::OpCode GetLdSlotOp(Scope *scope, int envIndex, Js::RegSlot scopeLocation, FuncInfo *funcInfo);
  341. Js::OpCode GetInitFldOp(Scope *scope, Js::RegSlot scopeLocation, FuncInfo *funcInfo, bool letDecl = false);
  342. private:
  343. bool NeedCheckBlockVar(Symbol* sym, Scope* scope, FuncInfo* funcInfo) const;
  344. Js::OpCode ToChkUndeclOp(Js::OpCode op) const;
  345. };
  346. template<class Fn> void ByteCodeGenerator::IterateBlockScopedVariables(ParseNode *pnodeBlock, Fn fn)
  347. {
  348. Assert(pnodeBlock->nop == knopBlock);
  349. for (auto lexvar = pnodeBlock->sxBlock.pnodeLexVars; lexvar; lexvar = lexvar->sxVar.pnodeNext)
  350. {
  351. fn(lexvar);
  352. }
  353. }
  354. struct ApplyCheck {
  355. bool matches;
  356. bool insideApplyCall;
  357. bool sawApply;
  358. };