|
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 | +} catch (e) { } |
| 81 | + |
| 82 | +// Checking behavior when length is 0 |
| 83 | +try { |
| 84 | + Array.prototype.lastIndexOf.call("", "chocolate cake"); |
| 85 | +} catch (e) { } |
| 86 | + |
| 87 | +// Checking behavior when length is not a number |
| 88 | +try { |
| 89 | + var o = {}; |
| 90 | + Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } }); |
| 91 | + var a = { length : o }; |
| 92 | + Array.prototype.lastIndexOf.call(a, function () { }); |
| 93 | + assert(false); |
| 94 | +} catch (e) { |
| 95 | + assert(e instanceof ReferenceError); |
| 96 | +} |
| 97 | + |
| 98 | +// Checking behavior when the 3rd argument (start index) is not a number |
| 99 | +try { |
| 100 | + var o = {}; |
| 101 | + Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } }); |
| 102 | + Array.prototype.lastIndexOf.call("foo", "foo", o); |
| 103 | +} catch (e) {} |
| 104 | + |
| 105 | +// Checking behavior when the 3rd argument (start index) is greater than the length of the first argument |
| 106 | +try { |
| 107 | + Array.prototype.lastIndexOf.call("foo", "foo", 999); |
| 108 | +} catch (e) {} |
| 109 | + |
| 110 | +// Checking behavior when the starting index is out of the range of the original array, so it points |
| 111 | +// to an empty space, as we modified the length of the array before |
| 112 | +try { |
| 113 | + var a = [1, 2, 3]; |
| 114 | + Object.defineProperty(a, "length", {value: 10}); |
| 115 | + Array.prototype.lastIndexOf.call(a, "", 6); |
| 116 | +} catch (e) {} |
0 commit comments