Skip to content

Commit eb9d470

Browse files
committed
Increase test coverage: Array.prototype.indexOf
Branch coverage: Before: 22/26 After: 26/26 JerryScript-DCO-1.0-Signed-off-by: Mate Dabis mdabis@inf.u-szeged.hu
1 parent 0c20f8e commit eb9d470

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/jerry/array-prototype-indexof.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,39 @@ try {
8686
assert(e.message === "foo");
8787
assert(e instanceof ReferenceError);
8888
}
89+
90+
// Checking behavior when values are unable to find
91+
var a = [undefined, undefined, undefined, undefined, undefined];
92+
for (var i = 0; i < a.length; i++) {
93+
delete a[i];
94+
}
95+
a.indexOf("bar");
96+
97+
// Checking behavior when this value is not coercible to object
98+
try {
99+
Array.prototype.indexOf.call(null, "asd");
100+
assert(false);
101+
} catch (e) {
102+
assert(e instanceof TypeError);
103+
}
104+
105+
// Checking behavior when length is not a number
106+
try {
107+
var o = {};
108+
Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } });
109+
var a = { length : o };
110+
Array.prototype.indexOf.call(a, function () { });
111+
assert(false);
112+
} catch (e) {
113+
assert(e instanceof ReferenceError);
114+
}
115+
116+
// Checking behavior when unable to get the first element
117+
try {
118+
var a = [0, 1, 2, 3, 4];
119+
Object.defineProperty(a, '0', { 'get' : function () { throw new ReferenceError; } });
120+
Array.prototype.indexOf.call(a, "bar");
121+
assert(false);
122+
} catch (e) {
123+
assert(e instanceof ReferenceError);
124+
}

0 commit comments

Comments
 (0)