Commit a01b45df authored by ager@chromium.org's avatar ager@chromium.org

Fix a number of tests that incorrectly used assertUnreachable.

Our testing infrastructure uses exceptions to indicate
errors. assertUnreachable therefore throws an exception to indicate
that it was reached. Therefore, it cannot be used to check that an
exception was thrown using the pattern:

try {
  shouldThrow();
  assertUnreachable();
} catch(e) {
}

Such a test will always pass because assertUnreachable will throw an
exception if shouldThrow does not.

R=ricow@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8117 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent bfa2ef1f
......@@ -411,67 +411,77 @@ testReduce("reduceRight", "ArrayWithNonElementPropertiesReduceRight", 6,
// Test error conditions:
var exception = false;
try {
[1].reduce("not a function");
assertUnreachable("Reduce callback not a function not throwing");
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError,
"reduce callback not a function not throwing TypeError");
assertEquals("called_non_callable", e.type,
"reduce non function TypeError type");
}
assertTrue(exception);
exception = false;
try {
[1].reduceRight("not a function");
assertUnreachable("ReduceRight callback not a function not throwing");
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError,
"reduceRight callback not a function not throwing TypeError");
assertEquals("called_non_callable", e.type,
"reduceRight non function TypeError type");
}
assertTrue(exception);
exception = false;
try {
[].reduce(sum);
assertUnreachable("Reduce no initial value not throwing");
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError,
"reduce no initial value not throwing TypeError");
assertEquals("reduce_no_initial", e.type,
"reduce no initial TypeError type");
}
assertTrue(exception);
exception = false;
try {
[].reduceRight(sum);
assertUnreachable("ReduceRight no initial value not throwing");
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError,
"reduceRight no initial value not throwing TypeError");
assertEquals("reduce_no_initial", e.type,
"reduceRight no initial TypeError type");
}
assertTrue(exception);
exception = false;
try {
[,,,].reduce(sum);
assertUnreachable("Reduce sparse no initial value not throwing");
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError,
"reduce sparse no initial value not throwing TypeError");
assertEquals("reduce_no_initial", e.type,
"reduce no initial TypeError type");
}
assertTrue(exception);
exception = false;
try {
[,,,].reduceRight(sum);
assertUnreachable("ReduceRight sparse no initial value not throwing");
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError,
"reduceRight sparse no initial value not throwing TypeError");
assertEquals("reduce_no_initial", e.type,
"reduceRight no initial TypeError type");
}
assertTrue(exception);
// Array changing length
......@@ -511,4 +521,3 @@ testReduce("reduce", "ArrayManipulationExtender", 10,
[3, 3, 2, [1, 2, 3, 4, 4, 5], 6],
[6, 4, 3, [1, 2, 3, 4, 4, 5, 6], 10],
], arr, extender, 0);
......@@ -155,6 +155,7 @@ for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
// Sanity check that all functions are correct
assertEquals(typeof(should_throw_on_null_and_undefined[i]), "function");
var exception = false;
try {
// We call all functions with no parameters, which means that essential
// parameters will have the undefined value.
......@@ -163,68 +164,84 @@ for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
// undefined value is an invalid argument value, it mustn't change
// the result of the test.
should_throw_on_null_and_undefined[i].call(null);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue("called_on_null_or_undefined" == e.type ||
"null_to_object" == e.type);
}
assertTrue(exception);
exception = false;
try {
should_throw_on_null_and_undefined[i].call(undefined);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue("called_on_null_or_undefined" == e.type ||
"null_to_object" == e.type);
}
assertTrue(exception);
exception = false;
try {
should_throw_on_null_and_undefined[i].apply(null);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue("called_on_null_or_undefined" == e.type ||
"null_to_object" == e.type);
}
assertTrue(exception);
exception = false;
try {
should_throw_on_null_and_undefined[i].apply(undefined);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue("called_on_null_or_undefined" == e.type ||
"null_to_object" == e.type);
}
assertTrue(exception);
}
// Test that all natives that are non generic throw on null and undefined.
for (var i = 0; i < non_generic.length; i++) {
// Sanity check that all functions are correct
assertEquals(typeof(non_generic[i]), "function");
exception = false;
try {
non_generic[i].call(null);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
}
assertTrue(exception);
exception = false;
try {
non_generic[i].call(null);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
}
assertTrue(exception);
exception = false;
try {
non_generic[i].apply(null);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
}
assertTrue(exception);
exception = false;
try {
non_generic[i].apply(null);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
}
assertTrue(exception);
}
......@@ -233,47 +250,55 @@ for (var i = 0; i < non_generic.length; i++) {
var array = [1,2,3,4,5];
for (var j = 0; j < mapping_functions.length; j++) {
for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
exception = false;
try {
mapping_functions[j].call(array,
should_throw_on_null_and_undefined[i],
null);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue("called_on_null_or_undefined" == e.type ||
"null_to_object" == e.type);
}
assertTrue(exception);
exception = false;
try {
mapping_functions[j].call(array,
should_throw_on_null_and_undefined[i],
undefined);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue("called_on_null_or_undefined" == e.type ||
"null_to_object" == e.type);
}
assertTrue(exception);
}
}
for (var j = 0; j < mapping_functions.length; j++) {
for (var i = 0; i < non_generic.length; i++) {
exception = false;
try {
mapping_functions[j].call(array,
non_generic[i],
null);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
}
assertTrue(exception);
exception = false;
try {
mapping_functions[j].call(array,
non_generic[i],
undefined);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
}
assertTrue(exception);
}
}
......@@ -281,39 +306,47 @@ for (var j = 0; j < mapping_functions.length; j++) {
// Reduce functions do a call with null as this argument.
for (var j = 0; j < reducing_functions.length; j++) {
for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
exception = false;
try {
reducing_functions[j].call(array, should_throw_on_null_and_undefined[i]);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue("called_on_null_or_undefined" == e.type ||
"null_to_object" == e.type);
}
assertTrue(exception);
exception = false;
try {
reducing_functions[j].call(array, should_throw_on_null_and_undefined[i]);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue("called_on_null_or_undefined" == e.type ||
"null_to_object" == e.type);
}
assertTrue(exception);
}
}
for (var j = 0; j < reducing_functions.length; j++) {
for (var i = 0; i < non_generic.length; i++) {
exception = false;
try {
reducing_functions[j].call(array, non_generic[i]);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
}
assertTrue(exception);
exception = false;
try {
reducing_functions[j].call(array, non_generic[i]);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
}
assertTrue(exception);
}
}
......
......@@ -30,28 +30,34 @@
// Flags: --allow-natives-syntax
// Check that an exception is thrown when null is passed as object.
var exception = false;
try {
Object.defineProperty(null, null, null);
assertTrue(false);
} catch (e) {
exception = true;
assertTrue(/called on non-object/.test(e));
}
assertTrue(exception);
// Check that an exception is thrown when undefined is passed as object.
exception = false;
try {
Object.defineProperty(undefined, undefined, undefined);
assertTrue(false);
} catch (e) {
exception = true;
assertTrue(/called on non-object/.test(e));
}
assertTrue(exception);
// Check that an exception is thrown when non-object is passed as object.
exception = false;
try {
Object.defineProperty(0, "foo", undefined);
assertTrue(false);
} catch (e) {
exception = true;
assertTrue(/called on non-object/.test(e));
}
assertTrue(exception);
// Object.
var obj1 = {};
......@@ -695,12 +701,14 @@ Object.defineProperty(obj5, 'minuszero', descMinusZero);
// Make sure we can redefine with -0.
Object.defineProperty(obj5, 'minuszero', descMinusZero);
exception = false;
try {
Object.defineProperty(obj5, 'minuszero', descPlusZero);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(/Cannot redefine property/.test(e));
}
assertTrue(exception);
Object.defineProperty(obj5, 'pluszero', descPlusZero);
......@@ -708,12 +716,14 @@ Object.defineProperty(obj5, 'pluszero', descPlusZero);
// Make sure we can redefine with +0.
Object.defineProperty(obj5, 'pluszero', descPlusZero);
exception = false;
try {
Object.defineProperty(obj5, 'pluszero', descMinusZero);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(/Cannot redefine property/.test(e));
}
assertTrue(exception);
var obj6 = {};
......@@ -761,13 +771,15 @@ try {
// Ensure that we can't change the descriptor of a
// non configurable property.
exception = false;
try {
var descAccessor = { get: function() { return 0; } };
Object.defineProperty(obj6, '2', descAccessor);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(/Cannot redefine property/.test(e));
}
assertTrue(exception);
Object.defineProperty(obj6, '2', descElementNonWritable);
desc = Object.getOwnPropertyDescriptor(obj6, '2');
......@@ -858,13 +870,15 @@ try {
// Ensure that we can't change the descriptor of a
// non configurable property.
exception = false;
try {
var descAccessor = { get: function() { return 0; } };
Object.defineProperty(arr, '2', descAccessor);
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(/Cannot redefine property/.test(e));
}
assertTrue(exception);
Object.defineProperty(arr, '2', descElementNonWritable);
desc = Object.getOwnPropertyDescriptor(arr, '2');
......
......@@ -32,21 +32,25 @@
// Test that we throw an error if an object is not passed as argument.
var non_objects = new Array(undefined, null, 1, -1, 0, 42.43);
for (var key in non_objects) {
var exception = false;
try {
Object.freeze(non_objects[key]);
assertUnreachable();
} catch(e) {
exception = true;
assertTrue(/Object.freeze called on non-object/.test(e));
}
assertTrue(exception);
}
for (var key in non_objects) {
exception = false;
try {
Object.isFrozen(non_objects[key]);
assertUnreachable();
} catch(e) {
exception = true;
assertTrue(/Object.isFrozen called on non-object/.test(e));
}
assertTrue(exception);
}
// Test normal data properties.
......
......@@ -141,11 +141,14 @@ var keywords = [
];
function testKeywordProperty(keyword) {
var exception = false;
try {
// Sanity check that what we get is a keyword.
eval("var " + keyword + " = 42;");
assertUnreachable("Not a keyword: " + keyword);
} catch (e) { }
} catch (e) {
exception = true;
}
assertTrue(exception);
// Simple property, read and write.
var x = eval("({" + keyword + ": 42})");
......@@ -187,4 +190,4 @@ function testKeywordProperty(keyword) {
for (var i = 0; i < keywords.length; i++) {
testKeywordProperty(keywords[i]);
}
\ No newline at end of file
}
......@@ -32,21 +32,25 @@
// Test that we throw an error if an object is not passed as argument.
var non_objects = new Array(undefined, null, 1, -1, 0, 42.43);
for (var key in non_objects) {
var exception = false;
try {
Object.seal(non_objects[key]);
assertUnreachable();
} catch(e) {
exception = true;
assertTrue(/Object.seal called on non-object/.test(e));
}
assertTrue(exception);
}
for (var key in non_objects) {
exception = false;
try {
Object.isSealed(non_objects[key]);
assertUnreachable();
} catch(e) {
exception = true;
assertTrue(/Object.isSealed called on non-object/.test(e));
}
assertTrue(exception);
}
// Test normal data properties.
......
......@@ -45,19 +45,21 @@ function testNoShadowing() {
assertEquals(2, y);
assertEquals('global', global_function());
assertEquals('local', local_function());
var exception = false;
try {
const_uninitialized();
assertUnreachable();
} catch(e) {
// Ignore.
exception = true;
}
assertTrue(exception);
assertEquals('const_global', const_initialized());
exception = false;
try {
local_const_uninitialized();
assertUnreachable();
} catch(e) {
// Ignore.
exception = true;
}
assertTrue(exception);
assertEquals('const_local', local_const_initialized());
function g() {
assertEquals(1, x);
......@@ -65,19 +67,21 @@ function testNoShadowing() {
assertEquals(2, y);
assertEquals('global', global_function());
assertEquals('local', local_function());
var exception = false;
try {
const_uninitialized();
assertUnreachable();
} catch(e) {
// Ignore.
exception = true;
}
assertTrue(exception);
assertEquals('const_global', const_initialized());
exception = false;
try {
local_const_uninitialized();
assertUnreachable();
} catch(e) {
// Ignore.
exception = true;
}
assertTrue(exception);
assertEquals('const_local', local_const_initialized());
}
g();
......
......@@ -38,7 +38,6 @@ assertTrue(hasBeenInvoked);
var exception;
try {
eval("try { } catch (e) { var y = false; }");
assertUnreachable();
} catch (e) {
exception = e;
}
......
......@@ -30,9 +30,11 @@
Object.prototype.__defineGetter__(0, function() { throw 42; } );
var exception = false;
try {
eval("(function() { const x; var x })")();
assertUnreachable();
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
}
assertTrue(exception);
......@@ -41,8 +41,10 @@ function test() {
}
}
var exception = false;
try {
test();
assertUnreachable();
} catch (e) {
exception = true;
}
assertTrue(exception);
......@@ -32,15 +32,10 @@
// when keyed store on the array does not work as expected because of
// the setter on its prototype.
try {
var N = 100;
var array = Array(N);
for (var i = 0; i < N; ++i) {
array[i] = i;
}
Array.prototype.__defineSetter__(32, function() { });
// The next line throws. We should make it work even with changed
// prototype. See http://code.google.com/p/v8/issues/detail?id=1161
array.join(",");
assertUnreachable();
} catch (e) { }
var N = 10;
var array = Array(N);
for (var i = 0; i < N; ++i) {
array[i] = i;
}
Array.prototype.__defineSetter__(2, function() { });
assertEquals("0,1,2,3,4,5,6,7,8,9", array.join(","));
......@@ -42,24 +42,31 @@ eval("function a() {}");
assertTrue(this.hasOwnProperty("a"));
__proto__.__defineSetter__("b", function(v) { assertUnreachable(); });
var exception = false;
try {
eval("const b = 23");
assertUnreachable();
} catch(e) {
exception = true;
assertTrue(/TypeError/.test(e));
}
assertTrue(exception);
exception = false;
try {
eval("with({}) { eval('const b = 23') }");
assertUnreachable();
} catch(e) {
exception = true;
assertTrue(/TypeError/.test(e));
}
assertTrue(exception);
__proto__.__defineSetter__("c", function(v) { throw 42; });
exception = false;
try {
eval("var c = 1");
assertUnreachable();
} catch(e) {
exception = true;
assertEquals(42, e);
assertFalse(this.hasOwnProperty("c"));
}
assertTrue(exception);
......@@ -29,9 +29,11 @@
// are properly treated.
Object.prototype.__defineGetter__(0, function() { throw 42; });
var exception = false;
try {
Object[0]();
assertUnreachable();
} catch(e) {
exception = true;
assertEquals(42, e);
}
assertTrue(exception);
......@@ -28,9 +28,11 @@
var x = { valueOf: function() { throw "x"; } };
var y = { valueOf: function() { throw "y"; } };
var exception = false;
try {
x * -y;
assertUnreachable("Didn't throw an exception");
} catch (e) {
exception = true;
assertEquals("y", e);
}
assertTrue(exception);
......@@ -54,13 +54,14 @@ function run() {
}
for (var i = 0; i < kIllegalEncoded.length; i++) {
var value = kIllegalEncoded[i];
var threw = false;
var exception = false;
try {
decodeURI(value);
assertUnreachable(value);
} catch (e) {
exception = true;
assertInstanceof(e, URIError);
}
assertTrue(exception);
}
}
......
......@@ -42,36 +42,44 @@ eval_alias(code3);
eval_alias(code4);
function strict1() {
var exception = false;
try {
eval(code1);
assertUnreachable("did not throw exception");
} catch (e) {
exception = true;
assertInstanceof(e, SyntaxError);
}
assertTrue(exception);
function strict2() {
var exception = false;
try {
eval(code2);
assertUnreachable("did not throw exception");
} catch (e) {
exception = true;
assertInstanceof(e, SyntaxError);
}
assertTrue(exception);
function strict3() {
var exception = false;
try {
eval(code3);
assertUnreachable("did not throw exception");
} catch (e) {
exception = true;
assertInstanceof(e, SyntaxError);
}
assertTrue(exception);
function strict4() {
var exception = false;
try {
eval(code4);
assertUnreachable("did not throw exception");
} catch (e) {
exception = true;
assertInstanceof(e, SyntaxError);
}
assertTrue(exception);
}
strict4();
}
......
......@@ -842,12 +842,14 @@ repeat(10, function() {
}
for (var i = 0; i < 10; i ++) {
var exception = false;
try {
strict(o, name);
assertUnreachable();
} catch(e) {
exception = true;
assertInstanceof(e, TypeError);
}
assertTrue(exception);
}
})();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment