Exemplo n.º 1
0
        public static ICollection <string> CanonicalizeLocaleList(EcmaValue locales)
        {
            if (locales == default)
            {
                return(new List <string>());
            }
            if (locales.Type == EcmaValueType.String)
            {
                string s = locales.ToString();
                if (!IsStructurallyValidLanguageTag(s))
                {
                    throw new EcmaRangeErrorException("Invalid language tag: {0}", s);
                }
                return(new List <string> {
                    CanonicalizeLanguageTag(s)
                });
            }
            HashSet <string> list = new HashSet <string>();
            RuntimeObject    obj  = locales.ToObject();

            if (obj is Locale locale)
            {
                return(new List <string> {
                    locale.LocaleString
                });
            }
            long len = obj[WellKnownProperty.Length].ToLength();

            for (long i = 0; i < len; i++)
            {
                if (obj.HasProperty(i))
                {
                    list.Add(CanonicalizeLanguageTag(obj[i]));
                }
            }
            return(list);
        }