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 non-objects are converted to objects before canonicalization. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: $INCLUDE("testIntl.js"); michael@0: michael@0: testWithIntlConstructors(function (Constructor) { michael@0: // undefined is handled separately michael@0: michael@0: // null should result in a TypeError michael@0: var error; michael@0: try { michael@0: var supportedForNull = Constructor.supportedLocalesOf(null); michael@0: } catch (e) { michael@0: error = e; michael@0: } michael@0: if (error === undefined) { michael@0: $ERROR("Null as locale list was not rejected."); michael@0: } else if (error.name !== "TypeError") { michael@0: $ERROR("Null as locale list was rejected with wrong error " + error.name + "."); michael@0: } michael@0: michael@0: // let's use an empty list for comparison michael@0: var supportedForEmptyList = Constructor.supportedLocalesOf([]); michael@0: // we don't compare the elements because length should be 0 - let's just verify that michael@0: if (supportedForEmptyList.length !== 0) { michael@0: $ERROR("Internal test error: Assumption about length being 0 is invalid."); michael@0: } michael@0: michael@0: // most non-objects will be interpreted as empty lists because a missing length property is interpreted as 0 michael@0: var supportedForNumber = Constructor.supportedLocalesOf(5); michael@0: if (supportedForNumber.length !== supportedForEmptyList.length) { michael@0: $ERROR("Supported locales differ between numeric and empty list input."); michael@0: } michael@0: var supportedForBoolean = Constructor.supportedLocalesOf(true); michael@0: if (supportedForBoolean.length !== supportedForEmptyList.length) { michael@0: $ERROR("Supported locales differ between boolean and empty list input."); michael@0: } michael@0: michael@0: return true; michael@0: }); michael@0: