Reviewers: Søren Gjesse,

Description:
Fix issue 420: accept truncated log files.

http://code.google.com/p/v8/issues/detail?id=420

Please review this at http://codereview.chromium.org/171038

Affected files:
   M test/mjsunit/mjsunit.js
   M test/mjsunit/tools/logreader.js
   M tools/logreader.js


Index: test/mjsunit/mjsunit.js
diff --git a/test/mjsunit/mjsunit.js b/test/mjsunit/mjsunit.js
index  
2c52a31e604451065363bc1fc90d1452a7b20427..1fb3f02afba9768109bee5dd34edcfdee3b0d12c
  
100644
--- a/test/mjsunit/mjsunit.js
+++ b/test/mjsunit/mjsunit.js
@@ -179,9 +179,13 @@ function assertInstanceof(obj, type) {

  function assertDoesNotThrow(code) {
    try {
-    eval(code);
+    if (typeof code == 'function') {
+      code();
+    } else {
+      eval(code);
+    }
    } catch (e) {
-    assertTrue(false, "threw an exception");
+    assertTrue(false, "threw an exception: " + (e.message || e));
    }
  }

Index: test/mjsunit/tools/logreader.js
diff --git a/test/mjsunit/tools/logreader.js  
b/test/mjsunit/tools/logreader.js
index  
dfd7f9f54eb003646ea91c182b6cc73efdb80a69..b460446c4f3115dc1ae2ffc2cbd252bf28aa876a
  
100644
--- a/test/mjsunit/tools/logreader.js
+++ b/test/mjsunit/tools/logreader.js
@@ -80,3 +80,18 @@
    assertEquals('bbbbaaaa', reader.expandBackRef_('bbbb#2:4'));
    assertEquals('"#1:1"', reader.expandBackRef_('"#1:1"'));
  })();
+
+
+(function testIssue420() {
+  // Having an incorrect event in the middle of a log should throw an  
exception.
+  var reader1 = new devtools.profiler.LogReader({});
+  assertThrows(function() {
+    reader1.processLogChunk('alias,a,b\nxxxx\nalias,c,d\n');
+  });
+
+  // But having it as the last record should not.
+  var reader2 = new devtools.profiler.LogReader({});
+  assertDoesNotThrow(function() {
+    reader2.processLogChunk('alias,a,b\nalias,c,d\nxxxx');
+  });
+})();
Index: tools/logreader.js
diff --git a/tools/logreader.js b/tools/logreader.js
index  
78085a451eb62e75de72d9c1c7b1724822b9efbd..88ab907740d5dc3807431bc53aa50865208bb1db
  
100644
--- a/tools/logreader.js
+++ b/tools/logreader.js
@@ -294,8 +294,11 @@ devtools.profiler.LogReader.prototype.processLog_ =  
function(lines) {
        this.dispatchLogRow_(fields);
      }
    } catch (e) {
-    this.printError('line ' + (i + 1) + ': ' + (e.message || e));
-    throw e;
+    // An error on the last line is acceptable since log file can be  
truncated.
+    if (i < n - 1) {
+      this.printError('line ' + (i + 1) + ': ' + (e.message || e));
+      throw e;
+    }
    }
  };




--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to