Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/jerry/array-prototype-indexof.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the expected behavior!


// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an assert for e.message

}

// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

}