ByteCodeGenerator.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. 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(ParseNode *pnode) { currentBlock = pnode; }
  74. ParseNode *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. Js::PropertyRecordList* EnsurePropertyRecordList()
  107. {
  108. if (this->propertyRecords == nullptr)
  109. {
  110. Recycler* recycler = this->scriptContext->GetRecycler();
  111. this->propertyRecords = RecyclerNew(recycler, Js::PropertyRecordList, recycler);
  112. }
  113. return this->propertyRecords;
  114. }
  115. bool IsEvalWithNoParentScopeInfo()
  116. {
  117. return (flags & fscrEvalCode) && !HasParentScopeInfo();
  118. }
  119. Js::ProfileId GetNextCallSiteId(Js::OpCode op)
  120. {
  121. if (m_writer.ShouldIncrementCallSiteId(op))
  122. {
  123. if (m_callSiteId != Js::Constants::NoProfileId)
  124. {
  125. return m_callSiteId++;
  126. }
  127. }
  128. return m_callSiteId;
  129. }
  130. Js::RegSlot NextVarRegister();
  131. Js::RegSlot NextConstRegister();
  132. FuncInfo *TopFuncInfo() const;
  133. void EnterLoop();
  134. void ExitLoop() { loopDepth--; }
  135. BOOL IsInLoop() const { return loopDepth > 0; }
  136. // TODO: per-function register assignment for env and global symbols
  137. void AssignRegister(Symbol *sym);
  138. void AddTargetStmt(ParseNode *pnodeStmt);
  139. Js::RegSlot AssignNullConstRegister();
  140. Js::RegSlot AssignUndefinedConstRegister();
  141. Js::RegSlot AssignTrueConstRegister();
  142. Js::RegSlot AssignFalseConstRegister();
  143. Js::RegSlot AssignThisRegister();
  144. Js::RegSlot AssignNewTargetRegister();
  145. void SetNeedEnvRegister();
  146. void AssignFrameObjRegister();
  147. void AssignFrameSlotsRegister();
  148. void AssignParamSlotsRegister();
  149. void AssignFrameDisplayRegister();
  150. void ProcessCapturedSym(Symbol *sym);
  151. void ProcessScopeWithCapturedSym(Scope *scope);
  152. void InitScopeSlotArray(FuncInfo * funcInfo);
  153. void FinalizeRegisters(FuncInfo * funcInfo, Js::FunctionBody * byteCodeFunction);
  154. void SetClosureRegisters(FuncInfo * funcInfo, Js::FunctionBody * byteCodeFunction);
  155. void EnsureSpecialScopeSlots(FuncInfo* funcInfo, Scope* scope);
  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::ParseableFunctionInfo* funcInfo);
  178. FuncInfo *StartBindGlobalStatements(ParseNode *pnode);
  179. void AssignPropertyId(Symbol *sym, Js::ParseableFunctionInfo* functionInfo);
  180. void AssignPropertyId(IdentPtr pid);
  181. void ProcessCapturedSyms(ParseNode *pnodeFnc);
  182. void RecordAllIntConstants(FuncInfo * funcInfo);
  183. void RecordAllStrConstants(FuncInfo * funcInfo);
  184. void RecordAllStringTemplateCallsiteConstants(FuncInfo* funcInfo);
  185. // For now, this just assigns field ids for the current script.
  186. // Later, we will combine this information with the global field ID map.
  187. // This temporary code will not work if a global member is accessed both with and without a LHS.
  188. void AssignPropertyIds(Js::ParseableFunctionInfo* functionInfo);
  189. void MapCacheIdsToPropertyIds(FuncInfo *funcInfo);
  190. void MapReferencedPropertyIds(FuncInfo *funcInfo);
  191. FuncInfo *StartBindFunction(const char16 *name, uint nameLength, uint shortNameOffset, bool* pfuncExprWithName, ParseNode *pnode, Js::ParseableFunctionInfo * reuseNestedFunc);
  192. void EndBindFunction(bool funcExprWithName);
  193. void StartBindCatch(ParseNode *pnode);
  194. // Block scopes related functions
  195. template<class Fn> void IterateBlockScopedVariables(ParseNode *pnodeBlock, Fn fn);
  196. void InitBlockScopedContent(ParseNode *pnodeBlock, Js::DebuggerScope *debuggerScope, FuncInfo *funcInfo);
  197. Js::DebuggerScope* RecordStartScopeObject(ParseNode *pnodeBlock, Js::DiagExtraScopesType scopeType, Js::RegSlot scopeLocation = Js::Constants::NoRegister, int* index = nullptr);
  198. void RecordEndScopeObject(ParseNode *pnodeBlock);
  199. void EndBindCatch();
  200. void StartEmitFunction(ParseNode *pnodeFnc);
  201. void EndEmitFunction(ParseNode *pnodeFnc);
  202. void StartEmitBlock(ParseNode *pnodeBlock);
  203. void EndEmitBlock(ParseNode *pnodeBlock);
  204. void StartEmitCatch(ParseNode *pnodeCatch);
  205. void EndEmitCatch(ParseNode *pnodeCatch);
  206. void StartEmitWith(ParseNode *pnodeWith);
  207. void EndEmitWith(ParseNode *pnodeWith);
  208. void EnsureFncScopeSlots(ParseNode *pnode, FuncInfo *funcInfo);
  209. void EnsureLetConstScopeSlots(ParseNode *pnodeBlock, FuncInfo *funcInfo);
  210. bool EnsureSymbolModuleSlots(Symbol* sym, FuncInfo* funcInfo);
  211. void EmitAssignmentToDefaultModuleExport(ParseNode* pnode, FuncInfo* funcInfo);
  212. void EmitModuleExportAccess(Symbol* sym, Js::OpCode opcode, Js::RegSlot location, FuncInfo* funcInfo);
  213. void PushScope(Scope *innerScope);
  214. void PopScope();
  215. void PushBlock(ParseNode *pnode);
  216. void PopBlock();
  217. void PushFuncInfo(char16 const * location, FuncInfo* funcInfo);
  218. void PopFuncInfo(char16 const * location);
  219. Js::RegSlot PrependLocalScopes(Js::RegSlot evalEnv, Js::RegSlot tempLoc, FuncInfo *funcInfo);
  220. Symbol *FindSymbol(Symbol **symRef, IdentPtr pid, bool forReference = false);
  221. Symbol *AddSymbolToScope(Scope *scope, const char16 *key, int keyLength, ParseNode *varDecl, SymbolType symbolType);
  222. Symbol *AddSymbolToFunctionScope(const char16 *key, int keyLength, ParseNode *varDecl, SymbolType symbolType);
  223. void FuncEscapes(Scope *scope);
  224. void EmitTopLevelStatement(ParseNode *stmt, FuncInfo *funcInfo, BOOL fReturnValue);
  225. void EmitInvertedLoop(ParseNode* outerLoop,ParseNode* invertedLoop,FuncInfo* funcInfo);
  226. void DefineFunctions(FuncInfo *funcInfoParent);
  227. Js::RegSlot DefineOneFunction(ParseNode *pnodeFnc, FuncInfo *funcInfoParent, bool generateAssignment=true, Js::RegSlot regEnv = Js::Constants::NoRegister, Js::RegSlot frameDisplayTemp = Js::Constants::NoRegister);
  228. void DefineCachedFunctions(FuncInfo *funcInfoParent);
  229. void DefineUncachedFunctions(FuncInfo *funcInfoParent);
  230. void DefineUserVars(FuncInfo *funcInfo);
  231. void InitBlockScopedNonTemps(ParseNode *pnode, FuncInfo *funcInfo);
  232. // temporarily load all constants and special registers in a single block
  233. void LoadAllConstants(FuncInfo *funcInfo);
  234. void LoadHeapArguments(FuncInfo *funcInfo);
  235. void LoadUncachedHeapArguments(FuncInfo *funcInfo);
  236. void LoadCachedHeapArguments(FuncInfo *funcInfo);
  237. void LoadThisObject(FuncInfo *funcInfo, bool thisLoadedFromParams = false);
  238. void EmitThis(FuncInfo *funcInfo, Js::RegSlot fromRegister);
  239. void LoadNewTargetObject(FuncInfo *funcInfo);
  240. void GetEnclosingNonLambdaScope(FuncInfo *funcInfo, Scope * &scope, Js::PropertyId &envIndex);
  241. void EmitInternalScopedSlotLoad(FuncInfo *funcInfo, Js::RegSlot slot, Js::RegSlot symbolRegister, bool chkUndecl = false);
  242. void EmitInternalScopedSlotLoad(FuncInfo *funcInfo, Scope *scope, Js::PropertyId envIndex, Js::RegSlot slot, Js::RegSlot symbolRegister, bool chkUndecl = false);
  243. void EmitInternalScopedSlotStore(FuncInfo *funcInfo, Js::RegSlot slot, Js::RegSlot symbolRegister);
  244. void EmitInternalScopeObjInit(FuncInfo *funcInfo, Scope *scope, Js::RegSlot valueLocation, Js::PropertyId propertyId);
  245. void EmitSuperCall(FuncInfo* funcInfo, ParseNode* pnode, BOOL fReturnValue);
  246. void EmitScopeSlotLoadThis(FuncInfo *funcInfo, Js::RegSlot regLoc, bool chkUndecl = true);
  247. void EmitScopeSlotStoreThis(FuncInfo *funcInfo, Js::RegSlot regLoc, bool chkUndecl = false);
  248. void EmitClassConstructorEndCode(FuncInfo *funcInfo);
  249. void EmitBaseClassConstructorThisObject(FuncInfo *funcInfo);
  250. // TODO: home the 'this' argument
  251. void EmitLoadFormalIntoRegister(ParseNode *pnodeFormal, Js::RegSlot pos, FuncInfo *funcInfo);
  252. void HomeArguments(FuncInfo *funcInfo);
  253. void EnsureNoRedeclarations(ParseNode *pnodeBlock, FuncInfo *funcInfo);
  254. void DefineLabels(FuncInfo *funcInfo);
  255. void EmitProgram(ParseNode *pnodeProg);
  256. void EmitScopeList(ParseNode *pnode, ParseNode *breakOnBodyScopeNode = nullptr);
  257. void EmitDefaultArgs(FuncInfo *funcInfo, ParseNode *pnode);
  258. void EmitOneFunction(ParseNode *pnode);
  259. void EmitGlobalFncDeclInit(Js::RegSlot rhsLocation, Js::PropertyId propertyId, FuncInfo * funcInfo);
  260. void EmitLocalPropInit(Js::RegSlot rhsLocation, Symbol *sym, FuncInfo *funcInfo);
  261. void EmitPropStore(Js::RegSlot rhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo, bool isLet = false, bool isConst = false, bool isFncDeclVar = false);
  262. void EmitPropLoad(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo);
  263. void EmitPropDelete(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo);
  264. void EmitPropTypeof(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo);
  265. void EmitTypeOfFld(FuncInfo * funcInfo, Js::PropertyId propertyId, Js::RegSlot value, Js::RegSlot instance, Js::OpCode op1);
  266. void EmitLoadInstance(Symbol *sym, IdentPtr pid, Js::RegSlot *pThisLocation, Js::RegSlot *pTargetLocation, FuncInfo *funcInfo);
  267. void EmitGlobalBody(FuncInfo *funcInfo);
  268. void EmitFunctionBody(FuncInfo *funcInfo);
  269. void EmitAsmFunctionBody(FuncInfo *funcInfo);
  270. void EmitScopeObjectInit(FuncInfo *funcInfo);
  271. void EmitPatchableRootProperty(Js::OpCode opcode, Js::RegSlot regSlot, Js::PropertyId propertyId, bool isLoadMethod, bool isStore, FuncInfo *funcInfo);
  272. struct TryScopeRecord;
  273. JsUtil::DoublyLinkedList<TryScopeRecord> tryScopeRecordsList;
  274. void EmitLeaveOpCodesBeforeYield();
  275. void EmitTryBlockHeadersAfterYield();
  276. void InvalidateCachedOuterScopes(FuncInfo *funcInfo);
  277. bool InDynamicScope() const { return dynamicScopeCount != 0; }
  278. Scope * FindScopeForSym(Scope *symScope, Scope *scope, Js::PropertyId *envIndex, FuncInfo *funcInfo) const;
  279. static Js::OpCode GetStFldOpCode(bool isStrictMode, bool isRoot, bool isLetDecl, bool isConstDecl, bool isClassMemberInit)
  280. {
  281. return isClassMemberInit ? Js::OpCode::InitClassMember :
  282. isConstDecl ? (isRoot ? Js::OpCode::InitRootConstFld : Js::OpCode::InitConstFld) :
  283. isLetDecl ? (isRoot ? Js::OpCode::InitRootLetFld : Js::OpCode::InitLetFld) :
  284. isStrictMode ? (isRoot ? Js::OpCode::StRootFldStrict : Js::OpCode::StFldStrict) :
  285. isRoot ? Js::OpCode::StRootFld : Js::OpCode::StFld;
  286. }
  287. static Js::OpCode GetStFldOpCode(FuncInfo* funcInfo, bool isRoot, bool isLetDecl, bool isConstDecl, bool isClassMemberInit);
  288. static Js::OpCode GetScopedStFldOpCode(bool isStrictMode)
  289. {
  290. return isStrictMode ? Js::OpCode::ScopedStFldStrict : Js::OpCode::ScopedStFld;
  291. }
  292. static Js::OpCode GetScopedStFldOpCode(FuncInfo* funcInfo, bool isConsoleScopeLetConst = false);
  293. static Js::OpCode GetStElemIOpCode(bool isStrictMode)
  294. {
  295. return isStrictMode ? Js::OpCode::StElemI_A_Strict : Js::OpCode::StElemI_A;
  296. }
  297. static Js::OpCode GetStElemIOpCode(FuncInfo* funcInfo);
  298. bool DoJitLoopBodies(FuncInfo *funcInfo) const;
  299. 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);
  300. void Begin(
  301. __in ArenaAllocator *alloc,
  302. __in uint32 grfscr,
  303. __in Js::ParseableFunctionInfo* pRootFunc);
  304. void SetCurrentSourceIndex(uint sourceIndex) { this->sourceIndex = sourceIndex; }
  305. uint GetCurrentSourceIndex() { return sourceIndex; }
  306. static bool IsFalse(ParseNode* node);
  307. void StartStatement(ParseNode* node);
  308. void EndStatement(ParseNode* node);
  309. void StartSubexpression(ParseNode* node);
  310. void EndSubexpression(ParseNode* node);
  311. bool IsES6DestructuringEnabled() const;
  312. bool IsES6ForLoopSemanticsEnabled() const;
  313. // Debugger methods.
  314. bool IsInDebugMode() const;
  315. bool IsInNonDebugMode() const;
  316. bool ShouldTrackDebuggerMetadata() const;
  317. void TrackRegisterPropertyForDebugger(Js::DebuggerScope *debuggerScope, Symbol *symbol, FuncInfo *funcInfo, Js::DebuggerScopePropertyFlags flags = Js::DebuggerScopePropertyFlags_None, bool isFunctionDeclaration = false);
  318. void TrackActivationObjectPropertyForDebugger(Js::DebuggerScope *debuggerScope, Symbol *symbol, Js::DebuggerScopePropertyFlags flags = Js::DebuggerScopePropertyFlags_None, bool isFunctionDeclaration = false);
  319. void TrackSlotArrayPropertyForDebugger(Js::DebuggerScope *debuggerScope, Symbol* symbol, Js::PropertyId propertyId, Js::DebuggerScopePropertyFlags flags = Js::DebuggerScopePropertyFlags_None, bool isFunctionDeclaration = false);
  320. void TrackFunctionDeclarationPropertyForDebugger(Symbol *functionDeclarationSymbol, FuncInfo *funcInfoParent);
  321. void UpdateDebuggerPropertyInitializationOffset(Js::RegSlot location, Js::PropertyId propertyId, bool shouldConsumeRegister = true);
  322. void PopulateFormalsScope(uint beginOffset, FuncInfo *funcInfo, ParseNode *pnode);
  323. void InsertPropertyToDebuggerScope(FuncInfo* funcInfo, Js::DebuggerScope* debuggerScope, Symbol* sym);
  324. FuncInfo *FindEnclosingNonLambda();
  325. bool CanStackNestedFunc(FuncInfo * funcInfo, bool trace = false);
  326. void CheckDeferParseHasMaybeEscapedNestedFunc();
  327. bool NeedObjectAsFunctionScope(FuncInfo * funcInfo, ParseNode * pnodeFnc) const;
  328. bool HasInterleavingDynamicScope(Symbol * sym) const;
  329. void MarkThisUsedInLambda();
  330. void EmitInitCapturedThis(FuncInfo* funcInfo, Scope* scope);
  331. void EmitInitCapturedNewTarget(FuncInfo* funcInfo, Scope* scope);
  332. Js::FunctionBody *EnsureFakeGlobalFuncForUndefer(ParseNode *pnode);
  333. Js::FunctionBody *MakeGlobalFunctionBody(ParseNode *pnode);
  334. static bool NeedScopeObjectForArguments(FuncInfo *funcInfo, ParseNode *pnodeFnc);
  335. Js::OpCode GetStSlotOp(Scope *scope, int envIndex, Js::RegSlot scopeLocation, bool chkBlockVar, FuncInfo *funcInfo);
  336. Js::OpCode GetLdSlotOp(Scope *scope, int envIndex, Js::RegSlot scopeLocation, FuncInfo *funcInfo);
  337. Js::OpCode GetInitFldOp(Scope *scope, Js::RegSlot scopeLocation, FuncInfo *funcInfo, bool letDecl = false);
  338. private:
  339. bool NeedCheckBlockVar(Symbol* sym, Scope* scope, FuncInfo* funcInfo) const;
  340. Js::OpCode ToChkUndeclOp(Js::OpCode op) const;
  341. };
  342. template<class Fn> void ByteCodeGenerator::IterateBlockScopedVariables(ParseNode *pnodeBlock, Fn fn)
  343. {
  344. Assert(pnodeBlock->nop == knopBlock);
  345. for (auto lexvar = pnodeBlock->sxBlock.pnodeLexVars; lexvar; lexvar = lexvar->sxVar.pnodeNext)
  346. {
  347. fn(lexvar);
  348. }
  349. }
  350. struct ApplyCheck {
  351. bool matches;
  352. bool insideApplyCall;
  353. bool sawApply;
  354. };