Skip to content
Snippets Groups Projects
Commit 10e0d977 authored by Mike Pennisi's avatar Mike Pennisi
Browse files

Prefer explicit error checking where possible

The `negative` frontmatter tag expresses an expectation for the behavior
of the test file as a whole. The `assert.throws` helper function offers
more fine-grained control over expectations because it may be applied to
specific statements and expressions. This makes it preferable in cases
where it may be used (i.e. when the test body does not describe a syntax
error or early error).

Re-implement assertions for errors to use the `assert.throws` helper
function wherever possible.
parent 0027a6b6
No related branches found
No related tags found
No related merge requests found
Showing
with 75 additions and 56 deletions
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
info: Array.prototype.splice sets `length` on `this` info: Array.prototype.splice sets `length` on `this`
es5id: 15.4.4.12_A6.1_T2 es5id: 15.4.4.12_A6.1_T2
description: Array.prototype.splice throws if `length` is read-only description: Array.prototype.splice throws if `length` is read-only
negative: TypeError
---*/ ---*/
var a = [0, 1, 2]; var a = [0, 1, 2];
...@@ -14,4 +13,6 @@ Object.defineProperty(a, 'length', { ...@@ -14,4 +13,6 @@ Object.defineProperty(a, 'length', {
writable: false writable: false
}); });
a.splice(1, 2, 4); assert.throws(TypeError, function() {
a.splice(1, 2, 4);
});
...@@ -9,10 +9,11 @@ es5id: 15.3.5-2gs ...@@ -9,10 +9,11 @@ es5id: 15.3.5-2gs
description: > description: >
StrictMode - error is thrown when reading the 'caller' property of StrictMode - error is thrown when reading the 'caller' property of
a function object a function object
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
function _15_3_5_1_gs() {} function _15_3_5_1_gs() {}
_15_3_5_1_gs.caller;
throw NotEarlyError; assert.throws(TypeError, function() {
_15_3_5_1_gs.caller;
});
...@@ -10,13 +10,14 @@ description: > ...@@ -10,13 +10,14 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
non-strict function (New'ed Function constructor includes strict non-strict function (New'ed Function constructor includes strict
directive prologue) directive prologue)
negative: TypeError
flags: [noStrict] flags: [noStrict]
---*/ ---*/
var f = new Function("\"use strict\";\nreturn gNonStrict();"); var f = new Function("\"use strict\";\nreturn gNonStrict();");
f();
assert.throws(TypeError, function() {
f();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller || gNonStrict.caller.throwTypeError; return gNonStrict.caller || gNonStrict.caller.throwTypeError;
......
...@@ -9,11 +9,12 @@ es5id: 15.3.5.4_2-11gs ...@@ -9,11 +9,12 @@ es5id: 15.3.5.4_2-11gs
description: > description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (eval used within strict mode) strict function (eval used within strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
eval("gNonStrict();"); assert.throws(TypeError, function() {
eval("gNonStrict();");
});
function gNonStrict() { function gNonStrict() {
......
...@@ -9,13 +9,14 @@ es5id: 15.3.5.4_2-13gs ...@@ -9,13 +9,14 @@ es5id: 15.3.5.4_2-13gs
description: > description: >
Strict mode - checking access to non-strict function caller from Strict mode - checking access to non-strict function caller from
strict function (indirect eval used within strict mode) strict function (indirect eval used within strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
var my_eval = eval; var my_eval = eval;
my_eval("gNonStrict();");
assert.throws(TypeError, function() {
my_eval("gNonStrict();");
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller; return gNonStrict.caller;
......
...@@ -10,15 +10,16 @@ description: > ...@@ -10,15 +10,16 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (New'ed object from FunctionDeclaration defined strict function (New'ed object from FunctionDeclaration defined
within strict mode) within strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
function f() { function f() {
return gNonStrict(); return gNonStrict();
} }
new f();
assert.throws(TypeError, function() {
new f();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller; return gNonStrict.caller;
......
...@@ -10,7 +10,6 @@ description: > ...@@ -10,7 +10,6 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
non-strict function (New'ed object from FunctionDeclaration non-strict function (New'ed object from FunctionDeclaration
includes strict directive prologue) includes strict directive prologue)
negative: TypeError
flags: [noStrict] flags: [noStrict]
---*/ ---*/
...@@ -18,8 +17,10 @@ function f() { ...@@ -18,8 +17,10 @@ function f() {
"use strict"; "use strict";
return gNonStrict(); return gNonStrict();
} }
new f();
assert.throws(TypeError, function() {
new f();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller || gNonStrict.caller.throwTypeError; return gNonStrict.caller || gNonStrict.caller.throwTypeError;
......
...@@ -10,15 +10,16 @@ description: > ...@@ -10,15 +10,16 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (New'ed object from FunctionExpression defined strict function (New'ed object from FunctionExpression defined
within strict mode) within strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
var f = function () { var f = function () {
return gNonStrict(); return gNonStrict();
} }
new f();
assert.throws(TypeError, function() {
new f();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller; return gNonStrict.caller;
......
...@@ -10,7 +10,6 @@ description: > ...@@ -10,7 +10,6 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
non-strict function (New'ed object from FunctionExpression non-strict function (New'ed object from FunctionExpression
includes strict directive prologue) includes strict directive prologue)
negative: TypeError
flags: [noStrict] flags: [noStrict]
---*/ ---*/
...@@ -18,8 +17,10 @@ var f = function () { ...@@ -18,8 +17,10 @@ var f = function () {
"use strict"; "use strict";
return gNonStrict(); return gNonStrict();
} }
new f();
assert.throws(TypeError, function() {
new f();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller || gNonStrict.caller.throwTypeError; return gNonStrict.caller || gNonStrict.caller.throwTypeError;
......
...@@ -10,15 +10,15 @@ description: > ...@@ -10,15 +10,15 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (New'ed object from Anonymous FunctionExpression strict function (New'ed object from Anonymous FunctionExpression
defined within strict mode) defined within strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
var obj = new (function () { assert.throws(TypeError, function() {
return gNonStrict(); var obj = new (function () {
return gNonStrict();
});
}); });
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller; return gNonStrict.caller;
} }
...@@ -9,15 +9,16 @@ es5id: 15.3.5.4_2-1gs ...@@ -9,15 +9,16 @@ es5id: 15.3.5.4_2-1gs
description: > description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (FunctionDeclaration defined within strict mode) strict function (FunctionDeclaration defined within strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
function f() { function f() {
return gNonStrict(); return gNonStrict();
} }
f();
assert.throws(TypeError, function() {
f();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller; return gNonStrict.caller;
......
...@@ -10,13 +10,14 @@ description: > ...@@ -10,13 +10,14 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
non-strict function (New'ed object from Anonymous non-strict function (New'ed object from Anonymous
FunctionExpression includes strict directive prologue) FunctionExpression includes strict directive prologue)
negative: TypeError
flags: [noStrict] flags: [noStrict]
---*/ ---*/
var obj = new (function () { assert.throws(TypeError, function() {
"use strict"; var obj = new (function () {
return gNonStrict(); "use strict";
return gNonStrict();
});
}); });
......
...@@ -10,7 +10,6 @@ description: > ...@@ -10,7 +10,6 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (FunctionDeclaration defined within a strict function (FunctionDeclaration defined within a
FunctionDeclaration inside strict mode) FunctionDeclaration inside strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
...@@ -20,8 +19,10 @@ function f1() { ...@@ -20,8 +19,10 @@ function f1() {
} }
return f(); return f();
} }
f1();
assert.throws(TypeError, function() {
f1();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller; return gNonStrict.caller;
......
...@@ -10,7 +10,6 @@ description: > ...@@ -10,7 +10,6 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (FunctionExpression defined within a strict function (FunctionExpression defined within a
FunctionDeclaration inside strict mode) FunctionDeclaration inside strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
...@@ -20,8 +19,10 @@ function f1() { ...@@ -20,8 +19,10 @@ function f1() {
} }
return f(); return f();
} }
f1();
assert.throws(TypeError, function() {
f1();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller; return gNonStrict.caller;
......
...@@ -10,7 +10,6 @@ description: > ...@@ -10,7 +10,6 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (Anonymous FunctionExpression defined within a strict function (Anonymous FunctionExpression defined within a
FunctionDeclaration inside strict mode) FunctionDeclaration inside strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
...@@ -19,8 +18,10 @@ function f1() { ...@@ -19,8 +18,10 @@ function f1() {
return gNonStrict(); return gNonStrict();
})(); })();
} }
f1();
assert.throws(TypeError, function() {
f1();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller; return gNonStrict.caller;
......
...@@ -10,7 +10,6 @@ description: > ...@@ -10,7 +10,6 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (FunctionDeclaration defined within a strict function (FunctionDeclaration defined within a
FunctionExpression inside strict mode) FunctionExpression inside strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
...@@ -20,7 +19,10 @@ var f1 = function () { ...@@ -20,7 +19,10 @@ var f1 = function () {
} }
return f(); return f();
} }
f1();
assert.throws(TypeError, function() {
f1();
});
function gNonStrict() { function gNonStrict() {
......
...@@ -10,7 +10,6 @@ description: > ...@@ -10,7 +10,6 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (FunctionExpression defined within a strict function (FunctionExpression defined within a
FunctionExpression inside strict mode) FunctionExpression inside strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
...@@ -20,8 +19,10 @@ var f1 = function () { ...@@ -20,8 +19,10 @@ var f1 = function () {
} }
return f(); return f();
} }
f1();
assert.throws(TypeError, function() {
f1();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller; return gNonStrict.caller;
......
...@@ -10,7 +10,6 @@ description: > ...@@ -10,7 +10,6 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (Anonymous FunctionExpression defined within a strict function (Anonymous FunctionExpression defined within a
FunctionExpression inside strict mode) FunctionExpression inside strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
...@@ -19,8 +18,10 @@ var f1 = function () { ...@@ -19,8 +18,10 @@ var f1 = function () {
return gNonStrict(); return gNonStrict();
})(); })();
} }
f1();
assert.throws(TypeError, function() {
f1();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller; return gNonStrict.caller;
......
...@@ -10,17 +10,17 @@ description: > ...@@ -10,17 +10,17 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (FunctionDeclaration defined within an Anonymous strict function (FunctionDeclaration defined within an Anonymous
FunctionExpression inside strict mode) FunctionExpression inside strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
(function () { assert.throws(TypeError, function() {
function f() { (function () {
return gNonStrict(); function f() {
} return gNonStrict();
return f(); }
})(); return f();
})();
});
function gNonStrict() { function gNonStrict() {
return gNonStrict.caller; return gNonStrict.caller;
......
...@@ -10,16 +10,17 @@ description: > ...@@ -10,16 +10,17 @@ description: >
Strict mode - checking access to strict function caller from Strict mode - checking access to strict function caller from
strict function (FunctionExpression defined within an Anonymous strict function (FunctionExpression defined within an Anonymous
FunctionExpression inside strict mode) FunctionExpression inside strict mode)
negative: TypeError
flags: [onlyStrict] flags: [onlyStrict]
---*/ ---*/
(function () { assert.throws(TypeError, function() {
var f = function () { (function () {
return gNonStrict(); var f = function () {
} return gNonStrict();
return f(); }
})(); return f();
})();
});
function gNonStrict() { function gNonStrict() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment