From eb9d470e386daf6d25552ba4bcbfe03306a57ceb Mon Sep 17 00:00:00 2001 From: Mate Dabis Date: Wed, 9 Jan 2019 10:19:01 +0100 Subject: [PATCH] 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 --- tests/jerry/array-prototype-indexof.js | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/jerry/array-prototype-indexof.js b/tests/jerry/array-prototype-indexof.js index ee77f8023f..3893a11b2e 100644 --- a/tests/jerry/array-prototype-indexof.js +++ b/tests/jerry/array-prototype-indexof.js @@ -86,3 +86,39 @@ try { assert(e.message === "foo"); assert(e instanceof ReferenceError); } + +// Checking behavior when values are unable to find +var a = [undefined, undefined, undefined, undefined, undefined]; +for (var i = 0; i < a.length; i++) { + delete a[i]; +} +a.indexOf("bar"); + +// Checking behavior when this value is not coercible to object +try { + Array.prototype.indexOf.call(null, "asd"); + assert(false); +} catch (e) { + assert(e instanceof TypeError); +} + +// Checking behavior when length is not a number +try { + var o = {}; + Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } }); + var a = { length : o }; + Array.prototype.indexOf.call(a, function () { }); + assert(false); +} catch (e) { + assert(e instanceof ReferenceError); +} + +// Checking behavior when unable to get the first element +try { + var a = [0, 1, 2, 3, 4]; + Object.defineProperty(a, '0', { 'get' : function () { throw new ReferenceError; } }); + Array.prototype.indexOf.call(a, "bar"); + assert(false); +} catch (e) { + assert(e instanceof ReferenceError); +}