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.9-1.js |
michael@0 | 9 | ECMA Section: 15.5.4.9 String.prototype.substring( start ) |
michael@0 | 10 | Description: |
michael@0 | 11 | |
michael@0 | 12 | 15.5.4.9 String.prototype.substring(start) |
michael@0 | 13 | |
michael@0 | 14 | Returns a substring of the result of converting this object to a string, |
michael@0 | 15 | starting from character position start and running to the end of the |
michael@0 | 16 | string. The result is a string value, not a String object. |
michael@0 | 17 | |
michael@0 | 18 | If the argument is NaN or negative, it is replaced with zero; if the |
michael@0 | 19 | argument is larger than the length of the string, it is replaced with the |
michael@0 | 20 | length of the string. |
michael@0 | 21 | |
michael@0 | 22 | When the substring method is called with one argument start, the following |
michael@0 | 23 | steps are taken: |
michael@0 | 24 | |
michael@0 | 25 | 1.Call ToString, giving it the this value as its argument. |
michael@0 | 26 | 2.Call ToInteger(start). |
michael@0 | 27 | 3.Compute the number of characters in Result(1). |
michael@0 | 28 | 4.Compute min(max(Result(2), 0), Result(3)). |
michael@0 | 29 | 5.Return a string whose length is the difference between Result(3) and Result(4), |
michael@0 | 30 | containing characters from Result(1), namely the characters with indices Result(4) |
michael@0 | 31 | through Result(3)1, in ascending order. |
michael@0 | 32 | |
michael@0 | 33 | Author: christine@netscape.com |
michael@0 | 34 | Date: 12 november 1997 |
michael@0 | 35 | */ |
michael@0 | 36 | |
michael@0 | 37 | var SECTION = "15.5.4.9-1"; |
michael@0 | 38 | var VERSION = "ECMA_1"; |
michael@0 | 39 | startTest(); |
michael@0 | 40 | var TITLE = "String.prototype.substring( start )"; |
michael@0 | 41 | |
michael@0 | 42 | writeHeaderToLog( SECTION + " "+ TITLE); |
michael@0 | 43 | |
michael@0 | 44 | new TestCase( SECTION, "String.prototype.substring.length", 2, String.prototype.substring.length ); |
michael@0 | 45 | new TestCase( SECTION, "delete String.prototype.substring.length", false, delete String.prototype.substring.length ); |
michael@0 | 46 | new TestCase( SECTION, "delete String.prototype.substring.length; String.prototype.substring.length", 2, eval("delete String.prototype.substring.length; String.prototype.substring.length") ); |
michael@0 | 47 | |
michael@0 | 48 | // test cases for when substring is called with no arguments. |
michael@0 | 49 | |
michael@0 | 50 | // this is a string object |
michael@0 | 51 | |
michael@0 | 52 | new TestCase( SECTION, |
michael@0 | 53 | "var s = new String('this is a string object'); typeof s.substring()", |
michael@0 | 54 | "string", |
michael@0 | 55 | eval("var s = new String('this is a string object'); typeof s.substring()") ); |
michael@0 | 56 | |
michael@0 | 57 | new TestCase( SECTION, |
michael@0 | 58 | "var s = new String(''); s.substring()", |
michael@0 | 59 | "", |
michael@0 | 60 | eval("var s = new String(''); s.substring()") ); |
michael@0 | 61 | |
michael@0 | 62 | |
michael@0 | 63 | new TestCase( SECTION, |
michael@0 | 64 | "var s = new String('this is a string object'); s.substring()", |
michael@0 | 65 | "this is a string object", |
michael@0 | 66 | eval("var s = new String('this is a string object'); s.substring()") ); |
michael@0 | 67 | |
michael@0 | 68 | new TestCase( SECTION, |
michael@0 | 69 | "var s = new String('this is a string object'); s.substring(NaN)", |
michael@0 | 70 | "this is a string object", |
michael@0 | 71 | eval("var s = new String('this is a string object'); s.substring(NaN)") ); |
michael@0 | 72 | |
michael@0 | 73 | |
michael@0 | 74 | new TestCase( SECTION, |
michael@0 | 75 | "var s = new String('this is a string object'); s.substring(-0.01)", |
michael@0 | 76 | "this is a string object", |
michael@0 | 77 | eval("var s = new String('this is a string object'); s.substring(-0.01)") ); |
michael@0 | 78 | |
michael@0 | 79 | |
michael@0 | 80 | new TestCase( SECTION, |
michael@0 | 81 | "var s = new String('this is a string object'); s.substring(s.length)", |
michael@0 | 82 | "", |
michael@0 | 83 | eval("var s = new String('this is a string object'); s.substring(s.length)") ); |
michael@0 | 84 | |
michael@0 | 85 | new TestCase( SECTION, |
michael@0 | 86 | "var s = new String('this is a string object'); s.substring(s.length+1)", |
michael@0 | 87 | "", |
michael@0 | 88 | eval("var s = new String('this is a string object'); s.substring(s.length+1)") ); |
michael@0 | 89 | |
michael@0 | 90 | |
michael@0 | 91 | new TestCase( SECTION, |
michael@0 | 92 | "var s = new String('this is a string object'); s.substring(Infinity)", |
michael@0 | 93 | "", |
michael@0 | 94 | eval("var s = new String('this is a string object'); s.substring(Infinity)") ); |
michael@0 | 95 | |
michael@0 | 96 | new TestCase( SECTION, |
michael@0 | 97 | "var s = new String('this is a string object'); s.substring(-Infinity)", |
michael@0 | 98 | "this is a string object", |
michael@0 | 99 | eval("var s = new String('this is a string object'); s.substring(-Infinity)") ); |
michael@0 | 100 | |
michael@0 | 101 | // this is not a String object, start is not an integer |
michael@0 | 102 | |
michael@0 | 103 | |
michael@0 | 104 | new TestCase( SECTION, |
michael@0 | 105 | "var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring()", |
michael@0 | 106 | "1,2,3,4,5", |
michael@0 | 107 | eval("var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring()") ); |
michael@0 | 108 | |
michael@0 | 109 | new TestCase( SECTION, |
michael@0 | 110 | "var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring(true)", |
michael@0 | 111 | ",2,3,4,5", |
michael@0 | 112 | eval("var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring(true)") ); |
michael@0 | 113 | |
michael@0 | 114 | new TestCase( SECTION, |
michael@0 | 115 | "var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring('4')", |
michael@0 | 116 | "3,4,5", |
michael@0 | 117 | eval("var s = new Array(1,2,3,4,5); s.substring = String.prototype.substring; s.substring('4')") ); |
michael@0 | 118 | |
michael@0 | 119 | new TestCase( SECTION, |
michael@0 | 120 | "var s = new Array(); s.substring = String.prototype.substring; s.substring('4')", |
michael@0 | 121 | "", |
michael@0 | 122 | eval("var s = new Array(); s.substring = String.prototype.substring; s.substring('4')") ); |
michael@0 | 123 | |
michael@0 | 124 | // this is an object object |
michael@0 | 125 | new TestCase( SECTION, |
michael@0 | 126 | "var obj = new Object(); obj.substring = String.prototype.substring; obj.substring(8)", |
michael@0 | 127 | "Object]", |
michael@0 | 128 | eval("var obj = new Object(); obj.substring = String.prototype.substring; obj.substring(8)") ); |
michael@0 | 129 | |
michael@0 | 130 | // this is a function object |
michael@0 | 131 | new TestCase( SECTION, |
michael@0 | 132 | "var obj = new Function(); obj.substring = String.prototype.substring; obj.toString = Object.prototype.toString; obj.substring(8)", |
michael@0 | 133 | "Function]", |
michael@0 | 134 | eval("var obj = new Function(); obj.substring = String.prototype.substring; obj.toString = Object.prototype.toString; obj.substring(8)") ); |
michael@0 | 135 | // this is a number object |
michael@0 | 136 | new TestCase( SECTION, |
michael@0 | 137 | "var obj = new Number(NaN); obj.substring = String.prototype.substring; obj.substring(false)", |
michael@0 | 138 | "NaN", |
michael@0 | 139 | eval("var obj = new Number(NaN); obj.substring = String.prototype.substring; obj.substring(false)") ); |
michael@0 | 140 | |
michael@0 | 141 | // this is the Math object |
michael@0 | 142 | new TestCase( SECTION, |
michael@0 | 143 | "var obj = Math; obj.substring = String.prototype.substring; obj.substring(Math.PI)", |
michael@0 | 144 | "ject Math]", |
michael@0 | 145 | eval("var obj = Math; obj.substring = String.prototype.substring; obj.substring(Math.PI)") ); |
michael@0 | 146 | |
michael@0 | 147 | // this is a Boolean object |
michael@0 | 148 | |
michael@0 | 149 | new TestCase( SECTION, |
michael@0 | 150 | "var obj = new Boolean(); obj.substring = String.prototype.substring; obj.substring(new Array())", |
michael@0 | 151 | "false", |
michael@0 | 152 | eval("var obj = new Boolean(); obj.substring = String.prototype.substring; obj.substring(new Array())") ); |
michael@0 | 153 | |
michael@0 | 154 | // this is a user defined object |
michael@0 | 155 | |
michael@0 | 156 | new TestCase( SECTION, |
michael@0 | 157 | "var obj = new MyObject( null ); obj.substring(0)", |
michael@0 | 158 | "null", |
michael@0 | 159 | eval( "var obj = new MyObject( null ); obj.substring(0)") ); |
michael@0 | 160 | |
michael@0 | 161 | |
michael@0 | 162 | test(); |
michael@0 | 163 | |
michael@0 | 164 | function MyObject( value ) { |
michael@0 | 165 | this.value = value; |
michael@0 | 166 | this.substring = String.prototype.substring; |
michael@0 | 167 | this.toString = new Function ( "return this.value+''" ); |
michael@0 | 168 | } |