Commit 6b5cfc1b authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] move defineWEProperty to C++

Bug: v8:7979
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Icf646f5b9888239acb100a4238bbccc288e93153
Reviewed-on: https://chromium-review.googlesource.com/1150918Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54762}
parent a24d5ad7
......@@ -558,7 +558,7 @@ function setOptions(inOptions, extensionMap, keyValues, getOption, outOptions) {
}
if (!IS_UNDEFINED(property)) {
defineWEProperty(outOptions, property, value);
%DefineWEProperty(outOptions, property, value);
}
}
......@@ -659,23 +659,13 @@ function getAvailableLocalesOf(service) {
}
/**
* Defines a property and sets writable and enumerable to true.
* Configurable is false by default.
*/
function defineWEProperty(object, property, value) {
%object_define_property(object, property,
{value: value, writable: true, enumerable: true});
}
/**
* Adds property to an object if the value is not undefined.
* Sets configurable descriptor to false.
*/
function addWEPropertyIfDefined(object, property, value) {
if (!IS_UNDEFINED(value)) {
defineWEProperty(object, property, value);
%DefineWEProperty(object, property, value);
}
}
......@@ -805,7 +795,7 @@ function CreateCollator(locales, options) {
var internalOptions = {__proto__: null};
defineWEProperty(internalOptions, 'usage', getOption(
%DefineWEProperty(internalOptions, 'usage', getOption(
'usage', 'string', ['sort', 'search'], 'sort'));
var sensitivity = getOption('sensitivity', 'string',
......@@ -813,9 +803,9 @@ function CreateCollator(locales, options) {
if (IS_UNDEFINED(sensitivity) && internalOptions.usage === 'sort') {
sensitivity = 'variant';
}
defineWEProperty(internalOptions, 'sensitivity', sensitivity);
%DefineWEProperty(internalOptions, 'sensitivity', sensitivity);
defineWEProperty(internalOptions, 'ignorePunctuation', getOption(
%DefineWEProperty(internalOptions, 'ignorePunctuation', getOption(
'ignorePunctuation', 'boolean', UNDEFINED, false));
var locale = resolveLocale('collator', locales, options);
......@@ -864,7 +854,7 @@ function CreateCollator(locales, options) {
} else if (internalOptions.usage === 'search') {
extension = '-u-co-search';
}
defineWEProperty(internalOptions, 'collation', collation);
%DefineWEProperty(internalOptions, 'collation', collation);
var requestedLocale = locale.locale + extension;
......@@ -979,7 +969,7 @@ function PluralRulesConstructor() {
var locale = resolveLocale('pluralrules', locales, options);
var internalOptions = {__proto__: null};
defineWEProperty(internalOptions, 'type', getOption(
%DefineWEProperty(internalOptions, 'type', getOption(
'type', 'string', ['cardinal', 'ordinal'], 'cardinal'));
SetNumberFormatDigitOptions(internalOptions, options, 0, 3);
......@@ -994,12 +984,12 @@ function PluralRulesConstructor() {
requestedLocale: {value: requestedLocale, writable: true},
});
if (HAS_OWN_PROPERTY(internalOptions, 'minimumSignificantDigits')) {
defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED);
%DefineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED);
}
if (HAS_OWN_PROPERTY(internalOptions, 'maximumSignificantDigits')) {
defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED);
%DefineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED);
}
defineWEProperty(resolved, 'pluralCategories', []);
%DefineWEProperty(resolved, 'pluralCategories', []);
var pluralRules = %CreatePluralRules(requestedLocale, internalOptions,
resolved);
......@@ -1090,27 +1080,27 @@ function SetNumberFormatDigitOptions(internalOptions, options,
mnfdDefault, mxfdDefault) {
// Digit ranges.
var mnid = getNumberOption(options, 'minimumIntegerDigits', 1, 21, 1);
defineWEProperty(internalOptions, 'minimumIntegerDigits', mnid);
%DefineWEProperty(internalOptions, 'minimumIntegerDigits', mnid);
var mnfd = getNumberOption(options, 'minimumFractionDigits', 0, 20,
mnfdDefault);
defineWEProperty(internalOptions, 'minimumFractionDigits', mnfd);
%DefineWEProperty(internalOptions, 'minimumFractionDigits', mnfd);
var mxfdActualDefault = MathMax(mnfd, mxfdDefault);
var mxfd = getNumberOption(options, 'maximumFractionDigits', mnfd, 20,
mxfdActualDefault);
defineWEProperty(internalOptions, 'maximumFractionDigits', mxfd);
%DefineWEProperty(internalOptions, 'maximumFractionDigits', mxfd);
var mnsd = options['minimumSignificantDigits'];
var mxsd = options['maximumSignificantDigits'];
if (!IS_UNDEFINED(mnsd) || !IS_UNDEFINED(mxsd)) {
mnsd = defaultNumberOption(mnsd, 1, 21, 1, 'minimumSignificantDigits');
defineWEProperty(internalOptions, 'minimumSignificantDigits', mnsd);
%DefineWEProperty(internalOptions, 'minimumSignificantDigits', mnsd);
mxsd = defaultNumberOption(mxsd, mnsd, 21, 21, 'maximumSignificantDigits');
defineWEProperty(internalOptions, 'maximumSignificantDigits', mxsd);
%DefineWEProperty(internalOptions, 'maximumSignificantDigits', mxsd);
}
}
......@@ -1128,7 +1118,7 @@ function CreateNumberFormat(locales, options) {
var locale = resolveLocale('numberformat', locales, options);
var internalOptions = {__proto__: null};
defineWEProperty(internalOptions, 'style', getOption(
%DefineWEProperty(internalOptions, 'style', getOption(
'style', 'string', ['decimal', 'percent', 'currency'], 'decimal'));
var currency = getOption('currency', 'string');
......@@ -1145,8 +1135,8 @@ function CreateNumberFormat(locales, options) {
var currencyDisplay = getOption(
'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol');
if (internalOptions.style === 'currency') {
defineWEProperty(internalOptions, 'currency', %StringToUpperCaseIntl(currency));
defineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay);
%DefineWEProperty(internalOptions, 'currency', %StringToUpperCaseIntl(currency));
%DefineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay);
mnfdDefault = mxfdDefault = %CurrencyDigits(internalOptions.currency);
} else {
......@@ -1158,7 +1148,7 @@ function CreateNumberFormat(locales, options) {
mxfdDefault);
// Grouping.
defineWEProperty(internalOptions, 'useGrouping', getOption(
%DefineWEProperty(internalOptions, 'useGrouping', getOption(
'useGrouping', 'boolean', UNDEFINED, true));
// ICU prefers options to be passed using -u- extension key/values for
......@@ -1191,10 +1181,10 @@ function CreateNumberFormat(locales, options) {
useGrouping: {writable: true}
});
if (HAS_OWN_PROPERTY(internalOptions, 'minimumSignificantDigits')) {
defineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED);
%DefineWEProperty(resolved, 'minimumSignificantDigits', UNDEFINED);
}
if (HAS_OWN_PROPERTY(internalOptions, 'maximumSignificantDigits')) {
defineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED);
%DefineWEProperty(resolved, 'maximumSignificantDigits', UNDEFINED);
}
var numberFormat = %CreateNumberFormat(requestedLocale, internalOptions,
resolved);
......@@ -1423,13 +1413,13 @@ function fromLDMLString(ldmlString) {
function appendToDateTimeObject(options, option, match, pairs) {
if (IS_NULL(match)) {
if (!HAS_OWN_PROPERTY(options, option)) {
defineWEProperty(options, option, UNDEFINED);
%DefineWEProperty(options, option, UNDEFINED);
}
return options;
}
var property = match[0];
defineWEProperty(options, option, pairs[property]);
%DefineWEProperty(options, option, pairs[property]);
return options;
}
......@@ -1734,7 +1724,7 @@ function CreateBreakIterator(locales, options) {
var internalOptions = {__proto__: null};
defineWEProperty(internalOptions, 'type', getOption(
%DefineWEProperty(internalOptions, 'type', getOption(
'type', 'string', ['character', 'word', 'sentence', 'line'], 'word'));
var locale = resolveLocale('breakiterator', locales, options);
......
......@@ -1335,6 +1335,18 @@ MaybeHandle<Object> NumberFormat::FormatNumber(
reinterpret_cast<const uint16_t*>(result.getBuffer()), result.length()));
}
void Intl::DefineWEProperty(Isolate* isolate, Handle<JSObject> target,
Handle<Name> key, Handle<Object> value) {
PropertyDescriptor desc;
desc.set_writable(true);
desc.set_enumerable(true);
desc.set_value(value);
Maybe<bool> success =
JSReceiver::DefineOwnProperty(isolate, target, key, &desc, kDontThrow);
DCHECK(success.IsJust() && success.FromJust());
USE(success);
}
namespace {
// Define general regexp macros.
......
......@@ -231,6 +231,9 @@ class Intl {
static V8_WARN_UNUSED_RESULT Handle<String> DefaultLocale(Isolate* isolate);
static void DefineWEProperty(Isolate* isolate, Handle<JSObject> target,
Handle<Name> key, Handle<Object> value);
// If locale has a script tag then return true and the locale without the
// script else return false and an empty string
static bool RemoveLocaleScriptTag(const std::string& icu_locale,
......
......@@ -89,6 +89,17 @@ RUNTIME_FUNCTION(Runtime_IsWellFormedCurrencyCode) {
Intl::IsWellFormedCurrencyCode(isolate, currency)));
}
RUNTIME_FUNCTION(Runtime_DefineWEProperty) {
HandleScope scope(isolate);
DCHECK_EQ(3, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0);
CONVERT_ARG_HANDLE_CHECKED(Name, key, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
Intl::DefineWEProperty(isolate, target, key, value);
return ReadOnlyRoots(isolate).undefined_value();
}
RUNTIME_FUNCTION(Runtime_IsInitializedIntlObjectOfType) {
HandleScope scope(isolate);
......
......@@ -213,6 +213,7 @@ namespace internal {
F(CreateCollator, 3, 1) \
F(CreateDateTimeFormat, 3, 1) \
F(CreateNumberFormat, 3, 1) \
F(DefineWEProperty, 3, 1) \
F(CreatePluralRules, 3, 1) \
F(CurrencyDigits, 1, 1) \
F(DateCacheVersion, 0, 1) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment