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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #include "scopeinfo.h" | 60 #include "scopeinfo.h" |
61 #include "smart-pointers.h" | 61 #include "smart-pointers.h" |
62 #include "string-search.h" | 62 #include "string-search.h" |
63 #include "stub-cache.h" | 63 #include "stub-cache.h" |
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 "unicode/brkiter.h" | 71 #include "unicode/brkiter.h" |
| 72 #include "unicode/calendar.h" |
71 #include "unicode/coll.h" | 73 #include "unicode/coll.h" |
72 #include "unicode/datefmt.h" | 74 #include "unicode/datefmt.h" |
| 75 #include "unicode/dtfmtsym.h" |
| 76 #include "unicode/dtptngen.h" |
| 77 #include "unicode/locid.h" |
73 #include "unicode/numfmt.h" | 78 #include "unicode/numfmt.h" |
| 79 #include "unicode/numsys.h" |
| 80 #include "unicode/smpdtfmt.h" |
| 81 #include "unicode/timezone.h" |
74 #include "unicode/uloc.h" | 82 #include "unicode/uloc.h" |
75 #include "unicode/uversion.h" | 83 #include "unicode/uversion.h" |
76 #endif | 84 #endif |
77 | 85 |
78 #ifndef _STLP_VENDOR_CSTD | 86 #ifndef _STLP_VENDOR_CSTD |
79 // STLPort doesn't import fpclassify and isless into the std namespace. | 87 // STLPort doesn't import fpclassify and isless into the std namespace. |
80 using std::fpclassify; | 88 using std::fpclassify; |
81 using std::isless; | 89 using std::isless; |
82 #endif | 90 #endif |
83 | 91 |
(...skipping 13462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13546 base, | 13554 base, |
13547 isolate->factory()->NewStringFromAscii(CStrVector(base_locale)), | 13555 isolate->factory()->NewStringFromAscii(CStrVector(base_locale)), |
13548 NONE)); | 13556 NONE)); |
13549 output->set(i, *result); | 13557 output->set(i, *result); |
13550 } | 13558 } |
13551 | 13559 |
13552 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(output); | 13560 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(output); |
13553 result->set_length(Smi::FromInt(length)); | 13561 result->set_length(Smi::FromInt(length)); |
13554 return *result; | 13562 return *result; |
13555 } | 13563 } |
| 13564 |
| 13565 |
| 13566 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateDateTimeFormat) { |
| 13567 HandleScope scope(isolate); |
| 13568 |
| 13569 ASSERT(args.length() == 3); |
| 13570 |
| 13571 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); |
| 13572 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); |
| 13573 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); |
| 13574 |
| 13575 Handle<ObjectTemplateInfo> date_format_template = |
| 13576 I18N::GetTemplate(isolate); |
| 13577 |
| 13578 // Create an empty object wrapper. |
| 13579 bool has_pending_exception = false; |
| 13580 Handle<JSObject> local_object = Execution::InstantiateObject( |
| 13581 date_format_template, &has_pending_exception); |
| 13582 if (has_pending_exception) { |
| 13583 ASSERT(isolate->has_pending_exception()); |
| 13584 return Failure::Exception(); |
| 13585 } |
| 13586 |
| 13587 // Set date time formatter as internal field of the resulting JS object. |
| 13588 icu::SimpleDateFormat* date_format = DateFormat::InitializeDateTimeFormat( |
| 13589 isolate, locale, options, resolved); |
| 13590 |
| 13591 if (!date_format) return isolate->ThrowIllegalOperation(); |
| 13592 |
| 13593 local_object->SetInternalField(0, reinterpret_cast<Smi*>(date_format)); |
| 13594 |
| 13595 RETURN_IF_EMPTY_HANDLE(isolate, |
| 13596 JSObject::SetLocalPropertyIgnoreAttributes( |
| 13597 local_object, |
| 13598 isolate->factory()->NewStringFromAscii(CStrVector("dateFormat")), |
| 13599 isolate->factory()->NewStringFromAscii(CStrVector("valid")), |
| 13600 NONE)); |
| 13601 |
| 13602 Persistent<v8::Object> wrapper(reinterpret_cast<v8::Isolate*>(isolate), |
| 13603 v8::Utils::ToLocal(local_object)); |
| 13604 // Make object handle weak so we can delete the data format once GC kicks in. |
| 13605 wrapper.MakeWeak<void>(NULL, &DateFormat::DeleteDateFormat); |
| 13606 Handle<Object> result = Utils::OpenPersistent(wrapper); |
| 13607 wrapper.ClearAndLeak(); |
| 13608 return *result; |
| 13609 } |
| 13610 |
| 13611 |
| 13612 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalDateFormat) { |
| 13613 HandleScope scope(isolate); |
| 13614 |
| 13615 ASSERT(args.length() == 2); |
| 13616 |
| 13617 CONVERT_ARG_HANDLE_CHECKED(JSObject, date_format_holder, 0); |
| 13618 CONVERT_ARG_HANDLE_CHECKED(JSDate, date, 1); |
| 13619 |
| 13620 bool has_pending_exception = false; |
| 13621 double millis = Execution::ToNumber(date, &has_pending_exception)->Number(); |
| 13622 if (has_pending_exception) { |
| 13623 ASSERT(isolate->has_pending_exception()); |
| 13624 return Failure::Exception(); |
| 13625 } |
| 13626 |
| 13627 icu::SimpleDateFormat* date_format = |
| 13628 DateFormat::UnpackDateFormat(isolate, date_format_holder); |
| 13629 if (!date_format) return isolate->ThrowIllegalOperation(); |
| 13630 |
| 13631 icu::UnicodeString result; |
| 13632 date_format->format(millis, result); |
| 13633 |
| 13634 return *isolate->factory()->NewStringFromTwoByte( |
| 13635 Vector<const uint16_t>( |
| 13636 reinterpret_cast<const uint16_t*>(result.getBuffer()), |
| 13637 result.length())); |
| 13638 } |
| 13639 |
| 13640 |
| 13641 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalDateParse) { |
| 13642 HandleScope scope(isolate); |
| 13643 |
| 13644 ASSERT(args.length() == 2); |
| 13645 |
| 13646 CONVERT_ARG_HANDLE_CHECKED(JSObject, date_format_holder, 0); |
| 13647 CONVERT_ARG_HANDLE_CHECKED(String, date_string, 1); |
| 13648 |
| 13649 v8::String::Utf8Value utf8_date(v8::Utils::ToLocal(date_string)); |
| 13650 icu::UnicodeString u_date(icu::UnicodeString::fromUTF8(*utf8_date)); |
| 13651 icu::SimpleDateFormat* date_format = |
| 13652 DateFormat::UnpackDateFormat(isolate, date_format_holder); |
| 13653 if (!date_format) return isolate->ThrowIllegalOperation(); |
| 13654 |
| 13655 UErrorCode status = U_ZERO_ERROR; |
| 13656 UDate date = date_format->parse(u_date, status); |
| 13657 if (U_FAILURE(status)) return isolate->heap()->undefined_value(); |
| 13658 |
| 13659 bool has_pending_exception = false; |
| 13660 Handle<JSDate> result = Handle<JSDate>::cast( |
| 13661 Execution::NewDate(static_cast<double>(date), &has_pending_exception)); |
| 13662 if (has_pending_exception) { |
| 13663 ASSERT(isolate->has_pending_exception()); |
| 13664 return Failure::Exception(); |
| 13665 } |
| 13666 return *result; |
| 13667 } |
13556 #endif // V8_I18N_SUPPORT | 13668 #endif // V8_I18N_SUPPORT |
13557 | 13669 |
13558 | 13670 |
13559 // Finds the script object from the script data. NOTE: This operation uses | 13671 // Finds the script object from the script data. NOTE: This operation uses |
13560 // heap traversal to find the function generated for the source position | 13672 // heap traversal to find the function generated for the source position |
13561 // for the requested break point. For lazily compiled functions several heap | 13673 // for the requested break point. For lazily compiled functions several heap |
13562 // traversals might be required rendering this operation as a rather slow | 13674 // traversals might be required rendering this operation as a rather slow |
13563 // operation. However for setting break points which is normally done through | 13675 // operation. However for setting break points which is normally done through |
13564 // some kind of user interaction the performance is not crucial. | 13676 // some kind of user interaction the performance is not crucial. |
13565 static Handle<Object> Runtime_GetScriptFromScriptName( | 13677 static Handle<Object> Runtime_GetScriptFromScriptName( |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14162 // Handle last resort GC and make sure to allow future allocations | 14274 // Handle last resort GC and make sure to allow future allocations |
14163 // to grow the heap without causing GCs (if possible). | 14275 // to grow the heap without causing GCs (if possible). |
14164 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14276 isolate->counters()->gc_last_resort_from_js()->Increment(); |
14165 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14277 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
14166 "Runtime::PerformGC"); | 14278 "Runtime::PerformGC"); |
14167 } | 14279 } |
14168 } | 14280 } |
14169 | 14281 |
14170 | 14282 |
14171 } } // namespace v8::internal | 14283 } } // namespace v8::internal |
OLD | NEW |