1/* 2 * Copyright 2008 Jacek Caban for CodeWeavers 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 19var tmp, i; 20 21var bigInt = Math.pow(2,40); 22 23ok(ScriptEngine() === "JScript", "ScriptEngine() = " + ScriptEngine()); 24ok(ScriptEngine(3) === "JScript", "ScriptEngine(3) = " + ScriptEngine(3)); 25ok(ScriptEngineMajorVersion() === ScriptEngineMajorVersion(2), "ScriptEngineMajorVersion() !== ScriptEngineMajorVersion(2)"); 26ok(ScriptEngineMinorVersion() === ScriptEngineMinorVersion(2), "ScriptEngineMinorVersion() !== ScriptEngineMinorVersion(2)"); 27ok(ScriptEngineBuildVersion() === ScriptEngineBuildVersion(2), "ScriptEngineBuildVersion() !== ScriptEngineBuildVersion(2)"); 28 29function testNoEnumerables(expr) { 30 for(var iter in obj) 31 ok(false, expr + " has property " + iter); 32} 33 34testNoEnumerables("Object"); 35testNoEnumerables("Object.prototype"); 36testNoEnumerables("new Object()"); 37testNoEnumerables("Math"); 38testNoEnumerables("String"); 39testNoEnumerables("String.prototype"); 40testNoEnumerables("new String()"); 41testNoEnumerables("Number"); 42testNoEnumerables("Number.prototype"); 43testNoEnumerables("new Number(1)"); 44testNoEnumerables("ActiveXObject"); 45testNoEnumerables("Array"); 46testNoEnumerables("Array.prototype"); 47testNoEnumerables("new Array()"); 48testNoEnumerables("Boolean"); 49testNoEnumerables("Boolean.prototype"); 50testNoEnumerables("new Boolean()"); 51testNoEnumerables("Date"); 52testNoEnumerables("Date.prototype"); 53testNoEnumerables("new Date()"); 54testNoEnumerables("TypeError"); 55testNoEnumerables("TypeError.prototype"); 56testNoEnumerables("new TypeError()"); 57testNoEnumerables("Function"); 58testNoEnumerables("Function.prototype"); 59testNoEnumerables("testNoEnumerates"); 60testNoEnumerables("VBArray"); 61 62ok(Object.propertyIsEnumerable("prototype") === false, "Object.prototype is enumerable"); 63ok(Math.propertyIsEnumerable("E") === false, "Math.E is enumerable"); 64ok(Math.propertyIsEnumerable("SQRT2") === false, "Math.SQRT2 is enumerable"); 65ok(Math.propertyIsEnumerable("PI") === false, "Math.PI is enumerable"); 66ok("test".propertyIsEnumerable("length") === false, "'test'.length is enumerable"); 67ok([1].propertyIsEnumerable("length") === false, "[1].length is enumerable"); 68ok((new TypeError()).propertyIsEnumerable("message") === true, "(new TypeError()).message is not enumerable"); 69ok((new TypeError()).propertyIsEnumerable("description") === false, "(new TypeError()).description is enumerable"); 70ok((new TypeError()).propertyIsEnumerable("name") === false, "(new TypeError()).name is enumerable"); 71ok((new TypeError()).propertyIsEnumerable("number") === false, "(new TypeError()).number is enumerable"); 72ok(Object.propertyIsEnumerable.propertyIsEnumerable("length") === false, "Object.propertyIsEnumerable.length is enumerable"); 73 74tmp = new Object(); 75tmp.test = "1"; 76ok(tmp.propertyIsEnumerable("test"), "tmp.test is not enumerable"); 77 78tmp = { test: 1 }; 79ok(tmp.propertyIsEnumerable("test"), "tmp.test is not enumerable"); 80 81ok([1].concat([2]).propertyIsEnumerable("1"), "[1].concat([2]).1 is not enumerable"); 82ok("t.e.s.t".split(".").propertyIsEnumerable("0"), "'test'.split().0 is not enumerable"); 83 84(function() { 85 ok(arguments.propertyIsEnumerable("0") === false, "arguments.0 is enumerable"); 86 ok(arguments.propertyIsEnumerable("length") === false, "arguments.length is enumerable"); 87 ok(arguments.propertyIsEnumerable("calee") === false, "arguments.calee is enumerable"); 88})(); 89 90tmp = [1]; 91tmp.push(""); 92ok(tmp.propertyIsEnumerable("1"), "[1].push() ... 1 is not enumerable"); 93 94ok([1,2].reverse().propertyIsEnumerable("1"), "[1,2].rverse().1 is not enumerable"); 95ok([1,2].propertyIsEnumerable("0"), "[1,2].0 is not enumerable"); 96 97i = parseInt("0"); 98ok(i === 0, "parseInt('0') = " + i); 99i = parseInt("123"); 100ok(i === 123, "parseInt('123') = " + i); 101i = parseInt("-123"); 102ok(i === -123, "parseInt('-123') = " + i); 103i = parseInt("0xff"); 104ok(i === 0xff, "parseInt('0xff') = " + i); 105i = parseInt("11", 8); 106ok(i === 9, "parseInt('11', 8) = " + i); 107i = parseInt("1j", 22); 108ok(i === 41, "parseInt('1j', 32) = " + i); 109i = parseInt("123", 0); 110ok(i === 123, "parseInt('123', 0) = " + i); 111i = parseInt("123", 10, "test"); 112ok(i === 123, "parseInt('123', 10, 'test') = " + i); 113i = parseInt("11", "8"); 114ok(i === 9, "parseInt('11', '8') = " + i); 115i = parseInt("010"); 116ok(i === 8, "parseInt('010') = " + i); 117i = parseInt(""); 118ok(isNaN(i), "parseInt('') = " + i); 119i = parseInt("0x"); 120ok(isNaN(i), "parseInt('0x') = " + i); 121i = parseInt("+"); 122ok(isNaN(i), "parseInt('+') = " + i); 123i = parseInt("-"); 124ok(isNaN(i), "parseInt('-') = " + i); 125i = parseInt("0x10", 11); 126ok(i === 0, "parseInt('0x10', 11) = " + i); 127i = parseInt("010", 7); 128ok(i === 7, "parseInt('010', 7) = " + i); 129i = parseInt("123abc"); 130ok(i === 123, "parseInt('123abc') = " + i); 131i = parseInt(" \t123abc"); 132ok(i === 123, "parseInt(' \\t123abc') = " + i); 133i = parseInt("abc"); 134ok(isNaN(i), "parseInt('123abc') = " + i); 135i = parseInt("-12", 11); 136ok(i === -13, "parseInt('-12') = " + i); 137i = parseInt("-0x10"); 138ok(i === -16, "parseInt('-0x10') = " + i); 139i = parseInt("-010"); 140ok(i === -8, "parseInt('-010') = " + i); 141i = parseInt("123", 0); 142ok(i === 123, "parseInt('123', 0) = " + i); 143i = parseInt("0x10", 0); 144ok(i === 16, "parseInt('123', 0) = " + i); 145i = parseInt("0x10", 10); 146ok(i === 0, "parseInt('0x10', 10) = " + i); 147i = parseInt("0xz"); 148ok(isNaN(i), "parseInt('0xz') = " + i); 149i = parseInt("1", 1); 150ok(isNaN(i), "parseInt('1', 1) = " + i); 151i = parseInt("1", -1); 152ok(isNaN(i), "parseInt('1', -1) = " + i); 153i = parseInt("1", 37); 154ok(isNaN(i), "parseInt('1', 37) = " + i); 155i = parseInt("1", 36); 156ok(i === 1, "parseInt('1', 36) = " + i); 157 158tmp = encodeURI("abc"); 159ok(tmp === "abc", "encodeURI('abc') = " + tmp); 160tmp = encodeURI("{abc}"); 161ok(tmp === "%7Babc%7D", "encodeURI('{abc}') = " + tmp); 162tmp = encodeURI(""); 163ok(tmp === "", "encodeURI('') = " + tmp); 164tmp = encodeURI("\01\02\03\04"); 165ok(tmp === "%01%02%03%04", "encodeURI('\\01\\02\\03\\04') = " + tmp); 166tmp = encodeURI("{#@}"); 167ok(tmp === "%7B#@%7D", "encodeURI('{#@}') = " + tmp); 168tmp = encodeURI("\xa1 "); 169ok(tmp === "%C2%A1%20", "encodeURI(\\xa1 ) = " + tmp); 170tmp = encodeURI("\xffff"); 171ok(tmp.length === 8, "encodeURI('\\xffff').length = " + tmp.length); 172tmp = encodeURI("abcABC123;/?:@&=+$,-_.!~*'()"); 173ok(tmp === "abcABC123;/?:@&=+$,-_.!~*'()", "encodeURI('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp); 174tmp = encodeURI("%"); 175ok(tmp === "%25", "encodeURI('%') = " + tmp); 176tmp = encodeURI(); 177ok(tmp === "undefined", "encodeURI() = " + tmp); 178tmp = encodeURI("abc", "test"); 179ok(tmp === "abc", "encodeURI('abc') = " + tmp); 180 181tmp = decodeURI("abc"); 182ok(tmp === "abc", "decodeURI('abc') = " + tmp); 183tmp = decodeURI("{abc}"); 184ok(tmp === "{abc}", "decodeURI('{abc}') = " + tmp); 185tmp = decodeURI(""); 186ok(tmp === "", "decodeURI('') = " + tmp); 187tmp = decodeURI("\01\02\03\04"); 188ok(tmp === "\01\02\03\04", "decodeURI('\\01\\02\\03\\04') = " + tmp); 189tmp = decodeURI(); 190ok(tmp === "undefined", "decodeURI() = " + tmp); 191tmp = decodeURI("abc", "test"); 192ok(tmp === "abc", "decodeURI('abc') = " + tmp); 193tmp = decodeURI("%7babc%7d"); 194ok(tmp === "{abc}", "decodeURI('%7Babc%7D') = " + tmp); 195tmp = decodeURI("%01%02%03%04"); 196ok(tmp === "\01\02\03\04", "decodeURI('%01%02%03%04') = " + tmp); 197tmp = decodeURI("%C2%A1%20"); 198ok(tmp === "\xa1 ", "decodeURI('%C2%A1%20') = " + tmp); 199tmp = decodeURI("%C3%BFff"); 200ok(tmp.length === 3, "decodeURI('%C3%BFff').length = " + tmp.length); 201 202tmp = encodeURIComponent("abc"); 203ok(tmp === "abc", "encodeURIComponent('abc') = " + tmp); 204dec = decodeURIComponent(tmp); 205ok(dec === "abc", "decodeURIComponent('" + tmp + "') = " + dec); 206tmp = encodeURIComponent("{abc}"); 207ok(tmp === "%7Babc%7D", "encodeURIComponent('{abc}') = " + tmp); 208dec = decodeURIComponent(tmp); 209ok(dec === "{abc}", "decodeURIComponent('" + tmp + "') = " + dec); 210tmp = encodeURIComponent(""); 211ok(tmp === "", "encodeURIComponent('') = " + tmp); 212dec = decodeURIComponent(tmp); 213ok(dec === "", "decodeURIComponent('" + tmp + "') = " + dec); 214tmp = encodeURIComponent("\01\02\03\04"); 215ok(tmp === "%01%02%03%04", "encodeURIComponent('\\01\\02\\03\\04') = " + tmp); 216dec = decodeURIComponent(tmp); 217ok(dec === "\01\02\03\04", "decodeURIComponent('" + tmp + "') = " + dec); 218tmp = encodeURIComponent("{#@}"); 219ok(tmp === "%7B%23%40%7D", "encodeURIComponent('{#@}') = " + tmp); 220dec = decodeURIComponent(tmp); 221ok(dec === "{#@}", "decodeURIComponent('" + tmp + "') = " + dec); 222tmp = encodeURIComponent("\xa1 "); 223ok(tmp === "%C2%A1%20", "encodeURIComponent(\\xa1 ) = " + tmp); 224dec = decodeURIComponent(tmp); 225ok(dec === "\xa1 ", "decodeURIComponent('" + tmp + "') = " + dec); 226tmp = encodeURIComponent("\xffff"); 227ok(tmp.length === 8, "encodeURIComponent('\\xffff').length = " + tmp.length); 228dec = decodeURIComponent(tmp); 229ok(dec === "\xffff", "decodeURIComponent('" + tmp + "') = " + dec); 230tmp = encodeURIComponent("abcABC123;/?:@&=+$,-_.!~*'()"); 231ok(tmp === "abcABC123%3B%2F%3F%3A%40%26%3D%2B%24%2C-_.!~*'()", "encodeURIComponent('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp); 232dec = decodeURIComponent(tmp); 233ok(dec === "abcABC123;/?:@&=+$,-_.!~*'()", "decodeURIComponent('" + tmp + "') = " + dec); 234tmp = encodeURIComponent(); 235ok(tmp === "undefined", "encodeURIComponent() = " + tmp); 236tmp = encodeURIComponent("abc", "test"); 237ok(tmp === "abc", "encodeURIComponent('abc') = " + tmp); 238dec = decodeURIComponent(); 239ok(dec === "undefined", "decodeURIComponent() = " + dec); 240dec = decodeURIComponent("abc", "test"); 241ok(dec === "abc", "decodeURIComponent('abc') = " + dec); 242 243tmp = escape("abc"); 244ok(tmp === "abc", "escape('abc') = " + tmp); 245tmp = escape(""); 246ok(tmp === "", "escape('') = " + tmp); 247tmp = escape("a1b c!d+e@*-_+./,"); 248ok(tmp === "a1b%20c%21d+e@*-_+./%2C", "escape('a1b c!d+e@*-_+./,') = " + tmp); 249tmp = escape(); 250ok(tmp === "undefined", "escape() = " + tmp); 251tmp = escape('\u1234\123\xf3'); 252ok(tmp == "%u1234S%F3", "escape('\u1234\123\xf3') = " + tmp); 253 254tmp = unescape("abc"); 255ok(tmp === "abc", "unescape('abc') = " + tmp); 256tmp = unescape(""); 257ok(tmp === "", "unescape('') = " + tmp); 258tmp = unescape("%%%"); 259ok(tmp === "%%%", "unescape('%%%') = " + tmp); 260tmp = unescape(); 261ok(tmp === "undefined", "unescape() = " + tmp); 262tmp = unescape("%54%65s%u0074"); 263ok(tmp === "Test", "unescape('%54%65s%u0074') = " + tmp); 264 265tmp = "aA1~`!@#$%^&*()_+=-][{}';:/.,<>?\|"; 266ok(escape(tmp) === "aA1%7E%60%21@%23%24%25%5E%26*%28%29_+%3D-%5D%5B%7B%7D%27%3B%3A/.%2C%3C%3E%3F%7C", "escape('" + tmp + "') = " + escape(tmp)); 267ok(unescape(escape(tmp)) === tmp, "unescape(escape('" + tmp + "')) = " + unescape(escape(tmp))); 268 269ok(Object.prototype.hasOwnProperty('toString'), "Object.prototype.hasOwnProperty('toString') is false"); 270ok(Object.prototype.hasOwnProperty('isPrototypeOf'), "Object.prototype.hasOwnProperty('isPrototypeOf') is false"); 271ok(Function.prototype.hasOwnProperty('call'), "Function.prototype.hasOwnProperty('call') is false"); 272 273obj = new Object(); 274 275ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true"); 276ok(!obj.hasOwnProperty('isPrototypeOf'), "obj.hasOwnProperty('isPrototypeOf') is true"); 277ok(!Object.hasOwnProperty('toString'), "Object.hasOwnProperty('toString') is true"); 278ok(!Object.hasOwnProperty('isPrototypeOf'), "Object.hasOwnProperty('isPrototypeOf') is true"); 279ok(!parseFloat.hasOwnProperty('call'), "parseFloat.hasOwnProperty('call') is true"); 280ok(!Function.hasOwnProperty('call'), "Function.hasOwnProperty('call') is true"); 281 282obj = new Array(); 283ok(Array.prototype.hasOwnProperty('sort'), "Array.prototype.hasOwnProperty('sort') is false"); 284ok(Array.prototype.hasOwnProperty('length'), "Array.prototype.hasOwnProperty('length') is false"); 285ok(!obj.hasOwnProperty('sort'), "obj.hasOwnProperty('sort') is true"); 286ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is true"); 287 288obj = new Boolean(false); 289ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true"); 290ok(!Boolean.hasOwnProperty('toString'), "Boolean.hasOwnProperty('toString') is true"); 291ok(Boolean.prototype.hasOwnProperty('toString'), "Boolean.prototype.hasOwnProperty('toString') is false"); 292 293obj = new Date(); 294ok(!obj.hasOwnProperty('getTime'), "obj.hasOwnProperty('getTime') is true"); 295ok(!Date.hasOwnProperty('getTime'), "Date.hasOwnProperty('getTime') is true"); 296ok(Date.prototype.hasOwnProperty('getTime'), "Date.prototype.hasOwnProperty('getTime') is false"); 297 298obj = new Number(); 299ok(!obj.hasOwnProperty('toFixed'), "obj.hasOwnProperty('toFixed') is true"); 300ok(!Number.hasOwnProperty('toFixed'), "Number.hasOwnProperty('toFixed') is true"); 301ok(Number.prototype.hasOwnProperty('toFixed'), "Number.prototype.hasOwnProperty('toFixed') is false"); 302 303obj = /x/; 304ok(!obj.hasOwnProperty('exec'), "obj.hasOwnProperty('exec') is true"); 305ok(obj.hasOwnProperty('source'), "obj.hasOwnProperty('source') is false"); 306ok(!RegExp.hasOwnProperty('exec'), "RegExp.hasOwnProperty('exec') is true"); 307ok(!RegExp.hasOwnProperty('source'), "RegExp.hasOwnProperty('source') is true"); 308ok(RegExp.prototype.hasOwnProperty('source'), "RegExp.prototype.hasOwnProperty('source') is false"); 309 310obj = new String(); 311ok(!obj.hasOwnProperty('charAt'), "obj.hasOwnProperty('charAt') is true"); 312ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is false"); 313ok(!String.hasOwnProperty('charAt'), "String.hasOwnProperty('charAt') is true"); 314ok(String.prototype.hasOwnProperty('charAt'), "String.prototype.hasOwnProperty('charAt') is false"); 315ok(String.prototype.hasOwnProperty('length'), "String.prototype.hasOwnProperty('length') is false"); 316 317tmp = "" + new Object(); 318ok(tmp === "[object Object]", "'' + new Object() = " + tmp); 319(tmp = new Array).f = Object.prototype.toString; 320ok(tmp.f() === "[object Array]", "tmp.f() = " + tmp.f()); 321(tmp = new Boolean).f = Object.prototype.toString; 322ok(tmp.f() === "[object Boolean]", "tmp.f() = " + tmp.f()); 323(tmp = new Date).f = Object.prototype.toString; 324ok(tmp.f() === "[object Date]", "tmp.f() = " + tmp.f()); 325(tmp = function() {}).f = Object.prototype.toString; 326ok(tmp.f() === "[object Function]", "tmp.f() = " + tmp.f()); 327Math.f = Object.prototype.toString; 328ok(Math.f() === "[object Math]", "tmp.f() = " + tmp.f()); 329(tmp = new Number).f = Object.prototype.toString; 330ok(tmp.f() === "[object Number]", "tmp.f() = " + tmp.f()); 331(tmp = new RegExp("")).f = Object.prototype.toString; 332ok(tmp.f() === "[object RegExp]", "tmp.f() = " + tmp.f()); 333(tmp = new String).f = Object.prototype.toString; 334ok(tmp.f() === "[object String]", "tmp.f() = " + tmp.f()); 335tmp = Object.prototype.toString.call(testObj); 336ok(tmp === "[object Object]", "toString.call(testObj) = " + tmp); 337tmp = Object.prototype.toString.call(this); 338ok(tmp === "[object Object]", "toString.call(this) = " + tmp); 339(function () { tmp = Object.prototype.toString.call(arguments); })(); 340ok(tmp === "[object Object]", "toString.call(arguments) = " + tmp); 341tmp = Object.prototype.toString.call(new VBArray(createArray())); 342ok(tmp === "[object Object]", "toString.call(new VBArray()) = " + tmp); 343 344function TSTestConstr() {} 345TSTestConstr.prototype = { toString: function() { return "test"; } }; 346obj = new TSTestConstr(); 347ok(obj.toString() === "test", "obj.toString() = " + obj.toString()); 348 349ok(Object(1) instanceof Number, "Object(1) is not instance of Number"); 350ok(Object("") instanceof String, "Object('') is not instance of String"); 351ok(Object(false) instanceof Boolean, "Object(false) is not instance of Boolean"); 352 353ok(new Object(1) instanceof Number, "Object(1) is not instance of Number"); 354ok(new Object("") instanceof String, "Object('') is not instance of String"); 355ok(new Object(false) instanceof Boolean, "Object(false) is not instance of Boolean"); 356 357obj = new Object(); 358ok(Object(obj) === obj, "Object(obj) !== obj"); 359 360ok(typeof(Object()) === "object", "typeof(Object()) !== 'object'"); 361ok(typeof(Object(undefined)) === "object", "typeof(Object(undefined)) !== 'object'"); 362ok(typeof(Object(null)) === "object", "typeof(Object(null)) !== 'object'"); 363ok(typeof(Object(nullDisp)) === "object", "typeof(Object(nullDisp)) !== 'object'"); 364 365ok(Object(nullDisp) != nullDisp, "Object(nullDisp) == nullDisp"); 366ok(new Object(nullDisp) != nullDisp, "new Object(nullDisp) == nullDisp"); 367 368ok(Object(testObj) === testObj, "Object(testObj) != testObj\n"); 369ok(new Object(testObj) === testObj, "new Object(testObj) != testObj\n"); 370 371tmp = new Object(); 372ok(Object(tmp) === tmp, "Object(tmp) != tmp"); 373ok(new Object(tmp) === tmp, "new Object(tmp) != tmp"); 374 375var obj = new Object(); 376obj.toString = function (x) { 377 ok(arguments.length === 0, "arguments.length = " + arguments.length); 378 return "test"; 379}; 380ok((tmp = obj.toLocaleString()) === "test", "obj.toLocaleString() = " + tmp); 381ok((tmp = obj.toLocaleString(1)) === "test", "obj.toLocaleString(1) = " + tmp); 382ok(obj === obj.valueOf(), "obj !== obj.valueOf"); 383 384ok("".length === 0, "\"\".length = " + "".length); 385ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length); 386ok("abc".length === 3, "\"abc\".length = " + "abc".length); 387ok(String.prototype.length === 0, "String.prototype.length = " + String.prototype.length); 388 389tmp = "".toString(); 390ok(tmp === "", "''.toString() = " + tmp); 391tmp = "test".toString(); 392ok(tmp === "test", "''.toString() = " + tmp); 393tmp = "test".toString(3); 394ok(tmp === "test", "''.toString(3) = " + tmp); 395 396tmp = "".valueOf(); 397ok(tmp === "", "''.valueOf() = " + tmp); 398tmp = "test".valueOf(); 399ok(tmp === "test", "''.valueOf() = " + tmp); 400tmp = "test".valueOf(3); 401ok(tmp === "test", "''.valueOf(3) = " + tmp); 402 403var str = new String("test"); 404ok(str.toString() === "test", "str.toString() = " + str.toString()); 405var str = new String(); 406ok(str.toString() === "", "str.toString() = " + str.toString()); 407var str = new String("test", "abc"); 408ok(str.toString() === "test", "str.toString() = " + str.toString()); 409 410var strObj = new Object(); 411strObj.toString = function() { return "abcd" }; 412strObj.substr = String.prototype.substr; 413strObj.lastIndexOf = String.prototype.lastIndexOf; 414 415tmp = "value " + str; 416ok(tmp === "value test", "'value ' + str = " + tmp); 417 418tmp = String(); 419ok(tmp === "", "String() = " + tmp); 420tmp = String(false); 421ok(tmp === "false", "String(false) = " + tmp); 422tmp = String(null); 423ok(tmp === "null", "String(null) = " + tmp); 424tmp = String("test"); 425ok(tmp === "test", "String('test') = " + tmp); 426tmp = String("test", "abc"); 427ok(tmp === "test", "String('test','abc') = " + tmp); 428 429tmp = "abc".charAt(0); 430ok(tmp === "a", "'abc',charAt(0) = " + tmp); 431tmp = "abc".charAt(1); 432ok(tmp === "b", "'abc',charAt(1) = " + tmp); 433tmp = "abc".charAt(2); 434ok(tmp === "c", "'abc',charAt(2) = " + tmp); 435tmp = "abc".charAt(3); 436ok(tmp === "", "'abc',charAt(3) = " + tmp); 437tmp = "abc".charAt(4); 438ok(tmp === "", "'abc',charAt(4) = " + tmp); 439tmp = "abc".charAt(); 440ok(tmp === "a", "'abc',charAt() = " + tmp); 441tmp = "abc".charAt(-1); 442ok(tmp === "", "'abc',charAt(-1) = " + tmp); 443tmp = "abc".charAt(0,2); 444ok(tmp === "a", "'abc',charAt(0.2) = " + tmp); 445tmp = "abc".charAt(NaN); 446ok(tmp === "a", "'abc',charAt(NaN) = " + tmp); 447tmp = "abc".charAt(bigInt); 448ok(tmp === "", "'abc',charAt(bigInt) = " + tmp); 449 450tmp = "abc".charCodeAt(0); 451ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp); 452tmp = "abc".charCodeAt(1); 453ok(tmp === 0x62, "'abc'.charCodeAt(1) = " + tmp); 454tmp = "abc".charCodeAt(2); 455ok(tmp === 0x63, "'abc'.charCodeAt(2) = " + tmp); 456tmp = "abc".charCodeAt(); 457ok(tmp === 0x61, "'abc'.charCodeAt() = " + tmp); 458tmp = "abc".charCodeAt(true); 459ok(tmp === 0x62, "'abc'.charCodeAt(true) = " + tmp); 460tmp = "abc".charCodeAt(0,2); 461ok(tmp === 0x61, "'abc'.charCodeAt(0,2) = " + tmp); 462tmp = "\u49F4".charCodeAt(0); 463ok(tmp === 0x49F4, "'\u49F4'.charCodeAt(0) = " + tmp); 464tmp = "\052".charCodeAt(0); 465ok(tmp === 0x2A, "'\052'.charCodeAt(0) = " + tmp); 466tmp = "\xa2".charCodeAt(0); 467ok(tmp === 0xA2, "'\xa2'.charCodeAt(0) = " + tmp); 468tmp = "abc".charCodeAt(bigInt); 469ok(isNaN(tmp), "'abc'.charCodeAt(bigInt) = " + tmp); 470 471tmp = "abcd".substring(1,3); 472ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp); 473tmp = "abcd".substring(-1,3); 474ok(tmp === "abc", "'abcd'.substring(-1,3) = " + tmp); 475tmp = "abcd".substring(1,6); 476ok(tmp === "bcd", "'abcd'.substring(1,6) = " + tmp); 477tmp = "abcd".substring(3,1); 478ok(tmp === "bc", "'abcd'.substring(3,1) = " + tmp); 479tmp = "abcd".substring(2,2); 480ok(tmp === "", "'abcd'.substring(2,2) = " + tmp); 481tmp = "abcd".substring(true,"3"); 482ok(tmp === "bc", "'abcd'.substring(true,'3') = " + tmp); 483tmp = "abcd".substring(1,3,2); 484ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp); 485tmp = "abcd".substring(); 486ok(tmp === "abcd", "'abcd'.substring() = " + tmp); 487 488tmp = "abcd".substr(1,3); 489ok(tmp === "bcd", "'abcd'.substr(1,3) = " + tmp); 490tmp = "abcd".substr(-1,3); 491ok(tmp === "abc", "'abcd'.substr(-1,3) = " + tmp); 492tmp = "abcd".substr(1,6); 493ok(tmp === "bcd", "'abcd'.substr(1,6) = " + tmp); 494tmp = "abcd".substr(2,-1); 495ok(tmp === "", "'abcd'.substr(3,1) = " + tmp); 496tmp = "abcd".substr(2,0); 497ok(tmp === "", "'abcd'.substr(2,2) = " + tmp); 498tmp = "abcd".substr(true,"3"); 499ok(tmp === "bcd", "'abcd'.substr(true,'3') = " + tmp); 500tmp = "abcd".substr(1,3,2); 501ok(tmp === "bcd", "'abcd'.substr(1,3,2) = " + tmp); 502tmp = "abcd".substr(); 503ok(tmp === "abcd", "'abcd'.substr() = " + tmp); 504tmp = strObj.substr(1,1); 505ok(tmp === "b", "'abcd'.substr(1,3) = " + tmp); 506 507tmp = "abcd".slice(1,3); 508ok(tmp === "bc", "'abcd'.slice(1,3) = " + tmp); 509tmp = "abcd".slice(1,-1); 510ok(tmp === "bc", "'abcd'.slice(1,-1) = " + tmp); 511tmp = "abcd".slice(-3,3); 512ok(tmp === "bc", "'abcd'.slice(-3,3) = " + tmp); 513tmp = "abcd".slice(-6,3); 514ok(tmp === "abc", "'abcd'.slice(-6,3) = " + tmp); 515tmp = "abcd".slice(3,1); 516ok(tmp === "", "'abcd'.slice(3,1) = " + tmp); 517tmp = "abcd".slice(true,3); 518ok(tmp === "bc", "'abcd'.slice(true,3) = " + tmp); 519tmp = "abcd".slice(); 520ok(tmp === "abcd", "'abcd'.slice() = " + tmp); 521tmp = "abcd".slice(1); 522ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp); 523 524tmp = "abc".concat(["d",1],2,false); 525ok(tmp === "abcd,12false", "concat returned " + tmp); 526var arr = new Array(2,"a"); 527arr.concat = String.prototype.concat; 528tmp = arr.concat("d"); 529ok(tmp === "2,ad", "arr.concat = " + tmp); 530 531m = "a+bcabc".match("a+"); 532ok(typeof(m) === "object", "typeof m is not object"); 533ok(m.length === 1, "m.length is not 1"); 534ok(m["0"] === "a", "m[0] is not \"a\""); 535 536r = "- [test] -".replace("[test]", "success"); 537ok(r === "- success -", "r = " + r + " expected '- success -'"); 538 539r = "- [test] -".replace("[test]", "success", "test"); 540ok(r === "- success -", "r = " + r + " expected '- success -'"); 541 542r = "test".replace(); 543ok(r === "test", "r = " + r + " expected 'test'"); 544 545function replaceFunc3(m, off, str) { 546 ok(arguments.length === 3, "arguments.length = " + arguments.length); 547 ok(m === "[test]", "m = " + m + " expected [test]"); 548 ok(off === 1, "off = " + off + " expected 0"); 549 ok(str === "-[test]-", "str = " + arguments[3]); 550 return "ret"; 551} 552 553r = "-[test]-".replace("[test]", replaceFunc3); 554ok(r === "-ret-", "r = " + r + " expected '-ret-'"); 555 556r = "-[test]-".replace("[test]", replaceFunc3, "test"); 557ok(r === "-ret-", "r = " + r + " expected '-ret-'"); 558 559r = "x,x,x".replace("x", "y"); 560ok(r === "y,x,x", "r = " + r + " expected 'y,x,x'"); 561 562r = "x,x,x".replace("", "y"); 563ok(r === "yx,x,x", "r = " + r + " expected 'yx,x,x'"); 564 565r = "x,x,x".replace("", ""); 566ok(r === "x,x,x", "r = " + r + " expected 'x,x,x'"); 567 568r = "1,2,3".split(","); 569ok(typeof(r) === "object", "typeof(r) = " + typeof(r)); 570ok(r.length === 3, "r.length = " + r.length); 571ok(r[0] === "1", "r[0] = " + r[0]); 572ok(r[1] === "2", "r[1] = " + r[1]); 573ok(r[2] === "3", "r[2] = " + r[2]); 574 575r = "1,2,3".split(",*"); 576ok(r.length === 1, "r.length = " + r.length); 577ok(r[0] === "1,2,3", "r[0] = " + r[0]); 578 579r = "123".split(""); 580ok(r.length === 3, "r.length = " + r.length); 581ok(r[0] === "1", "r[0] = " + r[0]); 582ok(r[1] === "2", "r[1] = " + r[1]); 583ok(r[2] === "3", "r[2] = " + r[2]); 584 585r = "123".split(2); 586ok(r.length === 2, "r.length = " + r.length); 587ok(r[0] === "1", "r[0] = " + r[0]); 588ok(r[1] === "3", "r[1] = " + r[1]); 589 590r = "1,2,".split(","); 591ok(typeof(r) === "object", "typeof(r) = " + typeof(r)); 592ok(r.length === 3, "r.length = " + r.length); 593ok(r[0] === "1", "r[0] = " + r[0]); 594ok(r[1] === "2", "r[1] = " + r[1]); 595ok(r[2] === "", "r[2] = " + r[2]); 596 597r = "1,2,3".split(",", 2); 598ok(typeof(r) === "object", "typeof(r) = " + typeof(r)); 599ok(r.length === 2, "r.length = " + r.length); 600ok(r[0] === "1", "r[0] = " + r[0]); 601ok(r[1] === "2", "r[1] = " + r[1]); 602 603r = "1,2,3".split(",", 0); 604ok(typeof(r) === "object", "typeof(r) = " + typeof(r)); 605ok(r.length === 0, "r.length = " + r.length); 606 607r = "1,2,3".split(",", -1); 608ok(typeof(r) === "object", "typeof(r) = " + typeof(r)); 609ok(r.length === 3, "r.length = " + r.length); 610ok(r[0] === "1", "r[0] = " + r[0]); 611ok(r[1] === "2", "r[1] = " + r[1]); 612ok(r[2] === "3", "r[1] = " + r[1]); 613 614tmp = "abcd".indexOf("bc",0); 615ok(tmp === 1, "indexOf = " + tmp); 616tmp = "abcd".indexOf("bc",1); 617ok(tmp === 1, "indexOf = " + tmp); 618tmp = "abcd".indexOf("bc"); 619ok(tmp === 1, "indexOf = " + tmp); 620tmp = "abcd".indexOf("ac"); 621ok(tmp === -1, "indexOf = " + tmp); 622tmp = "abcd".indexOf("bc",2); 623ok(tmp === -1, "indexOf = " + tmp); 624tmp = "abcd".indexOf("a",0); 625ok(tmp === 0, "indexOf = " + tmp); 626tmp = "abcd".indexOf("bc",0,"test"); 627ok(tmp === 1, "indexOf = " + tmp); 628tmp = "abcd".indexOf(); 629ok(tmp == -1, "indexOf = " + tmp); 630tmp = "abcd".indexOf("b", bigInt); 631ok(tmp == -1, "indexOf = " + tmp); 632tmp = "abcd".indexOf("abcd",0); 633ok(tmp === 0, "indexOf = " + tmp); 634tmp = "abcd".indexOf("abcd",1); 635ok(tmp === -1, "indexOf = " + tmp); 636tmp = ("ab" + String.fromCharCode(0) + "cd").indexOf(String.fromCharCode(0)); 637ok(tmp === 2, "indexOf = " + tmp); 638 639tmp = "abcd".lastIndexOf("bc",1); 640ok(tmp === 1, "lastIndexOf = " + tmp); 641tmp = "abcd".lastIndexOf("bc",2); 642ok(tmp === 1, "lastIndexOf = " + tmp); 643tmp = "abcd".lastIndexOf("bc"); 644ok(tmp === 1, "lastIndexOf = " + tmp); 645tmp = "abcd".lastIndexOf("ac"); 646ok(tmp === -1, "lastIndexOf = " + tmp); 647tmp = "abcd".lastIndexOf("d",10); 648ok(tmp === 3, "lastIndexOf = " + tmp); 649tmp = "abcd".lastIndexOf("bc",0,"test"); 650ok(tmp === -1, "lastIndexOf = " + tmp); 651tmp = "abcd".lastIndexOf(); 652ok(tmp === -1, "lastIndexOf = " + tmp); 653tmp = "aaaa".lastIndexOf("a",2); 654ok(tmp == 2, "lastIndexOf = " + tmp); 655tmp = strObj.lastIndexOf("b"); 656ok(tmp === 1, "lastIndexOf = " + tmp); 657tmp = "bbb".lastIndexOf("b", bigInt); 658ok(tmp === 2, "lastIndexOf = " + tmp); 659tmp = "abcd".lastIndexOf("abcd",4); 660ok(tmp === 0, "lastIndexOf = " + tmp); 661tmp = "abcd".lastIndexOf("abcd",0); 662ok(tmp === 0, "lastIndexOf = " + tmp); 663tmp = ("ab" + String.fromCharCode(0) + "cd").lastIndexOf(String.fromCharCode(0)); 664ok(tmp === 2, "lastIndexOf = " + tmp); 665 666tmp = "".toLowerCase(); 667ok(tmp === "", "''.toLowerCase() = " + tmp); 668tmp = "test".toLowerCase(); 669ok(tmp === "test", "''.toLowerCase() = " + tmp); 670tmp = "test".toLowerCase(3); 671ok(tmp === "test", "''.toLowerCase(3) = " + tmp); 672tmp = "tEsT".toLowerCase(); 673ok(tmp === "test", "''.toLowerCase() = " + tmp); 674tmp = "tEsT".toLowerCase(3); 675ok(tmp === "test", "''.toLowerCase(3) = " + tmp); 676tmp = ("tE" + String.fromCharCode(0) + "sT").toLowerCase(); 677ok(tmp === "te" + String.fromCharCode(0) + "st", "''.toLowerCase() = " + tmp); 678 679tmp = "".toUpperCase(); 680ok(tmp === "", "''.toUpperCase() = " + tmp); 681tmp = "TEST".toUpperCase(); 682ok(tmp === "TEST", "''.toUpperCase() = " + tmp); 683tmp = "TEST".toUpperCase(3); 684ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp); 685tmp = "tEsT".toUpperCase(); 686ok(tmp === "TEST", "''.toUpperCase() = " + tmp); 687tmp = "tEsT".toUpperCase(3); 688ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp); 689tmp = ("tE" + String.fromCharCode(0) + "sT").toUpperCase(); 690ok(tmp === "TE" + String.fromCharCode(0) + "ST", "''.toUpperCase() = " + tmp); 691 692tmp = "".anchor(); 693ok(tmp === "<A NAME=\"undefined\"></A>", "''.anchor() = " + tmp); 694tmp = "".anchor(3); 695ok(tmp === "<A NAME=\"3\"></A>", "''.anchor(3) = " + tmp); 696tmp = "".anchor("red"); 697ok(tmp === "<A NAME=\"red\"></A>", "''.anchor('red') = " + tmp); 698tmp = "test".anchor(); 699ok(tmp === "<A NAME=\"undefined\">test</A>", "'test'.anchor() = " + tmp); 700tmp = "test".anchor(3); 701ok(tmp === "<A NAME=\"3\">test</A>", "'test'.anchor(3) = " + tmp); 702tmp = "test".anchor("green"); 703ok(tmp === "<A NAME=\"green\">test</A>", "'test'.anchor('green') = " + tmp); 704 705tmp = "".big(); 706ok(tmp === "<BIG></BIG>", "''.big() = " + tmp); 707tmp = "".big(3); 708ok(tmp === "<BIG></BIG>", "''.big(3) = " + tmp); 709tmp = "test".big(); 710ok(tmp === "<BIG>test</BIG>", "'test'.big() = " + tmp); 711tmp = "test".big(3); 712ok(tmp === "<BIG>test</BIG>", "'test'.big(3) = " + tmp); 713 714tmp = "".blink(); 715ok(tmp === "<BLINK></BLINK>", "''.blink() = " + tmp); 716tmp = "".blink(3); 717ok(tmp === "<BLINK></BLINK>", "''.blink(3) = " + tmp); 718tmp = "test".blink(); 719ok(tmp === "<BLINK>test</BLINK>", "'test'.blink() = " + tmp); 720tmp = "test".blink(3); 721ok(tmp === "<BLINK>test</BLINK>", "'test'.blink(3) = " + tmp); 722 723tmp = "".bold(); 724ok(tmp === "<B></B>", "''.bold() = " + tmp); 725tmp = "".bold(3); 726ok(tmp === "<B></B>", "''.bold(3) = " + tmp); 727tmp = "test".bold(); 728ok(tmp === "<B>test</B>", "'test'.bold() = " + tmp); 729tmp = "test".bold(3); 730ok(tmp === "<B>test</B>", "'test'.bold(3) = " + tmp); 731 732tmp = "".fixed(); 733ok(tmp === "<TT></TT>", "''.fixed() = " + tmp); 734tmp = "".fixed(3); 735ok(tmp === "<TT></TT>", "''.fixed(3) = " + tmp); 736tmp = "test".fixed(); 737ok(tmp === "<TT>test</TT>", "'test'.fixed() = " + tmp); 738tmp = "test".fixed(3); 739ok(tmp === "<TT>test</TT>", "'test'.fixed(3) = " + tmp); 740 741tmp = "".fontcolor(); 742ok(tmp === "<FONT COLOR=\"undefined\"></FONT>", "''.fontcolor() = " + tmp); 743tmp = "".fontcolor(3); 744ok(tmp === "<FONT COLOR=\"3\"></FONT>", "''.fontcolor(3) = " + tmp); 745tmp = "".fontcolor("red"); 746ok(tmp === "<FONT COLOR=\"red\"></FONT>", "''.fontcolor('red') = " + tmp); 747tmp = "test".fontcolor(); 748ok(tmp === "<FONT COLOR=\"undefined\">test</FONT>", "'test'.fontcolor() = " + tmp); 749tmp = "test".fontcolor(3); 750ok(tmp === "<FONT COLOR=\"3\">test</FONT>", "'test'.fontcolor(3) = " + tmp); 751tmp = "test".fontcolor("green"); 752ok(tmp === "<FONT COLOR=\"green\">test</FONT>", "'test'.fontcolor('green') = " + tmp); 753 754tmp = "".fontsize(); 755ok(tmp === "<FONT SIZE=\"undefined\"></FONT>", "''.fontsize() = " + tmp); 756tmp = "".fontsize(3); 757ok(tmp === "<FONT SIZE=\"3\"></FONT>", "''.fontsize(3) = " + tmp); 758tmp = "".fontsize("red"); 759ok(tmp === "<FONT SIZE=\"red\"></FONT>", "''.fontsize('red') = " + tmp); 760tmp = "test".fontsize(); 761ok(tmp === "<FONT SIZE=\"undefined\">test</FONT>", "'test'.fontsize() = " + tmp); 762tmp = "test".fontsize(3); 763ok(tmp === "<FONT SIZE=\"3\">test</FONT>", "'test'.fontsize(3) = " + tmp); 764tmp = "test".fontsize("green"); 765ok(tmp === "<FONT SIZE=\"green\">test</FONT>", "'test'.fontsize('green') = " + tmp); 766 767tmp = ("".fontcolor()).fontsize(); 768ok(tmp === "<FONT SIZE=\"undefined\"><FONT COLOR=\"undefined\"></FONT></FONT>", "(''.fontcolor()).fontsize() = " + tmp); 769 770tmp = "".italics(); 771ok(tmp === "<I></I>", "''.italics() = " + tmp); 772tmp = "".italics(3); 773ok(tmp === "<I></I>", "''.italics(3) = " + tmp); 774tmp = "test".italics(); 775ok(tmp === "<I>test</I>", "'test'.italics() = " + tmp); 776tmp = "test".italics(3); 777ok(tmp === "<I>test</I>", "'test'.italics(3) = " + tmp); 778 779tmp = "".link(); 780ok(tmp === "<A HREF=\"undefined\"></A>", "''.link() = " + tmp); 781tmp = "".link(3); 782ok(tmp === "<A HREF=\"3\"></A>", "''.link(3) = " + tmp); 783tmp = "".link("red"); 784ok(tmp === "<A HREF=\"red\"></A>", "''.link('red') = " + tmp); 785tmp = "test".link(); 786ok(tmp === "<A HREF=\"undefined\">test</A>", "'test'.link() = " + tmp); 787tmp = "test".link(3); 788ok(tmp === "<A HREF=\"3\">test</A>", "'test'.link(3) = " + tmp); 789tmp = "test".link("green"); 790ok(tmp === "<A HREF=\"green\">test</A>", "'test'.link('green') = " + tmp); 791 792tmp = "".small(); 793ok(tmp === "<SMALL></SMALL>", "''.small() = " + tmp); 794tmp = "".small(3); 795ok(tmp === "<SMALL></SMALL>", "''.small(3) = " + tmp); 796tmp = "test".small(); 797ok(tmp === "<SMALL>test</SMALL>", "'test'.small() = " + tmp); 798tmp = "test".small(3); 799ok(tmp === "<SMALL>test</SMALL>", "'test'.small(3) = " + tmp); 800 801tmp = "".strike(); 802ok(tmp === "<STRIKE></STRIKE>", "''.strike() = " + tmp); 803tmp = "".strike(3); 804ok(tmp === "<STRIKE></STRIKE>", "''.strike(3) = " + tmp); 805tmp = "test".strike(); 806ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike() = " + tmp); 807tmp = "test".strike(3); 808ok(tmp === "<STRIKE>test</STRIKE>", "'test'.strike(3) = " + tmp); 809 810tmp = "".sub(); 811ok(tmp === "<SUB></SUB>", "''.sub() = " + tmp); 812tmp = "".sub(3); 813ok(tmp === "<SUB></SUB>", "''.sub(3) = " + tmp); 814tmp = "test".sub(); 815ok(tmp === "<SUB>test</SUB>", "'test'.sub() = " + tmp); 816tmp = "test".sub(3); 817ok(tmp === "<SUB>test</SUB>", "'test'.sub(3) = " + tmp); 818 819tmp = "".sup(); 820ok(tmp === "<SUP></SUP>", "''.sup() = " + tmp); 821tmp = "".sup(3); 822ok(tmp === "<SUP></SUP>", "''.sup(3) = " + tmp); 823tmp = "test".sup(); 824ok(tmp === "<SUP>test</SUP>", "'test'.sup() = " + tmp); 825tmp = "test".sup(3); 826ok(tmp === "<SUP>test</SUP>", "'test'.sup(3) = " + tmp); 827 828ok(String.fromCharCode() === "", "String.fromCharCode() = " + String.fromCharCode()); 829ok(String.fromCharCode(65,"66",67) === "ABC", "String.fromCharCode(65,'66',67) = " + String.fromCharCode(65,"66",67)); 830ok(String.fromCharCode(1024*64+65, -1024*64+65) === "AA", 831 "String.fromCharCode(1024*64+65, -1024*64+65) = " + String.fromCharCode(1024*64+65, -1024*64+65)); 832ok(String.fromCharCode(65, NaN, undefined).length === 3, 833 "String.fromCharCode(65, NaN, undefined).length = " + String.fromCharCode(65, NaN, undefined).length); 834 835var arr = new Array(); 836ok(typeof(arr) === "object", "arr () is not object"); 837ok((arr.length === 0), "arr.length is not 0"); 838ok(arr["0"] === undefined, "arr[0] is not undefined"); 839 840var arr = new Array(1, 2, "test"); 841ok(typeof(arr) === "object", "arr (1,2,test) is not object"); 842ok((arr.length === 3), "arr.length is not 3"); 843ok(arr["0"] === 1, "arr[0] is not 1"); 844ok(arr["1"] === 2, "arr[1] is not 2"); 845ok(arr["2"] === "test", "arr[2] is not \"test\""); 846 847arr["7"] = true; 848ok((arr.length === 8), "arr.length is not 8"); 849 850tmp = "" + []; 851ok(tmp === "", "'' + [] = " + tmp); 852tmp = "" + [1,true]; 853ok(tmp === "1,true", "'' + [1,true] = " + tmp); 854 855var arr = new Array(6); 856ok(typeof(arr) === "object", "arr (6) is not object"); 857ok((arr.length === 6), "arr.length is not 6"); 858ok(arr["0"] === undefined, "arr[0] is not undefined"); 859 860ok(arr.push() === 6, "arr.push() !== 6"); 861ok(arr.push(1) === 7, "arr.push(1) !== 7"); 862ok(arr[6] === 1, "arr[6] != 1"); 863ok(arr.length === 7, "arr.length != 10"); 864ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10"); 865ok(arr[8] === "b", "arr[8] != 'b'"); 866ok(arr.length === 10, "arr.length != 10"); 867 868var arr = new Object(); 869arr.push = Array.prototype.push; 870 871arr.length = 6; 872 873ok(arr.push() === 6, "arr.push() !== 6"); 874ok(arr.push(1) === 7, "arr.push(1) !== 7"); 875ok(arr[6] === 1, "arr[6] != 1"); 876ok(arr.length === 7, "arr.length != 10"); 877ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10"); 878ok(arr[8] === "b", "arr[8] != 'b'"); 879ok(arr.length === 10, "arr.length != 10"); 880 881arr.pop = Array.prototype.pop; 882ok(arr.pop() === false, "arr.pop() !== false"); 883ok(arr[8] === "b", "arr[8] !== 'b'"); 884ok(arr.pop() === 'b', "arr.pop() !== 'b'"); 885ok(arr[8] === undefined, "arr[8] !== undefined"); 886 887arr = [3,4,5]; 888tmp = arr.pop(); 889ok(arr.length === 2, "arr.length = " + arr.length); 890ok(tmp === 5, "pop() = " + tmp); 891tmp = arr.pop(2); 892ok(arr.length === 1, "arr.length = " + arr.length); 893ok(tmp === 4, "pop() = " + tmp); 894tmp = arr.pop(); 895ok(arr.length === 0, "arr.length = " + arr.length); 896ok(tmp === 3, "pop() = " + tmp); 897for(tmp in arr) 898 ok(false, "not deleted " + tmp); 899tmp = arr.pop(); 900ok(arr.length === 0, "arr.length = " + arr.length); 901ok(tmp === undefined, "tmp = " + tmp); 902arr = new Object(); 903arr.pop = Array.prototype.pop; 904tmp = arr.pop(); 905ok(arr.length === 0, "arr.length = " + arr.length); 906ok(tmp === undefined, "tmp = " + tmp); 907arr = [,,,,,]; 908tmp = arr.pop(); 909ok(arr.length === 5, "arr.length = " + arr.length); 910ok(tmp === undefined, "tmp = " + tmp); 911 912function PseudoArray() { 913 this[0] = 0; 914} 915PseudoArray.prototype = {length: 1}; 916arr = new PseudoArray(); 917Array.prototype.push.call(arr, 2); 918ok(arr.propertyIsEnumerable("length"), "arr.length is not enumerable"); 919 920arr = [1,2,null,false,undefined,,"a"]; 921 922tmp = arr.join(); 923ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp); 924tmp = arr.join(";"); 925ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp); 926tmp = arr.join(";","test"); 927ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp); 928tmp = arr.join(""); 929ok(tmp === "12falsea", "arr.join('') = " + tmp); 930 931tmp = arr.toString(); 932ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp); 933tmp = arr.toString("test"); 934ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp); 935 936arr = ["a", "b"]; 937 938tmp = arr.join(String.fromCharCode(0)); 939ok(tmp === "a" + String.fromCharCode(0) + "b", "arr.join(String.fromCharCode(0)) = " + tmp); 940 941arr = new Object(); 942arr.length = 3; 943arr[0] = "aa"; 944arr[2] = 2; 945arr[7] = 3; 946arr.join = Array.prototype.join; 947tmp = arr.join(","); 948ok(arr.length === 3, "arr.length = " + arr.length); 949ok(tmp === "aa,,2", "tmp = " + tmp); 950 951arr = [5,true,2,-1,3,false,"2.5"]; 952tmp = arr.sort(function(x,y) { return y-x; }); 953ok(tmp === arr, "tmp !== arr"); 954tmp = [5,3,"2.5",2,true,false,-1]; 955for(var i=0; i < arr.length; i++) 956 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]); 957 958arr = [5,false,2,0,"abc",3,"a",-1]; 959tmp = arr.sort(); 960ok(tmp === arr, "tmp !== arr"); 961tmp = [-1,0,2,3,5,"a","abc",false]; 962for(var i=0; i < arr.length; i++) 963 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]); 964 965arr = ["a", "b", "ab"]; 966tmp = ["a", "ab", "b"]; 967ok(arr.sort() === arr, "arr.sort() !== arr"); 968for(var i=0; i < arr.length; i++) 969 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]); 970 971arr = new Object(); 972arr.length = 3; 973arr[0] = 1; 974arr[2] = "aa"; 975arr.sort = Array.prototype.sort; 976tmp = arr.sort(); 977ok(arr === tmp, "tmp !== arr"); 978ok(arr[0]===1 && arr[1]==="aa" && arr[2]===undefined, "arr is sorted incorrectly"); 979 980tmp = [["bb","aa"],["ab","aa"]].sort().toString(); 981ok(tmp === "ab,aa,bb,aa", "sort() = " + tmp); 982 983tmp = [["bb","aa"],"ab"].sort().toString(); 984ok(tmp === "ab,bb,aa", "sort() = " + tmp); 985 986tmp = [["bb","aa"],"cc"].sort().toString(); 987ok(tmp === "bb,aa,cc", "sort() = " + tmp); 988 989tmp = [2,"1"].sort().toString(); 990ok(tmp === "1,2", "sort() = " + tmp); 991 992tmp = ["2",1].sort().toString(); 993ok(tmp === "1,2", "sort() = " + tmp); 994 995tmp = [,,0,"z"].sort().toString(); 996ok(tmp === "0,z,,", "sort() = " + tmp); 997 998tmp = ["a,b",["a","a"],["a","c"]].sort().toString(); 999ok(tmp === "a,a,a,b,a,c", "sort() = " + tmp); 1000 1001arr = ["1", "2", "3"]; 1002arr.length = 1; 1003ok(arr.length === 1, "arr.length = " + arr.length); 1004arr.length = 3; 1005ok(arr.length === 3, "arr.length = " + arr.length); 1006ok(arr.toString() === "1,,", "arr.toString() = " + arr.toString()); 1007 1008arr = Array("a","b","c"); 1009ok(arr.toString() === "a,b,c", "arr.toString() = " + arr.toString()); 1010 1011ok(arr.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.valueOf"); 1012ok(arr === arr.valueOf(), "arr !== arr.valueOf"); 1013 1014arr = [1,2,3]; 1015tmp = arr.reverse(); 1016ok(tmp === arr, "tmp !== arr"); 1017ok(arr.length === 3, "arr.length = " + arr.length); 1018ok(arr.toString() === "3,2,1", "arr.toString() = " + arr.toString()); 1019 1020arr = []; 1021arr[3] = 5; 1022arr[5] = 1; 1023tmp = arr.reverse(); 1024ok(tmp === arr, "tmp !== arr"); 1025ok(arr.length === 6, "arr.length = " + arr.length); 1026ok(arr.toString() === "1,,5,,,", "arr.toString() = " + arr.toString()); 1027 1028arr = new Object(); 1029arr.length = 3; 1030arr[0] = "aa"; 1031arr[2] = 2; 1032arr[7] = 3; 1033arr.reverse = Array.prototype.reverse; 1034tmp = arr.reverse(); 1035ok(tmp === arr, "tmp !== arr"); 1036ok(arr.length === 3, "arr.length = " + arr.length); 1037ok(arr[0] === 2 && arr[1] === undefined && arr[2] === "aa", "unexpected array"); 1038 1039arr = [1,2,3]; 1040tmp = arr.unshift(0); 1041ok(tmp === (invokeVersion < 2 ? undefined : 4), "[1,2,3].unshift(0) returned " +tmp); 1042ok(arr.length === 4, "arr.length = " + arr.length); 1043ok(arr.toString() === "0,1,2,3", "arr.toString() = " + arr.toString()); 1044 1045arr = new Array(3); 1046arr[0] = 1; 1047arr[2] = 3; 1048tmp = arr.unshift(-1,0); 1049ok(tmp === (invokeVersion < 2 ? undefined : 5), "unshift returned " +tmp); 1050ok(arr.length === 5, "arr.length = " + arr.length); 1051ok(arr.toString() === "-1,0,1,,3", "arr.toString() = " + arr.toString()); 1052 1053arr = [1,2,3]; 1054tmp = arr.unshift(); 1055ok(tmp === (invokeVersion < 2 ? undefined : 3), "unshift returned " +tmp); 1056ok(arr.length === 3, "arr.length = " + arr.length); 1057ok(arr.toString() === "1,2,3", "arr.toString() = " + arr.toString()); 1058 1059arr = new Object(); 1060arr.length = 2; 1061arr[0] = 1; 1062arr[1] = 2; 1063tmp = Array.prototype.unshift.call(arr, 0); 1064ok(tmp === (invokeVersion < 2 ? undefined : 3), "unshift returned " +tmp); 1065ok(arr.length === 3, "arr.length = " + arr.length); 1066ok(arr[0] === 0 && arr[1] === 1 && arr[2] === 2, "unexpected array"); 1067 1068arr = [1,2,,4]; 1069tmp = arr.shift(); 1070ok(tmp === 1, "[1,2,,4].shift() = " + tmp); 1071ok(arr.toString() === "2,,4", "arr = " + arr.toString()); 1072 1073arr = []; 1074tmp = arr.shift(); 1075ok(tmp === undefined, "[].shift() = " + tmp); 1076ok(arr.toString() === "", "arr = " + arr.toString()); 1077 1078arr = [1,2,,4]; 1079tmp = arr.shift(2); 1080ok(tmp === 1, "[1,2,,4].shift(2) = " + tmp); 1081ok(arr.toString() === "2,,4", "arr = " + arr.toString()); 1082 1083arr = [1,]; 1084tmp = arr.shift(); 1085ok(tmp === 1, "[1,].shift() = " + tmp); 1086ok(arr.toString() === "", "arr = " + arr.toString()); 1087 1088obj = new Object(); 1089obj[0] = "test"; 1090obj[2] = 3; 1091obj.length = 3; 1092tmp = Array.prototype.shift.call(obj); 1093ok(tmp === "test", "obj.shift() = " + tmp); 1094ok(obj.length == 2, "obj.length = " + obj.length); 1095ok(obj[1] === 3, "obj[1] = " + obj[1]); 1096 1097var num = new Number(6); 1098arr = [0,1,2]; 1099tmp = arr.concat(3, [4,5], num); 1100ok(tmp !== arr, "tmp === arr"); 1101for(var i=0; i<6; i++) 1102 ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]); 1103ok(tmp[6] === num, "tmp[6] !== num"); 1104ok(tmp.length === 7, "tmp.length = " + tmp.length); 1105 1106arr = [].concat(); 1107ok(arr.length === 0, "arr.length = " + arr.length); 1108 1109arr = [1,]; 1110tmp = arr.concat([2]); 1111ok(tmp.length === 3, "tmp.length = " + tmp.length); 1112ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]); 1113 1114arr = [1,false,'a',null,undefined,'a']; 1115ok(arr.slice(0,6).toString() === "1,false,a,,,a", "arr.slice(0,6).toString() = " + arr.slice(0,6)); 1116ok(arr.slice(0,6).length === 6, "arr.slice(0,6).length = " + arr.slice(0,6).length); 1117ok(arr.slice().toString() === "1,false,a,,,a", "arr.slice().toString() = " + arr.slice()); 1118ok(arr.slice("abc").toString() === "1,false,a,,,a", "arr.slice(\"abc\").toString() = " + arr.slice("abc")); 1119ok(arr.slice(3,8).toString() === ",,a", "arr.slice(3,8).toString() = " + arr.slice(3,8)); 1120ok(arr.slice(3,8).length === 3, "arr.slice(3,8).length = " + arr.slice(3,8).length); 1121ok(arr.slice(1).toString() === "false,a,,,a", "arr.slice(1).toString() = " + arr.slice(1)); 1122ok(arr.slice(-2).toString() === ",a", "arr.slice(-2).toString() = " + arr.slice(-2)); 1123ok(arr.slice(3,1).toString() === "", "arr.slice(3,1).toString() = " + arr.slice(3,1)); 1124tmp = arr.slice(0,6); 1125for(var i=0; i < arr.length; i++) 1126 ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]); 1127arr[12] = 2; 1128ok(arr.slice(5).toString() === "a,,,,,,,2", "arr.slice(5).toString() = " + arr.slice(5).toString()); 1129ok(arr.slice(5).length === 8, "arr.slice(5).length = " + arr.slice(5).length); 1130 1131arr = [1,2,3,4,5]; 1132tmp = arr.splice(2,2); 1133ok(tmp.toString() == "3,4", "arr.splice(2,2) returned " + tmp.toString()); 1134ok(arr.toString() == "1,2,5", "arr.splice(2,2) is " + arr.toString()); 1135 1136arr = [1,2,3,4,5]; 1137tmp = arr.splice(2,2,"a"); 1138ok(tmp.toString() == "3,4", "arr.splice(2,2,'a') returned " + tmp.toString()); 1139ok(arr.toString() == "1,2,a,5", "arr.splice(2,2,'a') is " + arr.toString()); 1140 1141arr = [1,2,3,4,5]; 1142tmp = arr.splice(2,2,'a','b','c'); 1143ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp.toString()); 1144ok(arr.toString() == "1,2,a,b,c,5", "arr.splice(2,2,'a','b','c') is " + arr.toString()); 1145 1146arr = [1,2,3,4,]; 1147tmp = arr.splice(2,2,'a','b','c'); 1148ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp.toString()); 1149ok(arr.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr.toString()); 1150 1151arr = [1,2,3,4,]; 1152arr.splice(2,2,'a','b','c'); 1153ok(arr.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr.toString()); 1154 1155arr = [1,2,3,4,5]; 1156tmp = arr.splice(2,2,'a','b'); 1157ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b') returned " + tmp.toString()); 1158ok(arr.toString() == "1,2,a,b,5", "arr.splice(2,2,'a','b') is " + arr.toString()); 1159 1160arr = [1,2,3,4,5]; 1161tmp = arr.splice(-1,2); 1162ok(tmp.toString() == "5", "arr.splice(-1,2) returned " + tmp.toString()); 1163ok(arr.toString() == "1,2,3,4", "arr.splice(-1,2) is " + arr.toString()); 1164 1165arr = [1,2,3,4,5]; 1166tmp = arr.splice(-10,3); 1167ok(tmp.toString() == "1,2,3", "arr.splice(-10,3) returned " + tmp.toString()); 1168ok(arr.toString() == "4,5", "arr.splice(-10,3) is " + arr.toString()); 1169 1170arr = [1,2,3,4,5]; 1171tmp = arr.splice(-10,100); 1172ok(tmp.toString() == "1,2,3,4,5", "arr.splice(-10,100) returned " + tmp.toString()); 1173ok(arr.toString() == "", "arr.splice(-10,100) is " + arr.toString()); 1174 1175arr = [1,2,3,4,5]; 1176tmp = arr.splice(2,-1); 1177ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString()); 1178ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString()); 1179 1180arr = [1,2,3,4,5]; 1181tmp = arr.splice(2); 1182ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString()); 1183ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString()); 1184 1185arr = [1,2,3,4,5]; 1186tmp = arr.splice(); 1187ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString()); 1188ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString()); 1189 1190arr = [1,2,3,4,5]; 1191tmp = arr.splice(bigInt); 1192ok(tmp.toString() == "", "arr.splice(bigInt) returned " + tmp.toString()); 1193ok(arr.toString() == "1,2,3,4,5", "arr.splice(bigInt) is " + arr.toString()); 1194 1195arr = [1,2,3,4,5]; 1196tmp = arr.splice(-bigInt); 1197ok(tmp.toString() == "", "arr.splice(-bigInt) returned " + tmp.toString()); 1198ok(arr.toString() == "1,2,3,4,5", "arr.splice(-bigInt) is " + arr.toString()); 1199 1200if(invokeVersion >= 2) { 1201 arr = [1,2,3,4,5]; 1202 tmp = arr.splice(2, bigInt); 1203 ok(tmp.toString() == "3,4,5", "arr.splice(2, bigInt) returned " + tmp.toString()); 1204 ok(arr.toString() == "1,2", "arr.splice(2, bigInt) is " + arr.toString()); 1205} 1206 1207arr = [1,2,3,4,5]; 1208tmp = arr.splice(2, -bigInt); 1209ok(tmp.toString() == "", "arr.splice(2, -bigInt) returned " + tmp.toString()); 1210ok(arr.toString() == "1,2,3,4,5", "arr.splice(2, -bigInt) is " + arr.toString()); 1211 1212obj = new Object(); 1213obj.length = 3; 1214obj[0] = 1; 1215obj[1] = 2; 1216obj[2] = 3; 1217tmp = Array.prototype.splice.call(obj, 1, 1, 'a', 'b'); 1218ok(tmp.toString() === "2", "obj.splice returned " + tmp); 1219ok(obj.length === 4, "obj.length = " + obj.length); 1220ok(obj[0] === 1, "obj[0] = " + obj[0]); 1221ok(obj[1] === 'a', "obj[1] = " + obj[1]); 1222ok(obj[2] === 'b', "obj[2] = " + obj[2]); 1223ok(obj[3] === 3, "obj[3] = " + obj[3]); 1224 1225obj = new Object(); 1226obj.length = 3; 1227obj[0] = 1; 1228obj[1] = 2; 1229obj[2] = 3; 1230tmp = Array.prototype.slice.call(obj, 1, 2); 1231ok(tmp.length === 1, "tmp.length = " + tmp.length); 1232ok(tmp[0] === 2, "tmp[0] = " + tmp[0]); 1233 1234tmp = (new Number(2)).toString(); 1235ok(tmp === "2", "num(2).toString = " + tmp); 1236tmp = (new Number()).toString(); 1237ok(tmp === "0", "num().toString = " + tmp); 1238tmp = (new Number(5.5)).toString(2); 1239ok(tmp === "101.1", "num(5.5).toString(2) = " + tmp); 1240 1241tmp = (new Number(3)).toFixed(3); 1242ok(tmp === "3.000", "num(3).toFixed(3) = " + tmp); 1243tmp = (new Number(3)).toFixed(); 1244ok(tmp === "3", "Number(3).toFixed() = " + tmp); 1245tmp = (new Number(0)).toFixed(); 1246ok(tmp === "0", "Number(0).toFixed() = " + tmp); 1247tmp = (new Number(0)).toFixed(1); 1248ok(tmp === "0.0", "Number(0).toFixed(1) = " + tmp); 1249tmp = (new Number(0)).toFixed(2); 1250ok(tmp === "0.00", "Number(0).toFixed(2) = " + tmp); 1251tmp = (new Number(1.76)).toFixed(1); 1252ok(tmp === "1.8", "num(1.76).toFixed(1) = " + tmp); 1253tmp = (new Number(7.92)).toFixed(5); 1254ok(tmp === "7.92000", "num(7.92).toFixed(5) = " + tmp); 1255tmp = (new Number(2.88)).toFixed(); 1256ok(tmp === "3", "num(2.88).toFixed = " + tmp); 1257tmp = (new Number(-2.5)).toFixed(); 1258ok(tmp === "-3", "num(-2.5).toFixed = " + tmp); 1259tmp = (new Number(1000000000000000128)).toFixed(0); 1260//todo_wine ok(tmp === "1000000000000000100", "num(1000000000000000128) = " + tmp); 1261tmp = (new Number(3.14).toFixed(NaN)); 1262ok(tmp === "3", "num(3.14).toFixed = " + tmp); 1263tmp = (new Number(0.95).toFixed(1)); 1264ok(tmp === "1.0", "num(0.95).toFixed(1) = " + tmp); 1265tmp = (new Number(1e900)).toFixed(0); 1266ok(tmp === "Infinity", "num(1000000000000000128) = " + tmp); 1267tmp = (new Number(0.12345678901234567890123)).toFixed(20); 1268ok(tmp === "0.12345678901234568000", "num(0.12345678901234567890123) = " + tmp); 1269 1270tmp = (new Number(2)).toExponential(3); 1271ok(tmp === "2.000e+0", "num(2).toExponential(3) = " + tmp); 1272tmp = (new Number(1.17e-32)).toExponential(20); 1273ok(tmp === "1.17000000000000000000e-32", "num(1.17e-32).toExponential(20) = " + tmp); 1274tmp = (new Number(0)).toExponential(7); 1275ok(tmp === "0.0000000e+0", "num(0).toExponential(7) = " + tmp); 1276tmp = (new Number(0)).toExponential(0); 1277ok(tmp === "0e+0", "num(0).toExponential() = " + tmp); 1278tmp = (new Number(-13.7567)).toExponential(); 1279ok(tmp === "-1.37567e+1", "num(-13.7567).toExponential() = " + tmp); 1280tmp = (new Number(-32.1)).toExponential(); 1281ok(tmp === "-3.21e+1", "num(-32.1).toExponential() = " + tmp); 1282tmp = (new Number(4723.4235)).toExponential(); 1283ok(tmp === "4.7234235e+3", "num(4723.4235).toExponential() = " + tmp); 1284 1285tmp = (new Number(5)).toPrecision(12); 1286ok(tmp == "5.00000000000", "num(5).toPrecision(12) = " + tmp); 1287tmp = (new Number(7.73)).toPrecision(7); 1288ok(tmp == "7.730000", "num(7.73).toPrecision(7) = " + tmp); 1289tmp = (new Number(-127547.47472)).toPrecision(17); 1290ok(tmp == "-127547.47472000000", "num(-127547.47472).toPrecision(17) = " + tmp); 1291tmp = (new Number(0)).toPrecision(3); 1292ok(tmp == "0.00", "num(0).toPrecision(3) = " + tmp); 1293tmp = (new Number(42345.52342465464562334)).toPrecision(15); 1294ok(tmp == "42345.5234246546", "num(42345.52342465464562334).toPrecision(15) = " + tmp); 1295tmp = (new Number(1.182e30)).toPrecision(5); 1296ok(tmp == "1.1820e+30", "num(1.182e30)).toPrecision(5) = " + tmp); 1297tmp = (new Number(1.123)).toPrecision(); 1298ok(tmp == "1.123", "num(1.123).toPrecision() = " + tmp); 1299 1300ok(Number() === 0, "Number() = " + Number()); 1301ok(Number(false) === 0, "Number(false) = " + Number(false)); 1302ok(Number("43") === 43, "Number('43') = " + Number("43")); 1303 1304tmp = (new Number(1)).valueOf(); 1305ok(tmp === 1, "(new Number(1)).valueOf = " + tmp); 1306tmp = (new Number(1,2)).valueOf(); 1307ok(tmp === 1, "(new Number(1,2)).valueOf = " + tmp); 1308tmp = (new Number()).valueOf(); 1309ok(tmp === 0, "(new Number()).valueOf = " + tmp); 1310tmp = Number.prototype.valueOf(); 1311ok(tmp === 0, "Number.prototype.valueOf = " + tmp); 1312 1313function equals(val, base) { 1314 var i; 1315 var num = 0; 1316 var str = val.toString(base); 1317 1318 for(i=0; i<str.length; i++) { 1319 if(str.substring(i, i+1) == '(') break; 1320 if(str.substring(i, i+1) == '.') break; 1321 num = num*base + parseInt(str.substring(i, i+1)); 1322 } 1323 1324 if(str.substring(i, i+1) == '.') { 1325 var mult = base; 1326 for(i++; i<str.length; i++) { 1327 if(str.substring(i, i+1) == '(') break; 1328 num += parseInt(str.substring(i, i+1))/mult; 1329 mult *= base; 1330 } 1331 } 1332 1333 if(str.substring(i, i+1) == '(') { 1334 exp = parseInt(str.substring(i+2)); 1335 num *= Math.pow(base, exp); 1336 } 1337 1338 ok(num>val-val/1000 && num<val+val/1000, "equals: num = " + num); 1339} 1340 1341ok((10).toString(11) === "a", "(10).toString(11) = " + (10).toString(11)); 1342ok((213213433).toString(17) === "8e2ddcb", "(213213433).toString(17) = " + (213213433).toString(17)); 1343ok((-3254343).toString(33) === "-2oicf", "(-3254343).toString(33) = " + (-3254343).toString(33)); 1344ok((NaN).toString(12) === "NaN", "(NaN).toString(11) = " + (NaN).toString(11)); 1345ok((Infinity).toString(13) === "Infinity", "(Infinity).toString(11) = " + (Infinity).toString(11)); 1346for(i=2; i<10; i++) { 1347 equals(1.123, i); 1348 equals(2305843009200000000, i); 1349 equals(5.123, i); 1350 equals(21711, i); 1351 equals(1024*1024*1024*1024*1024*1024*1.9999, i); 1352 equals(748382, i); 1353 equals(0.6, i); 1354 equals(4.65661287308e-10, i); 1355 ok((0).toString(i) === "0", "(0).toString("+i+") = " + (0).toString(i)); 1356} 1357 1358ok(parseFloat('123') === 123, "parseFloat('123') = " + parseFloat('123')); 1359ok(parseFloat('-13.7') === -13.7, "parseFloat('-13.7') = " + parseFloat('-13.7')); 1360ok(parseFloat('-0.01e-2') === -0.01e-2, "parseFloat('-0.01e-2') = " + parseFloat('-0.01e-2')); 1361ok(parseFloat('-12e+5') === -12e+5, "parseFloat('-12e+5') = " + parseFloat('-12e+5')); 1362ok(parseFloat('1E5 not parsed') === 1E5, "parseFloat('1E5 not parsed') = " + parseFloat('1E5 not parsed')); 1363ok(isNaN(parseFloat('not a number')), "parseFloat('not a number') is not NaN"); 1364ok(parseFloat('+13.2e-3') === 13.2e-3, "parseFloat('+13.2e-3') = " + parseFloat('+13.2e-3')); 1365ok(parseFloat('.12') === 0.12, "parseFloat('.12') = " + parseFloat('.12')); 1366ok(parseFloat('1e') === 1, "parseFloat('1e') = " + parseFloat('1e')); 1367 1368tmp = Math.min(1); 1369ok(tmp === 1, "Math.min(1) = " + tmp); 1370 1371tmp = Math.min(1, false); 1372ok(tmp === 0, "Math.min(1, false) = " + tmp); 1373 1374tmp = Math.min(); 1375ok(tmp === Infinity, "Math.min() = " + tmp); 1376 1377tmp = Math.min(1, NaN, -Infinity, false); 1378ok(isNaN(tmp), "Math.min(1, NaN, -Infinity, false) is not NaN"); 1379 1380tmp = Math.min(1, false, true, null, -3); 1381ok(tmp === -3, "Math.min(1, false, true, null, -3) = " + tmp); 1382 1383tmp = Math.max(1); 1384ok(tmp === 1, "Math.max(1) = " + tmp); 1385 1386tmp = Math.max(true, 0); 1387ok(tmp === 1, "Math.max(true, 0) = " + tmp); 1388 1389tmp = Math.max(-2, false, true, null, 1); 1390ok(tmp === 1, "Math.max(-2, false, true, null, 1) = " + tmp); 1391 1392tmp = Math.max(); 1393ok(tmp === -Infinity, "Math.max() = " + tmp); 1394 1395tmp = Math.max(true, NaN, 0); 1396ok(isNaN(tmp), "Math.max(true, NaN, 0) is not NaN"); 1397 1398tmp = Math.round(0.5); 1399ok(tmp === 1, "Math.round(0.5) = " + tmp); 1400 1401tmp = Math.round(-0.5); 1402ok(tmp === 0, "Math.round(-0.5) = " + tmp); 1403 1404tmp = Math.round(1.1); 1405ok(tmp === 1, "Math.round(1.1) = " + tmp); 1406 1407tmp = Math.round(true); 1408ok(tmp === 1, "Math.round(true) = " + tmp); 1409 1410tmp = Math.round(1.1, 3, 4); 1411ok(tmp === 1, "Math.round(1.1, 3, 4) = " + tmp); 1412 1413tmp = Math.round(); 1414ok(isNaN(tmp), "Math.round() is not NaN"); 1415 1416tmp = Math.ceil(0.5); 1417ok(tmp === 1, "Math.ceil(0.5) = " + tmp); 1418 1419tmp = Math.ceil(-0.5); 1420ok(tmp === 0, "Math.ceil(-0.5) = " + tmp); 1421 1422tmp = Math.ceil(1.1); 1423ok(tmp === 2, "Math.round(1.1) = " + tmp); 1424 1425tmp = Math.ceil(true); 1426ok(tmp === 1, "Math.ceil(true) = " + tmp); 1427 1428tmp = Math.ceil(1.1, 3, 4); 1429ok(tmp === 2, "Math.ceil(1.1, 3, 4) = " + tmp); 1430 1431tmp = Math.ceil(); 1432ok(isNaN(tmp), "ceil() is not NaN"); 1433 1434tmp = Math.floor(0.5); 1435ok(tmp === 0, "Math.floor(0.5) = " + tmp); 1436 1437tmp = Math.floor(-0.5); 1438ok(tmp === -1, "Math.floor(-0.5) = " + tmp); 1439 1440tmp = Math.floor(1.1); 1441ok(tmp === 1, "Math.floor(1.1) = " + tmp); 1442 1443tmp = Math.floor(true); 1444ok(tmp === 1, "Math.floor(true) = " + tmp); 1445 1446tmp = Math.floor(1.1, 3, 4); 1447ok(tmp === 1, "Math.floor(1.1, 3, 4) = " + tmp); 1448 1449tmp = Math.floor(); 1450ok(isNaN(tmp), "floor is not NaN"); 1451 1452tmp = Math.abs(3); 1453ok(tmp === 3, "Math.abs(3) = " + tmp); 1454 1455tmp = Math.abs(-3); 1456ok(tmp === 3, "Math.abs(-3) = " + tmp); 1457 1458tmp = Math.abs(true); 1459ok(tmp === 1, "Math.abs(true) = " + tmp); 1460 1461tmp = Math.abs(); 1462ok(isNaN(tmp), "Math.abs() is not NaN"); 1463 1464tmp = Math.abs(NaN); 1465ok(isNaN(tmp), "Math.abs() is not NaN"); 1466 1467tmp = Math.abs(-Infinity); 1468ok(tmp === Infinity, "Math.abs(-Infinite) = " + tmp); 1469 1470tmp = Math.abs(-3, 2); 1471ok(tmp === 3, "Math.abs(-3, 2) = " + tmp); 1472 1473tmp = Math.cos(0); 1474ok(tmp === 1, "Math.cos(0) = " + tmp); 1475 1476tmp = Math.cos(Math.PI/2); 1477ok(Math.floor(tmp*100) === 0, "Math.cos(Math.PI/2) = " + tmp); 1478 1479tmp = Math.cos(-Math.PI/2); 1480ok(Math.floor(tmp*100) === 0, "Math.cos(-Math.PI/2) = " + tmp); 1481 1482tmp = Math.cos(Math.PI/3, 2); 1483ok(Math.floor(tmp*100) === 50, "Math.cos(Math.PI/3, 2) = " + tmp); 1484 1485tmp = Math.cos(true); 1486ok(Math.floor(tmp*100) === 54, "Math.cos(true) = " + tmp); 1487 1488tmp = Math.cos(false); 1489ok(tmp === 1, "Math.cos(false) = " + tmp); 1490 1491tmp = Math.cos(); 1492ok(isNaN(tmp), "Math.cos() is not NaN"); 1493 1494tmp = Math.cos(NaN); 1495ok(isNaN(tmp), "Math.cos(NaN) is not NaN"); 1496 1497tmp = Math.cos(Infinity); 1498ok(isNaN(tmp), "Math.cos(Infinity) is not NaN"); 1499 1500tmp = Math.cos(-Infinity); 1501ok(isNaN(tmp), "Math.cos(-Infinity) is not NaN"); 1502 1503tmp = Math.pow(2, 2); 1504ok(tmp === 4, "Math.pow(2, 2) = " + tmp); 1505 1506tmp = Math.pow(4, 0.5); 1507ok(tmp === 2, "Math.pow(2, 2) = " + tmp); 1508 1509tmp = Math.pow(2, 2, 3); 1510ok(tmp === 4, "Math.pow(2, 2, 3) = " + tmp); 1511 1512tmp = Math.pow(2); 1513ok(isNaN(tmp), "Math.pow(2) is not NaN"); 1514 1515tmp = Math.pow(); 1516ok(isNaN(tmp), "Math.pow() is not NaN"); 1517 1518tmp = Math.random(); 1519ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp)); 1520ok(0 <= tmp && tmp <= 1, "Math.random() = " + tmp); 1521 1522tmp = Math.random(100); 1523ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp)); 1524ok(0 <= tmp && tmp <= 1, "Math.random(100) = " + tmp); 1525 1526tmp = Math.acos(0); 1527ok(Math.floor(tmp*100) === 157, "Math.acos(0) = " + tmp); 1528 1529tmp = Math.acos(1); 1530ok(Math.floor(tmp*100) === 0, "Math.acos(1) = " + tmp); 1531 1532tmp = Math.acos(-1); 1533ok(Math.floor(tmp*100) === 314, "Math.acos(-1) = " + tmp); 1534 1535tmp = Math.acos(Math.PI/4, 2); 1536ok(Math.floor(tmp*100) === 66, "Math.acos(Math.PI/4, 2) = " + tmp); 1537 1538tmp = Math.acos(true); 1539ok(Math.floor(tmp*100) === 0, "Math.acos(true) = " + tmp); 1540 1541tmp = Math.acos(false); 1542ok(Math.floor(tmp*100) === 157, "Math.acos(false) = " + tmp); 1543 1544tmp = Math.acos(1.1); 1545ok(isNaN(tmp), "Math.acos(1.1) is not NaN"); 1546 1547tmp = Math.acos(); 1548ok(isNaN(tmp), "Math.acos() is not NaN"); 1549 1550tmp = Math.acos(NaN); 1551ok(isNaN(tmp), "Math.acos(NaN) is not NaN"); 1552 1553tmp = Math.acos(Infinity); 1554ok(isNaN(tmp), "Math.acos(Infinity) is not NaN"); 1555 1556tmp = Math.acos(-Infinity); 1557ok(isNaN(tmp), "Math.acos(-Infinity) is not NaN"); 1558 1559tmp = Math.asin(0); 1560ok(Math.floor(tmp*100) === 0, "Math.asin(0) = " + tmp); 1561 1562tmp = Math.asin(1); 1563ok(Math.floor(tmp*100) === 157, "Math.asin(1) = " + tmp); 1564 1565tmp = Math.asin(-1); 1566ok(Math.floor(tmp*100) === -158, "Math.asin(-1) = " + tmp); 1567 1568tmp = Math.asin(Math.PI/4, 2); 1569ok(Math.floor(tmp*100) === 90, "Math.asin(Math.PI/4, 2) = " + tmp); 1570 1571tmp = Math.asin(true); 1572ok(Math.floor(tmp*100) === 157, "Math.asin(true) = " + tmp); 1573 1574tmp = Math.asin(false); 1575ok(Math.floor(tmp*100) === 0, "Math.asin(false) = " + tmp); 1576 1577tmp = Math.asin(1.1); 1578ok(isNaN(tmp), "Math.asin(1.1) is not NaN"); 1579 1580tmp = Math.asin(); 1581ok(isNaN(tmp), "Math.asin() is not NaN"); 1582 1583tmp = Math.asin(NaN); 1584ok(isNaN(tmp), "Math.asin(NaN) is not NaN"); 1585 1586tmp = Math.asin(Infinity); 1587ok(isNaN(tmp), "Math.asin(Infinity) is not NaN"); 1588 1589tmp = Math.asin(-Infinity); 1590ok(isNaN(tmp), "Math.asin(-Infinity) is not NaN"); 1591 1592tmp = Math.atan(0); 1593ok(Math.floor(tmp*100) === 0, "Math.atan(0) = " + tmp); 1594 1595tmp = Math.atan(1); 1596ok(Math.floor(tmp*100) === 78, "Math.atan(1) = " + tmp); 1597 1598tmp = Math.atan(-1); 1599ok(Math.floor(tmp*100) === -79, "Math.atan(-1) = " + tmp); 1600 1601tmp = Math.atan(true); 1602ok(Math.floor(tmp*100) === 78, "Math.atan(true) = " + tmp); 1603 1604tmp = Math.atan(false); 1605ok(Math.floor(tmp*100) === 0, "Math.atan(false) = " + tmp); 1606 1607tmp = Math.atan(); 1608ok(isNaN(tmp), "Math.atan() is not NaN"); 1609 1610tmp = Math.atan(NaN); 1611ok(isNaN(tmp), "Math.atan(NaN) is not NaN"); 1612 1613tmp = Math.atan(Infinity); 1614ok(Math.floor(tmp*100) === 157, "Math.atan(Infinity) = " + tmp); 1615 1616tmp = Math.atan(-Infinity); 1617ok(Math.floor(tmp*100) === -158, "Math.atan(Infinity) = " + tmp); 1618 1619tmp = Math.atan2(0, 0); 1620ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 0) = " + tmp); 1621 1622tmp = Math.atan2(0, 1); 1623ok(Math.floor(tmp*100) === 0, "Math.atan2(0, 1) = " + tmp); 1624 1625tmp = Math.atan2(0, Infinity); 1626ok(Math.floor(tmp*100) === 0, "Math.atan2(0, Infinity) = " + tmp); 1627 1628tmp = Math.atan2(0, -1); 1629ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -1) = " + tmp); 1630 1631tmp = Math.atan2(0, -Infinity); 1632ok(Math.floor(tmp*100) === 314, "Math.atan2(0, -Infinity) = " + tmp); 1633 1634tmp = Math.atan2(1, 0); 1635ok(Math.floor(tmp*100) === 157, "Math.atan2(1, 0) = " + tmp); 1636 1637tmp = Math.atan2(Infinity, 0); 1638ok(Math.floor(tmp*100) === 157, "Math.atan2(Infinity, 0) = " + tmp); 1639 1640tmp = Math.atan2(-1, 0); 1641ok(Math.floor(tmp*100) === -158, "Math.atan2(-1, 0) = " + tmp); 1642 1643tmp = Math.atan2(-Infinity, 0); 1644ok(Math.floor(tmp*100) === -158, "Math.atan2(-Infinity, 0) = " + tmp); 1645 1646tmp = Math.atan2(1, 1); 1647ok(Math.floor(tmp*100) === 78, "Math.atan2(1, 1) = " + tmp); 1648 1649tmp = Math.atan2(-1, -1); 1650ok(Math.floor(tmp*100) === -236, "Math.atan2(-1, -1) = " + tmp); 1651 1652tmp = Math.atan2(-1, 1); 1653ok(Math.floor(tmp*100) === -79, "Math.atan2(-1, 1) = " + tmp); 1654 1655tmp = Math.atan2(Infinity, Infinity); 1656ok(Math.floor(tmp*100) === 78, "Math.atan2(Infinity, Infinity) = " + tmp); 1657 1658tmp = Math.atan2(Infinity, -Infinity, 1); 1659ok(Math.floor(tmp*100) === 235, "Math.atan2(Infinity, -Infinity, 1) = " + tmp); 1660 1661tmp = Math.atan2(); 1662ok(isNaN(tmp), "Math.atan2() is not NaN"); 1663 1664tmp = Math.atan2(1); 1665ok(isNaN(tmp), "Math.atan2(1) is not NaN"); 1666 1667tmp = Math.exp(0); 1668ok(tmp === 1, "Math.exp(0) = " + tmp); 1669 1670tmp = Math.exp(1); 1671ok(Math.floor(tmp*100) === 271, "Math.exp(1) = " + tmp); 1672 1673tmp = Math.exp(-1); 1674ok(Math.floor(tmp*100) === 36, "Math.exp(-1) = " + tmp); 1675 1676tmp = Math.exp(true); 1677ok(Math.floor(tmp*100) === 271, "Math.exp(true) = " + tmp); 1678 1679tmp = Math.exp(1, 1); 1680ok(Math.floor(tmp*100) === 271, "Math.exp(1, 1) = " + tmp); 1681 1682tmp = Math.exp(); 1683ok(isNaN(tmp), "Math.exp() is not NaN"); 1684 1685tmp = Math.exp(NaN); 1686ok(isNaN(tmp), "Math.exp(NaN) is not NaN"); 1687 1688tmp = Math.exp(Infinity); 1689ok(tmp === Infinity, "Math.exp(Infinity) = " + tmp); 1690 1691tmp = Math.exp(-Infinity); 1692ok(tmp === 0, "Math.exp(-Infinity) = " + tmp); 1693 1694tmp = Math.log(1); 1695ok(Math.floor(tmp*100) === 0, "Math.log(1) = " + tmp); 1696 1697tmp = Math.log(-1); 1698ok(isNaN(tmp), "Math.log(-1) is not NaN"); 1699 1700tmp = Math.log(true); 1701ok(Math.floor(tmp*100) === 0, "Math.log(true) = " + tmp); 1702 1703tmp = Math.log(1, 1); 1704ok(Math.floor(tmp*100) === 0, "Math.log(1, 1) = " + tmp); 1705 1706tmp = Math.log(); 1707ok(isNaN(tmp), "Math.log() is not NaN"); 1708 1709tmp = Math.log(NaN); 1710ok(isNaN(tmp), "Math.log(NaN) is not NaN"); 1711 1712tmp = Math.log(Infinity); 1713ok(tmp === Infinity, "Math.log(Infinity) = " + tmp); 1714 1715tmp = Math.log(-Infinity); 1716ok(isNaN(tmp), "Math.log(-Infinity) is not NaN"); 1717 1718tmp = Math.sin(0); 1719ok(tmp === 0, "Math.sin(0) = " + tmp); 1720 1721tmp = Math.sin(Math.PI/2); 1722ok(tmp === 1, "Math.sin(Math.PI/2) = " + tmp); 1723 1724tmp = Math.sin(-Math.PI/2); 1725ok(tmp === -1, "Math.sin(-Math.PI/2) = " + tmp); 1726 1727tmp = Math.sin(Math.PI/3, 2); 1728ok(Math.floor(tmp*100) === 86, "Math.sin(Math.PI/3, 2) = " + tmp); 1729 1730tmp = Math.sin(true); 1731ok(Math.floor(tmp*100) === 84, "Math.sin(true) = " + tmp); 1732 1733tmp = Math.sin(false); 1734ok(tmp === 0, "Math.sin(false) = " + tmp); 1735 1736tmp = Math.sin(); 1737ok(isNaN(tmp), "Math.sin() is not NaN"); 1738 1739tmp = Math.sin(NaN); 1740ok(isNaN(tmp), "Math.sin(NaN) is not NaN"); 1741 1742tmp = Math.sin(Infinity); 1743ok(isNaN(tmp), "Math.sin(Infinity) is not NaN"); 1744 1745tmp = Math.sin(-Infinity); 1746ok(isNaN(tmp), "Math.sin(-Infinity) is not NaN"); 1747 1748tmp = Math.sqrt(0); 1749ok(tmp === 0, "Math.sqrt(0) = " + tmp); 1750 1751tmp = Math.sqrt(4); 1752ok(tmp === 2, "Math.sqrt(4) = " + tmp); 1753 1754tmp = Math.sqrt(-1); 1755ok(isNaN(tmp), "Math.sqrt(-1) is not NaN"); 1756 1757tmp = Math.sqrt(2, 2); 1758ok(Math.floor(tmp*100) === 141, "Math.sqrt(2, 2) = " + tmp); 1759 1760tmp = Math.sqrt(true); 1761ok(tmp === 1, "Math.sqrt(true) = " + tmp); 1762 1763tmp = Math.sqrt(false); 1764ok(tmp === 0, "Math.sqrt(false) = " + tmp); 1765 1766tmp = Math.sqrt(); 1767ok(isNaN(tmp), "Math.sqrt() is not NaN"); 1768 1769tmp = Math.sqrt(NaN); 1770ok(isNaN(tmp), "Math.sqrt(NaN) is not NaN"); 1771 1772tmp = Math.sqrt(Infinity); 1773ok(tmp === Infinity, "Math.sqrt(Infinity) = " + tmp); 1774 1775tmp = Math.sqrt(-Infinity); 1776ok(isNaN(tmp), "Math.sqrt(-Infinity) is not NaN"); 1777 1778tmp = Math.tan(0); 1779ok(tmp === 0, "Math.tan(0) = " + tmp); 1780 1781tmp = Math.tan(Math.PI); 1782ok(Math.floor(tmp*100) === -1, "Math.tan(Math.PI) = " + tmp); 1783 1784tmp = Math.tan(2, 2); 1785ok(Math.floor(tmp*100) === -219, "Math.tan(2, 2) = " + tmp); 1786 1787tmp = Math.tan(true); 1788ok(Math.floor(tmp*100) === 155, "Math.tan(true) = " + tmp); 1789 1790tmp = Math.tan(false); 1791ok(tmp === 0, "Math.tan(false) = " + tmp); 1792 1793tmp = Math.tan(); 1794ok(isNaN(tmp), "Math.tan() is not NaN"); 1795 1796tmp = Math.tan(NaN); 1797ok(isNaN(tmp), "Math.tan(NaN) is not NaN"); 1798 1799tmp = Math.tan(Infinity); 1800ok(isNaN(tmp), "Math.tan(Infinity) is not NaN"); 1801 1802tmp = Math.tan(-Infinity); 1803ok(isNaN(tmp), "Math.tan(-Infinity) is not NaN"); 1804 1805(function() { 1806 if(invokeVersion < 2) 1807 return; 1808 1809 var stringify_tests = [ 1810 [[true], "true"], 1811 [[false], "false"], 1812 [[null], "null"], 1813 [[1], "1"], 1814 [["test"], "\"test\""], 1815 [["test\"\\\b\f\n\r\t\u0002 !"], "\"test\\\"\\\\\\b\\f\\n\\r\\t\\u0002 !\""], 1816 [[NaN], "null"], 1817 [[Infinity], "null"], 1818 [[-Infinity], "null"], 1819 [[{prop1: true, prop2: "string"}], "{\"prop1\":true,\"prop2\":\"string\"}"], 1820 [[{prop1: true, prop2: testObj, prop3: undefined}], "{\"prop1\":true}"], 1821 [[{prop1: true, prop2: {prop: "string"}},undefined," "], 1822 "{\n \"prop1\": true,\n \"prop2\": {\n \"prop\": \"string\"\n }\n}"], 1823 [[{ },undefined," "], "{}"], 1824 [[[,2,undefined,3,{ },]],"[null,2,null,3,{},null]"], 1825 [[[,2,undefined,3,{prop:0},],undefined," "],"[\n null,\n 2,\n null,\n 3,\n {\n \"prop\": 0\n },\n null\n]"] 1826 ]; 1827 1828 var i, s, v; 1829 1830 for(i=0; i < stringify_tests.length; i++) { 1831 s = JSON.stringify.apply(null, stringify_tests[i][0]); 1832 ok(s === stringify_tests[i][1], 1833 "["+i+"] stringify(" + stringify_tests[i][0] + ") returned " + s + " expected " + stringify_tests[i][1]); 1834 } 1835 1836 s = JSON.stringify(testObj); 1837 ok(s === undefined || s === "undefined" /* broken on some old versions */, 1838 "stringify(testObj) returned " + s + " expected undfined"); 1839 1840 s = JSON.stringify(undefined); 1841 ok(s === undefined || s === "undefined" /* broken on some old versions */, 1842 "stringify(undefined) returned " + s + " expected undfined"); 1843 1844 var parse_tests = [ 1845 ["true", true], 1846 [" \nnull ", null], 1847 ["{}", {}], 1848 ["\"\\r\\n test\\u1111\"", "\r\n test\u1111"], 1849 ["{\"x\" :\n true}", {x:true}], 1850 ["{\"x y\": {}, \"z\": {\"x\":null}}", {"x y":{}, z:{x:null}}], 1851 ["[]", []], 1852 ["[false,{},{\"x\": []}]", [false,{},{x:[]}]], 1853 ["0", 0], 1854 ["- 1", -1], 1855 ["1e2147483648", Infinity] 1856 ]; 1857 1858 function json_cmp(x, y) { 1859 if(x === y) 1860 return true; 1861 1862 if(!(x instanceof Object) || !(y instanceof Object)) 1863 return false; 1864 1865 for(var prop in x) { 1866 if(!x.hasOwnProperty(prop)) 1867 continue; 1868 if(!x.hasOwnProperty(prop)) 1869 return false; 1870 if(!json_cmp(x[prop], y[prop])) 1871 return false; 1872 } 1873 1874 for(var prop in y) { 1875 if(!x.hasOwnProperty(prop) && y.hasOwnProperty(prop)) 1876 return false; 1877 } 1878 1879 return true; 1880 } 1881 1882 for(i=0; i < parse_tests.length; i++) { 1883 v = JSON.parse(parse_tests[i][0]); 1884 ok(json_cmp(v, parse_tests[i][1]), "parse[" + i + "] returned " + v + ", expected " + parse_tests[i][1]); 1885 } 1886})(); 1887 1888var func = function (a) { 1889 var a = 1; 1890 if(a) return; 1891 }; 1892ok(func.toString() === "function (a) {\n var a = 1;\n if(a) return;\n }", 1893 "func.toString() = " + func.toString()); 1894ok("" + func === "function (a) {\n var a = 1;\n if(a) return;\n }", 1895 "'' + func.toString() = " + func); 1896 1897ok(func.valueOf === Object.prototype.valueOf, "func.valueOf !== Object.prototype.valueOf"); 1898ok(func === func.valueOf(), "func !== func.valueOf()"); 1899 1900function testFuncToString(x,y) { 1901 return x+y; 1902} 1903ok(testFuncToString.toString() === "function testFuncToString(x,y) {\n return x+y;\n}", 1904 "testFuncToString.toString() = " + testFuncToString.toString()); 1905ok("" + testFuncToString === "function testFuncToString(x,y) {\n return x+y;\n}", 1906 "'' + testFuncToString = " + testFuncToString); 1907 1908tmp = new Object(); 1909 1910function callTest(argc) { 1911 ok(this === tmp, "this !== tmp\n"); 1912 ok(arguments.length === argc+1, "arguments.length = " + arguments.length + " expected " + (argc+1)); 1913 for(var i=1; i <= argc; i++) 1914 ok(arguments[i] === i, "arguments[i] = " + arguments[i]); 1915 var a = arguments; 1916 for(var i=1; i <= argc; i++) 1917 ok(a[i] === i, "a[i] = " + a[i]); 1918} 1919 1920callTest.call(tmp, 1, 1); 1921callTest.call(tmp, 2, 1, 2); 1922callTest.call(tmp, 3, 1, 2, 3); 1923 1924callTest.apply(tmp, [1, 1]); 1925callTest.apply(tmp, [2, 1, 2]); 1926callTest.apply(tmp, [3, 1, 2, 3]); 1927(function () { callTest.apply(tmp, arguments); })(2,1,2); 1928 1929function callTest2() { 1930 ok(this === tmp, "this !== tmp\n"); 1931 ok(arguments.length === 0, "callTest2: arguments.length = " + arguments.length + " expected 0"); 1932} 1933 1934callTest2.call(tmp); 1935callTest2.apply(tmp, []); 1936callTest2.apply(tmp); 1937(function () { callTest2.apply(tmp, arguments); })(); 1938 1939function callTest3() { 1940 testThis(this); 1941 ok(arguments.length === 0, "arguments.length = " + arguments.length + " expected 0"); 1942} 1943 1944callTest3.call(); 1945callTest3.call(undefined); 1946callTest3.call(null); 1947callTest3.apply(); 1948callTest3.apply(undefined); 1949callTest3.apply(null); 1950 1951tmp = Number.prototype.toString.call(3); 1952ok(tmp === "3", "Number.prototype.toString.call(3) = " + tmp); 1953 1954var func = new Function("return 3;"); 1955 1956tmp = func(); 1957ok(tmp === 3, "func() = " + tmp); 1958ok(func.call() === 3, "func.call() = " + tmp); 1959ok(func.length === 0, "func.length = " + func.length); 1960tmp = func.toString(); 1961ok(tmp === "function anonymous() {\nreturn 3;\n}", "func.toString() = " + tmp); 1962 1963func = new Function("x", "return x+2;"); 1964tmp = func(1); 1965ok(tmp === 3, "func(1) = " + tmp); 1966tmp = func.toString(); 1967ok(tmp === "function anonymous(x) {\nreturn x+2;\n}", "func.toString() = " + tmp); 1968 1969tmp = (new Function("x ", "return x+2;")).toString(); 1970ok(tmp === "function anonymous(x ) {\nreturn x+2;\n}", "func.toString() = " + tmp); 1971 1972func = new Function("x", "y", "return x+y"); 1973tmp = func(1,3); 1974ok(tmp === 4, "func(1,3) = " + tmp); 1975tmp = func.toString(); 1976ok(tmp === "function anonymous(x, y) {\nreturn x+y\n}", "func.toString() = " + tmp); 1977 1978func = new Function(" x, \ty", "\tz", "return x+y+z;"); 1979tmp = func(1,3,2); 1980ok(tmp === 6, "func(1,3,2) = " + tmp); 1981ok(func.length === 3, "func.length = " + func.length); 1982tmp = func.toString(); 1983ok(tmp === "function anonymous( x, \ty, \tz) {\nreturn x+y+z;\n}", "func.toString() = " + tmp); 1984 1985func = new Function(); 1986tmp = func(); 1987ok(tmp === undefined, "func() = " + tmp); 1988tmp = func.toString(); 1989ok(tmp == "function anonymous() {\n\n}", "func.toString() = " + tmp); 1990 1991// Function constructor called as function 1992func = Function("return 3;"); 1993 1994tmp = func(); 1995ok(tmp === 3, "func() = " + tmp); 1996ok(func.call() === 3, "func.call() = " + tmp); 1997ok(func.length === 0, "func.length = " + func.length); 1998tmp = func.toString(); 1999ok(tmp === "function anonymous() {\nreturn 3;\n}", "func.toString() = " + tmp); 2000 2001func = (function() { 2002 var tmp = 3; 2003 return new Function("return tmp;"); 2004 })(); 2005tmp = 2; 2006tmp = func(); 2007ok(tmp === 2, "func() = " + tmp); 2008 2009var date = new Date(); 2010 2011date = new Date(100); 2012ok(date.getTime() === 100, "date.getTime() = " + date.getTime()); 2013ok(Date.prototype.getTime() === 0, "date.prototype.getTime() = " + Date.prototype.getTime()); 2014date = new Date(8.64e15); 2015ok(date.getTime() === 8.64e15, "date.getTime() = " + date.getTime()); 2016date = new Date(8.64e15+1); 2017ok(isNaN(0+date.getTime()), "date.getTime() is not NaN"); 2018date = new Date(Infinity); 2019ok(isNaN(0+date.getTime()), "date.getTime() is not NaN"); 2020date = new Date("3 July 2009 22:28:00 UTC+0100"); 2021ok(date.getTime() === 1246656480000, "date.getTime() = " + date.getTime()); 2022date = new Date(1984, 11, 29, 13, 51, 24, 120); 2023ok(date.getFullYear() === 1984, "date.getFullYear() = " + date.getFullYear()); 2024ok(date.getMonth() === 11, "date.getMonth() = " + date.getMonth()); 2025ok(date.getDate() === 29, "date.getDate() = " + date.getDate()); 2026ok(date.getHours() === 13, "date.getHours() = " + date.getHours()); 2027ok(date.getMinutes() === 51, "date.getMinutes() = " + date.getMinutes()); 2028ok(date.getSeconds() === 24, "date.getSeconds() = " + date.getSeconds()); 2029ok(date.getMilliseconds() === 120, "date.getMilliseconds() = " + date.getMilliseconds()); 2030date = new Date(731, -32, 40, -1, 70, 65, -13); 2031ok(date.getFullYear() === 728, "date.getFullYear() = " + date.getFullYear()); 2032ok(date.getMonth() === 5, "date.getMonth() = " + date.getMonth()); 2033ok(date.getDate() === 9, "date.getDate() = " + date.getDate()); 2034ok(date.getHours() === 0, "date.getHours() = " + date.getHours()); 2035ok(date.getMinutes() === 11, "date.getMinutes() = " + date.getMinutes()); 2036ok(date.getSeconds() === 4, "date.getSeconds() = " + date.getSeconds()); 2037ok(date.getMilliseconds() === 987, "date.getMilliseconds() = " + date.getMilliseconds()); 2038 2039ok(date.setTime(123) === 123, "date.setTime(123) !== 123"); 2040ok(date.setTime("123", NaN) === 123, "date.setTime(\"123\") !== 123"); 2041ok(isNaN(date.setTime(NaN)), "date.setTime(NaN) is not NaN"); 2042 2043ok(date.setTime(0) === date.getTime(), "date.setTime(0) !== date.getTime()"); 2044ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear()); 2045ok(date.getUTCMonth() === 0, "date.getUTCMonth() = " + date.getUTCMonth()); 2046ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate()); 2047ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay()); 2048ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours()); 2049ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes()); 2050ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds()); 2051ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); 2052 2053date.setTime(60*24*60*60*1000); 2054ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear()); 2055ok(date.getUTCMonth() === 2, "date.getUTCMonth() = " + date.getUTCMonth()); 2056ok(date.getUTCDate() === 2, "date.getUTCDate() = " + date.getUTCDate()); 2057ok(date.getUTCDay() === 1, "date.getUTCDay() = " + date.getUTCDay()); 2058ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours()); 2059ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes()); 2060ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds()); 2061ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); 2062 2063date.setTime(59*24*60*60*1000 + 4*365*24*60*60*1000 + 60*60*1000 + 2*60*1000 + 2*1000 + 640); 2064ok(date.getUTCFullYear() === 1974, "date.getUTCFullYear() = " + date.getUTCFullYear()); 2065ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth()); 2066ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth()); 2067ok(date.getUTCDate() === 28, "date.getUTCDate() = " + date.getUTCDate()); 2068ok(date.getUTCDay() === 4, "date.getUTCDay() = " + date.getUTCDay()); 2069ok(date.getUTCHours() === 1, "date.getUTCHours() = " + date.getUTCHours()); 2070ok(date.getUTCMinutes() === 2, "date.getUTCMinutes() = " + date.getUTCMinutes()); 2071ok(date.getUTCSeconds() === 2, "date.getUTCSeconds() = " + date.getUTCSeconds()); 2072ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); 2073 2074tmp = date.setYear(96); 2075ok(date.getYear() === 96, "date.getYear() = " + date.getYear()); 2076ok(date.getFullYear() === 1996, "date.getFullYear() = " + date.getYear()); 2077ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth()); 2078ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth()); 2079ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); 2080 2081tmp = date.setYear(2010); 2082ok(tmp === date.getTime(), "date.setYear(2010) = " + tmp); 2083ok(date.getYear() === 2010, "date.getYear() = " + date.getYear()); 2084ok(date.getFullYear() === 2010, "date.getFullYear() = " + date.getYear()); 2085ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth()); 2086ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth()); 2087ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); 2088 2089date.setTime(Infinity); 2090ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN"); 2091ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN"); 2092ok(isNaN(date.getUTCDate()), "date.getUTCDate() is not NaN"); 2093ok(isNaN(date.getUTCDay()), "date.getUTCDay() is not NaN"); 2094ok(isNaN(date.getUTCHours()), "date.getUTCHours() is not NaN"); 2095ok(isNaN(date.getUTCMinutes()), "date.getUTCMinutes() is not NaN"); 2096ok(isNaN(date.getUTCSeconds()), "date.getUTCSeconds() is not NaN"); 2097ok(isNaN(date.getUTCMilliseconds()), "date.getUTCMilliseconds() is not NaN"); 2098ok(isNaN(date.setMilliseconds(0)), "date.setMilliseconds() is not NaN"); 2099 2100date.setTime(0); 2101tmp = date.setYear(NaN); 2102ok(isNaN(tmp), "date.setYear(NaN) = " + tmp); 2103ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN"); 2104ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN"); 2105 2106date.setTime(0); 2107date.setUTCMilliseconds(-10, 2); 2108ok(date.getUTCMilliseconds() === 990, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); 2109date.setUTCMilliseconds(10); 2110ok(date.getUTCMilliseconds() === 10, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); 2111date.setUTCSeconds(-10); 2112ok(date.getUTCSeconds() === 50, "date.getUTCSeconds() = " + date.getUTCSeconds()); 2113date.setUTCMinutes(-10); 2114ok(date.getUTCMinutes() === 50, "date.getUTCMinutes() = " + date.getUTCMinutes()); 2115date.setUTCHours(-10); 2116ok(date.getUTCHours() === 14, "date.getUTCHours() = " + date.getUTCHours()); 2117date.setUTCHours(-123); 2118ok(date.getTime() === -612549990, "date.getTime() = " + date.getTime()); 2119date.setUTCHours(20); 2120ok(date.getUTCHours() === 20, "date.getUTCHours() = " + date.getUTCHours()); 2121date.setUTCDate(32); 2122ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate()); 2123date.setUTCMonth(22, 37); 2124ok(date.getTime() === 60987050010, "date.getTime() = " + date.getTime()); 2125date.setUTCFullYear(83, 21, 321); 2126ok(date.getTime() === -59464984149990, "date.getTime() = " + date.getTime()); 2127ok(Math.abs(date) === 59464984149990, "Math.abs(date) = " + Math.abs(date)); 2128ok(getVT(date+1) === "VT_BSTR", "getVT(date+1) = " + getVT(date+1)); 2129 2130ok(isNaN(Date.parse()), "Date.parse() is not NaN"); 2131ok(isNaN(Date.parse("")), "Date.parse(\"\") is not NaN"); 2132ok(isNaN(Date.parse("Jan Jan 20 2009")), "Date.parse(\"Jan Jan 20 2009\") is not NaN"); 2133ok(Date.parse("Jan 20 2009 UTC") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC\") = " + Date.parse("Jan 20 2009 UTC")); 2134ok(Date.parse("Jan 20 2009 GMT") === 1232409600000, "Date.parse(\"Jan 20 2009 GMT\") = " + Date.parse("Jan 20 2009 GMT")); 2135ok(Date.parse("Jan 20 2009 UTC-0") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC-0\") = " + Date.parse("Jan 20 2009 UTC-0")); 2136ok(Date.parse("Jan 20 2009 UTC+0000") === 1232409600000, "Date.parse(\"Jan 20 2009 UTC+0000\") = " + Date.parse("Jan 20 2009 UTC+0000")); 2137ok(Date.parse("Jan 20 2009 UTC-1") === 1232413200000, "Date.parse(\"Jan 20 2009 UTC-1\") = " + Date.parse("Jan 20 2009 UTC-1")); 2138ok(Date.parse("Jan 20 2009 UTC+1") === 1232406000000, "Date.parse(\"Jan 20 2009 UTC+1\") = " + Date.parse("Jan 20 2009 UTC+1")); 2139ok(Date.parse("Ju 13 79 UTC") === 300672000000, "Date.parse(\"Ju 13 79 UTC\") = " + Date.parse("Ju 13 79 UTC")); 2140ok(Date.parse("12Au91 UTC") === 681955200000, "Date.parse(\"12Au91 UTC\") = " + Date.parse("12Au91 UTC")); 2141ok(Date.parse("7/02/17 UTC") === -1656806400000, "Date.parse(\"7/02/17 UTC\") = " + Date.parse("7/02/17 UTC")); 2142ok(Date.parse("Se001 70 12:31:17 UTC") === 21040277000, "Date.parse(\"Se001 70 12:31:17 UTC\") = " + Date.parse("Se001 70 12:31:17 UTC")); 2143ok(Date.parse("February 31 UTC, 2000 12:31:17 PM") === 952000277000, 2144 "Date.parse(\"February 31 UTC, 2000 12:31:17 PM\") = " + Date.parse("February 31 UTC, 2000 12:31:17 PM")); 2145ok(Date.parse("71 11:32AM Dec 12 UTC BC ") === -64346358480000, "Date.parse(\"71 11:32AM Dec 12 UTC BC \") = " + Date.parse("71 11:32AM Dec 12 UTC BC ")); 2146ok(Date.parse("23/71/2000 11::32::UTC") === 1010662320000, "Date.parse(\"23/71/2000 11::32::UTC\") = " + Date.parse("23/71/2000 11::32::UTC")); 2147ok(Date.parse("1970/01/01") === Date.parse("01/01/1970"), "Date.parse(\"1970/01/01\") = " + Date.parse("1970/01/01")); 2148ok(Date.parse("71/12/14") === Date.parse("12/14/1971"), "Date.parse(\"71/12/14\") = " + Date.parse("71/12/14")); 2149ok(Date.parse("Tue, 22 Mar 2016 09:57:55 -0300") === Date.parse("Tue, 22 Mar 2016 09:57:55 GMT-0300"), 2150 "Date.parse(\"Tue, 22 Mar 2016 09:57:55 -0300\") = " + Date.parse("Tue, 22 Mar 2016 09:57:55 -0300")); 2151ok(Date.parse("Tue, 22 Mar 2016 09:57:55 +0400") === Date.parse("Tue, 22 Mar 2016 09:57:55 UTC+0400"), 2152 "Date.parse(\"Tue, 22 Mar 2016 09:57:55 +0400\") = " + Date.parse("Tue, 22 Mar 2016 09:57:55 +0400")); 2153 2154tmp = (new Date()).toGMTString(); 2155ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte"); 2156tmp = (new Date()).toLocaleDateString(); 2157ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte"); 2158tmp = (new Date(1600, 1, 1, 0, 0, 0, 0)).toLocaleDateString(); 2159ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte"); 2160tmp = (new Date(1600, 1, 1, 0, 0, 0, 0)).toLocaleString(); 2161ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte"); 2162tmp = (new Date()).toLocaleTimeString(); 2163ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte"); 2164tmp = (new Date()).toString(); 2165ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte"); 2166tmp = (new Date()).toTimeString(); 2167ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte"); 2168tmp = (new Date()).toUTCString(); 2169ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte"); 2170 2171ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI)); 2172ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI); 2173Math.PI = "test"; 2174ok(Math.floor(Math.PI*100) === 314, "modified Math.PI = " + Math.PI); 2175 2176ok(typeof(Math.E) === "number", "typeof(Math.E) = " + typeof(Math.E)); 2177ok(Math.floor(Math.E*100) === 271, "Math.E = " + Math.E); 2178Math.E = "test"; 2179ok(Math.floor(Math.E*100) === 271, "modified Math.E = " + Math.E); 2180 2181ok(typeof(Math.LOG2E) === "number", "typeof(Math.LOG2E) = " + typeof(Math.LOG2E)); 2182ok(Math.floor(Math.LOG2E*100) === 144, "Math.LOG2E = " + Math.LOG2E); 2183Math.LOG2E = "test"; 2184ok(Math.floor(Math.LOG2E*100) === 144, "modified Math.LOG2E = " + Math.LOG2E); 2185 2186ok(typeof(Math.LOG10E) === "number", "typeof(Math.LOG10E) = " + typeof(Math.LOG10E)); 2187ok(Math.floor(Math.LOG10E*100) === 43, "Math.LOG10E = " + Math.LOG10E); 2188Math.LOG10E = "test"; 2189ok(Math.floor(Math.LOG10E*100) === 43, "modified Math.LOG10E = " + Math.LOG10E); 2190 2191ok(typeof(Math.LN2) === "number", "typeof(Math.LN2) = " + typeof(Math.LN2)); 2192ok(Math.floor(Math.LN2*100) === 69, "Math.LN2 = " + Math.LN2); 2193Math.LN2 = "test"; 2194ok(Math.floor(Math.LN2*100) === 69, "modified Math.LN2 = " + Math.LN2); 2195 2196ok(typeof(Math.LN10) === "number", "typeof(Math.LN10) = " + typeof(Math.LN10)); 2197ok(Math.floor(Math.LN10*100) === 230, "Math.LN10 = " + Math.LN10); 2198Math.LN10 = "test"; 2199ok(Math.floor(Math.LN10*100) === 230, "modified Math.LN10 = " + Math.LN10); 2200 2201ok(typeof(Math.SQRT2) === "number", "typeof(Math.SQRT2) = " + typeof(Math.SQRT2)); 2202ok(Math.floor(Math.SQRT2*100) === 141, "Math.SQRT2 = " + Math.SQRT2); 2203Math.SQRT2 = "test"; 2204ok(Math.floor(Math.SQRT2*100) === 141, "modified Math.SQRT2 = " + Math.SQRT2); 2205 2206ok(typeof(Math.SQRT1_2) === "number", "typeof(Math.SQRT1_2) = " + typeof(Math.SQRT1_2)); 2207ok(Math.floor(Math.SQRT1_2*100) === 70, "Math.SQRT1_2 = " + Math.SQRT1_2); 2208Math.SQRT1_2 = "test"; 2209ok(Math.floor(Math.SQRT1_2*100) === 70, "modified Math.SQRT1_2 = " + Math.SQRT1_2); 2210 2211ok(isNaN.toString() === "\nfunction isNaN() {\n [native code]\n}\n", 2212 "isNaN.toString = '" + isNaN.toString() + "'"); 2213ok(Array.toString() === "\nfunction Array() {\n [native code]\n}\n", 2214 "isNaN.toString = '" + Array.toString() + "'"); 2215ok(Function.toString() === "\nfunction Function() {\n [native code]\n}\n", 2216 "isNaN.toString = '" + Function.toString() + "'"); 2217ok(Function.prototype.toString() === "\nfunction prototype() {\n [native code]\n}\n", 2218 "isNaN.toString = '" + Function.prototype.toString() + "'"); 2219ok("".substr.toString() === "\nfunction substr() {\n [native code]\n}\n", 2220 "''.substr.toString = '" + "".substr.toString() + "'"); 2221 2222var bool = new Boolean(); 2223ok(bool.toString() === "false", "bool.toString() = " + bool.toString()); 2224var bool = new Boolean("false"); 2225ok(bool.toString() === "true", "bool.toString() = " + bool.toString()); 2226ok(bool.valueOf() === Boolean(1), "bool.valueOf() = " + bool.valueOf()); 2227ok(bool.toLocaleString() === bool.toString(), "bool.toLocaleString() = " + bool.toLocaleString()); 2228 2229ok(ActiveXObject instanceof Function, "ActiveXObject is not instance of Function"); 2230ok(ActiveXObject.prototype instanceof Object, "ActiveXObject.prototype is not instance of Object"); 2231 2232ok(Error.prototype !== TypeError.prototype, "Error.prototype === TypeError.prototype"); 2233ok(RangeError.prototype !== TypeError.prototype, "RangeError.prototype === TypeError.prototype"); 2234ok(Error.prototype.toLocaleString === Object.prototype.toLocaleString, 2235 "Error.prototype.toLocaleString !== Object.prototype.toLocaleString"); 2236err = new Error(); 2237ok(err.valueOf === Object.prototype.valueOf, "err.valueOf !== Object.prototype.valueOf"); 2238ok(Error.prototype.name === "Error", "Error.prototype.name = " + Error.prototype.name); 2239ok(err.name === "Error", "err.name = " + err.name); 2240EvalError.prototype.message = "test"; 2241ok(EvalError.prototype.message === "test", "EvalError.prototype.message = " + EvalError.prototype.message); 2242ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString"); 2243ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "Error"), "err.toString() = " + err.toString()); 2244err = new EvalError(); 2245ok(EvalError.prototype.name === "EvalError", "EvalError.prototype.name = " + EvalError.prototype.name); 2246ok(err.name === "EvalError", "err.name = " + err.name); 2247ok(err.toString === Error.prototype.toString, "err.toString !== Error.prototype.toString"); 2248ok(err.message === "", "err.message != ''"); 2249err.message = date; 2250ok(err.message === date, "err.message != date"); 2251ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "EvalError: "+err.message), 2252 "err.toString() = " + err.toString()); 2253ok(err.toString !== Object.prototype.toString, "err.toString === Object.prototype.toString"); 2254err = new RangeError(); 2255ok(RangeError.prototype.name === "RangeError", "RangeError.prototype.name = " + RangeError.prototype.name); 2256ok(err.name === "RangeError", "err.name = " + err.name); 2257ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "RangeError"), "err.toString() = " + err.toString()); 2258err = new ReferenceError(); 2259ok(ReferenceError.prototype.name === "ReferenceError", "ReferenceError.prototype.name = " + ReferenceError.prototype.name); 2260ok(err.name === "ReferenceError", "err.name = " + err.name); 2261ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "ReferenceError"), "err.toString() = " + err.toString()); 2262err = new SyntaxError(); 2263ok(SyntaxError.prototype.name === "SyntaxError", "SyntaxError.prototype.name = " + SyntaxError.prototype.name); 2264ok(err.name === "SyntaxError", "err.name = " + err.name); 2265ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "SyntaxError"), "err.toString() = " + err.toString()); 2266err = new TypeError(); 2267ok(TypeError.prototype.name === "TypeError", "TypeError.prototype.name = " + TypeError.prototype.name); 2268ok(err.name === "TypeError", "err.name = " + err.name); 2269ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "TypeError"), "err.toString() = " + err.toString()); 2270err = new URIError(); 2271ok(URIError.prototype.name === "URIError", "URIError.prototype.name = " + URIError.prototype.name); 2272ok(err.name === "URIError", "err.name = " + err.name); 2273ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "URIError"), "err.toString() = " + err.toString()); 2274err = new Error("message"); 2275ok(err.message === "message", "err.message !== 'message'"); 2276ok(err.toString() === (invokeVersion < 2 ? "[object Error]" : "Error: message"), "err.toString() = " + err.toString()); 2277err = new Error(123); 2278ok(err.number === 123, "err.number = " + err.number); 2279err.number = 254; 2280ok(err.number === 254, "err.number = " + err.number); 2281err = new Error(0, "message"); 2282ok(err.number === 0, "err.number = " + err.number); 2283ok(err.message === "message", "err.message = " + err.message); 2284ok(err.description === "message", "err.description = " + err.description); 2285err = new Error(); 2286ok(err.number === 0, "err.number = " + err.number); 2287ok(err.description === "", "err.description = " + err.description); 2288err.description = 5; 2289ok(err.description === 5, "err.description = " + err.description); 2290ok(err.message === "", "err.message = " + err.message); 2291err.message = 4; 2292ok(err.message === 4, "err.message = " + err.message); 2293 2294ok(!("number" in Error), "number is in Error"); 2295 2296tmp = new Object(); 2297ok(tmp.hasOwnProperty("toString") === false, "toString property should be inherited"); 2298tmp.toString = function() { return "test"; }; 2299ok(tmp.hasOwnProperty("toString") === true, "toString own property should exist"); 2300ok(tmp.hasOwnProperty("nonExisting") === false, "nonExisting property should not exist"); 2301 2302tmp = Error.prototype.toString.call(tmp); 2303ok(tmp === "[object Error]", "Error.prototype.toString.call(tmp) = " + tmp); 2304 2305tmp = function() { return 0; }; 2306tmp[0] = true; 2307ok(tmp.hasOwnProperty("toString") === false, "toString property should be inherited"); 2308ok(tmp.hasOwnProperty("0") === true, "hasOwnProperty(0) returned false"); 2309ok(tmp.hasOwnProperty() === false, "hasOwnProperty() returned true"); 2310 2311ok(Object.prototype.hasOwnProperty.call(testObj) === false, "hasOwnProperty without name returned true"); 2312 2313if(invokeVersion >= 2) { 2314 obj = new Object(); 2315 obj.name = "test"; 2316 tmp = Error.prototype.toString.call(obj); 2317 ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp); 2318 2319 obj = new Object(); 2320 obj.name = 6; 2321 obj.message = false; 2322 tmp = Error.prototype.toString.call(obj); 2323 ok(tmp === "6: false", "Error.prototype.toString.call(obj) = " + tmp); 2324 2325 obj = new Object(); 2326 obj.message = "test"; 2327 tmp = Error.prototype.toString.call(obj); 2328 ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp); 2329 2330 obj = new Object(); 2331 obj.name = ""; 2332 obj.message = "test"; 2333 tmp = Error.prototype.toString.call(obj); 2334 ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp); 2335} 2336 2337tmp = Error.prototype.toString.call(testObj); 2338ok(tmp === "[object Error]", "Error.prototype.toString.call(testObj) = " + tmp); 2339 2340err = new Error(); 2341err.name = null; 2342ok(err.name === null, "err.name = " + err.name + " expected null"); 2343if(invokeVersion >= 2) 2344 ok(err.toString() === "null", "err.toString() = " + err.toString()); 2345 2346err = new Error(); 2347err.message = false; 2348ok(err.message === false, "err.message = " + err.message + " expected false"); 2349if(invokeVersion >= 2) 2350 ok(err.toString() === "Error: false", "err.toString() = " + err.toString()); 2351 2352err = new Error(); 2353err.message = new Object(); 2354err.message.toString = function() { return ""; }; 2355if(invokeVersion >= 2) 2356 ok(err.toString() === "Error", "err.toString() = " + err.toString()); 2357 2358err = new Error(); 2359err.message = undefined; 2360if(invokeVersion >= 2) 2361 ok(err.toString() === "Error", "err.toString() = " + err.toString()); 2362 2363var exception_array = { 2364 E_INVALID_LENGTH: { type: "RangeError", number: -2146823259 }, 2365 2366 E_NOT_DATE: { type: "TypeError", number: -2146823282 }, 2367 E_NOT_BOOL: { type: "TypeError", number: -2146823278 }, 2368 E_ARG_NOT_OPT: { type: "TypeError", number: -2146827839 }, 2369 E_NO_PROPERTY: { type: "TypeError", number: -2146827850 }, 2370 E_NOT_NUM: { type: "TypeError", number: -2146823287 }, 2371 E_INVALID_CALL_ARG: { type: "TypeError", number: -2146828283 }, 2372 E_NOT_FUNC: { type: "TypeError", number: -2146823286 }, 2373 E_OBJECT_EXPECTED: { type: "TypeError", number: -2146823281 }, 2374 E_OBJECT_REQUIRED: { type: "TypeError", number: -2146827864 }, 2375 E_UNSUPPORTED_ACTION: { type: "TypeError", number: -2146827843 }, 2376 E_NOT_VBARRAY: { type: "TypeError", number: -2146823275 }, 2377 E_INVALID_DELETE: { type: "TypeError", number: -2146823276 }, 2378 E_UNDEFINED: { type: "TypeError", number: -2146823279 }, 2379 E_JSCRIPT_EXPECTED: { type: "TypeError", number: -2146823274 }, 2380 E_NOT_ARRAY: { type: "TypeError", number: -2146823257 }, 2381 2382 E_SYNTAX_ERROR: { type: "SyntaxError", number: -2146827286 }, 2383 E_LBRACKET: { type: "SyntaxError", number: -2146827283 }, 2384 E_RBRACKET: { type: "SyntaxError", number: -2146827282 }, 2385 E_SEMICOLON: { type: "SyntaxError", number: -2146827284 }, 2386 E_UNTERMINATED_STR: { type: "SyntaxError", number: -2146827273 }, 2387 E_DISABLED_CC: { type: "SyntaxError", number: -2146827258 }, 2388 E_INVALID_BREAK: { type: "SyntaxError", number: -2146827269 }, 2389 E_INVALID_CONTINUE: { type: "SyntaxError", number: -2146827268 }, 2390 E_LABEL_NOT_FOUND: { type: "SyntaxError", number: -2146827262 }, 2391 E_LABEL_REDEFINED: { type: "SyntaxError", number: -2146827263 }, 2392 E_MISPLACED_RETURN: { type: "SyntaxError", number: -2146827270 }, 2393 2394 E_ILLEGAL_ASSIGN: { type: "ReferenceError", number: -2146823280 }, 2395 2396 E_PRECISION_OUT_OF_RANGE: {type: "RangeError", number: -2146823261 }, 2397 E_FRACTION_DIGITS_OUT_OF_RANGE: {type: "RangeError", number: -2146823262 }, 2398 E_SUBSCRIPT_OUT_OF_RANGE: {type: "RangeError", number: -2146828279 }, 2399 2400 E_REGEXP_SYNTAX_ERROR: { type: "RegExpError", number: -2146823271 }, 2401 2402 E_URI_INVALID_CHAR: { type: "URIError", number: -2146823264 }, 2403 E_URI_INVALID_CODING: { type: "URIError", number: -2146823263 } 2404}; 2405 2406function testException(func, id) { 2407 var ex = exception_array[id]; 2408 var ret = "", num = ""; 2409 2410 try { 2411 func(); 2412 } catch(e) { 2413 ret = e.name; 2414 num = e.number; 2415 } 2416 2417 ok(ret === ex.type, "Exception test, ret = " + ret + ", expected " + ex.type +". Executed function: " + func.toString()); 2418 ok(num === ex.number, "Exception test, num = " + num + ", expected " + ex.number + ". Executed function: " + func.toString()); 2419} 2420 2421// RangeError tests 2422testException(function() {Array(-3);}, "E_INVALID_LENGTH"); 2423testException(function() {createArray().lbound("aaa");}, "E_SUBSCRIPT_OUT_OF_RANGE"); 2424testException(function() {createArray().lbound(3);}, "E_SUBSCRIPT_OUT_OF_RANGE"); 2425testException(function() {createArray().getItem(3);}, "E_SUBSCRIPT_OUT_OF_RANGE"); 2426 2427// TypeError tests 2428testException(function() {date.setTime();}, "E_ARG_NOT_OPT"); 2429testException(function() {date.setYear();}, "E_ARG_NOT_OPT"); 2430testException(function() {arr.test();}, "E_NO_PROPERTY"); 2431testException(function() {Number.prototype.toString.call(arr);}, "E_NOT_NUM"); 2432testException(function() {Number.prototype.toFixed.call(arr);}, "E_NOT_NUM"); 2433testException(function() {(new Number(3)).toString(1);}, "E_INVALID_CALL_ARG"); 2434testException(function() {(new Number(3)).toFixed(21);}, "E_FRACTION_DIGITS_OUT_OF_RANGE"); 2435testException(function() {(new Number(1)).toPrecision(0);}, "E_PRECISION_OUT_OF_RANGE"); 2436testException(function() {not_existing_variable.something();}, "E_UNDEFINED"); 2437testException(function() {date();}, "E_NOT_FUNC"); 2438testException(function() {arr();}, "E_NOT_FUNC"); 2439testException(function() {(new Object) instanceof (new Object);}, "E_NOT_FUNC"); 2440testException(function() {eval("nonexistingfunc()")}, "E_OBJECT_EXPECTED"); 2441testException(function() {(new Object()) instanceof 3;}, "E_NOT_FUNC"); 2442testException(function() {(new Object()) instanceof null;}, "E_NOT_FUNC"); 2443testException(function() {(new Object()) instanceof nullDisp;}, "E_NOT_FUNC"); 2444testException(function() {"test" in 3;}, "E_OBJECT_EXPECTED"); 2445testException(function() {"test" in null;}, "E_OBJECT_EXPECTED"); 2446testException(function() {"test" in nullDisp;}, "E_OBJECT_EXPECTED"); 2447testException(function() {new 3;}, "E_UNSUPPORTED_ACTION"); 2448testException(function() {new null;}, "E_OBJECT_EXPECTED"); 2449testException(function() {new nullDisp;}, "E_NO_PROPERTY"); 2450testException(function() {new VBArray();}, "E_NOT_VBARRAY"); 2451testException(function() {new VBArray(new VBArray(createArray()));}, "E_NOT_VBARRAY"); 2452testException(function() {VBArray.prototype.lbound.call(new Object());}, "E_NOT_VBARRAY"); 2453testException(function() {+nullDisp.prop;}, "E_OBJECT_REQUIRED"); 2454testException(function() {+nullDisp["prop"];}, "E_OBJECT_REQUIRED"); 2455testException(function() {delete (new Object());}, "E_INVALID_DELETE"); 2456testException(function() {delete false;}, "E_INVALID_DELETE"); 2457testException(function() {undefined.toString();}, "E_OBJECT_EXPECTED"); 2458testException(function() {null.toString();}, "E_OBJECT_EXPECTED"); 2459 2460obj = new Object(); 2461obj.prop = 1; 2462tmp = false; 2463testException(function() {delete ((tmp = true) ? obj.prop : obj.prop);}, "E_INVALID_DELETE"); 2464ok(tmp, "delete (..) expression not evaluated"); 2465 2466//FIXME: testException(function() {nonexistent++;}, "E_OBJECT_EXPECTED"); 2467//FIXME: testException(function() {undefined.nonexistent++;}, "E_OBJECT_EXPECTED"); 2468 2469 2470// SyntaxError tests 2471function testSyntaxError(code, id) { 2472 var ex = exception_array[id]; 2473 var ret = "", num = ""; 2474 2475 try { 2476 eval(code); 2477 } catch(e) { 2478 ret = e.name; 2479 num = e.number; 2480 } 2481 2482 ok(ret === ex.type, "Syntax exception test, ret = " + ret + ", expected " + ex.type +". Executed code: " + code); 2483 ok(num === ex.number, "Syntax exception test, num = " + num + ", expected " + ex.number + ". Executed code: " + code); 2484} 2485 2486testSyntaxError("for(i=0;) {}", "E_SYNTAX_ERROR"); 2487testSyntaxError("function {};", "E_LBRACKET"); 2488testSyntaxError("if", "E_LBRACKET"); 2489testSyntaxError("do i=0; while", "E_LBRACKET"); 2490testSyntaxError("while", "E_LBRACKET"); 2491testSyntaxError("for", "E_LBRACKET"); 2492testSyntaxError("with", "E_LBRACKET"); 2493testSyntaxError("switch", "E_LBRACKET"); 2494testSyntaxError("if(false", "E_RBRACKET"); 2495testSyntaxError("for(i=0; i<10; i++", "E_RBRACKET"); 2496testSyntaxError("while(true", "E_RBRACKET"); 2497testSyntaxError("for(i=0", "E_SEMICOLON"); 2498testSyntaxError("for(i=0;i<10", "E_SEMICOLON"); 2499testSyntaxError("while(", "E_SYNTAX_ERROR"); 2500testSyntaxError("if(", "E_SYNTAX_ERROR"); 2501testSyntaxError("'unterminated", "E_UNTERMINATED_STR"); 2502testSyntaxError("*", "E_SYNTAX_ERROR"); 2503testSyntaxError("@_jscript_version", "E_DISABLED_CC"); 2504testSyntaxError("@a", "E_DISABLED_CC"); 2505testSyntaxError("/* @cc_on @*/ @_jscript_version", "E_DISABLED_CC"); 2506testSyntaxError("ok(false, 'unexpected execution'); break;", "E_INVALID_BREAK"); 2507testSyntaxError("ok(false, 'unexpected execution'); continue;", "E_INVALID_CONTINUE"); 2508testSyntaxError("ok(false, 'unexpected execution'); while(true) break unknown_label;", "E_LABEL_NOT_FOUND"); 2509testSyntaxError("ok(false, 'unexpected execution'); some_label: continue some_label;", "E_INVALID_CONTINUE"); 2510testSyntaxError("ok(false, 'unexpected execution'); while(true) continue some_label;", "E_LABEL_NOT_FOUND"); 2511testSyntaxError("ok(false, 'unexpected execution'); some_label: { while(true) continue some_label; }", "E_INVALID_CONTINUE"); 2512testSyntaxError("ok(false, 'unexpected execution'); some_label: { some_label: while(true); }", "E_LABEL_REDEFINED"); 2513testSyntaxError("return;", "E_MISPLACED_RETURN"); 2514testSyntaxError("001.5;", "E_SEMICOLON"); 2515testSyntaxError("001.5", "E_SEMICOLON"); 2516testSyntaxError("0a", "E_SEMICOLON"); 2517testSyntaxError("01a", "E_SEMICOLON"); 2518testSyntaxError("0x1r", "E_SEMICOLON"); 2519testSyntaxError("1a", "E_SEMICOLON"); 2520testSyntaxError("1_", "E_SEMICOLON"); 2521 2522// ReferenceError tests 2523testException(function() {test = function() {}}, "E_ILLEGAL_ASSIGN"); 2524 2525tmp = false; 2526testException(function() {test = (tmp = true);}, "E_ILLEGAL_ASSIGN"); 2527ok(tmp, "expr value on invalid assign not evaluated"); 2528 2529tmp = false; 2530testException(function() {(tmp = true) = false;}, "E_ILLEGAL_ASSIGN"); 2531ok(tmp, "expr assign not evaluated"); 2532 2533tmp = false; 2534testException(function() {true = (tmp = true);}, "E_ILLEGAL_ASSIGN"); 2535ok(tmp, "expr value assign not evaluated"); 2536 2537tmp = ""; 2538testException(function() {(tmp = tmp+"1") = (tmp = tmp+"2");}, "E_ILLEGAL_ASSIGN"); 2539ok(tmp === "12", "assign evaluated in unexpected order"); 2540 2541tmp = false; 2542testException(function() { ((tmp = true) && false)++; }, "E_ILLEGAL_ASSIGN") 2543ok(tmp, "incremented expression not evaluated"); 2544 2545// RegExpError tests 2546testException(function() {RegExp(/a/, "g");}, "E_REGEXP_SYNTAX_ERROR"); 2547 2548// URIError tests 2549testException(function() {encodeURI('\udcaa');}, "E_URI_INVALID_CHAR"); 2550testException(function() {encodeURIComponent('\udcaa');}, "E_URI_INVALID_CHAR"); 2551testException(function() {decodeURI('%');}, "E_URI_INVALID_CODING"); 2552testException(function() {decodeURI('%aaaa');}, "E_URI_INVALID_CODING"); 2553 2554function testThisExcept(func, e) { 2555 testException(function() {func.call(new Object())}, e); 2556} 2557 2558function testBoolThis(func) { 2559 testThisExcept(Boolean.prototype[func], "E_NOT_BOOL"); 2560} 2561 2562testBoolThis("toString"); 2563testBoolThis("valueOf"); 2564 2565function testDateThis(func) { 2566 testThisExcept(Date.prototype[func], "E_NOT_DATE"); 2567} 2568 2569testDateThis("getDate"); 2570testDateThis("getDay"); 2571testDateThis("getFullYear"); 2572testDateThis("getHours"); 2573testDateThis("getMilliseconds"); 2574testDateThis("getMinutes"); 2575testDateThis("getMonth"); 2576testDateThis("getSeconds"); 2577testDateThis("getTime"); 2578testDateThis("getTimezoneOffset"); 2579testDateThis("getUTCDate"); 2580testDateThis("getUTCDay"); 2581testDateThis("getUTCFullYear"); 2582testDateThis("getUTCHours"); 2583testDateThis("getUTCMilliseconds"); 2584testDateThis("getUTCMinutes"); 2585testDateThis("getUTCMonth"); 2586testDateThis("getUTCSeconds"); 2587testDateThis("getYear"); 2588testDateThis("setDate"); 2589testDateThis("setFullYear"); 2590testDateThis("setHours"); 2591testDateThis("setMilliseconds"); 2592testDateThis("setMinutes"); 2593testDateThis("setMonth"); 2594testDateThis("setSeconds"); 2595testDateThis("setTime"); 2596testDateThis("setUTCDate"); 2597testDateThis("setUTCFullYear"); 2598testDateThis("setUTCHours"); 2599testDateThis("setUTCMilliseconds"); 2600testDateThis("setUTCMinutes"); 2601testDateThis("setUTCMonth"); 2602testDateThis("setUTCSeconds"); 2603testDateThis("setYear"); 2604testDateThis("toDateString"); 2605testDateThis("toLocaleDateString"); 2606testDateThis("toLocaleString"); 2607testDateThis("toLocaleTimeString"); 2608testDateThis("toString"); 2609testDateThis("toTimeString"); 2610testDateThis("toUTCString"); 2611testDateThis("valueOf"); 2612 2613function testArrayThis(func) { 2614 testThisExcept(Array.prototype[func], "E_NOT_ARRAY"); 2615} 2616 2617testArrayThis("toString"); 2618 2619function testFunctionThis(func) { 2620 testThisExcept(Function.prototype[func], "E_NOT_FUNC"); 2621} 2622 2623testFunctionThis("toString"); 2624testFunctionThis("call"); 2625testFunctionThis("apply"); 2626 2627function testArrayHostThis(func) { 2628 testException(function() { Array.prototype[func].call(testObj); }, "E_JSCRIPT_EXPECTED"); 2629} 2630 2631testArrayHostThis("push"); 2632testArrayHostThis("shift"); 2633testArrayHostThis("slice"); 2634testArrayHostThis("splice"); 2635testArrayHostThis("unshift"); 2636testArrayHostThis("reverse"); 2637testArrayHostThis("join"); 2638testArrayHostThis("pop"); 2639testArrayHostThis("sort"); 2640 2641function testObjectInherit(obj, constr, ts, tls, vo) { 2642 ok(obj instanceof Object, "obj is not instance of Object"); 2643 ok(obj instanceof constr, "obj is not instance of its constructor"); 2644 2645 ok(obj.hasOwnProperty === Object.prototype.hasOwnProperty, 2646 "obj.hasOwnProperty !== Object.prototype.hasOwnProprty"); 2647 ok(obj.isPrototypeOf === Object.prototype.isPrototypeOf, 2648 "obj.isPrototypeOf !== Object.prototype.isPrototypeOf"); 2649 ok(obj.propertyIsEnumerable === Object.prototype.propertyIsEnumerable, 2650 "obj.propertyIsEnumerable !== Object.prototype.propertyIsEnumerable"); 2651 2652 if(ts) 2653 ok(obj.toString === Object.prototype.toString, 2654 "obj.toString !== Object.prototype.toString"); 2655 else 2656 ok(obj.toString != Object.prototype.toString, 2657 "obj.toString == Object.prototype.toString"); 2658 2659 if(tls) 2660 ok(obj.toLocaleString === Object.prototype.toLocaleString, 2661 "obj.toLocaleString !== Object.prototype.toLocaleString"); 2662 else 2663 ok(obj.toLocaleString != Object.prototype.toLocaleString, 2664 "obj.toLocaleString == Object.prototype.toLocaleString"); 2665 2666 if(vo) 2667 ok(obj.valueOf === Object.prototype.valueOf, 2668 "obj.valueOf !== Object.prototype.valueOf"); 2669 else 2670 ok(obj.valueOf != Object.prototype.valueOf, 2671 "obj.valueOf == Object.prototype.valueOf"); 2672 2673 ok(obj._test === "test", "obj.test = " + obj._test); 2674} 2675 2676Object.prototype._test = "test"; 2677testObjectInherit(new String("test"), String, false, true, false); 2678testObjectInherit(/test/g, RegExp, false, true, true); 2679testObjectInherit(new Number(1), Number, false, false, false); 2680testObjectInherit(new Date(), Date, false, false, false); 2681testObjectInherit(new Boolean(true), Boolean, false, true, false); 2682testObjectInherit(new Array(), Array, false, false, true); 2683testObjectInherit(new Error(), Error, false, true, true); 2684testObjectInherit(testObjectInherit, Function, false, true, true); 2685testObjectInherit(Math, Object, true, true, true); 2686 2687(function() { testObjectInherit(arguments, Object, true, true, true); })(); 2688 2689function testFunctions(obj, arr) { 2690 var l; 2691 2692 for(var i=0; i<arr.length; i++) { 2693 l = obj[arr[i][0]].length; 2694 ok(l === arr[i][1], arr[i][0] + ".length = " + l); 2695 2696 ok(obj.propertyIsEnumerable(arr[i][0]) === false, arr[i][0] + " is enumerable"); 2697 } 2698} 2699 2700testFunctions(Boolean.prototype, [ 2701 ["valueOf", 0], 2702 ["toString", 0] 2703 ]); 2704 2705testFunctions(Number.prototype, [ 2706 ["valueOf", 0], 2707 ["toString", 1], 2708 ["toExponential", 1], 2709 ["toLocaleString", 0], 2710 ["toPrecision", 1] 2711 ]); 2712 2713testFunctions(String.prototype, [ 2714 ["valueOf", 0], 2715 ["toString", 0], 2716 ["anchor", 1], 2717 ["big", 0], 2718 ["blink", 0], 2719 ["bold", 0], 2720 ["charAt", 1], 2721 ["charCodeAt", 1], 2722 ["concat", 1], 2723 ["fixed", 0], 2724 ["fontcolor", 1], 2725 ["fontsize", 1], 2726 ["indexOf", 2], 2727 ["italics", 0], 2728 ["lastIndexOf", 2], 2729 ["link", 1], 2730 ["localeCompare", 1], 2731 ["match", 1], 2732 ["replace", 1], 2733 ["search", 0], 2734 ["slice", 0], 2735 ["small", 0], 2736 ["split", 2], 2737 ["strike", 0], 2738 ["sub", 0], 2739 ["substr", 2], 2740 ["substring", 2], 2741 ["sup", 0], 2742 ["toLocaleLowerCase", 0], 2743 ["toLocaleUpperCase", 0], 2744 ["toLowerCase", 0], 2745 ["toUpperCase", 0] 2746 ]); 2747 2748testFunctions(RegExp.prototype, [ 2749 ["toString", 0], 2750 ["exec", 1], 2751 ["test", 1] 2752 ]); 2753 2754testFunctions(Date.prototype, [ 2755 ["getDate", 0], 2756 ["getDay", 0], 2757 ["getFullYear", 0], 2758 ["getHours", 0], 2759 ["getMilliseconds", 0], 2760 ["getMinutes", 0], 2761 ["getMonth", 0], 2762 ["getSeconds", 0], 2763 ["getTime", 0], 2764 ["getTimezoneOffset", 0], 2765 ["getUTCDate", 0], 2766 ["getUTCDay", 0], 2767 ["getUTCFullYear", 0], 2768 ["getUTCHours", 0], 2769 ["getUTCMilliseconds", 0], 2770 ["getUTCMinutes", 0], 2771 ["getUTCMonth", 0], 2772 ["getUTCSeconds", 0], 2773 ["getYear", 0], 2774 ["setDate", 1], 2775 ["setFullYear", 3], 2776 ["setHours", 4], 2777 ["setMilliseconds", 1], 2778 ["setMinutes", 3], 2779 ["setMonth", 2], 2780 ["setSeconds", 2], 2781 ["setTime", 1], 2782 ["setUTCDate", 1], 2783 ["setUTCFullYear", 3], 2784 ["setUTCHours", 4], 2785 ["setUTCMilliseconds", 1], 2786 ["setUTCMinutes", 3], 2787 ["setUTCMonth", 2], 2788 ["setUTCSeconds", 2], 2789 ["setYear", 1], 2790 ["toDateString", 0], 2791 ["toLocaleDateString", 0], 2792 ["toLocaleString", 0], 2793 ["toLocaleTimeString", 0], 2794 ["toString", 0], 2795 ["toTimeString", 0], 2796 ["toUTCString", 0], 2797 ["toGMTString", 0], 2798 ["valueOf", 0] 2799 ]); 2800 2801testFunctions(Array.prototype, [ 2802 ["concat", 1], 2803 ["join", 1], 2804 ["push", 1], 2805 ["pop", 0], 2806 ["reverse", 0], 2807 ["shift", 0], 2808 ["slice", 2], 2809 ["sort", 1], 2810 ["splice", 2], 2811 ["toLocaleString", 0], 2812 ["toString", 0], 2813 ["unshift", 1] 2814 ]); 2815 2816testFunctions(Error.prototype, [ 2817 ["toString", 0] 2818 ]); 2819 2820testFunctions(Math, [ 2821 ["abs", 1], 2822 ["acos", 1], 2823 ["asin", 1], 2824 ["atan", 1], 2825 ["atan2", 2], 2826 ["ceil", 1], 2827 ["cos", 1], 2828 ["exp", 1], 2829 ["floor", 1], 2830 ["log", 1], 2831 ["max", 2], 2832 ["min", 2], 2833 ["pow", 2], 2834 ["random", 0], 2835 ["round", 1], 2836 ["sin", 1], 2837 ["sqrt", 1], 2838 ["tan", 1] 2839 ]); 2840 2841testFunctions(Object.prototype, [ 2842 ["hasOwnProperty", 1], 2843 ["isPrototypeOf", 1], 2844 ["propertyIsEnumerable", 1], 2845 ["toLocaleString", 0], 2846 ["toString", 0], 2847 ["valueOf", 0] 2848 ]); 2849 2850testFunctions(Function.prototype, [ 2851 ["apply", 2], 2852 ["call", 1], 2853 ["toString", 0] 2854 ]); 2855 2856testFunctions(VBArray.prototype, [ 2857 ["dimensions", 0], 2858 ["getItem", 1], 2859 ["lbound", 0], 2860 ["toArray", 0], 2861 ["ubound", 0] 2862]); 2863 2864if(invokeVersion < 2) 2865 ok(typeof(JSON) === "undefined", "JSON is not undefined"); 2866else 2867 testFunctions(JSON, [ 2868 ["parse", 2], 2869 ["stringify", 3] 2870 ]); 2871 2872ok(ActiveXObject.length == 1, "ActiveXObject.length = " + ActiveXObject.length); 2873ok(Array.length == 1, "Array.length = " + Array.length); 2874ok(Boolean.length == 1, "Boolean.length = " + Boolean.length); 2875ok(CollectGarbage.length == 0, "CollectGarbage.length = " + CollectGarbage.length); 2876ok(Date.length == 7, "Date.length = " + Date.length); 2877ok(Enumerator.length == 7, "Enumerator.length = " + Enumerator.length); 2878ok(Error.length == 1, "Error.length = " + Error.length); 2879ok(EvalError.length == 1, "EvalError.length = " + EvalError.length); 2880ok(RegExpError.length == 1, "RegExpError.length = " + RegExpError.length); 2881ok(Function.length == 1, "Function.length = " + Function.length); 2882ok(GetObject.length == 2, "GetObject.length = " + GetObject.length); 2883ok(Number.length == 1, "Number.length = " + Number.length); 2884ok(Object.length == 0, "Object.length = " + Object.length); 2885ok(RangeError.length == 1, "RangeError.length = " + RangeError.length); 2886ok(ReferenceError.length == 1, "ReferenceError.length = " + ReferenceError.length); 2887ok(RegExp.length == 2, "RegExp.length = " + RegExp.length); 2888ok(ScriptEngine.length == 0, "ScriptEngine.length = " + ScriptEngine.length); 2889ok(ScriptEngineBuildVersion.length == 0, 2890 "ScriptEngineBuildVersion.length = " + ScriptEngineBuildVersion.length); 2891ok(ScriptEngineMajorVersion.length == 0, 2892 "ScriptEngineMajorVersion.length = " + ScriptEngineMajorVersion.length); 2893ok(ScriptEngineMinorVersion.length == 0, 2894 "ScriptEngineMinorVersion.length = " + ScriptEngineMinorVersion.length); 2895ok(String.length == 1, "String.length = " + String.length); 2896ok(SyntaxError.length == 1, "SyntaxError.length = " + SyntaxError.length); 2897ok(TypeError.length == 1, "TypeError.length = " + TypeError.length); 2898ok(URIError.length == 1, "URIError.length = " + URIError.length); 2899ok(VBArray.length == 1, "VBArray.length = " + VBArray.length); 2900ok(decodeURI.length == 1, "decodeURI.length = " + decodeURI.length); 2901ok(decodeURIComponent.length == 1, "decodeURIComponent.length = " + decodeURIComponent.length); 2902ok(encodeURI.length == 1, "encodeURI.length = " + encodeURI.length); 2903ok(encodeURIComponent.length == 1, "encodeURIComponent.length = " + encodeURIComponent.length); 2904ok(escape.length == 1, "escape.length = " + escape.length); 2905ok(eval.length == 1, "eval.length = " + eval.length); 2906ok(isFinite.length == 1, "isFinite.length = " + isFinite.length); 2907ok(isNaN.length == 1, "isNaN.length = " + isNaN.length); 2908ok(parseFloat.length == 1, "parseFloat.length = " + parseFloat.length); 2909ok(parseInt.length == 2, "parseInt.length = " + parseInt.length); 2910ok(unescape.length == 1, "unescape.length = " + unescape.length); 2911 2912String.length = 3; 2913ok(String.length == 1, "String.length = " + String.length); 2914 2915var tmp = createArray(); 2916ok(getVT(tmp) == "VT_ARRAY|VT_VARIANT", "getVT(createArray()) = " + getVT(tmp)); 2917ok(getVT(VBArray(tmp)) == "VT_ARRAY|VT_VARIANT", "getVT(VBArray(tmp)) = " + getVT(VBArray(tmp))); 2918tmp = new VBArray(tmp); 2919tmp = new VBArray(VBArray(createArray())); 2920ok(tmp.dimensions() == 2, "tmp.dimensions() = " + tmp.dimensions()); 2921ok(tmp.lbound() == 0, "tmp.lbound() = " + tmp.lbound()); 2922ok(tmp.lbound(1) == 0, "tmp.lbound(1) = " + tmp.lbound(1)); 2923ok(tmp.lbound(2, 1) == 2, "tmp.lbound(2, 1) = " + tmp.lbound(2, 1)); 2924ok(tmp.ubound() == 4, "tmp.ubound() = " + tmp.ubound()); 2925ok(tmp.ubound("2") == 3, "tmp.ubound(\"2\") = " + tmp.ubound("2")); 2926ok(tmp.getItem(1, 2) == 3, "tmp.getItem(1, 2) = " + tmp.getItem(1, 2)); 2927ok(tmp.getItem(2, 3) == 33, "tmp.getItem(2, 3) = " + tmp.getItem(2, 3)); 2928ok(tmp.getItem(3, 2) == 13, "tmp.getItem(3, 2) = " + tmp.getItem(3, 2)); 2929ok(tmp.toArray() == "2,3,12,13,22,23,32,33,42,43", "tmp.toArray() = " + tmp.toArray()); 2930ok(createArray().toArray() == "2,3,12,13,22,23,32,33,42,43", 2931 "createArray.toArray()=" + createArray().toArray()); 2932 2933reportSuccess(); 2934