diff options
Diffstat (limited to 'js/src/tests/js1_6')
53 files changed, 2919 insertions, 0 deletions
diff --git a/js/src/tests/js1_6/Array/browser.js b/js/src/tests/js1_6/Array/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_6/Array/browser.js diff --git a/js/src/tests/js1_6/Array/filter.js b/js/src/tests/js1_6/Array/filter.js new file mode 100644 index 000000000..6cb929014 --- /dev/null +++ b/js/src/tests/js1_6/Array/filter.js @@ -0,0 +1,53 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "364603"; +var summary = "The value placed in a filtered array for an element is the " + + " element's value before the callback is run, not after"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +var failed = false; + +function mutate(val, index, arr) +{ + arr[index] = "mutated"; + return true; +} + +function assertEqual(v1, v2, msg) +{ + if (v1 !== v2) + throw msg; +} + +try +{ + var a = [1, 2]; + var m = a.filter(mutate); + + assertEqual(a[0], "mutated", "Array a not mutated!"); + assertEqual(a[1], "mutated", "Array a not mutated!"); + + assertEqual(m[0], 1, "Filtered value is value before callback is run"); + assertEqual(m[1], 2, "Filtered value is value before callback is run"); +} +catch (e) +{ + failed = e; +} + + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/Array/generics.js b/js/src/tests/js1_6/Array/generics.js new file mode 100644 index 000000000..c72149114 --- /dev/null +++ b/js/src/tests/js1_6/Array/generics.js @@ -0,0 +1,331 @@ +var BUGNUMBER = 1263558; +var summary = "Self-host all Array generics."; + +print(BUGNUMBER + ": " + summary); + +var arr, arrLike, tmp, f; + +function reset() { + arr = [5, 7, 13]; + arrLike = { + length: 3, + 0: 5, + 1: 7, + 2: 13, + toString() { + return "arrLike"; + } + }; + tmp = []; +} +function toString() { + return "G"; +} + +// Array.join (test this first to use it in remaining tests). +reset(); +assertThrowsInstanceOf(() => Array.join(), TypeError); +assertEq(Array.join(arr), "5,7,13"); +assertEq(Array.join(arr, "-"), "5-7-13"); +assertEq(Array.join(arrLike), "5,7,13"); +assertEq(Array.join(arrLike, "-"), "5-7-13"); + +// Array.concat. +reset(); +assertThrowsInstanceOf(() => Array.concat(), TypeError); +assertEq(Array.join(Array.concat(arr), ","), "5,7,13"); +assertEq(Array.join(Array.concat(arr, 11), ","), "5,7,13,11"); +assertEq(Array.join(Array.concat(arr, 11, 17), ","), "5,7,13,11,17"); +assertEq(Array.join(Array.concat(arrLike), ","), "arrLike"); +assertEq(Array.join(Array.concat(arrLike, 11), ","), "arrLike,11"); +assertEq(Array.join(Array.concat(arrLike, 11, 17), ","), "arrLike,11,17"); + +// Array.lastIndexOf. +reset(); +assertThrowsInstanceOf(() => Array.lastIndexOf(), TypeError); +assertEq(Array.lastIndexOf(arr), -1); +assertEq(Array.lastIndexOf(arr, 1), -1); +assertEq(Array.lastIndexOf(arr, 5), 0); +assertEq(Array.lastIndexOf(arr, 7), 1); +assertEq(Array.lastIndexOf(arr, 13, 1), -1); +assertEq(Array.lastIndexOf(arrLike), -1); +assertEq(Array.lastIndexOf(arrLike, 1), -1); +assertEq(Array.lastIndexOf(arrLike, 5), 0); +assertEq(Array.lastIndexOf(arrLike, 7), 1); +assertEq(Array.lastIndexOf(arrLike, 13, 1), -1); + +// Array.indexOf. +reset(); +assertThrowsInstanceOf(() => Array.indexOf(), TypeError); +assertEq(Array.indexOf(arr), -1); +assertEq(Array.indexOf(arr, 1), -1); +assertEq(Array.indexOf(arr, 5), 0); +assertEq(Array.indexOf(arr, 7), 1); +assertEq(Array.indexOf(arr, 1, 5), -1); +assertEq(Array.indexOf(arrLike), -1); +assertEq(Array.indexOf(arrLike, 1), -1); +assertEq(Array.indexOf(arrLike, 5), 0); +assertEq(Array.indexOf(arrLike, 7), 1); +assertEq(Array.indexOf(arrLike, 1, 5), -1); + +// Array.forEach. +reset(); +assertThrowsInstanceOf(() => Array.forEach(), TypeError); +assertThrowsInstanceOf(() => Array.forEach(arr), TypeError); +assertThrowsInstanceOf(() => Array.forEach(arrLike), TypeError); +f = function(...args) { + tmp.push(this, ...args); +}; +tmp = []; +Array.forEach(arr, f); +assertEq(tmp.join(","), "G,5,0,5,7,13," + "G,7,1,5,7,13," + "G,13,2,5,7,13"); +tmp = []; +Array.forEach(arr, f, "T"); +assertEq(tmp.join(","), "T,5,0,5,7,13," + "T,7,1,5,7,13," + "T,13,2,5,7,13"); +tmp = []; +Array.forEach(arrLike, f); +assertEq(tmp.join(","), "G,5,0,arrLike," + "G,7,1,arrLike," + "G,13,2,arrLike"); +tmp = []; +Array.forEach(arrLike, f, "T"); +assertEq(tmp.join(","), "T,5,0,arrLike," + "T,7,1,arrLike," + "T,13,2,arrLike"); + +// Array.map. +reset(); +assertThrowsInstanceOf(() => Array.map(), TypeError); +assertThrowsInstanceOf(() => Array.map(arr), TypeError); +assertThrowsInstanceOf(() => Array.map(arrLike), TypeError); +f = function(...args) { + tmp.push(this, ...args); + return args[0] * 2; +} +tmp = []; +assertEq(Array.join(Array.map(arr, f), ","), "10,14,26"); +assertEq(tmp.join(","), "G,5,0,5,7,13," + "G,7,1,5,7,13," + "G,13,2,5,7,13"); +tmp = []; +assertEq(Array.join(Array.map(arr, f, "T"), ","), "10,14,26"); +assertEq(tmp.join(","), "T,5,0,5,7,13," + "T,7,1,5,7,13," + "T,13,2,5,7,13"); +tmp = []; +assertEq(Array.join(Array.map(arrLike, f), ","), "10,14,26"); +assertEq(tmp.join(","), "G,5,0,arrLike," + "G,7,1,arrLike," + "G,13,2,arrLike"); +tmp = []; +assertEq(Array.join(Array.map(arrLike, f, "T"), ","), "10,14,26"); +assertEq(tmp.join(","), "T,5,0,arrLike," + "T,7,1,arrLike," + "T,13,2,arrLike"); + +// Array.filter. +reset(); +assertThrowsInstanceOf(() => Array.filter(), TypeError); +assertThrowsInstanceOf(() => Array.filter(arr), TypeError); +assertThrowsInstanceOf(() => Array.filter(arrLike), TypeError); +f = function(...args) { + tmp.push(this, ...args); + return args[0] < 10; +} +tmp = []; +assertEq(Array.join(Array.filter(arr, f), ","), "5,7"); +assertEq(tmp.join(","), "G,5,0,5,7,13," + "G,7,1,5,7,13," + "G,13,2,5,7,13"); +tmp = []; +assertEq(Array.join(Array.filter(arr, f, "T"), ","), "5,7"); +assertEq(tmp.join(","), "T,5,0,5,7,13," + "T,7,1,5,7,13," + "T,13,2,5,7,13"); +tmp = []; +assertEq(Array.join(Array.filter(arrLike, f), ","), "5,7"); +assertEq(tmp.join(","), "G,5,0,arrLike," + "G,7,1,arrLike," + "G,13,2,arrLike"); +tmp = []; +assertEq(Array.join(Array.filter(arrLike, f, "T"), ","), "5,7"); +assertEq(tmp.join(","), "T,5,0,arrLike," + "T,7,1,arrLike," + "T,13,2,arrLike"); + +// Array.every. +reset(); +assertThrowsInstanceOf(() => Array.every(), TypeError); +assertThrowsInstanceOf(() => Array.every(arr), TypeError); +assertThrowsInstanceOf(() => Array.every(arrLike), TypeError); +f = function(...args) { + tmp.push(this, ...args); + return args[0] < 6; +} +tmp = []; +assertEq(Array.every(arr, f), false); +assertEq(tmp.join(","), "G,5,0,5,7,13," + "G,7,1,5,7,13"); +tmp = []; +assertEq(Array.every(arr, f, "T"), false); +assertEq(tmp.join(","), "T,5,0,5,7,13," + "T,7,1,5,7,13"); +tmp = []; +assertEq(Array.every(arrLike, f), false); +assertEq(tmp.join(","), "G,5,0,arrLike," + "G,7,1,arrLike"); +tmp = []; +assertEq(Array.every(arrLike, f, "T"), false); +assertEq(tmp.join(","), "T,5,0,arrLike," + "T,7,1,arrLike"); + +// Array.some. +reset(); +assertThrowsInstanceOf(() => Array.some(), TypeError); +assertThrowsInstanceOf(() => Array.some(arr), TypeError); +assertThrowsInstanceOf(() => Array.some(arrLike), TypeError); +f = function(...args) { + tmp.push(this, ...args); + return args[0] == 7; +} +tmp = []; +assertEq(Array.some(arr, f), true); +assertEq(tmp.join(","), "G,5,0,5,7,13," + "G,7,1,5,7,13"); +tmp = []; +assertEq(Array.some(arr, f, "T"), true); +assertEq(tmp.join(","), "T,5,0,5,7,13," + "T,7,1,5,7,13"); +tmp = []; +assertEq(Array.some(arrLike, f), true); +assertEq(tmp.join(","), "G,5,0,arrLike," + "G,7,1,arrLike"); +tmp = []; +assertEq(Array.some(arrLike, f, "T"), true); +assertEq(tmp.join(","), "T,5,0,arrLike," + "T,7,1,arrLike"); + +// Array.reduce. +reset(); +assertThrowsInstanceOf(() => Array.reduce(), TypeError); +assertThrowsInstanceOf(() => Array.reduce(arr), TypeError); +assertThrowsInstanceOf(() => Array.reduce(arrLike), TypeError); +f = function(...args) { + tmp.push(...args); + return args[0] + args[1]; +} +tmp = []; +assertEq(Array.reduce(arr, f), 25); +assertEq(tmp.join(","), "5,7,1,5,7,13," + "12,13,2,5,7,13"); +tmp = []; +assertEq(Array.reduce(arr, f, 17), 42); +assertEq(tmp.join(","), "17,5,0,5,7,13," + "22,7,1,5,7,13," + "29,13,2,5,7,13"); +tmp = []; +assertEq(Array.reduce(arrLike, f), 25); +assertEq(tmp.join(","), "5,7,1,arrLike," + "12,13,2,arrLike"); +tmp = []; +assertEq(Array.reduce(arrLike, f, 17), 42); +assertEq(tmp.join(","), "17,5,0,arrLike," + "22,7,1,arrLike," + "29,13,2,arrLike"); + +// Array.reduceRight. +reset(); +assertThrowsInstanceOf(() => Array.reduceRight(), TypeError); +assertThrowsInstanceOf(() => Array.reduceRight(arr), TypeError); +assertThrowsInstanceOf(() => Array.reduceRight(arrLike), TypeError); +f = function(...args) { + tmp.push(...args); + return args[0] + args[1]; +} +tmp = []; +assertEq(Array.reduceRight(arr, f), 25); +assertEq(tmp.join(","), "13,7,1,5,7,13," + "20,5,0,5,7,13"); +tmp = []; +assertEq(Array.reduceRight(arr, f, 17), 42); +assertEq(tmp.join(","), "17,13,2,5,7,13," + "30,7,1,5,7,13," + "37,5,0,5,7,13"); +tmp = []; +assertEq(Array.reduceRight(arrLike, f), 25); +assertEq(tmp.join(","), "13,7,1,arrLike," + "20,5,0,arrLike"); +tmp = []; +assertEq(Array.reduceRight(arrLike, f, 17), 42); +assertEq(tmp.join(","), "17,13,2,arrLike," + "30,7,1,arrLike," + "37,5,0,arrLike"); + +// Array.reverse. +reset(); +assertThrowsInstanceOf(() => Array.reverse(), TypeError); +assertEq(Array.join(Array.reverse(arr), ","), "13,7,5"); +assertEq(Array.join(arr, ","), "13,7,5"); +assertEq(Array.join(Array.reverse(arrLike), ","), "13,7,5"); +assertEq(Array.join(arrLike, ","), "13,7,5"); + +// Array.sort. +reset(); +assertThrowsInstanceOf(() => Array.sort(), TypeError); +f = function(x, y) { + return y - x; +} +assertEq(Array.join(Array.sort(arr), ","), "13,5,7"); +assertEq(Array.join(Array.sort(arr, f), ","), "13,7,5"); +assertEq(Array.join(Array.sort(arrLike), ","), "13,5,7"); +assertEq(Array.join(Array.sort(arrLike, f), ","), "13,7,5"); + +// Array.push. +reset(); +assertThrowsInstanceOf(() => Array.push(), TypeError); +assertEq(Array.push(arr), 3); +assertEq(Array.join(arr), "5,7,13"); +assertEq(Array.push(arr, 17), 4); +assertEq(Array.join(arr), "5,7,13,17"); +assertEq(Array.push(arr, 19, 21), 6); +assertEq(Array.join(arr), "5,7,13,17,19,21"); +assertEq(Array.push(arrLike), 3); +assertEq(Array.join(arrLike), "5,7,13"); +assertEq(Array.push(arrLike, 17), 4); +assertEq(Array.join(arrLike), "5,7,13,17"); +assertEq(Array.push(arrLike, 19, 21), 6); +assertEq(Array.join(arrLike), "5,7,13,17,19,21"); + +// Array.pop. +reset(); +assertThrowsInstanceOf(() => Array.pop(), TypeError); +assertEq(Array.pop(arr), 13); +assertEq(Array.join(arr), "5,7"); +assertEq(Array.pop(arr), 7); +assertEq(Array.join(arr), "5"); +assertEq(Array.pop(arrLike), 13); +assertEq(Array.join(arrLike), "5,7"); +assertEq(Array.pop(arrLike), 7); +assertEq(Array.join(arrLike), "5"); + +// Array.shift. +reset(); +assertThrowsInstanceOf(() => Array.shift(), TypeError); +assertEq(Array.shift(arr), 5); +assertEq(Array.join(arr), "7,13"); +assertEq(Array.shift(arr), 7); +assertEq(Array.join(arr), "13"); +assertEq(Array.shift(arrLike), 5); +assertEq(Array.join(arrLike), "7,13"); +assertEq(Array.shift(arrLike), 7); +assertEq(Array.join(arrLike), "13"); + +// Array.unshift. +reset(); +assertThrowsInstanceOf(() => Array.unshift(), TypeError); +assertEq(Array.unshift(arr), 3); +assertEq(Array.join(arr), "5,7,13"); +assertEq(Array.unshift(arr, 17), 4); +assertEq(Array.join(arr), "17,5,7,13"); +assertEq(Array.unshift(arr, 19, 21), 6); +assertEq(Array.join(arr), "19,21,17,5,7,13"); +assertEq(Array.unshift(arrLike), 3); +assertEq(Array.join(arrLike), "5,7,13"); +assertEq(Array.unshift(arrLike, 17), 4); +assertEq(Array.join(arrLike), "17,5,7,13"); +assertEq(Array.unshift(arrLike, 19, 21), 6); +assertEq(Array.join(arrLike), "19,21,17,5,7,13"); + +// Array.splice. +reset(); +assertThrowsInstanceOf(() => Array.splice(), TypeError); +assertEq(Array.join(Array.splice(arr)), ""); +assertEq(Array.join(arr), "5,7,13"); +assertEq(Array.join(Array.splice(arr, 1)), "7,13"); +assertEq(Array.join(arr), "5"); +reset(); +assertEq(Array.join(Array.splice(arr, 1, 1)), "7"); +assertEq(Array.join(arr), "5,13"); +reset(); +assertEq(Array.join(Array.splice(arrLike)), ""); +assertEq(Array.join(arrLike), "5,7,13"); +assertEq(Array.join(Array.splice(arrLike, 1)), "7,13"); +assertEq(Array.join(arrLike), "5"); +reset(); +assertEq(Array.join(Array.splice(arrLike, 1, 1)), "7"); +assertEq(Array.join(arrLike), "5,13"); + +// Array.slice. +reset(); +assertThrowsInstanceOf(() => Array.slice(), TypeError); +assertEq(Array.join(Array.slice(arr)), "5,7,13"); +assertEq(Array.join(Array.slice(arr, 1)), "7,13"); +assertEq(Array.join(Array.slice(arr, 1, 1)), ""); +assertEq(Array.join(Array.slice(arr, 1, 2)), "7"); +assertEq(Array.join(Array.slice(arrLike)), "5,7,13"); +assertEq(Array.join(Array.slice(arrLike, 1)), "7,13"); +assertEq(Array.join(Array.slice(arrLike, 1, 1)), ""); +assertEq(Array.join(Array.slice(arrLike, 1, 2)), "7"); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/js1_6/Array/regress-290592.js b/js/src/tests/js1_6/Array/regress-290592.js new file mode 100644 index 000000000..788459a4e --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-290592.js @@ -0,0 +1,661 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 290592; +var summary = 'Array extras: forEach, indexOf, filter, map'; +var actual = ''; +var expect = ''; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +// Utility functions + +function identity(v, index, array) +{ + reportCompare(v, array[index], 'identity: check callback argument consistency'); + return v; +} + +function mutate(v, index, array) +{ + reportCompare(v, array[index], 'mutate: check callback argument consistency'); + if (index == 0) + { + array[1] = 'mutated'; + delete array[2]; + array.push('not visited'); + } + return v; +} + +function mutateForEach(v, index, array) +{ + reportCompare(v, array[index], 'mutateForEach: check callback argument consistency'); + if (index == 0) + { + array[1] = 'mutated'; + delete array[2]; + array.push('not visited'); + } + actual += v + ','; +} + +function makeUpperCase(v, index, array) +{ + reportCompare(v, array[index], 'makeUpperCase: check callback argument consistency'); + try + { + return v.toUpperCase(); + } + catch(e) + { + } + return v; +} + + +function concat(v, index, array) +{ + reportCompare(v, array[index], 'concat: check callback argument consistency'); + actual += v + ','; +} + + +function isUpperCase(v, index, array) +{ + reportCompare(v, array[index], 'isUpperCase: check callback argument consistency'); + try + { + return v == v.toUpperCase(); + } + catch(e) + { + } + return false; +} + +function isString(v, index, array) +{ + reportCompare(v, array[index], 'isString: check callback argument consistency'); + return typeof v == 'string'; +} + + +// callback object. +function ArrayCallback(state) +{ + this.state = state; +} + +ArrayCallback.prototype.makeUpperCase = function (v, index, array) +{ + reportCompare(v, array[index], 'ArrayCallback.prototype.makeUpperCase: check callback argument consistency'); + try + { + return this.state ? v.toUpperCase() : v.toLowerCase(); + } + catch(e) + { + } + return v; +}; + +ArrayCallback.prototype.concat = function(v, index, array) +{ + reportCompare(v, array[index], 'ArrayCallback.prototype.concat: check callback argument consistency'); + actual += v + ','; +}; + +ArrayCallback.prototype.isUpperCase = function(v, index, array) +{ + reportCompare(v, array[index], 'ArrayCallback.prototype.isUpperCase: check callback argument consistency'); + try + { + return this.state ? true : (v == v.toUpperCase()); + } + catch(e) + { + } + return false; +}; + +ArrayCallback.prototype.isString = function(v, index, array) +{ + reportCompare(v, array[index], 'ArrayCallback.prototype.isString: check callback argument consistency'); + return this.state ? true : (typeof v == 'string'); +}; + +function dumpError(e) +{ + var s = e.name + ': ' + e.message + + ' File: ' + e.fileName + + ', Line: ' + e.lineNumber + + ', Stack: ' + e.stack; + return s; +} + +var obj; +var strings = ['hello', 'Array', 'WORLD']; +var mixed = [0, '0', 0]; +var sparsestrings = new Array(); +sparsestrings[2] = 'sparse'; + +if ('map' in Array.prototype) +{ +// see http://developer-test.mozilla.org/docs/Core_JavaScript_1.5_Reference:Objects:Array:map + + // test Array.map + + // map has 1 required argument + expect = 1; + actual = Array.prototype.map.length; + reportCompare(expect, actual, 'Array.prototype.map.length == 1'); + + // throw TypeError if no callback function specified + expect = 'TypeError'; + try + { + strings.map(); + actual = 'no error'; + } + catch(e) + { + actual = e.name; + } + reportCompare(expect, actual, 'Array.map(undefined) throws TypeError'); + + try + { + // identity map + expect = 'hello,Array,WORLD'; + actual = strings.map(identity).toString(); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.map: identity'); + + + try + { + expect = 'hello,mutated,'; + actual = strings.map(mutate).toString(); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.map: mutate'); + + strings = ['hello', 'Array', 'WORLD']; + + try + { + // general map + expect = 'HELLO,ARRAY,WORLD'; + actual = strings.map(makeUpperCase).toString(); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.map: uppercase'); + + try + { + // pass object method as map callback + expect = 'HELLO,ARRAY,WORLD'; + var obj = new ArrayCallback(true); + actual = strings.map(obj.makeUpperCase, obj).toString(); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.map: uppercase with object callback'); + + try + { + expect = 'hello,array,world'; + obj = new ArrayCallback(false); + actual = strings.map(obj.makeUpperCase, obj).toString(); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.map: lowercase with object callback'); + + try + { + // map on sparse arrays + expect = ',,SPARSE'; + actual = sparsestrings.map(makeUpperCase).toString(); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.map: uppercase on sparse array'); +} + +if ('forEach' in Array.prototype) +{ +// see http://developer-test.mozilla.org/docs/Core_JavaScript_1.5_Reference:Objects:Array:forEach + + // test Array.forEach + + // forEach has 1 required argument + expect = 1; + actual = Array.prototype.forEach.length; + reportCompare(expect, actual, 'Array.prototype.forEach.length == 1'); + + // throw TypeError if no callback function specified + expect = 'TypeError'; + try + { + strings.forEach(); + actual = 'no error'; + } + catch(e) + { + actual = e.name; + } + reportCompare(expect, actual, 'Array.forEach(undefined) throws TypeError'); + + try + { + // general forEach + expect = 'hello,Array,WORLD,'; + actual = ''; + strings.forEach(concat); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.forEach'); + + try + { + expect = 'hello,mutated,'; + actual = ''; + strings.forEach(mutateForEach); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.forEach: mutate'); + + strings = ['hello', 'Array', 'WORLD']; + + + + try + { + // pass object method as forEach callback + expect = 'hello,Array,WORLD,'; + actual = ''; + obj = new ArrayCallback(true); + strings.forEach(obj.concat, obj); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.forEach with object callback 1'); + + try + { + expect = 'hello,Array,WORLD,'; + actual = ''; + obj = new ArrayCallback(false); + strings.forEach(obj.concat, obj); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.forEach with object callback 2'); + + try + { + // test forEach on sparse arrays + // see https://bugzilla.mozilla.org/show_bug.cgi?id=311082 + expect = 'sparse,'; + actual = ''; + sparsestrings.forEach(concat); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.forEach on sparse array'); +} + +if ('filter' in Array.prototype) +{ +// see http://developer-test.mozilla.org/docs/Core_JavaScript_1.5_Reference:Objects:Array:filter + + // test Array.filter + + // filter has 1 required argument + expect = 1; + actual = Array.prototype.filter.length; + reportCompare(expect, actual, 'Array.prototype.filter.length == 1'); + + // throw TypeError if no callback function specified + expect = 'TypeError'; + try + { + strings.filter(); + actual = 'no error'; + } + catch(e) + { + actual = e.name; + } + reportCompare(expect, actual, 'Array.filter(undefined) throws TypeError'); + + try + { + // test general filter + expect = 'WORLD'; + actual = strings.filter(isUpperCase).toString(); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.filter'); + + try + { + expect = 'WORLD'; + obj = new ArrayCallback(false); + actual = strings.filter(obj.isUpperCase, obj).toString(); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.filter object callback 1'); + + try + { + expect = 'hello,Array,WORLD'; + obj = new ArrayCallback(true); + actual = strings.filter(obj.isUpperCase, obj).toString(); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'Array.filter object callback 2'); +} + +if ('every' in Array.prototype) +{ +// see http://developer-test.mozilla.org/docs/Core_JavaScript_1.5_Reference:Objects:Array:every + + // test Array.every + + // every has 1 required argument + + expect = 1; + actual = Array.prototype.every.length; + reportCompare(expect, actual, 'Array.prototype.every.length == 1'); + + // throw TypeError if no every callback function specified + expect = 'TypeError'; + try + { + strings.every(); + actual = 'no error'; + } + catch(e) + { + actual = e.name; + } + reportCompare(expect, actual, 'Array.every(undefined) throws TypeError'); + + // test general every + + try + { + expect = true; + actual = strings.every(isString); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'strings: every element is a string'); + + try + { + expect = false; + actual = mixed.every(isString); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'mixed: every element is a string'); + + try + { + // see https://bugzilla.mozilla.org/show_bug.cgi?id=311082 + expect = true; + actual = sparsestrings.every(isString); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'sparsestrings: every element is a string'); + + // pass object method as map callback + + obj = new ArrayCallback(false); + + try + { + expect = true; + actual = strings.every(obj.isString, obj); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'strings: every element is a string, via object callback'); + + try + { + expect = false; + actual = mixed.every(obj.isString, obj); + } + catch(e) + { + actual = dumpError(e) ; + } + reportCompare(expect, actual, 'mixed: every element is a string, via object callback'); + + try + { + // see https://bugzilla.mozilla.org/show_bug.cgi?id=311082 + expect = true; + actual = sparsestrings.every(obj.isString, obj); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'sparsestrings: every element is a string, via object callback'); + +} + +if ('some' in Array.prototype) +{ +// see http://developer-test.mozilla.org/docs/Core_JavaScript_1.5_Reference:Objects:Array:some + + // test Array.some + + // some has 1 required argument + + expect = 1; + actual = Array.prototype.some.length; + reportCompare(expect, actual, 'Array.prototype.some.length == 1'); + + // throw TypeError if no some callback function specified + expect = 'TypeError'; + try + { + strings.some(); + actual = 'no error'; + } + catch(e) + { + actual = e.name; + } + reportCompare(expect, actual, 'Array.some(undefined) throws TypeError'); + + // test general some + + try + { + expect = true; + actual = strings.some(isString); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'strings: some element is a string'); + + try + { + expect = true; + actual = mixed.some(isString); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'mixed: some element is a string'); + + try + { + expect = true; + actual = sparsestrings.some(isString); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'sparsestrings: some element is a string'); + + // pass object method as map callback + + obj = new ArrayCallback(false); + + try + { + expect = true; + actual = strings.some(obj.isString, obj); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'strings: some element is a string, via object callback'); + + try + { + expect = true; + actual = mixed.some(obj.isString, obj); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'mixed: some element is a string, via object callback'); + + try + { + expect = true; + actual = sparsestrings.some(obj.isString, obj); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'sparsestrings: some element is a string, via object callback'); + +} + +if ('indexOf' in Array.prototype) +{ +// see http://developer-test.mozilla.org/docs/Core_JavaScript_1.5_Reference:Objects:Array:indexOf + + // test Array.indexOf + + // indexOf has 1 required argument + + expect = 1; + actual = Array.prototype.indexOf.length; + reportCompare(expect, actual, 'Array.prototype.indexOf.length == 1'); + + // test general indexOf + + try + { + expect = -1; + actual = mixed.indexOf('not found'); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'indexOf returns -1 if value not found'); + + try + { + expect = 0; + actual = mixed.indexOf(0); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'indexOf matches using strict equality'); + + try + { + expect = 1; + actual = mixed.indexOf('0'); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'indexOf matches using strict equality'); + + try + { + expect = 2; + actual = mixed.indexOf(0, 1); + } + catch(e) + { + actual = dumpError(e); + } + reportCompare(expect, actual, 'indexOf begins searching at fromIndex'); +} + diff --git a/js/src/tests/js1_6/Array/regress-304828.js b/js/src/tests/js1_6/Array/regress-304828.js new file mode 100644 index 000000000..0b15e21d2 --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-304828.js @@ -0,0 +1,256 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 304828; +var summary = 'Array Generic Methods'; +var actual = ''; +var expect = ''; +printBugNumber(BUGNUMBER); +printStatus (summary); + +var value; + +// use Array methods on a String +// join +value = '123'; +expect = '1,2,3'; +try +{ + actual = Array.prototype.join.call(value); +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': join'); + +// reverse +value = '123'; +expect = 'TypeError: 0 is read-only'; +try +{ + actual = Array.prototype.reverse.call(value) + ''; +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': reverse'); + +// sort +value = 'cba'; +expect = 'TypeError: 0 is read-only'; +try +{ + actual = Array.prototype.sort.call(value) + ''; +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': sort'); + +// push +value = 'abc'; +expect = 6; +try +{ + Array.prototype.push.call(value, 'd', 'e', 'f'); + throw new Error("didn't throw"); +} +catch(e) +{ + reportCompare(true, e instanceof TypeError, + "push on a string primitive should throw TypeError"); +} +reportCompare('abc', value, summary + ': push string primitive'); + +value = new String("abc"); +expect = 6; +try +{ + Array.prototype.push.call(value, 'd', 'e', 'f'); + throw new Error("didn't throw"); +} +catch(e) +{ + reportCompare(true, e instanceof TypeError, + "push on a String object should throw TypeError"); +} +reportCompare("d", value[3], summary + ': push String object index 3'); +reportCompare("e", value[4], summary + ': push String object index 4'); +reportCompare("f", value[5], summary + ': push String object index 5'); + +// pop +value = 'abc'; +expect = "TypeError: property 2 is non-configurable and can't be deleted"; +try +{ + actual = Array.prototype.pop.call(value); +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': pop'); +reportCompare('abc', value, summary + ': pop'); + +// unshift +value = 'def'; +expect = 'TypeError: 0 is read-only'; +try +{ + actual = Array.prototype.unshift.call(value, 'a', 'b', 'c'); +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': unshift'); +reportCompare('def', value, summary + ': unshift'); + +// shift +value = 'abc'; +expect = 'TypeError: 0 is read-only'; +try +{ + actual = Array.prototype.shift.call(value); +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': shift'); +reportCompare('abc', value, summary + ': shift'); + +// splice +value = 'abc'; +expect = 'TypeError: 1 is read-only'; +try +{ + actual = Array.prototype.splice.call(value, 1, 1) + ''; +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': splice'); + +// concat +value = 'abc'; +expect = 'abc,d,e,f'; +try +{ + actual = Array.prototype.concat.call(value, 'd', 'e', 'f') + ''; +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': concat'); + +// slice +value = 'abc'; +expect = 'b'; +try +{ + actual = Array.prototype.slice.call(value, 1, 2) + ''; +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': slice'); + +// indexOf +value = 'abc'; +expect = 1; +try +{ + actual = Array.prototype.indexOf.call(value, 'b'); +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': indexOf'); + +// lastIndexOf +value = 'abcabc'; +expect = 4; +try +{ + actual = Array.prototype.lastIndexOf.call(value, 'b'); +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': lastIndexOf'); + +// forEach +value = 'abc'; +expect = 'ABC'; +actual = ''; +try +{ + Array.prototype.forEach.call(value, + function (v, index, array) + {actual += array[index].toUpperCase();}); +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': forEach'); + +// map +value = 'abc'; +expect = 'A,B,C'; +try +{ + actual = Array.prototype.map.call(value, + function (v, index, array) + {return v.toUpperCase();}) + ''; +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': map'); + +// filter +value = '1234567890'; +expect = '2,4,6,8,0'; +try +{ + actual = Array.prototype.filter.call(value, + function (v, index, array) + {return array[index] % 2 == 0;}) + ''; +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': filter'); + +// every +value = '1234567890'; +expect = false; +try +{ + actual = Array.prototype.every.call(value, + function (v, index, array) + {return array[index] % 2 == 0;}); +} +catch(e) +{ + actual = e + ''; +} +reportCompare(expect, actual, summary + ': every'); + + + diff --git a/js/src/tests/js1_6/Array/regress-305002.js b/js/src/tests/js1_6/Array/regress-305002.js new file mode 100644 index 000000000..e59668e7f --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-305002.js @@ -0,0 +1,25 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 305002; +var summary = '[].every(f) == true'; +var actual = ''; +var expect = ''; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +var notcalled = true; + +function callback() +{ + notcalled = false; +} + +expect = true; +actual = [].every(callback) && notcalled; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/Array/regress-310425-01.js b/js/src/tests/js1_6/Array/regress-310425-01.js new file mode 100644 index 000000000..a60d6660a --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-310425-01.js @@ -0,0 +1,27 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 310425; +var summary = 'Array.indexOf/lastIndexOf edge cases'; +var actual = ''; +var expect = ''; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +expect = -1; +actual = [].lastIndexOf(undefined, -1); +reportCompare(expect, actual, summary); + +expect = -1; +actual = [].indexOf(undefined, -1); +reportCompare(expect, actual, summary); + +var x = []; +x[1 << 30] = 1; +expect = (1 << 30); +actual = x.lastIndexOf(1); +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/Array/regress-310425-02.js b/js/src/tests/js1_6/Array/regress-310425-02.js new file mode 100644 index 000000000..ff9e88ae4 --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-310425-02.js @@ -0,0 +1,17 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 310425; +var summary = 'Array.indexOf/lastIndexOf edge cases'; +var actual = ''; +var expect = ''; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +expect = -1; +actual = Array(1).indexOf(1); +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/Array/regress-320887.js b/js/src/tests/js1_6/Array/regress-320887.js new file mode 100644 index 000000000..baf6c3079 --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-320887.js @@ -0,0 +1,27 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + * Contributor: Blake Kaplan + */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 320887; +var summary = 'var x should not throw a ReferenceError'; +var actual = 'No error'; +var expect = 'No error'; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +try +{ + (function xxx() { ["var x"].map(eval); })() + } +catch(ex) +{ + actual = ex + ''; +} + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/Array/regress-352742-01.js b/js/src/tests/js1_6/Array/regress-352742-01.js new file mode 100644 index 000000000..a3088a5e6 --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-352742-01.js @@ -0,0 +1,39 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 352742; +var summary = 'Array filter on {valueOf: Function}'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + print('If the test harness fails, this test fails.'); + expect = 4; + z = {valueOf: Function}; + actual = 2; + try { + [11].filter(z); + } + catch(e) + { + actual = 3; + } + actual = 4; + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/Array/regress-352742-02.js b/js/src/tests/js1_6/Array/regress-352742-02.js new file mode 100644 index 000000000..96270c462 --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-352742-02.js @@ -0,0 +1,32 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 352742; +var summary = 'eval("return") in toString'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = 3; + var j = ({toString: function() { eval("return"); }}); + actual = 2; + try { "" + j; } catch(e){} + actual = 3; + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/Array/regress-386030.js b/js/src/tests/js1_6/Array/regress-386030.js new file mode 100644 index 000000000..85ff7fd0e --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-386030.js @@ -0,0 +1,67 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + * Contributor: Blake Kaplan + */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 386030; +var summary = 'Array.reduce should ignore holes'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + function add(a, b) { return a + b; } + function testreduce(v) { return v == 3 ? "PASS" : "FAIL"; } + + expect = 'PASS'; + + try { + a = new Array(2); + a[1] = 3; + actual = testreduce(a.reduce(add)); + } catch (e) { + actual = "FAIL, reduce"; + } + reportCompare(expect, actual, summary + ': 1'); + + try { + a = new Array(2); + a[0] = 3; + actual = testreduce(a.reduceRight(add)); + } catch (e) { + actual = "FAIL, reduceRight"; + } + reportCompare(expect, actual, summary + ': 2'); + + try { + a = new Array(2); + a.reduce(add); + actual = "FAIL, empty reduce"; + } catch (e) { + actual = "PASS"; + } + reportCompare(expect, actual, summary + ': 3'); + + try { + a = new Array(2); + print(a.reduceRight(add)); + actual = "FAIL, empty reduceRight"; + } catch (e) { + actual = "PASS"; + } + reportCompare(expect, actual, summary + ': 4'); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/Array/regress-415451.js b/js/src/tests/js1_6/Array/regress-415451.js new file mode 100644 index 000000000..b4674f5df --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-415451.js @@ -0,0 +1,24 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 415451; +var summary = 'indexOf/lastIndexOf behavior'; + +var expected = "3,0,3,3,3,-1,-1"; +results = []; +var a = [1,2,3,1]; +for (var i=-1; i < a.length+2; i++) + results.push(a.indexOf(1,i)); +var actual = String(results); +reportCompare(expected, actual, "indexOf"); + +results = []; +var expected = "3,0,0,0,3,3,3"; +for (var i=-1; i < a.length+2; i++) + results.push(a.lastIndexOf(1,i)); +var actual = String(results); +reportCompare(expected, actual, "lastIndexOf"); + diff --git a/js/src/tests/js1_6/Array/regress-415540.js b/js/src/tests/js1_6/Array/regress-415540.js new file mode 100644 index 000000000..0e2b9726a --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-415540.js @@ -0,0 +1,21 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 415540; +var summary = 'Array.push' +var actual = ''; +var expect = ''; + +var Constr = function() {}; +Constr.prototype = []; +var c = new Constr(); +c.push(5); +c.push(6); +var actual = Array.push(c,7); +reportCompare(3, actual, "result of Array.push is length"); +reportCompare(5, c[0], "contents of c[0]"); +reportCompare(6, c[1], "contents of c[1]"); +reportCompare(7, c[2], "contents of c[2]"); diff --git a/js/src/tests/js1_6/Array/regress-566651.js b/js/src/tests/js1_6/Array/regress-566651.js new file mode 100644 index 000000000..a05d0310a --- /dev/null +++ b/js/src/tests/js1_6/Array/regress-566651.js @@ -0,0 +1,20 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + * Contributor: Blake Kaplan + */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 566651; +var summary = 'setting array.length to null should not throw an uncatchable exception'; +var actual = 0; +var expect = 0; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +var a = []; +a.length = null; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/Array/shell.js b/js/src/tests/js1_6/Array/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_6/Array/shell.js diff --git a/js/src/tests/js1_6/README b/js/src/tests/js1_6/README new file mode 100644 index 000000000..7a3c7a022 --- /dev/null +++ b/js/src/tests/js1_6/README @@ -0,0 +1 @@ +JavaScript 1.6 diff --git a/js/src/tests/js1_6/Regress/browser.js b/js/src/tests/js1_6/Regress/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_6/Regress/browser.js diff --git a/js/src/tests/js1_6/Regress/regress-311157-01.js b/js/src/tests/js1_6/Regress/regress-311157-01.js new file mode 100644 index 000000000..8c0e07405 --- /dev/null +++ b/js/src/tests/js1_6/Regress/regress-311157-01.js @@ -0,0 +1,24 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +var BUGNUMBER = 311157; +var summary = 'Comment-hiding compromise left E4X parsing/scanning inconsistent'; +var actual = 'No Crash'; +var expect = 'No Crash'; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +try +{ + eval('var x = <hi> <!-- duh -->\n there </hi>'); +} +catch(e) +{ +} + +reportCompare(expect, actual, summary); + diff --git a/js/src/tests/js1_6/Regress/regress-311157-02.js b/js/src/tests/js1_6/Regress/regress-311157-02.js new file mode 100644 index 000000000..e84f03159 --- /dev/null +++ b/js/src/tests/js1_6/Regress/regress-311157-02.js @@ -0,0 +1,24 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +var BUGNUMBER = 311157; +var summary = 'Comment-hiding compromise left E4X parsing/scanning inconsistent'; +var actual = 'No Crash'; +var expect = 'No Crash'; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +try +{ + eval('var x = <hi> <![CDATA[ duh ]]>\n there </hi>'); +} +catch(e) +{ +} + +reportCompare(expect, actual, summary); + diff --git a/js/src/tests/js1_6/Regress/regress-320172.js b/js/src/tests/js1_6/Regress/regress-320172.js new file mode 100644 index 000000000..462eb5452 --- /dev/null +++ b/js/src/tests/js1_6/Regress/regress-320172.js @@ -0,0 +1,25 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 320172; +var summary = 'Regression from bug 285219'; +var actual = 'No Crash'; +var expect = 'No Crash'; + +enterFunc ('test'); +printBugNumber(BUGNUMBER); +printStatus (summary); + +try +{ + (function xxx(){ ["var x"].forEach(eval); })(); +} +catch(ex) +{ +} + +printStatus('No Crash'); +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/Regress/regress-351795.js b/js/src/tests/js1_6/Regress/regress-351795.js new file mode 100644 index 000000000..24e946446 --- /dev/null +++ b/js/src/tests/js1_6/Regress/regress-351795.js @@ -0,0 +1,35 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 351795; +var summary = 'Do not assert: top < ss->printer->script->depth'; +var actual = 'No Crash'; +var expect = 'No Crash'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + try + { + p={}; + (p.z = [1].some(function(y) { return y > 0; }) ? 4 : [6])(5); + } + catch(ex) + { + } + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/Regress/regress-352271.js b/js/src/tests/js1_6/Regress/regress-352271.js new file mode 100644 index 000000000..97ff2647a --- /dev/null +++ b/js/src/tests/js1_6/Regress/regress-352271.js @@ -0,0 +1,34 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 352271; +var summary = 'Do not crash with |getter| |for each|'; +var actual = 'No Crash'; +var expect = 'No Crash'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + try + { + eval('[window.x getter= t for each ([*].a(v) in [])]'); + } + catch(ex) + { + } + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/Regress/regress-353078.js b/js/src/tests/js1_6/Regress/regress-353078.js new file mode 100644 index 000000000..4bbd9fdb3 --- /dev/null +++ b/js/src/tests/js1_6/Regress/regress-353078.js @@ -0,0 +1,32 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 353078; +var summary = 'Do not assert with bogus toString, map, split'; +var actual = 'No Crash'; +var expect = 'No Crash'; + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + try + { + this.toString = function() { return {}; }; p = [11].map('foo'.split); + } + catch(ex) + { + } + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/Regress/regress-355002.js b/js/src/tests/js1_6/Regress/regress-355002.js new file mode 100644 index 000000000..20fc60fdb --- /dev/null +++ b/js/src/tests/js1_6/Regress/regress-355002.js @@ -0,0 +1,37 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 355002; +var summary = 'Do not assert on |for each (this in []) { }|'; +var actual = 'No Crash'; +var expect = 'No Crash'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = 'SyntaxError: invalid for-in/of left-hand side'; + actual = ''; + try + { + eval('for each (this in []) { }'); + } + catch(ex) + { + actual = ex + ''; + } + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/Regress/regress-372565.js b/js/src/tests/js1_6/Regress/regress-372565.js new file mode 100644 index 000000000..e5c0e1b07 --- /dev/null +++ b/js/src/tests/js1_6/Regress/regress-372565.js @@ -0,0 +1,28 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 372565; +var summary = 'Do not assert: top < ss->printer->script->depth" decompiling a function where a const identifier is used as a for-loop variable'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + (function() { for each(x in y) { } const x = undefined; }); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/Regress/regress-475469.js b/js/src/tests/js1_6/Regress/regress-475469.js new file mode 100644 index 000000000..14566fd38 --- /dev/null +++ b/js/src/tests/js1_6/Regress/regress-475469.js @@ -0,0 +1,33 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 475469; +var summary = 'TM: Do not crash @ FramePCOffset'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + +// print('Note this test originally required jit enabled with the environment '); +// print('variable TRACEMONKEY=verbose defined. Note that the calls to enable '); +// print('jit are necessary for the crash.'); + + [1,2,3].map(function(v, i, t) { return /a/gi.exec(v); }); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} + diff --git a/js/src/tests/js1_6/Regress/regress-476655.js b/js/src/tests/js1_6/Regress/regress-476655.js new file mode 100644 index 000000000..9077ba3a0 --- /dev/null +++ b/js/src/tests/js1_6/Regress/regress-476655.js @@ -0,0 +1,40 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 476655; +var summary = 'TM: Do not assert: count <= (size_t) (fp->regs->sp - StackBase(fp) - depth)'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + + try + { + eval( + "(function (){ for (var y in this) {} })();" + + "[''.watch(\"\", function(){}) for each (x in ['', '', eval, '', '']) if " + + "(x)].map(Function)" + ); + } + catch(ex) + { + } + + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/Regress/shell.js b/js/src/tests/js1_6/Regress/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_6/Regress/shell.js diff --git a/js/src/tests/js1_6/String/browser.js b/js/src/tests/js1_6/String/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_6/String/browser.js diff --git a/js/src/tests/js1_6/String/generics.js b/js/src/tests/js1_6/String/generics.js new file mode 100644 index 000000000..b2aa2c327 --- /dev/null +++ b/js/src/tests/js1_6/String/generics.js @@ -0,0 +1,228 @@ +var BUGNUMBER = 1263558; +var summary = "Self-host all String generics."; + +print(BUGNUMBER + ": " + summary); + +var result; +var str = "ABCde"; +var strObj = { + toString() { + return "ABCde"; + } +}; + +// String.substring. +assertThrowsInstanceOf(() => String.substring(), TypeError); +assertEq(String.substring(str), "ABCde"); +assertEq(String.substring(str, 1), "BCde"); +assertEq(String.substring(str, 1, 3), "BC"); +assertEq(String.substring(strObj), "ABCde"); +assertEq(String.substring(strObj, 1), "BCde"); +assertEq(String.substring(strObj, 1, 3), "BC"); + +// String.substr. +assertThrowsInstanceOf(() => String.substr(), TypeError); +assertEq(String.substr(str), "ABCde"); +assertEq(String.substr(str, 1), "BCde"); +assertEq(String.substr(str, 1, 3), "BCd"); +assertEq(String.substr(strObj), "ABCde"); +assertEq(String.substr(strObj, 1), "BCde"); +assertEq(String.substr(strObj, 1, 3), "BCd"); + +// String.slice. +assertThrowsInstanceOf(() => String.slice(), TypeError); +assertEq(String.slice(str), "ABCde"); +assertEq(String.slice(str, 1), "BCde"); +assertEq(String.slice(str, 1, 3), "BC"); +assertEq(String.slice(strObj), "ABCde"); +assertEq(String.slice(strObj, 1), "BCde"); +assertEq(String.slice(strObj, 1, 3), "BC"); + +// String.match. +assertThrowsInstanceOf(() => String.match(), TypeError); +result = String.match(str); +assertEq(result.index, 0); +assertEq(result.length, 1); +assertEq(result[0], ""); +result = String.match(str, /c/i); +assertEq(result.index, 2); +assertEq(result.length, 1); +assertEq(result[0], "C"); +result = String.match(strObj); +assertEq(result.index, 0); +assertEq(result.length, 1); +assertEq(result[0], ""); +result = String.match(strObj, /c/i); +assertEq(result.index, 2); +assertEq(result.length, 1); +assertEq(result[0], "C"); + +// String.replace. +assertThrowsInstanceOf(() => String.replace(), TypeError); +assertEq(String.replace(str), "ABCde"); +assertEq(String.replace(str, /c/i), "ABundefinedde"); +assertEq(String.replace(str, /c/i, "x"), "ABxde"); +assertEq(String.replace(strObj), "ABCde"); +assertEq(String.replace(strObj, /c/i), "ABundefinedde"); +assertEq(String.replace(strObj, /c/i, "x"), "ABxde"); + +// String.search. +assertThrowsInstanceOf(() => String.search(), TypeError); +assertEq(String.search(str), 0); +assertEq(String.search(str, /c/i), 2); +assertEq(String.search(strObj), 0); +assertEq(String.search(strObj, /c/i), 2); + +// String.split. +assertThrowsInstanceOf(() => String.split(), TypeError); +assertEq(String.split(str).join(","), "ABCde"); +assertEq(String.split(str, /[bd]/i).join(","), "A,C,e"); +assertEq(String.split(str, /[bd]/i, 2).join(","), "A,C"); +assertEq(String.split(strObj).join(","), "ABCde"); +assertEq(String.split(strObj, /[bd]/i).join(","), "A,C,e"); +assertEq(String.split(strObj, /[bd]/i, 2).join(","), "A,C"); + +// String.toLowerCase. +assertThrowsInstanceOf(() => String.toLowerCase(), TypeError); +assertEq(String.toLowerCase(str), "abcde"); +assertEq(String.toLowerCase(strObj), "abcde"); + +// String.toUpperCase. +assertThrowsInstanceOf(() => String.toUpperCase(), TypeError); +assertEq(String.toUpperCase(str), "ABCDE"); +assertEq(String.toUpperCase(strObj), "ABCDE"); + +// String.charAt. +assertThrowsInstanceOf(() => String.charAt(), TypeError); +assertEq(String.charAt(str), "A"); +assertEq(String.charAt(str, 2), "C"); +assertEq(String.charAt(strObj), "A"); +assertEq(String.charAt(strObj, 2), "C"); + +// String.charCodeAt. +assertThrowsInstanceOf(() => String.charCodeAt(), TypeError); +assertEq(String.charCodeAt(str), 65); +assertEq(String.charCodeAt(str, 2), 67); +assertEq(String.charCodeAt(strObj), 65); +assertEq(String.charCodeAt(strObj, 2), 67); + +// String.includes. +assertThrowsInstanceOf(() => String.includes(), TypeError); +assertEq(String.includes(str), false); +assertEq(String.includes(str, "C"), true); +assertEq(String.includes(str, "C", 2), true); +assertEq(String.includes(str, "C", 3), false); +assertEq(String.includes(strObj), false); +assertEq(String.includes(strObj, "C"), true); +assertEq(String.includes(strObj, "C", 2), true); +assertEq(String.includes(strObj, "C", 3), false); + +// String.indexOf. +assertThrowsInstanceOf(() => String.indexOf(), TypeError); +assertEq(String.indexOf(str), -1); +assertEq(String.indexOf(str, "C"), 2); +assertEq(String.indexOf(str, "C", 2), 2); +assertEq(String.indexOf(str, "C", 3), -1); +assertEq(String.indexOf(strObj), -1); +assertEq(String.indexOf(strObj, "C"), 2); +assertEq(String.indexOf(strObj, "C", 2), 2); +assertEq(String.indexOf(strObj, "C", 3), -1); + +// String.lastIndexOf. +assertThrowsInstanceOf(() => String.lastIndexOf(), TypeError); +assertEq(String.lastIndexOf(str), -1); +assertEq(String.lastIndexOf(str, "C"), 2); +assertEq(String.lastIndexOf(str, "C", 2), 2); +assertEq(String.lastIndexOf(str, "C", 1), -1); +assertEq(String.lastIndexOf(strObj), -1); +assertEq(String.lastIndexOf(strObj, "C"), 2); +assertEq(String.lastIndexOf(strObj, "C", 2), 2); +assertEq(String.lastIndexOf(strObj, "C", 1), -1); + +// String.startsWith. +assertThrowsInstanceOf(() => String.startsWith(), TypeError); +assertEq(String.startsWith(str), false); +assertEq(String.startsWith(str, "A"), true); +assertEq(String.startsWith(str, "B", 0), false); +assertEq(String.startsWith(str, "B", 1), true); +assertEq(String.startsWith(strObj), false); +assertEq(String.startsWith(strObj, "A"), true); +assertEq(String.startsWith(strObj, "B", 0), false); +assertEq(String.startsWith(strObj, "B", 1), true); + +// String.endsWith. +assertThrowsInstanceOf(() => String.endsWith(), TypeError); +assertEq(String.endsWith(str), false); +assertEq(String.endsWith(str, "e"), true); +assertEq(String.endsWith(str, "B", 0), false); +assertEq(String.endsWith(str, "B", 2), true); +assertEq(String.endsWith(strObj), false); +assertEq(String.endsWith(strObj, "e"), true); +assertEq(String.endsWith(strObj, "B", 0), false); +assertEq(String.endsWith(strObj, "B", 2), true); + +// String.trim. +var str2 = " ABCde "; +var strObj2 = { + toString() { + return " ABCde "; + } +}; +assertThrowsInstanceOf(() => String.trim(), TypeError); +assertEq(String.trim(str2), "ABCde"); +assertEq(String.trim(strObj2), "ABCde"); + +// String.trimLeft. +assertThrowsInstanceOf(() => String.trimLeft(), TypeError); +assertEq(String.trimLeft(str2), "ABCde "); +assertEq(String.trimLeft(strObj2), "ABCde "); + +// String.trimRight. +assertThrowsInstanceOf(() => String.trimRight(), TypeError); +assertEq(String.trimRight(str2), " ABCde"); +assertEq(String.trimRight(strObj2), " ABCde"); + +// String.toLocaleLowerCase. +assertThrowsInstanceOf(() => String.toLocaleLowerCase(), TypeError); +assertEq(String.toLocaleLowerCase(str), str.toLocaleLowerCase()); +assertEq(String.toLocaleLowerCase(strObj), str.toLocaleLowerCase()); + +// String.toLocaleUpperCase. +assertThrowsInstanceOf(() => String.toLocaleUpperCase(), TypeError); +assertEq(String.toLocaleUpperCase(str), str.toLocaleUpperCase()); +assertEq(String.toLocaleUpperCase(strObj), str.toLocaleUpperCase()); + +// String.localeCompare. +assertThrowsInstanceOf(() => String.localeCompare(), TypeError); +assertEq(String.localeCompare(str), str.localeCompare()); +assertEq(String.localeCompare(str, "abcde"), str.localeCompare("abcde")); +assertEq(String.localeCompare(strObj), str.localeCompare()); +assertEq(String.localeCompare(strObj, "abcde"), str.localeCompare("abcde")); + +// String.normalize. +if ("normalize" in String.prototype) { + var str3 = "\u3082\u3058\u3089 \u3082\u3057\u3099\u3089"; + var strObj3 = { + toString() { + return "\u3082\u3058\u3089 \u3082\u3057\u3099\u3089"; + } + }; + assertThrowsInstanceOf(() => String.normalize(), TypeError); + + assertEq(String.normalize(str3), "\u3082\u3058\u3089 \u3082\u3058\u3089"); + assertEq(String.normalize(str3, "NFD"), "\u3082\u3057\u3099\u3089 \u3082\u3057\u3099\u3089"); + assertEq(String.normalize(strObj3), "\u3082\u3058\u3089 \u3082\u3058\u3089"); + assertEq(String.normalize(strObj3, "NFD"), "\u3082\u3057\u3099\u3089 \u3082\u3057\u3099\u3089"); +} + +// String.concat. +assertThrowsInstanceOf(() => String.concat(), TypeError); +assertEq(String.concat(str), "ABCde"); +assertEq(String.concat(str, "f"), "ABCdef"); +assertEq(String.concat(str, "f", "g"), "ABCdefg"); +assertEq(String.concat(strObj), "ABCde"); +assertEq(String.concat(strObj, "f"), "ABCdef"); +assertEq(String.concat(strObj, "f", "g"), "ABCdefg"); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/js1_6/String/regress-306591.js b/js/src/tests/js1_6/String/regress-306591.js new file mode 100644 index 000000000..ca792b145 --- /dev/null +++ b/js/src/tests/js1_6/String/regress-306591.js @@ -0,0 +1,76 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 306591; +var summary = 'String static methods'; +var actual = ''; +var expect = ''; + +printBugNumber(BUGNUMBER); +printStatus (summary); +printStatus ('See https://bugzilla.mozilla.org/show_bug.cgi?id=304828'); + +expect = ['a', 'b', 'c'].toString(); +actual = String.split(new String('abc'), '').toString(); +reportCompare(expect, actual, summary + + " String.split(new String('abc'), '')"); + +expect = '2'; +actual = String.substring(new Number(123), 1, 2); +reportCompare(expect, actual, summary + + " String.substring(new Number(123), 1, 2)"); + +expect = 'TRUE'; +actual = String.toUpperCase(new Boolean(true)); +reportCompare(expect, actual, summary + + " String.toUpperCase(new Boolean(true))"); + +try +{ + String.indexOf(null, 'l'); + throw new Error("should have thrown a TypeError"); +} +catch (e) +{ + assertEq(e instanceof TypeError, true, + "String.indexOf(null [, ...]) didn't work correctly"); +} + +expect = 2; +actual = String.indexOf(String(null), 'l'); +reportCompare(expect, actual, summary + + " String.indexOf(String(null), 'l')"); + +expect = ['a', 'b', 'c'].toString(); +actual = String.split('abc', '').toString(); +reportCompare(expect, actual, summary + + " String.split('abc', '')"); + +expect = '2'; +actual = String.substring(123, 1, 2); +reportCompare(expect, actual, summary + + " String.substring(123, 1, 2)"); + +expect = 'TRUE'; +actual = String.toUpperCase(true); +reportCompare(expect, actual, summary + + " String.toUpperCase(true)"); + +try +{ + String.indexOf(undefined, 'd'); + throw new Error("should have thrown a TypeError"); +} +catch (e) +{ + assertEq(e instanceof TypeError, true, + "String.indexOf(undefined [, ...]) didn't work correctly"); +} + +expect = 2; +actual = String.indexOf(String(undefined), 'd'); +reportCompare(expect, actual, summary + + " String.indexOf(String(undefined), 'd')"); diff --git a/js/src/tests/js1_6/String/shell.js b/js/src/tests/js1_6/String/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_6/String/shell.js diff --git a/js/src/tests/js1_6/browser.js b/js/src/tests/js1_6/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_6/browser.js diff --git a/js/src/tests/js1_6/extensions/browser.js b/js/src/tests/js1_6/extensions/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_6/extensions/browser.js diff --git a/js/src/tests/js1_6/extensions/nested-for-each.js b/js/src/tests/js1_6/extensions/nested-for-each.js new file mode 100644 index 000000000..d311d30d2 --- /dev/null +++ b/js/src/tests/js1_6/extensions/nested-for-each.js @@ -0,0 +1,39 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +var summary = 'for-each-in should not affect for-in'; +var BUGNUMBER = 292020; +var actual = ''; +var expect = ''; + +printBugNumber(BUGNUMBER); + +// test here +function foreachbug() +{ + var arryOuter = ["outervalue0", "outervalue1"]; + var arryInner = ["innervalue1","innervalue2"]; + + for (var j in arryOuter) + { + var result = (j in arryOuter); + if (!result) + { + return ("enumerated property not in object: (" + + j + " in arryOuter) " + result); + return result; + } + + + for each (k in arryInner) + { + // this for-each-in should not affect the outer for-in + } + } + return ''; +} + +reportCompare('', foreachbug()); diff --git a/js/src/tests/js1_6/extensions/regress-312385-01.js b/js/src/tests/js1_6/extensions/regress-312385-01.js new file mode 100644 index 000000000..7aa5d0d46 --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-312385-01.js @@ -0,0 +1,129 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 312385; +var summary = 'Generic methods with null or undefined |this|'; +var actual = ''; +var expect = true; +var voids = [null, undefined]; + + +function noop() { } + +var generics = { +String: [{ substring: [] }, +{ toLowerCase: [] }, +{ toUpperCase: [] }, +{ charAt: [] }, +{ charCodeAt: [] }, +{ indexOf: [] }, +{ lastIndexOf: [] }, +{ toLocaleLowerCase: [] }, +{ toLocaleUpperCase: [] }, +{ localeCompare: [] }, +{ match: [/(?:)/] }, // match(regexp) +{ search: [] }, +{ replace: [] }, +{ split: [] }, +{ substr: [] }, +{ concat: [] }, +{ slice: [] }], + + Array: [{ join: [] }, +{ reverse: [] }, +{ sort: [] }, + // { push: [0] }, // push(item1, ...) + // { pop: [] }, + // { shift: [] }, +{ unshift: [] }, + // { splice: [0, 0, 1] }, // splice(start, deleteCount, item1, ...) +{ concat: [] }, +{ indexOf: [] }, +{ lastIndexOf: [] }, + // forEach is excluded since it does not return a value... + /* { forEach: [noop] }, // forEach(callback, thisObj) */ +{ map: [noop] }, // map(callback, thisObj) +{ filter: [noop] }, // filter(callback, thisObj) +{ some: [noop] }, // some(callback, thisObj) +{ every: [noop] } // every(callback, thisObj) + ] +}; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +var global = this; + +for (var c in generics) +{ + var methods = generics[c]; + for (var i = 0; i < methods.length; i++) + { + var method = methods[i]; + + for (var methodname in method) + { + for (var v = 0; v < voids.length; v++) + { + var Constructor = global[c] + + var argsLen = method[methodname].length; + assertEq(argsLen === 0 || argsLen === 1, true, "not all arities handled"); + + var generic = Constructor[methodname]; + var prototypy = Constructor.prototype[methodname]; + + assertEq(typeof generic, "function"); + assertEq(typeof prototypy, "function"); + + // GENERIC METHOD TESTING + + try + { + switch (method[methodname].length) + { + case 0: + generic(voids[v]); + break; + + case 1: + generic(voids[v], method[methodname][0]); + break; + } + throw new Error(c + "." + methodname + " must throw for null or " + + "undefined first argument"); + } + catch (e) + { + assertEq(e instanceof TypeError, true, + "Didn't get a TypeError for " + c + "." + methodname + + " called with null or undefined first argument"); + } + + + // PROTOTYPE METHOD TESTING + + try + { + prototypy.apply(voids[v], method[methodname][0]); + throw new Error(c + ".prototype." + methodname + " must throw " + + "for null or undefined this"); + } + catch (e) + { + assertEq(e instanceof TypeError, true, + c + ".prototype." + methodname + "didn't throw a " + + "TypeError when called with null or undefined this"); + } + } + } + } +} + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("Tests finished."); diff --git a/js/src/tests/js1_6/extensions/regress-385393-08.js b/js/src/tests/js1_6/extensions/regress-385393-08.js new file mode 100644 index 000000000..b00cafde9 --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-385393-08.js @@ -0,0 +1,25 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +//----------------------------------------------------------------------------- +var BUGNUMBER = 385393; +var summary = 'Regression test for bug 385393'; +var actual = 'No Crash'; +var expect = 'No Crash'; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +try +{ + this.__proto__ = []; + [1,2,3,4].map.call(); +} +catch(ex) +{ +} + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/extensions/regress-414098.js b/js/src/tests/js1_6/extensions/regress-414098.js new file mode 100644 index 000000000..aa2b6e9de --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-414098.js @@ -0,0 +1,34 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 414098; +var summary = 'Getter behavior on arrays'; +var actual = ''; +var expect = ''; + +var a=[1,2,3]; +var foo = 44; +a.__defineGetter__(1, function() { return foo + 10; }); +actual = String(a); +reportCompare("1,54,3", actual, "getter 1"); + +actual = String(a.reverse()); +reportCompare("3,54,1", actual, "reverse"); + +var s = ""; +a.forEach(function(e) { s += e + "|"; }); +actual = s; +reportCompare("3|54|1|", actual, "forEach"); + +actual = a.join(' - '); +reportCompare("3 - 54 - 1", actual, "join"); + +a[2]=3; +actual = a.pop(); +reportCompare(actual, 3, "pop"); + +actual = a.pop(); +reportCompare(actual, 54, "pop 2"); diff --git a/js/src/tests/js1_6/extensions/regress-455464-01.js b/js/src/tests/js1_6/extensions/regress-455464-01.js new file mode 100644 index 000000000..c9d3486e9 --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-455464-01.js @@ -0,0 +1,20 @@ +// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 455464; +var summary = 'Do not assert with JIT: !TRACE_RECORDER(cx) ^ (jumpTable == recordingJumpTable)'; +var actual = 'No Crash'; +var expect = 'No Crash'; + +printBugNumber(BUGNUMBER); +printStatus (summary); + + +a=b=c=d=0; this.__defineGetter__('g', gc); for each (y in this); + + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/extensions/regress-455464-02.js b/js/src/tests/js1_6/extensions/regress-455464-02.js new file mode 100644 index 000000000..6ca53a495 --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-455464-02.js @@ -0,0 +1,30 @@ +// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 455464; +var summary = 'Do not assert with JIT: !TRACE_RECORDER(cx) ^ (jumpTable == recordingJumpTable)'; +var actual = 'No Crash'; +var expect = 'No Crash'; + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + + a=b=c=d=0; this.__defineGetter__('g', gc); for each (y in this); + + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/extensions/regress-455464-03.js b/js/src/tests/js1_6/extensions/regress-455464-03.js new file mode 100644 index 000000000..9a29c4f3e --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-455464-03.js @@ -0,0 +1,32 @@ +// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 455464; +var summary = 'Do not assert with JIT: !TRACE_RECORDER(cx) ^ (jumpTable == recordingJumpTable)'; +var actual = 'No Crash'; +var expect = 'No Crash'; + +a=b=c=d=0; this.__defineGetter__('g', gc); for each (y in this); + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + + a=b=c=d=0; this.__defineGetter__('g', gc); for each (y in this); + + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/extensions/regress-455464-04.js b/js/src/tests/js1_6/extensions/regress-455464-04.js new file mode 100644 index 000000000..f7616d3b7 --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-455464-04.js @@ -0,0 +1,33 @@ +// |reftest| skip-if(Android) -- bug - nsIDOMWindow.crypto throws NS_ERROR_NOT_IMPLEMENTED on Android +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 455464; +var summary = 'Do not assert with JIT, gczeal 2: !TRACE_RECORDER(cx) ^ (jumpTable == recordingJumpTable)'; +var actual = 'No Crash'; +var expect = 'No Crash'; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +if (typeof gczeal == 'undefined') +{ + expect = actual = 'Test requires gczeal, skipped.'; +} +else +{ + // Enumerate the global once before we turn on gczeal, so we're not + // trying to do all the enumerate hook object creation with a gc on + // every object, because that makes tests time out. + for (z in this); + gczeal(2); + + a=b=c=d=0; this.__defineGetter__('g', gc); for each (y in this); + + gczeal(0); +} + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/extensions/regress-456826.js b/js/src/tests/js1_6/extensions/regress-456826.js new file mode 100644 index 000000000..a073e8c8d --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-456826.js @@ -0,0 +1,128 @@ +// |reftest| skip-if(!xulRuntime.shell||Android) slow -- bug 504632 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 456826; +var summary = 'Do not assert with JIT during OOM'; +var actual = 'No Crash'; +var expect = 'No Crash'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + + if (typeof gcparam != 'undefined') + { + gc(); + gc(); + gcparam("maxBytes", gcparam("gcBytes") + 4*1024); + expectExitCode(5); + } + + const numRows = 600; + const numCols = 600; + var scratch = {}; + var scratchZ = {}; + + function complexMult(a, b) { + var newr = a.r * b.r - a.i * b.i; + var newi = a.r * b.i + a.i * b.r; + scratch.r = newr; + scratch.i = newi; + return scratch; + } + + function complexAdd(a, b) { + scratch.r = a.r + b.r; + scratch.i = a.i + b.i; + return scratch; + } + + function abs(a) { + return Math.sqrt(a.r * a.r + a.i * a.i); + } + + function computeEscapeSpeed(c) { + scratchZ.r = scratchZ.i = 0; + const scaler = 5; + const threshold = (colors.length - 1) * scaler + 1; + for (var i = 1; i < threshold; ++i) { + scratchZ = complexAdd(c, complexMult(scratchZ, scratchZ)); + if (scratchZ.r * scratchZ.r + scratchZ.i * scratchZ.i > 4) { + return Math.floor((i - 1) / scaler) + 1; + } + } + return 0; + } + + const colorStrings = [ + "black", + "green", + "blue", + "red", + "purple", + "orange", + "cyan", + "yellow", + "magenta", + "brown", + "pink", + "chartreuse", + "darkorange", + "crimson", + "gray", + "deeppink", + "firebrick", + "lavender", + "lawngreen", + "lightsalmon", + "lime", + "goldenrod" + ]; + + var colors = []; + + function createMandelSet(realRange, imagRange) { + var start = new Date(); + + // Set up our colors + for each (var color in colorStrings) { + var [r, g, b] = [0, 0, 0]; + colors.push([r, g, b, 0xff]); + } + + var realStep = (realRange.max - realRange.min)/numCols; + var imagStep = (imagRange.min - imagRange.max)/numRows; + for (var i = 0, curReal = realRange.min; + i < numCols; + ++i, curReal += realStep) { + for (var j = 0, curImag = imagRange.max; + j < numRows; + ++j, curImag += imagStep) { + var c = { r: curReal, i: curImag } + var n = computeEscapeSpeed(c); + } + } + print(Date.now() - start); + } + + var realRange = { min: -2.1, max: 2 }; + var imagRange = { min: -2, max: 2 }; + createMandelSet(realRange, imagRange); + + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/extensions/regress-457521.js b/js/src/tests/js1_6/extensions/regress-457521.js new file mode 100644 index 000000000..6f4fbda50 --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-457521.js @@ -0,0 +1,24 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 457521; +var summary = 'Do not crash @ js_DecompileValueGenerator'; +var actual = ''; +var expect = ''; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +try +{ + this.__defineSetter__("x", [,,,].map); + this.watch("x", (new Function("var y, eval"))); + x = true; +} +catch(ex) +{ +} +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/extensions/regress-465443.js b/js/src/tests/js1_6/extensions/regress-465443.js new file mode 100644 index 000000000..529c59a54 --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-465443.js @@ -0,0 +1,39 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 465443; +var summary = ''; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = 'TypeError: invalid assignment to const `b\''; + + + try + { + eval('(function () { const b = 16; var out = []; for each (b in [true, "", true, "", true, ""]) out.push(b >> 1) })();'); + } + catch(ex) + { + actual = ex + ''; + } + + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/extensions/regress-470310.js b/js/src/tests/js1_6/extensions/regress-470310.js new file mode 100644 index 000000000..c144b54b1 --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-470310.js @@ -0,0 +1,33 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 470310; +var summary = 'Do not assert: (uint32_t)((atoms - script->atomMap.vector + ' + + '((uintN)(((regs.pc + 0)[1] << 8) | (regs.pc + 0)[2])))) < objects_->length'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = 'TypeError: 6 is not a function'; + + this.__defineSetter__('m', [].map); + function f() { for (var j = 0; j < 4; ++j) if (j == 3) m = 6; } + try { f(); } catch(e) { print(actual = e + ''); } + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_6/extensions/regress-472508.js b/js/src/tests/js1_6/extensions/regress-472508.js new file mode 100644 index 000000000..93b929add --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-472508.js @@ -0,0 +1,23 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 472508; +var summary = 'TM: Do not crash @ TraceRecorder::emitTreeCall'; +var actual = ''; +var expect = ''; + +printBugNumber(BUGNUMBER); +printStatus (summary); + + +for (var x in this) { } +var a = [false, false, false]; +a.__defineGetter__("q", function() { }); +a.__defineGetter__("r", function() { }); +for (var i = 0; i < 2; ++i) for each (var e in a) { } + + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/extensions/regress-479567.js b/js/src/tests/js1_6/extensions/regress-479567.js new file mode 100644 index 000000000..6f3525130 --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-479567.js @@ -0,0 +1,33 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 479567; +var summary = 'Do not assert: thing'; +var actual = ''; +var expect = ''; + +printBugNumber(BUGNUMBER); +printStatus (summary); + + +function f() +{ + (eval("(function(){for each (y in [false, false, false]);});"))(); +} + +try +{ + this.__defineGetter__("x", gc); + uneval(this.watch("y", this.toSource)) + f(); + throw x; +} +catch(ex) +{ +} + + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_6/extensions/regress-565521.js b/js/src/tests/js1_6/extensions/regress-565521.js new file mode 100644 index 000000000..9dd26a250 --- /dev/null +++ b/js/src/tests/js1_6/extensions/regress-565521.js @@ -0,0 +1,40 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + * Contributor: Blake Kaplan + */ + + +//----------------------------------------------------------------------------- +var BUGNUMBER = 565521; +var summary = 'for-each getter calling'; +var actual = ''; +var expect = 'PASS'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + var proto = { get prop() { return (this === proto) ? "FAIL" : "PASS"; } }; + var obj = Object.create(proto); + + var itercount = 0; + for each (var i in obj) { + ++itercount; + actual = i; + } + + reportCompare(itercount, 1, summary + ': right itercount') + reportCompare(expect, actual, summary + ': right value'); + + exitFunc ('test'); +} + diff --git a/js/src/tests/js1_6/extensions/shell.js b/js/src/tests/js1_6/extensions/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_6/extensions/shell.js diff --git a/js/src/tests/js1_6/shell.js b/js/src/tests/js1_6/shell.js new file mode 100644 index 000000000..b204e608f --- /dev/null +++ b/js/src/tests/js1_6/shell.js @@ -0,0 +1,12 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// NOTE: This only turns on 1.6 in shell builds. The browser requires the +// futzing in js/src/tests/browser.js. +if (typeof version != 'undefined') +{ + version(160); +} + diff --git a/js/src/tests/js1_6/template.js b/js/src/tests/js1_6/template.js new file mode 100644 index 000000000..089aae2d6 --- /dev/null +++ b/js/src/tests/js1_6/template.js @@ -0,0 +1,28 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + * Contributor: + */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 99999; +var summary = ''; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} |