#include "config.h"
#include "Interpreter.h"
#include "Arguments.h"
#include "BatchedTransitionOptimizer.h"
#include "CallFrame.h"
#include "CallFrameClosure.h"
#include "CodeBlock.h"
#include "Collector.h"
#include "Debugger.h"
#include "DebuggerCallFrame.h"
#include "EvalCodeCache.h"
#include "ExceptionHelpers.h"
#include "GlobalEvalFunction.h"
#include "JSActivation.h"
#include "JSArray.h"
#include "JSByteArray.h"
#include "JSFunction.h"
#include "JSNotAnObject.h"
#include "JSPropertyNameIterator.h"
#include "LiteralParser.h"
#include "JSStaticScopeObject.h"
#include "JSString.h"
#include "ObjectPrototype.h"
#include "Operations.h"
#include "Parser.h"
#include "Profiler.h"
#include "RegExpObject.h"
#include "RegExpPrototype.h"
#include "Register.h"
#include "SamplingTool.h"
#include <stdio.h>
#include <wtf/Threading.h>
#if ENABLE(JIT)
#include "JIT.h"
#endif
#if ENABLE(ASSEMBLER)
#include "AssemblerBuffer.h"
#endif
using namespace std;
namespace JSC {
static ALWAYS_INLINE unsigned bytecodeOffsetForPC(CallFrame* callFrame, CodeBlock* codeBlock, void* pc)
{
#if ENABLE(JIT)
return codeBlock->getBytecodeIndex(callFrame, pc);
#else
UNUSED_PARAM(callFrame);
return static_cast<Instruction*>(pc) - codeBlock->instructions().begin();
#endif
}
static int depth(CodeBlock* codeBlock, ScopeChain& sc)
{
if (!codeBlock->needsFullScopeChain())
return 0;
return sc.localDepth();
}
NEVER_INLINE bool Interpreter::resolve(CallFrame* callFrame, Instruction* vPC, JSValue& exceptionValue)
{
int dst = (vPC + 1)->u.operand;
int property = (vPC + 2)->u.operand;
ScopeChainNode* scopeChain = callFrame->scopeChain();
ScopeChainIterator iter = scopeChain->begin();
ScopeChainIterator end = scopeChain->end();
ASSERT(iter != end);
CodeBlock* codeBlock = callFrame->codeBlock();
Identifier& ident = codeBlock->identifier(property);
do {
JSObject* o = *iter;
PropertySlot slot(o);
if (o->getPropertySlot(callFrame, ident, slot)) {
JSValue result = slot.getValue(callFrame, ident);
exceptionValue = callFrame->globalData().exception;
if (exceptionValue)
return false;
callFrame[dst] = JSValue(result);
return true;
}
} while (++iter != end);
exceptionValue = createUndefinedVariableError(callFrame, ident, vPC - codeBlock->instructions().begin(), codeBlock);
return false;
}
NEVER_INLINE bool Interpreter::resolveSkip(CallFrame* callFrame, Instruction* vPC, JSValue& exceptionValue)
{
CodeBlock* codeBlock = callFrame->codeBlock();
int dst = (vPC + 1)->u.operand;
int property = (vPC + 2)->u.operand;
int skip = (vPC + 3)->u.operand + codeBlock->needsFullScopeChain();
ScopeChainNode* scopeChain = callFrame->scopeChain();
ScopeChainIterator iter = scopeChain->begin();
ScopeChainIterator end = scopeChain->end();
ASSERT(iter != end);
while (skip--) {
++iter;
ASSERT(iter != end);
}
Identifier& ident = codeBlock->identifier(property);
do {
JSObject* o = *iter;
PropertySlot slot(o);
if (o->getPropertySlot(callFrame, ident, slot)) {
JSValue result = slot.getValue(callFrame, ident);
exceptionValue = callFrame->globalData().exception;
if (exceptionValue)
return false;
callFrame[dst] = JSValue(result);
return true;
}
} while (++iter != end);
exceptionValue = createUndefinedVariableError(callFrame, ident, vPC - codeBlock->instructions().begin(), codeBlock);
return false;
}
NEVER_INLINE bool Interpreter::resolveGlobal(CallFrame* callFrame, Instruction* vPC, JSValue& exceptionValue)
{
int dst = (vPC + 1)->u.operand;
JSGlobalObject* globalObject = static_cast<JSGlobalObject*>((vPC + 2)->u.jsCell);
ASSERT(globalObject->isGlobalObject());
int property = (vPC + 3)->u.operand;
Structure* structure = (vPC + 4)->u.structure;
int offset = (vPC + 5)->u.operand;
if (structure == globalObject->structure()) {
callFrame[dst] = JSValue(globalObject->getDirectOffset(offset));
return true;
}
CodeBlock* codeBlock = callFrame->codeBlock();
Identifier& ident = codeBlock->identifier(property);
PropertySlot slot(globalObject);
if (globalObject->getPropertySlot(callFrame, ident, slot)) {
JSValue result = slot.getValue(callFrame, ident);
if (slot.isCacheable() && !globalObject->structure()->isDictionary() && slot.slotBase() == globalObject) {
if (vPC[4].u.structure)
vPC[4].u.structure->deref();
globalObject->structure()->ref();
vPC[4] = globalObject->structure();
vPC[5] = slot.cachedOffset();
callFrame[dst] = JSValue(result);
return true;
}
exceptionValue = callFrame->globalData().exception;
if (exceptionValue)
return false;
callFrame[dst] = JSValue(result);
return true;
}
exceptionValue = createUndefinedVariableError(callFrame, ident, vPC - codeBlock->instructions().begin(), codeBlock);
return false;
}
NEVER_INLINE void Interpreter::resolveBase(CallFrame* callFrame, Instruction* vPC)
{
int dst = (vPC + 1)->u.operand;
int property = (vPC + 2)->u.operand;
callFrame[dst] = JSValue(JSC::resolveBase(callFrame, callFrame->codeBlock()->identifier(property), callFrame->scopeChain()));
}
NEVER_INLINE bool Interpreter::resolveBaseAndProperty(CallFrame* callFrame, Instruction* vPC, JSValue& exceptionValue)
{
int baseDst = (vPC + 1)->u.operand;
int propDst = (vPC + 2)->u.operand;
int property = (vPC + 3)->u.operand;
ScopeChainNode* scopeChain = callFrame->scopeChain();
ScopeChainIterator iter = scopeChain->begin();
ScopeChainIterator end = scopeChain->end();
ASSERT(iter != end);
CodeBlock* codeBlock = callFrame->codeBlock();
Identifier& ident = codeBlock->identifier(property);
JSObject* base;
do {
base = *iter;
PropertySlot slot(base);
if (base->getPropertySlot(callFrame, ident, slot)) {
JSValue result = slot.getValue(callFrame, ident);
exceptionValue = callFrame->globalData().exception;
if (exceptionValue)
return false;
callFrame[propDst] = JSValue(result);
callFrame[baseDst] = JSValue(base);
return true;
}
++iter;
} while (iter != end);
exceptionValue = createUndefinedVariableError(callFrame, ident, vPC - codeBlock->instructions().begin(), codeBlock);
return false;
}
NEVER_INLINE bool Interpreter::resolveBaseAndFunc(CallFrame* callFrame, Instruction* vPC, JSValue& exceptionValue)
{
int baseDst = (vPC + 1)->u.operand;
int funcDst = (vPC + 2)->u.operand;
int property = (vPC + 3)->u.operand;
ScopeChainNode* scopeChain = callFrame->scopeChain();
ScopeChainIterator iter = scopeChain->begin();
ScopeChainIterator end = scopeChain->end();
ASSERT(iter != end);
CodeBlock* codeBlock = callFrame->codeBlock();
Identifier& ident = codeBlock->identifier(property);
JSObject* base;
do {
base = *iter;
PropertySlot slot(base);
if (base->getPropertySlot(callFrame, ident, slot)) {
JSObject* thisObj = base->toThisObject(callFrame);
JSValue result = slot.getValue(callFrame, ident);
exceptionValue = callFrame->globalData().exception;
if (exceptionValue)
return false;
callFrame[baseDst] = JSValue(thisObj);
callFrame[funcDst] = JSValue(result);
return true;
}
++iter;
} while (iter != end);
exceptionValue = createUndefinedVariableError(callFrame, ident, vPC - codeBlock->instructions().begin(), codeBlock);
return false;
}
ALWAYS_INLINE CallFrame* Interpreter::slideRegisterWindowForCall(CodeBlock* newCodeBlock, RegisterFile* registerFile, CallFrame* callFrame, size_t registerOffset, int argc)
{
Register* r = callFrame->registers();
Register* newEnd = r + registerOffset + newCodeBlock->m_numCalleeRegisters;
if (LIKELY(argc == newCodeBlock->m_numParameters)) { if (UNLIKELY(!registerFile->grow(newEnd)))
return 0;
r += registerOffset;
} else if (argc < newCodeBlock->m_numParameters) { size_t omittedArgCount = newCodeBlock->m_numParameters - argc;
registerOffset += omittedArgCount;
newEnd += omittedArgCount;
if (!registerFile->grow(newEnd))
return 0;
r += registerOffset;
Register* argv = r - RegisterFile::CallFrameHeaderSize - omittedArgCount;
for (size_t i = 0; i < omittedArgCount; ++i)
argv[i] = jsUndefined();
} else { size_t numParameters = newCodeBlock->m_numParameters;
registerOffset += numParameters;
newEnd += numParameters;
if (!registerFile->grow(newEnd))
return 0;
r += registerOffset;
Register* argv = r - RegisterFile::CallFrameHeaderSize - numParameters - argc;
for (size_t i = 0; i < numParameters; ++i)
argv[i + argc] = argv[i];
}
return CallFrame::create(r);
}
static NEVER_INLINE bool isInvalidParamForIn(CallFrame* callFrame, CodeBlock* codeBlock, const Instruction* vPC, JSValue value, JSValue& exceptionData)
{
if (value.isObject())
return false;
exceptionData = createInvalidParamError(callFrame, "in" , value, vPC - codeBlock->instructions().begin(), codeBlock);
return true;
}
static NEVER_INLINE bool isInvalidParamForInstanceOf(CallFrame* callFrame, CodeBlock* codeBlock, const Instruction* vPC, JSValue value, JSValue& exceptionData)
{
if (value.isObject() && asObject(value)->structure()->typeInfo().implementsHasInstance())
return false;
exceptionData = createInvalidParamError(callFrame, "instanceof" , value, vPC - codeBlock->instructions().begin(), codeBlock);
return true;
}
NEVER_INLINE JSValue Interpreter::callEval(CallFrame* callFrame, RegisterFile* registerFile, Register* argv, int argc, int registerOffset, JSValue& exceptionValue)
{
if (argc < 2)
return jsUndefined();
JSValue program = argv[1].jsValue();
if (!program.isString())
return program;
UString programSource = asString(program)->value();
LiteralParser preparser(callFrame, programSource);
if (JSValue parsedObject = preparser.tryLiteralParse())
return parsedObject;
ScopeChainNode* scopeChain = callFrame->scopeChain();
CodeBlock* codeBlock = callFrame->codeBlock();
RefPtr<EvalNode> evalNode = codeBlock->evalCodeCache().get(callFrame, programSource, scopeChain, exceptionValue);
JSValue result = jsUndefined();
if (evalNode)
result = callFrame->globalData().interpreter->execute(evalNode.get(), callFrame, callFrame->thisValue().toThisObject(callFrame), callFrame->registers() - registerFile->start() + registerOffset, scopeChain, &exceptionValue);
return result;
}
Interpreter::Interpreter()
: m_sampler(0)
, m_reentryDepth(0)
{
privateExecute(InitializeAndReturn, 0, 0, 0);
}
#ifndef NDEBUG
void Interpreter::dumpCallFrame(CallFrame* callFrame)
{
callFrame->codeBlock()->dump(callFrame);
dumpRegisters(callFrame);
}
void Interpreter::dumpRegisters(CallFrame* callFrame)
{
printf("Register frame: \n\n");
printf("----------------------------------------------------\n");
printf(" use | address | value \n");
printf("----------------------------------------------------\n");
CodeBlock* codeBlock = callFrame->codeBlock();
RegisterFile* registerFile = &callFrame->scopeChain()->globalObject()->globalData()->interpreter->registerFile();
const Register* it;
const Register* end;
if (codeBlock->codeType() == GlobalCode) {
it = registerFile->lastGlobal();
end = it + registerFile->numGlobals();
while (it != end) {
printf("[global var] | %10p | %10p \n", it, (*it).v());
++it;
}
printf("----------------------------------------------------\n");
}
it = callFrame->registers() - RegisterFile::CallFrameHeaderSize - codeBlock->m_numParameters;
printf("[this] | %10p | %10p \n", it, (*it).v()); ++it;
end = it + max(codeBlock->m_numParameters - 1, 0); if (it != end) {
do {
printf("[param] | %10p | %10p \n", it, (*it).v());
++it;
} while (it != end);
}
printf("----------------------------------------------------\n");
printf("[CodeBlock] | %10p | %10p \n", it, (*it).v()); ++it;
printf("[ScopeChain] | %10p | %10p \n", it, (*it).v()); ++it;
printf("[CallerRegisters] | %10p | %10p \n", it, (*it).v()); ++it;
printf("[ReturnPC] | %10p | %10p \n", it, (*it).v()); ++it;
printf("[ReturnValueRegister] | %10p | %10p \n", it, (*it).v()); ++it;
printf("[ArgumentCount] | %10p | %10p \n", it, (*it).v()); ++it;
printf("[Callee] | %10p | %10p \n", it, (*it).v()); ++it;
printf("[OptionalCalleeArguments] | %10p | %10p \n", it, (*it).v()); ++it;
printf("----------------------------------------------------\n");
int registerCount = 0;
end = it + codeBlock->m_numVars;
if (it != end) {
do {
printf("[r%2d] | %10p | %10p \n", registerCount, it, (*it).v());
++it;
++registerCount;
} while (it != end);
}
printf("----------------------------------------------------\n");
end = it + codeBlock->m_numConstants;
if (it != end) {
do {
printf("[r%2d] | %10p | %10p \n", registerCount, it, (*it).v());
++it;
++registerCount;
} while (it != end);
}
printf("----------------------------------------------------\n");
end = it + codeBlock->m_numCalleeRegisters - codeBlock->m_numConstants - codeBlock->m_numVars;
if (it != end) {
do {
printf("[r%2d] | %10p | %10p \n", registerCount, it, (*it).v());
++it;
++registerCount;
} while (it != end);
}
printf("----------------------------------------------------\n");
}
#endif
bool Interpreter::isOpcode(Opcode opcode)
{
#if HAVE(COMPUTED_GOTO)
return opcode != HashTraits<Opcode>::emptyValue()
&& !HashTraits<Opcode>::isDeletedValue(opcode)
&& m_opcodeIDTable.contains(opcode);
#else
return opcode >= 0 && opcode <= op_end;
#endif
}
NEVER_INLINE bool Interpreter::unwindCallFrame(CallFrame*& callFrame, JSValue exceptionValue, unsigned& bytecodeOffset, CodeBlock*& codeBlock)
{
CodeBlock* oldCodeBlock = codeBlock;
ScopeChainNode* scopeChain = callFrame->scopeChain();
if (Debugger* debugger = callFrame->dynamicGlobalObject()->debugger()) {
DebuggerCallFrame debuggerCallFrame(callFrame, exceptionValue);
if (callFrame->callee())
debugger->returnEvent(debuggerCallFrame, codeBlock->ownerNode()->sourceID(), codeBlock->ownerNode()->lastLine());
else
debugger->didExecuteProgram(debuggerCallFrame, codeBlock->ownerNode()->sourceID(), codeBlock->ownerNode()->lastLine());
}
if (Profiler* profiler = *Profiler::enabledProfilerReference()) {
if (callFrame->callee())
profiler->didExecute(callFrame, callFrame->callee());
else
profiler->didExecute(callFrame, codeBlock->ownerNode()->sourceURL(), codeBlock->ownerNode()->lineNo());
}
if (oldCodeBlock->codeType() == FunctionCode && oldCodeBlock->needsFullScopeChain()) {
while (!scopeChain->object->isObject(&JSActivation::info))
scopeChain = scopeChain->pop();
static_cast<JSActivation*>(scopeChain->object)->copyRegisters(callFrame->optionalCalleeArguments());
} else if (Arguments* arguments = callFrame->optionalCalleeArguments()) {
if (!arguments->isTornOff())
arguments->copyRegisters();
}
if (oldCodeBlock->needsFullScopeChain())
scopeChain->deref();
void* returnPC = callFrame->returnPC();
callFrame = callFrame->callerFrame();
if (callFrame->hasHostCallFrameFlag())
return false;
codeBlock = callFrame->codeBlock();
bytecodeOffset = bytecodeOffsetForPC(callFrame, codeBlock, returnPC);
return true;
}
NEVER_INLINE HandlerInfo* Interpreter::throwException(CallFrame*& callFrame, JSValue& exceptionValue, unsigned bytecodeOffset, bool explicitThrow)
{
CodeBlock* codeBlock = callFrame->codeBlock();
if (exceptionValue.isObject()) {
JSObject* exception = asObject(exceptionValue);
if (exception->isNotAnObjectErrorStub()) {
exception = createNotAnObjectError(callFrame, static_cast<JSNotAnObjectErrorStub*>(exception), bytecodeOffset, codeBlock);
exceptionValue = exception;
} else {
if (!exception->hasProperty(callFrame, Identifier(callFrame, "line")) &&
!exception->hasProperty(callFrame, Identifier(callFrame, "sourceId")) &&
!exception->hasProperty(callFrame, Identifier(callFrame, "sourceURL")) &&
!exception->hasProperty(callFrame, Identifier(callFrame, expressionBeginOffsetPropertyName)) &&
!exception->hasProperty(callFrame, Identifier(callFrame, expressionCaretOffsetPropertyName)) &&
!exception->hasProperty(callFrame, Identifier(callFrame, expressionEndOffsetPropertyName))) {
if (explicitThrow) {
int startOffset = 0;
int endOffset = 0;
int divotPoint = 0;
int line = codeBlock->expressionRangeForBytecodeOffset(callFrame, bytecodeOffset, divotPoint, startOffset, endOffset);
exception->putWithAttributes(callFrame, Identifier(callFrame, "line"), jsNumber(callFrame, line), ReadOnly | DontDelete);
exception->putWithAttributes(callFrame, Identifier(callFrame, expressionBeginOffsetPropertyName), jsNumber(callFrame, divotPoint - startOffset), ReadOnly | DontDelete);
exception->putWithAttributes(callFrame, Identifier(callFrame, expressionEndOffsetPropertyName), jsNumber(callFrame, divotPoint + endOffset), ReadOnly | DontDelete);
} else
exception->putWithAttributes(callFrame, Identifier(callFrame, "line"), jsNumber(callFrame, codeBlock->lineNumberForBytecodeOffset(callFrame, bytecodeOffset)), ReadOnly | DontDelete);
exception->putWithAttributes(callFrame, Identifier(callFrame, "sourceId"), jsNumber(callFrame, codeBlock->ownerNode()->sourceID()), ReadOnly | DontDelete);
exception->putWithAttributes(callFrame, Identifier(callFrame, "sourceURL"), jsOwnedString(callFrame, codeBlock->ownerNode()->sourceURL()), ReadOnly | DontDelete);
}
if (exception->isWatchdogException()) {
while (unwindCallFrame(callFrame, exceptionValue, bytecodeOffset, codeBlock)) {
}
return 0;
}
}
}
if (Debugger* debugger = callFrame->dynamicGlobalObject()->debugger()) {
DebuggerCallFrame debuggerCallFrame(callFrame, exceptionValue);
debugger->exception(debuggerCallFrame, codeBlock->ownerNode()->sourceID(), codeBlock->lineNumberForBytecodeOffset(callFrame, bytecodeOffset));
}
if (Profiler* profiler = *Profiler::enabledProfilerReference()) {
#if !ENABLE(JIT)
if (isCallBytecode(codeBlock->instructions()[bytecodeOffset].u.opcode))
profiler->didExecute(callFrame, callFrame[codeBlock->instructions()[bytecodeOffset + 2].u.operand].jsValue());
else if (codeBlock->instructions()[bytecodeOffset + 8].u.opcode == getOpcode(op_construct))
profiler->didExecute(callFrame, callFrame[codeBlock->instructions()[bytecodeOffset + 10].u.operand].jsValue());
#else
int functionRegisterIndex;
if (codeBlock->functionRegisterForBytecodeOffset(bytecodeOffset, functionRegisterIndex))
profiler->didExecute(callFrame, callFrame[functionRegisterIndex].jsValue());
#endif
}
HandlerInfo* handler = 0;
while (!(handler = codeBlock->handlerForBytecodeOffset(bytecodeOffset))) {
if (!unwindCallFrame(callFrame, exceptionValue, bytecodeOffset, codeBlock))
return 0;
}
ScopeChainNode* scopeChain = callFrame->scopeChain();
ScopeChain sc(scopeChain);
int scopeDelta = depth(codeBlock, sc) - handler->scopeDepth;
ASSERT(scopeDelta >= 0);
while (scopeDelta--)
scopeChain = scopeChain->pop();
callFrame->setScopeChain(scopeChain);
return handler;
}
JSValue Interpreter::execute(ProgramNode* programNode, CallFrame* callFrame, ScopeChainNode* scopeChain, JSObject* thisObj, JSValue* exception)
{
ASSERT(!scopeChain->globalData->exception);
if (m_reentryDepth >= MaxSecondaryThreadReentryDepth) {
if (!isMainThread() || m_reentryDepth >= MaxMainThreadReentryDepth) {
*exception = createStackOverflowError(callFrame);
return jsNull();
}
}
CodeBlock* codeBlock = &programNode->bytecode(scopeChain);
Register* oldEnd = m_registerFile.end();
Register* newEnd = oldEnd + codeBlock->m_numParameters + RegisterFile::CallFrameHeaderSize + codeBlock->m_numCalleeRegisters;
if (!m_registerFile.grow(newEnd)) {
*exception = createStackOverflowError(callFrame);
return jsNull();
}
DynamicGlobalObjectScope globalObjectScope(callFrame, scopeChain->globalObject());
JSGlobalObject* lastGlobalObject = m_registerFile.globalObject();
JSGlobalObject* globalObject = callFrame->dynamicGlobalObject();
globalObject->copyGlobalsTo(m_registerFile);
CallFrame* newCallFrame = CallFrame::create(oldEnd + codeBlock->m_numParameters + RegisterFile::CallFrameHeaderSize);
newCallFrame[codeBlock->thisRegister()] = JSValue(thisObj);
newCallFrame->init(codeBlock, 0, scopeChain, CallFrame::noCaller(), 0, 0, 0);
if (codeBlock->needsFullScopeChain())
scopeChain->ref();
Profiler** profiler = Profiler::enabledProfilerReference();
if (*profiler)
(*profiler)->willExecute(newCallFrame, programNode->sourceURL(), programNode->lineNo());
JSValue result;
{
SamplingTool::CallRecord callRecord(m_sampler);
m_reentryDepth++;
#if ENABLE(JIT)
if (!codeBlock->jitCode())
JIT::compile(scopeChain->globalData, codeBlock);
result = codeBlock->jitCode().execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
#else
result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
#endif
m_reentryDepth--;
}
if (*profiler)
(*profiler)->didExecute(callFrame, programNode->sourceURL(), programNode->lineNo());
if (m_reentryDepth && lastGlobalObject && globalObject != lastGlobalObject)
lastGlobalObject->copyGlobalsTo(m_registerFile);
m_registerFile.shrink(oldEnd);
return result;
}
JSValue Interpreter::execute(FunctionBodyNode* functionBodyNode, CallFrame* callFrame, JSFunction* function, JSObject* thisObj, const ArgList& args, ScopeChainNode* scopeChain, JSValue* exception)
{
ASSERT(!scopeChain->globalData->exception);
if (m_reentryDepth >= MaxSecondaryThreadReentryDepth) {
if (!isMainThread() || m_reentryDepth >= MaxMainThreadReentryDepth) {
*exception = createStackOverflowError(callFrame);
return jsNull();
}
}
Register* oldEnd = m_registerFile.end();
int argc = 1 + args.size();
if (!m_registerFile.grow(oldEnd + argc)) {
*exception = createStackOverflowError(callFrame);
return jsNull();
}
DynamicGlobalObjectScope globalObjectScope(callFrame, callFrame->globalData().dynamicGlobalObject ? callFrame->globalData().dynamicGlobalObject : scopeChain->globalObject());
CallFrame* newCallFrame = CallFrame::create(oldEnd);
size_t dst = 0;
newCallFrame[0] = JSValue(thisObj);
ArgList::const_iterator end = args.end();
for (ArgList::const_iterator it = args.begin(); it != end; ++it)
newCallFrame[++dst] = *it;
CodeBlock* codeBlock = &functionBodyNode->bytecode(scopeChain);
newCallFrame = slideRegisterWindowForCall(codeBlock, &m_registerFile, newCallFrame, argc + RegisterFile::CallFrameHeaderSize, argc);
if (UNLIKELY(!newCallFrame)) {
*exception = createStackOverflowError(callFrame);
m_registerFile.shrink(oldEnd);
return jsNull();
}
newCallFrame->init(codeBlock, 0, scopeChain, callFrame->addHostCallFrameFlag(), 0, argc, function);
Profiler** profiler = Profiler::enabledProfilerReference();
if (*profiler)
(*profiler)->willExecute(callFrame, function);
JSValue result;
{
SamplingTool::CallRecord callRecord(m_sampler);
m_reentryDepth++;
#if ENABLE(JIT)
result = functionBodyNode->jitCode(scopeChain).execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
#else
result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
#endif
m_reentryDepth--;
}
if (*profiler)
(*profiler)->didExecute(callFrame, function);
m_registerFile.shrink(oldEnd);
return result;
}
CallFrameClosure Interpreter::prepareForRepeatCall(FunctionBodyNode* functionBodyNode, CallFrame* callFrame, JSFunction* function, int argCount, ScopeChainNode* scopeChain, JSValue* exception)
{
ASSERT(!scopeChain->globalData->exception);
if (m_reentryDepth >= MaxSecondaryThreadReentryDepth) {
if (!isMainThread() || m_reentryDepth >= MaxMainThreadReentryDepth) {
*exception = createStackOverflowError(callFrame);
return CallFrameClosure();
}
}
Register* oldEnd = m_registerFile.end();
int argc = 1 + argCount;
if (!m_registerFile.grow(oldEnd + argc)) {
*exception = createStackOverflowError(callFrame);
return CallFrameClosure();
}
CallFrame* newCallFrame = CallFrame::create(oldEnd);
size_t dst = 0;
for (int i = 0; i < argc; ++i)
newCallFrame[++dst] = jsUndefined();
CodeBlock* codeBlock = &functionBodyNode->bytecode(scopeChain);
newCallFrame = slideRegisterWindowForCall(codeBlock, &m_registerFile, newCallFrame, argc + RegisterFile::CallFrameHeaderSize, argc);
if (UNLIKELY(!newCallFrame)) {
*exception = createStackOverflowError(callFrame);
m_registerFile.shrink(oldEnd);
return CallFrameClosure();
}
newCallFrame->init(codeBlock, 0, scopeChain, callFrame->addHostCallFrameFlag(), 0, argc, function);
#if ENABLE(JIT)
functionBodyNode->jitCode(scopeChain);
#endif
CallFrameClosure result = { callFrame, newCallFrame, function, codeBlock, scopeChain->globalData, oldEnd, scopeChain, codeBlock->m_numParameters, argc };
return result;
}
JSValue Interpreter::execute(CallFrameClosure& closure, JSValue* exception)
{
closure.resetCallFrame();
Profiler** profiler = Profiler::enabledProfilerReference();
if (*profiler)
(*profiler)->willExecute(closure.oldCallFrame, closure.function);
JSValue result;
{
SamplingTool::CallRecord callRecord(m_sampler);
m_reentryDepth++;
#if ENABLE(JIT)
ASSERT(closure.codeBlock->jitCode());
result = closure.codeBlock->jitCode().execute(&m_registerFile, closure.newCallFrame, closure.globalData, exception);
#else
result = privateExecute(Normal, &m_registerFile, closure.newCallFrame, exception);
#endif
m_reentryDepth--;
}
if (*profiler)
(*profiler)->didExecute(closure.oldCallFrame, closure.function);
return result;
}
void Interpreter::endRepeatCall(CallFrameClosure& closure)
{
m_registerFile.shrink(closure.oldEnd);
}
JSValue Interpreter::execute(EvalNode* evalNode, CallFrame* callFrame, JSObject* thisObj, ScopeChainNode* scopeChain, JSValue* exception)
{
return execute(evalNode, callFrame, thisObj, m_registerFile.size() + evalNode->bytecode(scopeChain).m_numParameters + RegisterFile::CallFrameHeaderSize, scopeChain, exception);
}
JSValue Interpreter::execute(EvalNode* evalNode, CallFrame* callFrame, JSObject* thisObj, int globalRegisterOffset, ScopeChainNode* scopeChain, JSValue* exception)
{
ASSERT(!scopeChain->globalData->exception);
if (m_reentryDepth >= MaxSecondaryThreadReentryDepth) {
if (!isMainThread() || m_reentryDepth >= MaxMainThreadReentryDepth) {
*exception = createStackOverflowError(callFrame);
return jsNull();
}
}
DynamicGlobalObjectScope globalObjectScope(callFrame, callFrame->globalData().dynamicGlobalObject ? callFrame->globalData().dynamicGlobalObject : scopeChain->globalObject());
EvalCodeBlock* codeBlock = &evalNode->bytecode(scopeChain);
JSVariableObject* variableObject;
for (ScopeChainNode* node = scopeChain; ; node = node->next) {
ASSERT(node);
if (node->object->isVariableObject()) {
variableObject = static_cast<JSVariableObject*>(node->object);
break;
}
}
{
BatchedTransitionOptimizer optimizer(variableObject);
const DeclarationStacks::VarStack& varStack = codeBlock->ownerNode()->varStack();
DeclarationStacks::VarStack::const_iterator varStackEnd = varStack.end();
for (DeclarationStacks::VarStack::const_iterator it = varStack.begin(); it != varStackEnd; ++it) {
const Identifier& ident = (*it).first;
if (!variableObject->hasProperty(callFrame, ident)) {
PutPropertySlot slot;
variableObject->put(callFrame, ident, jsUndefined(), slot);
}
}
const DeclarationStacks::FunctionStack& functionStack = codeBlock->ownerNode()->functionStack();
DeclarationStacks::FunctionStack::const_iterator functionStackEnd = functionStack.end();
for (DeclarationStacks::FunctionStack::const_iterator it = functionStack.begin(); it != functionStackEnd; ++it) {
PutPropertySlot slot;
variableObject->put(callFrame, (*it)->m_ident, (*it)->makeFunction(callFrame, scopeChain), slot);
}
}
Register* oldEnd = m_registerFile.end();
Register* newEnd = m_registerFile.start() + globalRegisterOffset + codeBlock->m_numCalleeRegisters;
if (!m_registerFile.grow(newEnd)) {
*exception = createStackOverflowError(callFrame);
return jsNull();
}
CallFrame* newCallFrame = CallFrame::create(m_registerFile.start() + globalRegisterOffset);
newCallFrame[codeBlock->thisRegister()] = JSValue(thisObj);
newCallFrame->init(codeBlock, 0, scopeChain, callFrame->addHostCallFrameFlag(), 0, 0, 0);
if (codeBlock->needsFullScopeChain())
scopeChain->ref();
Profiler** profiler = Profiler::enabledProfilerReference();
if (*profiler)
(*profiler)->willExecute(newCallFrame, evalNode->sourceURL(), evalNode->lineNo());
JSValue result;
{
SamplingTool::CallRecord callRecord(m_sampler);
m_reentryDepth++;
#if ENABLE(JIT)
if (!codeBlock->jitCode())
JIT::compile(scopeChain->globalData, codeBlock);
result = codeBlock->jitCode().execute(&m_registerFile, newCallFrame, scopeChain->globalData, exception);
#else
result = privateExecute(Normal, &m_registerFile, newCallFrame, exception);
#endif
m_reentryDepth--;
}
if (*profiler)
(*profiler)->didExecute(callFrame, evalNode->sourceURL(), evalNode->lineNo());
m_registerFile.shrink(oldEnd);
return result;
}
NEVER_INLINE void Interpreter::debug(CallFrame* callFrame, DebugHookID debugHookID, int firstLine, int lastLine)
{
Debugger* debugger = callFrame->dynamicGlobalObject()->debugger();
if (!debugger)
return;
switch (debugHookID) {
case DidEnterCallFrame:
debugger->callEvent(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), firstLine);
return;
case WillLeaveCallFrame:
debugger->returnEvent(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), lastLine);
return;
case WillExecuteStatement:
debugger->atStatement(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), firstLine);
return;
case WillExecuteProgram:
debugger->willExecuteProgram(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), firstLine);
return;
case DidExecuteProgram:
debugger->didExecuteProgram(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), lastLine);
return;
case DidReachBreakpoint:
debugger->didReachBreakpoint(callFrame, callFrame->codeBlock()->ownerNode()->sourceID(), lastLine);
return;
}
}
NEVER_INLINE ScopeChainNode* Interpreter::createExceptionScope(CallFrame* callFrame, const Instruction* vPC)
{
int dst = (++vPC)->u.operand;
CodeBlock* codeBlock = callFrame->codeBlock();
Identifier& property = codeBlock->identifier((++vPC)->u.operand);
JSValue value = callFrame[(++vPC)->u.operand].jsValue();
JSObject* scope = new (callFrame) JSStaticScopeObject(callFrame, property, value, DontDelete);
callFrame[dst] = JSValue(scope);
return callFrame->scopeChain()->push(scope);
}
NEVER_INLINE void Interpreter::tryCachePutByID(CallFrame* callFrame, CodeBlock* codeBlock, Instruction* vPC, JSValue baseValue, const PutPropertySlot& slot)
{
if (vPC[0].u.opcode != getOpcode(op_put_by_id))
return;
if (!baseValue.isCell())
return;
if (!slot.isCacheable()) {
vPC[0] = getOpcode(op_put_by_id_generic);
return;
}
JSCell* baseCell = asCell(baseValue);
Structure* structure = baseCell->structure();
if (structure->isDictionary()) {
vPC[0] = getOpcode(op_put_by_id_generic);
return;
}
Structure* lastStructure = vPC[4].u.structure;
if (structure != lastStructure) {
if (!lastStructure) {
vPC[4] = structure;
return;
}
vPC[0] = getOpcode(op_put_by_id_generic);
return;
}
if (baseCell != slot.base()) {
vPC[0] = getOpcode(op_put_by_id_generic);
return;
}
if (slot.type() == PutPropertySlot::NewProperty) {
vPC[0] = getOpcode(op_put_by_id_transition);
vPC[4] = structure->previousID();
vPC[5] = structure;
vPC[6] = structure->prototypeChain(callFrame);
vPC[7] = slot.cachedOffset();
codeBlock->refStructures(vPC);
return;
}
vPC[0] = getOpcode(op_put_by_id_replace);
vPC[5] = slot.cachedOffset();
codeBlock->refStructures(vPC);
}
NEVER_INLINE void Interpreter::uncachePutByID(CodeBlock* codeBlock, Instruction* vPC)
{
codeBlock->derefStructures(vPC);
vPC[0] = getOpcode(op_put_by_id);
vPC[4] = 0;
}
NEVER_INLINE void Interpreter::tryCacheGetByID(CallFrame* callFrame, CodeBlock* codeBlock, Instruction* vPC, JSValue baseValue, const Identifier& propertyName, const PropertySlot& slot)
{
if (vPC[0].u.opcode != getOpcode(op_get_by_id))
return;
if (!baseValue.isCell()) {
vPC[0] = getOpcode(op_get_by_id_generic);
return;
}
JSGlobalData* globalData = &callFrame->globalData();
if (isJSArray(globalData, baseValue) && propertyName == callFrame->propertyNames().length) {
vPC[0] = getOpcode(op_get_array_length);
return;
}
if (isJSString(globalData, baseValue) && propertyName == callFrame->propertyNames().length) {
vPC[0] = getOpcode(op_get_string_length);
return;
}
if (!slot.isCacheable()) {
vPC[0] = getOpcode(op_get_by_id_generic);
return;
}
Structure* structure = asCell(baseValue)->structure();
if (structure->isDictionary()) {
vPC[0] = getOpcode(op_get_by_id_generic);
return;
}
Structure* lastStructure = vPC[4].u.structure;
if (structure != lastStructure) {
if (!lastStructure) {
vPC[4] = structure;
return;
}
vPC[0] = getOpcode(op_get_by_id_generic);
return;
}
if (slot.slotBase() == baseValue) {
vPC[0] = getOpcode(op_get_by_id_self);
vPC[5] = slot.cachedOffset();
codeBlock->refStructures(vPC);
return;
}
if (slot.slotBase() == structure->prototypeForLookup(callFrame)) {
ASSERT(slot.slotBase().isObject());
JSObject* baseObject = asObject(slot.slotBase());
if (baseObject->structure()->isDictionary())
baseObject->setStructure(Structure::fromDictionaryTransition(baseObject->structure()));
vPC[0] = getOpcode(op_get_by_id_proto);
vPC[5] = baseObject->structure();
vPC[6] = slot.cachedOffset();
codeBlock->refStructures(vPC);
return;
}
size_t count = countPrototypeChainEntriesAndCheckForProxies(callFrame, baseValue, slot);
if (!count) {
vPC[0] = getOpcode(op_get_by_id_generic);
return;
}
vPC[0] = getOpcode(op_get_by_id_chain);
vPC[4] = structure;
vPC[5] = structure->prototypeChain(callFrame);
vPC[6] = count;
vPC[7] = slot.cachedOffset();
codeBlock->refStructures(vPC);
}
NEVER_INLINE void Interpreter::uncacheGetByID(CodeBlock* codeBlock, Instruction* vPC)
{
codeBlock->derefStructures(vPC);
vPC[0] = getOpcode(op_get_by_id);
vPC[4] = 0;
}
JSValue Interpreter::privateExecute(ExecutionFlag flag, RegisterFile* registerFile, CallFrame* callFrame, JSValue* exception)
{
if (flag == InitializeAndReturn) {
#if HAVE(COMPUTED_GOTO)
#define ADD_BYTECODE(id, length) m_opcodeTable[id] = &&id;
FOR_EACH_OPCODE_ID(ADD_BYTECODE);
#undef ADD_BYTECODE
#define ADD_OPCODE_ID(id, length) m_opcodeIDTable.add(&&id, id);
FOR_EACH_OPCODE_ID(ADD_OPCODE_ID);
#undef ADD_OPCODE_ID
ASSERT(m_opcodeIDTable.size() == numOpcodeIDs);
#endif return JSValue();
}
#if ENABLE(JIT)
ASSERT_NOT_REACHED();
#endif
JSGlobalData* globalData = &callFrame->globalData();
JSValue exceptionValue;
HandlerInfo* handler = 0;
Instruction* vPC = callFrame->codeBlock()->instructions().begin();
Profiler** enabledProfilerReference = Profiler::enabledProfilerReference();
unsigned tickCount = globalData->timeoutChecker.ticksUntilNextCheck();
#define CHECK_FOR_EXCEPTION() \
do { \
if (UNLIKELY(globalData->exception != JSValue())) { \
exceptionValue = globalData->exception; \
goto vm_throw; \
} \
} while (0)
#if ENABLE(OPCODE_STATS)
OpcodeStats::resetLastInstruction();
#endif
#define CHECK_FOR_TIMEOUT() \
if (!--tickCount) { \
if (globalData->timeoutChecker.didTimeOut(callFrame)) { \
exceptionValue = jsNull(); \
goto vm_throw; \
} \
tickCount = globalData->timeoutChecker.ticksUntilNextCheck(); \
}
#if ENABLE(OPCODE_SAMPLING)
#define SAMPLE(codeBlock, vPC) m_sampler->sample(codeBlock, vPC)
#else
#define SAMPLE(codeBlock, vPC)
#endif
#if HAVE(COMPUTED_GOTO)
#define NEXT_INSTRUCTION() SAMPLE(callFrame->codeBlock(), vPC); goto *vPC->u.opcode
#if ENABLE(OPCODE_STATS)
#define DEFINE_OPCODE(opcode) opcode: OpcodeStats::recordInstruction(opcode);
#else
#define DEFINE_OPCODE(opcode) opcode:
#endif
NEXT_INSTRUCTION();
#else
#define NEXT_INSTRUCTION() SAMPLE(callFrame->codeBlock(), vPC); goto interpreterLoopStart
#if ENABLE(OPCODE_STATS)
#define DEFINE_OPCODE(opcode) case opcode: OpcodeStats::recordInstruction(opcode);
#else
#define DEFINE_OPCODE(opcode) case opcode:
#endif
while (1) { interpreterLoopStart:;
switch (vPC->u.opcode)
#endif
{
DEFINE_OPCODE(op_new_object) {
int dst = (++vPC)->u.operand;
callFrame[dst] = JSValue(constructEmptyObject(callFrame));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_new_array) {
int dst = (++vPC)->u.operand;
int firstArg = (++vPC)->u.operand;
int argCount = (++vPC)->u.operand;
ArgList args(callFrame->registers() + firstArg, argCount);
callFrame[dst] = JSValue(constructArray(callFrame, args));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_new_regexp) {
int dst = (++vPC)->u.operand;
int regExp = (++vPC)->u.operand;
callFrame[dst] = JSValue(new (globalData) RegExpObject(callFrame->scopeChain()->globalObject()->regExpStructure(), callFrame->codeBlock()->regexp(regExp)));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_mov) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
callFrame[dst] = callFrame[src];
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_eq) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
if (JSFastMath::canDoFastBitwiseOperations(src1, src2))
callFrame[dst] = JSFastMath::equal(src1, src2);
else {
JSValue result = jsBoolean(JSValue::equalSlowCase(callFrame, src1, src2));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_eq_null) {
int dst = (++vPC)->u.operand;
JSValue src = callFrame[(++vPC)->u.operand].jsValue();
if (src.isUndefinedOrNull()) {
callFrame[dst] = jsBoolean(true);
++vPC;
NEXT_INSTRUCTION();
}
callFrame[dst] = jsBoolean(src.isCell() && src.asCell()->structure()->typeInfo().masqueradesAsUndefined());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_neq) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
if (JSFastMath::canDoFastBitwiseOperations(src1, src2))
callFrame[dst] = JSFastMath::notEqual(src1, src2);
else {
JSValue result = jsBoolean(!JSValue::equalSlowCase(callFrame, src1, src2));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_neq_null) {
int dst = (++vPC)->u.operand;
JSValue src = callFrame[(++vPC)->u.operand].jsValue();
if (src.isUndefinedOrNull()) {
callFrame[dst] = jsBoolean(false);
++vPC;
NEXT_INSTRUCTION();
}
callFrame[dst] = jsBoolean(!src.isCell() || !asCell(src)->structure()->typeInfo().masqueradesAsUndefined());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_stricteq) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
callFrame[dst] = jsBoolean(JSValue::strictEqual(src1, src2));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_nstricteq) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
callFrame[dst] = jsBoolean(!JSValue::strictEqual(src1, src2));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_less) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
JSValue result = jsBoolean(jsLess(callFrame, src1, src2));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_lesseq) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
JSValue result = jsBoolean(jsLessEq(callFrame, src1, src2));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_pre_inc) {
int srcDst = (++vPC)->u.operand;
JSValue v = callFrame[srcDst].jsValue();
if (JSFastMath::canDoFastAdditiveOperations(v))
callFrame[srcDst] = JSValue(JSFastMath::incImmediateNumber(v));
else {
JSValue result = jsNumber(callFrame, v.toNumber(callFrame) + 1);
CHECK_FOR_EXCEPTION();
callFrame[srcDst] = result;
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_pre_dec) {
int srcDst = (++vPC)->u.operand;
JSValue v = callFrame[srcDst].jsValue();
if (JSFastMath::canDoFastAdditiveOperations(v))
callFrame[srcDst] = JSValue(JSFastMath::decImmediateNumber(v));
else {
JSValue result = jsNumber(callFrame, v.toNumber(callFrame) - 1);
CHECK_FOR_EXCEPTION();
callFrame[srcDst] = result;
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_post_inc) {
int dst = (++vPC)->u.operand;
int srcDst = (++vPC)->u.operand;
JSValue v = callFrame[srcDst].jsValue();
if (JSFastMath::canDoFastAdditiveOperations(v)) {
callFrame[dst] = v;
callFrame[srcDst] = JSValue(JSFastMath::incImmediateNumber(v));
} else {
JSValue number = callFrame[srcDst].jsValue().toJSNumber(callFrame);
CHECK_FOR_EXCEPTION();
callFrame[dst] = number;
callFrame[srcDst] = JSValue(jsNumber(callFrame, number.uncheckedGetNumber() + 1));
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_post_dec) {
int dst = (++vPC)->u.operand;
int srcDst = (++vPC)->u.operand;
JSValue v = callFrame[srcDst].jsValue();
if (JSFastMath::canDoFastAdditiveOperations(v)) {
callFrame[dst] = v;
callFrame[srcDst] = JSValue(JSFastMath::decImmediateNumber(v));
} else {
JSValue number = callFrame[srcDst].jsValue().toJSNumber(callFrame);
CHECK_FOR_EXCEPTION();
callFrame[dst] = number;
callFrame[srcDst] = JSValue(jsNumber(callFrame, number.uncheckedGetNumber() - 1));
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_to_jsnumber) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
JSValue srcVal = callFrame[src].jsValue();
if (LIKELY(srcVal.isNumber()))
callFrame[dst] = callFrame[src];
else {
JSValue result = srcVal.toJSNumber(callFrame);
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_negate) {
int dst = (++vPC)->u.operand;
JSValue src = callFrame[(++vPC)->u.operand].jsValue();
++vPC;
double v;
if (src.getNumber(v))
callFrame[dst] = JSValue(jsNumber(callFrame, -v));
else {
JSValue result = jsNumber(callFrame, -src.toNumber(callFrame));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_add) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
if (JSFastMath::canDoFastAdditiveOperations(src1, src2))
callFrame[dst] = JSValue(JSFastMath::addImmediateNumbers(src1, src2));
else {
JSValue result = jsAdd(callFrame, src1, src2);
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
vPC += 2;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_mul) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
double left;
double right;
if (JSValue::areBothInt32Fast(src1, src2)) {
int32_t left = src1.getInt32Fast();
int32_t right = src2.getInt32Fast();
if ((left | right) >> 15 == 0)
callFrame[dst] = JSValue(jsNumber(callFrame, left * right));
else
callFrame[dst] = JSValue(jsNumber(callFrame, static_cast<double>(left) * static_cast<double>(right)));
} else if (src1.getNumber(left) && src2.getNumber(right))
callFrame[dst] = JSValue(jsNumber(callFrame, left * right));
else {
JSValue result = jsNumber(callFrame, src1.toNumber(callFrame) * src2.toNumber(callFrame));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
vPC += 2;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_div) {
int dst = (++vPC)->u.operand;
JSValue dividend = callFrame[(++vPC)->u.operand].jsValue();
JSValue divisor = callFrame[(++vPC)->u.operand].jsValue();
double left;
double right;
if (dividend.getNumber(left) && divisor.getNumber(right))
callFrame[dst] = JSValue(jsNumber(callFrame, left / right));
else {
JSValue result = jsNumber(callFrame, dividend.toNumber(callFrame) / divisor.toNumber(callFrame));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_mod) {
int dst = (++vPC)->u.operand;
int dividend = (++vPC)->u.operand;
int divisor = (++vPC)->u.operand;
JSValue dividendValue = callFrame[dividend].jsValue();
JSValue divisorValue = callFrame[divisor].jsValue();
if (JSValue::areBothInt32Fast(dividendValue, divisorValue) && divisorValue != jsNumber(callFrame, 0)) {
JSValue result = JSValue::makeInt32Fast(dividendValue.getInt32Fast() % divisorValue.getInt32Fast());
ASSERT(result);
callFrame[dst] = result;
++vPC;
NEXT_INSTRUCTION();
}
double d = dividendValue.toNumber(callFrame);
JSValue result = jsNumber(callFrame, fmod(d, divisorValue.toNumber(callFrame)));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_sub) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
double left;
double right;
if (JSFastMath::canDoFastAdditiveOperations(src1, src2))
callFrame[dst] = JSValue(JSFastMath::subImmediateNumbers(src1, src2));
else if (src1.getNumber(left) && src2.getNumber(right))
callFrame[dst] = JSValue(jsNumber(callFrame, left - right));
else {
JSValue result = jsNumber(callFrame, src1.toNumber(callFrame) - src2.toNumber(callFrame));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
vPC += 2;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_lshift) {
int dst = (++vPC)->u.operand;
JSValue val = callFrame[(++vPC)->u.operand].jsValue();
JSValue shift = callFrame[(++vPC)->u.operand].jsValue();
int32_t left;
uint32_t right;
if (JSValue::areBothInt32Fast(val, shift))
callFrame[dst] = JSValue(jsNumber(callFrame, val.getInt32Fast() << (shift.getInt32Fast() & 0x1f)));
else if (val.numberToInt32(left) && shift.numberToUInt32(right))
callFrame[dst] = JSValue(jsNumber(callFrame, left << (right & 0x1f)));
else {
JSValue result = jsNumber(callFrame, (val.toInt32(callFrame)) << (shift.toUInt32(callFrame) & 0x1f));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_rshift) {
int dst = (++vPC)->u.operand;
JSValue val = callFrame[(++vPC)->u.operand].jsValue();
JSValue shift = callFrame[(++vPC)->u.operand].jsValue();
int32_t left;
uint32_t right;
if (JSFastMath::canDoFastRshift(val, shift))
callFrame[dst] = JSValue(JSFastMath::rightShiftImmediateNumbers(val, shift));
else if (val.numberToInt32(left) && shift.numberToUInt32(right))
callFrame[dst] = JSValue(jsNumber(callFrame, left >> (right & 0x1f)));
else {
JSValue result = jsNumber(callFrame, (val.toInt32(callFrame)) >> (shift.toUInt32(callFrame) & 0x1f));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_urshift) {
int dst = (++vPC)->u.operand;
JSValue val = callFrame[(++vPC)->u.operand].jsValue();
JSValue shift = callFrame[(++vPC)->u.operand].jsValue();
if (JSFastMath::canDoFastUrshift(val, shift))
callFrame[dst] = JSValue(JSFastMath::rightShiftImmediateNumbers(val, shift));
else {
JSValue result = jsNumber(callFrame, (val.toUInt32(callFrame)) >> (shift.toUInt32(callFrame) & 0x1f));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_bitand) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
int32_t left;
int32_t right;
if (JSFastMath::canDoFastBitwiseOperations(src1, src2))
callFrame[dst] = JSValue(JSFastMath::andImmediateNumbers(src1, src2));
else if (src1.numberToInt32(left) && src2.numberToInt32(right))
callFrame[dst] = JSValue(jsNumber(callFrame, left & right));
else {
JSValue result = jsNumber(callFrame, src1.toInt32(callFrame) & src2.toInt32(callFrame));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
vPC += 2;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_bitxor) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
int32_t left;
int32_t right;
if (JSFastMath::canDoFastBitwiseOperations(src1, src2))
callFrame[dst] = JSValue(JSFastMath::xorImmediateNumbers(src1, src2));
else if (src1.numberToInt32(left) && src2.numberToInt32(right))
callFrame[dst] = JSValue(jsNumber(callFrame, left ^ right));
else {
JSValue result = jsNumber(callFrame, src1.toInt32(callFrame) ^ src2.toInt32(callFrame));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
vPC += 2;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_bitor) {
int dst = (++vPC)->u.operand;
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
int32_t left;
int32_t right;
if (JSFastMath::canDoFastBitwiseOperations(src1, src2))
callFrame[dst] = JSValue(JSFastMath::orImmediateNumbers(src1, src2));
else if (src1.numberToInt32(left) && src2.numberToInt32(right))
callFrame[dst] = JSValue(jsNumber(callFrame, left | right));
else {
JSValue result = jsNumber(callFrame, src1.toInt32(callFrame) | src2.toInt32(callFrame));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
vPC += 2;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_bitnot) {
int dst = (++vPC)->u.operand;
JSValue src = callFrame[(++vPC)->u.operand].jsValue();
int32_t value;
if (src.numberToInt32(value))
callFrame[dst] = JSValue(jsNumber(callFrame, ~value));
else {
JSValue result = jsNumber(callFrame, ~src.toInt32(callFrame));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_not) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
JSValue result = jsBoolean(!callFrame[src].jsValue().toBoolean(callFrame));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_instanceof) {
int dst = vPC[1].u.operand;
int value = vPC[2].u.operand;
int base = vPC[3].u.operand;
int baseProto = vPC[4].u.operand;
JSValue baseVal = callFrame[base].jsValue();
if (isInvalidParamForInstanceOf(callFrame, callFrame->codeBlock(), vPC, baseVal, exceptionValue))
goto vm_throw;
bool result = asObject(baseVal)->hasInstance(callFrame, callFrame[value].jsValue(), callFrame[baseProto].jsValue());
CHECK_FOR_EXCEPTION();
callFrame[dst] = jsBoolean(result);
vPC += 5;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_typeof) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
callFrame[dst] = JSValue(jsTypeStringForValue(callFrame, callFrame[src].jsValue()));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_is_undefined) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
JSValue v = callFrame[src].jsValue();
callFrame[dst] = jsBoolean(v.isCell() ? v.asCell()->structure()->typeInfo().masqueradesAsUndefined() : v.isUndefined());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_is_boolean) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
callFrame[dst] = jsBoolean(callFrame[src].jsValue().isBoolean());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_is_number) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
callFrame[dst] = jsBoolean(callFrame[src].jsValue().isNumber());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_is_string) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
callFrame[dst] = jsBoolean(callFrame[src].jsValue().isString());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_is_object) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
callFrame[dst] = jsBoolean(jsIsObjectType(callFrame[src].jsValue()));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_is_function) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
callFrame[dst] = jsBoolean(jsIsFunctionType(callFrame[src].jsValue()));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_in) {
int dst = (++vPC)->u.operand;
int property = (++vPC)->u.operand;
int base = (++vPC)->u.operand;
JSValue baseVal = callFrame[base].jsValue();
if (isInvalidParamForIn(callFrame, callFrame->codeBlock(), vPC, baseVal, exceptionValue))
goto vm_throw;
JSObject* baseObj = asObject(baseVal);
JSValue propName = callFrame[property].jsValue();
uint32_t i;
if (propName.getUInt32(i))
callFrame[dst] = jsBoolean(baseObj->hasProperty(callFrame, i));
else {
Identifier property(callFrame, propName.toString(callFrame));
CHECK_FOR_EXCEPTION();
callFrame[dst] = jsBoolean(baseObj->hasProperty(callFrame, property));
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_resolve) {
if (UNLIKELY(!resolve(callFrame, vPC, exceptionValue)))
goto vm_throw;
vPC += 3;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_resolve_skip) {
if (UNLIKELY(!resolveSkip(callFrame, vPC, exceptionValue)))
goto vm_throw;
vPC += 4;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_resolve_global) {
if (UNLIKELY(!resolveGlobal(callFrame, vPC, exceptionValue)))
goto vm_throw;
vPC += 6;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_global_var) {
int dst = (++vPC)->u.operand;
JSGlobalObject* scope = static_cast<JSGlobalObject*>((++vPC)->u.jsCell);
ASSERT(scope->isGlobalObject());
int index = (++vPC)->u.operand;
callFrame[dst] = scope->registerAt(index);
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_put_global_var) {
JSGlobalObject* scope = static_cast<JSGlobalObject*>((++vPC)->u.jsCell);
ASSERT(scope->isGlobalObject());
int index = (++vPC)->u.operand;
int value = (++vPC)->u.operand;
scope->registerAt(index) = JSValue(callFrame[value].jsValue());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_scoped_var) {
int dst = (++vPC)->u.operand;
int index = (++vPC)->u.operand;
int skip = (++vPC)->u.operand + callFrame->codeBlock()->needsFullScopeChain();
ScopeChainNode* scopeChain = callFrame->scopeChain();
ScopeChainIterator iter = scopeChain->begin();
ScopeChainIterator end = scopeChain->end();
ASSERT(iter != end);
while (skip--) {
++iter;
ASSERT(iter != end);
}
ASSERT((*iter)->isVariableObject());
JSVariableObject* scope = static_cast<JSVariableObject*>(*iter);
callFrame[dst] = scope->registerAt(index);
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_put_scoped_var) {
int index = (++vPC)->u.operand;
int skip = (++vPC)->u.operand + callFrame->codeBlock()->needsFullScopeChain();
int value = (++vPC)->u.operand;
ScopeChainNode* scopeChain = callFrame->scopeChain();
ScopeChainIterator iter = scopeChain->begin();
ScopeChainIterator end = scopeChain->end();
ASSERT(iter != end);
while (skip--) {
++iter;
ASSERT(iter != end);
}
ASSERT((*iter)->isVariableObject());
JSVariableObject* scope = static_cast<JSVariableObject*>(*iter);
scope->registerAt(index) = JSValue(callFrame[value].jsValue());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_resolve_base) {
resolveBase(callFrame, vPC);
vPC += 3;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_resolve_with_base) {
if (UNLIKELY(!resolveBaseAndProperty(callFrame, vPC, exceptionValue)))
goto vm_throw;
vPC += 4;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_resolve_func) {
if (UNLIKELY(!resolveBaseAndFunc(callFrame, vPC, exceptionValue)))
goto vm_throw;
vPC += 4;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_by_id) {
int dst = vPC[1].u.operand;
int base = vPC[2].u.operand;
int property = vPC[3].u.operand;
CodeBlock* codeBlock = callFrame->codeBlock();
Identifier& ident = codeBlock->identifier(property);
JSValue baseValue = callFrame[base].jsValue();
PropertySlot slot(baseValue);
JSValue result = baseValue.get(callFrame, ident, slot);
CHECK_FOR_EXCEPTION();
tryCacheGetByID(callFrame, codeBlock, vPC, baseValue, ident, slot);
callFrame[dst] = result;
vPC += 8;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_by_id_self) {
int base = vPC[2].u.operand;
JSValue baseValue = callFrame[base].jsValue();
if (LIKELY(baseValue.isCell())) {
JSCell* baseCell = asCell(baseValue);
Structure* structure = vPC[4].u.structure;
if (LIKELY(baseCell->structure() == structure)) {
ASSERT(baseCell->isObject());
JSObject* baseObject = asObject(baseCell);
int dst = vPC[1].u.operand;
int offset = vPC[5].u.operand;
ASSERT(baseObject->get(callFrame, callFrame->codeBlock()->identifier(vPC[3].u.operand)) == baseObject->getDirectOffset(offset));
callFrame[dst] = JSValue(baseObject->getDirectOffset(offset));
vPC += 8;
NEXT_INSTRUCTION();
}
}
uncacheGetByID(callFrame->codeBlock(), vPC);
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_by_id_proto) {
int base = vPC[2].u.operand;
JSValue baseValue = callFrame[base].jsValue();
if (LIKELY(baseValue.isCell())) {
JSCell* baseCell = asCell(baseValue);
Structure* structure = vPC[4].u.structure;
if (LIKELY(baseCell->structure() == structure)) {
ASSERT(structure->prototypeForLookup(callFrame).isObject());
JSObject* protoObject = asObject(structure->prototypeForLookup(callFrame));
Structure* prototypeStructure = vPC[5].u.structure;
if (LIKELY(protoObject->structure() == prototypeStructure)) {
int dst = vPC[1].u.operand;
int offset = vPC[6].u.operand;
ASSERT(protoObject->get(callFrame, callFrame->codeBlock()->identifier(vPC[3].u.operand)) == protoObject->getDirectOffset(offset));
callFrame[dst] = JSValue(protoObject->getDirectOffset(offset));
vPC += 8;
NEXT_INSTRUCTION();
}
}
}
uncacheGetByID(callFrame->codeBlock(), vPC);
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_by_id_self_list) {
ASSERT_NOT_REACHED();
vPC += 8;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_by_id_proto_list) {
ASSERT_NOT_REACHED();
vPC += 8;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_by_id_chain) {
int base = vPC[2].u.operand;
JSValue baseValue = callFrame[base].jsValue();
if (LIKELY(baseValue.isCell())) {
JSCell* baseCell = asCell(baseValue);
Structure* structure = vPC[4].u.structure;
if (LIKELY(baseCell->structure() == structure)) {
RefPtr<Structure>* it = vPC[5].u.structureChain->head();
size_t count = vPC[6].u.operand;
RefPtr<Structure>* end = it + count;
while (true) {
JSObject* baseObject = asObject(baseCell->structure()->prototypeForLookup(callFrame));
if (UNLIKELY(baseObject->structure() != (*it).get()))
break;
if (++it == end) {
int dst = vPC[1].u.operand;
int offset = vPC[7].u.operand;
ASSERT(baseObject->get(callFrame, callFrame->codeBlock()->identifier(vPC[3].u.operand)) == baseObject->getDirectOffset(offset));
callFrame[dst] = JSValue(baseObject->getDirectOffset(offset));
vPC += 8;
NEXT_INSTRUCTION();
}
baseCell = baseObject;
}
}
}
uncacheGetByID(callFrame->codeBlock(), vPC);
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_by_id_generic) {
int dst = vPC[1].u.operand;
int base = vPC[2].u.operand;
int property = vPC[3].u.operand;
Identifier& ident = callFrame->codeBlock()->identifier(property);
JSValue baseValue = callFrame[base].jsValue();
PropertySlot slot(baseValue);
JSValue result = baseValue.get(callFrame, ident, slot);
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
vPC += 8;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_array_length) {
int base = vPC[2].u.operand;
JSValue baseValue = callFrame[base].jsValue();
if (LIKELY(isJSArray(globalData, baseValue))) {
int dst = vPC[1].u.operand;
callFrame[dst] = JSValue(jsNumber(callFrame, asArray(baseValue)->length()));
vPC += 8;
NEXT_INSTRUCTION();
}
uncacheGetByID(callFrame->codeBlock(), vPC);
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_string_length) {
int base = vPC[2].u.operand;
JSValue baseValue = callFrame[base].jsValue();
if (LIKELY(isJSString(globalData, baseValue))) {
int dst = vPC[1].u.operand;
callFrame[dst] = JSValue(jsNumber(callFrame, asString(baseValue)->value().size()));
vPC += 8;
NEXT_INSTRUCTION();
}
uncacheGetByID(callFrame->codeBlock(), vPC);
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_put_by_id) {
int base = vPC[1].u.operand;
int property = vPC[2].u.operand;
int value = vPC[3].u.operand;
CodeBlock* codeBlock = callFrame->codeBlock();
JSValue baseValue = callFrame[base].jsValue();
Identifier& ident = codeBlock->identifier(property);
PutPropertySlot slot;
baseValue.put(callFrame, ident, callFrame[value].jsValue(), slot);
CHECK_FOR_EXCEPTION();
tryCachePutByID(callFrame, codeBlock, vPC, baseValue, slot);
vPC += 8;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_put_by_id_transition) {
int base = vPC[1].u.operand;
JSValue baseValue = callFrame[base].jsValue();
if (LIKELY(baseValue.isCell())) {
JSCell* baseCell = asCell(baseValue);
Structure* oldStructure = vPC[4].u.structure;
Structure* newStructure = vPC[5].u.structure;
if (LIKELY(baseCell->structure() == oldStructure)) {
ASSERT(baseCell->isObject());
JSObject* baseObject = asObject(baseCell);
RefPtr<Structure>* it = vPC[6].u.structureChain->head();
JSValue proto = baseObject->structure()->prototypeForLookup(callFrame);
while (!proto.isNull()) {
if (UNLIKELY(asObject(proto)->structure() != (*it).get())) {
uncachePutByID(callFrame->codeBlock(), vPC);
NEXT_INSTRUCTION();
}
++it;
proto = asObject(proto)->structure()->prototypeForLookup(callFrame);
}
baseObject->transitionTo(newStructure);
int value = vPC[3].u.operand;
unsigned offset = vPC[7].u.operand;
ASSERT(baseObject->offsetForLocation(baseObject->getDirectLocation(callFrame->codeBlock()->identifier(vPC[2].u.operand))) == offset);
baseObject->putDirectOffset(offset, callFrame[value].jsValue());
vPC += 8;
NEXT_INSTRUCTION();
}
}
uncachePutByID(callFrame->codeBlock(), vPC);
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_put_by_id_replace) {
int base = vPC[1].u.operand;
JSValue baseValue = callFrame[base].jsValue();
if (LIKELY(baseValue.isCell())) {
JSCell* baseCell = asCell(baseValue);
Structure* structure = vPC[4].u.structure;
if (LIKELY(baseCell->structure() == structure)) {
ASSERT(baseCell->isObject());
JSObject* baseObject = asObject(baseCell);
int value = vPC[3].u.operand;
unsigned offset = vPC[5].u.operand;
ASSERT(baseObject->offsetForLocation(baseObject->getDirectLocation(callFrame->codeBlock()->identifier(vPC[2].u.operand))) == offset);
baseObject->putDirectOffset(offset, callFrame[value].jsValue());
vPC += 8;
NEXT_INSTRUCTION();
}
}
uncachePutByID(callFrame->codeBlock(), vPC);
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_put_by_id_generic) {
int base = vPC[1].u.operand;
int property = vPC[2].u.operand;
int value = vPC[3].u.operand;
JSValue baseValue = callFrame[base].jsValue();
Identifier& ident = callFrame->codeBlock()->identifier(property);
PutPropertySlot slot;
baseValue.put(callFrame, ident, callFrame[value].jsValue(), slot);
CHECK_FOR_EXCEPTION();
vPC += 8;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_del_by_id) {
int dst = (++vPC)->u.operand;
int base = (++vPC)->u.operand;
int property = (++vPC)->u.operand;
JSObject* baseObj = callFrame[base].jsValue().toObject(callFrame);
Identifier& ident = callFrame->codeBlock()->identifier(property);
JSValue result = jsBoolean(baseObj->deleteProperty(callFrame, ident));
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_by_val) {
int dst = (++vPC)->u.operand;
int base = (++vPC)->u.operand;
int property = (++vPC)->u.operand;
JSValue baseValue = callFrame[base].jsValue();
JSValue subscript = callFrame[property].jsValue();
JSValue result;
if (LIKELY(subscript.isUInt32Fast())) {
uint32_t i = subscript.getUInt32Fast();
if (isJSArray(globalData, baseValue)) {
JSArray* jsArray = asArray(baseValue);
if (jsArray->canGetIndex(i))
result = jsArray->getIndex(i);
else
result = jsArray->JSArray::get(callFrame, i);
} else if (isJSString(globalData, baseValue) && asString(baseValue)->canGetIndex(i))
result = asString(baseValue)->getIndex(&callFrame->globalData(), i);
else if (isJSByteArray(globalData, baseValue) && asByteArray(baseValue)->canAccessIndex(i))
result = asByteArray(baseValue)->getIndex(callFrame, i);
else
result = baseValue.get(callFrame, i);
} else {
Identifier property(callFrame, subscript.toString(callFrame));
result = baseValue.get(callFrame, property);
}
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_put_by_val) {
int base = (++vPC)->u.operand;
int property = (++vPC)->u.operand;
int value = (++vPC)->u.operand;
JSValue baseValue = callFrame[base].jsValue();
JSValue subscript = callFrame[property].jsValue();
if (LIKELY(subscript.isUInt32Fast())) {
uint32_t i = subscript.getUInt32Fast();
if (isJSArray(globalData, baseValue)) {
JSArray* jsArray = asArray(baseValue);
if (jsArray->canSetIndex(i))
jsArray->setIndex(i, callFrame[value].jsValue());
else
jsArray->JSArray::put(callFrame, i, callFrame[value].jsValue());
} else if (isJSByteArray(globalData, baseValue) && asByteArray(baseValue)->canAccessIndex(i)) {
JSByteArray* jsByteArray = asByteArray(baseValue);
double dValue = 0;
JSValue jsValue = callFrame[value].jsValue();
if (jsValue.isInt32Fast())
jsByteArray->setIndex(i, jsValue.getInt32Fast());
else if (jsValue.getNumber(dValue))
jsByteArray->setIndex(i, dValue);
else
baseValue.put(callFrame, i, jsValue);
} else
baseValue.put(callFrame, i, callFrame[value].jsValue());
} else {
Identifier property(callFrame, subscript.toString(callFrame));
if (!globalData->exception) { PutPropertySlot slot;
baseValue.put(callFrame, property, callFrame[value].jsValue(), slot);
}
}
CHECK_FOR_EXCEPTION();
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_del_by_val) {
int dst = (++vPC)->u.operand;
int base = (++vPC)->u.operand;
int property = (++vPC)->u.operand;
JSObject* baseObj = callFrame[base].jsValue().toObject(callFrame);
JSValue subscript = callFrame[property].jsValue();
JSValue result;
uint32_t i;
if (subscript.getUInt32(i))
result = jsBoolean(baseObj->deleteProperty(callFrame, i));
else {
CHECK_FOR_EXCEPTION();
Identifier property(callFrame, subscript.toString(callFrame));
CHECK_FOR_EXCEPTION();
result = jsBoolean(baseObj->deleteProperty(callFrame, property));
}
CHECK_FOR_EXCEPTION();
callFrame[dst] = result;
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_put_by_index) {
int base = (++vPC)->u.operand;
unsigned property = (++vPC)->u.operand;
int value = (++vPC)->u.operand;
callFrame[base].jsValue().put(callFrame, property, callFrame[value].jsValue());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_loop) {
#if ENABLE(OPCODE_STATS)
OpcodeStats::resetLastInstruction();
#endif
int target = (++vPC)->u.operand;
CHECK_FOR_TIMEOUT();
vPC += target;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_jmp) {
#if ENABLE(OPCODE_STATS)
OpcodeStats::resetLastInstruction();
#endif
int target = (++vPC)->u.operand;
vPC += target;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_loop_if_true) {
int cond = (++vPC)->u.operand;
int target = (++vPC)->u.operand;
if (callFrame[cond].jsValue().toBoolean(callFrame)) {
vPC += target;
CHECK_FOR_TIMEOUT();
NEXT_INSTRUCTION();
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_jtrue) {
int cond = (++vPC)->u.operand;
int target = (++vPC)->u.operand;
if (callFrame[cond].jsValue().toBoolean(callFrame)) {
vPC += target;
NEXT_INSTRUCTION();
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_jfalse) {
int cond = (++vPC)->u.operand;
int target = (++vPC)->u.operand;
if (!callFrame[cond].jsValue().toBoolean(callFrame)) {
vPC += target;
NEXT_INSTRUCTION();
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_jeq_null) {
int src = (++vPC)->u.operand;
int target = (++vPC)->u.operand;
JSValue srcValue = callFrame[src].jsValue();
if (srcValue.isUndefinedOrNull() || (srcValue.isCell() && srcValue.asCell()->structure()->typeInfo().masqueradesAsUndefined())) {
vPC += target;
NEXT_INSTRUCTION();
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_jneq_null) {
int src = (++vPC)->u.operand;
int target = (++vPC)->u.operand;
JSValue srcValue = callFrame[src].jsValue();
if (!srcValue.isUndefinedOrNull() || (srcValue.isCell() && !srcValue.asCell()->structure()->typeInfo().masqueradesAsUndefined())) {
vPC += target;
NEXT_INSTRUCTION();
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_jneq_ptr) {
int src = (++vPC)->u.operand;
JSValue ptr = JSValue((++vPC)->u.jsCell);
int target = (++vPC)->u.operand;
JSValue srcValue = callFrame[src].jsValue();
if (srcValue != ptr) {
vPC += target;
NEXT_INSTRUCTION();
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_loop_if_less) {
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
int target = (++vPC)->u.operand;
bool result = jsLess(callFrame, src1, src2);
CHECK_FOR_EXCEPTION();
if (result) {
vPC += target;
CHECK_FOR_TIMEOUT();
NEXT_INSTRUCTION();
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_loop_if_lesseq) {
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
int target = (++vPC)->u.operand;
bool result = jsLessEq(callFrame, src1, src2);
CHECK_FOR_EXCEPTION();
if (result) {
vPC += target;
CHECK_FOR_TIMEOUT();
NEXT_INSTRUCTION();
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_jnless) {
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
int target = (++vPC)->u.operand;
bool result = jsLess(callFrame, src1, src2);
CHECK_FOR_EXCEPTION();
if (!result) {
vPC += target;
NEXT_INSTRUCTION();
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_jnlesseq) {
JSValue src1 = callFrame[(++vPC)->u.operand].jsValue();
JSValue src2 = callFrame[(++vPC)->u.operand].jsValue();
int target = (++vPC)->u.operand;
bool result = jsLessEq(callFrame, src1, src2);
CHECK_FOR_EXCEPTION();
if (!result) {
vPC += target;
NEXT_INSTRUCTION();
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_switch_imm) {
int tableIndex = (++vPC)->u.operand;
int defaultOffset = (++vPC)->u.operand;
JSValue scrutinee = callFrame[(++vPC)->u.operand].jsValue();
if (scrutinee.isInt32Fast())
vPC += callFrame->codeBlock()->immediateSwitchJumpTable(tableIndex).offsetForValue(scrutinee.getInt32Fast(), defaultOffset);
else {
double value;
int32_t intValue;
if (scrutinee.getNumber(value) && ((intValue = static_cast<int32_t>(value)) == value))
vPC += callFrame->codeBlock()->immediateSwitchJumpTable(tableIndex).offsetForValue(intValue, defaultOffset);
else
vPC += defaultOffset;
}
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_switch_char) {
int tableIndex = (++vPC)->u.operand;
int defaultOffset = (++vPC)->u.operand;
JSValue scrutinee = callFrame[(++vPC)->u.operand].jsValue();
if (!scrutinee.isString())
vPC += defaultOffset;
else {
UString::Rep* value = asString(scrutinee)->value().rep();
if (value->size() != 1)
vPC += defaultOffset;
else
vPC += callFrame->codeBlock()->characterSwitchJumpTable(tableIndex).offsetForValue(value->data()[0], defaultOffset);
}
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_switch_string) {
int tableIndex = (++vPC)->u.operand;
int defaultOffset = (++vPC)->u.operand;
JSValue scrutinee = callFrame[(++vPC)->u.operand].jsValue();
if (!scrutinee.isString())
vPC += defaultOffset;
else
vPC += callFrame->codeBlock()->stringSwitchJumpTable(tableIndex).offsetForValue(asString(scrutinee)->value().rep(), defaultOffset);
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_new_func) {
int dst = (++vPC)->u.operand;
int func = (++vPC)->u.operand;
callFrame[dst] = callFrame->codeBlock()->function(func)->makeFunction(callFrame, callFrame->scopeChain());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_new_func_exp) {
int dst = (++vPC)->u.operand;
int func = (++vPC)->u.operand;
callFrame[dst] = callFrame->codeBlock()->functionExpression(func)->makeFunction(callFrame, callFrame->scopeChain());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_call_eval) {
int dst = vPC[1].u.operand;
int func = vPC[2].u.operand;
int argCount = vPC[3].u.operand;
int registerOffset = vPC[4].u.operand;
JSValue funcVal = callFrame[func].jsValue();
Register* newCallFrame = callFrame->registers() + registerOffset;
Register* argv = newCallFrame - RegisterFile::CallFrameHeaderSize - argCount;
JSValue thisValue = argv[0].jsValue();
JSGlobalObject* globalObject = callFrame->scopeChain()->globalObject();
if (thisValue == globalObject && funcVal == globalObject->evalFunction()) {
JSValue result = callEval(callFrame, registerFile, argv, argCount, registerOffset, exceptionValue);
if (exceptionValue)
goto vm_throw;
callFrame[dst] = result;
vPC += 5;
NEXT_INSTRUCTION();
}
}
DEFINE_OPCODE(op_call) {
int dst = vPC[1].u.operand;
int func = vPC[2].u.operand;
int argCount = vPC[3].u.operand;
int registerOffset = vPC[4].u.operand;
JSValue v = callFrame[func].jsValue();
CallData callData;
CallType callType = v.getCallData(callData);
if (callType == CallTypeJS) {
ScopeChainNode* callDataScopeChain = callData.js.scopeChain;
FunctionBodyNode* functionBodyNode = callData.js.functionBody;
CodeBlock* newCodeBlock = &functionBodyNode->bytecode(callDataScopeChain);
CallFrame* previousCallFrame = callFrame;
callFrame = slideRegisterWindowForCall(newCodeBlock, registerFile, callFrame, registerOffset, argCount);
if (UNLIKELY(!callFrame)) {
callFrame = previousCallFrame;
exceptionValue = createStackOverflowError(callFrame);
goto vm_throw;
}
callFrame->init(newCodeBlock, vPC + 5, callDataScopeChain, previousCallFrame, dst, argCount, asFunction(v));
vPC = newCodeBlock->instructions().begin();
#if ENABLE(OPCODE_STATS)
OpcodeStats::resetLastInstruction();
#endif
NEXT_INSTRUCTION();
}
if (callType == CallTypeHost) {
ScopeChainNode* scopeChain = callFrame->scopeChain();
CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + registerOffset);
newCallFrame->init(0, vPC + 5, scopeChain, callFrame, dst, argCount, 0);
Register* thisRegister = newCallFrame->registers() - RegisterFile::CallFrameHeaderSize - argCount;
ArgList args(thisRegister + 1, argCount - 1);
JSValue thisValue = thisRegister->jsValue();
if (thisValue == jsNull())
thisValue = callFrame->globalThisValue();
JSValue returnValue;
{
SamplingTool::HostCallRecord callRecord(m_sampler);
returnValue = callData.native.function(newCallFrame, asObject(v), thisValue, args);
}
CHECK_FOR_EXCEPTION();
callFrame[dst] = JSValue(returnValue);
vPC += 5;
NEXT_INSTRUCTION();
}
ASSERT(callType == CallTypeNone);
exceptionValue = createNotAFunctionError(callFrame, v, vPC - callFrame->codeBlock()->instructions().begin(), callFrame->codeBlock());
goto vm_throw;
}
DEFINE_OPCODE(op_load_varargs) {
int argCountDst = (++vPC)->u.operand;
int argsOffset = (++vPC)->u.operand;
JSValue arguments = callFrame[argsOffset].jsValue();
uint32_t argCount = 0;
if (!arguments) {
argCount = (uint32_t)(callFrame[RegisterFile::ArgumentCount].u.i) - 1;
int32_t sizeDelta = argsOffset + argCount + RegisterFile::CallFrameHeaderSize;
Register* newEnd = callFrame->registers() + sizeDelta;
if (!registerFile->grow(newEnd) || ((newEnd - callFrame->registers()) != sizeDelta)) {
exceptionValue = createStackOverflowError(callFrame);
goto vm_throw;
}
uint32_t expectedParams = asFunction(callFrame[RegisterFile::Callee].jsValue())->body()->parameterCount();
uint32_t inplaceArgs = min(argCount, expectedParams);
uint32_t i = 0;
Register* argStore = callFrame->registers() + argsOffset;
for (; i < inplaceArgs; i++)
argStore[i] = callFrame->registers()[i - RegisterFile::CallFrameHeaderSize - expectedParams];
for (; i < argCount; i++)
argStore[i] = callFrame->registers()[i - RegisterFile::CallFrameHeaderSize - expectedParams - argCount - 1];
} else if (!arguments.isUndefinedOrNull()) {
if (!arguments.isObject()) {
exceptionValue = createInvalidParamError(callFrame, "Function.prototype.apply", arguments, vPC - callFrame->codeBlock()->instructions().begin(), callFrame->codeBlock());
goto vm_throw;
}
if (asObject(arguments)->classInfo() == &Arguments::info) {
Arguments* args = asArguments(arguments);
argCount = args->numProvidedArguments(callFrame);
int32_t sizeDelta = argsOffset + argCount + RegisterFile::CallFrameHeaderSize;
Register* newEnd = callFrame->registers() + sizeDelta;
if (!registerFile->grow(newEnd) || ((newEnd - callFrame->registers()) != sizeDelta)) {
exceptionValue = createStackOverflowError(callFrame);
goto vm_throw;
}
args->copyToRegisters(callFrame, callFrame->registers() + argsOffset, argCount);
} else if (isJSArray(&callFrame->globalData(), arguments)) {
JSArray* array = asArray(arguments);
argCount = array->length();
int32_t sizeDelta = argsOffset + argCount + RegisterFile::CallFrameHeaderSize;
Register* newEnd = callFrame->registers() + sizeDelta;
if (!registerFile->grow(newEnd) || ((newEnd - callFrame->registers()) != sizeDelta)) {
exceptionValue = createStackOverflowError(callFrame);
goto vm_throw;
}
array->copyToRegisters(callFrame, callFrame->registers() + argsOffset, argCount);
} else if (asObject(arguments)->inherits(&JSArray::info)) {
JSObject* argObject = asObject(arguments);
argCount = argObject->get(callFrame, callFrame->propertyNames().length).toUInt32(callFrame);
int32_t sizeDelta = argsOffset + argCount + RegisterFile::CallFrameHeaderSize;
Register* newEnd = callFrame->registers() + sizeDelta;
if (!registerFile->grow(newEnd) || ((newEnd - callFrame->registers()) != sizeDelta)) {
exceptionValue = createStackOverflowError(callFrame);
goto vm_throw;
}
Register* argsBuffer = callFrame->registers() + argsOffset;
for (unsigned i = 0; i < argCount; ++i) {
argsBuffer[i] = asObject(arguments)->get(callFrame, i);
CHECK_FOR_EXCEPTION();
}
} else {
if (!arguments.isObject()) {
exceptionValue = createInvalidParamError(callFrame, "Function.prototype.apply", arguments, vPC - callFrame->codeBlock()->instructions().begin(), callFrame->codeBlock());
goto vm_throw;
}
}
}
CHECK_FOR_EXCEPTION();
callFrame[argCountDst] = argCount + 1;
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_call_varargs) {
int dst = vPC[1].u.operand;
int func = vPC[2].u.operand;
int argCountReg = vPC[3].u.operand;
int registerOffset = vPC[4].u.operand;
JSValue v = callFrame[func].jsValue();
int argCount = callFrame[argCountReg].i();
registerOffset += argCount;
CallData callData;
CallType callType = v.getCallData(callData);
if (callType == CallTypeJS) {
ScopeChainNode* callDataScopeChain = callData.js.scopeChain;
FunctionBodyNode* functionBodyNode = callData.js.functionBody;
CodeBlock* newCodeBlock = &functionBodyNode->bytecode(callDataScopeChain);
CallFrame* previousCallFrame = callFrame;
callFrame = slideRegisterWindowForCall(newCodeBlock, registerFile, callFrame, registerOffset, argCount);
if (UNLIKELY(!callFrame)) {
callFrame = previousCallFrame;
exceptionValue = createStackOverflowError(callFrame);
goto vm_throw;
}
callFrame->init(newCodeBlock, vPC + 5, callDataScopeChain, previousCallFrame, dst, argCount, asFunction(v));
vPC = newCodeBlock->instructions().begin();
#if ENABLE(OPCODE_STATS)
OpcodeStats::resetLastInstruction();
#endif
NEXT_INSTRUCTION();
}
if (callType == CallTypeHost) {
ScopeChainNode* scopeChain = callFrame->scopeChain();
CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + registerOffset);
newCallFrame->init(0, vPC + 5, scopeChain, callFrame, dst, argCount, 0);
Register* thisRegister = newCallFrame->registers() - RegisterFile::CallFrameHeaderSize - argCount;
ArgList args(thisRegister + 1, argCount - 1);
JSValue thisValue = thisRegister->jsValue();
if (thisValue == jsNull())
thisValue = callFrame->globalThisValue();
JSValue returnValue;
{
SamplingTool::HostCallRecord callRecord(m_sampler);
returnValue = callData.native.function(newCallFrame, asObject(v), thisValue, args);
}
CHECK_FOR_EXCEPTION();
callFrame[dst] = JSValue(returnValue);
vPC += 5;
NEXT_INSTRUCTION();
}
ASSERT(callType == CallTypeNone);
exceptionValue = createNotAFunctionError(callFrame, v, vPC - callFrame->codeBlock()->instructions().begin(), callFrame->codeBlock());
goto vm_throw;
}
DEFINE_OPCODE(op_tear_off_activation) {
int src = (++vPC)->u.operand;
ASSERT(callFrame->codeBlock()->needsFullScopeChain());
asActivation(callFrame[src].jsValue())->copyRegisters(callFrame->optionalCalleeArguments());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_tear_off_arguments) {
ASSERT(callFrame->codeBlock()->usesArguments() && !callFrame->codeBlock()->needsFullScopeChain());
if (callFrame->optionalCalleeArguments())
callFrame->optionalCalleeArguments()->copyRegisters();
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_ret) {
int result = (++vPC)->u.operand;
if (callFrame->codeBlock()->needsFullScopeChain())
callFrame->scopeChain()->deref();
JSValue returnValue = callFrame[result].jsValue();
vPC = callFrame->returnPC();
int dst = callFrame->returnValueRegister();
callFrame = callFrame->callerFrame();
if (callFrame->hasHostCallFrameFlag())
return returnValue;
callFrame[dst] = JSValue(returnValue);
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_enter) {
size_t i = 0;
CodeBlock* codeBlock = callFrame->codeBlock();
for (size_t count = codeBlock->m_numVars; i < count; ++i)
callFrame[i] = jsUndefined();
for (size_t count = codeBlock->numberOfConstantRegisters(), j = 0; j < count; ++i, ++j)
callFrame[i] = codeBlock->constantRegister(j);
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_enter_with_activation) {
size_t i = 0;
CodeBlock* codeBlock = callFrame->codeBlock();
for (size_t count = codeBlock->m_numVars; i < count; ++i)
callFrame[i] = jsUndefined();
for (size_t count = codeBlock->numberOfConstantRegisters(), j = 0; j < count; ++i, ++j)
callFrame[i] = codeBlock->constantRegister(j);
int dst = (++vPC)->u.operand;
JSActivation* activation = new (globalData) JSActivation(callFrame, static_cast<FunctionBodyNode*>(codeBlock->ownerNode()));
callFrame[dst] = activation;
callFrame->setScopeChain(callFrame->scopeChain()->copy()->push(activation));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_convert_this) {
int thisRegister = (++vPC)->u.operand;
JSValue thisVal = callFrame[thisRegister].jsValue();
if (thisVal.needsThisConversion())
callFrame[thisRegister] = JSValue(thisVal.toThisObject(callFrame));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_init_arguments) {
callFrame[RegisterFile::ArgumentsRegister] = JSValue();
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_create_arguments) {
if (!callFrame->optionalCalleeArguments()) {
Arguments* arguments = new (globalData) Arguments(callFrame);
callFrame->setCalleeArguments(arguments);
callFrame[RegisterFile::ArgumentsRegister] = arguments;
}
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_construct) {
int dst = vPC[1].u.operand;
int func = vPC[2].u.operand;
int argCount = vPC[3].u.operand;
int registerOffset = vPC[4].u.operand;
int proto = vPC[5].u.operand;
int thisRegister = vPC[6].u.operand;
JSValue v = callFrame[func].jsValue();
ConstructData constructData;
ConstructType constructType = v.getConstructData(constructData);
if (constructType == ConstructTypeJS) {
ScopeChainNode* callDataScopeChain = constructData.js.scopeChain;
FunctionBodyNode* functionBodyNode = constructData.js.functionBody;
CodeBlock* newCodeBlock = &functionBodyNode->bytecode(callDataScopeChain);
Structure* structure;
JSValue prototype = callFrame[proto].jsValue();
if (prototype.isObject())
structure = asObject(prototype)->inheritorID();
else
structure = callDataScopeChain->globalObject()->emptyObjectStructure();
JSObject* newObject = new (globalData) JSObject(structure);
callFrame[thisRegister] = JSValue(newObject);
CallFrame* previousCallFrame = callFrame;
callFrame = slideRegisterWindowForCall(newCodeBlock, registerFile, callFrame, registerOffset, argCount);
if (UNLIKELY(!callFrame)) {
callFrame = previousCallFrame;
exceptionValue = createStackOverflowError(callFrame);
goto vm_throw;
}
callFrame->init(newCodeBlock, vPC + 7, callDataScopeChain, previousCallFrame, dst, argCount, asFunction(v));
vPC = newCodeBlock->instructions().begin();
#if ENABLE(OPCODE_STATS)
OpcodeStats::resetLastInstruction();
#endif
NEXT_INSTRUCTION();
}
if (constructType == ConstructTypeHost) {
ArgList args(callFrame->registers() + thisRegister + 1, argCount - 1);
ScopeChainNode* scopeChain = callFrame->scopeChain();
CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + registerOffset);
newCallFrame->init(0, vPC + 7, scopeChain, callFrame, dst, argCount, 0);
JSValue returnValue;
{
SamplingTool::HostCallRecord callRecord(m_sampler);
returnValue = constructData.native.function(newCallFrame, asObject(v), args);
}
CHECK_FOR_EXCEPTION();
callFrame[dst] = JSValue(returnValue);
vPC += 7;
NEXT_INSTRUCTION();
}
ASSERT(constructType == ConstructTypeNone);
exceptionValue = createNotAConstructorError(callFrame, v, vPC - callFrame->codeBlock()->instructions().begin(), callFrame->codeBlock());
goto vm_throw;
}
DEFINE_OPCODE(op_construct_verify) {
int dst = vPC[1].u.operand;
if (LIKELY(callFrame[dst].jsValue().isObject())) {
vPC += 3;
NEXT_INSTRUCTION();
}
int override = vPC[2].u.operand;
callFrame[dst] = callFrame[override];
vPC += 3;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_strcat) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
int count = (++vPC)->u.operand;
callFrame[dst] = concatenateStrings(callFrame, &callFrame->registers()[src], count);
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_to_primitive) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
callFrame[dst] = callFrame[src].jsValue().toPrimitive(callFrame);
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_push_scope) {
int scope = (++vPC)->u.operand;
JSValue v = callFrame[scope].jsValue();
JSObject* o = v.toObject(callFrame);
CHECK_FOR_EXCEPTION();
callFrame[scope] = JSValue(o);
callFrame->setScopeChain(callFrame->scopeChain()->push(o));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_pop_scope) {
callFrame->setScopeChain(callFrame->scopeChain()->pop());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_get_pnames) {
int dst = (++vPC)->u.operand;
int base = (++vPC)->u.operand;
callFrame[dst] = JSPropertyNameIterator::create(callFrame, callFrame[base].jsValue());
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_next_pname) {
int dst = (++vPC)->u.operand;
int iter = (++vPC)->u.operand;
int target = (++vPC)->u.operand;
JSPropertyNameIterator* it = callFrame[iter].propertyNameIterator();
if (JSValue temp = it->next(callFrame)) {
CHECK_FOR_TIMEOUT();
callFrame[dst] = JSValue(temp);
vPC += target;
NEXT_INSTRUCTION();
}
it->invalidate();
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_jmp_scopes) {
int count = (++vPC)->u.operand;
int target = (++vPC)->u.operand;
ScopeChainNode* tmp = callFrame->scopeChain();
while (count--)
tmp = tmp->pop();
callFrame->setScopeChain(tmp);
vPC += target;
NEXT_INSTRUCTION();
}
#if HAVE(COMPUTED_GOTO)
goto *(&&skip_new_scope);
#endif
DEFINE_OPCODE(op_push_new_scope) {
callFrame->setScopeChain(createExceptionScope(callFrame, vPC));
vPC += 4;
NEXT_INSTRUCTION();
}
#if HAVE(COMPUTED_GOTO)
skip_new_scope:
#endif
DEFINE_OPCODE(op_catch) {
ASSERT(exceptionValue);
ASSERT(!globalData->exception);
int ex = (++vPC)->u.operand;
callFrame[ex] = exceptionValue;
exceptionValue = JSValue();
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_throw) {
int ex = (++vPC)->u.operand;
exceptionValue = callFrame[ex].jsValue();
handler = throwException(callFrame, exceptionValue, vPC - callFrame->codeBlock()->instructions().begin(), true);
if (!handler) {
*exception = exceptionValue;
return jsNull();
}
vPC = callFrame->codeBlock()->instructions().begin() + handler->target;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_unexpected_load) {
int dst = (++vPC)->u.operand;
int src = (++vPC)->u.operand;
callFrame[dst] = JSValue(callFrame->codeBlock()->unexpectedConstant(src));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_new_error) {
int dst = (++vPC)->u.operand;
int type = (++vPC)->u.operand;
int message = (++vPC)->u.operand;
CodeBlock* codeBlock = callFrame->codeBlock();
callFrame[dst] = JSValue(Error::create(callFrame, (ErrorType)type, codeBlock->unexpectedConstant(message).toString(callFrame), codeBlock->lineNumberForBytecodeOffset(callFrame, vPC - codeBlock->instructions().begin()), codeBlock->ownerNode()->sourceID(), codeBlock->ownerNode()->sourceURL()));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_end) {
if (callFrame->codeBlock()->needsFullScopeChain()) {
ScopeChainNode* scopeChain = callFrame->scopeChain();
ASSERT(scopeChain->refCount > 1);
scopeChain->deref();
}
int result = (++vPC)->u.operand;
return callFrame[result].jsValue();
}
DEFINE_OPCODE(op_put_getter) {
int base = (++vPC)->u.operand;
int property = (++vPC)->u.operand;
int function = (++vPC)->u.operand;
ASSERT(callFrame[base].jsValue().isObject());
JSObject* baseObj = asObject(callFrame[base].jsValue());
Identifier& ident = callFrame->codeBlock()->identifier(property);
ASSERT(callFrame[function].jsValue().isObject());
baseObj->defineGetter(callFrame, ident, asObject(callFrame[function].jsValue()));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_put_setter) {
int base = (++vPC)->u.operand;
int property = (++vPC)->u.operand;
int function = (++vPC)->u.operand;
ASSERT(callFrame[base].jsValue().isObject());
JSObject* baseObj = asObject(callFrame[base].jsValue());
Identifier& ident = callFrame->codeBlock()->identifier(property);
ASSERT(callFrame[function].jsValue().isObject());
baseObj->defineSetter(callFrame, ident, asObject(callFrame[function].jsValue()));
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_jsr) {
int retAddrDst = (++vPC)->u.operand;
int target = (++vPC)->u.operand;
callFrame[retAddrDst] = vPC + 1;
vPC += target;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_sret) {
int retAddrSrc = (++vPC)->u.operand;
vPC = callFrame[retAddrSrc].vPC();
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_debug) {
int debugHookID = (++vPC)->u.operand;
int firstLine = (++vPC)->u.operand;
int lastLine = (++vPC)->u.operand;
debug(callFrame, static_cast<DebugHookID>(debugHookID), firstLine, lastLine);
++vPC;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_profile_will_call) {
int function = vPC[1].u.operand;
if (*enabledProfilerReference)
(*enabledProfilerReference)->willExecute(callFrame, callFrame[function].jsValue());
vPC += 2;
NEXT_INSTRUCTION();
}
DEFINE_OPCODE(op_profile_did_call) {
int function = vPC[1].u.operand;
if (*enabledProfilerReference)
(*enabledProfilerReference)->didExecute(callFrame, callFrame[function].jsValue());
vPC += 2;
NEXT_INSTRUCTION();
}
vm_throw: {
globalData->exception = JSValue();
if (!tickCount) {
exceptionValue = createInterruptedExecutionException(globalData);
}
handler = throwException(callFrame, exceptionValue, vPC - callFrame->codeBlock()->instructions().begin(), false);
if (!handler) {
*exception = exceptionValue;
return jsNull();
}
vPC = callFrame->codeBlock()->instructions().begin() + handler->target;
NEXT_INSTRUCTION();
}
}
#if !HAVE(COMPUTED_GOTO)
} #endif
#undef NEXT_INSTRUCTION
#undef DEFINE_OPCODE
#undef CHECK_FOR_EXCEPTION
#undef CHECK_FOR_TIMEOUT
}
JSValue Interpreter::retrieveArguments(CallFrame* callFrame, JSFunction* function) const
{
CallFrame* functionCallFrame = findFunctionCallFrame(callFrame, function);
if (!functionCallFrame)
return jsNull();
CodeBlock* codeBlock = functionCallFrame->codeBlock();
if (codeBlock->usesArguments()) {
ASSERT(codeBlock->codeType() == FunctionCode);
SymbolTable& symbolTable = codeBlock->symbolTable();
int argumentsIndex = symbolTable.get(functionCallFrame->propertyNames().arguments.ustring().rep()).getIndex();
if (!functionCallFrame[argumentsIndex].arguments()) {
Arguments* arguments = new (callFrame) Arguments(functionCallFrame);
functionCallFrame->setCalleeArguments(arguments);
functionCallFrame[RegisterFile::ArgumentsRegister] = arguments;
}
return functionCallFrame[argumentsIndex].jsValue();
}
Arguments* arguments = functionCallFrame->optionalCalleeArguments();
if (!arguments) {
arguments = new (functionCallFrame) Arguments(functionCallFrame);
arguments->copyRegisters();
callFrame->setCalleeArguments(arguments);
}
return arguments;
}
JSValue Interpreter::retrieveCaller(CallFrame* callFrame, InternalFunction* function) const
{
CallFrame* functionCallFrame = findFunctionCallFrame(callFrame, function);
if (!functionCallFrame)
return jsNull();
CallFrame* callerFrame = functionCallFrame->callerFrame();
if (callerFrame->hasHostCallFrameFlag())
return jsNull();
JSValue caller = callerFrame->callee();
if (!caller)
return jsNull();
return caller;
}
void Interpreter::retrieveLastCaller(CallFrame* callFrame, int& lineNumber, intptr_t& sourceID, UString& sourceURL, JSValue& function) const
{
function = JSValue();
lineNumber = -1;
sourceURL = UString();
CallFrame* callerFrame = callFrame->callerFrame();
if (callerFrame->hasHostCallFrameFlag())
return;
CodeBlock* callerCodeBlock = callerFrame->codeBlock();
if (!callerCodeBlock)
return;
unsigned bytecodeOffset = bytecodeOffsetForPC(callerFrame, callerCodeBlock, callFrame->returnPC());
lineNumber = callerCodeBlock->lineNumberForBytecodeOffset(callerFrame, bytecodeOffset - 1);
sourceID = callerCodeBlock->ownerNode()->sourceID();
sourceURL = callerCodeBlock->ownerNode()->sourceURL();
function = callerFrame->callee();
}
CallFrame* Interpreter::findFunctionCallFrame(CallFrame* callFrame, InternalFunction* function)
{
for (CallFrame* candidate = callFrame; candidate; candidate = candidate->callerFrame()->removeHostCallFrameFlag()) {
if (candidate->callee() == function)
return candidate;
}
return 0;
}
}