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