- Revision
- 120676
- Author
- [email protected]
- Date
- 2012-06-18 23:07:28 -0700 (Mon, 18 Jun 2012)
Log Message
Source/_javascript_Core: 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 <[email protected]> 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 <[email protected]> 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):
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (120675 => 120676)
--- trunk/LayoutTests/ChangeLog 2012-06-19 05:47:57 UTC (rev 120675)
+++ trunk/LayoutTests/ChangeLog 2012-06-19 06:07:28 UTC (rev 120676)
@@ -1,3 +1,17 @@
+2012-06-18 Mark Lam <[email protected]>
+
+ 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
+
+ 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):
+
2012-06-18 Kinuko Yasuda <[email protected]>
Unreviewed test fix (one more) for r120667: skip '.svn' directory from the test results.
Added: trunk/LayoutTests/fast/js/exception-line-number-expected.txt (0 => 120676)
--- trunk/LayoutTests/fast/js/exception-line-number-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/js/exception-line-number-expected.txt 2012-06-19 06:07:28 UTC (rev 120676)
@@ -0,0 +1,11 @@
+This test makes sure the exception stack has line number information.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS result is "LayoutTests/fast/js/script-tests/exception-line-number.js:6,LayoutTests/fast/js/script-tests/exception-line-number.js:11"
+PASS result is "LayoutTests/fast/js/script-tests/exception-line-number.js:36"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/js/exception-line-number.html (0 => 120676)
--- trunk/LayoutTests/fast/js/exception-line-number.html (rev 0)
+++ trunk/LayoutTests/fast/js/exception-line-number.html 2012-06-19 06:07:28 UTC (rev 120676)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/fast/js/script-tests/exception-line-number.js (0 => 120676)
--- trunk/LayoutTests/fast/js/script-tests/exception-line-number.js (rev 0)
+++ trunk/LayoutTests/fast/js/script-tests/exception-line-number.js 2012-06-19 06:07:28 UTC (rev 120676)
@@ -0,0 +1,36 @@
+description('This test makes sure the exception stack has line number information.');
+
+// Test error.stack:
+function foo() { // line 4
+ try {
+ doError(); // line 6
+ } catch(err) {
+ temp = err.stack;
+ }
+}
+foo(); // line 11
+
+// The stack trace contains the full path to the file. We need to trim it to
+// only the part below LayoutTest so that the test results are consistent
+// regardless of which server it is served from.
+//
+// String.match() generates an array of matches. We'll just convert all the
+// elements back into a comma separated string by simply stringifying the
+// array. This makes it easier to compare the resultant stack trace info.
+
+result = String(temp.match(/LayoutTests\/[^:]+\:[0-9]+/g));
+
+shouldBe("result", '"LayoutTests/fast/js/script-tests/exception-line-number.js:6,LayoutTests/fast/js/script-tests/exception-line-number.js:11"');
+
+
+// Test window.onerror:
+
+window._onerror_ = function(msg, url, line) {
+ url = ""
+ result = url + ':' + line;
+ shouldBe("result", '"LayoutTests/fast/js/script-tests/exception-line-number.js:36"');
+ return true; // We handled it.
+}
+
+this.err = Error(12, "line number test");
+throw this.err; // Line 36.
Modified: trunk/Source/_javascript_Core/ChangeLog (120675 => 120676)
--- trunk/Source/_javascript_Core/ChangeLog 2012-06-19 05:47:57 UTC (rev 120675)
+++ trunk/Source/_javascript_Core/ChangeLog 2012-06-19 06:07:28 UTC (rev 120676)
@@ -1,3 +1,27 @@
+2012-06-18 Mark Lam <[email protected]>
+
+ 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 <[email protected]>
Fix r120663, which didn't land the change that was reviewed.
Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp (120675 => 120676)
--- trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp 2012-06-19 05:47:57 UTC (rev 120675)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp 2012-06-19 06:07:28 UTC (rev 120676)
@@ -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,11 +2163,8 @@
{
ASSERT(bytecodeOffset < instructions().size());
- if (!m_rareData)
- return m_ownerExecutable->source().firstLine();
+ Vector<LineInfo>& lineInfo = m_lineInfo;
- Vector<LineInfo>& lineInfo = m_rareData->m_lineInfo;
-
int low = 0;
int high = lineInfo.size();
while (low < high) {
@@ -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
Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.h (120675 => 120676)
--- trunk/Source/_javascript_Core/bytecode/CodeBlock.h 2012-06-19 05:47:57 UTC (rev 120675)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.h 2012-06-19 06:07:28 UTC (rev 120676)
@@ -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
Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h (120675 => 120676)
--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h 2012-06-19 05:47:57 UTC (rev 120675)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h 2012-06-19 06:07:28 UTC (rev 120676)
@@ -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*);