summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/javascriptcore/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/javascriptcore/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp')
-rw-r--r--src/3rdparty/javascriptcore/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp90
1 files changed, 43 insertions, 47 deletions
diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp b/src/3rdparty/javascriptcore/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
index 711beb4c0a..74bf4f8584 100644
--- a/src/3rdparty/javascriptcore/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
+++ b/src/3rdparty/javascriptcore/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
@@ -256,15 +256,15 @@ BytecodeGenerator::BytecodeGenerator(ProgramNode* programNode, const Debugger* d
m_nextGlobalIndex -= symbolTable->size();
for (size_t i = 0; i < functionStack.size(); ++i) {
- FuncDeclNode* funcDecl = functionStack[i];
- globalObject->removeDirect(funcDecl->m_ident); // Make sure our new function is not shadowed by an old property.
- emitNewFunction(addGlobalVar(funcDecl->m_ident, false), funcDecl);
+ FunctionBodyNode* function = functionStack[i];
+ globalObject->removeDirect(function->ident()); // Make sure our new function is not shadowed by an old property.
+ emitNewFunction(addGlobalVar(function->ident(), false), function);
}
Vector<RegisterID*, 32> newVars;
for (size_t i = 0; i < varStack.size(); ++i)
- if (!globalObject->hasProperty(exec, varStack[i].first))
- newVars.append(addGlobalVar(varStack[i].first, varStack[i].second & DeclarationStacks::IsConstant));
+ if (!globalObject->hasProperty(exec, *varStack[i].first))
+ newVars.append(addGlobalVar(*varStack[i].first, varStack[i].second & DeclarationStacks::IsConstant));
preserveLastVar();
@@ -272,16 +272,16 @@ BytecodeGenerator::BytecodeGenerator(ProgramNode* programNode, const Debugger* d
emitLoad(newVars[i], jsUndefined());
} else {
for (size_t i = 0; i < functionStack.size(); ++i) {
- FuncDeclNode* funcDecl = functionStack[i];
- globalObject->putWithAttributes(exec, funcDecl->m_ident, funcDecl->makeFunction(exec, scopeChain.node()), DontDelete);
+ FunctionBodyNode* function = functionStack[i];
+ globalObject->putWithAttributes(exec, function->ident(), new (exec) JSFunction(exec, makeFunction(function), scopeChain.node()), DontDelete);
}
for (size_t i = 0; i < varStack.size(); ++i) {
- if (globalObject->hasProperty(exec, varStack[i].first))
+ if (globalObject->hasProperty(exec, *varStack[i].first))
continue;
int attributes = DontDelete;
if (varStack[i].second & DeclarationStacks::IsConstant)
attributes |= ReadOnly;
- globalObject->putWithAttributes(exec, varStack[i].first, jsUndefined(), attributes);
+ globalObject->putWithAttributes(exec, *varStack[i].first, jsUndefined(), attributes);
}
preserveLastVar();
@@ -327,7 +327,7 @@ BytecodeGenerator::BytecodeGenerator(FunctionBodyNode* functionBody, const Debug
} else
emitOpcode(op_enter);
- if (usesArguments) {
+ if (usesArguments) {
emitOpcode(op_init_arguments);
// The debugger currently retrieves the arguments object from an activation rather than pulling
@@ -339,18 +339,18 @@ BytecodeGenerator::BytecodeGenerator(FunctionBodyNode* functionBody, const Debug
const DeclarationStacks::FunctionStack& functionStack = functionBody->functionStack();
for (size_t i = 0; i < functionStack.size(); ++i) {
- FuncDeclNode* funcDecl = functionStack[i];
- const Identifier& ident = funcDecl->m_ident;
+ FunctionBodyNode* function = functionStack[i];
+ const Identifier& ident = function->ident();
m_functions.add(ident.ustring().rep());
- emitNewFunction(addVar(ident, false), funcDecl);
+ emitNewFunction(addVar(ident, false), function);
}
const DeclarationStacks::VarStack& varStack = functionBody->varStack();
for (size_t i = 0; i < varStack.size(); ++i)
- addVar(varStack[i].first, varStack[i].second & DeclarationStacks::IsConstant);
+ addVar(*varStack[i].first, varStack[i].second & DeclarationStacks::IsConstant);
- const Identifier* parameters = functionBody->parameters();
- size_t parameterCount = functionBody->parameterCount();
+ FunctionParameters& parameters = *functionBody->parameters();
+ size_t parameterCount = parameters.size();
m_nextParameterIndex = -RegisterFile::CallFrameHeaderSize - parameterCount - 1;
m_parameters.grow(1 + parameterCount); // reserve space for "this"
@@ -397,6 +397,18 @@ BytecodeGenerator::BytecodeGenerator(EvalNode* evalNode, const Debugger* debugge
codeBlock->setGlobalData(m_globalData);
m_codeBlock->m_numParameters = 1; // Allocate space for "this"
+ const DeclarationStacks::FunctionStack& functionStack = evalNode->functionStack();
+ for (size_t i = 0; i < functionStack.size(); ++i)
+ m_codeBlock->addFunctionDecl(makeFunction(functionStack[i]));
+
+ const DeclarationStacks::VarStack& varStack = evalNode->varStack();
+ unsigned numVariables = varStack.size();
+ Vector<Identifier> variables;
+ variables.reserveCapacity(numVariables);
+ for (size_t i = 0; i < numVariables; ++i)
+ variables.append(*varStack[i].first);
+ codeBlock->adoptVariables(variables);
+
preserveLastVar();
}
@@ -470,7 +482,8 @@ RegisterID* BytecodeGenerator::constRegisterFor(const Identifier& ident)
return 0;
SymbolTableEntry entry = symbolTable().get(ident.ustring().rep());
- ASSERT(!entry.isNull());
+ if (entry.isNull())
+ return 0;
return &registerFor(entry.getIndex());
}
@@ -765,18 +778,6 @@ PassRefPtr<Label> BytecodeGenerator::emitJumpIfNotFunctionApply(RegisterID* cond
return target;
}
-unsigned BytecodeGenerator::addConstant(FuncDeclNode* n)
-{
- // No need to explicitly unique function body nodes -- they're unique already.
- return m_codeBlock->addFunction(n);
-}
-
-unsigned BytecodeGenerator::addConstant(FuncExprNode* n)
-{
- // No need to explicitly unique function expression nodes -- they're unique already.
- return m_codeBlock->addFunctionExpression(n);
-}
-
unsigned BytecodeGenerator::addConstant(const Identifier& ident)
{
UString::Rep* rep = ident.ustring().rep();
@@ -861,9 +862,8 @@ RegisterID* BytecodeGenerator::emitBinaryOp(OpcodeID opcodeID, RegisterID* dst,
instructions().append(src2->index());
if (opcodeID == op_bitor || opcodeID == op_bitand || opcodeID == op_bitxor ||
- opcodeID == op_add || opcodeID == op_mul || opcodeID == op_sub) {
+ opcodeID == op_add || opcodeID == op_mul || opcodeID == op_sub || opcodeID == op_div)
instructions().append(types.toInt());
- }
return dst;
}
@@ -1183,15 +1183,6 @@ RegisterID* BytecodeGenerator::emitResolveWithBase(RegisterID* baseDst, Register
return baseDst;
}
-RegisterID* BytecodeGenerator::emitResolveFunction(RegisterID* baseDst, RegisterID* funcDst, const Identifier& property)
-{
- emitOpcode(op_resolve_func);
- instructions().append(baseDst->index());
- instructions().append(funcDst->index());
- instructions().append(addConstant(property));
- return baseDst;
-}
-
void BytecodeGenerator::emitMethodCheck()
{
emitOpcode(op_method_check);
@@ -1200,7 +1191,7 @@ void BytecodeGenerator::emitMethodCheck()
RegisterID* BytecodeGenerator::emitGetById(RegisterID* dst, RegisterID* base, const Identifier& property)
{
#if ENABLE(JIT)
- m_codeBlock->addStructureStubInfo(StructureStubInfo(op_get_by_id));
+ m_codeBlock->addStructureStubInfo(StructureStubInfo(access_get_by_id));
#else
m_codeBlock->addPropertyAccessInstruction(instructions().size());
#endif
@@ -1219,7 +1210,7 @@ RegisterID* BytecodeGenerator::emitGetById(RegisterID* dst, RegisterID* base, co
RegisterID* BytecodeGenerator::emitPutById(RegisterID* base, const Identifier& property, RegisterID* value)
{
#if ENABLE(JIT)
- m_codeBlock->addStructureStubInfo(StructureStubInfo(op_put_by_id));
+ m_codeBlock->addStructureStubInfo(StructureStubInfo(access_put_by_id));
#else
m_codeBlock->addPropertyAccessInstruction(instructions().size());
#endif
@@ -1323,11 +1314,13 @@ RegisterID* BytecodeGenerator::emitNewArray(RegisterID* dst, ElementNode* elemen
return dst;
}
-RegisterID* BytecodeGenerator::emitNewFunction(RegisterID* dst, FuncDeclNode* n)
+RegisterID* BytecodeGenerator::emitNewFunction(RegisterID* dst, FunctionBodyNode* function)
{
+ unsigned index = m_codeBlock->addFunctionDecl(makeFunction(function));
+
emitOpcode(op_new_func);
instructions().append(dst->index());
- instructions().append(addConstant(n));
+ instructions().append(index);
return dst;
}
@@ -1342,9 +1335,12 @@ RegisterID* BytecodeGenerator::emitNewRegExp(RegisterID* dst, RegExp* regExp)
RegisterID* BytecodeGenerator::emitNewFunctionExpression(RegisterID* r0, FuncExprNode* n)
{
+ FunctionBodyNode* function = n->body();
+ unsigned index = m_codeBlock->addFunctionExpr(makeFunction(function));
+
emitOpcode(op_new_func_exp);
instructions().append(r0->index());
- instructions().append(addConstant(n));
+ instructions().append(index);
return r0;
}
@@ -1806,6 +1802,7 @@ PassRefPtr<Label> BytecodeGenerator::emitJumpSubroutine(RegisterID* retAddrDst,
emitOpcode(op_jsr);
instructions().append(retAddrDst->index());
instructions().append(finally->offsetFrom(instructions().size()));
+ emitLabel(newLabel().get()); // Record the fact that the next instruction is implicitly labeled, because op_sret will return to it.
return finally;
}
@@ -1815,7 +1812,7 @@ void BytecodeGenerator::emitSubroutineReturn(RegisterID* retAddrSrc)
instructions().append(retAddrSrc->index());
}
-void BytecodeGenerator::emitPushNewScope(RegisterID* dst, Identifier& property, RegisterID* value)
+void BytecodeGenerator::emitPushNewScope(RegisterID* dst, const Identifier& property, RegisterID* value)
{
ControlFlowContext context;
context.isFinallyBlock = false;
@@ -1859,7 +1856,6 @@ static int32_t keyForImmediateSwitch(ExpressionNode* node, int32_t min, int32_t
ASSERT(node->isNumber());
double value = static_cast<NumberNode*>(node)->value();
int32_t key = static_cast<int32_t>(value);
- ASSERT(JSValue::makeInt32Fast(key) && (JSValue::makeInt32Fast(key).getInt32Fast() == value));
ASSERT(key == value);
ASSERT(key >= min);
ASSERT(key <= max);