Author: [email protected]
Date: Thu Jun 25 03:27:36 2009
New Revision: 2269

Added:
    branches/bleeding_edge/test/message/overwritten-builtins.js
    branches/bleeding_edge/test/message/overwritten-builtins.out
Modified:
    branches/bleeding_edge/src/messages.js
    branches/bleeding_edge/test/mjsunit/debug-sourceinfo.js

Log:
Make sure that message reporting works when the builtin string and
array functions are overwritten.

Review URL: http://codereview.chromium.org/147142

Modified: branches/bleeding_edge/src/messages.js
==============================================================================
--- branches/bleeding_edge/src/messages.js      (original)
+++ branches/bleeding_edge/src/messages.js      Thu Jun 25 03:27:36 2009
@@ -37,13 +37,13 @@
    if (cons.length == 0) {
      return "";
    }
-  var first = cons.charAt(0).toLowerCase();
+  var first = %StringToLowerCase(StringCharAt.call(cons, 0));
    var mapping = kVowelSounds;
-  if (cons.length > 1 && (cons.charAt(0) != first)) {
+  if (cons.length > 1 && (StringCharAt.call(cons, 0) != first)) {
      // First char is upper case
-    var second = cons.charAt(1).toLowerCase();
+    var second = %StringToLowerCase(StringCharAt.call(cons, 1));
      // Second char is upper case
-    if (cons.charAt(1) != second)
+    if (StringCharAt.call(cons, 1) != second)
        mapping = kCapitalVowelSounds;
    }
    var s = mapping[first] ? "an " : "a ";
@@ -126,7 +126,7 @@
      var str;
      try { str = ToDetailString(args[i]); }
      catch (e) { str = "#<error>"; }
-    result = result.split("%" + i).join(str);
+    result = ArrayJoin.call(StringSplit.call(result, "%" + i), str);
    }
    return result;
  }
@@ -146,17 +146,9 @@


  function MakeGenericError(constructor, type, args) {
-  if (args instanceof $Array) {
-    for (var i = 0; i < args.length; i++) {
-      var elem = args[i];
-      if (elem instanceof $Array && elem.length > 100) { // arbitrary  
limit, grab a reasonable slice to report
-        args[i] = elem.slice(0,20).concat("...");
-      }
-    }
-  } else if (IS_UNDEFINED(args)) {
+  if (IS_UNDEFINED(args)) {
      args = [];
    }
-
    var e = new constructor(kAddMessageAccessorsMarker);
    e.type = type;
    e.arguments = args;
@@ -281,7 +273,7 @@
    // Determine start, end and column.
    var start = line == 0 ? 0 : this.line_ends[line - 1] + 1;
    var end = this.line_ends[line];
-  if (end > 0 && this.source.charAt(end - 1) == '\r') end--;
+  if (end > 0 && StringCharAt.call(this.source, end - 1) == '\r') end--;
    var column = position - start;

    // Adjust according to the offset within the resource.
@@ -394,7 +386,7 @@
    // Return the source line.
    var start = line == 0 ? 0 : this.line_ends[line - 1] + 1;
    var end = this.line_ends[line];
-  return this.source.substring(start, end);
+  return StringSubstring.call(this.source, start, end);
  }


@@ -498,7 +490,7 @@
   *     Source text for this location.
   */
  SourceLocation.prototype.sourceText = function () {
-  return this.script.source.substring(this.start, this.end);
+  return StringSubstring.call(this.script.source, this.start, this.end);
  };


@@ -535,7 +527,7 @@
   *     the line terminating characters (if any)
   */
  SourceSlice.prototype.sourceText = function () {
-  return this.script.source.substring(this.from_position,  
this.to_position);
+  return StringSubstring.call(this.script.source, this.from_position,  
this.to_position);
  };



Added: branches/bleeding_edge/test/message/overwritten-builtins.js
==============================================================================
--- (empty file)
+++ branches/bleeding_edge/test/message/overwritten-builtins.js Thu Jun 25  
03:27:36 2009
@@ -0,0 +1,31 @@
+// Copyright 2009 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+String.prototype.split = function() { return "SPLIT ERROR"; };
+Array.prototype.join = function() { return []; };
+
+undefined.x

Added: branches/bleeding_edge/test/message/overwritten-builtins.out
==============================================================================
--- (empty file)
+++ branches/bleeding_edge/test/message/overwritten-builtins.out        Thu Jun 
25  
03:27:36 2009
@@ -0,0 +1,30 @@
+# Copyright 2009 the V8 project authors. All rights reserved.
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above
+#       copyright notice, this list of conditions and the following
+#       disclaimer in the documentation and/or other materials provided
+#       with the distribution.
+#     * Neither the name of Google Inc. nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*%(basename)s:31: TypeError: Cannot read property 'x' of undefined
+undefined.x
+^

Modified: branches/bleeding_edge/test/mjsunit/debug-sourceinfo.js
==============================================================================
--- branches/bleeding_edge/test/mjsunit/debug-sourceinfo.js     (original)
+++ branches/bleeding_edge/test/mjsunit/debug-sourceinfo.js     Thu Jun 25  
03:27:36 2009
@@ -64,12 +64,12 @@

  // This is the last position in the entire file (note: this equals
  // file size of <debug-sourceinfo.js> - 1, since starting at 0).
-var last_position = 14072;
+var last_position = 14312;
  // This is the last line of entire file (note: starting at 0).
-var last_line = 345;
+var last_line = 351;
  // This is the last column of last line (note: starting at 0 and +2, due
  // to trailing <CR><LF>).
-var last_column = 48;
+var last_column = 2;

  // This magic number is the length or the first line comment (actually  
number
  // of characters before 'function a(...'.
@@ -344,3 +344,9 @@
  location = script.locationFromLine(1, 0, start_b);
  location.restrict(7, 6);
  assertEquals('  c(tru', location.sourceText());
+
+// Test that script.sourceLine(line) works.
+for (line = 0; line < num_lines_d; line++) {
+  var line_content_regexp = new RegExp("  x = " + (line + 1));
+  assertTrue(line_content_regexp.test(script.sourceLine(start_line_d +  
line)));
+}

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

Reply via email to