| 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 <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 if (previous_end_pos < length) { | 523 if (previous_end_pos < length) { |
| 524 if (!AddElement(result, index, -1, formatted, previous_end_pos, length, | 524 if (!AddElement(result, index, -1, formatted, previous_end_pos, length, |
| 525 isolate)) { | 525 isolate)) { |
| 526 return isolate->heap()->undefined_value(); | 526 return isolate->heap()->undefined_value(); |
| 527 } | 527 } |
| 528 } | 528 } |
| 529 JSObject::ValidateElements(result); | 529 JSObject::ValidateElements(result); |
| 530 return *result; | 530 return *result; |
| 531 } | 531 } |
| 532 | 532 |
| 533 RUNTIME_FUNCTION(Runtime_InternalDateParse) { | |
| 534 HandleScope scope(isolate); | |
| 535 | |
| 536 DCHECK(args.length() == 2); | |
| 537 | |
| 538 CONVERT_ARG_HANDLE_CHECKED(JSObject, date_format_holder, 0); | |
| 539 CONVERT_ARG_HANDLE_CHECKED(String, date_string, 1); | |
| 540 | |
| 541 v8::String::Utf8Value utf8_date(v8::Utils::ToLocal(date_string)); | |
| 542 icu::UnicodeString u_date(icu::UnicodeString::fromUTF8(*utf8_date)); | |
| 543 icu::SimpleDateFormat* date_format = | |
| 544 DateFormat::UnpackDateFormat(isolate, date_format_holder); | |
| 545 if (!date_format) return isolate->ThrowIllegalOperation(); | |
| 546 | |
| 547 UErrorCode status = U_ZERO_ERROR; | |
| 548 UDate date = date_format->parse(u_date, status); | |
| 549 if (U_FAILURE(status)) return isolate->heap()->undefined_value(); | |
| 550 | |
| 551 RETURN_RESULT_OR_FAILURE( | |
| 552 isolate, JSDate::New(isolate->date_function(), isolate->date_function(), | |
| 553 static_cast<double>(date))); | |
| 554 } | |
| 555 | |
| 556 | |
| 557 RUNTIME_FUNCTION(Runtime_CreateNumberFormat) { | 533 RUNTIME_FUNCTION(Runtime_CreateNumberFormat) { |
| 558 HandleScope scope(isolate); | 534 HandleScope scope(isolate); |
| 559 | 535 |
| 560 DCHECK(args.length() == 3); | 536 DCHECK(args.length() == 3); |
| 561 | 537 |
| 562 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); | 538 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); |
| 563 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); | 539 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); |
| 564 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); | 540 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); |
| 565 | 541 |
| 566 Handle<ObjectTemplateInfo> number_format_template = | 542 Handle<ObjectTemplateInfo> number_format_template = |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 icu::UnicodeString result; | 587 icu::UnicodeString result; |
| 612 number_format->format(value->Number(), result); | 588 number_format->format(value->Number(), result); |
| 613 | 589 |
| 614 RETURN_RESULT_OR_FAILURE( | 590 RETURN_RESULT_OR_FAILURE( |
| 615 isolate, isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>( | 591 isolate, isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>( |
| 616 reinterpret_cast<const uint16_t*>(result.getBuffer()), | 592 reinterpret_cast<const uint16_t*>(result.getBuffer()), |
| 617 result.length()))); | 593 result.length()))); |
| 618 } | 594 } |
| 619 | 595 |
| 620 | 596 |
| 621 RUNTIME_FUNCTION(Runtime_InternalNumberParse) { | |
| 622 HandleScope scope(isolate); | |
| 623 | |
| 624 DCHECK(args.length() == 2); | |
| 625 | |
| 626 CONVERT_ARG_HANDLE_CHECKED(JSObject, number_format_holder, 0); | |
| 627 CONVERT_ARG_HANDLE_CHECKED(String, number_string, 1); | |
| 628 | |
| 629 isolate->CountUsage(v8::Isolate::UseCounterFeature::kIntlV8Parse); | |
| 630 | |
| 631 v8::String::Utf8Value utf8_number(v8::Utils::ToLocal(number_string)); | |
| 632 icu::UnicodeString u_number(icu::UnicodeString::fromUTF8(*utf8_number)); | |
| 633 icu::DecimalFormat* number_format = | |
| 634 NumberFormat::UnpackNumberFormat(isolate, number_format_holder); | |
| 635 if (!number_format) return isolate->ThrowIllegalOperation(); | |
| 636 | |
| 637 UErrorCode status = U_ZERO_ERROR; | |
| 638 icu::Formattable result; | |
| 639 // ICU 4.6 doesn't support parseCurrency call. We need to wait for ICU49 | |
| 640 // to be part of Chrome. | |
| 641 // TODO(cira): Include currency parsing code using parseCurrency call. | |
| 642 // We need to check if the formatter parses all currencies or only the | |
| 643 // one it was constructed with (it will impact the API - how to return ISO | |
| 644 // code and the value). | |
| 645 number_format->parse(u_number, result, status); | |
| 646 if (U_FAILURE(status)) return isolate->heap()->undefined_value(); | |
| 647 | |
| 648 switch (result.getType()) { | |
| 649 case icu::Formattable::kDouble: | |
| 650 return *isolate->factory()->NewNumber(result.getDouble()); | |
| 651 case icu::Formattable::kLong: | |
| 652 return *isolate->factory()->NewNumberFromInt(result.getLong()); | |
| 653 case icu::Formattable::kInt64: | |
| 654 return *isolate->factory()->NewNumber( | |
| 655 static_cast<double>(result.getInt64())); | |
| 656 default: | |
| 657 return isolate->heap()->undefined_value(); | |
| 658 } | |
| 659 } | |
| 660 | |
| 661 | |
| 662 RUNTIME_FUNCTION(Runtime_CreateCollator) { | 597 RUNTIME_FUNCTION(Runtime_CreateCollator) { |
| 663 HandleScope scope(isolate); | 598 HandleScope scope(isolate); |
| 664 | 599 |
| 665 DCHECK(args.length() == 3); | 600 DCHECK(args.length() == 3); |
| 666 | 601 |
| 667 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); | 602 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); |
| 668 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); | 603 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); |
| 669 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); | 604 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); |
| 670 | 605 |
| 671 Handle<ObjectTemplateInfo> collator_template = I18N::GetTemplate(isolate); | 606 Handle<ObjectTemplateInfo> collator_template = I18N::GetTemplate(isolate); |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 Handle<FixedArray> date_cache_version = | 1201 Handle<FixedArray> date_cache_version = |
| 1267 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( | 1202 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( |
| 1268 EternalHandles::DATE_CACHE_VERSION)); | 1203 EternalHandles::DATE_CACHE_VERSION)); |
| 1269 return date_cache_version->get(0); | 1204 return date_cache_version->get(0); |
| 1270 } | 1205 } |
| 1271 | 1206 |
| 1272 } // namespace internal | 1207 } // namespace internal |
| 1273 } // namespace v8 | 1208 } // namespace v8 |
| 1274 | 1209 |
| 1275 #endif // V8_I18N_SUPPORT | 1210 #endif // V8_I18N_SUPPORT |
| OLD | NEW |