| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = '15.5.4.7-2.js'; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
var SECTION = "15.5.4.7-2"; |
| 49 |
var VERSION = "ECMA_1"; |
| 50 |
startTest(); |
| 51 |
var TITLE = "String.protoype.lastIndexOf"; |
| 52 |
|
| 53 |
writeHeaderToLog( SECTION + " "+ TITLE); |
| 54 |
|
| 55 |
|
| 56 |
new TestCase( SECTION, "String.prototype.lastIndexOf.length", 1, String.prototype.lastIndexOf.length ); |
| 57 |
new TestCase( SECTION, "delete String.prototype.lastIndexOf.length", false, delete String.prototype.lastIndexOf.length ); |
| 58 |
new TestCase( SECTION, "delete String.prototype.lastIndexOf.length; String.prototype.lastIndexOf.length", 1, eval("delete String.prototype.lastIndexOf.length; String.prototype.lastIndexOf.length" ) ); |
| 59 |
|
| 60 |
new TestCase( SECTION, "var s = new String(''); s.lastIndexOf('', 0)", LastIndexOf("","",0), eval("var s = new String(''); s.lastIndexOf('', 0)") ); |
| 61 |
new TestCase( SECTION, "var s = new String(''); s.lastIndexOf('')", LastIndexOf("",""), eval("var s = new String(''); s.lastIndexOf('')") ); |
| 62 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('', 0)", LastIndexOf("hello","",0), eval("var s = new String('hello'); s.lastIndexOf('',0)") ); |
| 63 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('')", LastIndexOf("hello",""), eval("var s = new String('hello'); s.lastIndexOf('')") ); |
| 64 |
|
| 65 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll')", LastIndexOf("hello","ll"), eval("var s = new String('hello'); s.lastIndexOf('ll')") ); |
| 66 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', 0)", LastIndexOf("hello","ll",0), eval("var s = new String('hello'); s.lastIndexOf('ll', 0)") ); |
| 67 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', 1)", LastIndexOf("hello","ll",1), eval("var s = new String('hello'); s.lastIndexOf('ll', 1)") ); |
| 68 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', 2)", LastIndexOf("hello","ll",2), eval("var s = new String('hello'); s.lastIndexOf('ll', 2)") ); |
| 69 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', 3)", LastIndexOf("hello","ll",3), eval("var s = new String('hello'); s.lastIndexOf('ll', 3)") ); |
| 70 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', 4)", LastIndexOf("hello","ll",4), eval("var s = new String('hello'); s.lastIndexOf('ll', 4)") ); |
| 71 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', 5)", LastIndexOf("hello","ll",5), eval("var s = new String('hello'); s.lastIndexOf('ll', 5)") ); |
| 72 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', 6)", LastIndexOf("hello","ll",6), eval("var s = new String('hello'); s.lastIndexOf('ll', 6)") ); |
| 73 |
|
| 74 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', 1.5)", LastIndexOf('hello','ll', 1.5), eval("var s = new String('hello'); s.lastIndexOf('ll', 1.5)") ); |
| 75 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', 2.5)", LastIndexOf('hello','ll', 2.5), eval("var s = new String('hello'); s.lastIndexOf('ll', 2.5)") ); |
| 76 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', -1)", LastIndexOf('hello','ll', -1), eval("var s = new String('hello'); s.lastIndexOf('ll', -1)") ); |
| 77 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', -1.5)",LastIndexOf('hello','ll', -1.5), eval("var s = new String('hello'); s.lastIndexOf('ll', -1.5)") ); |
| 78 |
|
| 79 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', -Infinity)", LastIndexOf("hello","ll",-Infinity), eval("var s = new String('hello'); s.lastIndexOf('ll', -Infinity)") ); |
| 80 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', Infinity)", LastIndexOf("hello","ll",Infinity), eval("var s = new String('hello'); s.lastIndexOf('ll', Infinity)") ); |
| 81 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', NaN)", LastIndexOf("hello","ll",NaN), eval("var s = new String('hello'); s.lastIndexOf('ll', NaN)") ); |
| 82 |
new TestCase( SECTION, "var s = new String('hello'); s.lastIndexOf('ll', -0)", LastIndexOf("hello","ll",-0), eval("var s = new String('hello'); s.lastIndexOf('ll', -0)") ); |
| 83 |
for ( var i = 0; i < ( "[object Object]" ).length; i++ ) { |
| 84 |
new TestCase( SECTION, |
| 85 |
"var o = new Object(); o.lastIndexOf = String.prototype.lastIndexOf; o.lastIndexOf('b', "+ i + ")", |
| 86 |
( i < 2 ? -1 : ( i < 9 ? 2 : 9 )) , |
| 87 |
eval("var o = new Object(); o.lastIndexOf = String.prototype.lastIndexOf; o.lastIndexOf('b', "+ i + ")") ); |
| 88 |
} |
| 89 |
for ( var i = 0; i < 5; i ++ ) { |
| 90 |
new TestCase( SECTION, |
| 91 |
"var b = new Boolean(); b.lastIndexOf = String.prototype.lastIndexOf; b.lastIndexOf('l', "+ i + ")", |
| 92 |
( i < 2 ? -1 : 2 ), |
| 93 |
eval("var b = new Boolean(); b.lastIndexOf = String.prototype.lastIndexOf; b.lastIndexOf('l', "+ i + ")") ); |
| 94 |
} |
| 95 |
for ( var i = 0; i < 5; i ++ ) { |
| 96 |
new TestCase( SECTION, |
| 97 |
"var b = new Boolean(); b.toString = Object.prototype.toString; b.lastIndexOf = String.prototype.lastIndexOf; b.lastIndexOf('o', "+ i + ")", |
| 98 |
( i < 1 ? -1 : ( i < 9 ? 1 : ( i < 10 ? 9 : 10 ) ) ), |
| 99 |
eval("var b = new Boolean(); b.toString = Object.prototype.toString; b.lastIndexOf = String.prototype.lastIndexOf; b.lastIndexOf('o', "+ i + ")") ); |
| 100 |
} |
| 101 |
for ( var i = 0; i < 9; i++ ) { |
| 102 |
new TestCase( SECTION, |
| 103 |
"var n = new Number(Infinity); n.lastIndexOf = String.prototype.lastIndexOf; n.lastIndexOf( 'i', " + i + " )", |
| 104 |
( i < 3 ? -1 : ( i < 5 ? 3 : 5 ) ), |
| 105 |
eval("var n = new Number(Infinity); n.lastIndexOf = String.prototype.lastIndexOf; n.lastIndexOf( 'i', " + i + " )") ); |
| 106 |
} |
| 107 |
var a = new Array( "abc","def","ghi","jkl","mno","pqr","stu","vwx","yz" ); |
| 108 |
|
| 109 |
for ( var i = 0; i < (a.toString()).length; i++ ) { |
| 110 |
new TestCase( SECTION, |
| 111 |
"var a = new Array( 'abc','def','ghi','jkl','mno','pqr','stu','vwx','yz' ); a.lastIndexOf = String.prototype.lastIndexOf; a.lastIndexOf( ',mno,p', "+i+" )", |
| 112 |
( i < 15 ? -1 : 15 ), |
| 113 |
eval("var a = new Array( 'abc','def','ghi','jkl','mno','pqr','stu','vwx','yz' ); a.lastIndexOf = String.prototype.lastIndexOf; a.lastIndexOf( ',mno,p', "+i+" )") ); |
| 114 |
} |
| 115 |
|
| 116 |
for ( var i = 0; i < 15; i ++ ) { |
| 117 |
new TestCase( SECTION, |
| 118 |
"var m = Math; m.lastIndexOf = String.prototype.lastIndexOf; m.lastIndexOf('t', "+ i + ")", |
| 119 |
( i < 6 ? -1 : ( i < 10 ? 6 : 10 ) ), |
| 120 |
eval("var m = Math; m.lastIndexOf = String.prototype.lastIndexOf; m.lastIndexOf('t', "+ i + ")") ); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
test(); |
| 132 |
|
| 133 |
function LastIndexOf( string, search, position ) { |
| 134 |
string = String( string ); |
| 135 |
search = String( search ); |
| 136 |
|
| 137 |
position = Number( position ) |
| 138 |
|
| 139 |
if ( isNaN( position ) ) { |
| 140 |
position = Infinity; |
| 141 |
} else { |
| 142 |
position = ToInteger( position ); |
| 143 |
} |
| 144 |
|
| 145 |
result5= string.length; |
| 146 |
result6 = Math.min(Math.max(position, 0), result5); |
| 147 |
result7 = search.length; |
| 148 |
|
| 149 |
if (result7 == 0) { |
| 150 |
return Math.min(position, result5); |
| 151 |
} |
| 152 |
|
| 153 |
result8 = -1; |
| 154 |
|
| 155 |
for ( k = 0; k <= result6; k++ ) { |
| 156 |
if ( k+ result7 > result5 ) { |
| 157 |
break; |
| 158 |
} |
| 159 |
for ( j = 0; j < result7; j++ ) { |
| 160 |
if ( string.charAt(k+j) != search.charAt(j) ){ |
| 161 |
break; |
| 162 |
} else { |
| 163 |
if ( j == result7 -1 ) { |
| 164 |
result8 = k; |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
return result8; |
| 171 |
} |
| 172 |
function ToInteger( n ) { |
| 173 |
n = Number( n ); |
| 174 |
if ( isNaN(n) ) { |
| 175 |
return 0; |
| 176 |
} |
| 177 |
if ( Math.abs(n) == 0 || Math.abs(n) == Infinity ) { |
| 178 |
return n; |
| 179 |
} |
| 180 |
|
| 181 |
var sign = ( n < 0 ) ? -1 : 1; |
| 182 |
|
| 183 |
return ( sign * Math.floor(Math.abs(n)) ); |
| 184 |
} |