Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | File Name: 15.5.4.6-1.js |
michael@0 | 9 | ECMA Section: 15.5.4.6 String.prototype.indexOf( searchString, pos) |
michael@0 | 10 | Description: If the given searchString appears as a substring of the |
michael@0 | 11 | result of converting this object to a string, at one or |
michael@0 | 12 | more positions that are at or to the right of the |
michael@0 | 13 | specified position, then the index of the leftmost such |
michael@0 | 14 | position is returned; otherwise -1 is returned. If |
michael@0 | 15 | positionis undefined or not supplied, 0 is assumed, so |
michael@0 | 16 | as to search all of the string. |
michael@0 | 17 | |
michael@0 | 18 | When the indexOf method is called with two arguments, |
michael@0 | 19 | searchString and pos, the following steps are taken: |
michael@0 | 20 | |
michael@0 | 21 | 1. Call ToString, giving it the this value as its |
michael@0 | 22 | argument. |
michael@0 | 23 | 2. Call ToString(searchString). |
michael@0 | 24 | 3. Call ToInteger(position). (If position is undefined |
michael@0 | 25 | or not supplied, this step produces the value 0). |
michael@0 | 26 | 4. Compute the number of characters in Result(1). |
michael@0 | 27 | 5. Compute min(max(Result(3), 0), Result(4)). |
michael@0 | 28 | 6. Compute the number of characters in the string that |
michael@0 | 29 | is Result(2). |
michael@0 | 30 | 7. Compute the smallest possible integer k not smaller |
michael@0 | 31 | than Result(5) such that k+Result(6) is not greater |
michael@0 | 32 | than Result(4), and for all nonnegative integers j |
michael@0 | 33 | less than Result(6), the character at position k+j |
michael@0 | 34 | of Result(1) is the same as the character at position |
michael@0 | 35 | j of Result(2); but if there is no such integer k, |
michael@0 | 36 | then compute the value -1. |
michael@0 | 37 | 8. Return Result(7). |
michael@0 | 38 | |
michael@0 | 39 | Note that the indexOf function is intentionally generic; |
michael@0 | 40 | it does not require that its this value be a String object. |
michael@0 | 41 | Therefore it can be transferred to other kinds of objects |
michael@0 | 42 | for use as a method. |
michael@0 | 43 | |
michael@0 | 44 | Author: christine@netscape.com |
michael@0 | 45 | Date: 2 october 1997 |
michael@0 | 46 | */ |
michael@0 | 47 | var SECTION = "15.5.4.6-1"; |
michael@0 | 48 | var VERSION = "ECMA_1"; |
michael@0 | 49 | startTest(); |
michael@0 | 50 | var TITLE = "String.protoype.indexOf"; |
michael@0 | 51 | |
michael@0 | 52 | var TEST_STRING = new String( " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ); |
michael@0 | 53 | |
michael@0 | 54 | writeHeaderToLog( SECTION + " "+ TITLE); |
michael@0 | 55 | |
michael@0 | 56 | var j = 0; |
michael@0 | 57 | |
michael@0 | 58 | for ( k = 0, i = 0x0020; i < 0x007e; i++, j++, k++ ) { |
michael@0 | 59 | new TestCase( SECTION, |
michael@0 | 60 | "String.indexOf(" +String.fromCharCode(i)+ ", 0)", |
michael@0 | 61 | k, |
michael@0 | 62 | TEST_STRING.indexOf( String.fromCharCode(i), 0 ) ); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | for ( k = 0, i = 0x0020; i < 0x007e; i++, j++, k++ ) { |
michael@0 | 66 | new TestCase( SECTION, |
michael@0 | 67 | "String.indexOf("+String.fromCharCode(i)+ ", "+ k +")", |
michael@0 | 68 | k, |
michael@0 | 69 | TEST_STRING.indexOf( String.fromCharCode(i), k ) ); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | for ( k = 0, i = 0x0020; i < 0x007e; i++, j++, k++ ) { |
michael@0 | 73 | new TestCase( SECTION, |
michael@0 | 74 | "String.indexOf("+String.fromCharCode(i)+ ", "+k+1+")", |
michael@0 | 75 | -1, |
michael@0 | 76 | TEST_STRING.indexOf( String.fromCharCode(i), k+1 ) ); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | for ( k = 0, i = 0x0020; i < 0x007d; i++, j++, k++ ) { |
michael@0 | 80 | new TestCase( SECTION, |
michael@0 | 81 | "String.indexOf("+(String.fromCharCode(i) + |
michael@0 | 82 | String.fromCharCode(i+1)+ |
michael@0 | 83 | String.fromCharCode(i+2)) +", "+0+")", |
michael@0 | 84 | k, |
michael@0 | 85 | TEST_STRING.indexOf( (String.fromCharCode(i)+ |
michael@0 | 86 | String.fromCharCode(i+1)+ |
michael@0 | 87 | String.fromCharCode(i+2)), |
michael@0 | 88 | 0 ) ); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | for ( k = 0, i = 0x0020; i < 0x007d; i++, j++, k++ ) { |
michael@0 | 92 | new TestCase( SECTION, |
michael@0 | 93 | "String.indexOf("+(String.fromCharCode(i) + |
michael@0 | 94 | String.fromCharCode(i+1)+ |
michael@0 | 95 | String.fromCharCode(i+2)) +", "+ k +")", |
michael@0 | 96 | k, |
michael@0 | 97 | TEST_STRING.indexOf( (String.fromCharCode(i)+ |
michael@0 | 98 | String.fromCharCode(i+1)+ |
michael@0 | 99 | String.fromCharCode(i+2)), |
michael@0 | 100 | k ) ); |
michael@0 | 101 | } |
michael@0 | 102 | for ( k = 0, i = 0x0020; i < 0x007d; i++, j++, k++ ) { |
michael@0 | 103 | new TestCase( SECTION, |
michael@0 | 104 | "String.indexOf("+(String.fromCharCode(i) + |
michael@0 | 105 | String.fromCharCode(i+1)+ |
michael@0 | 106 | String.fromCharCode(i+2)) +", "+ k+1 +")", |
michael@0 | 107 | -1, |
michael@0 | 108 | TEST_STRING.indexOf( (String.fromCharCode(i)+ |
michael@0 | 109 | String.fromCharCode(i+1)+ |
michael@0 | 110 | String.fromCharCode(i+2)), |
michael@0 | 111 | k+1 ) ); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | new TestCase( SECTION, "String.indexOf(" +TEST_STRING + ", 0 )", 0, TEST_STRING.indexOf( TEST_STRING, 0 ) ); |
michael@0 | 115 | |
michael@0 | 116 | new TestCase( SECTION, "String.indexOf(" +TEST_STRING + ", 1 )", -1, TEST_STRING.indexOf( TEST_STRING, 1 )); |
michael@0 | 117 | |
michael@0 | 118 | print( "TEST_STRING = new String(\" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\")" ); |
michael@0 | 119 | |
michael@0 | 120 | |
michael@0 | 121 | test(); |