1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/test262/intl402/ch09/9.2/9.2.1_4.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +// Copyright 2012 Mozilla Corporation. All rights reserved. 1.5 +// This code is governed by the BSD license found in the LICENSE file. 1.6 + 1.7 +/** 1.8 + * @description Tests that non-objects are converted to objects before canonicalization. 1.9 + * @author Norbert Lindenberg 1.10 + */ 1.11 + 1.12 +$INCLUDE("testIntl.js"); 1.13 + 1.14 +testWithIntlConstructors(function (Constructor) { 1.15 + // undefined is handled separately 1.16 + 1.17 + // null should result in a TypeError 1.18 + var error; 1.19 + try { 1.20 + var supportedForNull = Constructor.supportedLocalesOf(null); 1.21 + } catch (e) { 1.22 + error = e; 1.23 + } 1.24 + if (error === undefined) { 1.25 + $ERROR("Null as locale list was not rejected."); 1.26 + } else if (error.name !== "TypeError") { 1.27 + $ERROR("Null as locale list was rejected with wrong error " + error.name + "."); 1.28 + } 1.29 + 1.30 + // let's use an empty list for comparison 1.31 + var supportedForEmptyList = Constructor.supportedLocalesOf([]); 1.32 + // we don't compare the elements because length should be 0 - let's just verify that 1.33 + if (supportedForEmptyList.length !== 0) { 1.34 + $ERROR("Internal test error: Assumption about length being 0 is invalid."); 1.35 + } 1.36 + 1.37 + // most non-objects will be interpreted as empty lists because a missing length property is interpreted as 0 1.38 + var supportedForNumber = Constructor.supportedLocalesOf(5); 1.39 + if (supportedForNumber.length !== supportedForEmptyList.length) { 1.40 + $ERROR("Supported locales differ between numeric and empty list input."); 1.41 + } 1.42 + var supportedForBoolean = Constructor.supportedLocalesOf(true); 1.43 + if (supportedForBoolean.length !== supportedForEmptyList.length) { 1.44 + $ERROR("Supported locales differ between boolean and empty list input."); 1.45 + } 1.46 + 1.47 + return true; 1.48 +}); 1.49 +