#pragma once
#include "ArgList.h"
#include "JSCJSValue.h"
#include "JSObject.h"
#include "Opcode.h"
#include "StackAlignment.h"
#include <wtf/HashMap.h>
#if ENABLE(C_LOOP)
#include "CLoopStack.h"
#endif
namespace JSC {
class CodeBlock;
class EvalExecutable;
class FunctionExecutable;
class VM;
class JSFunction;
class JSGlobalObject;
class JSModuleEnvironment;
class JSModuleRecord;
class LLIntOffsetsExtractor;
class ProgramExecutable;
class ModuleProgramExecutable;
class Register;
class JSScope;
class SourceCode;
class StackFrame;
struct CallFrameClosure;
struct HandlerInfo;
struct Instruction;
struct ProtoCallFrame;
enum DebugHookType {
WillExecuteProgram,
DidExecuteProgram,
DidEnterCallFrame,
DidReachDebuggerStatement,
WillLeaveCallFrame,
WillExecuteStatement,
WillExecuteExpression,
};
enum StackFrameCodeType {
StackFrameGlobalCode,
StackFrameEvalCode,
StackFrameModuleCode,
StackFrameFunctionCode,
StackFrameNativeCode
};
class Interpreter {
WTF_MAKE_FAST_ALLOCATED;
friend class CachedCall;
friend class LLIntOffsetsExtractor;
friend class JIT;
friend class VM;
public:
Interpreter(VM &);
~Interpreter();
#if ENABLE(C_LOOP)
CLoopStack& cloopStack() { return m_cloopStack; }
#endif
static inline Opcode getOpcode(OpcodeID);
static inline OpcodeID getOpcodeID(Opcode);
#if ASSERT_ENABLED
static bool isOpcode(Opcode);
#endif
JSValue executeProgram(const SourceCode&, JSGlobalObject*, JSObject* thisObj);
JSValue executeModuleProgram(ModuleProgramExecutable*, JSGlobalObject*, JSModuleEnvironment*);
JSValue executeCall(JSGlobalObject*, JSObject* function, const CallData&, JSValue thisValue, const ArgList&);
JSObject* executeConstruct(JSGlobalObject*, JSObject* function, const CallData&, const ArgList&, JSValue newTarget);
JSValue execute(EvalExecutable*, JSGlobalObject*, JSValue thisValue, JSScope*);
void getArgumentsData(CallFrame*, JSFunction*&, ptrdiff_t& firstParameterIndex, Register*& argv, int& argc);
NEVER_INLINE HandlerInfo* unwind(VM&, CallFrame*&, Exception*);
void notifyDebuggerOfExceptionToBeThrown(VM&, JSGlobalObject*, CallFrame*, Exception*);
NEVER_INLINE void debug(CallFrame*, DebugHookType);
static String stackTraceAsString(VM&, const Vector<StackFrame>&);
void getStackTrace(JSCell* owner, Vector<StackFrame>& results, size_t framesToSkip = 0, size_t maxStackSize = std::numeric_limits<size_t>::max());
private:
enum ExecutionFlag { Normal, InitializeAndReturn };
static JSValue checkedReturn(JSValue returnValue)
{
ASSERT(returnValue);
return returnValue;
}
static JSObject* checkedReturn(JSObject* returnValue)
{
ASSERT(returnValue);
return returnValue;
}
CallFrameClosure prepareForRepeatCall(FunctionExecutable*, CallFrame*, ProtoCallFrame*, JSFunction*, int argumentCountIncludingThis, JSScope*, const ArgList&);
JSValue execute(CallFrameClosure&);
VM& m_vm;
#if ENABLE(C_LOOP)
CLoopStack m_cloopStack;
#endif
#if ENABLE(COMPUTED_GOTO_OPCODES)
#if !ENABLE(LLINT_EMBEDDED_OPCODE_ID) || ASSERT_ENABLED
static HashMap<Opcode, OpcodeID>& opcodeIDTable(); #endif // !ENABLE(LLINT_EMBEDDED_OPCODE_ID) || ASSERT_ENABLED
#endif // ENABLE(COMPUTED_GOTO_OPCODES)
};
JSValue eval(JSGlobalObject*, CallFrame*, ECMAMode);
inline CallFrame* calleeFrameForVarargs(CallFrame* callFrame, unsigned numUsedStackSlots, unsigned argumentCountIncludingThis)
{
argumentCountIncludingThis = WTF::roundUpToMultipleOf(
stackAlignmentRegisters(),
argumentCountIncludingThis + CallFrame::headerSizeInRegisters) - CallFrame::headerSizeInRegisters;
unsigned paddedCalleeFrameOffset = WTF::roundUpToMultipleOf(
stackAlignmentRegisters(),
numUsedStackSlots + argumentCountIncludingThis + CallFrame::headerSizeInRegisters);
return CallFrame::create(callFrame->registers() - paddedCalleeFrameOffset);
}
unsigned sizeOfVarargs(JSGlobalObject*, JSValue arguments, uint32_t firstVarArgOffset);
static constexpr unsigned maxArguments = 0x10000;
unsigned sizeFrameForVarargs(JSGlobalObject*, CallFrame*, VM&, JSValue arguments, unsigned numUsedStackSlots, uint32_t firstVarArgOffset);
unsigned sizeFrameForForwardArguments(JSGlobalObject*, CallFrame*, VM&, unsigned numUsedStackSlots);
void loadVarargs(JSGlobalObject*, JSValue* firstElementDest, JSValue source, uint32_t offset, uint32_t length);
void setupVarargsFrame(JSGlobalObject*, CallFrame* execCaller, CallFrame* execCallee, JSValue arguments, uint32_t firstVarArgOffset, uint32_t length);
void setupVarargsFrameAndSetThis(JSGlobalObject*, CallFrame* execCaller, CallFrame* execCallee, JSValue thisValue, JSValue arguments, uint32_t firstVarArgOffset, uint32_t length);
void setupForwardArgumentsFrame(JSGlobalObject*, CallFrame* execCaller, CallFrame* execCallee, uint32_t length);
void setupForwardArgumentsFrameAndSetThis(JSGlobalObject*, CallFrame* execCaller, CallFrame* execCallee, JSValue thisValue, uint32_t length);
}
namespace WTF {
class PrintStream;
void printInternal(PrintStream&, JSC::DebugHookType);
}