ByteCodeGenerator.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. // A flag that when set will force bytecode opcodes to be emitted in strict mode when avaliable.
  60. // This flag is set outside of emit calls under the condition that the bytecode being emitted
  61. // corresponds to computed property names within classes. This fixes a bug where computed property
  62. // names would not enforce strict mode when inside a class even though the spec requires that
  63. // all code within a class must be strict.
  64. bool forceStrictModeForClassComputedPropertyName = false;
  65. ByteCodeGenerator(Js::ScriptContext* scriptContext, Js::ScopeInfo* parentScopeInfo);
  66. #if DBG_DUMP
  67. bool Trace() const
  68. {
  69. return Js::Configuration::Global.flags.Trace.IsEnabled(Js::ByteCodePhase);
  70. }
  71. #else
  72. bool Trace() const
  73. {
  74. return false;
  75. }
  76. #endif
  77. Js::ScriptContext* GetScriptContext() { return scriptContext; }
  78. Scope *GetCurrentScope() const { return currentScope; }
  79. void SetCurrentBlock(ParseNodeBlock *pnode) { currentBlock = pnode; }
  80. ParseNodeBlock *GetCurrentBlock() const { return currentBlock; }
  81. void SetCurrentTopStatement(ParseNode *pnode) { currentTopStatement = pnode; }
  82. ParseNode *GetCurrentTopStatement() const { return currentTopStatement; }
  83. Js::ModuleID GetModuleID() const
  84. {
  85. return m_utf8SourceInfo->GetSrcInfo()->moduleID;
  86. }
  87. void SetFlags(uint32 grfscr)
  88. {
  89. flags = grfscr;
  90. }
  91. uint32 GetFlags(void)
  92. {
  93. return flags;
  94. }
  95. bool IsConsoleScopeEval(void)
  96. {
  97. return (flags & fscrConsoleScopeEval) == fscrConsoleScopeEval;
  98. }
  99. bool IsModuleCode()
  100. {
  101. return (flags & fscrIsModuleCode) == fscrIsModuleCode;
  102. }
  103. bool IsBinding() const {
  104. return isBinding;
  105. }
  106. Js::ByteCodeWriter *Writer() {
  107. return &m_writer;
  108. }
  109. ArenaAllocator *GetAllocator() {
  110. return alloc;
  111. }
  112. bool IsEvalWithNoParentScopeInfo()
  113. {
  114. return (flags & fscrEvalCode) && !HasParentScopeInfo();
  115. }
  116. Js::ProfileId GetNextCallSiteId(Js::OpCode op)
  117. {
  118. if (m_writer.ShouldIncrementCallSiteId(op))
  119. {
  120. if (m_callSiteId != Js::Constants::NoProfileId)
  121. {
  122. return m_callSiteId++;
  123. }
  124. }
  125. return m_callSiteId;
  126. }
  127. Js::ProfileId GetCurrentCallSiteId() { return m_callSiteId; }
  128. Js::RegSlot NextVarRegister();
  129. Js::RegSlot NextConstRegister();
  130. FuncInfo *TopFuncInfo() const;
  131. void EnterLoop();
  132. void ExitLoop() { loopDepth--; }
  133. BOOL IsInLoop() const { return loopDepth > 0; }
  134. // TODO: per-function register assignment for env and global symbols
  135. void AssignRegister(Symbol *sym);
  136. void AddTargetStmt(ParseNodeStmt *pnodeStmt);
  137. Js::RegSlot AssignNullConstRegister();
  138. Js::RegSlot AssignUndefinedConstRegister();
  139. Js::RegSlot AssignTrueConstRegister();
  140. Js::RegSlot AssignFalseConstRegister();
  141. Js::RegSlot AssignThisConstRegister();
  142. void SetNeedEnvRegister();
  143. void AssignFrameObjRegister();
  144. void AssignFrameSlotsRegister();
  145. void AssignParamSlotsRegister();
  146. void AssignFrameDisplayRegister();
  147. void ProcessCapturedSym(Symbol *sym);
  148. void ProcessScopeWithCapturedSym(Scope *scope);
  149. void InitScopeSlotArray(FuncInfo * funcInfo);
  150. void FinalizeRegisters(FuncInfo * funcInfo, Js::FunctionBody * byteCodeFunction);
  151. void SetClosureRegisters(FuncInfo * funcInfo, Js::FunctionBody * byteCodeFunction);
  152. void SetHasTry(bool has);
  153. void SetHasFinally(bool has);
  154. void SetNumberOfInArgs(Js::ArgSlot argCount);
  155. Js::RegSlot EnregisterConstant(unsigned int constant);
  156. Js::RegSlot EnregisterStringConstant(IdentPtr pid);
  157. Js::RegSlot EnregisterDoubleConstant(double d);
  158. Js::RegSlot EnregisterBigIntConstant(ParseNodePtr pid);
  159. Js::RegSlot EnregisterStringTemplateCallsiteConstant(ParseNode* pnode);
  160. static Js::JavascriptArray* BuildArrayFromStringList(ParseNode* stringNodeList, uint arrayLength, Js::ScriptContext* scriptContext);
  161. bool HasParentScopeInfo() const
  162. {
  163. return this->parentScopeInfo != nullptr;
  164. }
  165. Js::RegSlot EmitLdObjProto(Js::OpCode op, Js::RegSlot objReg, FuncInfo *funcInfo)
  166. {
  167. // LdHomeObjProto protoReg, objReg
  168. // LdFuncObjProto protoReg, objReg
  169. Js::RegSlot protoReg = funcInfo->AcquireTmpRegister();
  170. this->Writer()->Reg2(op, protoReg, objReg);
  171. funcInfo->ReleaseTmpRegister(protoReg);
  172. return protoReg;
  173. }
  174. void RestoreScopeInfo(Js::ScopeInfo *scopeInfo, FuncInfo * func);
  175. void RestoreOneScope(Js::ScopeInfo * scopeInfo, FuncInfo * func);
  176. FuncInfo *StartBindGlobalStatements(ParseNodeProg *pnode);
  177. void AssignPropertyId(Symbol *sym, Js::ParseableFunctionInfo* functionInfo);
  178. void AssignPropertyId(IdentPtr pid);
  179. void ProcessCapturedSyms(ParseNode *pnodeFnc);
  180. void RecordAllIntConstants(FuncInfo * funcInfo);
  181. void RecordAllStrConstants(FuncInfo * funcInfo);
  182. void RecordAllBigIntConstants(FuncInfo * funcInfo);
  183. void RecordAllStringTemplateCallsiteConstants(FuncInfo* funcInfo);
  184. // For now, this just assigns field ids for the current script.
  185. // Later, we will combine this information with the global field ID map.
  186. // This temporary code will not work if a global member is accessed both with and without a LHS.
  187. void AssignPropertyIds(Js::ParseableFunctionInfo* functionInfo);
  188. void MapCacheIdsToPropertyIds(FuncInfo *funcInfo);
  189. void MapReferencedPropertyIds(FuncInfo *funcInfo);
  190. FuncInfo *StartBindFunction(const char16 *name, uint nameLength, uint shortNameOffset, bool* pfuncExprWithName, ParseNodeFnc *pnodeFnc, Js::ParseableFunctionInfo * reuseNestedFunc);
  191. void EndBindFunction(bool funcExprWithName);
  192. void StartBindCatch(ParseNode *pnode);
  193. // Block scopes related functions
  194. template<class Fn> void IterateBlockScopedVariables(ParseNodeBlock *pnodeBlock, Fn fn);
  195. void InitBlockScopedContent(ParseNodeBlock *pnodeBlock, Js::DebuggerScope *debuggerScope, FuncInfo *funcInfo);
  196. Js::DebuggerScope* RecordStartScopeObject(ParseNode *pnodeBlock, Js::DiagExtraScopesType scopeType, Js::RegSlot scopeLocation = Js::Constants::NoRegister, int* index = nullptr);
  197. void RecordEndScopeObject(ParseNode *pnodeBlock);
  198. void EndBindCatch();
  199. void StartEmitFunction(ParseNodeFnc *pnodeFnc);
  200. void EndEmitFunction(ParseNodeFnc *pnodeFnc);
  201. void StartEmitBlock(ParseNodeBlock *pnodeBlock);
  202. void EndEmitBlock(ParseNodeBlock *pnodeBlock);
  203. void StartEmitCatch(ParseNodeCatch *pnodeCatch);
  204. void EndEmitCatch(ParseNodeCatch *pnodeCatch);
  205. void StartEmitWith(ParseNode *pnodeWith);
  206. void EndEmitWith(ParseNode *pnodeWith);
  207. void EnsureFncScopeSlots(ParseNode *pnode, FuncInfo *funcInfo);
  208. void EnsureLetConstScopeSlots(ParseNodeBlock *pnodeBlock, FuncInfo *funcInfo);
  209. bool EnsureSymbolModuleSlots(Symbol* sym, FuncInfo* funcInfo);
  210. void EmitAssignmentToDefaultModuleExport(ParseNode* pnode, FuncInfo* funcInfo);
  211. void EmitModuleExportAccess(Symbol* sym, Js::OpCode opcode, Js::RegSlot location, FuncInfo* funcInfo);
  212. void PushScope(Scope *innerScope);
  213. void PopScope();
  214. void PushBlock(ParseNodeBlock *pnode);
  215. void PopBlock();
  216. void PushFuncInfo(char16 const * location, FuncInfo* funcInfo);
  217. void PopFuncInfo(char16 const * location);
  218. Js::RegSlot PrependLocalScopes(Js::RegSlot evalEnv, Js::RegSlot tempLoc, FuncInfo *funcInfo);
  219. Symbol *FindSymbol(Symbol **symRef, IdentPtr pid, bool forReference = false);
  220. Symbol *AddSymbolToScope(Scope *scope, const char16 *key, int keyLength, ParseNode *varDecl, SymbolType symbolType);
  221. Symbol *AddSymbolToFunctionScope(const char16 *key, int keyLength, ParseNode *varDecl, SymbolType symbolType);
  222. void FuncEscapes(Scope *scope);
  223. void EmitTopLevelStatement(ParseNode *stmt, FuncInfo *funcInfo, BOOL fReturnValue);
  224. void EmitInvertedLoop(ParseNodeLoop* outerLoop,ParseNodeFor* invertedLoop,FuncInfo* funcInfo);
  225. void DefineFunctions(FuncInfo *funcInfoParent);
  226. Js::RegSlot DefineOneFunction(ParseNodeFnc *pnodeFnc, FuncInfo *funcInfoParent, bool generateAssignment=true, Js::RegSlot regEnv = Js::Constants::NoRegister, Js::RegSlot frameDisplayTemp = Js::Constants::NoRegister);
  227. void DefineCachedFunctions(FuncInfo *funcInfoParent);
  228. void DefineUncachedFunctions(FuncInfo *funcInfoParent);
  229. void DefineUserVars(FuncInfo *funcInfo);
  230. void InitBlockScopedNonTemps(ParseNode *pnode, FuncInfo *funcInfo);
  231. // temporarily load all constants and special registers in a single block
  232. void LoadAllConstants(FuncInfo *funcInfo);
  233. void LoadHeapArguments(FuncInfo *funcInfo);
  234. void LoadUncachedHeapArguments(FuncInfo *funcInfo);
  235. void LoadCachedHeapArguments(FuncInfo *funcInfo);
  236. void LoadThisObject(FuncInfo *funcInfo, bool thisLoadedFromParams = false);
  237. void EmitThis(FuncInfo *funcInfo, Js::RegSlot lhsLocation, Js::RegSlot fromRegister);
  238. void LoadNewTargetObject(FuncInfo *funcInfo);
  239. void LoadSuperObject(FuncInfo *funcInfo);
  240. void LoadSuperConstructorObject(FuncInfo *funcInfo);
  241. void EmitSuperCall(FuncInfo* funcInfo, ParseNodeSuperCall * pnodeSuperCall, BOOL fReturnValue);
  242. void EmitClassConstructorEndCode(FuncInfo *funcInfo);
  243. // TODO: home the 'this' argument
  244. void EmitLoadFormalIntoRegister(ParseNode *pnodeFormal, Js::RegSlot pos, FuncInfo *funcInfo);
  245. void HomeArguments(FuncInfo *funcInfo);
  246. void EnsureNoRedeclarations(ParseNodeBlock *pnodeBlock, FuncInfo *funcInfo);
  247. void DefineLabels(FuncInfo *funcInfo);
  248. void EmitProgram(ParseNodeProg *pnodeProg);
  249. void EmitScopeList(ParseNode *pnode, ParseNode *breakOnBodyScopeNode = nullptr);
  250. void EmitDefaultArgs(FuncInfo *funcInfo, ParseNodeFnc *pnode);
  251. void EmitOneFunction(ParseNodeFnc *pnodeFnc);
  252. void EmitGlobalFncDeclInit(Js::RegSlot rhsLocation, Js::PropertyId propertyId, FuncInfo * funcInfo);
  253. void EmitLocalPropInit(Js::RegSlot rhsLocation, Symbol *sym, FuncInfo *funcInfo);
  254. void EmitPropStore(Js::RegSlot rhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo, bool isLet = false, bool isConst = false, bool isFncDeclVar = false, bool skipUseBeforeDeclarationCheck = false);
  255. void EmitPropLoad(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo, bool skipUseBeforeDeclarationCheck = false);
  256. void EmitPropDelete(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo);
  257. void EmitPropTypeof(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo);
  258. void EmitTypeOfFld(FuncInfo * funcInfo, Js::PropertyId propertyId, Js::RegSlot value, Js::RegSlot instance, Js::OpCode op1);
  259. bool ShouldLoadConstThis(FuncInfo* funcInfo);
  260. void EmitPropLoadThis(Js::RegSlot lhsLocation, ParseNodeSpecialName *pnode, FuncInfo *funcInfo, bool chkUndecl);
  261. void EmitPropStoreForSpecialSymbol(Js::RegSlot rhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo, bool init);
  262. void EmitLoadInstance(Symbol *sym, IdentPtr pid, Js::RegSlot *pThisLocation, Js::RegSlot *pTargetLocation, FuncInfo *funcInfo);
  263. void EmitGlobalBody(FuncInfo *funcInfo);
  264. void EmitFunctionBody(FuncInfo *funcInfo);
  265. void EmitAsmFunctionBody(FuncInfo *funcInfo);
  266. void EmitScopeObjectInit(FuncInfo *funcInfo);
  267. void EmitPatchableRootProperty(Js::OpCode opcode, Js::RegSlot regSlot, Js::PropertyId propertyId, bool isLoadMethod, bool isStore, FuncInfo *funcInfo);
  268. struct TryScopeRecord;
  269. JsUtil::DoublyLinkedList<TryScopeRecord> tryScopeRecordsList;
  270. void EmitLeaveOpCodesBeforeYield();
  271. void EmitTryBlockHeadersAfterYield();
  272. void InvalidateCachedOuterScopes(FuncInfo *funcInfo);
  273. bool InDynamicScope() const { return dynamicScopeCount != 0; }
  274. Scope * FindScopeForSym(Scope *symScope, Scope *scope, Js::PropertyId *envIndex, FuncInfo *funcInfo) const;
  275. static Js::OpCode GetStFldOpCode(bool isStrictMode, bool isRoot, bool isLetDecl, bool isConstDecl, bool isClassMemberInit)
  276. {
  277. return isClassMemberInit ? Js::OpCode::InitClassMember :
  278. isConstDecl ? (isRoot ? Js::OpCode::InitRootConstFld : Js::OpCode::InitConstFld) :
  279. isLetDecl ? (isRoot ? Js::OpCode::InitRootLetFld : Js::OpCode::InitLetFld) :
  280. isStrictMode ? (isRoot ? Js::OpCode::StRootFldStrict : Js::OpCode::StFldStrict) :
  281. isRoot ? Js::OpCode::StRootFld : Js::OpCode::StFld;
  282. }
  283. static Js::OpCode GetStFldOpCode(FuncInfo* funcInfo, bool isRoot, bool isLetDecl, bool isConstDecl, bool isClassMemberInit, bool forceStrictModeForClassComputedPropertyName = false);
  284. static Js::OpCode GetScopedStFldOpCode(bool isStrictMode, bool isConsoleScope = false)
  285. {
  286. return isStrictMode ?
  287. (isConsoleScope ? Js::OpCode::ConsoleScopedStFldStrict : Js::OpCode::ScopedStFldStrict) :
  288. (isConsoleScope ? Js::OpCode::ConsoleScopedStFld : Js::OpCode::ScopedStFld);
  289. }
  290. static Js::OpCode GetScopedStFldOpCode(FuncInfo* funcInfo, bool isConsoleScopeLetConst = false);
  291. static Js::OpCode GetStElemIOpCode(bool isStrictMode)
  292. {
  293. return isStrictMode ? Js::OpCode::StElemI_A_Strict : Js::OpCode::StElemI_A;
  294. }
  295. static Js::OpCode GetStElemIOpCode(FuncInfo* funcInfo);
  296. bool DoJitLoopBodies(FuncInfo *funcInfo) const;
  297. 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);
  298. void Begin(
  299. __in ArenaAllocator *alloc,
  300. __in uint32 grfscr,
  301. __in Js::ParseableFunctionInfo* pRootFunc);
  302. void SetCurrentSourceIndex(uint sourceIndex) { this->sourceIndex = sourceIndex; }
  303. uint GetCurrentSourceIndex() { return sourceIndex; }
  304. static bool IsFalse(ParseNode* node);
  305. static bool IsThis(ParseNode* pnode);
  306. static bool IsSuper(ParseNode* pnode);
  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, ParseNodeFnc *pnodeFnc);
  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, ParseNodeFnc * pnodeFnc) const;
  328. bool HasInterleavingDynamicScope(Symbol * sym) const;
  329. Js::FunctionBody *EnsureFakeGlobalFuncForUndefer(ParseNode *pnode);
  330. Js::FunctionBody *MakeGlobalFunctionBody(ParseNode *pnode);
  331. bool NeedScopeObjectForArguments(FuncInfo *funcInfo, ParseNodeFnc *pnodeFnc) const;
  332. void AddFuncInfoToFinalizationSet(FuncInfo *funcInfo);
  333. void FinalizeFuncInfos();
  334. void CheckFncDeclScopeSlot(ParseNodeFnc *pnodeFnc, FuncInfo *funcInfo);
  335. void EnsureFncDeclScopeSlot(ParseNodeFnc *pnodeFnc, FuncInfo *funcInfo);
  336. Js::OpCode GetStSlotOp(Scope *scope, int envIndex, Js::RegSlot scopeLocation, bool chkBlockVar, FuncInfo *funcInfo);
  337. Js::OpCode GetLdSlotOp(Scope *scope, int envIndex, Js::RegSlot scopeLocation, FuncInfo *funcInfo);
  338. Js::OpCode GetInitFldOp(Scope *scope, Js::RegSlot scopeLocation, FuncInfo *funcInfo, bool letDecl = false);
  339. private:
  340. bool NeedCheckBlockVar(Symbol* sym, Scope* scope, FuncInfo* funcInfo) const;
  341. Js::OpCode ToChkUndeclOp(Js::OpCode op) const;
  342. };
  343. template<class Fn> void ByteCodeGenerator::IterateBlockScopedVariables(ParseNodeBlock *pnodeBlock, Fn fn)
  344. {
  345. Assert(pnodeBlock->nop == knopBlock);
  346. for (auto lexvar = pnodeBlock->pnodeLexVars; lexvar; lexvar = lexvar->AsParseNodeVar()->pnodeNext)
  347. {
  348. fn(lexvar);
  349. }
  350. }
  351. struct ApplyCheck {
  352. bool matches;
  353. bool insideApplyCall;
  354. bool sawApply;
  355. };