|
Lines 522-529
BytecodeGenerator::BytecodeGenerator(VM& vm, FunctionNode* functionNode, Unlinke
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec1
|
| 522 |
instructions().append(0); |
522 |
instructions().append(0); |
| 523 |
} |
523 |
} |
| 524 |
|
524 |
|
| 525 |
if (m_lexicalEnvironmentRegister) |
|
|
| 526 |
pushScopedControlFlowContext(); |
| 527 |
m_symbolTableStack.append(SymbolTableStackEntry{ Strong<SymbolTable>(*m_vm, m_symbolTable), m_lexicalEnvironmentRegister, false, symbolTableConstantIndex }); |
525 |
m_symbolTableStack.append(SymbolTableStackEntry{ Strong<SymbolTable>(*m_vm, m_symbolTable), m_lexicalEnvironmentRegister, false, symbolTableConstantIndex }); |
| 528 |
m_TDZStack.append(std::make_pair(*parentScopeTDZVariables, false)); |
526 |
m_TDZStack.append(std::make_pair(*parentScopeTDZVariables, false)); |
| 529 |
} |
527 |
} |
|
Lines 629-635
LabelScopePtr BytecodeGenerator::newLabelScope(LabelScope::Type type, const Iden
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec2
|
| 629 |
m_labelScopes.removeLast(); |
627 |
m_labelScopes.removeLast(); |
| 630 |
|
628 |
|
| 631 |
// Allocate new label scope. |
629 |
// Allocate new label scope. |
| 632 |
LabelScope scope(type, name, labelScopeDepth(), newLabel(), type == LabelScope::Loop ? newLabel() : PassRefPtr<Label>()); // Only loops have continue targets. |
630 |
LabelScope scope(type, name, scopeDepth(), newLabel(), type == LabelScope::Loop ? newLabel() : PassRefPtr<Label>()); // Only loops have continue targets. |
| 633 |
m_labelScopes.append(scope); |
631 |
m_labelScopes.append(scope); |
| 634 |
return LabelScopePtr(m_labelScopes, m_labelScopes.size() - 1); |
632 |
return LabelScopePtr(m_labelScopes, m_labelScopes.size() - 1); |
| 635 |
} |
633 |
} |
|
Lines 1212-1218
void BytecodeGenerator::emitProfileType(RegisterID* registerToProfile, ProfileTy
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec3
|
| 1212 |
// The format of this instruction is: op_profile_type regToProfile, TypeLocation*, flag, identifier?, resolveType? |
1210 |
// The format of this instruction is: op_profile_type regToProfile, TypeLocation*, flag, identifier?, resolveType? |
| 1213 |
emitOpcode(op_profile_type); |
1211 |
emitOpcode(op_profile_type); |
| 1214 |
instructions().append(registerToProfile->index()); |
1212 |
instructions().append(registerToProfile->index()); |
| 1215 |
instructions().append(localScopeDepth()); |
1213 |
instructions().append(currentScopeDepth()); |
| 1216 |
instructions().append(flag); |
1214 |
instructions().append(flag); |
| 1217 |
instructions().append(identifier ? addConstant(*identifier) : 0); |
1215 |
instructions().append(identifier ? addConstant(*identifier) : 0); |
| 1218 |
instructions().append(resolveType()); |
1216 |
instructions().append(resolveType()); |
|
Lines 1320-1327
void BytecodeGenerator::pushLexicalScope(VariableEnvironmentNode* node, bool can
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec4
|
| 1320 |
instructions().append(addConstantValue(jsTDZValue())->index()); |
1318 |
instructions().append(addConstantValue(jsTDZValue())->index()); |
| 1321 |
|
1319 |
|
| 1322 |
emitMove(scopeRegister(), newScope); |
1320 |
emitMove(scopeRegister(), newScope); |
| 1323 |
|
|
|
| 1324 |
pushScopedControlFlowContext(); |
| 1325 |
} |
1321 |
} |
| 1326 |
|
1322 |
|
| 1327 |
m_symbolTableStack.append(SymbolTableStackEntry{ symbolTable, newScope, false, symbolTableConstantIndex }); |
1323 |
m_symbolTableStack.append(SymbolTableStackEntry{ symbolTable, newScope, false, symbolTableConstantIndex }); |
|
Lines 1369-1376
void BytecodeGenerator::popLexicalScope(VariableEnvironmentNode* node)
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec5
|
| 1369 |
|
1365 |
|
| 1370 |
if (hasCapturedVariables) { |
1366 |
if (hasCapturedVariables) { |
| 1371 |
RELEASE_ASSERT(stackEntry.m_scope); |
1367 |
RELEASE_ASSERT(stackEntry.m_scope); |
| 1372 |
emitPopScope(scopeRegister(), stackEntry.m_scope); |
1368 |
RefPtr<RegisterID> parentScope = emitGetParentScope(newTemporary(), scopeRegister()); |
| 1373 |
popScopedControlFlowContext(); |
1369 |
emitMove(scopeRegister(), parentScope.get()); |
| 1374 |
stackEntry.m_scope->deref(); |
1370 |
stackEntry.m_scope->deref(); |
| 1375 |
} |
1371 |
} |
| 1376 |
|
1372 |
|
|
Lines 1427-1433
void BytecodeGenerator::prepareLexicalScopeForNextForLoopIteration(VariableEnvir
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec6
|
| 1427 |
// as the previous scope because the loop body is compiled under |
1423 |
// as the previous scope because the loop body is compiled under |
| 1428 |
// the assumption that the scope's register index is constant even |
1424 |
// the assumption that the scope's register index is constant even |
| 1429 |
// though the value in that register will change on each loop iteration. |
1425 |
// though the value in that register will change on each loop iteration. |
| 1430 |
RefPtr<RegisterID> parentScope = emitGetParentScope(newTemporary(), loopScope); |
1426 |
RefPtr<RegisterID> parentScope = emitGetParentScope(newTemporary(), scopeRegister()); |
| 1431 |
emitMove(scopeRegister(), parentScope.get()); |
1427 |
emitMove(scopeRegister(), parentScope.get()); |
| 1432 |
|
1428 |
|
| 1433 |
emitOpcode(op_create_lexical_environment); |
1429 |
emitOpcode(op_create_lexical_environment); |
|
Lines 1576-1586
void BytecodeGenerator::emitCheckHasInstance(RegisterID* dst, RegisterID* value,
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec7
|
| 1576 |
// will start with this ResolveType and compute the least upper bound including intercepting scopes. |
1572 |
// will start with this ResolveType and compute the least upper bound including intercepting scopes. |
| 1577 |
ResolveType BytecodeGenerator::resolveType() |
1573 |
ResolveType BytecodeGenerator::resolveType() |
| 1578 |
{ |
1574 |
{ |
| 1579 |
for (unsigned i = m_symbolTableStack.size(); i--; ) { |
1575 |
if (m_localScopeDepth) |
| 1580 |
if (m_symbolTableStack[i].m_isWithOrCatch) |
1576 |
return Dynamic; |
| 1581 |
return Dynamic; |
|
|
| 1582 |
} |
| 1583 |
|
| 1584 |
if (m_symbolTable && m_symbolTable->usesNonStrictEval()) |
1577 |
if (m_symbolTable && m_symbolTable->usesNonStrictEval()) |
| 1585 |
return GlobalPropertyWithVarInjectionChecks; |
1578 |
return GlobalPropertyWithVarInjectionChecks; |
| 1586 |
return GlobalProperty; |
1579 |
return GlobalProperty; |
|
Lines 1639-1645
RegisterID* BytecodeGenerator::emitResolveScope(RegisterID* dst, const Variable&
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec8
|
| 1639 |
instructions().append(scopeRegister()->index()); |
1632 |
instructions().append(scopeRegister()->index()); |
| 1640 |
instructions().append(addConstant(variable.ident())); |
1633 |
instructions().append(addConstant(variable.ident())); |
| 1641 |
instructions().append(resolveType()); |
1634 |
instructions().append(resolveType()); |
| 1642 |
instructions().append(localScopeDepth()); |
1635 |
instructions().append(currentScopeDepth()); |
| 1643 |
instructions().append(0); |
1636 |
instructions().append(0); |
| 1644 |
return dst; |
1637 |
return dst; |
| 1645 |
} |
1638 |
} |
|
Lines 1673-1679
RegisterID* BytecodeGenerator::emitGetFromScope(RegisterID* dst, RegisterID* sco
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec9
|
| 1673 |
instructions().append(scope->index()); |
1666 |
instructions().append(scope->index()); |
| 1674 |
instructions().append(addConstant(variable.ident())); |
1667 |
instructions().append(addConstant(variable.ident())); |
| 1675 |
instructions().append(ResolveModeAndType(resolveMode, variable.offset().isScope() ? LocalClosureVar : resolveType()).operand()); |
1668 |
instructions().append(ResolveModeAndType(resolveMode, variable.offset().isScope() ? LocalClosureVar : resolveType()).operand()); |
| 1676 |
instructions().append(localScopeDepth()); |
1669 |
instructions().append(currentScopeDepth()); |
| 1677 |
instructions().append(variable.offset().isScope() ? variable.offset().scopeOffset().offset() : 0); |
1670 |
instructions().append(variable.offset().isScope() ? variable.offset().scopeOffset().offset() : 0); |
| 1678 |
instructions().append(profile); |
1671 |
instructions().append(profile); |
| 1679 |
return dst; |
1672 |
return dst; |
|
Lines 1713-1719
RegisterID* BytecodeGenerator::emitPutToScope(RegisterID* scope, const Variable&
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec10
|
| 1713 |
} else { |
1706 |
} else { |
| 1714 |
ASSERT(resolveType() != LocalClosureVar); |
1707 |
ASSERT(resolveType() != LocalClosureVar); |
| 1715 |
instructions().append(ResolveModeAndType(resolveMode, resolveType()).operand()); |
1708 |
instructions().append(ResolveModeAndType(resolveMode, resolveType()).operand()); |
| 1716 |
instructions().append(localScopeDepth()); |
1709 |
instructions().append(currentScopeDepth()); |
| 1717 |
} |
1710 |
} |
| 1718 |
instructions().append(!!offset ? offset.offset() : 0); |
1711 |
instructions().append(!!offset ? offset.offset() : 0); |
| 1719 |
return value; |
1712 |
return value; |
|
Lines 2481-2487
void BytecodeGenerator::emitGetScope()
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec11
|
| 2481 |
|
2474 |
|
| 2482 |
RegisterID* BytecodeGenerator::emitPushWithScope(RegisterID* dst, RegisterID* scope) |
2475 |
RegisterID* BytecodeGenerator::emitPushWithScope(RegisterID* dst, RegisterID* scope) |
| 2483 |
{ |
2476 |
{ |
| 2484 |
pushScopedControlFlowContext(); |
2477 |
ControlFlowContext context; |
|
|
2478 |
context.isFinallyBlock = false; |
| 2479 |
m_scopeContextStack.append(context); |
| 2480 |
m_localScopeDepth++; |
| 2485 |
|
2481 |
|
| 2486 |
RegisterID* result = emitUnaryOp(op_push_with_scope, dst, scope); |
2482 |
RegisterID* result = emitUnaryOp(op_push_with_scope, dst, scope); |
| 2487 |
m_symbolTableStack.append(SymbolTableStackEntry{ Strong<SymbolTable>(), nullptr, true, 0 }); |
2483 |
m_symbolTableStack.append(SymbolTableStackEntry{ Strong<SymbolTable>(), nullptr, true, 0 }); |
|
Lines 2496-2511
RegisterID* BytecodeGenerator::emitGetParentScope(RegisterID* dst, RegisterID* s
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec12
|
| 2496 |
return dst; |
2492 |
return dst; |
| 2497 |
} |
2493 |
} |
| 2498 |
|
2494 |
|
| 2499 |
void BytecodeGenerator::emitPopScope(RegisterID* dst, RegisterID* scope) |
2495 |
void BytecodeGenerator::emitPopScope(RegisterID* srcDst) |
| 2500 |
{ |
2496 |
{ |
| 2501 |
RefPtr<RegisterID> parentScope = emitGetParentScope(newTemporary(), scope); |
2497 |
ASSERT(m_scopeContextStack.size()); |
| 2502 |
emitMove(dst, parentScope.get()); |
2498 |
ASSERT(!m_scopeContextStack.last().isFinallyBlock); |
| 2503 |
} |
|
|
| 2504 |
|
2499 |
|
| 2505 |
void BytecodeGenerator::emitPopWithOrCatchScope(RegisterID* srcDst) |
2500 |
RefPtr<RegisterID> parentScope = emitGetParentScope(newTemporary(), srcDst); |
| 2506 |
{ |
2501 |
emitMove(srcDst, parentScope.get()); |
| 2507 |
emitPopScope(srcDst, srcDst); |
2502 |
|
| 2508 |
popScopedControlFlowContext(); |
2503 |
m_scopeContextStack.removeLast(); |
|
|
2504 |
m_localScopeDepth--; |
| 2509 |
SymbolTableStackEntry stackEntry = m_symbolTableStack.takeLast(); |
2505 |
SymbolTableStackEntry stackEntry = m_symbolTableStack.takeLast(); |
| 2510 |
RELEASE_ASSERT(stackEntry.m_isWithOrCatch); |
2506 |
RELEASE_ASSERT(stackEntry.m_isWithOrCatch); |
| 2511 |
} |
2507 |
} |
|
Lines 2819-2827
void BytecodeGenerator::emitComplexPopScopes(RegisterID* scope, ControlFlowConte
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec13
|
| 2819 |
|
2815 |
|
| 2820 |
void BytecodeGenerator::emitPopScopes(RegisterID* scope, int targetScopeDepth) |
2816 |
void BytecodeGenerator::emitPopScopes(RegisterID* scope, int targetScopeDepth) |
| 2821 |
{ |
2817 |
{ |
| 2822 |
ASSERT(labelScopeDepth() - targetScopeDepth >= 0); |
2818 |
ASSERT(scopeDepth() - targetScopeDepth >= 0); |
| 2823 |
|
2819 |
|
| 2824 |
size_t scopeDelta = labelScopeDepth() - targetScopeDepth; |
2820 |
size_t scopeDelta = scopeDepth() - targetScopeDepth; |
| 2825 |
ASSERT(scopeDelta <= m_scopeContextStack.size()); |
2821 |
ASSERT(scopeDelta <= m_scopeContextStack.size()); |
| 2826 |
if (!scopeDelta) |
2822 |
if (!scopeDelta) |
| 2827 |
return; |
2823 |
return; |
|
Lines 2880-2889
void BytecodeGenerator::popTryAndEmitCatch(TryData* tryData, RegisterID* excepti
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec14
|
| 2880 |
|
2876 |
|
| 2881 |
int BytecodeGenerator::calculateTargetScopeDepthForExceptionHandler() const |
2877 |
int BytecodeGenerator::calculateTargetScopeDepthForExceptionHandler() const |
| 2882 |
{ |
2878 |
{ |
| 2883 |
int depth = localScopeDepth(); |
2879 |
int depth = m_localScopeDepth; |
|
|
2880 |
|
| 2881 |
for (unsigned i = m_symbolTableStack.size(); i--; ) { |
| 2882 |
RegisterID* scope = m_symbolTableStack[i].m_scope; |
| 2883 |
if (scope) |
| 2884 |
depth++; |
| 2885 |
} |
| 2884 |
|
2886 |
|
| 2885 |
// Currently, we're maintaing compatibility with how things are done and letting the exception handling |
2887 |
// Currently, we're maintaing compatibility with how things are done and letting the exception handling |
| 2886 |
// code take into consideration the base activation of the function. There is no reason we shouldn't |
2888 |
// code take into consideration the base activation of the function. There is no reason we shouldn't |
| 2887 |
// be able to calculate the exact depth here and let the exception handler not worry if there is a base |
2889 |
// be able to calculate the exact depth here and let the exception handler not worry if there is a base |
| 2888 |
// activation or not. |
2890 |
// activation or not. |
| 2889 |
if (m_lexicalEnvironmentRegister) |
2891 |
if (m_lexicalEnvironmentRegister) |
|
Lines 2893-2906
int BytecodeGenerator::calculateTargetScopeDepthForExceptionHandler() const
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec15
|
| 2893 |
return depth; |
2895 |
return depth; |
| 2894 |
} |
2896 |
} |
| 2895 |
|
2897 |
|
| 2896 |
int BytecodeGenerator::localScopeDepth() const |
2898 |
int BytecodeGenerator::currentScopeDepth() const |
| 2897 |
{ |
2899 |
{ |
| 2898 |
return m_localScopeDepth; |
2900 |
// This is the current number of JSScope descendents that would be allocated |
| 2899 |
} |
2901 |
// in this function/program if this code were running. |
| 2900 |
|
2902 |
int depth = 0; |
| 2901 |
int BytecodeGenerator::labelScopeDepth() const |
2903 |
for (unsigned i = m_symbolTableStack.size(); i--; ) { |
| 2902 |
{ |
2904 |
if (m_symbolTableStack[i].m_scope || m_symbolTableStack[i].m_isWithOrCatch) |
| 2903 |
return localScopeDepth() + m_finallyDepth; |
2905 |
depth++; |
|
|
2906 |
} |
| 2907 |
return depth; |
| 2904 |
} |
2908 |
} |
| 2905 |
|
2909 |
|
| 2906 |
void BytecodeGenerator::emitThrowReferenceError(const String& message) |
2910 |
void BytecodeGenerator::emitThrowReferenceError(const String& message) |
|
Lines 2926-2950
void BytecodeGenerator::emitPushFunctionNameScope(RegisterID* dst, const Identif
a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp_sec16
|
| 2926 |
instructions().append(JSNameScope::FunctionNameScope); |
2930 |
instructions().append(JSNameScope::FunctionNameScope); |
| 2927 |
} |
2931 |
} |
| 2928 |
|
2932 |
|
| 2929 |
void BytecodeGenerator::pushScopedControlFlowContext() |
2933 |
void BytecodeGenerator::emitPushCatchScope(RegisterID* dst, const Identifier& property, RegisterID* value, unsigned attributes) |
| 2930 |
{ |
2934 |
{ |
| 2931 |
ControlFlowContext context; |
2935 |
ControlFlowContext context; |
| 2932 |
context.isFinallyBlock = false; |
2936 |
context.isFinallyBlock = false; |
| 2933 |
m_scopeContextStack.append(context); |
2937 |
m_scopeContextStack.append(context); |
| 2934 |
m_localScopeDepth++; |
2938 |
m_localScopeDepth++; |
| 2935 |
} |
|
|
| 2936 |
|
| 2937 |
void BytecodeGenerator::popScopedControlFlowContext() |
| 2938 |
{ |
| 2939 |
ASSERT(m_scopeContextStack.size()); |
| 2940 |
ASSERT(!m_scopeContextStack.last().isFinallyBlock); |
| 2941 |
m_scopeContextStack.removeLast(); |
| 2942 |
m_localScopeDepth--; |
| 2943 |
} |
| 2944 |
|
| 2945 |
void BytecodeGenerator::emitPushCatchScope(RegisterID* dst, const Identifier& property, RegisterID* value, unsigned attributes) |
| 2946 |
{ |
| 2947 |
pushScopedControlFlowContext(); |
| 2948 |
|
2939 |
|
| 2949 |
emitOpcode(op_push_name_scope); |
2940 |
emitOpcode(op_push_name_scope); |
| 2950 |
instructions().append(dst->index()); |
2941 |
instructions().append(dst->index()); |