1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_INTL_SUPPORT
6 #error Internationalization is expected to be enabled.
7 #endif // V8_INTL_SUPPORT
8
9 #include <cmath>
10 #include <memory>
11
12 #include "src/api/api-inl.h"
13 #include "src/api/api-natives.h"
14 #include "src/date/date.h"
15 #include "src/execution/arguments-inl.h"
16 #include "src/execution/isolate-inl.h"
17 #include "src/handles/global-handles.h"
18 #include "src/heap/factory.h"
19 #include "src/logging/counters.h"
20 #include "src/objects/intl-objects.h"
21 #include "src/objects/js-array-inl.h"
22 #include "src/objects/js-collator-inl.h"
23 #include "src/objects/js-date-time-format-inl.h"
24 #include "src/objects/js-list-format-inl.h"
25 #include "src/objects/js-list-format.h"
26 #include "src/objects/js-number-format-inl.h"
27 #include "src/objects/js-plural-rules-inl.h"
28 #include "src/objects/managed.h"
29 #include "src/runtime/runtime-utils.h"
30 #include "src/utils/utils.h"
31
32 namespace v8 {
33 namespace internal {
34
35 // ecma402 #sec-formatlist
RUNTIME_FUNCTION(Runtime_FormatList)36 RUNTIME_FUNCTION(Runtime_FormatList) {
37 HandleScope scope(isolate);
38 DCHECK_EQ(2, args.length());
39 Handle<JSListFormat> list_format = args.at<JSListFormat>(0);
40 Handle<FixedArray> list = args.at<FixedArray>(1);
41 RETURN_RESULT_OR_FAILURE(
42 isolate, JSListFormat::FormatList(isolate, list_format, list));
43 }
44
45 // ecma402 #sec-formatlisttoparts
RUNTIME_FUNCTION(Runtime_FormatListToParts)46 RUNTIME_FUNCTION(Runtime_FormatListToParts) {
47 HandleScope scope(isolate);
48 DCHECK_EQ(2, args.length());
49 Handle<JSListFormat> list_format = args.at<JSListFormat>(0);
50 Handle<FixedArray> list = args.at<FixedArray>(1);
51 RETURN_RESULT_OR_FAILURE(
52 isolate, JSListFormat::FormatListToParts(isolate, list_format, list));
53 }
54
RUNTIME_FUNCTION(Runtime_StringToLowerCaseIntl)55 RUNTIME_FUNCTION(Runtime_StringToLowerCaseIntl) {
56 HandleScope scope(isolate);
57 DCHECK_EQ(args.length(), 1);
58 Handle<String> s = args.at<String>(0);
59 s = String::Flatten(isolate, s);
60 RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToLower(isolate, s));
61 }
62
RUNTIME_FUNCTION(Runtime_StringToUpperCaseIntl)63 RUNTIME_FUNCTION(Runtime_StringToUpperCaseIntl) {
64 HandleScope scope(isolate);
65 DCHECK_EQ(args.length(), 1);
66 Handle<String> s = args.at<String>(0);
67 s = String::Flatten(isolate, s);
68 RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToUpper(isolate, s));
69 }
70
71 } // namespace internal
72 } // namespace v8
73