ByteCodeGenerator.h 19 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. 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::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 fromRegister);
  240. void LoadNewTargetObject(FuncInfo *funcInfo);
  241. void GetEnclosingNonLambdaScope(FuncInfo *funcInfo, Scope * &scope, Js::PropertyId &envIndex);
  242. void EmitInternalScopedSlotLoad(FuncInfo *funcInfo, Js::RegSlot slot, Js::RegSlot symbolRegister, bool chkUndecl = false);
  243. void EmitInternalScopedSlotLoad(FuncInfo *funcInfo, Scope *scope, Js::PropertyId envIndex, Js::RegSlot slot, Js::RegSlot symbolRegister, bool chkUndecl = false);
  244. void EmitInternalScopedSlotStore(FuncInfo *funcInfo, Js::RegSlot slot, Js::RegSlot symbolRegister);
  245. void EmitInternalScopeObjInit(FuncInfo *funcInfo, Scope *scope, Js::RegSlot valueLocation, Js::PropertyId propertyId);
  246. void EmitSuperCall(FuncInfo* funcInfo, ParseNode* pnode, BOOL fReturnValue);
  247. void EmitScopeSlotLoadThis(FuncInfo *funcInfo, Js::RegSlot regLoc, bool chkUndecl = true);
  248. void EmitScopeSlotStoreThis(FuncInfo *funcInfo, Js::RegSlot regLoc, bool chkUndecl = false);
  249. void EmitClassConstructorEndCode(FuncInfo *funcInfo);
  250. void EmitBaseClassConstructorThisObject(FuncInfo *funcInfo);
  251. // TODO: home the 'this' argument
  252. void EmitLoadFormalIntoRegister(ParseNode *pnodeFormal, Js::RegSlot pos, FuncInfo *funcInfo);
  253. void HomeArguments(FuncInfo *funcInfo);
  254. void EnsureNoRedeclarations(ParseNode *pnodeBlock, FuncInfo *funcInfo);
  255. void DefineLabels(FuncInfo *funcInfo);
  256. void EmitProgram(ParseNode *pnodeProg);
  257. void EmitScopeList(ParseNode *pnode, ParseNode *breakOnBodyScopeNode = nullptr);
  258. void EmitDefaultArgs(FuncInfo *funcInfo, ParseNode *pnode);
  259. void EmitOneFunction(ParseNode *pnode);
  260. void EmitGlobalFncDeclInit(Js::RegSlot rhsLocation, Js::PropertyId propertyId, FuncInfo * funcInfo);
  261. void EmitLocalPropInit(Js::RegSlot rhsLocation, Symbol *sym, FuncInfo *funcInfo);
  262. void EmitPropStore(Js::RegSlot rhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo, bool isLet = false, bool isConst = false, bool isFncDeclVar = false);
  263. void EmitPropLoad(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo);
  264. void EmitPropDelete(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo);
  265. void EmitPropTypeof(Js::RegSlot lhsLocation, Symbol *sym, IdentPtr pid, FuncInfo *funcInfo);
  266. void EmitTypeOfFld(FuncInfo * funcInfo, Js::PropertyId propertyId, Js::RegSlot value, Js::RegSlot instance, Js::OpCode op1);
  267. void EmitLoadInstance(Symbol *sym, IdentPtr pid, Js::RegSlot *pThisLocation, Js::RegSlot *pTargetLocation, FuncInfo *funcInfo);
  268. void EmitGlobalBody(FuncInfo *funcInfo);
  269. void EmitFunctionBody(FuncInfo *funcInfo);
  270. void EmitAsmFunctionBody(FuncInfo *funcInfo);
  271. void EmitScopeObjectInit(FuncInfo *funcInfo);
  272. void EmitPatchableRootProperty(Js::OpCode opcode, Js::RegSlot regSlot, Js::PropertyId propertyId, bool isLoadMethod, bool isStore, FuncInfo *funcInfo);
  273. struct TryScopeRecord;
  274. JsUtil::DoublyLinkedList<TryScopeRecord> tryScopeRecordsList;
  275. void EmitLeaveOpCodesBeforeYield();
  276. void EmitTryBlockHeadersAfterYield();
  277. void InvalidateCachedOuterScopes(FuncInfo *funcInfo);
  278. bool InDynamicScope() const { return dynamicScopeCount != 0; }
  279. Scope * FindScopeForSym(Scope *symScope, Scope *scope, Js::PropertyId *envIndex, FuncInfo *funcInfo) const;
  280. static Js::OpCode GetStFldOpCode(bool isStrictMode, bool isRoot, bool isLetDecl, bool isConstDecl, bool isClassMemberInit)
  281. {
  282. return isClassMemberInit ? Js::OpCode::InitClassMember :
  283. isConstDecl ? (isRoot ? Js::OpCode::InitRootConstFld : Js::OpCode::InitConstFld) :
  284. isLetDecl ? (isRoot ? Js::OpCode::InitRootLetFld : Js::OpCode::InitLetFld) :
  285. isStrictMode ? (isRoot ? Js::OpCode::StRootFldStrict : Js::OpCode::StFldStrict) :
  286. isRoot ? Js::OpCode::StRootFld : Js::OpCode::StFld;
  287. }
  288. static Js::OpCode GetStFldOpCode(FuncInfo* funcInfo, bool isRoot, bool isLetDecl, bool isConstDecl, bool isClassMemberInit);
  289. static Js::OpCode GetScopedStFldOpCode(bool isStrictMode, bool isConsoleScope = false)
  290. {
  291. return isStrictMode ?
  292. (isConsoleScope ? Js::OpCode::ConsoleScopedStFldStrict : Js::OpCode::ScopedStFldStrict) :
  293. (isConsoleScope ? Js::OpCode::ConsoleScopedStFld : Js::OpCode::ScopedStFld);
  294. }
  295. static Js::OpCode GetScopedStFldOpCode(FuncInfo* funcInfo, bool isConsoleScopeLetConst = false);
  296. static Js::OpCode GetStElemIOpCode(bool isStrictMode)
  297. {
  298. return isStrictMode ? Js::OpCode::StElemI_A_Strict : Js::OpCode::StElemI_A;
  299. }
  300. static Js::OpCode GetStElemIOpCode(FuncInfo* funcInfo);
  301. bool DoJitLoopBodies(FuncInfo *funcInfo) const;
  302. 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);
  303. void Begin(
  304. __in ArenaAllocator *alloc,
  305. __in uint32 grfscr,
  306. __in Js::ParseableFunctionInfo* pRootFunc);
  307. void SetCurrentSourceIndex(uint sourceIndex) { this->sourceIndex = sourceIndex; }
  308. uint GetCurrentSourceIndex() { return sourceIndex; }
  309. static bool IsFalse(ParseNode* node);
  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. void MarkThisUsedInLambda();
  333. void EmitInitCapturedThis(FuncInfo* funcInfo, Scope* scope);
  334. void EmitInitCapturedNewTarget(FuncInfo* funcInfo, Scope* scope);
  335. Js::FunctionBody *EnsureFakeGlobalFuncForUndefer(ParseNode *pnode);
  336. Js::FunctionBody *MakeGlobalFunctionBody(ParseNode *pnode);
  337. static bool NeedScopeObjectForArguments(FuncInfo *funcInfo, ParseNode *pnodeFnc);
  338. Js::OpCode GetStSlotOp(Scope *scope, int envIndex, Js::RegSlot scopeLocation, bool chkBlockVar, FuncInfo *funcInfo);
  339. Js::OpCode GetLdSlotOp(Scope *scope, int envIndex, Js::RegSlot scopeLocation, FuncInfo *funcInfo);
  340. Js::OpCode GetInitFldOp(Scope *scope, Js::RegSlot scopeLocation, FuncInfo *funcInfo, bool letDecl = false);
  341. private:
  342. bool NeedCheckBlockVar(Symbol* sym, Scope* scope, FuncInfo* funcInfo) const;
  343. Js::OpCode ToChkUndeclOp(Js::OpCode op) const;
  344. };
  345. template<class Fn> void ByteCodeGenerator::IterateBlockScopedVariables(ParseNode *pnodeBlock, Fn fn)
  346. {
  347. Assert(pnodeBlock->nop == knopBlock);
  348. for (auto lexvar = pnodeBlock->sxBlock.pnodeLexVars; lexvar; lexvar = lexvar->sxVar.pnodeNext)
  349. {
  350. fn(lexvar);
  351. }
  352. }
  353. struct ApplyCheck {
  354. bool matches;
  355. bool insideApplyCall;
  356. bool sawApply;
  357. };