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