Make sure that message reporting works when the builtin string and
array functions are overwritten. Review URL: http://codereview.chromium.org/147142 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2269 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
08d098e082
commit
e3fa53edef
@ -37,13 +37,13 @@ function GetInstanceName(cons) {
|
||||
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 @@ function FormatString(format, args) {
|
||||
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 ToDetailString(obj) {
|
||||
|
||||
|
||||
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 @@ Script.prototype.locationFromPosition = function (position,
|
||||
// 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 @@ Script.prototype.sourceLine = function (opt_line) {
|
||||
// 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 @@ SourceLocation.prototype.restrict = function (opt_limit, opt_before) {
|
||||
* 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 @@ function SourceSlice(script, from_line, to_line, from_position, to_position) {
|
||||
* 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);
|
||||
};
|
||||
|
||||
|
||||
|
31
test/message/overwritten-builtins.js
Normal file
31
test/message/overwritten-builtins.js
Normal file
@ -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
|
30
test/message/overwritten-builtins.out
Normal file
30
test/message/overwritten-builtins.out
Normal file
@ -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
|
||||
^
|
@ -64,12 +64,12 @@ var comment_lines = 29;
|
||||
|
||||
// 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 @@ assertEquals(' c(tru', location.sourceText());
|
||||
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)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user