Reviewers: marja,

Description:
Correctly parse line ends for debugging.

Instead of using only \n as line terminator, we now use the definition
in http://www.ecma-international.org/ecma-262/5.1/#sec-7.3

[email protected]
BUG=v8:2825
LOG=Y

Please review this at https://codereview.chromium.org/821383009/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+58, -14 lines):
  M src/objects.cc
  M src/scanner.h
  A test/mjsunit/regress/regress-2825.js


Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 414306f2b465553ed3dfe839f37347583d22996b..86efdc0826a0275dd4bc2cc39379f323a5131b6b 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -8928,20 +8928,18 @@ static void CalculateLineEndsImpl(Isolate* isolate,
                                   Vector<const SourceChar> src,
                                   bool include_ending_line) {
   const int src_len = src.length();
- StringSearch<uint8_t, SourceChar> search(isolate, STATIC_CHAR_VECTOR("\n"));
-
-  // Find and record line ends.
-  int position = 0;
-  while (position != -1 && position < src_len) {
-    position = search.Search(src, position);
-    if (position != -1) {
-      line_ends->Add(position);
-      position++;
-    } else if (include_ending_line) {
-      // Even if the last line misses a line end, it is counted.
-      line_ends->Add(src_len);
-      return;
-    }
+  UnicodeCache* cache = isolate->unicode_cache();
+  for (int i = 0; i < src_len - 1; i++) {
+    SourceChar current = src[i];
+    SourceChar next = src[i + 1];
+    if (cache->IsLineTerminatorSequence(current, next)) line_ends->Add(i);
+  }
+
+ if (src_len > 0 && cache->IsLineTerminatorSequence(src[src_len - 1], 0)) {
+    line_ends->Add(src_len - 1);
+  } else if (include_ending_line) {
+    // Even if the last line misses a line end, it is counted.
+    line_ends->Add(src_len);
   }
 }

Index: src/scanner.h
diff --git a/src/scanner.h b/src/scanner.h
index 6e668fd4921ca23e7dbbcd1755404c8269c20bd7..8537c5308c9f73e8dbf2f5f97e8188f195d531cc 100644
--- a/src/scanner.h
+++ b/src/scanner.h
@@ -121,6 +121,12 @@ class UnicodeCache {
bool IsIdentifierStart(unibrow::uchar c) { return kIsIdentifierStart.get(c); } bool IsIdentifierPart(unibrow::uchar c) { return kIsIdentifierPart.get(c); } bool IsLineTerminator(unibrow::uchar c) { return kIsLineTerminator.get(c); }
+  bool IsLineTerminatorSequence(unibrow::uchar c, unibrow::uchar next) {
+    if (!IsLineTerminator(c)) return false;
+ if (c == 0x000d && next == 0x000a) return false; // CR with following LF.
+    return true;
+  }
+
   bool IsWhiteSpace(unibrow::uchar c) { return kIsWhiteSpace.get(c); }
   bool IsWhiteSpaceOrLineTerminator(unibrow::uchar c) {
     return kIsWhiteSpaceOrLineTerminator.get(c);
Index: test/mjsunit/regress/regress-2825.js
diff --git a/test/mjsunit/regress/regress-2825.js b/test/mjsunit/regress/regress-2825.js
new file mode 100644
index 0000000000000000000000000000000000000000..6ffd8ec150658fa6d2f3d0028117260c078db7a8
--- /dev/null
+++ b/test/mjsunit/regress/regress-2825.js
@@ -0,0 +1,40 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug
+
+// Do not edit this file with an editor that replaces \r with \r\n.
+// Variable definitions for i0 through i3 are each terminated with \r.
+function f() {
+  var i0 = 0;
  var i1 = 1;
  var i2 = 2;
  var i3 = 3;
+  var j0 = 0;
+  var j1 = 1;
+  var j2 = 2;
+  var j3 = 3;
+}
+
+Debug = debug.Debug;
+var exception = null;
+var break_point_hit = false;
+
+function listener(event, exec_state, event_data, data) {
+  if (event != Debug.DebugEvent.Break) return;
+  try {
+    break_point_hit = true;
+    assertEquals("  var i2 = 2;", exec_state.frame(0).sourceLineText());
+  } catch (e) {
+    print(e + e.stack);
+    exception = e;
+  }
+}
+
+Debug.setListener(listener);
+
+Debug.setBreakPoint(f, 3, 0);
+
+f();
+
+Debug.setListener(null);
+assertTrue(break_point_hit);
+assertNull(exception);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to