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