Index: src/js/i18n.js |
diff --git a/src/js/i18n.js b/src/js/i18n.js |
index 47d5208edf92a6ed800ed394c880cc189a520a81..13e78dcd0859823a0338c7fda2ca37a84916d3dd 100644 |
--- a/src/js/i18n.js |
+++ b/src/js/i18n.js |
@@ -64,39 +64,146 @@ |
StringSubstring = from.StringSubstring; |
}); |
-// Utilities for definitions |
- |
-function OverrideFunction(object, name, f) { |
- %CheckIsBootstrapping(); |
- ObjectDefineProperty(object, name, { value: f, |
- writeable: true, |
- configurable: true, |
- enumerable: false }); |
- %FunctionSetName(f, name); |
- %FunctionRemovePrototype(f); |
- %SetNativeFlag(f); |
-} |
- |
-function InstallFunction(object, name, func) { |
- utils.InstallFunctions(object, DONT_ENUM, [name, func]); |
-} |
- |
- |
-function InstallConstructor(object, name, func) { |
- %CheckIsBootstrapping(); |
- utils.SetFunctionName(func, name); |
- %AddNamedProperty(object, name, func, DONT_ENUM); |
- %SetNativeFlag(func); |
- %ToFastProperties(object); |
+// ------------------------------------------------------------------- |
+ |
+var Intl = {}; |
+ |
+%AddNamedProperty(global, "Intl", Intl, DONT_ENUM); |
+ |
+/** |
+ * Caches available locales for each service. |
+ */ |
+var AVAILABLE_LOCALES = { |
+ 'collator': UNDEFINED, |
+ 'numberformat': UNDEFINED, |
+ 'dateformat': UNDEFINED, |
+ 'breakiterator': UNDEFINED |
+}; |
+ |
+/** |
+ * Caches default ICU locale. |
+ */ |
+var DEFAULT_ICU_LOCALE = UNDEFINED; |
+ |
+/** |
+ * Unicode extension regular expression. |
+ */ |
+var UNICODE_EXTENSION_RE = UNDEFINED; |
+ |
+function GetUnicodeExtensionRE() { |
+ if (IS_UNDEFINED(UNDEFINED)) { |
+ UNICODE_EXTENSION_RE = new GlobalRegExp('-u(-[a-z0-9]{2,8})+', 'g'); |
+ } |
+ return UNICODE_EXTENSION_RE; |
+} |
+ |
+/** |
+ * Matches any Unicode extension. |
+ */ |
+var ANY_EXTENSION_RE = UNDEFINED; |
+ |
+function GetAnyExtensionRE() { |
+ if (IS_UNDEFINED(ANY_EXTENSION_RE)) { |
+ ANY_EXTENSION_RE = new GlobalRegExp('-[a-z0-9]{1}-.*', 'g'); |
+ } |
+ return ANY_EXTENSION_RE; |
+} |
+ |
+/** |
+ * Replace quoted text (single quote, anything but the quote and quote again). |
+ */ |
+var QUOTED_STRING_RE = UNDEFINED; |
+ |
+function GetQuotedStringRE() { |
+ if (IS_UNDEFINED(QUOTED_STRING_RE)) { |
+ QUOTED_STRING_RE = new GlobalRegExp("'[^']+'", 'g'); |
+ } |
+ return QUOTED_STRING_RE; |
+} |
+ |
+/** |
+ * Matches valid service name. |
+ */ |
+var SERVICE_RE = UNDEFINED; |
+ |
+function GetServiceRE() { |
+ if (IS_UNDEFINED(SERVICE_RE)) { |
+ SERVICE_RE = |
+ new GlobalRegExp('^(collator|numberformat|dateformat|breakiterator)$'); |
+ } |
+ return SERVICE_RE; |
+} |
+ |
+/** |
+ * Validates a language tag against bcp47 spec. |
+ * Actual value is assigned on first run. |
+ */ |
+var LANGUAGE_TAG_RE = UNDEFINED; |
+ |
+function GetLanguageTagRE() { |
+ if (IS_UNDEFINED(LANGUAGE_TAG_RE)) { |
+ BuildLanguageTagREs(); |
+ } |
+ return LANGUAGE_TAG_RE; |
+} |
+ |
+/** |
+ * Helps find duplicate variants in the language tag. |
+ */ |
+var LANGUAGE_VARIANT_RE = UNDEFINED; |
+ |
+function GetLanguageVariantRE() { |
+ if (IS_UNDEFINED(LANGUAGE_VARIANT_RE)) { |
+ BuildLanguageTagREs(); |
+ } |
+ return LANGUAGE_VARIANT_RE; |
+} |
+ |
+/** |
+ * Helps find duplicate singletons in the language tag. |
+ */ |
+var LANGUAGE_SINGLETON_RE = UNDEFINED; |
+ |
+function GetLanguageSingletonRE() { |
+ if (IS_UNDEFINED(LANGUAGE_SINGLETON_RE)) { |
+ BuildLanguageTagREs(); |
+ } |
+ return LANGUAGE_SINGLETON_RE; |
+} |
+ |
+/** |
+ * Matches valid IANA time zone names. |
+ */ |
+var TIMEZONE_NAME_CHECK_RE = UNDEFINED; |
+ |
+function GetTimezoneNameCheckRE() { |
+ if (IS_UNDEFINED(TIMEZONE_NAME_CHECK_RE)) { |
+ TIMEZONE_NAME_CHECK_RE = new GlobalRegExp( |
+ '^([A-Za-z]+)/([A-Za-z_-]+)((?:\/[A-Za-z_-]+)+)*$'); |
+ } |
+ return TIMEZONE_NAME_CHECK_RE; |
+} |
+ |
+/** |
+ * Matches valid location parts of IANA time zone names. |
+ */ |
+var TIMEZONE_NAME_LOCATION_PART_RE = UNDEFINED; |
+ |
+function GetTimezoneNameLocationPartRE() { |
+ if (IS_UNDEFINED(TIMEZONE_NAME_LOCATION_PART_RE)) { |
+ TIMEZONE_NAME_LOCATION_PART_RE = |
+ new GlobalRegExp('^([A-Za-z]+)((?:[_-][A-Za-z]+)+)*$'); |
+ } |
+ return TIMEZONE_NAME_LOCATION_PART_RE; |
} |
/** |
* Adds bound method to the prototype of the given object. |
*/ |
-function AddBoundMethod(obj, methodName, implementation, length) { |
+function addBoundMethod(obj, methodName, implementation, length) { |
%CheckIsBootstrapping(); |
var internalName = %CreatePrivateSymbol(methodName); |
- var getter = function() { |
+ function getter() { |
if (!%IsInitializedIntlObject(this)) { |
throw MakeTypeError(kMethodCalledOnWrongObject, methodName); |
} |
@@ -127,142 +234,17 @@ |
this[internalName] = boundMethod; |
} |
return this[internalName]; |
- }; |
- |
- utils.InstallGetter(obj.prototype, methodName, getter, DONT_ENUM); |
-} |
- |
-// ------------------------------------------------------------------- |
- |
-var Intl = {}; |
- |
-%AddNamedProperty(global, "Intl", Intl, DONT_ENUM); |
- |
-/** |
- * Caches available locales for each service. |
- */ |
-var AVAILABLE_LOCALES = { |
- 'collator': UNDEFINED, |
- 'numberformat': UNDEFINED, |
- 'dateformat': UNDEFINED, |
- 'breakiterator': UNDEFINED |
-}; |
- |
-/** |
- * Caches default ICU locale. |
- */ |
-var DEFAULT_ICU_LOCALE = UNDEFINED; |
- |
-/** |
- * Unicode extension regular expression. |
- */ |
-var UNICODE_EXTENSION_RE = UNDEFINED; |
- |
-function GetUnicodeExtensionRE() { |
- if (IS_UNDEFINED(UNDEFINED)) { |
- UNICODE_EXTENSION_RE = new GlobalRegExp('-u(-[a-z0-9]{2,8})+', 'g'); |
- } |
- return UNICODE_EXTENSION_RE; |
-} |
- |
-/** |
- * Matches any Unicode extension. |
- */ |
-var ANY_EXTENSION_RE = UNDEFINED; |
- |
-function GetAnyExtensionRE() { |
- if (IS_UNDEFINED(ANY_EXTENSION_RE)) { |
- ANY_EXTENSION_RE = new GlobalRegExp('-[a-z0-9]{1}-.*', 'g'); |
- } |
- return ANY_EXTENSION_RE; |
-} |
- |
-/** |
- * Replace quoted text (single quote, anything but the quote and quote again). |
- */ |
-var QUOTED_STRING_RE = UNDEFINED; |
- |
-function GetQuotedStringRE() { |
- if (IS_UNDEFINED(QUOTED_STRING_RE)) { |
- QUOTED_STRING_RE = new GlobalRegExp("'[^']+'", 'g'); |
- } |
- return QUOTED_STRING_RE; |
-} |
- |
-/** |
- * Matches valid service name. |
- */ |
-var SERVICE_RE = UNDEFINED; |
- |
-function GetServiceRE() { |
- if (IS_UNDEFINED(SERVICE_RE)) { |
- SERVICE_RE = |
- new GlobalRegExp('^(collator|numberformat|dateformat|breakiterator)$'); |
- } |
- return SERVICE_RE; |
-} |
- |
-/** |
- * Validates a language tag against bcp47 spec. |
- * Actual value is assigned on first run. |
- */ |
-var LANGUAGE_TAG_RE = UNDEFINED; |
- |
-function GetLanguageTagRE() { |
- if (IS_UNDEFINED(LANGUAGE_TAG_RE)) { |
- BuildLanguageTagREs(); |
- } |
- return LANGUAGE_TAG_RE; |
-} |
- |
-/** |
- * Helps find duplicate variants in the language tag. |
- */ |
-var LANGUAGE_VARIANT_RE = UNDEFINED; |
- |
-function GetLanguageVariantRE() { |
- if (IS_UNDEFINED(LANGUAGE_VARIANT_RE)) { |
- BuildLanguageTagREs(); |
- } |
- return LANGUAGE_VARIANT_RE; |
-} |
- |
-/** |
- * Helps find duplicate singletons in the language tag. |
- */ |
-var LANGUAGE_SINGLETON_RE = UNDEFINED; |
- |
-function GetLanguageSingletonRE() { |
- if (IS_UNDEFINED(LANGUAGE_SINGLETON_RE)) { |
- BuildLanguageTagREs(); |
- } |
- return LANGUAGE_SINGLETON_RE; |
-} |
- |
-/** |
- * Matches valid IANA time zone names. |
- */ |
-var TIMEZONE_NAME_CHECK_RE = UNDEFINED; |
- |
-function GetTimezoneNameCheckRE() { |
- if (IS_UNDEFINED(TIMEZONE_NAME_CHECK_RE)) { |
- TIMEZONE_NAME_CHECK_RE = new GlobalRegExp( |
- '^([A-Za-z]+)/([A-Za-z_-]+)((?:\/[A-Za-z_-]+)+)*$'); |
- } |
- return TIMEZONE_NAME_CHECK_RE; |
-} |
- |
-/** |
- * Matches valid location parts of IANA time zone names. |
- */ |
-var TIMEZONE_NAME_LOCATION_PART_RE = UNDEFINED; |
- |
-function GetTimezoneNameLocationPartRE() { |
- if (IS_UNDEFINED(TIMEZONE_NAME_LOCATION_PART_RE)) { |
- TIMEZONE_NAME_LOCATION_PART_RE = |
- new GlobalRegExp('^([A-Za-z]+)((?:[_-][A-Za-z]+)+)*$'); |
- } |
- return TIMEZONE_NAME_LOCATION_PART_RE; |
+ } |
+ |
+ %FunctionSetName(getter, methodName); |
+ %FunctionRemovePrototype(getter); |
+ %SetNativeFlag(getter); |
+ |
+ ObjectDefineProperty(obj.prototype, methodName, { |
+ get: getter, |
+ enumerable: false, |
+ configurable: true |
+ }); |
} |
@@ -1008,7 +990,7 @@ |
* |
* @constructor |
*/ |
-InstallConstructor(Intl, 'Collator', function() { |
+%AddNamedProperty(Intl, 'Collator', function() { |
var locales = arguments[0]; |
var options = arguments[1]; |
@@ -1018,14 +1000,15 @@ |
} |
return initializeCollator(TO_OBJECT(this), locales, options); |
- } |
+ }, |
+ DONT_ENUM |
); |
/** |
* Collator resolvedOptions method. |
*/ |
-InstallFunction(Intl.Collator.prototype, 'resolvedOptions', function() { |
+%AddNamedProperty(Intl.Collator.prototype, 'resolvedOptions', function() { |
if (!IS_UNDEFINED(new.target)) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
@@ -1047,8 +1030,12 @@ |
caseFirst: coll[resolvedSymbol].caseFirst, |
collation: coll[resolvedSymbol].collation |
}; |
- } |
+ }, |
+ DONT_ENUM |
); |
+%FunctionSetName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions'); |
+%FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions); |
+%SetNativeFlag(Intl.Collator.prototype.resolvedOptions); |
/** |
@@ -1057,14 +1044,18 @@ |
* order in the returned list as in the input list. |
* Options are optional parameter. |
*/ |
-InstallFunction(Intl.Collator, 'supportedLocalesOf', function(locales) { |
+%AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) { |
if (!IS_UNDEFINED(new.target)) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
return supportedLocalesOf('collator', locales, arguments[1]); |
- } |
+ }, |
+ DONT_ENUM |
); |
+%FunctionSetName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); |
+%FunctionRemovePrototype(Intl.Collator.supportedLocalesOf); |
+%SetNativeFlag(Intl.Collator.supportedLocalesOf); |
/** |
@@ -1083,7 +1074,7 @@ |
}; |
-AddBoundMethod(Intl.Collator, 'compare', compare, 2); |
+addBoundMethod(Intl.Collator, 'compare', compare, 2); |
/** |
* Verifies that the input is a well-formed ISO 4217 currency code. |
@@ -1252,7 +1243,7 @@ |
* |
* @constructor |
*/ |
-InstallConstructor(Intl, 'NumberFormat', function() { |
+%AddNamedProperty(Intl, 'NumberFormat', function() { |
var locales = arguments[0]; |
var options = arguments[1]; |
@@ -1262,14 +1253,15 @@ |
} |
return initializeNumberFormat(TO_OBJECT(this), locales, options); |
- } |
+ }, |
+ DONT_ENUM |
); |
/** |
* NumberFormat resolvedOptions method. |
*/ |
-InstallFunction(Intl.NumberFormat.prototype, 'resolvedOptions', function() { |
+%AddNamedProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() { |
if (!IS_UNDEFINED(new.target)) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
@@ -1309,8 +1301,13 @@ |
} |
return result; |
- } |
+ }, |
+ DONT_ENUM |
); |
+%FunctionSetName(Intl.NumberFormat.prototype.resolvedOptions, |
+ 'resolvedOptions'); |
+%FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions); |
+%SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions); |
/** |
@@ -1319,14 +1316,18 @@ |
* order in the returned list as in the input list. |
* Options are optional parameter. |
*/ |
-InstallFunction(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { |
+%AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) { |
if (!IS_UNDEFINED(new.target)) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
return supportedLocalesOf('numberformat', locales, arguments[1]); |
- } |
+ }, |
+ DONT_ENUM |
); |
+%FunctionSetName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf'); |
+%FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); |
+%SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); |
/** |
@@ -1352,8 +1353,8 @@ |
} |
-AddBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1); |
-AddBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1); |
+addBoundMethod(Intl.NumberFormat, 'format', formatNumber, 1); |
+addBoundMethod(Intl.NumberFormat, 'v8Parse', parseNumber, 1); |
/** |
* Returns a string that matches LDML representation of the options object. |
@@ -1646,7 +1647,7 @@ |
* |
* @constructor |
*/ |
-InstallConstructor(Intl, 'DateTimeFormat', function() { |
+%AddNamedProperty(Intl, 'DateTimeFormat', function() { |
var locales = arguments[0]; |
var options = arguments[1]; |
@@ -1656,14 +1657,15 @@ |
} |
return initializeDateTimeFormat(TO_OBJECT(this), locales, options); |
- } |
+ }, |
+ DONT_ENUM |
); |
/** |
* DateTimeFormat resolvedOptions method. |
*/ |
-InstallFunction(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { |
+%AddNamedProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() { |
if (!IS_UNDEFINED(new.target)) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
@@ -1722,8 +1724,13 @@ |
addWECPropertyIfDefined(result, 'second', fromPattern.second); |
return result; |
- } |
+ }, |
+ DONT_ENUM |
); |
+%FunctionSetName(Intl.DateTimeFormat.prototype.resolvedOptions, |
+ 'resolvedOptions'); |
+%FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions); |
+%SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions); |
/** |
@@ -1732,14 +1739,18 @@ |
* order in the returned list as in the input list. |
* Options are optional parameter. |
*/ |
-InstallFunction(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { |
+%AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) { |
if (!IS_UNDEFINED(new.target)) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
return supportedLocalesOf('dateformat', locales, arguments[1]); |
- } |
+ }, |
+ DONT_ENUM |
); |
+%FunctionSetName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf'); |
+%FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); |
+%SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); |
/** |
@@ -1775,8 +1786,8 @@ |
// 0 because date is optional argument. |
-AddBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); |
-AddBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1); |
+addBoundMethod(Intl.DateTimeFormat, 'format', formatDate, 0); |
+addBoundMethod(Intl.DateTimeFormat, 'v8Parse', parseDate, 1); |
/** |
@@ -1863,7 +1874,7 @@ |
* |
* @constructor |
*/ |
-InstallConstructor(Intl, 'v8BreakIterator', function() { |
+%AddNamedProperty(Intl, 'v8BreakIterator', function() { |
var locales = arguments[0]; |
var options = arguments[1]; |
@@ -1873,14 +1884,15 @@ |
} |
return initializeBreakIterator(TO_OBJECT(this), locales, options); |
- } |
+ }, |
+ DONT_ENUM |
); |
/** |
* BreakIterator resolvedOptions method. |
*/ |
-InstallFunction(Intl.v8BreakIterator.prototype, 'resolvedOptions', |
+%AddNamedProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions', |
function() { |
if (!IS_UNDEFINED(new.target)) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
@@ -1899,8 +1911,13 @@ |
locale: locale, |
type: segmenter[resolvedSymbol].type |
}; |
- } |
+ }, |
+ DONT_ENUM |
); |
+%FunctionSetName(Intl.v8BreakIterator.prototype.resolvedOptions, |
+ 'resolvedOptions'); |
+%FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions); |
+%SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions); |
/** |
@@ -1909,15 +1926,19 @@ |
* order in the returned list as in the input list. |
* Options are optional parameter. |
*/ |
-InstallFunction(Intl.v8BreakIterator, 'supportedLocalesOf', |
+%AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf', |
function(locales) { |
if (!IS_UNDEFINED(new.target)) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
return supportedLocalesOf('breakiterator', locales, arguments[1]); |
- } |
+ }, |
+ DONT_ENUM |
); |
+%FunctionSetName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); |
+%FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); |
+%SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); |
/** |
@@ -1962,11 +1983,11 @@ |
} |
-AddBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1); |
-AddBoundMethod(Intl.v8BreakIterator, 'first', first, 0); |
-AddBoundMethod(Intl.v8BreakIterator, 'next', next, 0); |
-AddBoundMethod(Intl.v8BreakIterator, 'current', current, 0); |
-AddBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0); |
+addBoundMethod(Intl.v8BreakIterator, 'adoptText', adoptText, 1); |
+addBoundMethod(Intl.v8BreakIterator, 'first', first, 0); |
+addBoundMethod(Intl.v8BreakIterator, 'next', next, 0); |
+addBoundMethod(Intl.v8BreakIterator, 'current', current, 0); |
+addBoundMethod(Intl.v8BreakIterator, 'breakType', breakType, 0); |
// Save references to Intl objects and methods we use, for added security. |
var savedObjects = { |
@@ -2004,6 +2025,18 @@ |
return new savedObjects[service](locales, useOptions); |
} |
+ |
+function OverrideFunction(object, name, f) { |
+ %CheckIsBootstrapping(); |
+ ObjectDefineProperty(object, name, { value: f, |
+ writeable: true, |
+ configurable: true, |
+ enumerable: false }); |
+ %FunctionSetName(f, name); |
+ %FunctionRemovePrototype(f); |
+ %SetNativeFlag(f); |
+} |
+ |
/** |
* Compares this and that, and returns less than 0, 0 or greater than 0 value. |
* Overrides the built-in method. |