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