forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-intl.cc
More file actions
89 lines (74 loc) Β· 3.15 KB
/
runtime-intl.cc
File metadata and controls
89 lines (74 loc) Β· 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_INTL_SUPPORT
#error Internationalization is expected to be enabled.
#endif // V8_INTL_SUPPORT
#include <cmath>
#include <memory>
#include "src/execution/isolate-inl.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-collator-inl.h"
#include "src/objects/js-date-time-format-inl.h"
#include "src/objects/js-list-format-inl.h"
#include "src/objects/js-list-format.h"
#include "src/objects/js-number-format-inl.h"
#include "src/objects/js-plural-rules-inl.h"
#include "src/runtime/runtime-utils.h"
namespace v8 {
namespace internal {
// ecma402 #sec-formatlist
RUNTIME_FUNCTION(Runtime_FormatList) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
DirectHandle<JSListFormat> list_format = args.at<JSListFormat>(0);
DirectHandle<FixedArray> list = args.at<FixedArray>(1);
RETURN_RESULT_OR_FAILURE(
isolate, JSListFormat::FormatList(isolate, list_format, list));
}
// ecma402 #sec-formatlisttoparts
RUNTIME_FUNCTION(Runtime_FormatListToParts) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
DirectHandle<JSListFormat> list_format = args.at<JSListFormat>(0);
DirectHandle<FixedArray> list = args.at<FixedArray>(1);
RETURN_RESULT_OR_FAILURE(
isolate, JSListFormat::FormatListToParts(isolate, list_format, list));
}
RUNTIME_FUNCTION(Runtime_StringToLowerCaseIntl) {
// When this is called from Wasm code, clear the "thread in wasm" flag,
// which is important in case any GC needs to happen.
// TODO(40192807): Find a better fix, likely by replacing the global flag.
SaveAndClearThreadInWasmFlag clear_wasm_flag(isolate);
HandleScope scope(isolate);
DCHECK_EQ(args.length(), 1);
Handle<String> s = args.at<String>(0);
s = String::Flatten(isolate, s);
RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToLower(isolate, s));
}
RUNTIME_FUNCTION(Runtime_StringToUpperCaseIntl) {
// When this is called from Wasm code, clear the "thread in wasm" flag,
// which is important in case any GC needs to happen.
// TODO(40192807): Find a better fix, likely by replacing the global flag.
SaveAndClearThreadInWasmFlag clear_wasm_flag(isolate);
HandleScope scope(isolate);
DCHECK_EQ(args.length(), 1);
Handle<String> s = args.at<String>(0);
s = String::Flatten(isolate, s);
RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToUpper(isolate, s));
}
RUNTIME_FUNCTION(Runtime_StringToLocaleLowerCase) {
// When this is called from Wasm code, clear the "thread in wasm" flag,
// which is important in case any GC needs to happen.
// TODO(40192807): Find a better fix, likely by replacing the global flag.
SaveAndClearThreadInWasmFlag clear_wasm_flag(isolate);
HandleScope scope(isolate);
DCHECK_EQ(args.length(), 2);
DirectHandle<String> s = args.at<String>(0);
DirectHandle<Object> locale = args.at<Object>(1);
isolate->CountUsage(v8::Isolate::UseCounterFeature::kStringToLocaleLowerCase);
RETURN_RESULT_OR_FAILURE(
isolate, Intl::StringLocaleConvertCase(isolate, s, false, locale));
}
} // namespace internal
} // namespace v8