Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: src/runtime/runtime-i18n.cc

Issue 2601833002: [intl] Remove indirection in Intl objects (Closed)
Patch Set: Fix a dcheck Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 Handle<Symbol> marker = isolate->factory()->intl_initialized_marker_symbol(); 286 Handle<Symbol> marker = isolate->factory()->intl_initialized_marker_symbol();
287 Handle<Object> tag = JSReceiver::GetDataProperty(obj, marker); 287 Handle<Object> tag = JSReceiver::GetDataProperty(obj, marker);
288 return isolate->heap()->ToBoolean(tag->IsString() && 288 return isolate->heap()->ToBoolean(tag->IsString() &&
289 String::cast(*tag)->Equals(*expected_type)); 289 String::cast(*tag)->Equals(*expected_type));
290 } 290 }
291 291
292 292
293 RUNTIME_FUNCTION(Runtime_MarkAsInitializedIntlObjectOfType) { 293 RUNTIME_FUNCTION(Runtime_MarkAsInitializedIntlObjectOfType) {
294 HandleScope scope(isolate); 294 HandleScope scope(isolate);
295 295
296 DCHECK_EQ(3, args.length()); 296 DCHECK_EQ(2, args.length());
297 297
298 CONVERT_ARG_HANDLE_CHECKED(JSObject, input, 0); 298 CONVERT_ARG_HANDLE_CHECKED(JSObject, input, 0);
299 CONVERT_ARG_HANDLE_CHECKED(String, type, 1); 299 CONVERT_ARG_HANDLE_CHECKED(String, type, 1);
300 CONVERT_ARG_HANDLE_CHECKED(JSObject, impl, 2);
301 300
302 Handle<Symbol> marker = isolate->factory()->intl_initialized_marker_symbol(); 301 Handle<Symbol> marker = isolate->factory()->intl_initialized_marker_symbol();
303 JSObject::SetProperty(input, marker, type, STRICT).Assert(); 302 JSObject::SetProperty(input, marker, type, STRICT).Assert();
304 303
305 marker = isolate->factory()->intl_impl_object_symbol();
306 JSObject::SetProperty(input, marker, impl, STRICT).Assert();
307
308 return isolate->heap()->undefined_value(); 304 return isolate->heap()->undefined_value();
309 } 305 }
310 306
311 307
312 RUNTIME_FUNCTION(Runtime_GetImplFromInitializedIntlObject) {
313 HandleScope scope(isolate);
314
315 DCHECK_EQ(1, args.length());
316
317 CONVERT_ARG_HANDLE_CHECKED(JSObject, input, 0);
318
319 if (!input->IsJSObject()) {
320 THROW_NEW_ERROR_RETURN_FAILURE(
321 isolate, NewTypeError(MessageTemplate::kNotIntlObject, input));
322 }
323
324 Handle<JSObject> obj = Handle<JSObject>::cast(input);
325
326 Handle<Symbol> marker = isolate->factory()->intl_impl_object_symbol();
327
328 Handle<Object> impl = JSReceiver::GetDataProperty(obj, marker);
329 if (!impl->IsJSObject()) {
330 THROW_NEW_ERROR_RETURN_FAILURE(
331 isolate, NewTypeError(MessageTemplate::kNotIntlObject, obj));
332 }
333 return *impl;
334 }
335
336
337 RUNTIME_FUNCTION(Runtime_CreateDateTimeFormat) { 308 RUNTIME_FUNCTION(Runtime_CreateDateTimeFormat) {
338 HandleScope scope(isolate); 309 HandleScope scope(isolate);
339 310
340 DCHECK_EQ(3, args.length()); 311 DCHECK_EQ(3, args.length());
341 312
342 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); 313 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0);
343 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); 314 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1);
344 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); 315 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2);
345 316
346 Handle<ObjectTemplateInfo> date_format_template = I18N::GetTemplate(isolate); 317 Handle<JSFunction> constructor(
318 isolate->native_context()->intl_date_time_format_function());
347 319
348 // Create an empty object wrapper.
349 Handle<JSObject> local_object; 320 Handle<JSObject> local_object;
350 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 321 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, local_object,
351 isolate, local_object, 322 JSObject::New(constructor, constructor));
352 ApiNatives::InstantiateObject(date_format_template));
353 323
354 // Set date time formatter as internal field of the resulting JS object. 324 // Set date time formatter as internal field of the resulting JS object.
355 icu::SimpleDateFormat* date_format = 325 icu::SimpleDateFormat* date_format =
356 DateFormat::InitializeDateTimeFormat(isolate, locale, options, resolved); 326 DateFormat::InitializeDateTimeFormat(isolate, locale, options, resolved);
357 327
358 if (!date_format) return isolate->ThrowIllegalOperation(); 328 if (!date_format) return isolate->ThrowIllegalOperation();
359 329
360 local_object->SetInternalField(0, reinterpret_cast<Smi*>(date_format)); 330 local_object->SetInternalField(0, reinterpret_cast<Smi*>(date_format));
361 331
362 // Make object handle weak so we can delete the data format once GC kicks in. 332 // Make object handle weak so we can delete the data format once GC kicks in.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 497
528 RUNTIME_FUNCTION(Runtime_CreateNumberFormat) { 498 RUNTIME_FUNCTION(Runtime_CreateNumberFormat) {
529 HandleScope scope(isolate); 499 HandleScope scope(isolate);
530 500
531 DCHECK_EQ(3, args.length()); 501 DCHECK_EQ(3, args.length());
532 502
533 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); 503 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0);
534 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); 504 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1);
535 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); 505 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2);
536 506
537 Handle<ObjectTemplateInfo> number_format_template = 507 Handle<JSFunction> constructor(
538 I18N::GetTemplate(isolate); 508 isolate->native_context()->intl_number_format_function());
539 509
540 // Create an empty object wrapper.
541 Handle<JSObject> local_object; 510 Handle<JSObject> local_object;
542 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 511 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, local_object,
543 isolate, local_object, 512 JSObject::New(constructor, constructor));
544 ApiNatives::InstantiateObject(number_format_template));
545 513
546 // Set number formatter as internal field of the resulting JS object. 514 // Set number formatter as internal field of the resulting JS object.
547 icu::DecimalFormat* number_format = 515 icu::DecimalFormat* number_format =
548 NumberFormat::InitializeNumberFormat(isolate, locale, options, resolved); 516 NumberFormat::InitializeNumberFormat(isolate, locale, options, resolved);
549 517
550 if (!number_format) return isolate->ThrowIllegalOperation(); 518 if (!number_format) return isolate->ThrowIllegalOperation();
551 519
552 local_object->SetInternalField(0, reinterpret_cast<Smi*>(number_format)); 520 local_object->SetInternalField(0, reinterpret_cast<Smi*>(number_format));
553 521
554 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); 522 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 554
587 RUNTIME_FUNCTION(Runtime_CreateCollator) { 555 RUNTIME_FUNCTION(Runtime_CreateCollator) {
588 HandleScope scope(isolate); 556 HandleScope scope(isolate);
589 557
590 DCHECK_EQ(3, args.length()); 558 DCHECK_EQ(3, args.length());
591 559
592 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); 560 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0);
593 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); 561 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1);
594 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); 562 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2);
595 563
596 Handle<ObjectTemplateInfo> collator_template = I18N::GetTemplate(isolate); 564 Handle<JSFunction> constructor(
565 isolate->native_context()->intl_collator_function());
597 566
598 // Create an empty object wrapper.
599 Handle<JSObject> local_object; 567 Handle<JSObject> local_object;
600 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 568 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, local_object,
601 isolate, local_object, ApiNatives::InstantiateObject(collator_template)); 569 JSObject::New(constructor, constructor));
602 570
603 // Set collator as internal field of the resulting JS object. 571 // Set collator as internal field of the resulting JS object.
604 icu::Collator* collator = 572 icu::Collator* collator =
605 Collator::InitializeCollator(isolate, locale, options, resolved); 573 Collator::InitializeCollator(isolate, locale, options, resolved);
606 574
607 if (!collator) return isolate->ThrowIllegalOperation(); 575 if (!collator) return isolate->ThrowIllegalOperation();
608 576
609 local_object->SetInternalField(0, reinterpret_cast<Smi*>(collator)); 577 local_object->SetInternalField(0, reinterpret_cast<Smi*>(collator));
610 578
611 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); 579 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 680
713 RUNTIME_FUNCTION(Runtime_CreateBreakIterator) { 681 RUNTIME_FUNCTION(Runtime_CreateBreakIterator) {
714 HandleScope scope(isolate); 682 HandleScope scope(isolate);
715 683
716 DCHECK_EQ(3, args.length()); 684 DCHECK_EQ(3, args.length());
717 685
718 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); 686 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0);
719 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); 687 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1);
720 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); 688 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2);
721 689
722 Handle<ObjectTemplateInfo> break_iterator_template = 690 Handle<JSFunction> constructor(
723 I18N::GetTemplate2(isolate); 691 isolate->native_context()->intl_v8_break_iterator_function());
724 692
725 // Create an empty object wrapper.
726 Handle<JSObject> local_object; 693 Handle<JSObject> local_object;
727 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 694 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, local_object,
728 isolate, local_object, 695 JSObject::New(constructor, constructor));
729 ApiNatives::InstantiateObject(break_iterator_template));
730 696
731 // Set break iterator as internal field of the resulting JS object. 697 // Set break iterator as internal field of the resulting JS object.
732 icu::BreakIterator* break_iterator = BreakIterator::InitializeBreakIterator( 698 icu::BreakIterator* break_iterator = V8BreakIterator::InitializeBreakIterator(
733 isolate, locale, options, resolved); 699 isolate, locale, options, resolved);
734 700
735 if (!break_iterator) return isolate->ThrowIllegalOperation(); 701 if (!break_iterator) return isolate->ThrowIllegalOperation();
736 702
737 local_object->SetInternalField(0, reinterpret_cast<Smi*>(break_iterator)); 703 local_object->SetInternalField(0, reinterpret_cast<Smi*>(break_iterator));
738 // Make sure that the pointer to adopted text is NULL. 704 // Make sure that the pointer to adopted text is NULL.
739 local_object->SetInternalField(1, static_cast<Smi*>(nullptr)); 705 local_object->SetInternalField(1, static_cast<Smi*>(nullptr));
740 706
741 // Make object handle weak so we can delete the break iterator once GC kicks 707 // Make object handle weak so we can delete the break iterator once GC kicks
742 // in. 708 // in.
743 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); 709 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
744 GlobalHandles::MakeWeak(wrapper.location(), wrapper.location(), 710 GlobalHandles::MakeWeak(wrapper.location(), wrapper.location(),
745 BreakIterator::DeleteBreakIterator, 711 V8BreakIterator::DeleteBreakIterator,
746 WeakCallbackType::kInternalFields); 712 WeakCallbackType::kInternalFields);
747 return *local_object; 713 return *local_object;
748 } 714 }
749 715
750 716
751 RUNTIME_FUNCTION(Runtime_BreakIteratorAdoptText) { 717 RUNTIME_FUNCTION(Runtime_BreakIteratorAdoptText) {
752 HandleScope scope(isolate); 718 HandleScope scope(isolate);
753 719
754 DCHECK_EQ(2, args.length()); 720 DCHECK_EQ(2, args.length());
755 721
756 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); 722 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0);
757 CONVERT_ARG_HANDLE_CHECKED(String, text, 1); 723 CONVERT_ARG_HANDLE_CHECKED(String, text, 1);
758 724
759 icu::BreakIterator* break_iterator = 725 icu::BreakIterator* break_iterator =
760 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); 726 V8BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder);
761 CHECK_NOT_NULL(break_iterator); 727 CHECK_NOT_NULL(break_iterator);
762 728
763 icu::UnicodeString* u_text = reinterpret_cast<icu::UnicodeString*>( 729 icu::UnicodeString* u_text = reinterpret_cast<icu::UnicodeString*>(
764 break_iterator_holder->GetInternalField(1)); 730 break_iterator_holder->GetInternalField(1));
765 delete u_text; 731 delete u_text;
766 732
767 int length = text->length(); 733 int length = text->length();
768 text = String::Flatten(text); 734 text = String::Flatten(text);
769 DisallowHeapAllocation no_gc; 735 DisallowHeapAllocation no_gc;
770 String::FlatContent flat = text->GetFlatContent(); 736 String::FlatContent flat = text->GetFlatContent();
771 std::unique_ptr<uc16[]> sap; 737 std::unique_ptr<uc16[]> sap;
772 const UChar* text_value = GetUCharBufferFromFlat(flat, &sap, length); 738 const UChar* text_value = GetUCharBufferFromFlat(flat, &sap, length);
773 u_text = new icu::UnicodeString(text_value, length); 739 u_text = new icu::UnicodeString(text_value, length);
774 break_iterator_holder->SetInternalField(1, reinterpret_cast<Smi*>(u_text)); 740 break_iterator_holder->SetInternalField(1, reinterpret_cast<Smi*>(u_text));
775 741
776 break_iterator->setText(*u_text); 742 break_iterator->setText(*u_text);
777 743
778 return isolate->heap()->undefined_value(); 744 return isolate->heap()->undefined_value();
779 } 745 }
780 746
781 747
782 RUNTIME_FUNCTION(Runtime_BreakIteratorFirst) { 748 RUNTIME_FUNCTION(Runtime_BreakIteratorFirst) {
783 HandleScope scope(isolate); 749 HandleScope scope(isolate);
784 750
785 DCHECK_EQ(1, args.length()); 751 DCHECK_EQ(1, args.length());
786 752
787 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); 753 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0);
788 754
789 icu::BreakIterator* break_iterator = 755 icu::BreakIterator* break_iterator =
790 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); 756 V8BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder);
791 CHECK_NOT_NULL(break_iterator); 757 CHECK_NOT_NULL(break_iterator);
792 758
793 return *isolate->factory()->NewNumberFromInt(break_iterator->first()); 759 return *isolate->factory()->NewNumberFromInt(break_iterator->first());
794 } 760 }
795 761
796 762
797 RUNTIME_FUNCTION(Runtime_BreakIteratorNext) { 763 RUNTIME_FUNCTION(Runtime_BreakIteratorNext) {
798 HandleScope scope(isolate); 764 HandleScope scope(isolate);
799 765
800 DCHECK_EQ(1, args.length()); 766 DCHECK_EQ(1, args.length());
801 767
802 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); 768 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0);
803 769
804 icu::BreakIterator* break_iterator = 770 icu::BreakIterator* break_iterator =
805 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); 771 V8BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder);
806 CHECK_NOT_NULL(break_iterator); 772 CHECK_NOT_NULL(break_iterator);
807 773
808 return *isolate->factory()->NewNumberFromInt(break_iterator->next()); 774 return *isolate->factory()->NewNumberFromInt(break_iterator->next());
809 } 775 }
810 776
811 777
812 RUNTIME_FUNCTION(Runtime_BreakIteratorCurrent) { 778 RUNTIME_FUNCTION(Runtime_BreakIteratorCurrent) {
813 HandleScope scope(isolate); 779 HandleScope scope(isolate);
814 780
815 DCHECK_EQ(1, args.length()); 781 DCHECK_EQ(1, args.length());
816 782
817 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); 783 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0);
818 784
819 icu::BreakIterator* break_iterator = 785 icu::BreakIterator* break_iterator =
820 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); 786 V8BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder);
821 CHECK_NOT_NULL(break_iterator); 787 CHECK_NOT_NULL(break_iterator);
822 788
823 return *isolate->factory()->NewNumberFromInt(break_iterator->current()); 789 return *isolate->factory()->NewNumberFromInt(break_iterator->current());
824 } 790 }
825 791
826 792
827 RUNTIME_FUNCTION(Runtime_BreakIteratorBreakType) { 793 RUNTIME_FUNCTION(Runtime_BreakIteratorBreakType) {
828 HandleScope scope(isolate); 794 HandleScope scope(isolate);
829 795
830 DCHECK_EQ(1, args.length()); 796 DCHECK_EQ(1, args.length());
831 797
832 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); 798 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0);
833 799
834 icu::BreakIterator* break_iterator = 800 icu::BreakIterator* break_iterator =
835 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); 801 V8BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder);
836 CHECK_NOT_NULL(break_iterator); 802 CHECK_NOT_NULL(break_iterator);
837 803
838 // TODO(cira): Remove cast once ICU fixes base BreakIterator class. 804 // TODO(cira): Remove cast once ICU fixes base BreakIterator class.
839 icu::RuleBasedBreakIterator* rule_based_iterator = 805 icu::RuleBasedBreakIterator* rule_based_iterator =
840 static_cast<icu::RuleBasedBreakIterator*>(break_iterator); 806 static_cast<icu::RuleBasedBreakIterator*>(break_iterator);
841 int32_t status = rule_based_iterator->getRuleStatus(); 807 int32_t status = rule_based_iterator->getRuleStatus();
842 // Keep return values in sync with JavaScript BreakType enum. 808 // Keep return values in sync with JavaScript BreakType enum.
843 if (status >= UBRK_WORD_NONE && status < UBRK_WORD_NONE_LIMIT) { 809 if (status >= UBRK_WORD_NONE && status < UBRK_WORD_NONE_LIMIT) {
844 return *isolate->factory()->NewStringFromStaticChars("none"); 810 return *isolate->factory()->NewStringFromStaticChars("none");
845 } else if (status >= UBRK_WORD_NUMBER && status < UBRK_WORD_NUMBER_LIMIT) { 811 } else if (status >= UBRK_WORD_NUMBER && status < UBRK_WORD_NUMBER_LIMIT) {
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 Handle<FixedArray> date_cache_version = 1175 Handle<FixedArray> date_cache_version =
1210 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton( 1176 Handle<FixedArray>::cast(isolate->eternal_handles()->GetSingleton(
1211 EternalHandles::DATE_CACHE_VERSION)); 1177 EternalHandles::DATE_CACHE_VERSION));
1212 return date_cache_version->get(0); 1178 return date_cache_version->get(0);
1213 } 1179 }
1214 1180
1215 } // namespace internal 1181 } // namespace internal
1216 } // namespace v8 1182 } // namespace v8
1217 1183
1218 #endif // V8_I18N_SUPPORT 1184 #endif // V8_I18N_SUPPORT
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698