ByteCodeGenerator.h 19 KB

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