| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 namespace v8 { | 49 namespace v8 { |
| 50 namespace internal { | 50 namespace internal { |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 bool ExtractStringSetting(Isolate* isolate, | 54 bool ExtractStringSetting(Isolate* isolate, |
| 55 Handle<JSObject> options, | 55 Handle<JSObject> options, |
| 56 const char* key, | 56 const char* key, |
| 57 icu::UnicodeString* setting) { | 57 icu::UnicodeString* setting) { |
| 58 MaybeObject* maybe_object = options->GetProperty( | 58 Handle<String> str = isolate->factory()->NewStringFromAscii(CStrVector(key)); |
| 59 *isolate->factory()->NewStringFromAscii(CStrVector(key))); | 59 MaybeObject* maybe_object = options->GetProperty(*str); |
| 60 Object* object; | 60 Object* object; |
| 61 if (maybe_object->ToObject(&object) && object->IsString()) { | 61 if (maybe_object->ToObject(&object) && object->IsString()) { |
| 62 v8::String::Utf8Value utf8_string( | 62 v8::String::Utf8Value utf8_string( |
| 63 v8::Utils::ToLocal(Handle<String>(String::cast(object)))); | 63 v8::Utils::ToLocal(Handle<String>(String::cast(object)))); |
| 64 *setting = icu::UnicodeString::fromUTF8(*utf8_string); | 64 *setting = icu::UnicodeString::fromUTF8(*utf8_string); |
| 65 return true; | 65 return true; |
| 66 } | 66 } |
| 67 return false; | 67 return false; |
| 68 } | 68 } |
| 69 | 69 |
| 70 | 70 |
| 71 bool ExtractIntegerSetting(Isolate* isolate, | 71 bool ExtractIntegerSetting(Isolate* isolate, |
| 72 Handle<JSObject> options, | 72 Handle<JSObject> options, |
| 73 const char* key, | 73 const char* key, |
| 74 int32_t* value) { | 74 int32_t* value) { |
| 75 MaybeObject* maybe_object = options->GetProperty( | 75 Handle<String> str = isolate->factory()->NewStringFromAscii(CStrVector(key)); |
| 76 *isolate->factory()->NewStringFromAscii(CStrVector(key))); | 76 MaybeObject* maybe_object = options->GetProperty(*str); |
| 77 Object* object; | 77 Object* object; |
| 78 if (maybe_object->ToObject(&object) && object->IsNumber()) { | 78 if (maybe_object->ToObject(&object) && object->IsNumber()) { |
| 79 object->ToInt32(value); | 79 object->ToInt32(value); |
| 80 return true; | 80 return true; |
| 81 } | 81 } |
| 82 return false; | 82 return false; |
| 83 } | 83 } |
| 84 | 84 |
| 85 | 85 |
| 86 bool ExtractBooleanSetting(Isolate* isolate, | 86 bool ExtractBooleanSetting(Isolate* isolate, |
| 87 Handle<JSObject> options, | 87 Handle<JSObject> options, |
| 88 const char* key, | 88 const char* key, |
| 89 bool* value) { | 89 bool* value) { |
| 90 MaybeObject* maybe_object = options->GetProperty( | 90 Handle<String> str = isolate->factory()->NewStringFromAscii(CStrVector(key)); |
| 91 *isolate->factory()->NewStringFromAscii(CStrVector(key))); | 91 MaybeObject* maybe_object = options->GetProperty(*str); |
| 92 Object* object; | 92 Object* object; |
| 93 if (maybe_object->ToObject(&object) && object->IsBoolean()) { | 93 if (maybe_object->ToObject(&object) && object->IsBoolean()) { |
| 94 *value = object->BooleanValue(); | 94 *value = object->BooleanValue(); |
| 95 return true; | 95 return true; |
| 96 } | 96 } |
| 97 return false; | 97 return false; |
| 98 } | 98 } |
| 99 | 99 |
| 100 | 100 |
| 101 icu::SimpleDateFormat* CreateICUDateFormat( | 101 icu::SimpleDateFormat* CreateICUDateFormat( |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 | 453 |
| 454 JSObject::SetProperty( | 454 JSObject::SetProperty( |
| 455 resolved, | 455 resolved, |
| 456 isolate->factory()->NewStringFromAscii( | 456 isolate->factory()->NewStringFromAscii( |
| 457 CStrVector("maximumFractionDigits")), | 457 CStrVector("maximumFractionDigits")), |
| 458 isolate->factory()->NewNumberFromInt( | 458 isolate->factory()->NewNumberFromInt( |
| 459 number_format->getMaximumFractionDigits()), | 459 number_format->getMaximumFractionDigits()), |
| 460 NONE, | 460 NONE, |
| 461 kNonStrictMode); | 461 kNonStrictMode); |
| 462 | 462 |
| 463 if (resolved->HasLocalProperty(*isolate->factory()->NewStringFromAscii( | 463 Handle<String> key = isolate->factory()->NewStringFromAscii( |
| 464 CStrVector("minimumSignificantDigits")))) { | 464 CStrVector("minimumSignificantDigits")); |
| 465 if (resolved->HasLocalProperty(*key)) { |
| 465 JSObject::SetProperty( | 466 JSObject::SetProperty( |
| 466 resolved, | 467 resolved, |
| 467 isolate->factory()->NewStringFromAscii( | 468 isolate->factory()->NewStringFromAscii( |
| 468 CStrVector("minimumSignificantDigits")), | 469 CStrVector("minimumSignificantDigits")), |
| 469 isolate->factory()->NewNumberFromInt( | 470 isolate->factory()->NewNumberFromInt( |
| 470 number_format->getMinimumSignificantDigits()), | 471 number_format->getMinimumSignificantDigits()), |
| 471 NONE, | 472 NONE, |
| 472 kNonStrictMode); | 473 kNonStrictMode); |
| 473 } | 474 } |
| 474 | 475 |
| 475 if (resolved->HasLocalProperty(*isolate->factory()->NewStringFromAscii( | 476 key = isolate->factory()->NewStringFromAscii( |
| 476 CStrVector("maximumSignificantDigits")))) { | 477 CStrVector("maximumSignificantDigits")); |
| 478 if (resolved->HasLocalProperty(*key)) { |
| 477 JSObject::SetProperty( | 479 JSObject::SetProperty( |
| 478 resolved, | 480 resolved, |
| 479 isolate->factory()->NewStringFromAscii( | 481 isolate->factory()->NewStringFromAscii( |
| 480 CStrVector("maximumSignificantDigits")), | 482 CStrVector("maximumSignificantDigits")), |
| 481 isolate->factory()->NewNumberFromInt( | 483 isolate->factory()->NewNumberFromInt( |
| 482 number_format->getMaximumSignificantDigits()), | 484 number_format->getMaximumSignificantDigits()), |
| 483 NONE, | 485 NONE, |
| 484 kNonStrictMode); | 486 kNonStrictMode); |
| 485 } | 487 } |
| 486 | 488 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 SetResolvedDateSettings(isolate, icu_locale, date_format, resolved); | 781 SetResolvedDateSettings(isolate, icu_locale, date_format, resolved); |
| 780 } | 782 } |
| 781 | 783 |
| 782 return date_format; | 784 return date_format; |
| 783 } | 785 } |
| 784 | 786 |
| 785 | 787 |
| 786 icu::SimpleDateFormat* DateFormat::UnpackDateFormat( | 788 icu::SimpleDateFormat* DateFormat::UnpackDateFormat( |
| 787 Isolate* isolate, | 789 Isolate* isolate, |
| 788 Handle<JSObject> obj) { | 790 Handle<JSObject> obj) { |
| 789 if (obj->HasLocalProperty( | 791 Handle<String> key = |
| 790 *isolate->factory()->NewStringFromAscii(CStrVector("dateFormat")))) { | 792 isolate->factory()->NewStringFromAscii(CStrVector("dateFormat")); |
| 793 if (obj->HasLocalProperty(*key)) { |
| 791 return reinterpret_cast<icu::SimpleDateFormat*>( | 794 return reinterpret_cast<icu::SimpleDateFormat*>( |
| 792 obj->GetInternalField(0)); | 795 obj->GetInternalField(0)); |
| 793 } | 796 } |
| 794 | 797 |
| 795 return NULL; | 798 return NULL; |
| 796 } | 799 } |
| 797 | 800 |
| 798 | 801 |
| 799 void DateFormat::DeleteDateFormat(v8::Isolate* isolate, | 802 void DateFormat::DeleteDateFormat(v8::Isolate* isolate, |
| 800 Persistent<v8::Object>* object, | 803 Persistent<v8::Object>* object, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 SetResolvedNumberSettings(isolate, icu_locale, number_format, resolved); | 846 SetResolvedNumberSettings(isolate, icu_locale, number_format, resolved); |
| 844 } | 847 } |
| 845 | 848 |
| 846 return number_format; | 849 return number_format; |
| 847 } | 850 } |
| 848 | 851 |
| 849 | 852 |
| 850 icu::DecimalFormat* NumberFormat::UnpackNumberFormat( | 853 icu::DecimalFormat* NumberFormat::UnpackNumberFormat( |
| 851 Isolate* isolate, | 854 Isolate* isolate, |
| 852 Handle<JSObject> obj) { | 855 Handle<JSObject> obj) { |
| 853 if (obj->HasLocalProperty(*isolate->factory()->NewStringFromAscii( | 856 Handle<String> key = |
| 854 CStrVector("numberFormat")))) { | 857 isolate->factory()->NewStringFromAscii(CStrVector("numberFormat")); |
| 858 if (obj->HasLocalProperty(*key)) { |
| 855 return reinterpret_cast<icu::DecimalFormat*>(obj->GetInternalField(0)); | 859 return reinterpret_cast<icu::DecimalFormat*>(obj->GetInternalField(0)); |
| 856 } | 860 } |
| 857 | 861 |
| 858 return NULL; | 862 return NULL; |
| 859 } | 863 } |
| 860 | 864 |
| 861 | 865 |
| 862 void NumberFormat::DeleteNumberFormat(v8::Isolate* isolate, | 866 void NumberFormat::DeleteNumberFormat(v8::Isolate* isolate, |
| 863 Persistent<v8::Object>* object, | 867 Persistent<v8::Object>* object, |
| 864 void* param) { | 868 void* param) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 } else { | 907 } else { |
| 904 SetResolvedCollatorSettings(isolate, icu_locale, collator, resolved); | 908 SetResolvedCollatorSettings(isolate, icu_locale, collator, resolved); |
| 905 } | 909 } |
| 906 | 910 |
| 907 return collator; | 911 return collator; |
| 908 } | 912 } |
| 909 | 913 |
| 910 | 914 |
| 911 icu::Collator* Collator::UnpackCollator(Isolate* isolate, | 915 icu::Collator* Collator::UnpackCollator(Isolate* isolate, |
| 912 Handle<JSObject> obj) { | 916 Handle<JSObject> obj) { |
| 913 if (obj->HasLocalProperty(*isolate->factory()->NewStringFromAscii( | 917 Handle<String> key = |
| 914 CStrVector("collator")))) { | 918 isolate->factory()->NewStringFromAscii(CStrVector("collator")); |
| 919 if (obj->HasLocalProperty(*key)) { |
| 915 return reinterpret_cast<icu::Collator*>(obj->GetInternalField(0)); | 920 return reinterpret_cast<icu::Collator*>(obj->GetInternalField(0)); |
| 916 } | 921 } |
| 917 | 922 |
| 918 return NULL; | 923 return NULL; |
| 919 } | 924 } |
| 920 | 925 |
| 921 | 926 |
| 922 void Collator::DeleteCollator(v8::Isolate* isolate, | 927 void Collator::DeleteCollator(v8::Isolate* isolate, |
| 923 Persistent<v8::Object>* object, | 928 Persistent<v8::Object>* object, |
| 924 void* param) { | 929 void* param) { |
| 925 // First delete the hidden C++ object. | 930 // First delete the hidden C++ object. |
| 926 delete reinterpret_cast<icu::Collator*>(Handle<JSObject>::cast( | 931 delete reinterpret_cast<icu::Collator*>(Handle<JSObject>::cast( |
| 927 v8::Utils::OpenPersistent(object))->GetInternalField(0)); | 932 v8::Utils::OpenPersistent(object))->GetInternalField(0)); |
| 928 | 933 |
| 929 // Then dispose of the persistent handle to JS object. | 934 // Then dispose of the persistent handle to JS object. |
| 930 object->Dispose(isolate); | 935 object->Dispose(isolate); |
| 931 } | 936 } |
| 932 | 937 |
| 933 } } // namespace v8::internal | 938 } } // namespace v8::internal |
| OLD | NEW |