|
69 | 69 | assert(e.message === "foo"); |
70 | 70 | assert(e instanceof ReferenceError); |
71 | 71 | } |
| 72 | + |
| 73 | +// Checking behavior when there are no arguments except "this" |
| 74 | +var a = "This is a sample text string to test this function"; |
| 75 | +Array.prototype.lastIndexOf.call(a); |
| 76 | + |
| 77 | +// Checking behavior when value is null |
| 78 | +try{ |
| 79 | + Array.prototype.lastIndexOf.call(null, "asd"); |
| 80 | + assert(false); |
| 81 | +} catch (e) { |
| 82 | + assert(e instanceof TypeError); |
| 83 | +} |
| 84 | + |
| 85 | +// Checking behavior when length is 0 |
| 86 | +Array.prototype.lastIndexOf.call("", "chocolate cake"); |
| 87 | + |
| 88 | +// Checking behavior when length is not a number |
| 89 | +try { |
| 90 | + var o = {}; |
| 91 | + Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } }); |
| 92 | + var a = { length : o }; |
| 93 | + Array.prototype.lastIndexOf.call(a, function () { }); |
| 94 | + assert(false); |
| 95 | +} catch (e) { |
| 96 | + assert(e instanceof ReferenceError); |
| 97 | +} |
| 98 | + |
| 99 | +// Checking behavior when the 3rd argument (start index) is not a number |
| 100 | +try { |
| 101 | + var o = {}; |
| 102 | + Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } }); |
| 103 | + Array.prototype.lastIndexOf.call("foo", "foo", o); |
| 104 | + assert(false); |
| 105 | +} catch (e) { |
| 106 | + assert(e instanceof ReferenceError); |
| 107 | +} |
| 108 | + |
| 109 | +// Checking behavior when the 3rd argument (start index) is greater than the length of the first argument |
| 110 | +Array.prototype.lastIndexOf.call("foo", "foo", 999); |
| 111 | + |
| 112 | +// Checking behavior when the starting index is out of the range of the original array, so it points |
| 113 | +// to an empty space, as we modified the length of the array before |
| 114 | +var a = [1, 2, 3]; |
| 115 | +Object.defineProperty(a, "length", {value: 10}); |
| 116 | +Array.prototype.lastIndexOf.call(a, "", 6); |
0 commit comments