/*
* Copyright 2008 Jacek Caban for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
var JS_E_NUMBER_EXPECTED = 0x800a1389;
var JS_E_FUNCTION_EXPECTED = 0x800a138a;
var JS_E_DATE_EXPECTED = 0x800a138e;
var JS_E_OBJECT_EXPECTED = 0x800a138f;
var JS_E_BOOLEAN_EXPECTED = 0x800a1392;
var JS_E_VBARRAY_EXPECTED = 0x800a1395;
var JS_E_ENUMERATOR_EXPECTED = 0x800a1397;
var JS_E_REGEXP_EXPECTED = 0x800a1398;
var tmp, i;
var bigInt = Math.pow(2,40);
ok(ScriptEngine() === "JScript", "ScriptEngine() = " + ScriptEngine());
ok(ScriptEngine(3) === "JScript", "ScriptEngine(3) = " + ScriptEngine(3));
ok(ScriptEngineMajorVersion() === ScriptEngineMajorVersion(2), "ScriptEngineMajorVersion() !== ScriptEngineMajorVersion(2)");
ok(ScriptEngineMinorVersion() === ScriptEngineMinorVersion(2), "ScriptEngineMinorVersion() !== ScriptEngineMinorVersion(2)");
ok(ScriptEngineBuildVersion() === ScriptEngineBuildVersion(2), "ScriptEngineBuildVersion() !== ScriptEngineBuildVersion(2)");
function testNoEnumerables(expr) {
for(var iter in obj)
ok(false, expr + " has property " + iter);
}
testNoEnumerables("Object");
testNoEnumerables("Object.prototype");
testNoEnumerables("new Object()");
testNoEnumerables("Math");
testNoEnumerables("String");
testNoEnumerables("String.prototype");
testNoEnumerables("new String()");
testNoEnumerables("Number");
testNoEnumerables("Number.prototype");
testNoEnumerables("new Number(1)");
testNoEnumerables("ActiveXObject");
testNoEnumerables("Array");
testNoEnumerables("Array.prototype");
testNoEnumerables("new Array()");
testNoEnumerables("Boolean");
testNoEnumerables("Boolean.prototype");
testNoEnumerables("new Boolean()");
testNoEnumerables("Date");
testNoEnumerables("Date.prototype");
testNoEnumerables("new Date()");
testNoEnumerables("TypeError");
testNoEnumerables("TypeError.prototype");
testNoEnumerables("new TypeError()");
testNoEnumerables("Function");
testNoEnumerables("Function.prototype");
testNoEnumerables("testNoEnumerates");
testNoEnumerables("VBArray");
testNoEnumerables("new Enumerator()");
testNoEnumerables("Enumerator()");
ok(Object.propertyIsEnumerable("prototype") === false, "Object.prototype is enumerable");
ok(Math.propertyIsEnumerable("E") === false, "Math.E is enumerable");
ok(Math.propertyIsEnumerable("SQRT2") === false, "Math.SQRT2 is enumerable");
ok(Math.propertyIsEnumerable("PI") === false, "Math.PI is enumerable");
ok("test".propertyIsEnumerable("length") === false, "'test'.length is enumerable");
ok([1].propertyIsEnumerable("length") === false, "[1].length is enumerable");
ok((new TypeError()).propertyIsEnumerable("message") === true, "(new TypeError()).message is not enumerable");
ok((new TypeError()).propertyIsEnumerable("description") === false, "(new TypeError()).description is enumerable");
ok((new TypeError()).propertyIsEnumerable("name") === false, "(new TypeError()).name is enumerable");
ok((new TypeError()).propertyIsEnumerable("number") === false, "(new TypeError()).number is enumerable");
ok(Object.propertyIsEnumerable.propertyIsEnumerable("length") === false, "Object.propertyIsEnumerable.length is enumerable");
tmp = new Object();
tmp.test = "1";
ok(tmp.propertyIsEnumerable("test"), "tmp.test is not enumerable");
tmp = { test: 1 };
ok(tmp.propertyIsEnumerable("test"), "tmp.test is not enumerable");
ok([1].concat([2]).propertyIsEnumerable("1"), "[1].concat([2]).1 is not enumerable");
ok("t.e.s.t".split(".").propertyIsEnumerable("0"), "'test'.split().0 is not enumerable");
(function() {
ok(arguments.propertyIsEnumerable("0") === false, "arguments.0 is enumerable");
ok(arguments.propertyIsEnumerable("length") === false, "arguments.length is enumerable");
ok(arguments.propertyIsEnumerable("calee") === false, "arguments.calee is enumerable");
})();
tmp = [1];
tmp.push("");
ok(tmp.propertyIsEnumerable("1"), "[1].push() ... 1 is not enumerable");
ok([1,2].reverse().propertyIsEnumerable("1"), "[1,2].rverse().1 is not enumerable");
ok([1,2].propertyIsEnumerable("0"), "[1,2].0 is not enumerable");
i = parseInt("0");
ok(i === 0, "parseInt('0') = " + i);
i = parseInt("123");
ok(i === 123, "parseInt('123') = " + i);
i = parseInt("-123");
ok(i === -123, "parseInt('-123') = " + i);
i = parseInt("0xff");
ok(i === 0xff, "parseInt('0xff') = " + i);
i = parseInt("11", 8);
ok(i === 9, "parseInt('11', 8) = " + i);
i = parseInt("1j", 22);
ok(i === 41, "parseInt('1j', 32) = " + i);
i = parseInt("123", 0);
ok(i === 123, "parseInt('123', 0) = " + i);
i = parseInt("123", 10, "test");
ok(i === 123, "parseInt('123', 10, 'test') = " + i);
i = parseInt("11", "8");
ok(i === 9, "parseInt('11', '8') = " + i);
i = parseInt("010");
ok(i === 8, "parseInt('010') = " + i);
i = parseInt("");
ok(isNaN(i), "parseInt('') = " + i);
i = parseInt("0x");
ok(isNaN(i), "parseInt('0x') = " + i);
i = parseInt("+");
ok(isNaN(i), "parseInt('+') = " + i);
i = parseInt("-");
ok(isNaN(i), "parseInt('-') = " + i);
i = parseInt("0x10", 11);
ok(i === 0, "parseInt('0x10', 11) = " + i);
i = parseInt("010", 7);
ok(i === 7, "parseInt('010', 7) = " + i);
i = parseInt("123abc");
ok(i === 123, "parseInt('123abc') = " + i);
i = parseInt(" \t123abc");
ok(i === 123, "parseInt(' \\t123abc') = " + i);
i = parseInt("abc");
ok(isNaN(i), "parseInt('123abc') = " + i);
i = parseInt("-12", 11);
ok(i === -13, "parseInt('-12') = " + i);
i = parseInt("-0x10");
ok(i === -16, "parseInt('-0x10') = " + i);
i = parseInt("-010");
ok(i === -8, "parseInt('-010') = " + i);
i = parseInt("123", 0);
ok(i === 123, "parseInt('123', 0) = " + i);
i = parseInt("0x10", 0);
ok(i === 16, "parseInt('123', 0) = " + i);
i = parseInt("0x10", 10);
ok(i === 0, "parseInt('0x10', 10) = " + i);
i = parseInt("0xz");
ok(isNaN(i), "parseInt('0xz') = " + i);
i = parseInt("1", 1);
ok(isNaN(i), "parseInt('1', 1) = " + i);
i = parseInt("1", -1);
ok(isNaN(i), "parseInt('1', -1) = " + i);
i = parseInt("1", 37);
ok(isNaN(i), "parseInt('1', 37) = " + i);
i = parseInt("1", 36);
ok(i === 1, "parseInt('1', 36) = " + i);
i = parseInt("0x1f", 16);
ok(i === 31, "parseInt('0xf', 16) = " + i);
i = parseInt("0x", 16);
ok(isNaN(i), "parseInt('0x', 16) = " + i);
i = parseInt("0x1f", 17);
ok(i === 0, "parseInt('0xf', 16) = " + i);
tmp = encodeURI("abc");
ok(tmp === "abc", "encodeURI('abc') = " + tmp);
tmp = encodeURI("{abc}");
ok(tmp === "%7Babc%7D", "encodeURI('{abc}') = " + tmp);
tmp = encodeURI("");
ok(tmp === "", "encodeURI('') = " + tmp);
tmp = encodeURI("\01\02\03\04");
ok(tmp === "%01%02%03%04", "encodeURI('\\01\\02\\03\\04') = " + tmp);
tmp = encodeURI("{#@}");
ok(tmp === "%7B#@%7D", "encodeURI('{#@}') = " + tmp);
tmp = encodeURI("\xa1 ");
ok(tmp === "%C2%A1%20", "encodeURI(\\xa1 ) = " + tmp);
tmp = encodeURI("\xffff");
ok(tmp.length === 8, "encodeURI('\\xffff').length = " + tmp.length);
tmp = encodeURI("abcABC123;/?:@&=+$,-_.!~*'()");
ok(tmp === "abcABC123;/?:@&=+$,-_.!~*'()", "encodeURI('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp);
tmp = encodeURI("%");
ok(tmp === "%25", "encodeURI('%') = " + tmp);
tmp = encodeURI();
ok(tmp === "undefined", "encodeURI() = " + tmp);
tmp = encodeURI("abc", "test");
ok(tmp === "abc", "encodeURI('abc') = " + tmp);
tmp = decodeURI("abc");
ok(tmp === "abc", "decodeURI('abc') = " + tmp);
tmp = decodeURI("{abc}");
ok(tmp === "{abc}", "decodeURI('{abc}') = " + tmp);
tmp = decodeURI("");
ok(tmp === "", "decodeURI('') = " + tmp);
tmp = decodeURI("\01\02\03\04");
ok(tmp === "\01\02\03\04", "decodeURI('\\01\\02\\03\\04') = " + tmp);
tmp = decodeURI();
ok(tmp === "undefined", "decodeURI() = " + tmp);
tmp = decodeURI("abc", "test");
ok(tmp === "abc", "decodeURI('abc') = " + tmp);
tmp = decodeURI("%7babc%7d");
ok(tmp === "{abc}", "decodeURI('%7Babc%7D') = " + tmp);
tmp = decodeURI("%01%02%03%04");
ok(tmp === "\01\02\03\04", "decodeURI('%01%02%03%04') = " + tmp);
tmp = decodeURI("%C2%A1%20");
ok(tmp === "\xa1 ", "decodeURI('%C2%A1%20') = " + tmp);
tmp = decodeURI("%C3%BFff");
ok(tmp.length === 3, "decodeURI('%C3%BFff').length = " + tmp.length);
tmp = encodeURIComponent("abc");
ok(tmp === "abc", "encodeURIComponent('abc') = " + tmp);
dec = decodeURIComponent(tmp);
ok(dec === "abc", "decodeURIComponent('" + tmp + "') = " + dec);
tmp = encodeURIComponent("{abc}");
ok(tmp === "%7Babc%7D", "encodeURIComponent('{abc}') = " + tmp);
dec = decodeURIComponent(tmp);
ok(dec === "{abc}", "decodeURIComponent('" + tmp + "') = " + dec);
tmp = encodeURIComponent("");
ok(tmp === "", "encodeURIComponent('') = " + tmp);
dec = decodeURIComponent(tmp);
ok(dec === "", "decodeURIComponent('" + tmp + "') = " + dec);
tmp = encodeURIComponent("\01\02\03\04");
ok(tmp === "%01%02%03%04", "encodeURIComponent('\\01\\02\\03\\04') = " + tmp);
dec = decodeURIComponent(tmp);
ok(dec === "\01\02\03\04", "decodeURIComponent('" + tmp + "') = " + dec);
tmp = encodeURIComponent("{#@}");
ok(tmp === "%7B%23%40%7D", "encodeURIComponent('{#@}') = " + tmp);
dec = decodeURIComponent(tmp);
ok(dec === "{#@}", "decodeURIComponent('" + tmp + "') = " + dec);
tmp = encodeURIComponent("\xa1 ");
ok(tmp === "%C2%A1%20", "encodeURIComponent(\\xa1 ) = " + tmp);
dec = decodeURIComponent(tmp);
ok(dec === "\xa1 ", "decodeURIComponent('" + tmp + "') = " + dec);
tmp = encodeURIComponent("\xffff");
ok(tmp.length === 8, "encodeURIComponent('\\xffff').length = " + tmp.length);
dec = decodeURIComponent(tmp);
ok(dec === "\xffff", "decodeURIComponent('" + tmp + "') = " + dec);
tmp = encodeURIComponent("abcABC123;/?:@&=+$,-_.!~*'()");
ok(tmp === "abcABC123%3B%2F%3F%3A%40%26%3D%2B%24%2C-_.!~*'()", "encodeURIComponent('abcABC123;/?:@&=+$,-_.!~*'()') = " + tmp);
dec = decodeURIComponent(tmp);
ok(dec === "abcABC123;/?:@&=+$,-_.!~*'()", "decodeURIComponent('" + tmp + "') = " + dec);
tmp = encodeURIComponent();
ok(tmp === "undefined", "encodeURIComponent() = " + tmp);
tmp = encodeURIComponent("abc", "test");
ok(tmp === "abc", "encodeURIComponent('abc') = " + tmp);
dec = decodeURIComponent();
ok(dec === "undefined", "decodeURIComponent() = " + dec);
dec = decodeURIComponent("abc", "test");
ok(dec === "abc", "decodeURIComponent('abc') = " + dec);
tmp = escape("abc");
ok(tmp === "abc", "escape('abc') = " + tmp);
tmp = escape("");
ok(tmp === "", "escape('') = " + tmp);
tmp = escape("a1b c!d+e@*-_+./,");
ok(tmp === "a1b%20c%21d+e@*-_+./%2C", "escape('a1b c!d+e@*-_+./,') = " + tmp);
tmp = escape();
ok(tmp === "undefined", "escape() = " + tmp);
tmp = escape('\u1234\123\xf3');
ok(tmp == "%u1234S%F3", "escape('\u1234\123\xf3') = " + tmp);
tmp = unescape("abc");
ok(tmp === "abc", "unescape('abc') = " + tmp);
tmp = unescape("");
ok(tmp === "", "unescape('') = " + tmp);
tmp = unescape("%%%");
ok(tmp === "%%%", "unescape('%%%') = " + tmp);
tmp = unescape();
ok(tmp === "undefined", "unescape() = " + tmp);
tmp = unescape("%54%65s%u0074");
ok(tmp === "Test", "unescape('%54%65s%u0074') = " + tmp);
tmp = "aA1~`!@#$%^&*()_+=-][{}';:/.,<>?\|";
ok(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));
ok(unescape(escape(tmp)) === tmp, "unescape(escape('" + tmp + "')) = " + unescape(escape(tmp)));
ok(Object.prototype.hasOwnProperty('toString'), "Object.prototype.hasOwnProperty('toString') is false");
ok(Object.prototype.hasOwnProperty('isPrototypeOf'), "Object.prototype.hasOwnProperty('isPrototypeOf') is false");
ok(Function.prototype.hasOwnProperty('call'), "Function.prototype.hasOwnProperty('call') is false");
Object();
new Object();
obj = new Object();
ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
ok(!obj.hasOwnProperty('isPrototypeOf'), "obj.hasOwnProperty('isPrototypeOf') is true");
ok(!Object.hasOwnProperty('toString'), "Object.hasOwnProperty('toString') is true");
ok(!Object.hasOwnProperty('isPrototypeOf'), "Object.hasOwnProperty('isPrototypeOf') is true");
ok(!parseFloat.hasOwnProperty('call'), "parseFloat.hasOwnProperty('call') is true");
ok(!Function.hasOwnProperty('call'), "Function.hasOwnProperty('call') is true");
Array();
new Array();
obj = new Array();
ok(Array.prototype.hasOwnProperty('sort'), "Array.prototype.hasOwnProperty('sort') is false");
ok(Array.prototype.hasOwnProperty('length'), "Array.prototype.hasOwnProperty('length') is false");
ok(!obj.hasOwnProperty('sort'), "obj.hasOwnProperty('sort') is true");
ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is true");
Boolean();
new Boolean();
obj = new Boolean(false);
ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
ok(!Boolean.hasOwnProperty('toString'), "Boolean.hasOwnProperty('toString') is true");
ok(Boolean.prototype.hasOwnProperty('toString'), "Boolean.prototype.hasOwnProperty('toString') is false");
Date();
new Date();
obj = new Date();
ok(!obj.hasOwnProperty('getTime'), "obj.hasOwnProperty('getTime') is true");
ok(!Date.hasOwnProperty('getTime'), "Date.hasOwnProperty('getTime') is true");
ok(Date.prototype.hasOwnProperty('getTime'), "Date.prototype.hasOwnProperty('getTime') is false");
ok(!("now" in Date), "now found in Date");
Number();
new Number();
obj = new Number();
ok(!obj.hasOwnProperty('toFixed'), "obj.hasOwnProperty('toFixed') is true");
ok(!Number.hasOwnProperty('toFixed'), "Number.hasOwnProperty('toFixed') is true");
ok(Number.prototype.hasOwnProperty('toFixed'), "Number.prototype.hasOwnProperty('toFixed') is false");
/x/;
obj = /x/;
ok(!obj.hasOwnProperty('exec'), "obj.hasOwnProperty('exec') is true");
ok(obj.hasOwnProperty('source'), "obj.hasOwnProperty('source') is false");
ok(!RegExp.hasOwnProperty('exec'), "RegExp.hasOwnProperty('exec') is true");
ok(!RegExp.hasOwnProperty('source'), "RegExp.hasOwnProperty('source') is true");
ok(RegExp.prototype.hasOwnProperty('source'), "RegExp.prototype.hasOwnProperty('source') is false");
String();
new String();
obj = new String();
ok(!obj.hasOwnProperty('charAt'), "obj.hasOwnProperty('charAt') is true");
ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is false");
ok(!String.hasOwnProperty('charAt'), "String.hasOwnProperty('charAt') is true");
ok(String.prototype.hasOwnProperty('charAt'), "String.prototype.hasOwnProperty('charAt') is false");
ok(String.prototype.hasOwnProperty('length'), "String.prototype.hasOwnProperty('length') is false");
tmp = "" + new Object();
ok(tmp === "[object Object]", "'' + new Object() = " + tmp);
(tmp = new Array).f = Object.prototype.toString;
ok(tmp.f() === "[object Array]", "tmp.f() = " + tmp.f());
(tmp = new Boolean).f = Object.prototype.toString;
ok(tmp.f() === "[object Boolean]", "tmp.f() = " + tmp.f());
(tmp = new Date).f = Object.prototype.toString;
ok(tmp.f() === "[object Date]", "tmp.f() = " + tmp.f());
(tmp = function() {}).f = Object.prototype.toString;
ok(tmp.f() === "[object Function]", "tmp.f() = " + tmp.f());
Math.f = Object.prototype.toString;
ok(Math.f() === "[object Math]", "tmp.f() = " + tmp.f());
(tmp = new Number).f = Object.prototype.toString;
ok(tmp.f() === "[object Number]", "tmp.f() = " + tmp.f());
(tmp = new RegExp("")).f = Object.prototype.toString;
ok(tmp.f() === "[object RegExp]", "tmp.f() = " + tmp.f());
(tmp = new String).f = Object.prototype.toString;
ok(tmp.f() === "[object String]", "tmp.f() = " + tmp.f());
tmp = Object.prototype.toString.call(testObj);
ok(tmp === "[object Object]", "toString.call(testObj) = " + tmp);
tmp = Object.prototype.toString.call(this);
ok(tmp === "[object Object]", "toString.call(this) = " + tmp);
(function () { tmp = Object.prototype.toString.call(arguments); })();
ok(tmp === "[object Object]", "toString.call(arguments) = " + tmp);
tmp = Object.prototype.toString.call(new VBArray(createArray()));
ok(tmp === "[object Object]", "toString.call(new VBArray()) = " + tmp);
(tmp = new Enumerator()).f = Object.prototype.toString;
ok(tmp.f() === "[object Object]", "tmp.f() = " + tmp.f());
tmp = Object.prototype.toString.call(null);
ok(tmp === "[object Object]", "toString.call(null) = " + tmp);
tmp = Object.prototype.toString.call(undefined);
ok(tmp === "[object Object]", "toString.call(undefined) = " + tmp);
tmp = Object.prototype.toString.call();
ok(tmp === "[object Object]", "toString.call() = " + tmp);
function TSTestConstr() {}
TSTestConstr.prototype = { toString: function() { return "test"; } };
obj = new TSTestConstr();
ok(obj.toString() === "test", "obj.toString() = " + obj.toString());
ok(Object(1) instanceof Number, "Object(1) is not instance of Number");
ok(Object("") instanceof String, "Object('') is not instance of String");
ok(Object(false) instanceof Boolean, "Object(false) is not instance of Boolean");
ok(new Object(1) instanceof Number, "Object(1) is not instance of Number");
ok(new Object("") instanceof String, "Object('') is not instance of String");
ok(new Object(false) instanceof Boolean, "Object(false) is not instance of Boolean");
obj = new Object();
ok(Object(obj) === obj, "Object(obj) !== obj");
ok(typeof(Object()) === "object", "typeof(Object()) !== 'object'");
ok(typeof(Object(undefined)) === "object", "typeof(Object(undefined)) !== 'object'");
ok(typeof(Object(null)) === "object", "typeof(Object(null)) !== 'object'");
ok(typeof(Object(nullDisp)) === "object", "typeof(Object(nullDisp)) !== 'object'");
ok(Object(nullDisp) != nullDisp, "Object(nullDisp) == nullDisp");
ok(new Object(nullDisp) != nullDisp, "new Object(nullDisp) == nullDisp");
ok(Object(testObj) === testObj, "Object(testObj) != testObj\n");
ok(new Object(testObj) === testObj, "new Object(testObj) != testObj\n");
tmp = new Object();
ok(Object(tmp) === tmp, "Object(tmp) != tmp");
ok(new Object(tmp) === tmp, "new Object(tmp) != tmp");
var obj = new Object();
obj.toString = function (x) {
ok(arguments.length === 0, "arguments.length = " + arguments.length);
return "test";
};
ok((tmp = obj.toLocaleString()) === "test", "obj.toLocaleString() = " + tmp);
ok((tmp = obj.toLocaleString(1)) === "test", "obj.toLocaleString(1) = " + tmp);
ok(obj === obj.valueOf(), "obj !== obj.valueOf");
ok("".length === 0, "\"\".length = " + "".length);
ok(getVT("".length) == "VT_I4", "\"\".length = " + "".length);
ok("abc".length === 3, "\"abc\".length = " + "abc".length);
ok(String.prototype.length === 0, "String.prototype.length = " + String.prototype.length);
tmp = "".toString();
ok(tmp === "", "''.toString() = " + tmp);
tmp = "test".toString();
ok(tmp === "test", "''.toString() = " + tmp);
tmp = "test".toString(3);
ok(tmp === "test", "''.toString(3) = " + tmp);
tmp = "".valueOf();
ok(tmp === "", "''.valueOf() = " + tmp);
tmp = "test".valueOf();
ok(tmp === "test", "''.valueOf() = " + tmp);
tmp = "test".valueOf(3);
ok(tmp === "test", "''.valueOf(3) = " + tmp);
var str = new String("test");
ok(str.toString() === "test", "str.toString() = " + str.toString());
var str = new String();
ok(str.toString() === "", "str.toString() = " + str.toString());
var str = new String("test", "abc");
ok(str.toString() === "test", "str.toString() = " + str.toString());
str = new String("test");
ok(str.length === 4, "str.length = " + str.length);
str.length = 3;
str.length = 5;
ok(str.length === 4, "str.length = " + str.length);
var strObj = new Object();
strObj.toString = function() { return "abcd" };
strObj.substr = String.prototype.substr;
strObj.lastIndexOf = String.prototype.lastIndexOf;
tmp = "value " + str;
ok(tmp === "value test", "'value ' + str = " + tmp);
tmp = String();
ok(tmp === "", "String() = " + tmp);
tmp = String(false);
ok(tmp === "false", "String(false) = " + tmp);
tmp = String(null);
ok(tmp === "null", "String(null) = " + tmp);
tmp = String("test");
ok(tmp === "test", "String('test') = " + tmp);
tmp = String("test", "abc");
ok(tmp === "test", "String('test','abc') = " + tmp);
tmp = "abc".charAt(0);
ok(tmp === "a", "'abc',charAt(0) = " + tmp);
tmp = "abc".charAt(1);
ok(tmp === "b", "'abc',charAt(1) = " + tmp);
tmp = "abc".charAt(2);
ok(tmp === "c", "'abc',charAt(2) = " + tmp);
tmp = "abc".charAt(3);
ok(tmp === "", "'abc',charAt(3) = " + tmp);
tmp = "abc".charAt(4);
ok(tmp === "", "'abc',charAt(4) = " + tmp);
tmp = "abc".charAt();
ok(tmp === "a", "'abc',charAt() = " + tmp);
tmp = "abc".charAt(-1);
ok(tmp === "", "'abc',charAt(-1) = " + tmp);
tmp = "abc".charAt(0,2);
ok(tmp === "a", "'abc',charAt(0.2) = " + tmp);
tmp = "abc".charAt(NaN);
ok(tmp === "a", "'abc',charAt(NaN) = " + tmp);
tmp = "abc".charAt(bigInt);
ok(tmp === "", "'abc',charAt(bigInt) = " + tmp);
tmp = "abc".charCodeAt(0);
ok(tmp === 0x61, "'abc'.charCodeAt(0) = " + tmp);
tmp = "abc".charCodeAt(1);
ok(tmp === 0x62, "'abc'.charCodeAt(1) = " + tmp);
tmp = "abc".charCodeAt(2);
ok(tmp === 0x63, "'abc'.charCodeAt(2) = " + tmp);
tmp = "abc".charCodeAt();
ok(tmp === 0x61, "'abc'.charCodeAt() = " + tmp);
tmp = "abc".charCodeAt(true);
ok(tmp === 0x62, "'abc'.charCodeAt(true) = " + tmp);
tmp = "abc".charCodeAt(0,2);
ok(tmp === 0x61, "'abc'.charCodeAt(0,2) = " + tmp);
tmp = "\u49F4".charCodeAt(0);
ok(tmp === 0x49F4, "'\u49F4'.charCodeAt(0) = " + tmp);
tmp = "\052".charCodeAt(0);
ok(tmp === 0x2A, "'\052'.charCodeAt(0) = " + tmp);
tmp = "\xa2".charCodeAt(0);
ok(tmp === 0xA2, "'\xa2'.charCodeAt(0) = " + tmp);
tmp = "abc".charCodeAt(bigInt);
ok(isNaN(tmp), "'abc'.charCodeAt(bigInt) = " + tmp);
tmp = "abcd".substring(1,3);
ok(tmp === "bc", "'abcd'.substring(1,3) = " + tmp);
tmp = "abcd".substring(-1,3);
ok(tmp === "abc", "'abcd'.substring(-1,3) = " + tmp);
tmp = "abcd".substring(1,6);
ok(tmp === "bcd", "'abcd'.substring(1,6) = " + tmp);
tmp = "abcd".substring(3,1);
ok(tmp === "bc", "'abcd'.substring(3,1) = " + tmp);
tmp = "abcd".substring(2,2);
ok(tmp === "", "'abcd'.substring(2,2) = " + tmp);
tmp = "abcd".substring(true,"3");
ok(tmp === "bc", "'abcd'.substring(true,'3') = " + tmp);
tmp = "abcd".substring(1,3,2);
ok(tmp === "bc", "'abcd'.substring(1,3,2) = " + tmp);
tmp = "abcd".substring();
ok(tmp === "abcd", "'abcd'.substring() = " + tmp);
tmp = "abcd".substr(1,3);
ok(tmp === "bcd", "'abcd'.substr(1,3) = " + tmp);
tmp = "abcd".substr(-1,3);
ok(tmp === "abc", "'abcd'.substr(-1,3) = " + tmp);
tmp = "abcd".substr(1,6);
ok(tmp === "bcd", "'abcd'.substr(1,6) = " + tmp);
tmp = "abcd".substr(2,-1);
ok(tmp === "", "'abcd'.substr(3,1) = " + tmp);
tmp = "abcd".substr(2,0);
ok(tmp === "", "'abcd'.substr(2,2) = " + tmp);
tmp = "abcd".substr(true,"3");
ok(tmp === "bcd", "'abcd'.substr(true,'3') = " + tmp);
tmp = "abcd".substr(1,3,2);
ok(tmp === "bcd", "'abcd'.substr(1,3,2) = " + tmp);
tmp = "abcd".substr();
ok(tmp === "abcd", "'abcd'.substr() = " + tmp);
tmp = strObj.substr(1,1);
ok(tmp === "b", "'abcd'.substr(1,3) = " + tmp);
tmp = "abcd".slice(1,3);
ok(tmp === "bc", "'abcd'.slice(1,3) = " + tmp);
tmp = "abcd".slice(1,-1);
ok(tmp === "bc", "'abcd'.slice(1,-1) = " + tmp);
tmp = "abcd".slice(-3,3);
ok(tmp === "bc", "'abcd'.slice(-3,3) = " + tmp);
tmp = "abcd".slice(-6,3);
ok(tmp === "abc", "'abcd'.slice(-6,3) = " + tmp);
tmp = "abcd".slice(3,1);
ok(tmp === "", "'abcd'.slice(3,1) = " + tmp);
tmp = "abcd".slice(true,3);
ok(tmp === "bc", "'abcd'.slice(true,3) = " + tmp);
tmp = "abcd".slice();
ok(tmp === "abcd", "'abcd'.slice() = " + tmp);
tmp = "abcd".slice(1);
ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp);
tmp = "abc".concat(["d",1],2,false);
ok(tmp === "abcd,12false", "concat returned " + tmp);
var arr = new Array(2,"a");
arr.concat = String.prototype.concat;
tmp = arr.concat("d");
ok(tmp === "2,ad", "arr.concat = " + tmp);
m = "a+bcabc".match("a+");
ok(typeof(m) === "object", "typeof m is not object");
ok(m.length === 1, "m.length is not 1");
ok(m["0"] === "a", "m[0] is not \"a\"");
r = "- [test] -".replace("[test]", "success");
ok(r === "- success -", "r = " + r + " expected '- success -'");
r = "- [test] -".replace("[test]", "success", "test");
ok(r === "- success -", "r = " + r + " expected '- success -'");
r = "test".replace();
ok(r === "test", "r = " + r + " expected 'test'");
function replaceFunc3(m, off, str) {
ok(arguments.length === 3, "arguments.length = " + arguments.length);
ok(m === "[test]", "m = " + m + " expected [test]");
ok(off === 1, "off = " + off + " expected 0");
ok(str === "-[test]-", "str = " + arguments[3]);
return "ret";
}
r = "-[test]-".replace("[test]", replaceFunc3);
ok(r === "-ret-", "r = " + r + " expected '-ret-'");
r = "-[test]-".replace("[test]", replaceFunc3, "test");
ok(r === "-ret-", "r = " + r + " expected '-ret-'");
r = "x,x,x".replace("x", "y");
ok(r === "y,x,x", "r = " + r + " expected 'y,x,x'");
r = "x,x,x".replace("", "y");
ok(r === "yx,x,x", "r = " + r + " expected 'yx,x,x'");
r = "x,x,x".replace("", "");
ok(r === "x,x,x", "r = " + r + " expected 'x,x,x'");
r = "1,2,3".split(",");
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 3, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(r[2] === "3", "r[2] = " + r[2]);
r = "1,2,3".split(",*");
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "1,2,3", "r[0] = " + r[0]);
r = "123".split("");
ok(r.length === 3, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(r[2] === "3", "r[2] = " + r[2]);
r = "123".split(2);
ok(r.length === 2, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "3", "r[1] = " + r[1]);
r = "1,2,".split(",");
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 3, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(r[2] === "", "r[2] = " + r[2]);
r = "1,2,3".split(",", 2);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 2, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
r = "1,2,3".split(",", 0);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 0, "r.length = " + r.length);
r = "1,2,3".split(",", -1);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 3, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(r[2] === "3", "r[1] = " + r[1]);
r = "1,2,3".split(undefined);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "1,2,3", "r[0] = " + r[0]);
r = "1,undefined2undefined,3".split(undefined);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 3, "r.length = " + r.length);
ok(r[0] === "1,", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(r[2] === ",3", "r[2] = " + r[2]);
r = "1,undefined2undefined,3".split();
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "1,undefined2undefined,3", "r[0] = " + r[0]);
r = "".split();
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 1, "r.length = " + r.length);
ok(r[0] === "", "r[0] = " + r[0]);
(function() {
function test(string, separator, result) {
var r = string.split(separator);
ok(r == result, "\"" + string + "\".split(" + separator + ") returned " + r + " expected " + result);
}
test("test", /^|\s+/, "test");
test("test", /$|\s+/, "test");
test("test", /^|./, "t");
test("test", /.*/, "");
test("test", /x*/, "t,e,s,t");
test("test", /$|x*/, "t,e,s,t");
test("test", /^|x*/, "t,e,s,t");
test("test", /t*/, "e,s");
test("xaabaax", /a*|b*/, "x,b,x");
test("xaabaax", /a+|b+/, "x,x");
test("xaabaax", /a+|b*/, "x,x");
test("xaaxbaax", /b+|a+/, "x,x,x");
test("test", /^|t/, "tes");
test("test", /^|t/, "tes");
test("a,,b", /,/, "a,b");
test("ab", /a*/, "b");
test("aab", "a", ",,b");
test("a", "a", ",");
function test_length(string, separator, len) {
var r = string.split(separator);
ok(r.length === len, "\"" + string + "\".split(" + separator + ").length = "
+ r.length + " expected " + len);
}
test_length("", /a*/, 0);
test_length("", /a+/, 1);
test_length("", "", 0);
test_length("", "x", 1);
})();
tmp = "abcd".indexOf("bc",0);
ok(tmp === 1, "indexOf = " + tmp);
tmp = "abcd".indexOf("bc",1);
ok(tmp === 1, "indexOf = " + tmp);
tmp = "abcd".indexOf("bc");
ok(tmp === 1, "indexOf = " + tmp);
tmp = "abcd".indexOf("ac");
ok(tmp === -1, "indexOf = " + tmp);
tmp = "abcd".indexOf("bc",2);
ok(tmp === -1, "indexOf = " + tmp);
tmp = "abcd".indexOf("a",0);
ok(tmp === 0, "indexOf = " + tmp);
tmp = "abcd".indexOf("bc",0,"test");
ok(tmp === 1, "indexOf = " + tmp);
tmp = "abcd".indexOf();
ok(tmp == -1, "indexOf = " + tmp);
tmp = "abcd".indexOf("b", bigInt);
ok(tmp == -1, "indexOf = " + tmp);
tmp = "abcd".indexOf("abcd",0);
ok(tmp === 0, "indexOf = " + tmp);
tmp = "abcd".indexOf("abcd",1);
ok(tmp === -1, "indexOf = " + tmp);
tmp = ("ab" + String.fromCharCode(0) + "cd").indexOf(String.fromCharCode(0));
ok(tmp === 2, "indexOf = " + tmp);
tmp = "abcd".lastIndexOf("bc",1);
ok(tmp === 1, "lastIndexOf = " + tmp);
tmp = "abcd".lastIndexOf("bc",2);
ok(tmp === 1, "lastIndexOf = " + tmp);
tmp = "abcd".lastIndexOf("bc");
ok(tmp === 1, "lastIndexOf = " + tmp);
tmp = "abcd".lastIndexOf("ac");
ok(tmp === -1, "lastIndexOf = " + tmp);
tmp = "abcd".lastIndexOf("d",10);
ok(tmp === 3, "lastIndexOf = " + tmp);
tmp = "abcd".lastIndexOf("bc",0,"test");
ok(tmp === -1, "lastIndexOf = " + tmp);
tmp = "abcd".lastIndexOf();
ok(tmp === -1, "lastIndexOf = " + tmp);
tmp = "aaaa".lastIndexOf("a",2);
ok(tmp == 2, "lastIndexOf = " + tmp);
tmp = strObj.lastIndexOf("b");
ok(tmp === 1, "lastIndexOf = " + tmp);
tmp = "bbb".lastIndexOf("b", bigInt);
ok(tmp === 2, "lastIndexOf = " + tmp);
tmp = "abcd".lastIndexOf("abcd",4);
ok(tmp === 0, "lastIndexOf = " + tmp);
tmp = "abcd".lastIndexOf("abcd",0);
ok(tmp === 0, "lastIndexOf = " + tmp);
tmp = ("ab" + String.fromCharCode(0) + "cd").lastIndexOf(String.fromCharCode(0));
ok(tmp === 2, "lastIndexOf = " + tmp);
tmp = "".toLowerCase();
ok(tmp === "", "''.toLowerCase() = " + tmp);
tmp = "test".toLowerCase();
ok(tmp === "test", "''.toLowerCase() = " + tmp);
tmp = "test".toLowerCase(3);
ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
tmp = "tEsT".toLowerCase();
ok(tmp === "test", "''.toLowerCase() = " + tmp);
tmp = "tEsT".toLocaleLowerCase();
ok(tmp === "test", "''.toLocaleLowerCase() = " + tmp);
tmp = "tEsT".toLowerCase(3);
ok(tmp === "test", "''.toLowerCase(3) = " + tmp);
tmp = ("tE" + String.fromCharCode(0) + "sT").toLowerCase();
ok(tmp === "te" + String.fromCharCode(0) + "st", "''.toLowerCase() = " + tmp);
ok(String.prototype.toLocaleLowerCase != String.prototype.toLowerCase,
"String.prototype.toLocaleLowerCase == String.prototype.toLowerCase");
tmp = "".toUpperCase();
ok(tmp === "", "''.toUpperCase() = " + tmp);
tmp = "TEST".toUpperCase();
ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
tmp = "TEST".toUpperCase(3);
ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
tmp = "tEsT".toUpperCase();
ok(tmp === "TEST", "''.toUpperCase() = " + tmp);
tmp = "tEsT".toUpperCase(3);
ok(tmp === "TEST", "''.toUpperCase(3) = " + tmp);
tmp = "tEsT".toLocaleUpperCase(3);
ok(tmp === "TEST", "''.toLocaleUpperCase(3) = " + tmp);
tmp = ("tE" + String.fromCharCode(0) + "sT").toUpperCase();
ok(tmp === "TE" + String.fromCharCode(0) + "ST", "''.toUpperCase() = " + tmp);
ok(String.prototype.toLocaleUpperCase != String.prototype.toUpperCase,
"String.prototype.toLocaleUpperCase == String.prototype.toUpperCase");
tmp = "".anchor();
ok(tmp === "", "''.anchor() = " + tmp);
tmp = "".anchor(3);
ok(tmp === "", "''.anchor(3) = " + tmp);
tmp = "".anchor("red");
ok(tmp === "", "''.anchor('red') = " + tmp);
tmp = "test".anchor();
ok(tmp === "test", "'test'.anchor() = " + tmp);
tmp = "test".anchor(3);
ok(tmp === "test", "'test'.anchor(3) = " + tmp);
tmp = "test".anchor("green");
ok(tmp === "test", "'test'.anchor('green') = " + tmp);
tmp = "".big();
ok(tmp === "", "''.big() = " + tmp);
tmp = "".big(3);
ok(tmp === "", "''.big(3) = " + tmp);
tmp = "test".big();
ok(tmp === "test", "'test'.big() = " + tmp);
tmp = "test".big(3);
ok(tmp === "test", "'test'.big(3) = " + tmp);
tmp = "".blink();
ok(tmp === "", "''.blink() = " + tmp);
tmp = "".blink(3);
ok(tmp === "", "''.blink(3) = " + tmp);
tmp = "test".blink();
ok(tmp === "", "'test'.blink() = " + tmp);
tmp = "test".blink(3);
ok(tmp === "", "'test'.blink(3) = " + tmp);
tmp = "".bold();
ok(tmp === "", "''.bold() = " + tmp);
tmp = "".bold(3);
ok(tmp === "", "''.bold(3) = " + tmp);
tmp = "test".bold();
ok(tmp === "test", "'test'.bold() = " + tmp);
tmp = "test".bold(3);
ok(tmp === "test", "'test'.bold(3) = " + tmp);
tmp = "".fixed();
ok(tmp === "", "''.fixed() = " + tmp);
tmp = "".fixed(3);
ok(tmp === "", "''.fixed(3) = " + tmp);
tmp = "test".fixed();
ok(tmp === "test", "'test'.fixed() = " + tmp);
tmp = "test".fixed(3);
ok(tmp === "test", "'test'.fixed(3) = " + tmp);
tmp = "".fontcolor();
ok(tmp === "", "''.fontcolor() = " + tmp);
tmp = "".fontcolor(3);
ok(tmp === "", "''.fontcolor(3) = " + tmp);
tmp = "".fontcolor("red");
ok(tmp === "", "''.fontcolor('red') = " + tmp);
tmp = "test".fontcolor();
ok(tmp === "test", "'test'.fontcolor() = " + tmp);
tmp = "test".fontcolor(3);
ok(tmp === "test", "'test'.fontcolor(3) = " + tmp);
tmp = "test".fontcolor("green");
ok(tmp === "test", "'test'.fontcolor('green') = " + tmp);
tmp = "".fontsize();
ok(tmp === "", "''.fontsize() = " + tmp);
tmp = "".fontsize(3);
ok(tmp === "", "''.fontsize(3) = " + tmp);
tmp = "".fontsize("red");
ok(tmp === "", "''.fontsize('red') = " + tmp);
tmp = "test".fontsize();
ok(tmp === "test", "'test'.fontsize() = " + tmp);
tmp = "test".fontsize(3);
ok(tmp === "test", "'test'.fontsize(3) = " + tmp);
tmp = "test".fontsize("green");
ok(tmp === "test", "'test'.fontsize('green') = " + tmp);
tmp = ("".fontcolor()).fontsize();
ok(tmp === "", "(''.fontcolor()).fontsize() = " + tmp);
tmp = "".italics();
ok(tmp === "", "''.italics() = " + tmp);
tmp = "".italics(3);
ok(tmp === "", "''.italics(3) = " + tmp);
tmp = "test".italics();
ok(tmp === "test", "'test'.italics() = " + tmp);
tmp = "test".italics(3);
ok(tmp === "test", "'test'.italics(3) = " + tmp);
tmp = "".link();
ok(tmp === "", "''.link() = " + tmp);
tmp = "".link(3);
ok(tmp === "", "''.link(3) = " + tmp);
tmp = "".link("red");
ok(tmp === "", "''.link('red') = " + tmp);
tmp = "test".link();
ok(tmp === "test", "'test'.link() = " + tmp);
tmp = "test".link(3);
ok(tmp === "test", "'test'.link(3) = " + tmp);
tmp = "test".link("green");
ok(tmp === "test", "'test'.link('green') = " + tmp);
tmp = "".small();
ok(tmp === "", "''.small() = " + tmp);
tmp = "".small(3);
ok(tmp === "", "''.small(3) = " + tmp);
tmp = "test".small();
ok(tmp === "test", "'test'.small() = " + tmp);
tmp = "test".small(3);
ok(tmp === "test", "'test'.small(3) = " + tmp);
tmp = "".strike();
ok(tmp === "", "''.strike() = " + tmp);
tmp = "".strike(3);
ok(tmp === "", "''.strike(3) = " + tmp);
tmp = "test".strike();
ok(tmp === "test", "'test'.strike() = " + tmp);
tmp = "test".strike(3);
ok(tmp === "test", "'test'.strike(3) = " + tmp);
tmp = "".sub();
ok(tmp === "", "''.sub() = " + tmp);
tmp = "".sub(3);
ok(tmp === "", "''.sub(3) = " + tmp);
tmp = "test".sub();
ok(tmp === "test", "'test'.sub() = " + tmp);
tmp = "test".sub(3);
ok(tmp === "test", "'test'.sub(3) = " + tmp);
tmp = "".sup();
ok(tmp === "", "''.sup() = " + tmp);
tmp = "".sup(3);
ok(tmp === "", "''.sup(3) = " + tmp);
tmp = "test".sup();
ok(tmp === "test", "'test'.sup() = " + tmp);
tmp = "test".sup(3);
ok(tmp === "test", "'test'.sup(3) = " + tmp);
ok(String.fromCharCode() === "", "String.fromCharCode() = " + String.fromCharCode());
ok(String.fromCharCode(65,"66",67) === "ABC", "String.fromCharCode(65,'66',67) = " + String.fromCharCode(65,"66",67));
ok(String.fromCharCode(1024*64+65, -1024*64+65) === "AA",
"String.fromCharCode(1024*64+65, -1024*64+65) = " + String.fromCharCode(1024*64+65, -1024*64+65));
ok(String.fromCharCode(65, NaN, undefined).length === 3,
"String.fromCharCode(65, NaN, undefined).length = " + String.fromCharCode(65, NaN, undefined).length);
var arr = new Array();
ok(typeof(arr) === "object", "arr () is not object");
ok((arr.length === 0), "arr.length is not 0");
ok(arr["0"] === undefined, "arr[0] is not undefined");
var arr = new Array(1, 2, "test");
ok(typeof(arr) === "object", "arr (1,2,test) is not object");
ok((arr.length === 3), "arr.length is not 3");
ok(arr["0"] === 1, "arr[0] is not 1");
ok(arr["1"] === 2, "arr[1] is not 2");
ok(arr["2"] === "test", "arr[2] is not \"test\"");
arr["7"] = true;
ok((arr.length === 8), "arr.length is not 8");
tmp = "" + [];
ok(tmp === "", "'' + [] = " + tmp);
tmp = "" + [1,true];
ok(tmp === "1,true", "'' + [1,true] = " + tmp);
var arr = new Array(6);
ok(typeof(arr) === "object", "arr (6) is not object");
ok((arr.length === 6), "arr.length is not 6");
ok(arr["0"] === undefined, "arr[0] is not undefined");
ok(arr.push() === 6, "arr.push() !== 6");
ok(arr.push(1) === 7, "arr.push(1) !== 7");
ok(arr[6] === 1, "arr[6] != 1");
ok(arr.length === 7, "arr.length != 10");
ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
ok(arr[8] === "b", "arr[8] != 'b'");
ok(arr.length === 10, "arr.length != 10");
var arr = new Object();
arr.push = Array.prototype.push;
arr.length = 6;
ok(arr.push() === 6, "arr.push() !== 6");
ok(arr.push(1) === 7, "arr.push(1) !== 7");
ok(arr[6] === 1, "arr[6] != 1");
ok(arr.length === 7, "arr.length != 10");
ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
ok(arr[8] === "b", "arr[8] != 'b'");
ok(arr.length === 10, "arr.length != 10");
arr.pop = Array.prototype.pop;
ok(arr.pop() === false, "arr.pop() !== false");
ok(arr[8] === "b", "arr[8] !== 'b'");
ok(arr.pop() === 'b', "arr.pop() !== 'b'");
ok(arr[8] === undefined, "arr[8] !== undefined");
arr = [3,4,5];
tmp = arr.pop();
ok(arr.length === 2, "arr.length = " + arr.length);
ok(tmp === 5, "pop() = " + tmp);
tmp = arr.pop(2);
ok(arr.length === 1, "arr.length = " + arr.length);
ok(tmp === 4, "pop() = " + tmp);
tmp = arr.pop();
ok(arr.length === 0, "arr.length = " + arr.length);
ok(tmp === 3, "pop() = " + tmp);
for(tmp in arr)
ok(false, "not deleted " + tmp);
tmp = arr.pop();
ok(arr.length === 0, "arr.length = " + arr.length);
ok(tmp === undefined, "tmp = " + tmp);
arr = new Object();
arr.pop = Array.prototype.pop;
tmp = arr.pop();
ok(arr.length === 0, "arr.length = " + arr.length);
ok(tmp === undefined, "tmp = " + tmp);
arr = [,,,,,];
tmp = arr.pop();
ok(arr.length === 5, "arr.length = " + arr.length);
ok(tmp === undefined, "tmp = " + tmp);
tmp = [1,2,,,].pop();
ok(tmp === undefined, "tmp = " + tmp);
function PseudoArray() {
this[0] = 0;
}
PseudoArray.prototype = {length: 1};
arr = new PseudoArray();
Array.prototype.push.call(arr, 2);
ok(arr.propertyIsEnumerable("length"), "arr.length is not enumerable");
arr = [1,2,null,false,undefined,,"a"];
tmp = arr.join();
ok(tmp === "1,2,,false,,,a", "arr.join() = " + tmp);
tmp = arr.join(";");
ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
tmp = arr.join(";","test");
ok(tmp === "1;2;;false;;;a", "arr.join(';') = " + tmp);
tmp = arr.join("");
ok(tmp === "12falsea", "arr.join('') = " + tmp);
tmp = arr.toString();
ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
tmp = arr.toString("test");
ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
arr = ["a", "b"];
tmp = arr.join(String.fromCharCode(0));
ok(tmp === "a" + String.fromCharCode(0) + "b", "arr.join(String.fromCharCode(0)) = " + tmp);
arr = new Object();
arr.length = 3;
arr[0] = "aa";
arr[2] = 2;
arr[7] = 3;
arr.join = Array.prototype.join;
tmp = arr.join(",");
ok(arr.length === 3, "arr.length = " + arr.length);
ok(tmp === "aa,,2", "tmp = " + tmp);
arr = [5,true,2,-1,3,false,"2.5"];
tmp = arr.sort(function(x,y) { return y-x; });
ok(tmp === arr, "tmp !== arr");
tmp = [5,3,"2.5",2,true,false,-1];
for(var i=0; i < arr.length; i++)
ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
tmp = [3,1,2].sort(function(x,y) { return y-x; }).join();
ok(tmp === "3,2,1", "reverse sorted [3,1,2] = " + tmp);
tmp = [3,1,2].sort(null).join();
ok(tmp === "1,2,3", "null sorted [3,1,2] = " + tmp);
try {
tmp = [3,1,2].sort(function(x,y) { return y-x; }, 1, 2, 3);
ok(false, "expected sort(undefined) exception");
} catch(e) {
ok(e.name === "TypeError", "got exception " + e.name);
}
arr = [5,false,2,0,"abc",3,"a",-1];
tmp = arr.sort();
ok(tmp === arr, "tmp !== arr");
tmp = [-1,0,2,3,5,"a","abc",false];
for(var i=0; i < arr.length; i++)
ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
arr = ["a", "b", "ab"];
tmp = ["a", "ab", "b"];
ok(arr.sort() === arr, "arr.sort() !== arr");
for(var i=0; i < arr.length; i++)
ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
arr = new Object();
arr.length = 3;
arr[0] = 1;
arr[2] = "aa";
arr.sort = Array.prototype.sort;
tmp = arr.sort();
ok(arr === tmp, "tmp !== arr");
ok(arr[0]===1 && arr[1]==="aa" && arr[2]===undefined, "arr is sorted incorrectly");
tmp = [["bb","aa"],["ab","aa"]].sort().toString();
ok(tmp === "ab,aa,bb,aa", "sort() = " + tmp);
tmp = [["bb","aa"],"ab"].sort().toString();
ok(tmp === "ab,bb,aa", "sort() = " + tmp);
tmp = [["bb","aa"],"cc"].sort().toString();
ok(tmp === "bb,aa,cc", "sort() = " + tmp);
tmp = [2,"1"].sort().toString();
ok(tmp === "1,2", "sort() = " + tmp);
tmp = ["2",1].sort().toString();
ok(tmp === "1,2", "sort() = " + tmp);
tmp = [,,0,"z"].sort().toString();
ok(tmp === "0,z,,", "sort() = " + tmp);
tmp = ["a,b",["a","a"],["a","c"]].sort().toString();
ok(tmp === "a,a,a,b,a,c", "sort() = " + tmp);
arr = ["1", "2", "3"];
arr.length = 1;
ok(arr.length === 1, "arr.length = " + arr.length);
arr.length = 3;
ok(arr.length === 3, "arr.length = " + arr.length);
ok(arr.toString() === "1,,", "arr.toString() = " + arr.toString());
arr = Array("a","b","c");
ok(arr.toString() === "a,b,c", "arr.toString() = " + arr.toString());
ok(arr.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.valueOf");
ok(arr === arr.valueOf(), "arr !== arr.valueOf");
arr = [1,2,3];
tmp = arr.reverse();
ok(tmp === arr, "tmp !== arr");
ok(arr.length === 3, "arr.length = " + arr.length);
ok(arr.toString() === "3,2,1", "arr.toString() = " + arr.toString());
arr = [];
arr[3] = 5;
arr[5] = 1;
tmp = arr.reverse();
ok(tmp === arr, "tmp !== arr");
ok(arr.length === 6, "arr.length = " + arr.length);
ok(arr.toString() === "1,,5,,,", "arr.toString() = " + arr.toString());
arr = new Object();
arr.length = 3;
arr[0] = "aa";
arr[2] = 2;
arr[7] = 3;
arr.reverse = Array.prototype.reverse;
tmp = arr.reverse();
ok(tmp === arr, "tmp !== arr");
ok(arr.length === 3, "arr.length = " + arr.length);
ok(arr[0] === 2 && arr[1] === undefined && arr[2] === "aa", "unexpected array");
arr = [1,2,3];
tmp = arr.unshift(0);
ok(tmp === (invokeVersion < 2 ? undefined : 4), "[1,2,3].unshift(0) returned " +tmp);
ok(arr.length === 4, "arr.length = " + arr.length);
ok(arr.toString() === "0,1,2,3", "arr.toString() = " + arr.toString());
arr = new Array(3);
arr[0] = 1;
arr[2] = 3;
tmp = arr.unshift(-1,0);
ok(tmp === (invokeVersion < 2 ? undefined : 5), "unshift returned " +tmp);
ok(arr.length === 5, "arr.length = " + arr.length);
ok(arr.toString() === "-1,0,1,,3", "arr.toString() = " + arr.toString());
arr = [1,2,3];
tmp = arr.unshift();
ok(tmp === (invokeVersion < 2 ? undefined : 3), "unshift returned " +tmp);
ok(arr.length === 3, "arr.length = " + arr.length);
ok(arr.toString() === "1,2,3", "arr.toString() = " + arr.toString());
arr = new Object();
arr.length = 2;
arr[0] = 1;
arr[1] = 2;
tmp = Array.prototype.unshift.call(arr, 0);
ok(tmp === (invokeVersion < 2 ? undefined : 3), "unshift returned " +tmp);
ok(arr.length === 3, "arr.length = " + arr.length);
ok(arr[0] === 0 && arr[1] === 1 && arr[2] === 2, "unexpected array");
arr = [1,2,,4];
tmp = arr.shift();
ok(tmp === 1, "[1,2,,4].shift() = " + tmp);
ok(arr.toString() === "2,,4", "arr = " + arr.toString());
arr = [];
tmp = arr.shift();
ok(tmp === undefined, "[].shift() = " + tmp);
ok(arr.toString() === "", "arr = " + arr.toString());
arr = [1,2,,4];
tmp = arr.shift(2);
ok(tmp === 1, "[1,2,,4].shift(2) = " + tmp);
ok(arr.toString() === "2,,4", "arr = " + arr.toString());
arr = [1,];
tmp = arr.shift();
ok(tmp === 1, "[1,].shift() = " + tmp);
ok(arr.toString() === "", "arr = " + arr.toString());
obj = new Object();
obj[0] = "test";
obj[2] = 3;
obj.length = 3;
tmp = Array.prototype.shift.call(obj);
ok(tmp === "test", "obj.shift() = " + tmp);
ok(obj.length == 2, "obj.length = " + obj.length);
ok(obj[1] === 3, "obj[1] = " + obj[1]);
var num = new Number(6);
arr = [0,1,2];
tmp = arr.concat(3, [4,5], num);
ok(tmp !== arr, "tmp === arr");
for(var i=0; i<6; i++)
ok(tmp[i] === i, "tmp[" + i + "] = " + tmp[i]);
ok(tmp[6] === num, "tmp[6] !== num");
ok(tmp.length === 7, "tmp.length = " + tmp.length);
arr = [].concat();
ok(arr.length === 0, "arr.length = " + arr.length);
arr = [1,];
tmp = arr.concat([2]);
ok(tmp.length === 3, "tmp.length = " + tmp.length);
ok(tmp[1] === undefined, "tmp[1] = " + tmp[1]);
arr = [1,false,'a',null,undefined,'a'];
ok(arr.slice(0,6).toString() === "1,false,a,,,a", "arr.slice(0,6).toString() = " + arr.slice(0,6));
ok(arr.slice(0,6).length === 6, "arr.slice(0,6).length = " + arr.slice(0,6).length);
ok(arr.slice().toString() === "1,false,a,,,a", "arr.slice().toString() = " + arr.slice());
ok(arr.slice("abc").toString() === "1,false,a,,,a", "arr.slice(\"abc\").toString() = " + arr.slice("abc"));
ok(arr.slice(3,8).toString() === ",,a", "arr.slice(3,8).toString() = " + arr.slice(3,8));
ok(arr.slice(3,8).length === 3, "arr.slice(3,8).length = " + arr.slice(3,8).length);
ok(arr.slice(1).toString() === "false,a,,,a", "arr.slice(1).toString() = " + arr.slice(1));
ok(arr.slice(-2).toString() === ",a", "arr.slice(-2).toString() = " + arr.slice(-2));
ok(arr.slice(3,1).toString() === "", "arr.slice(3,1).toString() = " + arr.slice(3,1));
tmp = arr.slice(0,6);
for(var i=0; i < arr.length; i++)
ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
arr[12] = 2;
ok(arr.slice(5).toString() === "a,,,,,,,2", "arr.slice(5).toString() = " + arr.slice(5).toString());
ok(arr.slice(5).length === 8, "arr.slice(5).length = " + arr.slice(5).length);
arr = [1,2,3,4,5];
tmp = arr.splice(2,2);
ok(tmp.toString() == "3,4", "arr.splice(2,2) returned " + tmp.toString());
ok(arr.toString() == "1,2,5", "arr.splice(2,2) is " + arr.toString());
arr = [1,2,3,4,5];
tmp = arr.splice(2,2,"a");
ok(tmp.toString() == "3,4", "arr.splice(2,2,'a') returned " + tmp.toString());
ok(arr.toString() == "1,2,a,5", "arr.splice(2,2,'a') is " + arr.toString());
arr = [1,2,3,4,5];
tmp = arr.splice(2,2,'a','b','c');
ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp.toString());
ok(arr.toString() == "1,2,a,b,c,5", "arr.splice(2,2,'a','b','c') is " + arr.toString());
arr = [1,2,3,4,];
tmp = arr.splice(2,2,'a','b','c');
ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b','c') returned " + tmp.toString());
ok(arr.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr.toString());
arr = [1,2,3,4,];
arr.splice(2,2,'a','b','c');
ok(arr.toString() == "1,2,a,b,c,", "arr.splice(2,2,'a','b','c') is " + arr.toString());
arr = [1,2,3,4,5];
tmp = arr.splice(2,2,'a','b');
ok(tmp.toString() == "3,4", "arr.splice(2,2,'a','b') returned " + tmp.toString());
ok(arr.toString() == "1,2,a,b,5", "arr.splice(2,2,'a','b') is " + arr.toString());
arr = [1,2,3,4,5];
tmp = arr.splice(-1,2);
ok(tmp.toString() == "5", "arr.splice(-1,2) returned " + tmp.toString());
ok(arr.toString() == "1,2,3,4", "arr.splice(-1,2) is " + arr.toString());
arr = [1,2,3,4,5];
tmp = arr.splice(-10,3);
ok(tmp.toString() == "1,2,3", "arr.splice(-10,3) returned " + tmp.toString());
ok(arr.toString() == "4,5", "arr.splice(-10,3) is " + arr.toString());
arr = [1,2,3,4,5];
tmp = arr.splice(-10,100);
ok(tmp.toString() == "1,2,3,4,5", "arr.splice(-10,100) returned " + tmp.toString());
ok(arr.toString() == "", "arr.splice(-10,100) is " + arr.toString());
arr = [1,2,3,4,5];
tmp = arr.splice(2,-1);
ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString());
ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString());
arr = [1,2,3,4,5];
tmp = arr.splice(2);
ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString());
ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString());
arr = [1,2,3,4,5];
tmp = arr.splice();
ok(tmp.toString() == "", "arr.splice(2,-1) returned " + tmp.toString());
ok(arr.toString() == "1,2,3,4,5", "arr.splice(2,-1) is " + arr.toString());
arr = [1,2,3,4,5];
tmp = arr.splice(bigInt);
ok(tmp.toString() == "", "arr.splice(bigInt) returned " + tmp.toString());
ok(arr.toString() == "1,2,3,4,5", "arr.splice(bigInt) is " + arr.toString());
arr = [1,2,3,4,5];
tmp = arr.splice(-bigInt);
ok(tmp.toString() == "", "arr.splice(-bigInt) returned " + tmp.toString());
ok(arr.toString() == "1,2,3,4,5", "arr.splice(-bigInt) is " + arr.toString());
if(invokeVersion >= 2) {
arr = [1,2,3,4,5];
tmp = arr.splice(2, bigInt);
ok(tmp.toString() == "3,4,5", "arr.splice(2, bigInt) returned " + tmp.toString());
ok(arr.toString() == "1,2", "arr.splice(2, bigInt) is " + arr.toString());
}
arr = [1,2,3,4,5];
tmp = arr.splice(2, -bigInt);
ok(tmp.toString() == "", "arr.splice(2, -bigInt) returned " + tmp.toString());
ok(arr.toString() == "1,2,3,4,5", "arr.splice(2, -bigInt) is " + arr.toString());
obj = new Object();
obj.length = 3;
obj[0] = 1;
obj[1] = 2;
obj[2] = 3;
tmp = Array.prototype.splice.call(obj, 1, 1, 'a', 'b');
ok(tmp.toString() === "2", "obj.splice returned " + tmp);
ok(obj.length === 4, "obj.length = " + obj.length);
ok(obj[0] === 1, "obj[0] = " + obj[0]);
ok(obj[1] === 'a', "obj[1] = " + obj[1]);
ok(obj[2] === 'b', "obj[2] = " + obj[2]);
ok(obj[3] === 3, "obj[3] = " + obj[3]);
obj = new Object();
obj.length = 3;
obj[0] = 1;
obj[1] = 2;
obj[2] = 3;
tmp = Array.prototype.slice.call(obj, 1, 2);
ok(tmp.length === 1, "tmp.length = " + tmp.length);
ok(tmp[0] === 2, "tmp[0] = " + tmp[0]);
tmp = (new Number(2)).toString();
ok(tmp === "2", "num(2).toString = " + tmp);
tmp = (new Number()).toString();
ok(tmp === "0", "num().toString = " + tmp);
tmp = (new Number(5.5)).toString(2);
ok(tmp === "101.1", "num(5.5).toString(2) = " + tmp);
tmp = (new Number(12)).toLocaleString();
ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
tmp = Number.prototype.toLocaleString.call(NaN);
ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
tmp = (new Number(3)).toFixed(3);
ok(tmp === "3.000", "num(3).toFixed(3) = " + tmp);
tmp = (new Number(3)).toFixed();
ok(tmp === "3", "Number(3).toFixed() = " + tmp);
tmp = (new Number(0)).toFixed();
ok(tmp === "0", "Number(0).toFixed() = " + tmp);
tmp = (new Number(0)).toFixed(1);
ok(tmp === "0.0", "Number(0).toFixed(1) = " + tmp);
tmp = (new Number(0)).toFixed(2);
ok(tmp === "0.00", "Number(0).toFixed(2) = " + tmp);
tmp = (new Number(1.76)).toFixed(1);
ok(tmp === "1.8", "num(1.76).toFixed(1) = " + tmp);
tmp = (new Number(7.92)).toFixed(5);
ok(tmp === "7.92000", "num(7.92).toFixed(5) = " + tmp);
tmp = (new Number(2.88)).toFixed();
ok(tmp === "3", "num(2.88).toFixed = " + tmp);
tmp = (new Number(-2.5)).toFixed();
ok(tmp === "-3", "num(-2.5).toFixed = " + tmp);
tmp = (new Number(1000000000000000128)).toFixed(0);
//todo_wine ok(tmp === "1000000000000000100", "num(1000000000000000128) = " + tmp);
tmp = (new Number(3.14).toFixed(NaN));
ok(tmp === "3", "num(3.14).toFixed = " + tmp);
tmp = (new Number(0.95).toFixed(1));
ok(tmp === "1.0", "num(0.95).toFixed(1) = " + tmp);
tmp = (new Number(1e900)).toFixed(0);
ok(tmp === "Infinity", "num(1000000000000000128) = " + tmp);
tmp = (new Number(0.12345678901234567890123)).toFixed(20);
ok(tmp === "0.12345678901234568000", "num(0.12345678901234567890123) = " + tmp);
tmp = (new Number(2)).toExponential(3);
ok(tmp === "2.000e+0", "num(2).toExponential(3) = " + tmp);
tmp = (new Number(1.17e-32)).toExponential(20);
ok(tmp === "1.17000000000000000000e-32", "num(1.17e-32).toExponential(20) = " + tmp);
tmp = (new Number(0)).toExponential(7);
ok(tmp === "0.0000000e+0", "num(0).toExponential(7) = " + tmp);
tmp = (new Number(0)).toExponential(0);
ok(tmp === "0e+0", "num(0).toExponential() = " + tmp);
tmp = (new Number(-13.7567)).toExponential();
ok(tmp === "-1.37567e+1", "num(-13.7567).toExponential() = " + tmp);
tmp = (new Number(-32.1)).toExponential();
ok(tmp === "-3.21e+1", "num(-32.1).toExponential() = " + tmp);
tmp = (new Number(4723.4235)).toExponential();
ok(tmp === "4.7234235e+3", "num(4723.4235).toExponential() = " + tmp);
tmp = (new Number(5)).toPrecision(12);
ok(tmp == "5.00000000000", "num(5).toPrecision(12) = " + tmp);
tmp = (new Number(7.73)).toPrecision(7);
ok(tmp == "7.730000", "num(7.73).toPrecision(7) = " + tmp);
tmp = (new Number(-127547.47472)).toPrecision(17);
ok(tmp == "-127547.47472000000", "num(-127547.47472).toPrecision(17) = " + tmp);
tmp = (new Number(0)).toPrecision(3);
ok(tmp == "0.00", "num(0).toPrecision(3) = " + tmp);
tmp = (new Number(42345.52342465464562334)).toPrecision(15);
ok(tmp == "42345.5234246546", "num(42345.52342465464562334).toPrecision(15) = " + tmp);
tmp = (new Number(1.182e30)).toPrecision(5);
ok(tmp == "1.1820e+30", "num(1.182e30)).toPrecision(5) = " + tmp);
tmp = (new Number(1.123)).toPrecision();
ok(tmp == "1.123", "num(1.123).toPrecision() = " + tmp);
ok(Number() === 0, "Number() = " + Number());
ok(Number(false) === 0, "Number(false) = " + Number(false));
ok(Number("43") === 43, "Number('43') = " + Number("43"));
tmp = (new Number(1)).valueOf();
ok(tmp === 1, "(new Number(1)).valueOf = " + tmp);
tmp = (new Number(1,2)).valueOf();
ok(tmp === 1, "(new Number(1,2)).valueOf = " + tmp);
tmp = (new Number()).valueOf();
ok(tmp === 0, "(new Number()).valueOf = " + tmp);
tmp = Number.prototype.valueOf();
ok(tmp === 0, "Number.prototype.valueOf = " + tmp);
function equals(val, base) {
var i;
var num = 0;
var str = val.toString(base);
for(i=0; ival-val/1000 && num= 2) {
obj = new Object();
obj.name = "test";
tmp = Error.prototype.toString.call(obj);
ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
obj = new Object();
obj.name = 6;
obj.message = false;
tmp = Error.prototype.toString.call(obj);
ok(tmp === "6: false", "Error.prototype.toString.call(obj) = " + tmp);
obj = new Object();
obj.message = "test";
tmp = Error.prototype.toString.call(obj);
ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
obj = new Object();
obj.name = "";
obj.message = "test";
tmp = Error.prototype.toString.call(obj);
ok(tmp === "test", "Error.prototype.toString.call(obj) = " + tmp);
}
tmp = Error.prototype.toString.call(testObj);
ok(tmp === "[object Error]", "Error.prototype.toString.call(testObj) = " + tmp);
err = new Error();
err.name = null;
ok(err.name === null, "err.name = " + err.name + " expected null");
if(invokeVersion >= 2)
ok(err.toString() === "null", "err.toString() = " + err.toString());
err = new Error();
err.message = false;
ok(err.message === false, "err.message = " + err.message + " expected false");
if(invokeVersion >= 2)
ok(err.toString() === "Error: false", "err.toString() = " + err.toString());
err = new Error();
err.message = new Object();
err.message.toString = function() { return ""; };
if(invokeVersion >= 2)
ok(err.toString() === "Error", "err.toString() = " + err.toString());
err = new Error();
err.message = undefined;
if(invokeVersion >= 2)
ok(err.toString() === "Error", "err.toString() = " + err.toString());
var exception_array = {
E_INVALID_LENGTH: { type: "RangeError", number: -2146823259 },
E_NOT_DATE: { type: "TypeError", number: -2146823282 },
E_NOT_BOOL: { type: "TypeError", number: -2146823278 },
E_ARG_NOT_OPT: { type: "TypeError", number: -2146827839 },
E_NO_PROPERTY: { type: "TypeError", number: -2146827850 },
E_NOT_NUM: { type: "TypeError", number: -2146823287 },
E_INVALID_CALL_ARG: { type: "TypeError", number: -2146828283 },
E_NOT_FUNC: { type: "TypeError", number: -2146823286 },
E_OBJECT_EXPECTED: { type: "TypeError", number: -2146823281 },
E_OBJECT_REQUIRED: { type: "TypeError", number: -2146827864 },
E_UNSUPPORTED_ACTION: { type: "TypeError", number: -2146827843 },
E_REGEXP_EXPECTED: { type: "TypeError", number: -2146823272 },
E_NOT_ENUMERATOR: { type: "TypeError", number: -2146823273 },
E_NOT_VBARRAY: { type: "TypeError", number: -2146823275 },
E_INVALID_DELETE: { type: "TypeError", number: -2146823276 },
E_UNDEFINED: { type: "TypeError", number: -2146823279 },
E_JSCRIPT_EXPECTED: { type: "TypeError", number: -2146823274 },
E_NOT_ARRAY: { type: "TypeError", number: -2146823257 },
E_SYNTAX_ERROR: { type: "SyntaxError", number: -2146827286 },
E_LBRACKET: { type: "SyntaxError", number: -2146827283 },
E_RBRACKET: { type: "SyntaxError", number: -2146827282 },
E_SEMICOLON: { type: "SyntaxError", number: -2146827284 },
E_UNTERMINATED_STR: { type: "SyntaxError", number: -2146827273 },
E_DISABLED_CC: { type: "SyntaxError", number: -2146827258 },
E_INVALID_BREAK: { type: "SyntaxError", number: -2146827269 },
E_INVALID_CONTINUE: { type: "SyntaxError", number: -2146827268 },
E_LABEL_NOT_FOUND: { type: "SyntaxError", number: -2146827262 },
E_LABEL_REDEFINED: { type: "SyntaxError", number: -2146827263 },
E_MISPLACED_RETURN: { type: "SyntaxError", number: -2146827270 },
E_ILLEGAL_ASSIGN: { type: "ReferenceError", number: -2146823280 },
E_PRECISION_OUT_OF_RANGE: {type: "RangeError", number: -2146823261 },
E_FRACTION_DIGITS_OUT_OF_RANGE: {type: "RangeError", number: -2146823262 },
E_SUBSCRIPT_OUT_OF_RANGE: {type: "RangeError", number: -2146828279 },
E_REGEXP_SYNTAX_ERROR: { type: "RegExpError", number: -2146823271 },
E_URI_INVALID_CHAR: { type: "URIError", number: -2146823264 },
E_URI_INVALID_CODING: { type: "URIError", number: -2146823263 },
E_STACK_OVERFLOW: { type: "Error", number: -2146828260 }
};
function testException(func, id) {
var ex = exception_array[id];
var ret = "", num = "";
try {
func();
} catch(e) {
ret = e.name;
num = e.number;
}
ok(ret === ex.type, "Exception test, ret = " + ret + ", expected " + ex.type +". Executed function: " + func.toString());
ok(num === ex.number, "Exception test, num = " + num + " (" + (num + 0x80000000).toString(16) + "), expected " + ex.number
+ ". Executed function: " + func.toString());
}
// RangeError tests
testException(function() {Array(-3);}, "E_INVALID_LENGTH");
testException(function() {createArray().lbound("aaa");}, "E_SUBSCRIPT_OUT_OF_RANGE");
testException(function() {createArray().lbound(3);}, "E_SUBSCRIPT_OUT_OF_RANGE");
testException(function() {createArray().getItem(3);}, "E_SUBSCRIPT_OUT_OF_RANGE");
// TypeError tests
testException(function() {date.setTime();}, "E_ARG_NOT_OPT");
testException(function() {date.setYear();}, "E_ARG_NOT_OPT");
testException(function() {arr.test();}, "E_NO_PROPERTY");
testException(function() {[1,2,3].sort(nullDisp);}, "E_JSCRIPT_EXPECTED");
testException(function() {var o = new Object(); o.length = 1; o[0] = "a"; Array.prototype.toLocaleString.call(o);}, "E_NOT_ARRAY");
testException(function() {Number.prototype.toString.call(arr);}, "E_NOT_NUM");
testException(function() {Number.prototype.toFixed.call(arr);}, "E_NOT_NUM");
testException(function() {Number.prototype.toLocaleString.call(arr);}, "E_NOT_NUM");
testException(function() {Number.prototype.toLocaleString.call(null);}, "E_NOT_NUM");
testException(function() {(new Number(3)).toString(1);}, "E_INVALID_CALL_ARG");
testException(function() {(new Number(3)).toFixed(21);}, "E_FRACTION_DIGITS_OUT_OF_RANGE");
testException(function() {(new Number(1)).toPrecision(0);}, "E_PRECISION_OUT_OF_RANGE");
testException(function() {not_existing_variable.something();}, "E_UNDEFINED");
testException(function() {date();}, "E_NOT_FUNC");
testException(function() {arr();}, "E_NOT_FUNC");
testException(function() {(new Object) instanceof (new Object);}, "E_NOT_FUNC");
testException(function() {eval("nonexistingfunc()")}, "E_OBJECT_EXPECTED");
testException(function() {(new Object()) instanceof 3;}, "E_NOT_FUNC");
testException(function() {(new Object()) instanceof null;}, "E_NOT_FUNC");
testException(function() {(new Object()) instanceof nullDisp;}, "E_NOT_FUNC");
testException(function() {nullDisp instanceof Object;}, "E_OBJECT_EXPECTED");
testException(function() {Function.prototype.apply.call(nullDisp, Object, []);}, "E_OBJECT_REQUIRED");
testException(function() {Function.prototype.call.call(nullDisp, Object);}, "E_OBJECT_REQUIRED");
testException(function() {"test" in 3;}, "E_OBJECT_EXPECTED");
testException(function() {"test" in null;}, "E_OBJECT_EXPECTED");
testException(function() {"test" in nullDisp;}, "E_OBJECT_EXPECTED");
testException(function() {new 3;}, "E_UNSUPPORTED_ACTION");
testException(function() {new null;}, "E_OBJECT_EXPECTED");
testException(function() {new nullDisp;}, "E_NO_PROPERTY");
testException(function() {new VBArray();}, "E_NOT_VBARRAY");
testException(function() {new VBArray(new VBArray(createArray()));}, "E_NOT_VBARRAY");
testException(function() {VBArray.prototype.lbound.call(new Object());}, "E_NOT_VBARRAY");
testException(function() {+nullDisp.prop;}, "E_OBJECT_REQUIRED");
testException(function() {+nullDisp["prop"];}, "E_OBJECT_REQUIRED");
testException(function() {delete (new Object());}, "E_INVALID_DELETE");
testException(function() {delete false;}, "E_INVALID_DELETE");
testException(function() {undefined.toString();}, "E_OBJECT_EXPECTED");
testException(function() {null.toString();}, "E_OBJECT_EXPECTED");
testException(function() {RegExp.prototype.toString.call(new Object());}, "E_REGEXP_EXPECTED");
testException(function() {/a/.lastIndex();}, "E_NOT_FUNC");
testException(function() {"a".length();}, "E_NOT_FUNC");
testException(function() { return arguments.callee(); }, "E_STACK_OVERFLOW");
obj = new Object();
obj.prop = 1;
tmp = false;
testException(function() {delete ((tmp = true) ? obj.prop : obj.prop);}, "E_INVALID_DELETE");
ok(tmp, "delete (..) expression not evaluated");
//FIXME: testException(function() {nonexistent++;}, "E_OBJECT_EXPECTED");
//FIXME: testException(function() {undefined.nonexistent++;}, "E_OBJECT_EXPECTED");
// SyntaxError tests
function testSyntaxError(code, id) {
var ex = exception_array[id];
var ret = "", num = "";
try {
eval(code);
} catch(e) {
ret = e.name;
num = e.number;
}
ok(ret === ex.type, "Syntax exception test, ret = " + ret + ", expected " + ex.type +". Executed code: " + code);
ok(num === ex.number, "Syntax exception test, num = " + num + ", expected " + ex.number + ". Executed code: " + code);
}
testSyntaxError("for(i=0;) {}", "E_SYNTAX_ERROR");
testSyntaxError("function {};", "E_LBRACKET");
testSyntaxError("if", "E_LBRACKET");
testSyntaxError("do i=0; while", "E_LBRACKET");
testSyntaxError("while", "E_LBRACKET");
testSyntaxError("for", "E_LBRACKET");
testSyntaxError("with", "E_LBRACKET");
testSyntaxError("switch", "E_LBRACKET");
testSyntaxError("if(false", "E_RBRACKET");
testSyntaxError("for(i=0; i<10; i++", "E_RBRACKET");
testSyntaxError("while(true", "E_RBRACKET");
testSyntaxError("for(i=0", "E_SEMICOLON");
testSyntaxError("for(i=0;i<10", "E_SEMICOLON");
testSyntaxError("while(", "E_SYNTAX_ERROR");
testSyntaxError("if(", "E_SYNTAX_ERROR");
testSyntaxError("'unterminated", "E_UNTERMINATED_STR");
testSyntaxError("*", "E_SYNTAX_ERROR");
testSyntaxError("@_jscript_version", "E_DISABLED_CC");
testSyntaxError("@a", "E_DISABLED_CC");
testSyntaxError("/* @cc_on @*/ @_jscript_version", "E_DISABLED_CC");
testSyntaxError("ok(false, 'unexpected execution'); break;", "E_INVALID_BREAK");
testSyntaxError("ok(false, 'unexpected execution'); continue;", "E_INVALID_CONTINUE");
testSyntaxError("ok(false, 'unexpected execution'); while(true) break unknown_label;", "E_LABEL_NOT_FOUND");
testSyntaxError("ok(false, 'unexpected execution'); some_label: continue some_label;", "E_INVALID_CONTINUE");
testSyntaxError("ok(false, 'unexpected execution'); while(true) continue some_label;", "E_LABEL_NOT_FOUND");
testSyntaxError("ok(false, 'unexpected execution'); some_label: { while(true) continue some_label; }", "E_INVALID_CONTINUE");
testSyntaxError("ok(false, 'unexpected execution'); some_label: { some_label: while(true); }", "E_LABEL_REDEFINED");
testSyntaxError("return;", "E_MISPLACED_RETURN");
testSyntaxError("001.5;", "E_SEMICOLON");
testSyntaxError("001.5", "E_SEMICOLON");
testSyntaxError("0a", "E_SEMICOLON");
testSyntaxError("01a", "E_SEMICOLON");
testSyntaxError("0x1r", "E_SEMICOLON");
testSyntaxError("1a", "E_SEMICOLON");
testSyntaxError("1_", "E_SEMICOLON");
// ReferenceError tests
testException(function() {test = function() {}}, "E_ILLEGAL_ASSIGN");
tmp = false;
testException(function() {test = (tmp = true);}, "E_ILLEGAL_ASSIGN");
ok(tmp, "expr value on invalid assign not evaluated");
tmp = false;
testException(function() {(tmp = true) = false;}, "E_ILLEGAL_ASSIGN");
ok(tmp, "expr assign not evaluated");
tmp = false;
testException(function() {true = (tmp = true);}, "E_ILLEGAL_ASSIGN");
ok(tmp, "expr value assign not evaluated");
tmp = "";
testException(function() {(tmp = tmp+"1") = (tmp = tmp+"2");}, "E_ILLEGAL_ASSIGN");
ok(tmp === "12", "assign evaluated in unexpected order");
tmp = false;
testException(function() { ((tmp = true) && false)++; }, "E_ILLEGAL_ASSIGN")
ok(tmp, "incremented expression not evaluated");
// RegExpError tests
testException(function() {RegExp(/a/, "g");}, "E_REGEXP_SYNTAX_ERROR");
// URIError tests
testException(function() {encodeURI('\udcaa');}, "E_URI_INVALID_CHAR");
testException(function() {encodeURIComponent('\udcaa');}, "E_URI_INVALID_CHAR");
testException(function() {decodeURI('%');}, "E_URI_INVALID_CODING");
testException(function() {decodeURI('%aaaa');}, "E_URI_INVALID_CODING");
function testThisExcept(func, e) {
testException(function() {func.call(new Object())}, e);
}
function testBoolThis(func) {
testThisExcept(Boolean.prototype[func], "E_NOT_BOOL");
}
testBoolThis("toString");
testBoolThis("valueOf");
function testDateThis(func) {
testThisExcept(Date.prototype[func], "E_NOT_DATE");
}
testDateThis("getDate");
testDateThis("getDay");
testDateThis("getFullYear");
testDateThis("getHours");
testDateThis("getMilliseconds");
testDateThis("getMinutes");
testDateThis("getMonth");
testDateThis("getSeconds");
testDateThis("getTime");
testDateThis("getTimezoneOffset");
testDateThis("getUTCDate");
testDateThis("getUTCDay");
testDateThis("getUTCFullYear");
testDateThis("getUTCHours");
testDateThis("getUTCMilliseconds");
testDateThis("getUTCMinutes");
testDateThis("getUTCMonth");
testDateThis("getUTCSeconds");
testDateThis("getYear");
testDateThis("setDate");
testDateThis("setFullYear");
testDateThis("setHours");
testDateThis("setMilliseconds");
testDateThis("setMinutes");
testDateThis("setMonth");
testDateThis("setSeconds");
testDateThis("setTime");
testDateThis("setUTCDate");
testDateThis("setUTCFullYear");
testDateThis("setUTCHours");
testDateThis("setUTCMilliseconds");
testDateThis("setUTCMinutes");
testDateThis("setUTCMonth");
testDateThis("setUTCSeconds");
testDateThis("setYear");
testDateThis("toDateString");
testDateThis("toLocaleDateString");
testDateThis("toLocaleString");
testDateThis("toLocaleTimeString");
testDateThis("toString");
testDateThis("toTimeString");
testDateThis("toUTCString");
testDateThis("valueOf");
function testArrayThis(func) {
testThisExcept(Array.prototype[func], "E_NOT_ARRAY");
}
testArrayThis("toString");
function testFunctionThis(func) {
testThisExcept(Function.prototype[func], "E_NOT_FUNC");
}
testFunctionThis("toString");
testFunctionThis("call");
testFunctionThis("apply");
function testArrayHostThis(func) {
testException(function() { Array.prototype[func].call(testObj); }, "E_JSCRIPT_EXPECTED");
}
testArrayHostThis("push");
testArrayHostThis("shift");
testArrayHostThis("slice");
testArrayHostThis("splice");
testArrayHostThis("unshift");
testArrayHostThis("reverse");
testArrayHostThis("join");
testArrayHostThis("pop");
testArrayHostThis("sort");
function testEnumeratorThis(func) {
testThisExcept(Enumerator.prototype[func], "E_NOT_ENUMERATOR");
}
testEnumeratorThis("atEnd");
testEnumeratorThis("item");
testEnumeratorThis("moveFirst");
testEnumeratorThis("moveNext");
function testObjectInherit(obj, constr, ts, tls, vo) {
ok(obj instanceof Object, "obj is not instance of Object");
ok(obj instanceof constr, "obj is not instance of its constructor");
ok(obj.hasOwnProperty === Object.prototype.hasOwnProperty,
"obj.hasOwnProperty !== Object.prototype.hasOwnProprty");
ok(obj.isPrototypeOf === Object.prototype.isPrototypeOf,
"obj.isPrototypeOf !== Object.prototype.isPrototypeOf");
ok(obj.propertyIsEnumerable === Object.prototype.propertyIsEnumerable,
"obj.propertyIsEnumerable !== Object.prototype.propertyIsEnumerable");
if(ts)
ok(obj.toString === Object.prototype.toString,
"obj.toString !== Object.prototype.toString");
else
ok(obj.toString != Object.prototype.toString,
"obj.toString == Object.prototype.toString");
if(tls)
ok(obj.toLocaleString === Object.prototype.toLocaleString,
"obj.toLocaleString !== Object.prototype.toLocaleString");
else
ok(obj.toLocaleString != Object.prototype.toLocaleString,
"obj.toLocaleString == Object.prototype.toLocaleString");
if(vo)
ok(obj.valueOf === Object.prototype.valueOf,
"obj.valueOf !== Object.prototype.valueOf");
else
ok(obj.valueOf != Object.prototype.valueOf,
"obj.valueOf == Object.prototype.valueOf");
ok(obj._test === "test", "obj.test = " + obj._test);
}
Object.prototype._test = "test";
testObjectInherit(new String("test"), String, false, true, false);
testObjectInherit(/test/g, RegExp, false, true, true);
testObjectInherit(new Number(1), Number, false, false, false);
testObjectInherit(new Date(), Date, false, false, false);
testObjectInherit(new Boolean(true), Boolean, false, true, false);
testObjectInherit(new Array(), Array, false, false, true);
testObjectInherit(new Error(), Error, false, true, true);
testObjectInherit(testObjectInherit, Function, false, true, true);
testObjectInherit(Math, Object, true, true, true);
(function() { testObjectInherit(arguments, Object, true, true, true); })();
function testFunctions(obj, arr) {
var l;
for(var i=0; i>> 0; /* make it unsigned like HRESULT */
ok(n === tests[i][1], tests[i][0] + " with null context exception code = " + n);
}
try {
tests[i][2](undefined);
ok(false, "expected exception calling " + tests[i][0] + " with undefined context");
}catch(ex) {
var n = ex.number >>> 0;
ok(n === tests[i][1], tests[i][0] + " with undefined context exception code = " + n);
}
}
var r = Error.prototype.toString.call(undefined);
ok(r === "[object Error]", "Error.toString with undefined context returned " + r);
r = String.prototype.slice.call(null, 1, 3);
ok(r === "ul", "String.slice with null context returned " + r);
r = String.prototype.slice.call(undefined, 2, 5);
ok(r === "def", "String.slice with undefined context returned " + r);
r = (function() { return this; }).call(null);
ok(r === test, "wrong 'this' of function with null context");
r = (function() { return this; }).call(undefined);
ok(r === test, "wrong 'this' of function with undefined context");
r = (function() { return this; }).call(42);
ok(r.valueOf() === 42, "'this' of function with 42 context = " + r);
})();
var tmp = createArray();
ok(getVT(tmp) == "VT_ARRAY|VT_VARIANT", "getVT(createArray()) = " + getVT(tmp));
ok(getVT(VBArray(tmp)) == "VT_ARRAY|VT_VARIANT", "getVT(VBArray(tmp)) = " + getVT(VBArray(tmp)));
VBArray(tmp);
new VBArray(tmp);
tmp = new VBArray(tmp);
tmp = new VBArray(VBArray(createArray()));
ok(tmp.dimensions() == 2, "tmp.dimensions() = " + tmp.dimensions());
ok(tmp.lbound() == 0, "tmp.lbound() = " + tmp.lbound());
ok(tmp.lbound(1) == 0, "tmp.lbound(1) = " + tmp.lbound(1));
ok(tmp.lbound(2, 1) == 2, "tmp.lbound(2, 1) = " + tmp.lbound(2, 1));
ok(tmp.ubound() == 4, "tmp.ubound() = " + tmp.ubound());
ok(tmp.ubound("2") == 3, "tmp.ubound(\"2\") = " + tmp.ubound("2"));
ok(tmp.getItem(1, 2) == 3, "tmp.getItem(1, 2) = " + tmp.getItem(1, 2));
ok(tmp.getItem(2, 3) == 33, "tmp.getItem(2, 3) = " + tmp.getItem(2, 3));
ok(tmp.getItem(3, 2) == 13, "tmp.getItem(3, 2) = " + tmp.getItem(3, 2));
ok(tmp.toArray() == "2,3,12,13,22,23,32,33,42,43", "tmp.toArray() = " + tmp.toArray());
ok(createArray().toArray() == "2,3,12,13,22,23,32,33,42,43",
"createArray.toArray()=" + createArray().toArray());
obj = new Enumerator();
ok(obj.atEnd(), "atEnd() = " + obj.atEnd());
obj.moveFirst();
ok(obj.atEnd(), "atEnd() = " + obj.atEnd());
reportSuccess();