Skip to content

Commit 10dd9ce

Browse files
mstarzingerCommit bot
authored andcommitted
Make compilers agree on source position of thrown errors.
This makes the compilers agree on the source position of a message generated by "throw new Error()", it points to the beginning of the throw directive. R=titzer@chromium.org TEST=message/regress/regress-3995 BUG=v8:3995 LOG=N Review URL: https://codereview.chromium.org/1049703002 Cr-Commit-Position: refs/heads/master@{#27775}
1 parent e21f9ab commit 10dd9ce

7 files changed

Lines changed: 31 additions & 21 deletions

File tree

src/assembler.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,19 +1615,20 @@ bool PositionsRecorder::WriteRecordedPositions() {
16151615
EnsureSpace ensure_space(assembler_);
16161616
assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION,
16171617
state_.current_statement_position);
1618-
state_.written_statement_position = state_.current_statement_position;
16191618
written = true;
16201619
}
1620+
state_.written_statement_position = state_.current_statement_position;
16211621

16221622
// Write the position if it is different from what was written last time and
1623-
// also different from the written statement position.
1623+
// also different from the statement position that was just written.
16241624
if (state_.current_position != state_.written_position &&
1625-
state_.current_position != state_.written_statement_position) {
1625+
(state_.current_position != state_.written_statement_position ||
1626+
!written)) {
16261627
EnsureSpace ensure_space(assembler_);
16271628
assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position);
1628-
state_.written_position = state_.current_position;
16291629
written = true;
16301630
}
1631+
state_.written_position = state_.current_position;
16311632

16321633
// Return whether something was written.
16331634
return written;

src/full-codegen.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,7 @@ void FullCodeGenerator::VisitNativeFunctionLiteral(
16391639
void FullCodeGenerator::VisitThrow(Throw* expr) {
16401640
Comment cmnt(masm_, "[ Throw");
16411641
VisitForStackValue(expr->exception());
1642+
SetSourcePosition(expr->position());
16421643
__ CallRuntime(Runtime::kThrow, 1);
16431644
// Never returns here.
16441645
}

src/prettyprinter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void CallPrinter::VisitCall(Call* node) {
325325

326326

327327
void CallPrinter::VisitCallNew(CallNew* node) {
328-
bool was_found = !found_ && node->expression()->position() == position_;
328+
bool was_found = !found_ && node->position() == position_;
329329
if (was_found) found_ = true;
330330
Find(node->expression(), was_found);
331331
FindArguments(node->arguments());

test/cctest/test-api.cc

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5312,8 +5312,7 @@ void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) {
53125312
CHECK_EQ(0,
53135313
strcmp(*v8::String::Utf8Value(message->Get()), "Uncaught Error: a"));
53145314
CHECK_EQ(1, message->GetLineNumber());
5315-
// TODO(3995): Our compilers disagree about the position.
5316-
if (!i::FLAG_always_opt) CHECK_EQ(6, message->GetStartColumn());
5315+
CHECK_EQ(0, message->GetStartColumn());
53175316
}
53185317

53195318

@@ -9795,11 +9794,7 @@ THREADED_TEST(ConstructorForObject) {
97959794
value = CompileRun("new obj2(28)");
97969795
CHECK(try_catch.HasCaught());
97979796
String::Utf8Value exception_value1(try_catch.Exception());
9798-
// TODO(3995): Our compilers disagree about the position (and message).
9799-
if (!i::FLAG_always_opt) {
9800-
CHECK_EQ(0,
9801-
strcmp("TypeError: obj2 is not a function", *exception_value1));
9802-
}
9797+
CHECK_EQ(0, strcmp("TypeError: obj2 is not a function", *exception_value1));
98039798
try_catch.Reset();
98049799

98059800
Local<Value> args[] = {v8_num(29)};
@@ -15005,11 +15000,9 @@ void AnalyzeStackInNativeCode(const v8::FunctionCallbackInfo<v8::Value>& args) {
1500515000
checkStackFrame(origin, "foo", 6, 3, false, false,
1500615001
stackTrace->GetFrame(1));
1500715002
// This is the source string inside the eval which has the call to foo.
15008-
checkStackFrame(NULL, "", 1, 5, false, false,
15009-
stackTrace->GetFrame(2));
15003+
checkStackFrame(NULL, "", 1, 1, false, false, stackTrace->GetFrame(2));
1501015004
// The last frame is an anonymous function which has the initial eval call.
15011-
checkStackFrame(origin, "", 8, 7, false, false,
15012-
stackTrace->GetFrame(3));
15005+
checkStackFrame(origin, "", 8, 7, false, false, stackTrace->GetFrame(3));
1501315006

1501415007
CHECK(stackTrace->AsArray()->IsArray());
1501515008
} else if (testGroup == kDetailedTest) {
@@ -15022,11 +15015,9 @@ void AnalyzeStackInNativeCode(const v8::FunctionCallbackInfo<v8::Value>& args) {
1502215015
stackTrace->GetFrame(1));
1502315016
bool is_eval = true;
1502415017
// This is the source string inside the eval which has the call to baz.
15025-
checkStackFrame(NULL, "", 1, 5, is_eval, false,
15026-
stackTrace->GetFrame(2));
15018+
checkStackFrame(NULL, "", 1, 1, is_eval, false, stackTrace->GetFrame(2));
1502715019
// The last frame is an anonymous function which has the initial eval call.
15028-
checkStackFrame(origin, "", 10, 1, false, false,
15029-
stackTrace->GetFrame(3));
15020+
checkStackFrame(origin, "", 10, 1, false, false, stackTrace->GetFrame(3));
1503015021

1503115022
CHECK(stackTrace->AsArray()->IsArray());
1503215023
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2015 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
(function() {
6+
throw new Error("boom");
7+
})();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2015 the V8 project authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
*%(basename)s:6: Error: boom
6+
throw new Error("boom");
7+
^
8+
Error: boom
9+
at *%(basename)s:6:9
10+
at *%(basename)s:7:3

test/mjsunit/debug-backtrace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function listener(event, exec_state, event_data, data) {
195195
assertEquals("m", response.lookup(frame.func.ref).inferredName);
196196
assertFalse(frame.constructCall);
197197
assertEquals(35, frame.line);
198-
assertEquals(6, frame.column);
198+
assertEquals(2, frame.column);
199199
assertEquals(0, frame.arguments.length);
200200

201201
json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":3}}'

0 commit comments

Comments
 (0)