V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
runtime-intl.cc
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-inl.h"
13 #include "src/api-natives.h"
14 #include "src/arguments-inl.h"
15 #include "src/counters.h"
16 #include "src/date.h"
17 #include "src/global-handles.h"
18 #include "src/heap/factory.h"
19 #include "src/isolate-inl.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.h"
31 
32 namespace v8 {
33 namespace internal {
34 
35 // ecma402 #sec-formatlist
36 RUNTIME_FUNCTION(Runtime_FormatList) {
37  HandleScope scope(isolate);
38  DCHECK_EQ(2, args.length());
39  CONVERT_ARG_HANDLE_CHECKED(JSListFormat, list_format, 0);
40  CONVERT_ARG_HANDLE_CHECKED(JSArray, list, 1);
41  RETURN_RESULT_OR_FAILURE(
42  isolate, JSListFormat::FormatList(isolate, list_format, list));
43 }
44 
45 // ecma402 #sec-formatlisttoparts
46 RUNTIME_FUNCTION(Runtime_FormatListToParts) {
47  HandleScope scope(isolate);
48  DCHECK_EQ(2, args.length());
49  CONVERT_ARG_HANDLE_CHECKED(JSListFormat, list_format, 0);
50  CONVERT_ARG_HANDLE_CHECKED(JSArray, list, 1);
51  RETURN_RESULT_OR_FAILURE(
52  isolate, JSListFormat::FormatListToParts(isolate, list_format, list));
53 }
54 
55 // ECMA 402 6.2.3
56 RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) {
57  HandleScope scope(isolate);
58 
59  DCHECK_EQ(1, args.length());
60  CONVERT_ARG_HANDLE_CHECKED(Object, locale, 0);
61 
62  std::string canonicalized;
63  if (!Intl::CanonicalizeLanguageTag(isolate, locale).To(&canonicalized)) {
64  return ReadOnlyRoots(isolate).exception();
65  }
66  return *isolate->factory()->NewStringFromAsciiChecked(canonicalized.c_str());
67 }
68 
69 RUNTIME_FUNCTION(Runtime_GetDefaultICULocale) {
70  HandleScope scope(isolate);
71 
72  DCHECK_EQ(0, args.length());
73  return *isolate->factory()->NewStringFromAsciiChecked(
74  Intl::DefaultLocale(isolate).c_str());
75 }
76 
77 RUNTIME_FUNCTION(Runtime_StringToLowerCaseIntl) {
78  HandleScope scope(isolate);
79  DCHECK_EQ(args.length(), 1);
80  CONVERT_ARG_HANDLE_CHECKED(String, s, 0);
81  s = String::Flatten(isolate, s);
82  RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToLower(isolate, s));
83 }
84 
85 RUNTIME_FUNCTION(Runtime_StringToUpperCaseIntl) {
86  HandleScope scope(isolate);
87  DCHECK_EQ(args.length(), 1);
88  CONVERT_ARG_HANDLE_CHECKED(String, s, 0);
89  s = String::Flatten(isolate, s);
90  RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToUpper(isolate, s));
91 }
92 
93 } // namespace internal
94 } // namespace v8
Definition: libplatform.h:13