| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 #ifdef V8_I18N_SUPPORT | 6 #ifdef V8_I18N_SUPPORT |
| 7 #include "src/runtime/runtime-utils.h" | 7 #include "src/runtime/runtime-utils.h" |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/api-natives.h" | 10 #include "src/api-natives.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 HandleScope scope(isolate); | 166 HandleScope scope(isolate); |
| 167 Factory* factory = isolate->factory(); | 167 Factory* factory = isolate->factory(); |
| 168 | 168 |
| 169 DCHECK(args.length() == 1); | 169 DCHECK(args.length() == 1); |
| 170 | 170 |
| 171 CONVERT_ARG_HANDLE_CHECKED(JSArray, input, 0); | 171 CONVERT_ARG_HANDLE_CHECKED(JSArray, input, 0); |
| 172 | 172 |
| 173 uint32_t length = static_cast<uint32_t>(input->length()->Number()); | 173 uint32_t length = static_cast<uint32_t>(input->length()->Number()); |
| 174 // Set some limit to prevent fuzz tests from going OOM. | 174 // Set some limit to prevent fuzz tests from going OOM. |
| 175 // Can be bumped when callers' requirements change. | 175 // Can be bumped when callers' requirements change. |
| 176 RUNTIME_ASSERT(length < 100); | 176 if (length >= 100) return isolate->ThrowIllegalOperation(); |
| 177 Handle<FixedArray> output = factory->NewFixedArray(length); | 177 Handle<FixedArray> output = factory->NewFixedArray(length); |
| 178 Handle<Name> maximized = factory->NewStringFromStaticChars("maximized"); | 178 Handle<Name> maximized = factory->NewStringFromStaticChars("maximized"); |
| 179 Handle<Name> base = factory->NewStringFromStaticChars("base"); | 179 Handle<Name> base = factory->NewStringFromStaticChars("base"); |
| 180 for (unsigned int i = 0; i < length; ++i) { | 180 for (unsigned int i = 0; i < length; ++i) { |
| 181 Handle<Object> locale_id; | 181 Handle<Object> locale_id; |
| 182 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 182 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 183 isolate, locale_id, JSReceiver::GetElement(isolate, input, i)); | 183 isolate, locale_id, JSReceiver::GetElement(isolate, input, i)); |
| 184 if (!locale_id->IsString()) { | 184 if (!locale_id->IsString()) { |
| 185 return isolate->Throw(*factory->illegal_argument_string()); | 185 return isolate->Throw(*factory->illegal_argument_string()); |
| 186 } | 186 } |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 {"nfc", UNORM2_COMPOSE}, | 596 {"nfc", UNORM2_COMPOSE}, |
| 597 {"nfc", UNORM2_DECOMPOSE}, | 597 {"nfc", UNORM2_DECOMPOSE}, |
| 598 {"nfkc", UNORM2_COMPOSE}, | 598 {"nfkc", UNORM2_COMPOSE}, |
| 599 {"nfkc", UNORM2_DECOMPOSE}, | 599 {"nfkc", UNORM2_DECOMPOSE}, |
| 600 }; | 600 }; |
| 601 | 601 |
| 602 DCHECK(args.length() == 2); | 602 DCHECK(args.length() == 2); |
| 603 | 603 |
| 604 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); | 604 CONVERT_ARG_HANDLE_CHECKED(String, s, 0); |
| 605 CONVERT_NUMBER_CHECKED(int, form_id, Int32, args[1]); | 605 CONVERT_NUMBER_CHECKED(int, form_id, Int32, args[1]); |
| 606 RUNTIME_ASSERT(form_id >= 0 && | 606 CHECK(form_id >= 0 && |
| 607 static_cast<size_t>(form_id) < arraysize(normalizationForms)); | 607 static_cast<size_t>(form_id) < arraysize(normalizationForms)); |
| 608 | 608 |
| 609 int length = s->length(); | 609 int length = s->length(); |
| 610 s = String::Flatten(s); | 610 s = String::Flatten(s); |
| 611 icu::UnicodeString result; | 611 icu::UnicodeString result; |
| 612 base::SmartArrayPointer<uc16> sap; | 612 base::SmartArrayPointer<uc16> sap; |
| 613 UErrorCode status = U_ZERO_ERROR; | 613 UErrorCode status = U_ZERO_ERROR; |
| 614 { | 614 { |
| 615 DisallowHeapAllocation no_gc; | 615 DisallowHeapAllocation no_gc; |
| 616 String::FlatContent flat = s->GetFlatContent(); | 616 String::FlatContent flat = s->GetFlatContent(); |
| 617 const UChar* src = GetUCharBufferFromFlat(flat, &sap, length); | 617 const UChar* src = GetUCharBufferFromFlat(flat, &sap, length); |
| 618 icu::UnicodeString input(false, src, length); | 618 icu::UnicodeString input(false, src, length); |
| 619 // Getting a singleton. Should not free it. | 619 // Getting a singleton. Should not free it. |
| 620 const icu::Normalizer2* normalizer = | 620 const icu::Normalizer2* normalizer = |
| 621 icu::Normalizer2::getInstance(nullptr, normalizationForms[form_id].name, | 621 icu::Normalizer2::getInstance(nullptr, normalizationForms[form_id].name, |
| 622 normalizationForms[form_id].mode, status); | 622 normalizationForms[form_id].mode, status); |
| 623 DCHECK(U_SUCCESS(status)); | 623 DCHECK(U_SUCCESS(status)); |
| 624 RUNTIME_ASSERT(normalizer != nullptr); | 624 CHECK(normalizer != nullptr); |
| 625 int32_t normalized_prefix_length = | 625 int32_t normalized_prefix_length = |
| 626 normalizer->spanQuickCheckYes(input, status); | 626 normalizer->spanQuickCheckYes(input, status); |
| 627 // Quick return if the input is already normalized. | 627 // Quick return if the input is already normalized. |
| 628 if (length == normalized_prefix_length) return *s; | 628 if (length == normalized_prefix_length) return *s; |
| 629 icu::UnicodeString unnormalized = | 629 icu::UnicodeString unnormalized = |
| 630 input.tempSubString(normalized_prefix_length); | 630 input.tempSubString(normalized_prefix_length); |
| 631 // Read-only alias of the normalized prefix. | 631 // Read-only alias of the normalized prefix. |
| 632 result.setTo(false, input.getBuffer(), normalized_prefix_length); | 632 result.setTo(false, input.getBuffer(), normalized_prefix_length); |
| 633 // copy-on-write; normalize the suffix and append to |result|. | 633 // copy-on-write; normalize the suffix and append to |result|. |
| 634 normalizer->normalizeSecondAndAppend(result, unnormalized, status); | 634 normalizer->normalizeSecondAndAppend(result, unnormalized, status); |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 Handle<FixedArray> date_cache_version = | 1145 Handle<FixedArray> date_cache_version = |
| 1146 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( | 1146 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( |
| 1147 EternalHandles::DATE_CACHE_VERSION)); | 1147 EternalHandles::DATE_CACHE_VERSION)); |
| 1148 return date_cache_version->get(0); | 1148 return date_cache_version->get(0); |
| 1149 } | 1149 } |
| 1150 | 1150 |
| 1151 } // namespace internal | 1151 } // namespace internal |
| 1152 } // namespace v8 | 1152 } // namespace v8 |
| 1153 | 1153 |
| 1154 #endif // V8_I18N_SUPPORT | 1154 #endif // V8_I18N_SUPPORT |
| OLD | NEW |