Index: src/i18n.js |
diff --git a/src/i18n.js b/src/i18n.js |
index 94fe7d653e9dd78352b2ccf7f120c52c484c093c..ae01cc464343200775386ccd9ab91791ab98d997 100644 |
--- a/src/i18n.js |
+++ b/src/i18n.js |
@@ -22,10 +22,17 @@ |
var GlobalNumber = global.Number; |
var GlobalRegExp = global.RegExp; |
var GlobalString = global.String; |
- |
+var ObjectDefineProperties = utils.ObjectDefineProperties; |
+var ObjectDefineProperty = utils.ObjectDefineProperty; |
+var SetFunctionName = utils.SetFunctionName; |
+ |
+var IsFinite; |
+var IsNaN; |
var MathFloor; |
utils.Import(function(from) { |
+ IsFinite = from.IsFinite; |
+ IsNaN = from.IsNaN; |
MathFloor = from.MathFloor; |
}); |
@@ -153,6 +160,7 @@ |
* Adds bound method to the prototype of the given object. |
*/ |
function addBoundMethod(obj, methodName, implementation, length) { |
+ %CheckIsBootstrapping(); |
function getter() { |
if (!%IsInitializedIntlObject(this)) { |
throw MakeTypeError(kMethodCalledOnWrongObject, methodName); |
@@ -190,7 +198,7 @@ |
} |
} |
} |
- $setFunctionName(boundMethod, internalName); |
+ SetFunctionName(boundMethod, internalName); |
%FunctionRemovePrototype(boundMethod); |
%SetNativeFlag(boundMethod); |
this[internalName] = boundMethod; |
@@ -198,11 +206,11 @@ |
return this[internalName]; |
} |
- $setFunctionName(getter, methodName); |
+ SetFunctionName(getter, methodName); |
%FunctionRemovePrototype(getter); |
%SetNativeFlag(getter); |
- $objectDefineProperty(obj.prototype, methodName, { |
+ ObjectDefineProperty(obj.prototype, methodName, { |
get: getter, |
enumerable: false, |
configurable: true |
@@ -521,14 +529,14 @@ |
*/ |
function freezeArray(array) { |
array.forEach(function(element, index) { |
- $objectDefineProperty(array, index, {value: element, |
- configurable: false, |
- writable: false, |
- enumerable: true}); |
+ ObjectDefineProperty(array, index, {value: element, |
+ configurable: false, |
+ writable: false, |
+ enumerable: true}); |
}); |
- $objectDefineProperty(array, 'length', {value: array.length, |
- writable: false}); |
+ ObjectDefineProperty(array, 'length', {value: array.length, |
+ writable: false}); |
return array; |
} |
@@ -589,8 +597,8 @@ |
* Configurable is false by default. |
*/ |
function defineWEProperty(object, property, value) { |
- $objectDefineProperty(object, property, |
- {value: value, writable: true, enumerable: true}); |
+ ObjectDefineProperty(object, property, |
+ {value: value, writable: true, enumerable: true}); |
} |
@@ -609,10 +617,10 @@ |
* Defines a property and sets writable, enumerable and configurable to true. |
*/ |
function defineWECProperty(object, property, value) { |
- $objectDefineProperty(object, property, {value: value, |
- writable: true, |
- enumerable: true, |
- configurable: true}); |
+ ObjectDefineProperty(object, property, {value: value, |
+ writable: true, |
+ enumerable: true, |
+ configurable: true}); |
} |
@@ -873,7 +881,7 @@ |
// problems. If malicious user decides to redefine Object.prototype.locale |
// we can't just use plain x.locale = 'us' or in C++ Set("locale", "us"). |
// ObjectDefineProperties will either succeed defining or throw an error. |
- var resolved = $objectDefineProperties({}, { |
+ var resolved = ObjectDefineProperties({}, { |
caseFirst: {writable: true}, |
collation: {value: internalOptions.collation, writable: true}, |
ignorePunctuation: {writable: true}, |
@@ -891,7 +899,7 @@ |
// Writable, configurable and enumerable are set to false by default. |
%MarkAsInitializedIntlObjectOfType(collator, 'collator', internalCollator); |
- $objectDefineProperty(collator, 'resolved', {value: resolved}); |
+ ObjectDefineProperty(collator, 'resolved', {value: resolved}); |
return collator; |
} |
@@ -946,7 +954,7 @@ |
}, |
DONT_ENUM |
); |
-$setFunctionName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions'); |
+SetFunctionName(Intl.Collator.prototype.resolvedOptions, 'resolvedOptions'); |
%FunctionRemovePrototype(Intl.Collator.prototype.resolvedOptions); |
%SetNativeFlag(Intl.Collator.prototype.resolvedOptions); |
@@ -966,7 +974,7 @@ |
}, |
DONT_ENUM |
); |
-$setFunctionName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); |
+SetFunctionName(Intl.Collator.supportedLocalesOf, 'supportedLocalesOf'); |
%FunctionRemovePrototype(Intl.Collator.supportedLocalesOf); |
%SetNativeFlag(Intl.Collator.supportedLocalesOf); |
@@ -1009,7 +1017,7 @@ |
var value = options[property]; |
if (!IS_UNDEFINED(value)) { |
value = GlobalNumber(value); |
- if ($isNaN(value) || value < min || value > max) { |
+ if (IsNaN(value) || value < min || value > max) { |
throw MakeRangeError(kPropertyValueOutOfRange, property); |
} |
return MathFloor(value); |
@@ -1096,7 +1104,7 @@ |
getOption, internalOptions); |
var requestedLocale = locale.locale + extension; |
- var resolved = $objectDefineProperties({}, { |
+ var resolved = ObjectDefineProperties({}, { |
currency: {writable: true}, |
currencyDisplay: {writable: true}, |
locale: {writable: true}, |
@@ -1121,12 +1129,12 @@ |
// We can't get information about number or currency style from ICU, so we |
// assume user request was fulfilled. |
if (internalOptions.style === 'currency') { |
- $objectDefineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, |
- writable: true}); |
+ ObjectDefineProperty(resolved, 'currencyDisplay', {value: currencyDisplay, |
+ writable: true}); |
} |
%MarkAsInitializedIntlObjectOfType(numberFormat, 'numberformat', formatter); |
- $objectDefineProperty(numberFormat, 'resolved', {value: resolved}); |
+ ObjectDefineProperty(numberFormat, 'resolved', {value: resolved}); |
return numberFormat; |
} |
@@ -1199,8 +1207,7 @@ |
}, |
DONT_ENUM |
); |
-$setFunctionName(Intl.NumberFormat.prototype.resolvedOptions, |
- 'resolvedOptions'); |
+SetFunctionName(Intl.NumberFormat.prototype.resolvedOptions, 'resolvedOptions'); |
%FunctionRemovePrototype(Intl.NumberFormat.prototype.resolvedOptions); |
%SetNativeFlag(Intl.NumberFormat.prototype.resolvedOptions); |
@@ -1220,7 +1227,7 @@ |
}, |
DONT_ENUM |
); |
-$setFunctionName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf'); |
+SetFunctionName(Intl.NumberFormat.supportedLocalesOf, 'supportedLocalesOf'); |
%FunctionRemovePrototype(Intl.NumberFormat.supportedLocalesOf); |
%SetNativeFlag(Intl.NumberFormat.supportedLocalesOf); |
@@ -1416,33 +1423,33 @@ |
} |
if (needsDefault && (defaults === 'date' || defaults === 'all')) { |
- $objectDefineProperty(options, 'year', {value: 'numeric', |
+ ObjectDefineProperty(options, 'year', {value: 'numeric', |
+ writable: true, |
+ enumerable: true, |
+ configurable: true}); |
+ ObjectDefineProperty(options, 'month', {value: 'numeric', |
writable: true, |
enumerable: true, |
configurable: true}); |
- $objectDefineProperty(options, 'month', {value: 'numeric', |
+ ObjectDefineProperty(options, 'day', {value: 'numeric', |
+ writable: true, |
+ enumerable: true, |
+ configurable: true}); |
+ } |
+ |
+ if (needsDefault && (defaults === 'time' || defaults === 'all')) { |
+ ObjectDefineProperty(options, 'hour', {value: 'numeric', |
+ writable: true, |
+ enumerable: true, |
+ configurable: true}); |
+ ObjectDefineProperty(options, 'minute', {value: 'numeric', |
writable: true, |
enumerable: true, |
configurable: true}); |
- $objectDefineProperty(options, 'day', {value: 'numeric', |
- writable: true, |
- enumerable: true, |
- configurable: true}); |
- } |
- |
- if (needsDefault && (defaults === 'time' || defaults === 'all')) { |
- $objectDefineProperty(options, 'hour', {value: 'numeric', |
- writable: true, |
- enumerable: true, |
- configurable: true}); |
- $objectDefineProperty(options, 'minute', {value: 'numeric', |
- writable: true, |
- enumerable: true, |
- configurable: true}); |
- $objectDefineProperty(options, 'second', {value: 'numeric', |
- writable: true, |
- enumerable: true, |
- configurable: true}); |
+ ObjectDefineProperty(options, 'second', {value: 'numeric', |
+ writable: true, |
+ enumerable: true, |
+ configurable: true}); |
} |
return options; |
@@ -1500,7 +1507,7 @@ |
getOption, internalOptions); |
var requestedLocale = locale.locale + extension; |
- var resolved = $objectDefineProperties({}, { |
+ var resolved = ObjectDefineProperties({}, { |
calendar: {writable: true}, |
day: {writable: true}, |
era: {writable: true}, |
@@ -1528,7 +1535,7 @@ |
} |
%MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter); |
- $objectDefineProperty(dateFormat, 'resolved', {value: resolved}); |
+ ObjectDefineProperty(dateFormat, 'resolved', {value: resolved}); |
return dateFormat; |
} |
@@ -1620,7 +1627,7 @@ |
}, |
DONT_ENUM |
); |
-$setFunctionName(Intl.DateTimeFormat.prototype.resolvedOptions, |
+SetFunctionName(Intl.DateTimeFormat.prototype.resolvedOptions, |
'resolvedOptions'); |
%FunctionRemovePrototype(Intl.DateTimeFormat.prototype.resolvedOptions); |
%SetNativeFlag(Intl.DateTimeFormat.prototype.resolvedOptions); |
@@ -1641,7 +1648,7 @@ |
}, |
DONT_ENUM |
); |
-$setFunctionName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf'); |
+SetFunctionName(Intl.DateTimeFormat.supportedLocalesOf, 'supportedLocalesOf'); |
%FunctionRemovePrototype(Intl.DateTimeFormat.supportedLocalesOf); |
%SetNativeFlag(Intl.DateTimeFormat.supportedLocalesOf); |
@@ -1659,7 +1666,7 @@ |
dateMs = $toNumber(dateValue); |
} |
- if (!$isFinite(dateMs)) throw MakeRangeError(kDateRange); |
+ if (!IsFinite(dateMs)) throw MakeRangeError(kDateRange); |
return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter), |
new GlobalDate(dateMs)); |
@@ -1736,7 +1743,7 @@ |
'type', 'string', ['character', 'word', 'sentence', 'line'], 'word')); |
var locale = resolveLocale('breakiterator', locales, options); |
- var resolved = $objectDefineProperties({}, { |
+ var resolved = ObjectDefineProperties({}, { |
requestedLocale: {value: locale.locale, writable: true}, |
type: {value: internalOptions.type, writable: true}, |
locale: {writable: true} |
@@ -1748,7 +1755,7 @@ |
%MarkAsInitializedIntlObjectOfType(iterator, 'breakiterator', |
internalIterator); |
- $objectDefineProperty(iterator, 'resolved', {value: resolved}); |
+ ObjectDefineProperty(iterator, 'resolved', {value: resolved}); |
return iterator; |
} |
@@ -1799,7 +1806,7 @@ |
}, |
DONT_ENUM |
); |
-$setFunctionName(Intl.v8BreakIterator.prototype.resolvedOptions, |
+SetFunctionName(Intl.v8BreakIterator.prototype.resolvedOptions, |
'resolvedOptions'); |
%FunctionRemovePrototype(Intl.v8BreakIterator.prototype.resolvedOptions); |
%SetNativeFlag(Intl.v8BreakIterator.prototype.resolvedOptions); |
@@ -1821,7 +1828,7 @@ |
}, |
DONT_ENUM |
); |
-$setFunctionName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); |
+SetFunctionName(Intl.v8BreakIterator.supportedLocalesOf, 'supportedLocalesOf'); |
%FunctionRemovePrototype(Intl.v8BreakIterator.supportedLocalesOf); |
%SetNativeFlag(Intl.v8BreakIterator.supportedLocalesOf); |
@@ -1911,11 +1918,22 @@ |
} |
+function OverrideFunction(object, name, f) { |
+ %CheckIsBootstrapping(); |
+ ObjectDefineProperty(object, name, { value: f, |
+ writeable: true, |
+ configurable: true, |
+ enumerable: false }); |
+ SetFunctionName(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. |
*/ |
-$overrideFunction(GlobalString.prototype, 'localeCompare', function(that) { |
+OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) { |
if (%_IsConstructCall()) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
@@ -1939,7 +1957,7 @@ |
* If the form is not one of "NFC", "NFD", "NFKC", or "NFKD", then throw |
* a RangeError Exception. |
*/ |
-$overrideFunction(GlobalString.prototype, 'normalize', function(that) { |
+OverrideFunction(GlobalString.prototype, 'normalize', function(that) { |
if (%_IsConstructCall()) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
@@ -1964,7 +1982,7 @@ |
* Formats a Number object (this) using locale and options values. |
* If locale or options are omitted, defaults are used. |
*/ |
-$overrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { |
+OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() { |
if (%_IsConstructCall()) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
@@ -1989,9 +2007,7 @@ |
throw MakeTypeError(kMethodInvokedOnWrongType, "Date"); |
} |
- if ($isNaN(date)) { |
- return 'Invalid Date'; |
- } |
+ if (IsNaN(date)) return 'Invalid Date'; |
var internalOptions = toDateTimeOptions(options, required, defaults); |
@@ -2007,7 +2023,7 @@ |
* If locale or options are omitted, defaults are used - both date and time are |
* present in the output. |
*/ |
-$overrideFunction(GlobalDate.prototype, 'toLocaleString', function() { |
+OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() { |
if (%_IsConstructCall()) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
@@ -2025,7 +2041,7 @@ |
* If locale or options are omitted, defaults are used - only date is present |
* in the output. |
*/ |
-$overrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { |
+OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() { |
if (%_IsConstructCall()) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |
@@ -2043,7 +2059,7 @@ |
* If locale or options are omitted, defaults are used - only time is present |
* in the output. |
*/ |
-$overrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { |
+OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() { |
if (%_IsConstructCall()) { |
throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor); |
} |