6346118797be82bf5c99c7d3da38549542a52ec9
[WebKit-https.git] / Source / JavaScriptCore / bytecompiler / BytecodeGenerator.h
1 /*
2  * Copyright (C) 2008-2009, 2012-2016 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
4  * Copyright (C) 2012 Igalia, S.L.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1.  Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer.
12  * 2.  Redistributions in binary form must reproduce the above copyright
13  *     notice, this list of conditions and the following disclaimer in the
14  *     documentation and/or other materials provided with the distribution.
15  * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
16  *     its contributors may be used to endorse or promote products derived
17  *     from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #pragma once
32
33 #include "CodeBlock.h"
34 #include "Instruction.h"
35 #include "Interpreter.h"
36 #include "JSGeneratorFunction.h"
37 #include "Label.h"
38 #include "LabelScope.h"
39 #include "Nodes.h"
40 #include "ParserError.h"
41 #include "RegisterID.h"
42 #include "SetForScope.h"
43 #include "StaticPropertyAnalyzer.h"
44 #include "SymbolTable.h"
45 #include "TemplateRegistryKey.h"
46 #include "UnlinkedCodeBlock.h"
47 #include <functional>
48 #include <wtf/HashTraits.h>
49 #include <wtf/PassRefPtr.h>
50 #include <wtf/SegmentedVector.h>
51 #include <wtf/Vector.h>
52
53 namespace JSC {
54
55     class Identifier;
56     class JSTemplateRegistryKey;
57
58     enum ExpectedFunction {
59         NoExpectedFunction,
60         ExpectObjectConstructor,
61         ExpectArrayConstructor
62     };
63
64     enum class DebuggableCall { Yes, No };
65     enum class ThisResolutionType { Local, Scoped };
66     
67     class CallArguments {
68     public:
69         CallArguments(BytecodeGenerator&, ArgumentsNode*, unsigned additionalArguments = 0);
70
71         RegisterID* thisRegister() { return m_argv[0].get(); }
72         RegisterID* argumentRegister(unsigned i) { return m_argv[i + 1].get(); }
73         unsigned stackOffset() { return -m_argv[0]->index() + CallFrame::headerSizeInRegisters; }
74         unsigned argumentCountIncludingThis() { return m_argv.size() - m_padding; }
75         ArgumentsNode* argumentsNode() { return m_argumentsNode; }
76
77     private:
78         ArgumentsNode* m_argumentsNode;
79         Vector<RefPtr<RegisterID>, 8, UnsafeVectorOverflow> m_argv;
80         unsigned m_padding;
81     };
82
83     struct FinallyContext {
84         StatementNode* finallyBlock;
85         RegisterID* iterator;
86         ThrowableExpressionData* enumerationNode;
87         unsigned scopeContextStackSize;
88         unsigned switchContextStackSize;
89         unsigned forInContextStackSize;
90         unsigned tryContextStackSize;
91         unsigned labelScopesSize;
92         unsigned symbolTableStackSize;
93         int finallyDepth;
94         int dynamicScopeDepth;
95     };
96
97     struct ControlFlowContext {
98         bool isFinallyBlock;
99         FinallyContext finallyContext;
100     };
101
102     class ForInContext : public RefCounted<ForInContext> {
103         WTF_MAKE_FAST_ALLOCATED;
104         WTF_MAKE_NONCOPYABLE(ForInContext);
105     public:
106         ForInContext(RegisterID* localRegister)
107             : m_localRegister(localRegister)
108             , m_isValid(true)
109         {
110         }
111
112         virtual ~ForInContext()
113         {
114         }
115
116         bool isValid() const { return m_isValid; }
117         void invalidate() { m_isValid = false; }
118
119         enum ForInContextType {
120             StructureForInContextType,
121             IndexedForInContextType
122         };
123         virtual ForInContextType type() const = 0;
124
125         RegisterID* local() const { return m_localRegister.get(); }
126
127     private:
128         RefPtr<RegisterID> m_localRegister;
129         bool m_isValid;
130     };
131
132     class StructureForInContext : public ForInContext {
133     public:
134         StructureForInContext(RegisterID* localRegister, RegisterID* indexRegister, RegisterID* propertyRegister, RegisterID* enumeratorRegister)
135             : ForInContext(localRegister)
136             , m_indexRegister(indexRegister)
137             , m_propertyRegister(propertyRegister)
138             , m_enumeratorRegister(enumeratorRegister)
139         {
140         }
141
142         virtual ForInContextType type() const
143         {
144             return StructureForInContextType;
145         }
146
147         RegisterID* index() const { return m_indexRegister.get(); }
148         RegisterID* property() const { return m_propertyRegister.get(); }
149         RegisterID* enumerator() const { return m_enumeratorRegister.get(); }
150
151     private:
152         RefPtr<RegisterID> m_indexRegister;
153         RefPtr<RegisterID> m_propertyRegister;
154         RefPtr<RegisterID> m_enumeratorRegister;
155     };
156
157     class IndexedForInContext : public ForInContext {
158     public:
159         IndexedForInContext(RegisterID* localRegister, RegisterID* indexRegister)
160             : ForInContext(localRegister)
161             , m_indexRegister(indexRegister)
162         {
163         }
164
165         virtual ForInContextType type() const
166         {
167             return IndexedForInContextType;
168         }
169
170         RegisterID* index() const { return m_indexRegister.get(); }
171
172     private:
173         RefPtr<RegisterID> m_indexRegister;
174     };
175
176     struct TryData {
177         RefPtr<Label> target;
178         HandlerType handlerType;
179     };
180
181     struct TryContext {
182         RefPtr<Label> start;
183         TryData* tryData;
184     };
185
186     class Variable {
187     public:
188         enum VariableKind { NormalVariable, SpecialVariable };
189
190         Variable()
191             : m_offset()
192             , m_local(nullptr)
193             , m_attributes(0)
194             , m_kind(NormalVariable)
195             , m_symbolTableConstantIndex(0) // This is meaningless here for this kind of Variable.
196             , m_isLexicallyScoped(false)
197         {
198         }
199         
200         Variable(const Identifier& ident)
201             : m_ident(ident)
202             , m_local(nullptr)
203             , m_attributes(0)
204             , m_kind(NormalVariable) // This is somewhat meaningless here for this kind of Variable.
205             , m_symbolTableConstantIndex(0) // This is meaningless here for this kind of Variable.
206             , m_isLexicallyScoped(false)
207         {
208         }
209
210         Variable(const Identifier& ident, VarOffset offset, RegisterID* local, unsigned attributes, VariableKind kind, int symbolTableConstantIndex, bool isLexicallyScoped)
211             : m_ident(ident)
212             , m_offset(offset)
213             , m_local(local)
214             , m_attributes(attributes)
215             , m_kind(kind)
216             , m_symbolTableConstantIndex(symbolTableConstantIndex)
217             , m_isLexicallyScoped(isLexicallyScoped)
218         {
219         }
220
221         // If it's unset, then it is a non-locally-scoped variable. If it is set, then it could be
222         // a stack variable, a scoped variable in a local scope, or a variable captured in the
223         // direct arguments object.
224         bool isResolved() const { return !!m_offset; }
225         int symbolTableConstantIndex() const { ASSERT(isResolved() && !isSpecial()); return m_symbolTableConstantIndex; }
226         
227         const Identifier& ident() const { return m_ident; }
228         
229         VarOffset offset() const { return m_offset; }
230         bool isLocal() const { return m_offset.isStack(); }
231         RegisterID* local() const { return m_local; }
232
233         bool isReadOnly() const { return m_attributes & ReadOnly; }
234         bool isSpecial() const { return m_kind != NormalVariable; }
235         bool isConst() const { return isReadOnly() && m_isLexicallyScoped; }
236         void setIsReadOnly() { m_attributes |= ReadOnly; }
237
238         void dump(PrintStream&) const;
239
240     private:
241         Identifier m_ident;
242         VarOffset m_offset;
243         RegisterID* m_local;
244         unsigned m_attributes;
245         VariableKind m_kind;
246         int m_symbolTableConstantIndex;
247         bool m_isLexicallyScoped;
248     };
249
250     struct TryRange {
251         RefPtr<Label> start;
252         RefPtr<Label> end;
253         TryData* tryData;
254     };
255
256     enum ProfileTypeBytecodeFlag {
257         ProfileTypeBytecodeClosureVar,
258         ProfileTypeBytecodeLocallyResolved,
259         ProfileTypeBytecodeDoesNotHaveGlobalID,
260         ProfileTypeBytecodeFunctionArgument,
261         ProfileTypeBytecodeFunctionReturnStatement
262     };
263
264     class BytecodeGenerator {
265         WTF_MAKE_FAST_ALLOCATED;
266         WTF_MAKE_NONCOPYABLE(BytecodeGenerator);
267     public:
268         typedef DeclarationStacks::FunctionStack FunctionStack;
269
270         BytecodeGenerator(VM&, ProgramNode*, UnlinkedProgramCodeBlock*, DebuggerMode, const VariableEnvironment*);
271         BytecodeGenerator(VM&, FunctionNode*, UnlinkedFunctionCodeBlock*, DebuggerMode, const VariableEnvironment*);
272         BytecodeGenerator(VM&, EvalNode*, UnlinkedEvalCodeBlock*, DebuggerMode, const VariableEnvironment*);
273         BytecodeGenerator(VM&, ModuleProgramNode*, UnlinkedModuleProgramCodeBlock*, DebuggerMode, const VariableEnvironment*);
274
275         ~BytecodeGenerator();
276         
277         VM* vm() const { return m_vm; }
278         ParserArena& parserArena() const { return m_scopeNode->parserArena(); }
279         const CommonIdentifiers& propertyNames() const { return *m_vm->propertyNames; }
280
281         bool isConstructor() const { return m_codeBlock->isConstructor(); }
282         DerivedContextType derivedContextType() const { return m_derivedContextType; }
283         bool usesArrowFunction() const { return m_scopeNode->usesArrowFunction(); }
284         bool needsToUpdateArrowFunctionContext() const { return m_needsToUpdateArrowFunctionContext; }
285         bool usesEval() const { return m_scopeNode->usesEval(); }
286         bool usesThis() const { return m_scopeNode->usesThis(); }
287         ConstructorKind constructorKind() const { return m_codeBlock->constructorKind(); }
288         SuperBinding superBinding() const { return m_codeBlock->superBinding(); }
289         JSParserScriptMode scriptMode() const { return m_codeBlock->scriptMode(); }
290
291         template<typename... Args>
292         static ParserError generate(VM& vm, Args&& ...args)
293         {
294             DeferGC deferGC(vm.heap);
295             auto bytecodeGenerator = std::make_unique<BytecodeGenerator>(vm, std::forward<Args>(args)...);
296             return bytecodeGenerator->generate(); 
297         }
298
299         bool isArgumentNumber(const Identifier&, int);
300
301         Variable variable(const Identifier&, ThisResolutionType = ThisResolutionType::Local);
302         
303         enum ExistingVariableMode { VerifyExisting, IgnoreExisting };
304         void createVariable(const Identifier&, VarKind, SymbolTable*, ExistingVariableMode = VerifyExisting); // Creates the variable, or asserts that the already-created variable is sufficiently compatible.
305         
306         // Returns the register storing "this"
307         RegisterID* thisRegister() { return &m_thisRegister; }
308         RegisterID* argumentsRegister() { return m_argumentsRegister; }
309         RegisterID* newTarget()
310         {
311             return m_newTargetRegister;
312         }
313
314         RegisterID* scopeRegister() { return m_scopeRegister; }
315
316         RegisterID* generatorRegister() { return m_generatorRegister; }
317
318         // Returns the next available temporary register. Registers returned by
319         // newTemporary require a modified form of reference counting: any
320         // register with a refcount of 0 is considered "available", meaning that
321         // the next instruction may overwrite it.
322         RegisterID* newTemporary();
323
324         // The same as newTemporary(), but this function returns "suggestion" if
325         // "suggestion" is a temporary. This function is helpful in situations
326         // where you've put "suggestion" in a RefPtr, but you'd like to allow
327         // the next instruction to overwrite it anyway.
328         RegisterID* newTemporaryOr(RegisterID* suggestion) { return suggestion->isTemporary() ? suggestion : newTemporary(); }
329
330         // Functions for handling of dst register
331
332         RegisterID* ignoredResult() { return &m_ignoredResultRegister; }
333
334         // This will be allocated in the temporary region of registers, but it will
335         // not be marked as a temporary. This will ensure that finalDestination() does
336         // not overwrite a block scope variable that it mistakes as a temporary. These
337         // registers can be (and are) reclaimed when the lexical scope they belong to
338         // is no longer on the symbol table stack.
339         RegisterID* newBlockScopeVariable();
340
341         // Returns a place to write intermediate values of an operation
342         // which reuses dst if it is safe to do so.
343         RegisterID* tempDestination(RegisterID* dst)
344         {
345             return (dst && dst != ignoredResult() && dst->isTemporary()) ? dst : newTemporary();
346         }
347
348         // Returns the place to write the final output of an operation.
349         RegisterID* finalDestination(RegisterID* originalDst, RegisterID* tempDst = 0)
350         {
351             if (originalDst && originalDst != ignoredResult())
352                 return originalDst;
353             ASSERT(tempDst != ignoredResult());
354             if (tempDst && tempDst->isTemporary())
355                 return tempDst;
356             return newTemporary();
357         }
358
359         RegisterID* destinationForAssignResult(RegisterID* dst)
360         {
361             if (dst && dst != ignoredResult())
362                 return dst->isTemporary() ? dst : newTemporary();
363             return 0;
364         }
365
366         // Moves src to dst if dst is not null and is different from src, otherwise just returns src.
367         RegisterID* moveToDestinationIfNeeded(RegisterID* dst, RegisterID* src)
368         {
369             return dst == ignoredResult() ? 0 : (dst && dst != src) ? emitMove(dst, src) : src;
370         }
371
372         LabelScopePtr newLabelScope(LabelScope::Type, const Identifier* = 0);
373         PassRefPtr<Label> newLabel();
374
375         void emitNode(RegisterID* dst, StatementNode* n)
376         {
377             SetForScope<bool> tailPositionPoisoner(m_inTailPosition, false);
378             return emitNodeInTailPosition(dst, n);
379         }
380
381         void emitNodeInTailPosition(RegisterID* dst, StatementNode* n)
382         {
383             // Node::emitCode assumes that dst, if provided, is either a local or a referenced temporary.
384             ASSERT(!dst || dst == ignoredResult() || !dst->isTemporary() || dst->refCount());
385             if (UNLIKELY(!m_vm->isSafeToRecurse())) {
386                 emitThrowExpressionTooDeepException();
387                 return;
388             }
389             if (UNLIKELY(n->needsDebugHook()))
390                 emitDebugHook(n);
391             n->emitBytecode(*this, dst);
392         }
393
394         void emitNode(StatementNode* n)
395         {
396             emitNode(nullptr, n);
397         }
398
399         void emitNodeInTailPosition(StatementNode* n)
400         {
401             emitNodeInTailPosition(nullptr, n);
402         }
403
404         RegisterID* emitNode(RegisterID* dst, ExpressionNode* n)
405         {
406             SetForScope<bool> tailPositionPoisoner(m_inTailPosition, false);
407             return emitNodeInTailPosition(dst, n);
408         }
409
410         RegisterID* emitNodeInTailPosition(RegisterID* dst, ExpressionNode* n)
411         {
412             // Node::emitCode assumes that dst, if provided, is either a local or a referenced temporary.
413             ASSERT(!dst || dst == ignoredResult() || !dst->isTemporary() || dst->refCount());
414             if (UNLIKELY(!m_vm->isSafeToRecurse()))
415                 return emitThrowExpressionTooDeepException();
416             if (UNLIKELY(n->needsDebugHook()))
417                 emitDebugHook(n);
418             return n->emitBytecode(*this, dst);
419         }
420
421         RegisterID* emitNode(ExpressionNode* n)
422         {
423             return emitNode(nullptr, n);
424         }
425
426         RegisterID* emitNodeInTailPosition(ExpressionNode* n)
427         {
428             return emitNodeInTailPosition(nullptr, n);
429         }
430
431         void emitNodeInConditionContext(ExpressionNode* n, Label* trueTarget, Label* falseTarget, FallThroughMode fallThroughMode)
432         {
433             if (UNLIKELY(!m_vm->isSafeToRecurse())) {
434                 emitThrowExpressionTooDeepException();
435                 return;
436             }
437             n->emitBytecodeInConditionContext(*this, trueTarget, falseTarget, fallThroughMode);
438         }
439
440         void emitExpressionInfo(const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd)
441         {            
442             ASSERT(divot.offset >= divotStart.offset);
443             ASSERT(divotEnd.offset >= divot.offset);
444
445             int sourceOffset = m_scopeNode->source().startOffset();
446             unsigned firstLine = m_scopeNode->source().firstLine();
447
448             int divotOffset = divot.offset - sourceOffset;
449             int startOffset = divot.offset - divotStart.offset;
450             int endOffset = divotEnd.offset - divot.offset;
451
452             unsigned line = divot.line;
453             ASSERT(line >= firstLine);
454             line -= firstLine;
455
456             int lineStart = divot.lineStartOffset;
457             if (lineStart > sourceOffset)
458                 lineStart -= sourceOffset;
459             else
460                 lineStart = 0;
461
462             if (divotOffset < lineStart)
463                 return;
464
465             unsigned column = divotOffset - lineStart;
466
467             unsigned instructionOffset = instructions().size();
468             if (!m_isBuiltinFunction)
469                 m_codeBlock->addExpressionInfo(instructionOffset, divotOffset, startOffset, endOffset, line, column);
470         }
471
472
473         ALWAYS_INLINE bool leftHandSideNeedsCopy(bool rightHasAssignments, bool rightIsPure)
474         {
475             return (m_codeType != FunctionCode || rightHasAssignments) && !rightIsPure;
476         }
477
478         ALWAYS_INLINE PassRefPtr<RegisterID> emitNodeForLeftHandSide(ExpressionNode* n, bool rightHasAssignments, bool rightIsPure)
479         {
480             if (leftHandSideNeedsCopy(rightHasAssignments, rightIsPure)) {
481                 PassRefPtr<RegisterID> dst = newTemporary();
482                 emitNode(dst.get(), n);
483                 return dst;
484             }
485
486             return emitNode(n);
487         }
488
489         void hoistSloppyModeFunctionIfNecessary(const Identifier& functionName);
490
491     private:
492         void emitTypeProfilerExpressionInfo(const JSTextPosition& startDivot, const JSTextPosition& endDivot);
493     public:
494
495         // This doesn't emit expression info. If using this, make sure you shouldn't be emitting text offset.
496         void emitProfileType(RegisterID* registerToProfile, ProfileTypeBytecodeFlag); 
497         // These variables are associated with variables in a program. They could be Locals, LocalClosureVar, or ClosureVar.
498         void emitProfileType(RegisterID* registerToProfile, const Variable&, const JSTextPosition& startDivot, const JSTextPosition& endDivot);
499
500         void emitProfileType(RegisterID* registerToProfile, ProfileTypeBytecodeFlag, const JSTextPosition& startDivot, const JSTextPosition& endDivot);
501         // These are not associated with variables and don't have a global id.
502         void emitProfileType(RegisterID* registerToProfile, const JSTextPosition& startDivot, const JSTextPosition& endDivot);
503
504         void emitProfileControlFlow(int);
505         
506         RegisterID* emitLoadArrowFunctionLexicalEnvironment(const Identifier&);
507         RegisterID* ensureThis();
508         void emitLoadThisFromArrowFunctionLexicalEnvironment();
509         RegisterID* emitLoadNewTargetFromArrowFunctionLexicalEnvironment();
510
511         RegisterID* emitLoad(RegisterID* dst, bool);
512         RegisterID* emitLoad(RegisterID* dst, const Identifier&);
513         RegisterID* emitLoad(RegisterID* dst, JSValue, SourceCodeRepresentation = SourceCodeRepresentation::Other);
514         RegisterID* emitLoadGlobalObject(RegisterID* dst);
515
516         RegisterID* emitUnaryOp(OpcodeID, RegisterID* dst, RegisterID* src);
517         RegisterID* emitUnaryOp(OpcodeID, RegisterID* dst, RegisterID* src, OperandTypes);
518         RegisterID* emitUnaryOpProfiled(OpcodeID, RegisterID* dst, RegisterID* src);
519         RegisterID* emitBinaryOp(OpcodeID, RegisterID* dst, RegisterID* src1, RegisterID* src2, OperandTypes);
520         RegisterID* emitEqualityOp(OpcodeID, RegisterID* dst, RegisterID* src1, RegisterID* src2);
521         RegisterID* emitUnaryNoDstOp(OpcodeID, RegisterID* src);
522
523         RegisterID* emitCreateThis(RegisterID* dst);
524         void emitTDZCheck(RegisterID* target);
525         bool needsTDZCheck(const Variable&);
526         void emitTDZCheckIfNecessary(const Variable&, RegisterID* target, RegisterID* scope);
527         void liftTDZCheckIfPossible(const Variable&);
528         RegisterID* emitNewObject(RegisterID* dst);
529         RegisterID* emitNewArray(RegisterID* dst, ElementNode*, unsigned length); // stops at first elision
530         RegisterID* emitNewArrayWithSize(RegisterID* dst, RegisterID* length);
531
532         RegisterID* emitNewFunction(RegisterID* dst, FunctionMetadataNode*);
533         RegisterID* emitNewFunctionExpression(RegisterID* dst, FuncExprNode*);
534         RegisterID* emitNewDefaultConstructor(RegisterID* dst, ConstructorKind, const Identifier& name, const Identifier& ecmaName, const SourceCode& classSource);
535         RegisterID* emitNewArrowFunctionExpression(RegisterID*, ArrowFuncExprNode*);
536         RegisterID* emitNewMethodDefinition(RegisterID* dst, MethodDefinitionNode*);
537         RegisterID* emitNewRegExp(RegisterID* dst, RegExp*);
538
539         void emitSetFunctionNameIfNeeded(ExpressionNode* valueNode, RegisterID* value, RegisterID* name);
540
541         RegisterID* emitMoveLinkTimeConstant(RegisterID* dst, LinkTimeConstant);
542         RegisterID* emitMoveEmptyValue(RegisterID* dst);
543         RegisterID* emitMove(RegisterID* dst, RegisterID* src);
544
545         RegisterID* emitToNumber(RegisterID* dst, RegisterID* src) { return emitUnaryOpProfiled(op_to_number, dst, src); }
546         RegisterID* emitToString(RegisterID* dst, RegisterID* src) { return emitUnaryOp(op_to_string, dst, src); }
547         RegisterID* emitInc(RegisterID* srcDst);
548         RegisterID* emitDec(RegisterID* srcDst);
549
550         RegisterID* emitOverridesHasInstance(RegisterID* dst, RegisterID* constructor, RegisterID* hasInstanceValue);
551         RegisterID* emitInstanceOf(RegisterID* dst, RegisterID* value, RegisterID* basePrototype);
552         RegisterID* emitInstanceOfCustom(RegisterID* dst, RegisterID* value, RegisterID* constructor, RegisterID* hasInstanceValue);
553         RegisterID* emitTypeOf(RegisterID* dst, RegisterID* src) { return emitUnaryOp(op_typeof, dst, src); }
554         RegisterID* emitIn(RegisterID* dst, RegisterID* property, RegisterID* base) { return emitBinaryOp(op_in, dst, property, base, OperandTypes()); }
555
556         RegisterID* emitTryGetById(RegisterID* dst, RegisterID* base, const Identifier& property);
557         RegisterID* emitGetById(RegisterID* dst, RegisterID* base, const Identifier& property);
558         RegisterID* emitGetById(RegisterID* dst, RegisterID* base, RegisterID* thisVal, const Identifier& property);
559         RegisterID* emitPutById(RegisterID* base, const Identifier& property, RegisterID* value);
560         RegisterID* emitPutById(RegisterID* base, RegisterID* thisValue, const Identifier& property, RegisterID* value);
561         RegisterID* emitDirectPutById(RegisterID* base, const Identifier& property, RegisterID* value, PropertyNode::PutType);
562         RegisterID* emitDeleteById(RegisterID* dst, RegisterID* base, const Identifier&);
563         RegisterID* emitGetByVal(RegisterID* dst, RegisterID* base, RegisterID* property);
564         RegisterID* emitGetByVal(RegisterID* dst, RegisterID* base, RegisterID* thisValue, RegisterID* property);
565         RegisterID* emitGetArgumentByVal(RegisterID* dst, RegisterID* base, RegisterID* property);
566         RegisterID* emitPutByVal(RegisterID* base, RegisterID* property, RegisterID* value);
567         RegisterID* emitPutByVal(RegisterID* base, RegisterID* thisValue, RegisterID* property, RegisterID* value);
568         RegisterID* emitDirectPutByVal(RegisterID* base, RegisterID* property, RegisterID* value);
569         RegisterID* emitDeleteByVal(RegisterID* dst, RegisterID* base, RegisterID* property);
570         RegisterID* emitPutByIndex(RegisterID* base, unsigned index, RegisterID* value);
571
572         RegisterID* emitAssert(RegisterID* condition, int line);
573
574         void emitPutGetterById(RegisterID* base, const Identifier& property, unsigned propertyDescriptorOptions, RegisterID* getter);
575         void emitPutSetterById(RegisterID* base, const Identifier& property, unsigned propertyDescriptorOptions, RegisterID* setter);
576         void emitPutGetterSetter(RegisterID* base, const Identifier& property, unsigned attributes, RegisterID* getter, RegisterID* setter);
577         void emitPutGetterByVal(RegisterID* base, RegisterID* property, unsigned propertyDescriptorOptions, RegisterID* getter);
578         void emitPutSetterByVal(RegisterID* base, RegisterID* property, unsigned propertyDescriptorOptions, RegisterID* setter);
579
580         RegisterID* emitGetArgument(RegisterID* dst, int32_t index);
581
582         // Initialize object with generator fields (@generatorThis, @generatorNext, @generatorState, @generatorFrame)
583         void emitPutGeneratorFields(RegisterID* nextFunction);
584
585         ExpectedFunction expectedFunctionForIdentifier(const Identifier&);
586         RegisterID* emitCall(RegisterID* dst, RegisterID* func, ExpectedFunction, CallArguments&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall);
587         RegisterID* emitCallInTailPosition(RegisterID* dst, RegisterID* func, ExpectedFunction, CallArguments&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall);
588         RegisterID* emitCallEval(RegisterID* dst, RegisterID* func, CallArguments&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall);
589         RegisterID* emitCallVarargs(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall);
590         RegisterID* emitCallVarargsInTailPosition(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall);
591         RegisterID* emitCallForwardArgumentsInTailPosition(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall);
592
593         enum PropertyDescriptorOption {
594             PropertyConfigurable = 1,
595             PropertyWritable     = 1 << 1,
596             PropertyEnumerable   = 1 << 2,
597         };
598         void emitCallDefineProperty(RegisterID* newObj, RegisterID* propertyNameRegister,
599             RegisterID* valueRegister, RegisterID* getterRegister, RegisterID* setterRegister, unsigned options, const JSTextPosition&);
600
601         void emitEnumeration(ThrowableExpressionData* enumerationNode, ExpressionNode* subjectNode, const std::function<void(BytecodeGenerator&, RegisterID*)>& callBack, ForOfNode* = nullptr, RegisterID* forLoopSymbolTable = nullptr);
602
603         RegisterID* emitGetTemplateObject(RegisterID* dst, TaggedTemplateNode*);
604
605         RegisterID* emitReturn(RegisterID* src);
606         RegisterID* emitEnd(RegisterID* src) { return emitUnaryNoDstOp(op_end, src); }
607
608         RegisterID* emitConstruct(RegisterID* dst, RegisterID* func, ExpectedFunction, CallArguments&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd);
609         RegisterID* emitStrcat(RegisterID* dst, RegisterID* src, int count);
610         void emitToPrimitive(RegisterID* dst, RegisterID* src);
611
612         ResolveType resolveType();
613         RegisterID* emitResolveConstantLocal(RegisterID* dst, const Variable&);
614         RegisterID* emitResolveScope(RegisterID* dst, const Variable&);
615         RegisterID* emitGetFromScope(RegisterID* dst, RegisterID* scope, const Variable&, ResolveMode);
616         RegisterID* emitPutToScope(RegisterID* scope, const Variable&, RegisterID* value, ResolveMode, InitializationMode);
617         RegisterID* initializeVariable(const Variable&, RegisterID* value);
618
619         PassRefPtr<Label> emitLabel(Label*);
620         void emitLoopHint();
621         PassRefPtr<Label> emitJump(Label* target);
622         PassRefPtr<Label> emitJumpIfTrue(RegisterID* cond, Label* target);
623         PassRefPtr<Label> emitJumpIfFalse(RegisterID* cond, Label* target);
624         PassRefPtr<Label> emitJumpIfNotFunctionCall(RegisterID* cond, Label* target);
625         PassRefPtr<Label> emitJumpIfNotFunctionApply(RegisterID* cond, Label* target);
626         void emitPopScopes(RegisterID* srcDst, int targetScopeDepth);
627
628         void emitEnter();
629         void emitWatchdog();
630
631         RegisterID* emitHasIndexedProperty(RegisterID* dst, RegisterID* base, RegisterID* propertyName);
632         RegisterID* emitHasStructureProperty(RegisterID* dst, RegisterID* base, RegisterID* propertyName, RegisterID* enumerator);
633         RegisterID* emitHasGenericProperty(RegisterID* dst, RegisterID* base, RegisterID* propertyName);
634         RegisterID* emitGetPropertyEnumerator(RegisterID* dst, RegisterID* base);
635         RegisterID* emitGetEnumerableLength(RegisterID* dst, RegisterID* base);
636         RegisterID* emitGetStructurePropertyEnumerator(RegisterID* dst, RegisterID* base, RegisterID* length);
637         RegisterID* emitGetGenericPropertyEnumerator(RegisterID* dst, RegisterID* base, RegisterID* length, RegisterID* structureEnumerator);
638         RegisterID* emitEnumeratorStructurePropertyName(RegisterID* dst, RegisterID* enumerator, RegisterID* index);
639         RegisterID* emitEnumeratorGenericPropertyName(RegisterID* dst, RegisterID* enumerator, RegisterID* index);
640         RegisterID* emitToIndexString(RegisterID* dst, RegisterID* index);
641
642         RegisterID* emitIsCellWithType(RegisterID* dst, RegisterID* src, JSType);
643         RegisterID* emitIsJSArray(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, ArrayType); }
644         RegisterID* emitIsProxyObject(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, ProxyObjectType); }
645         RegisterID* emitIsRegExpObject(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, RegExpObjectType); }
646         RegisterID* emitIsMap(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, JSMapType); }
647         RegisterID* emitIsSet(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, JSSetType); }
648         RegisterID* emitIsObject(RegisterID* dst, RegisterID* src);
649         RegisterID* emitIsUndefined(RegisterID* dst, RegisterID* src);
650         RegisterID* emitIsEmpty(RegisterID* dst, RegisterID* src);
651         RegisterID* emitIsDerivedArray(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, DerivedArrayType); }
652         void emitRequireObjectCoercible(RegisterID* value, const String& error);
653
654         RegisterID* emitIteratorNext(RegisterID* dst, RegisterID* iterator, const ThrowableExpressionData* node);
655         RegisterID* emitIteratorNextWithValue(RegisterID* dst, RegisterID* iterator, RegisterID* value, const ThrowableExpressionData* node);
656         void emitIteratorClose(RegisterID* iterator, const ThrowableExpressionData* node);
657
658         RegisterID* emitRestParameter(RegisterID* result, unsigned numParametersToSkip);
659
660         bool emitReadOnlyExceptionIfNeeded(const Variable&);
661
662         // Start a try block. 'start' must have been emitted.
663         TryData* pushTry(Label* start);
664         // End a try block. 'end' must have been emitted.
665         void popTryAndEmitCatch(TryData*, RegisterID* exceptionRegister, RegisterID* thrownValueRegister, Label* end, HandlerType);
666
667         void emitThrow(RegisterID* exc)
668         { 
669             m_usesExceptions = true;
670             emitUnaryNoDstOp(op_throw, exc);
671         }
672
673         void emitThrowStaticError(ErrorType, RegisterID*);
674         void emitThrowStaticError(ErrorType, const Identifier& message);
675         void emitThrowReferenceError(const String& message);
676         void emitThrowTypeError(const String& message);
677         void emitThrowTypeError(const Identifier& message);
678         void emitThrowRangeError(const Identifier& message);
679         void emitThrowOutOfMemoryError();
680
681         void emitPushCatchScope(VariableEnvironment&);
682         void emitPopCatchScope(VariableEnvironment&);
683
684         void emitGetScope();
685         RegisterID* emitPushWithScope(RegisterID* objectScope);
686         void emitPopWithScope();
687         void emitPutThisToArrowFunctionContextScope();
688         void emitPutNewTargetToArrowFunctionContextScope();
689         void emitPutDerivedConstructorToArrowFunctionContextScope();
690         RegisterID* emitLoadDerivedConstructorFromArrowFunctionLexicalEnvironment();
691
692         void emitDebugHook(DebugHookType, const JSTextPosition&);
693         void emitDebugHook(DebugHookType, unsigned line, unsigned charOffset, unsigned lineStart);
694         void emitDebugHook(StatementNode*);
695         void emitDebugHook(ExpressionNode*);
696         void emitWillLeaveCallFrameDebugHook();
697
698         bool isInFinallyBlock() { return m_finallyDepth > 0; }
699
700         void pushFinallyContext(StatementNode* finallyBlock);
701         void popFinallyContext();
702         void pushIteratorCloseContext(RegisterID* iterator, ThrowableExpressionData* enumerationNode);
703         void popIteratorCloseContext();
704
705         void pushIndexedForInScope(RegisterID* local, RegisterID* index);
706         void popIndexedForInScope(RegisterID* local);
707         void pushStructureForInScope(RegisterID* local, RegisterID* index, RegisterID* property, RegisterID* enumerator);
708         void popStructureForInScope(RegisterID* local);
709         void invalidateForInContextForLocal(RegisterID* local);
710
711         LabelScopePtr breakTarget(const Identifier&);
712         LabelScopePtr continueTarget(const Identifier&);
713
714         void beginSwitch(RegisterID*, SwitchInfo::SwitchType);
715         void endSwitch(uint32_t clauseCount, RefPtr<Label>*, ExpressionNode**, Label* defaultLabel, int32_t min, int32_t range);
716
717         void emitYieldPoint(RegisterID*);
718
719         void emitGeneratorStateLabel();
720         void emitGeneratorStateChange(int32_t state);
721         RegisterID* emitYield(RegisterID* argument);
722         RegisterID* emitDelegateYield(RegisterID* argument, ThrowableExpressionData*);
723         RegisterID* generatorStateRegister() { return &m_parameters[static_cast<int32_t>(JSGeneratorFunction::GeneratorArgument::State)]; }
724         RegisterID* generatorValueRegister() { return &m_parameters[static_cast<int32_t>(JSGeneratorFunction::GeneratorArgument::Value)]; }
725         RegisterID* generatorResumeModeRegister() { return &m_parameters[static_cast<int32_t>(JSGeneratorFunction::GeneratorArgument::ResumeMode)]; }
726         RegisterID* generatorFrameRegister() { return &m_parameters[static_cast<int32_t>(JSGeneratorFunction::GeneratorArgument::Frame)]; }
727
728         CodeType codeType() const { return m_codeType; }
729
730         bool shouldEmitDebugHooks() { return m_shouldEmitDebugHooks; }
731         
732         bool isStrictMode() const { return m_codeBlock->isStrictMode(); }
733
734         SourceParseMode parseMode() const { return m_codeBlock->parseMode(); }
735         
736         bool isBuiltinFunction() const { return m_isBuiltinFunction; }
737
738         OpcodeID lastOpcodeID() const { return m_lastOpcodeID; }
739         
740         bool isDerivedConstructorContext() { return m_derivedContextType == DerivedContextType::DerivedConstructorContext; }
741         bool isDerivedClassContext() { return m_derivedContextType == DerivedContextType::DerivedMethodContext; }
742         bool isArrowFunction() { return m_codeBlock->isArrowFunction(); }
743
744         enum class TDZCheckOptimization { Optimize, DoNotOptimize };
745         enum class NestedScopeType { IsNested, IsNotNested };
746     private:
747         enum class TDZRequirement { UnderTDZ, NotUnderTDZ };
748         enum class ScopeType { CatchScope, LetConstScope, FunctionNameScope };
749         enum class ScopeRegisterType { Var, Block };
750         void pushLexicalScopeInternal(VariableEnvironment&, TDZCheckOptimization, NestedScopeType, RegisterID** constantSymbolTableResult, TDZRequirement, ScopeType, ScopeRegisterType);
751         void initializeBlockScopedFunctions(VariableEnvironment&, FunctionStack&, RegisterID* constantSymbolTable);
752         void popLexicalScopeInternal(VariableEnvironment&);
753         template<typename LookUpVarKindFunctor>
754         bool instantiateLexicalVariables(const VariableEnvironment&, SymbolTable*, ScopeRegisterType, LookUpVarKindFunctor);
755         void emitPrefillStackTDZVariables(const VariableEnvironment&, SymbolTable*);
756         void emitPopScope(RegisterID* dst, RegisterID* scope);
757         RegisterID* emitGetParentScope(RegisterID* dst, RegisterID* scope);
758         void emitPushFunctionNameScope(const Identifier& property, RegisterID* value, bool isCaptured);
759         void emitNewFunctionExpressionCommon(RegisterID*, FunctionMetadataNode*);
760         
761         bool isNewTargetUsedInInnerArrowFunction();
762         bool isSuperUsedInInnerArrowFunction();
763         bool isArgumentsUsedInInnerArrowFunction();
764
765     public:
766         bool isSuperCallUsedInInnerArrowFunction();
767         bool isThisUsedInInnerArrowFunction();
768         void pushLexicalScope(VariableEnvironmentNode*, TDZCheckOptimization, NestedScopeType = NestedScopeType::IsNotNested, RegisterID** constantSymbolTableResult = nullptr, bool shouldInitializeBlockScopedFunctions = true);
769         void popLexicalScope(VariableEnvironmentNode*);
770         void prepareLexicalScopeForNextForLoopIteration(VariableEnvironmentNode*, RegisterID* loopSymbolTable);
771         int labelScopeDepth() const;
772
773     private:
774         ParserError generate();
775         void reclaimFreeRegisters();
776         Variable variableForLocalEntry(const Identifier&, const SymbolTableEntry&, int symbolTableConstantIndex, bool isLexicallyScoped);
777
778         void emitOpcode(OpcodeID);
779         UnlinkedArrayAllocationProfile newArrayAllocationProfile();
780         UnlinkedObjectAllocationProfile newObjectAllocationProfile();
781         UnlinkedArrayProfile newArrayProfile();
782         UnlinkedValueProfile emitProfiledOpcode(OpcodeID);
783         int kill(RegisterID* dst)
784         {
785             int index = dst->index();
786             m_staticPropertyAnalyzer.kill(index);
787             return index;
788         }
789
790         void retrieveLastBinaryOp(int& dstIndex, int& src1Index, int& src2Index);
791         void retrieveLastUnaryOp(int& dstIndex, int& srcIndex);
792         ALWAYS_INLINE void rewindBinaryOp();
793         ALWAYS_INLINE void rewindUnaryOp();
794
795         void allocateCalleeSaveSpace();
796         void allocateAndEmitScope();
797         void emitComplexPopScopes(RegisterID*, ControlFlowContext* topScope, ControlFlowContext* bottomScope);
798
799         typedef HashMap<double, JSValue> NumberMap;
800         typedef HashMap<UniquedStringImpl*, JSString*, IdentifierRepHash> IdentifierStringMap;
801         typedef HashMap<TemplateRegistryKey, JSTemplateRegistryKey*> TemplateRegistryKeyMap;
802         
803         // Helper for emitCall() and emitConstruct(). This works because the set of
804         // expected functions have identical behavior for both call and construct
805         // (i.e. "Object()" is identical to "new Object()").
806         ExpectedFunction emitExpectedFunctionSnippet(RegisterID* dst, RegisterID* func, ExpectedFunction, CallArguments&, Label* done);
807         
808         RegisterID* emitCall(OpcodeID, RegisterID* dst, RegisterID* func, ExpectedFunction, CallArguments&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall);
809
810         RegisterID* newRegister();
811
812         // Adds an anonymous local var slot. To give this slot a name, add it to symbolTable().
813         RegisterID* addVar()
814         {
815             ++m_codeBlock->m_numVars;
816             RegisterID* result = newRegister();
817             ASSERT(VirtualRegister(result->index()).toLocal() == m_codeBlock->m_numVars - 1);
818             result->ref(); // We should never free this slot.
819             return result;
820         }
821
822         // Initializes the stack form the parameter; does nothing for the symbol table.
823         RegisterID* initializeNextParameter();
824         UniquedStringImpl* visibleNameForParameter(DestructuringPatternNode*);
825         
826         RegisterID& registerFor(VirtualRegister reg)
827         {
828             if (reg.isLocal())
829                 return m_calleeLocals[reg.toLocal()];
830
831             if (reg.offset() == CallFrameSlot::callee)
832                 return m_calleeRegister;
833
834             ASSERT(m_parameters.size());
835             return m_parameters[reg.toArgument()];
836         }
837
838         bool hasConstant(const Identifier&) const;
839         unsigned addConstant(const Identifier&);
840         RegisterID* addConstantValue(JSValue, SourceCodeRepresentation = SourceCodeRepresentation::Other);
841         RegisterID* addConstantEmptyValue();
842         unsigned addRegExp(RegExp*);
843
844         unsigned addConstantBuffer(unsigned length);
845         
846         UnlinkedFunctionExecutable* makeFunction(FunctionMetadataNode* metadata)
847         {
848             DerivedContextType newDerivedContextType = DerivedContextType::None;
849
850             if (SourceParseModeSet(SourceParseMode::ArrowFunctionMode, SourceParseMode::AsyncArrowFunctionMode).contains(metadata->parseMode())) {
851                 if (constructorKind() == ConstructorKind::Extends || isDerivedConstructorContext())
852                     newDerivedContextType = DerivedContextType::DerivedConstructorContext;
853                 else if (m_codeBlock->isClassContext() || isDerivedClassContext())
854                     newDerivedContextType = DerivedContextType::DerivedMethodContext;
855             }
856
857             VariableEnvironment variablesUnderTDZ;
858             getVariablesUnderTDZ(variablesUnderTDZ);
859
860             // FIXME: These flags, ParserModes and propagation to XXXCodeBlocks should be reorganized.
861             // https://bugs.webkit.org/show_bug.cgi?id=151547
862             SourceParseMode parseMode = metadata->parseMode();
863             ConstructAbility constructAbility = constructAbilityForParseMode(parseMode);
864             if (parseMode == SourceParseMode::MethodMode && metadata->constructorKind() != ConstructorKind::None)
865                 constructAbility = ConstructAbility::CanConstruct;
866
867             return UnlinkedFunctionExecutable::create(m_vm, m_scopeNode->source(), metadata, isBuiltinFunction() ? UnlinkedBuiltinFunction : UnlinkedNormalFunction, constructAbility, scriptMode(), variablesUnderTDZ, newDerivedContextType);
868         }
869
870         void getVariablesUnderTDZ(VariableEnvironment&);
871
872         RegisterID* emitConstructVarargs(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall);
873         RegisterID* emitCallVarargs(OpcodeID, RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd, DebuggableCall);
874         
875         void emitLogShadowChickenPrologueIfNecessary();
876         void emitLogShadowChickenTailIfNecessary();
877
878         void initializeParameters(FunctionParameters&);
879         void initializeVarLexicalEnvironment(int symbolTableConstantIndex, SymbolTable* functionSymbolTable, bool hasCapturedVariables);
880         void initializeDefaultParameterValuesAndSetupFunctionScopeStack(FunctionParameters&, bool isSimpleParameterList, FunctionNode*, SymbolTable*, int symbolTableConstantIndex, const std::function<bool (UniquedStringImpl*)>& captures, bool shouldCreateArgumentsVariableInParameterScope);
881         void initializeArrowFunctionContextScopeIfNeeded(SymbolTable* functionSymbolTable = nullptr, bool canReuseLexicalEnvironment = false);
882
883     public:
884         JSString* addStringConstant(const Identifier&);
885         JSTemplateRegistryKey* addTemplateRegistryKeyConstant(const TemplateRegistryKey&);
886
887         Vector<UnlinkedInstruction, 0, UnsafeVectorOverflow>& instructions() { return m_instructions; }
888
889         RegisterID* emitThrowExpressionTooDeepException();
890
891     private:
892         Vector<UnlinkedInstruction, 0, UnsafeVectorOverflow> m_instructions;
893
894         bool m_shouldEmitDebugHooks;
895
896         struct SymbolTableStackEntry {
897             SymbolTable* m_symbolTable;
898             RegisterID* m_scope;
899             bool m_isWithScope;
900             int m_symbolTableConstantIndex;
901         };
902         Vector<SymbolTableStackEntry> m_symbolTableStack;
903         enum class TDZNecessityLevel {
904             NotNeeded,
905             Optimize,
906             DoNotOptimize
907         };
908         typedef HashMap<RefPtr<UniquedStringImpl>, TDZNecessityLevel, IdentifierRepHash> TDZMap;
909         Vector<TDZMap> m_TDZStack;
910         Optional<size_t> m_varScopeSymbolTableIndex;
911         void pushTDZVariables(const VariableEnvironment&, TDZCheckOptimization, TDZRequirement);
912
913         ScopeNode* const m_scopeNode;
914         Strong<UnlinkedCodeBlock> m_codeBlock;
915
916         // Some of these objects keep pointers to one another. They are arranged
917         // to ensure a sane destruction order that avoids references to freed memory.
918         HashSet<RefPtr<UniquedStringImpl>, IdentifierRepHash> m_functions;
919         RegisterID m_ignoredResultRegister;
920         RegisterID m_thisRegister;
921         RegisterID m_calleeRegister;
922         RegisterID* m_scopeRegister { nullptr };
923         RegisterID* m_topMostScope { nullptr };
924         RegisterID* m_argumentsRegister { nullptr };
925         RegisterID* m_lexicalEnvironmentRegister { nullptr };
926         RegisterID* m_generatorRegister { nullptr };
927         RegisterID* m_emptyValueRegister { nullptr };
928         RegisterID* m_globalObjectRegister { nullptr };
929         RegisterID* m_newTargetRegister { nullptr };
930         RegisterID* m_isDerivedConstuctor { nullptr };
931         RegisterID* m_linkTimeConstantRegisters[LinkTimeConstantCount];
932         RegisterID* m_arrowFunctionContextLexicalEnvironmentRegister { nullptr };
933
934         SegmentedVector<RegisterID*, 16> m_localRegistersForCalleeSaveRegisters;
935         SegmentedVector<RegisterID, 32> m_constantPoolRegisters;
936         SegmentedVector<RegisterID, 32> m_calleeLocals;
937         SegmentedVector<RegisterID, 32> m_parameters;
938         SegmentedVector<Label, 32> m_labels;
939         LabelScopeStore m_labelScopes;
940         int m_finallyDepth { 0 };
941         int m_localScopeDepth { 0 };
942         const CodeType m_codeType;
943
944         int localScopeDepth() const;
945         void pushScopedControlFlowContext();
946         void popScopedControlFlowContext();
947
948         Vector<ControlFlowContext, 0, UnsafeVectorOverflow> m_scopeContextStack;
949         Vector<SwitchInfo> m_switchContextStack;
950         Vector<RefPtr<ForInContext>> m_forInContextStack;
951         Vector<TryContext> m_tryContextStack;
952         unsigned m_yieldPoints { 0 };
953
954         Strong<SymbolTable> m_generatorFrameSymbolTable;
955         int m_generatorFrameSymbolTableIndex { 0 };
956
957         enum FunctionVariableType : uint8_t { NormalFunctionVariable, GlobalFunctionVariable };
958         Vector<std::pair<FunctionMetadataNode*, FunctionVariableType>> m_functionsToInitialize;
959         bool m_needToInitializeArguments { false };
960         RestParameterNode* m_restParameter { nullptr };
961         
962         Vector<TryRange> m_tryRanges;
963         SegmentedVector<TryData, 8> m_tryData;
964
965         int m_nextConstantOffset { 0 };
966
967         typedef HashMap<FunctionMetadataNode*, unsigned> FunctionOffsetMap;
968         FunctionOffsetMap m_functionOffsets;
969         
970         // Constant pool
971         IdentifierMap m_identifierMap;
972
973         typedef HashMap<EncodedJSValueWithRepresentation, unsigned, EncodedJSValueWithRepresentationHash, EncodedJSValueWithRepresentationHashTraits> JSValueMap;
974         JSValueMap m_jsValueMap;
975         IdentifierStringMap m_stringMap;
976         TemplateRegistryKeyMap m_templateRegistryKeyMap;
977
978         StaticPropertyAnalyzer m_staticPropertyAnalyzer { &m_instructions };
979
980         VM* m_vm;
981
982         OpcodeID m_lastOpcodeID = op_end;
983 #ifndef NDEBUG
984         size_t m_lastOpcodePosition { 0 };
985 #endif
986
987         bool m_usesExceptions { false };
988         bool m_expressionTooDeep { false };
989         bool m_isBuiltinFunction { false };
990         bool m_usesNonStrictEval { false };
991         bool m_inTailPosition { false };
992         bool m_needsToUpdateArrowFunctionContext;
993         DerivedContextType m_derivedContextType { DerivedContextType::None };
994     };
995
996 } // namespace JSC
997
998 namespace WTF {
999
1000 void printInternal(PrintStream&, JSC::Variable::VariableKind);
1001
1002 } // namespace WTF