Revert "[Intl] Move Number.toLocaleString from js to c++"
This reverts commit a895f01ab2
.
Reason for revert: Needed for other revert:
https://chromium-review.googlesource.com/c/v8/v8/+/1152767
Original change's description:
> [Intl] Move Number.toLocaleString from js to c++
>
>
> Bug: v8:7960
> Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
> Change-Id: I21a524b620e210cce625a1a00e68c0b687187087
> Reviewed-on: https://chromium-review.googlesource.com/1144659
> Commit-Queue: Frank Tang <ftang@chromium.org>
> Reviewed-by: Jungshik Shin <jshin@chromium.org>
> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#54741}
TBR=jshin@chromium.org,gsathya@chromium.org,bstell.chromium.org@gmail.com,ftang@chromium.org
Change-Id: I060fa2834dde5e1b4cc71923cc066d97bce2a33b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7960
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/1152787
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54746}
This commit is contained in:
parent
4ef4deae6e
commit
c83fae0663
@ -1834,6 +1834,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
|
|||||||
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
SimpleInstallFunction(isolate_, prototype, "valueOf",
|
||||||
Builtins::kNumberPrototypeValueOf, 0, true);
|
Builtins::kNumberPrototypeValueOf, 0, true);
|
||||||
|
|
||||||
|
// Install Intl fallback functions.
|
||||||
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
|
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
|
||||||
Builtins::kNumberPrototypeToLocaleString, 0, false);
|
Builtins::kNumberPrototypeToLocaleString, 0, false);
|
||||||
|
|
||||||
|
@ -8,9 +8,6 @@
|
|||||||
#include "src/conversions.h"
|
#include "src/conversions.h"
|
||||||
#include "src/counters.h"
|
#include "src/counters.h"
|
||||||
#include "src/objects-inl.h"
|
#include "src/objects-inl.h"
|
||||||
#ifdef V8_INTL_SUPPORT
|
|
||||||
#include "src/objects/intl-objects.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
@ -117,7 +114,6 @@ BUILTIN(NumberPrototypeToLocaleString) {
|
|||||||
if (value->IsJSValue()) {
|
if (value->IsJSValue()) {
|
||||||
value = handle(Handle<JSValue>::cast(value)->value(), isolate);
|
value = handle(Handle<JSValue>::cast(value)->value(), isolate);
|
||||||
}
|
}
|
||||||
// 1. Let x be ? thisNumberValue(this value)
|
|
||||||
if (!value->IsNumber()) {
|
if (!value->IsNumber()) {
|
||||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||||
isolate, NewTypeError(MessageTemplate::kNotGeneric,
|
isolate, NewTypeError(MessageTemplate::kNotGeneric,
|
||||||
@ -126,15 +122,8 @@ BUILTIN(NumberPrototypeToLocaleString) {
|
|||||||
isolate->factory()->Number_string()));
|
isolate->factory()->Number_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef V8_INTL_SUPPORT
|
|
||||||
RETURN_RESULT_OR_FAILURE(
|
|
||||||
isolate,
|
|
||||||
Intl::NumberToLocaleString(isolate, value, args.atOrUndefined(isolate, 1),
|
|
||||||
args.atOrUndefined(isolate, 2)));
|
|
||||||
#else
|
|
||||||
// Turn the {value} into a String.
|
// Turn the {value} into a String.
|
||||||
return *isolate->factory()->NumberToString(value);
|
return *isolate->factory()->NumberToString(value);
|
||||||
#endif // V8_INTL_SUPPORT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ES6 section 20.1.3.5 Number.prototype.toPrecision ( precision )
|
// ES6 section 20.1.3.5 Number.prototype.toPrecision ( precision )
|
||||||
|
@ -1452,6 +1452,19 @@ DEFINE_METHOD(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a String value representing the result of calling ToNumber(value)
|
||||||
|
* according to the effective locale and the formatting options of this
|
||||||
|
* NumberFormat.
|
||||||
|
*/
|
||||||
|
function formatNumber(formatter, value) {
|
||||||
|
// Spec treats -0 and +0 as 0.
|
||||||
|
var number = TO_NUMBER(value) + 0;
|
||||||
|
|
||||||
|
return %InternalNumberFormat(formatter, number);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string that matches LDML representation of the options object.
|
* Returns a string that matches LDML representation of the options object.
|
||||||
*/
|
*/
|
||||||
@ -2082,6 +2095,25 @@ function cachedOrNewService(service, locales, options, defaults) {
|
|||||||
"cached_or_new_service", cachedOrNewService
|
"cached_or_new_service", cachedOrNewService
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a Number object (this) using locale and options values.
|
||||||
|
* If locale or options are omitted, defaults are used.
|
||||||
|
*/
|
||||||
|
DEFINE_METHOD(
|
||||||
|
GlobalNumber.prototype,
|
||||||
|
toLocaleString() {
|
||||||
|
if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') {
|
||||||
|
throw %make_type_error(kMethodInvokedOnWrongType, "Number");
|
||||||
|
}
|
||||||
|
|
||||||
|
var locales = arguments[0];
|
||||||
|
var options = arguments[1];
|
||||||
|
var numberFormat = cachedOrNewService('numberformat', locales, options);
|
||||||
|
return formatNumber(numberFormat, this);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns actual formatted date or fails if date parameter is invalid.
|
* Returns actual formatted date or fails if date parameter is invalid.
|
||||||
*/
|
*/
|
||||||
|
@ -1322,7 +1322,7 @@ MaybeHandle<JSObject> NumberFormat::Unwrap(Isolate* isolate,
|
|||||||
Intl::Type::kNumberFormat, method_name_str, true);
|
Intl::Type::kNumberFormat, method_name_str, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeHandle<String> NumberFormat::FormatNumber(
|
MaybeHandle<Object> NumberFormat::FormatNumber(
|
||||||
Isolate* isolate, Handle<JSObject> number_format_holder, double value) {
|
Isolate* isolate, Handle<JSObject> number_format_holder, double value) {
|
||||||
icu::DecimalFormat* number_format =
|
icu::DecimalFormat* number_format =
|
||||||
NumberFormat::UnpackNumberFormat(number_format_holder);
|
NumberFormat::UnpackNumberFormat(number_format_holder);
|
||||||
@ -1986,32 +1986,5 @@ Handle<Object> Intl::InternalCompare(Isolate* isolate,
|
|||||||
|
|
||||||
return factory->NewNumberFromInt(result);
|
return factory->NewNumberFromInt(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ecma402/#sup-properties-of-the-number-prototype-object
|
|
||||||
MaybeHandle<String> Intl::NumberToLocaleString(Isolate* isolate,
|
|
||||||
Handle<Object> num,
|
|
||||||
Handle<Object> locales,
|
|
||||||
Handle<Object> options) {
|
|
||||||
Factory* factory = isolate->factory();
|
|
||||||
Handle<JSObject> number_format_holder;
|
|
||||||
// 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »).
|
|
||||||
ASSIGN_RETURN_ON_EXCEPTION(
|
|
||||||
isolate, number_format_holder,
|
|
||||||
CachedOrNewService(isolate,
|
|
||||||
factory->NewStringFromStaticChars("numberformat"),
|
|
||||||
locales, options),
|
|
||||||
String);
|
|
||||||
DCHECK(
|
|
||||||
Intl::IsObjectOfType(isolate, number_format_holder, Intl::kNumberFormat));
|
|
||||||
Handle<Object> number_obj;
|
|
||||||
ASSIGN_RETURN_ON_EXCEPTION(isolate, number_obj,
|
|
||||||
Object::ToNumber(isolate, num), String);
|
|
||||||
|
|
||||||
// Spec treats -0 and +0 as 0.
|
|
||||||
double number = number_obj->Number() + 0;
|
|
||||||
// Return FormatNumber(numberFormat, x).
|
|
||||||
return NumberFormat::FormatNumber(isolate, number_format_holder, number);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace v8
|
} // namespace v8
|
||||||
|
@ -81,7 +81,7 @@ class NumberFormat {
|
|||||||
const char* method_name);
|
const char* method_name);
|
||||||
|
|
||||||
// ecm402/#sec-formatnumber
|
// ecm402/#sec-formatnumber
|
||||||
static MaybeHandle<String> FormatNumber(Isolate* isolate,
|
static MaybeHandle<Object> FormatNumber(Isolate* isolate,
|
||||||
Handle<JSObject> number_format_holder,
|
Handle<JSObject> number_format_holder,
|
||||||
double value);
|
double value);
|
||||||
|
|
||||||
@ -327,11 +327,6 @@ class Intl {
|
|||||||
V8_WARN_UNUSED_RESULT static Handle<Object> InternalCompare(
|
V8_WARN_UNUSED_RESULT static Handle<Object> InternalCompare(
|
||||||
Isolate* isolate, Handle<JSObject> collator, Handle<String> s1,
|
Isolate* isolate, Handle<JSObject> collator, Handle<String> s1,
|
||||||
Handle<String> s2);
|
Handle<String> s2);
|
||||||
|
|
||||||
// ecma402/#sup-properties-of-the-number-prototype-object
|
|
||||||
V8_WARN_UNUSED_RESULT static MaybeHandle<String> NumberToLocaleString(
|
|
||||||
Isolate* isolate, Handle<Object> num, Handle<Object> locales,
|
|
||||||
Handle<Object> options);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -229,6 +229,23 @@ RUNTIME_FUNCTION(Runtime_CreateNumberFormat) {
|
|||||||
isolate, Intl::CreateNumberFormat(isolate, locale, options, resolved));
|
isolate, Intl::CreateNumberFormat(isolate, locale, options, resolved));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RUNTIME_FUNCTION(Runtime_InternalNumberFormat) {
|
||||||
|
HandleScope scope(isolate);
|
||||||
|
|
||||||
|
DCHECK_EQ(2, args.length());
|
||||||
|
|
||||||
|
CONVERT_ARG_HANDLE_CHECKED(JSObject, number_format_holder, 0);
|
||||||
|
CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
|
||||||
|
|
||||||
|
Handle<Object> number_obj;
|
||||||
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, number_obj,
|
||||||
|
Object::ToNumber(isolate, value));
|
||||||
|
|
||||||
|
double number = number_obj->Number();
|
||||||
|
RETURN_RESULT_OR_FAILURE(isolate, NumberFormat::FormatNumber(
|
||||||
|
isolate, number_format_holder, number));
|
||||||
|
}
|
||||||
|
|
||||||
RUNTIME_FUNCTION(Runtime_CurrencyDigits) {
|
RUNTIME_FUNCTION(Runtime_CurrencyDigits) {
|
||||||
HandleScope scope(isolate);
|
HandleScope scope(isolate);
|
||||||
DCHECK_EQ(1, args.length());
|
DCHECK_EQ(1, args.length());
|
||||||
|
@ -219,6 +219,7 @@ namespace internal {
|
|||||||
F(GetDefaultICULocale, 0, 1) \
|
F(GetDefaultICULocale, 0, 1) \
|
||||||
F(InternalCompare, 3, 1) \
|
F(InternalCompare, 3, 1) \
|
||||||
F(InternalDateFormat, 2, 1) \
|
F(InternalDateFormat, 2, 1) \
|
||||||
|
F(InternalNumberFormat, 2, 1) \
|
||||||
F(IntlUnwrapReceiver, 5, 1) \
|
F(IntlUnwrapReceiver, 5, 1) \
|
||||||
F(IsInitializedIntlObjectOfType, 2, 1) \
|
F(IsInitializedIntlObjectOfType, 2, 1) \
|
||||||
F(IsWellFormedCurrencyCode, 1, 1) \
|
F(IsWellFormedCurrencyCode, 1, 1) \
|
||||||
|
Loading…
Reference in New Issue
Block a user