OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 // |
| 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions |
| 6 // are met: |
| 7 // 1. Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. |
| 9 // 2. Redistributions in binary form must reproduce the above copyright |
| 10 // notice, this list of conditions and the following disclaimer in the |
| 11 // documentation and/or other materials provided with the distribution. |
| 12 // |
| 13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 |
| 24 description( |
| 25 "This test checks that using the typeof operator on a JavaScript value and compa
ring it to a constant string works as expected." |
| 26 ); |
| 27 |
| 28 function isUndefined(a) |
| 29 { |
| 30 return typeof a == "undefined"; |
| 31 } |
| 32 |
| 33 shouldBeTrue("isUndefined(undefined)"); |
| 34 shouldBeFalse("isUndefined(1)"); |
| 35 |
| 36 function isUndefinedStrict(a) |
| 37 { |
| 38 return typeof a === "undefined"; |
| 39 } |
| 40 |
| 41 shouldBeTrue("isUndefinedStrict(undefined)"); |
| 42 shouldBeFalse("isUndefinedStrict(1)"); |
| 43 |
| 44 function isBoolean(a) |
| 45 { |
| 46 return typeof a == "boolean"; |
| 47 } |
| 48 |
| 49 shouldBeTrue("isBoolean(true)"); |
| 50 shouldBeTrue("isBoolean(false)"); |
| 51 shouldBeFalse("isBoolean(1)"); |
| 52 |
| 53 function isBooleanStrict(a) |
| 54 { |
| 55 return typeof a === "boolean"; |
| 56 } |
| 57 |
| 58 shouldBeTrue("isBooleanStrict(true)"); |
| 59 shouldBeTrue("isBooleanStrict(false)"); |
| 60 shouldBeFalse("isBooleanStrict(1)"); |
| 61 |
| 62 function isNumber(a) |
| 63 { |
| 64 return typeof a == "number"; |
| 65 } |
| 66 |
| 67 shouldBeTrue("isNumber(1)"); |
| 68 shouldBeFalse("isNumber(undefined)"); |
| 69 |
| 70 function isNumberStrict(a) |
| 71 { |
| 72 return typeof a === "number"; |
| 73 } |
| 74 |
| 75 shouldBeTrue("isNumberStrict(1)"); |
| 76 shouldBeFalse("isNumberStrict(undefined)"); |
| 77 |
| 78 function isString(a) |
| 79 { |
| 80 return typeof a == "string"; |
| 81 } |
| 82 |
| 83 shouldBeTrue("isString('string')"); |
| 84 shouldBeFalse("isString(1)"); |
| 85 |
| 86 function isStringStrict(a) |
| 87 { |
| 88 return typeof a === "string"; |
| 89 } |
| 90 |
| 91 shouldBeTrue("isStringStrict('string')"); |
| 92 shouldBeFalse("isStringStrict(1)"); |
| 93 |
| 94 function isObject(a) |
| 95 { |
| 96 return typeof a == "object"; |
| 97 } |
| 98 |
| 99 shouldBeTrue("isObject({ })"); |
| 100 shouldBeFalse("isObject(1)"); |
| 101 |
| 102 function isObjectStrict(a) |
| 103 { |
| 104 return typeof a === "object"; |
| 105 } |
| 106 |
| 107 shouldBeTrue("isObjectStrict({ })"); |
| 108 shouldBeFalse("isObjectStrict(1)"); |
| 109 |
| 110 function isFunction(a) |
| 111 { |
| 112 return typeof a == "function"; |
| 113 } |
| 114 |
| 115 shouldBeTrue("isFunction(function () { })"); |
| 116 shouldBeFalse("isFunction(1)"); |
| 117 |
| 118 function isFunctionStrict(a) |
| 119 { |
| 120 return typeof a === "function"; |
| 121 } |
| 122 |
| 123 shouldBeTrue("isFunctionStrict(function () { })"); |
| 124 shouldBeFalse("isFunctionStrict(1)"); |
| 125 |
| 126 function complexIsUndefinedTest() |
| 127 { |
| 128 function replace_formats() { |
| 129 var o = ["text", 0]; |
| 130 if (typeof o == "string") { |
| 131 } else if (typeof o == "undefined") { |
| 132 } else if (typeof o == "object" && typeof o[0] == "string") { |
| 133 return "PASS"; |
| 134 } |
| 135 return "FAIL"; |
| 136 }; |
| 137 |
| 138 return "%d".replace(/%d/, replace_formats); |
| 139 } |
| 140 shouldBe("complexIsUndefinedTest()", "'PASS'"); |
| 141 |
| 142 function complexIsBooleanTest() |
| 143 { |
| 144 function replace_formats() { |
| 145 var o = ["text", 0]; |
| 146 if (typeof o == "string") { |
| 147 } else if (typeof o == "boolean") { |
| 148 } else if (typeof o == "object" && typeof o[0] == "string") { |
| 149 return "PASS"; |
| 150 } |
| 151 return "FAIL"; |
| 152 }; |
| 153 |
| 154 return "%d".replace(/%d/, replace_formats); |
| 155 } |
| 156 shouldBe("complexIsBooleanTest()", "'PASS'"); |
| 157 |
| 158 function complexIsNumberTest() |
| 159 { |
| 160 function replace_formats() { |
| 161 var o = ["text", 0]; |
| 162 if (typeof o == "string") { |
| 163 } else if (typeof o == "number") { |
| 164 } else if (typeof o == "object" && typeof o[0] == "string") { |
| 165 return "PASS"; |
| 166 } |
| 167 return "FAIL"; |
| 168 }; |
| 169 |
| 170 return "%d".replace(/%d/, replace_formats); |
| 171 } |
| 172 shouldBe("complexIsNumberTest()", "'PASS'"); |
| 173 |
| 174 function complexIsStringTest() |
| 175 { |
| 176 function replace_formats() { |
| 177 var o = ["text", 0]; |
| 178 if (typeof o == "string") { |
| 179 } else if (typeof o == "string") { |
| 180 } else if (typeof o == "object" && typeof o[0] == "string") { |
| 181 return "PASS"; |
| 182 } |
| 183 return "FAIL"; |
| 184 }; |
| 185 |
| 186 return "%d".replace(/%d/, replace_formats); |
| 187 } |
| 188 shouldBe("complexIsStringTest()", "'PASS'"); |
| 189 |
| 190 function complexIsObjectTest() |
| 191 { |
| 192 var a = ["text", 0]; |
| 193 function replace_formats() { |
| 194 var o = function () { }; |
| 195 if (typeof o == "string") { |
| 196 } else if (typeof o == "object") { |
| 197 } else if (typeof o == "function" && typeof a[0] == "string") { |
| 198 return "PASS"; |
| 199 } |
| 200 return "FAIL"; |
| 201 }; |
| 202 |
| 203 return "%d".replace(/%d/, replace_formats); |
| 204 } |
| 205 shouldBe("complexIsObjectTest()", "'PASS'"); |
| 206 |
| 207 function complexIsFunctionTest() |
| 208 { |
| 209 function replace_formats() { |
| 210 var o = ["text", 0]; |
| 211 if (typeof o == "string") { |
| 212 } else if (typeof o == "function") { |
| 213 } else if (typeof o == "object" && typeof o[0] == "string") { |
| 214 return "PASS"; |
| 215 } |
| 216 return "FAIL"; |
| 217 }; |
| 218 |
| 219 return "%d".replace(/%d/, replace_formats); |
| 220 } |
| 221 shouldBe("complexIsFunctionTest()", "'PASS'"); |
| 222 |
| 223 function complexIsUndefinedStrictTest() |
| 224 { |
| 225 function replace_formats() { |
| 226 var o = ["text", 0]; |
| 227 if (typeof o == "string") { |
| 228 } else if (typeof o === "undefined") { |
| 229 } else if (typeof o == "object" && typeof o[0] == "string") { |
| 230 return "PASS"; |
| 231 } |
| 232 return "FAIL"; |
| 233 }; |
| 234 |
| 235 return "%d".replace(/%d/, replace_formats); |
| 236 } |
| 237 shouldBe("complexIsUndefinedStrictTest()", "'PASS'"); |
| 238 |
| 239 function complexIsBooleanStrictTest() |
| 240 { |
| 241 function replace_formats() { |
| 242 var o = ["text", 0]; |
| 243 if (typeof o == "string") { |
| 244 } else if (typeof o === "boolean") { |
| 245 } else if (typeof o == "object" && typeof o[0] == "string") { |
| 246 return "PASS"; |
| 247 } |
| 248 return "FAIL"; |
| 249 }; |
| 250 |
| 251 return "%d".replace(/%d/, replace_formats); |
| 252 } |
| 253 shouldBe("complexIsBooleanStrictTest()", "'PASS'"); |
| 254 |
| 255 function complexIsNumberStrictTest() |
| 256 { |
| 257 function replace_formats() { |
| 258 var o = ["text", 0]; |
| 259 if (typeof o == "string") { |
| 260 } else if (typeof o === "number") { |
| 261 } else if (typeof o == "object" && typeof o[0] == "string") { |
| 262 return "PASS"; |
| 263 } |
| 264 return "FAIL"; |
| 265 }; |
| 266 |
| 267 return "%d".replace(/%d/, replace_formats); |
| 268 } |
| 269 shouldBe("complexIsNumberStrictTest()", "'PASS'"); |
| 270 |
| 271 function complexIsStringStrictTest() |
| 272 { |
| 273 function replace_formats() { |
| 274 var o = ["text", 0]; |
| 275 if (typeof o == "string") { |
| 276 } else if (typeof o === "string") { |
| 277 } else if (typeof o == "object" && typeof o[0] == "string") { |
| 278 return "PASS"; |
| 279 } |
| 280 return "FAIL"; |
| 281 }; |
| 282 |
| 283 return "%d".replace(/%d/, replace_formats); |
| 284 } |
| 285 shouldBe("complexIsStringStrictTest()", "'PASS'"); |
| 286 |
| 287 function complexIsObjectStrictTest() |
| 288 { |
| 289 var a = ["text", 0]; |
| 290 function replace_formats() { |
| 291 var o = function () { }; |
| 292 if (typeof o == "string") { |
| 293 } else if (typeof o === "object") { |
| 294 } else if (typeof o == "function" && typeof a[0] == "string") { |
| 295 return "PASS"; |
| 296 } |
| 297 return "FAIL"; |
| 298 }; |
| 299 |
| 300 return "%d".replace(/%d/, replace_formats); |
| 301 } |
| 302 shouldBe("complexIsObjectStrictTest()", "'PASS'"); |
| 303 |
| 304 function complexIsFunctionStrictTest() |
| 305 { |
| 306 function replace_formats() { |
| 307 var o = ["text", 0]; |
| 308 if (typeof o == "string") { |
| 309 } else if (typeof o === "function") { |
| 310 } else if (typeof o == "object" && typeof o[0] == "string") { |
| 311 return "PASS"; |
| 312 } |
| 313 return "FAIL"; |
| 314 }; |
| 315 |
| 316 return "%d".replace(/%d/, replace_formats); |
| 317 } |
| 318 shouldBe("complexIsFunctionStrictTest()", "'PASS'"); |
OLD | NEW |