michael@0: // Copyright 2012 Mozilla Corporation. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * @description Tests that Date.prototype.toLocaleString & Co. handle "this time value" correctly. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: var functions = { michael@0: toLocaleString: Date.prototype.toLocaleString, michael@0: toLocaleDateString: Date.prototype.toLocaleDateString, michael@0: toLocaleTimeString: Date.prototype.toLocaleTimeString michael@0: }; michael@0: var invalidValues = [undefined, null, 5, "5", false, {valueOf: function () { return 5; }}]; michael@0: michael@0: Object.getOwnPropertyNames(functions).forEach(function (p) { michael@0: var f = functions[p]; michael@0: invalidValues.forEach(function (value) { michael@0: var error; michael@0: try { michael@0: var result = f.call(value); michael@0: } catch (e) { michael@0: error = e; michael@0: } michael@0: if (error === undefined) { michael@0: $ERROR("Date.prototype." + p + " did not reject this = " + value + "."); michael@0: } else if (error.name !== "TypeError") { michael@0: $ERROR("Date.prototype." + p + " rejected this = " + value + " with wrong error " + error.name + "."); michael@0: } michael@0: }); michael@0: }); michael@0: