Source/JavaScriptCore: Changed JSC to always record line number information so that error.stack
and window.onerror() can report proper line numbers.
https://bugs.webkit.org/show_bug.cgi?id=89410
Patch by Mark Lam <mark.lam@apple.com> on 2012-06-18
Reviewed by Geoffrey Garen.
* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::CodeBlock):
(JSC::CodeBlock::lineNumberForBytecodeOffset):
(JSC::CodeBlock::shrinkToFit): m_lineInfo is now available unconditionally.
* bytecode/CodeBlock.h:
(JSC::CodeBlock::addLineInfo):
(JSC::CodeBlock::hasLineInfo): Unused. Now removed.
(JSC::CodeBlock::needsCallReturnIndices):
(CodeBlock):
(RareData): Hoisted m_lineInfo out of m_rareData. m_lineInfo is now
filled in unconditionally.
* bytecompiler/BytecodeGenerator.h:
(JSC::BytecodeGenerator::addLineInfo):
LayoutTests: Ensure that error.stack and window.onerror always have the appropriate
line numbers of the exception being thrown.
https://bugs.webkit.org/show_bug.cgi?id=89410
Patch by Mark Lam <mark.lam@apple.com> on 2012-06-18
Reviewed by Geoffrey Garen.
* fast/js/exception-line-number-expected.txt: Added.
* fast/js/exception-line-number.html: Added.
* fast/js/script-tests/exception-line-number.js: Added.
(foo):
(window.onerror):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@120676 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog
index bf9d357..5afd9a0 100644
--- a/Source/JavaScriptCore/ChangeLog
+++ b/Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,27 @@
+2012-06-18 Mark Lam <mark.lam@apple.com>
+
+ Changed JSC to always record line number information so that error.stack
+ and window.onerror() can report proper line numbers.
+ https://bugs.webkit.org/show_bug.cgi?id=89410
+
+ Reviewed by Geoffrey Garen.
+
+ * bytecode/CodeBlock.cpp:
+ (JSC::CodeBlock::CodeBlock):
+ (JSC::CodeBlock::lineNumberForBytecodeOffset):
+ (JSC::CodeBlock::shrinkToFit): m_lineInfo is now available unconditionally.
+
+ * bytecode/CodeBlock.h:
+ (JSC::CodeBlock::addLineInfo):
+ (JSC::CodeBlock::hasLineInfo): Unused. Now removed.
+ (JSC::CodeBlock::needsCallReturnIndices):
+ (CodeBlock):
+ (RareData): Hoisted m_lineInfo out of m_rareData. m_lineInfo is now
+ filled in unconditionally.
+
+ * bytecompiler/BytecodeGenerator.h:
+ (JSC::BytecodeGenerator::addLineInfo):
+
2012-06-18 Andy Estes <aestes@apple.com>
Fix r120663, which didn't land the change that was reviewed.
diff --git a/Source/JavaScriptCore/bytecode/CodeBlock.cpp b/Source/JavaScriptCore/bytecode/CodeBlock.cpp
index 5f4006c..60596d1 100644
--- a/Source/JavaScriptCore/bytecode/CodeBlock.cpp
+++ b/Source/JavaScriptCore/bytecode/CodeBlock.cpp
@@ -1600,6 +1600,7 @@
, m_forcedOSRExitCounter(0)
, m_optimizationDelayCounter(0)
, m_reoptimizationRetryCounter(0)
+ , m_lineInfo(other.m_lineInfo)
#if ENABLE(JIT)
, m_canCompileWithDFGState(DFG::CapabilityLevelNotSet)
#endif
@@ -1607,7 +1608,7 @@
setNumParameters(other.numParameters());
optimizeAfterWarmUp();
jitAfterWarmUp();
-
+
if (other.m_rareData) {
createRareDataIfNecessary();
@@ -1618,7 +1619,6 @@
m_rareData->m_characterSwitchJumpTables = other.m_rareData->m_characterSwitchJumpTables;
m_rareData->m_stringSwitchJumpTables = other.m_rareData->m_stringSwitchJumpTables;
m_rareData->m_expressionInfo = other.m_rareData->m_expressionInfo;
- m_rareData->m_lineInfo = other.m_rareData->m_lineInfo;
}
}
@@ -2163,10 +2163,7 @@
{
ASSERT(bytecodeOffset < instructions().size());
- if (!m_rareData)
- return m_ownerExecutable->source().firstLine();
-
- Vector<LineInfo>& lineInfo = m_rareData->m_lineInfo;
+ Vector<LineInfo>& lineInfo = m_lineInfo;
int low = 0;
int high = lineInfo.size();
@@ -2291,6 +2288,7 @@
m_constantRegisters.shrinkToFit();
} // else don't shrink these, because we would have already pointed pointers into these tables.
+ m_lineInfo.shrinkToFit();
if (m_rareData) {
m_rareData->m_exceptionHandlers.shrinkToFit();
m_rareData->m_regexps.shrinkToFit();
@@ -2298,7 +2296,6 @@
m_rareData->m_characterSwitchJumpTables.shrinkToFit();
m_rareData->m_stringSwitchJumpTables.shrinkToFit();
m_rareData->m_expressionInfo.shrinkToFit();
- m_rareData->m_lineInfo.shrinkToFit();
#if ENABLE(JIT)
m_rareData->m_callReturnIndexVector.shrinkToFit();
#endif
diff --git a/Source/JavaScriptCore/bytecode/CodeBlock.h b/Source/JavaScriptCore/bytecode/CodeBlock.h
index aa724fc..67b377e 100644
--- a/Source/JavaScriptCore/bytecode/CodeBlock.h
+++ b/Source/JavaScriptCore/bytecode/CodeBlock.h
@@ -711,8 +711,7 @@
void addLineInfo(unsigned bytecodeOffset, int lineNo)
{
- createRareDataIfNecessary();
- Vector<LineInfo>& lineInfo = m_rareData->m_lineInfo;
+ Vector<LineInfo>& lineInfo = m_lineInfo;
if (!lineInfo.size() || lineInfo.last().lineNumber != lineNo) {
LineInfo info = { bytecodeOffset, lineNo };
lineInfo.append(info);
@@ -720,13 +719,12 @@
}
bool hasExpressionInfo() { return m_rareData && m_rareData->m_expressionInfo.size(); }
- bool hasLineInfo() { return m_rareData && m_rareData->m_lineInfo.size(); }
// We only generate exception handling info if the user is debugging
// (and may want line number info), or if the function contains exception handler.
bool needsCallReturnIndices()
{
- return m_rareData &&
- (m_rareData->m_expressionInfo.size() || m_rareData->m_lineInfo.size() || m_rareData->m_exceptionHandlers.size());
+ return true || (m_rareData
+ && (m_rareData->m_expressionInfo.size() || m_rareData->m_exceptionHandlers.size()));
}
#if ENABLE(JIT)
@@ -1311,7 +1309,9 @@
uint32_t m_forcedOSRExitCounter;
uint16_t m_optimizationDelayCounter;
uint16_t m_reoptimizationRetryCounter;
-
+
+ Vector<LineInfo> m_lineInfo;
+
struct RareData {
WTF_MAKE_FAST_ALLOCATED;
public:
@@ -1333,7 +1333,6 @@
// Expression info - present if debugging.
Vector<ExpressionRangeInfo> m_expressionInfo;
// Line info - present if profiling or debugging.
- Vector<LineInfo> m_lineInfo;
#if ENABLE(JIT)
Vector<CallReturnOffsetToBytecodeOffset> m_callReturnIndexVector;
#endif
diff --git a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h b/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
index 8c3fc7b..8b1d1d7 100644
--- a/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
+++ b/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
@@ -616,10 +616,7 @@
void addLineInfo(unsigned lineNo)
{
-#if !ENABLE(OPCODE_SAMPLING)
- if (m_shouldEmitRichSourceInfo)
-#endif
- m_codeBlock->addLineInfo(instructions().size(), lineNo);
+ m_codeBlock->addLineInfo(instructions().size(), lineNo);
}
RegisterID* emitInitLazyRegister(RegisterID*);