| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 #include "uri.h" | 64 #include "uri.h" |
| 65 #include "v8conversions.h" | 65 #include "v8conversions.h" |
| 66 #include "v8threads.h" | 66 #include "v8threads.h" |
| 67 #include "vm-state-inl.h" | 67 #include "vm-state-inl.h" |
| 68 | 68 |
| 69 #ifdef V8_I18N_SUPPORT | 69 #ifdef V8_I18N_SUPPORT |
| 70 #include "i18n.h" | 70 #include "i18n.h" |
| 71 #include "unicode/brkiter.h" | 71 #include "unicode/brkiter.h" |
| 72 #include "unicode/calendar.h" | 72 #include "unicode/calendar.h" |
| 73 #include "unicode/coll.h" | 73 #include "unicode/coll.h" |
| 74 #include "unicode/curramt.h" |
| 74 #include "unicode/datefmt.h" | 75 #include "unicode/datefmt.h" |
| 76 #include "unicode/dcfmtsym.h" |
| 77 #include "unicode/decimfmt.h" |
| 75 #include "unicode/dtfmtsym.h" | 78 #include "unicode/dtfmtsym.h" |
| 76 #include "unicode/dtptngen.h" | 79 #include "unicode/dtptngen.h" |
| 77 #include "unicode/locid.h" | 80 #include "unicode/locid.h" |
| 78 #include "unicode/numfmt.h" | 81 #include "unicode/numfmt.h" |
| 79 #include "unicode/numsys.h" | 82 #include "unicode/numsys.h" |
| 80 #include "unicode/smpdtfmt.h" | 83 #include "unicode/smpdtfmt.h" |
| 81 #include "unicode/timezone.h" | 84 #include "unicode/timezone.h" |
| 85 #include "unicode/uchar.h" |
| 86 #include "unicode/ucurr.h" |
| 82 #include "unicode/uloc.h" | 87 #include "unicode/uloc.h" |
| 88 #include "unicode/unum.h" |
| 83 #include "unicode/uversion.h" | 89 #include "unicode/uversion.h" |
| 84 #endif | 90 #endif |
| 85 | 91 |
| 86 #ifndef _STLP_VENDOR_CSTD | 92 #ifndef _STLP_VENDOR_CSTD |
| 87 // STLPort doesn't import fpclassify and isless into the std namespace. | 93 // STLPort doesn't import fpclassify and isless into the std namespace. |
| 88 using std::fpclassify; | 94 using std::fpclassify; |
| 89 using std::isless; | 95 using std::isless; |
| 90 #endif | 96 #endif |
| 91 | 97 |
| 92 namespace v8 { | 98 namespace v8 { |
| (...skipping 13565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13658 | 13664 |
| 13659 bool has_pending_exception = false; | 13665 bool has_pending_exception = false; |
| 13660 Handle<JSDate> result = Handle<JSDate>::cast( | 13666 Handle<JSDate> result = Handle<JSDate>::cast( |
| 13661 Execution::NewDate(static_cast<double>(date), &has_pending_exception)); | 13667 Execution::NewDate(static_cast<double>(date), &has_pending_exception)); |
| 13662 if (has_pending_exception) { | 13668 if (has_pending_exception) { |
| 13663 ASSERT(isolate->has_pending_exception()); | 13669 ASSERT(isolate->has_pending_exception()); |
| 13664 return Failure::Exception(); | 13670 return Failure::Exception(); |
| 13665 } | 13671 } |
| 13666 return *result; | 13672 return *result; |
| 13667 } | 13673 } |
| 13674 |
| 13675 |
| 13676 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateNumberFormat) { |
| 13677 HandleScope scope(isolate); |
| 13678 |
| 13679 ASSERT(args.length() == 3); |
| 13680 |
| 13681 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); |
| 13682 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); |
| 13683 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); |
| 13684 |
| 13685 Handle<ObjectTemplateInfo> number_format_template = |
| 13686 I18N::GetTemplate(isolate); |
| 13687 |
| 13688 // Create an empty object wrapper. |
| 13689 bool has_pending_exception = false; |
| 13690 Handle<JSObject> local_object = Execution::InstantiateObject( |
| 13691 number_format_template, &has_pending_exception); |
| 13692 if (has_pending_exception) { |
| 13693 ASSERT(isolate->has_pending_exception()); |
| 13694 return Failure::Exception(); |
| 13695 } |
| 13696 |
| 13697 // Set number formatter as internal field of the resulting JS object. |
| 13698 icu::DecimalFormat* number_format = NumberFormat::InitializeNumberFormat( |
| 13699 isolate, locale, options, resolved); |
| 13700 |
| 13701 if (!number_format) return isolate->ThrowIllegalOperation(); |
| 13702 |
| 13703 local_object->SetInternalField(0, reinterpret_cast<Smi*>(number_format)); |
| 13704 |
| 13705 RETURN_IF_EMPTY_HANDLE(isolate, |
| 13706 JSObject::SetLocalPropertyIgnoreAttributes( |
| 13707 local_object, |
| 13708 isolate->factory()->NewStringFromAscii(CStrVector("numberFormat")), |
| 13709 isolate->factory()->NewStringFromAscii(CStrVector("valid")), |
| 13710 NONE)); |
| 13711 |
| 13712 Persistent<v8::Object> wrapper(reinterpret_cast<v8::Isolate*>(isolate), |
| 13713 v8::Utils::ToLocal(local_object)); |
| 13714 // Make object handle weak so we can delete the number format once GC kicks |
| 13715 // in. |
| 13716 wrapper.MakeWeak<void>(NULL, &NumberFormat::DeleteNumberFormat); |
| 13717 Handle<Object> result = Utils::OpenPersistent(wrapper); |
| 13718 wrapper.ClearAndLeak(); |
| 13719 return *result; |
| 13720 } |
| 13721 |
| 13722 |
| 13723 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalNumberFormat) { |
| 13724 HandleScope scope(isolate); |
| 13725 |
| 13726 ASSERT(args.length() == 2); |
| 13727 |
| 13728 CONVERT_ARG_HANDLE_CHECKED(JSObject, number_format_holder, 0); |
| 13729 CONVERT_ARG_HANDLE_CHECKED(Object, number, 1); |
| 13730 |
| 13731 bool has_pending_exception = false; |
| 13732 double value = Execution::ToNumber(number, &has_pending_exception)->Number(); |
| 13733 if (has_pending_exception) { |
| 13734 ASSERT(isolate->has_pending_exception()); |
| 13735 return Failure::Exception(); |
| 13736 } |
| 13737 |
| 13738 icu::DecimalFormat* number_format = |
| 13739 NumberFormat::UnpackNumberFormat(isolate, number_format_holder); |
| 13740 if (!number_format) return isolate->ThrowIllegalOperation(); |
| 13741 |
| 13742 icu::UnicodeString result; |
| 13743 number_format->format(value, result); |
| 13744 |
| 13745 return *isolate->factory()->NewStringFromTwoByte( |
| 13746 Vector<const uint16_t>( |
| 13747 reinterpret_cast<const uint16_t*>(result.getBuffer()), |
| 13748 result.length())); |
| 13749 } |
| 13750 |
| 13751 |
| 13752 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalNumberParse) { |
| 13753 HandleScope scope(isolate); |
| 13754 |
| 13755 ASSERT(args.length() == 2); |
| 13756 |
| 13757 CONVERT_ARG_HANDLE_CHECKED(JSObject, number_format_holder, 0); |
| 13758 CONVERT_ARG_HANDLE_CHECKED(String, number_string, 1); |
| 13759 |
| 13760 v8::String::Utf8Value utf8_number(v8::Utils::ToLocal(number_string)); |
| 13761 icu::UnicodeString u_number(icu::UnicodeString::fromUTF8(*utf8_number)); |
| 13762 icu::DecimalFormat* number_format = |
| 13763 NumberFormat::UnpackNumberFormat(isolate, number_format_holder); |
| 13764 if (!number_format) return isolate->ThrowIllegalOperation(); |
| 13765 |
| 13766 UErrorCode status = U_ZERO_ERROR; |
| 13767 icu::Formattable result; |
| 13768 // ICU 4.6 doesn't support parseCurrency call. We need to wait for ICU49 |
| 13769 // to be part of Chrome. |
| 13770 // TODO(cira): Include currency parsing code using parseCurrency call. |
| 13771 // We need to check if the formatter parses all currencies or only the |
| 13772 // one it was constructed with (it will impact the API - how to return ISO |
| 13773 // code and the value). |
| 13774 number_format->parse(u_number, result, status); |
| 13775 if (U_FAILURE(status)) return isolate->heap()->undefined_value(); |
| 13776 |
| 13777 switch (result.getType()) { |
| 13778 case icu::Formattable::kDouble: |
| 13779 return *isolate->factory()->NewNumber(result.getDouble()); |
| 13780 case icu::Formattable::kLong: |
| 13781 return *isolate->factory()->NewNumberFromInt(result.getLong()); |
| 13782 case icu::Formattable::kInt64: |
| 13783 return *isolate->factory()->NewNumber( |
| 13784 static_cast<double>(result.getInt64())); |
| 13785 default: |
| 13786 return isolate->heap()->undefined_value(); |
| 13787 } |
| 13788 } |
| 13668 #endif // V8_I18N_SUPPORT | 13789 #endif // V8_I18N_SUPPORT |
| 13669 | 13790 |
| 13670 | 13791 |
| 13671 // Finds the script object from the script data. NOTE: This operation uses | 13792 // Finds the script object from the script data. NOTE: This operation uses |
| 13672 // heap traversal to find the function generated for the source position | 13793 // heap traversal to find the function generated for the source position |
| 13673 // for the requested break point. For lazily compiled functions several heap | 13794 // for the requested break point. For lazily compiled functions several heap |
| 13674 // traversals might be required rendering this operation as a rather slow | 13795 // traversals might be required rendering this operation as a rather slow |
| 13675 // operation. However for setting break points which is normally done through | 13796 // operation. However for setting break points which is normally done through |
| 13676 // some kind of user interaction the performance is not crucial. | 13797 // some kind of user interaction the performance is not crucial. |
| 13677 static Handle<Object> Runtime_GetScriptFromScriptName( | 13798 static Handle<Object> Runtime_GetScriptFromScriptName( |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14274 // Handle last resort GC and make sure to allow future allocations | 14395 // Handle last resort GC and make sure to allow future allocations |
| 14275 // to grow the heap without causing GCs (if possible). | 14396 // to grow the heap without causing GCs (if possible). |
| 14276 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14397 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14277 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14398 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14278 "Runtime::PerformGC"); | 14399 "Runtime::PerformGC"); |
| 14279 } | 14400 } |
| 14280 } | 14401 } |
| 14281 | 14402 |
| 14282 | 14403 |
| 14283 } } // namespace v8::internal | 14404 } } // namespace v8::internal |
| OLD | NEW |