runtime-intl.cc 2.27 KB
Newer Older
1 2 3 4
// 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.

5 6 7
#ifndef V8_INTL_SUPPORT
#error Internationalization is expected to be enabled.
#endif  // V8_INTL_SUPPORT
8

9
#include <cmath>
10 11
#include <memory>

12 13
#include "src/api/api-inl.h"
#include "src/api/api-natives.h"
Yang Guo's avatar
Yang Guo committed
14
#include "src/date/date.h"
15 16
#include "src/execution/arguments-inl.h"
#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 25
#include "src/objects/js-list-format-inl.h"
#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 33 34

namespace v8 {
namespace internal {

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
// ecma402 #sec-formatlist
RUNTIME_FUNCTION(Runtime_FormatList) {
  HandleScope scope(isolate);
  DCHECK_EQ(2, args.length());
  CONVERT_ARG_HANDLE_CHECKED(JSListFormat, list_format, 0);
  CONVERT_ARG_HANDLE_CHECKED(JSArray, list, 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());
  CONVERT_ARG_HANDLE_CHECKED(JSListFormat, list_format, 0);
  CONVERT_ARG_HANDLE_CHECKED(JSArray, list, 1);
  RETURN_RESULT_OR_FAILURE(
      isolate, JSListFormat::FormatListToParts(isolate, list_format, list));
}

55
RUNTIME_FUNCTION(Runtime_StringToLowerCaseIntl) {
56 57 58
  HandleScope scope(isolate);
  DCHECK_EQ(args.length(), 1);
  CONVERT_ARG_HANDLE_CHECKED(String, s, 0);
59
  s = String::Flatten(isolate, s);
Frank Tang's avatar
Frank Tang committed
60
  RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToLower(isolate, s));
61 62
}

63
RUNTIME_FUNCTION(Runtime_StringToUpperCaseIntl) {
64 65 66
  HandleScope scope(isolate);
  DCHECK_EQ(args.length(), 1);
  CONVERT_ARG_HANDLE_CHECKED(String, s, 0);
67
  s = String::Flatten(isolate, s);
Frank Tang's avatar
Frank Tang committed
68
  RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToUpper(isolate, s));
69 70
}

71 72
}  // namespace internal
}  // namespace v8