| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 #include "unicode/coll.h" | 73 #include "unicode/coll.h" |
| 74 #include "unicode/curramt.h" | 74 #include "unicode/curramt.h" |
| 75 #include "unicode/datefmt.h" | 75 #include "unicode/datefmt.h" |
| 76 #include "unicode/dcfmtsym.h" | 76 #include "unicode/dcfmtsym.h" |
| 77 #include "unicode/decimfmt.h" | 77 #include "unicode/decimfmt.h" |
| 78 #include "unicode/dtfmtsym.h" | 78 #include "unicode/dtfmtsym.h" |
| 79 #include "unicode/dtptngen.h" | 79 #include "unicode/dtptngen.h" |
| 80 #include "unicode/locid.h" | 80 #include "unicode/locid.h" |
| 81 #include "unicode/numfmt.h" | 81 #include "unicode/numfmt.h" |
| 82 #include "unicode/numsys.h" | 82 #include "unicode/numsys.h" |
| 83 #include "unicode/rbbi.h" |
| 83 #include "unicode/smpdtfmt.h" | 84 #include "unicode/smpdtfmt.h" |
| 84 #include "unicode/timezone.h" | 85 #include "unicode/timezone.h" |
| 85 #include "unicode/uchar.h" | 86 #include "unicode/uchar.h" |
| 87 #include "unicode/ucol.h" |
| 86 #include "unicode/ucurr.h" | 88 #include "unicode/ucurr.h" |
| 87 #include "unicode/uloc.h" | 89 #include "unicode/uloc.h" |
| 88 #include "unicode/unum.h" | 90 #include "unicode/unum.h" |
| 89 #include "unicode/uversion.h" | 91 #include "unicode/uversion.h" |
| 90 #endif | 92 #endif |
| 91 | 93 |
| 92 #ifndef _STLP_VENDOR_CSTD | 94 #ifndef _STLP_VENDOR_CSTD |
| 93 // STLPort doesn't import fpclassify and isless into the std namespace. | 95 // STLPort doesn't import fpclassify and isless into the std namespace. |
| 94 using std::fpclassify; | 96 using std::fpclassify; |
| 95 using std::isless; | 97 using std::isless; |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 | 989 |
| 988 if (source->IsJSTypedArray()) { | 990 if (source->IsJSTypedArray()) { |
| 989 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*source)); | 991 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*source)); |
| 990 | 992 |
| 991 if (typed_array->type() == holder->type()) { | 993 if (typed_array->type() == holder->type()) { |
| 992 uint8_t* backing_store = | 994 uint8_t* backing_store = |
| 993 static_cast<uint8_t*>( | 995 static_cast<uint8_t*>( |
| 994 JSArrayBuffer::cast(typed_array->buffer())->backing_store()); | 996 JSArrayBuffer::cast(typed_array->buffer())->backing_store()); |
| 995 size_t source_byte_offset = | 997 size_t source_byte_offset = |
| 996 NumberToSize(isolate, typed_array->byte_offset()); | 998 NumberToSize(isolate, typed_array->byte_offset()); |
| 997 OS::MemCopy( | 999 memcpy( |
| 998 buffer->backing_store(), | 1000 buffer->backing_store(), |
| 999 backing_store + source_byte_offset, | 1001 backing_store + source_byte_offset, |
| 1000 byte_length); | 1002 byte_length); |
| 1001 return *isolate->factory()->true_value(); | 1003 return *isolate->factory()->true_value(); |
| 1002 } else { | 1004 } else { |
| 1003 return *isolate->factory()->false_value(); | 1005 return *isolate->factory()->false_value(); |
| 1004 } | 1006 } |
| 1005 } | 1007 } |
| 1006 | 1008 |
| 1007 return *isolate->factory()->false_value(); | 1009 return *isolate->factory()->false_value(); |
| (...skipping 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2772 ASSERT(args.length() == 2); | 2774 ASSERT(args.length() == 2); |
| 2773 | 2775 |
| 2774 CONVERT_ARG_CHECKED(JSFunction, fun, 0); | 2776 CONVERT_ARG_CHECKED(JSFunction, fun, 0); |
| 2775 CONVERT_SMI_ARG_CHECKED(length, 1); | 2777 CONVERT_SMI_ARG_CHECKED(length, 1); |
| 2776 fun->shared()->set_length(length); | 2778 fun->shared()->set_length(length); |
| 2777 return isolate->heap()->undefined_value(); | 2779 return isolate->heap()->undefined_value(); |
| 2778 } | 2780 } |
| 2779 | 2781 |
| 2780 | 2782 |
| 2781 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionSetPrototype) { | 2783 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionSetPrototype) { |
| 2782 SealHandleScope shs(isolate); | 2784 HandleScope scope(isolate); |
| 2783 ASSERT(args.length() == 2); | 2785 ASSERT(args.length() == 2); |
| 2784 | 2786 |
| 2785 CONVERT_ARG_CHECKED(JSFunction, fun, 0); | 2787 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); |
| 2788 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
| 2786 ASSERT(fun->should_have_prototype()); | 2789 ASSERT(fun->should_have_prototype()); |
| 2787 Object* obj; | 2790 Accessors::FunctionSetPrototype(fun, value); |
| 2788 { MaybeObject* maybe_obj = | |
| 2789 Accessors::FunctionSetPrototype(fun, args[1], NULL); | |
| 2790 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | |
| 2791 } | |
| 2792 return args[0]; // return TOS | 2791 return args[0]; // return TOS |
| 2793 } | 2792 } |
| 2794 | 2793 |
| 2795 | 2794 |
| 2796 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionSetReadOnlyPrototype) { | 2795 RUNTIME_FUNCTION(MaybeObject*, Runtime_FunctionSetReadOnlyPrototype) { |
| 2797 SealHandleScope shs(isolate); | 2796 SealHandleScope shs(isolate); |
| 2798 RUNTIME_ASSERT(args.length() == 1); | 2797 RUNTIME_ASSERT(args.length() == 1); |
| 2799 CONVERT_ARG_CHECKED(JSFunction, function, 0); | 2798 CONVERT_ARG_CHECKED(JSFunction, function, 0); |
| 2800 | 2799 |
| 2801 String* name = isolate->heap()->prototype_string(); | 2800 String* name = isolate->heap()->prototype_string(); |
| (...skipping 5825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8627 return Smi::FromInt(ast_id.ToInt()); | 8626 return Smi::FromInt(ast_id.ToInt()); |
| 8628 } else { | 8627 } else { |
| 8629 if (function->IsMarkedForLazyRecompilation()) { | 8628 if (function->IsMarkedForLazyRecompilation()) { |
| 8630 function->ReplaceCode(function->shared()->code()); | 8629 function->ReplaceCode(function->shared()->code()); |
| 8631 } | 8630 } |
| 8632 return Smi::FromInt(-1); | 8631 return Smi::FromInt(-1); |
| 8633 } | 8632 } |
| 8634 } | 8633 } |
| 8635 | 8634 |
| 8636 | 8635 |
| 8636 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetAllocationTimeout) { |
| 8637 SealHandleScope shs(isolate); |
| 8638 ASSERT(args.length() == 2); |
| 8639 #ifdef DEBUG |
| 8640 CONVERT_SMI_ARG_CHECKED(interval, 0); |
| 8641 CONVERT_SMI_ARG_CHECKED(timeout, 1); |
| 8642 isolate->heap()->set_allocation_timeout(timeout); |
| 8643 FLAG_gc_interval = interval; |
| 8644 #endif |
| 8645 return isolate->heap()->undefined_value(); |
| 8646 } |
| 8647 |
| 8648 |
| 8637 RUNTIME_FUNCTION(MaybeObject*, Runtime_CheckIsBootstrapping) { | 8649 RUNTIME_FUNCTION(MaybeObject*, Runtime_CheckIsBootstrapping) { |
| 8638 SealHandleScope shs(isolate); | 8650 SealHandleScope shs(isolate); |
| 8639 RUNTIME_ASSERT(isolate->bootstrapper()->IsActive()); | 8651 RUNTIME_ASSERT(isolate->bootstrapper()->IsActive()); |
| 8640 return isolate->heap()->undefined_value(); | 8652 return isolate->heap()->undefined_value(); |
| 8641 } | 8653 } |
| 8642 | 8654 |
| 8643 | 8655 |
| 8644 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetRootNaN) { | 8656 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetRootNaN) { |
| 8645 SealHandleScope shs(isolate); | 8657 SealHandleScope shs(isolate); |
| 8646 RUNTIME_ASSERT(isolate->bootstrapper()->IsActive()); | 8658 RUNTIME_ASSERT(isolate->bootstrapper()->IsActive()); |
| (...skipping 2572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11219 FrameInspector* frame_inspector) { | 11231 FrameInspector* frame_inspector) { |
| 11220 Handle<SharedFunctionInfo> shared(function->shared()); | 11232 Handle<SharedFunctionInfo> shared(function->shared()); |
| 11221 Handle<ScopeInfo> scope_info(shared->scope_info()); | 11233 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 11222 | 11234 |
| 11223 // First fill all parameters. | 11235 // First fill all parameters. |
| 11224 for (int i = 0; i < scope_info->ParameterCount(); ++i) { | 11236 for (int i = 0; i < scope_info->ParameterCount(); ++i) { |
| 11225 Handle<Object> value(i < frame_inspector->GetParametersCount() | 11237 Handle<Object> value(i < frame_inspector->GetParametersCount() |
| 11226 ? frame_inspector->GetParameter(i) | 11238 ? frame_inspector->GetParameter(i) |
| 11227 : isolate->heap()->undefined_value(), | 11239 : isolate->heap()->undefined_value(), |
| 11228 isolate); | 11240 isolate); |
| 11241 ASSERT(!value->IsTheHole()); |
| 11229 | 11242 |
| 11230 RETURN_IF_EMPTY_HANDLE_VALUE( | 11243 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 11231 isolate, | 11244 isolate, |
| 11232 SetProperty(isolate, | 11245 SetProperty(isolate, |
| 11233 target, | 11246 target, |
| 11234 Handle<String>(scope_info->ParameterName(i)), | 11247 Handle<String>(scope_info->ParameterName(i)), |
| 11235 value, | 11248 value, |
| 11236 NONE, | 11249 NONE, |
| 11237 kNonStrictMode), | 11250 kNonStrictMode), |
| 11238 Handle<JSObject>()); | 11251 Handle<JSObject>()); |
| 11239 } | 11252 } |
| 11240 | 11253 |
| 11241 // Second fill all stack locals. | 11254 // Second fill all stack locals. |
| 11242 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { | 11255 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { |
| 11256 Handle<Object> value(frame_inspector->GetExpression(i), isolate); |
| 11257 if (value->IsTheHole()) continue; |
| 11258 |
| 11243 RETURN_IF_EMPTY_HANDLE_VALUE( | 11259 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 11244 isolate, | 11260 isolate, |
| 11245 SetProperty(isolate, | 11261 SetProperty(isolate, |
| 11246 target, | 11262 target, |
| 11247 Handle<String>(scope_info->StackLocalName(i)), | 11263 Handle<String>(scope_info->StackLocalName(i)), |
| 11248 Handle<Object>(frame_inspector->GetExpression(i), isolate), | 11264 value, |
| 11249 NONE, | 11265 NONE, |
| 11250 kNonStrictMode), | 11266 kNonStrictMode), |
| 11251 Handle<JSObject>()); | 11267 Handle<JSObject>()); |
| 11252 } | 11268 } |
| 11253 | 11269 |
| 11254 return target; | 11270 return target; |
| 11255 } | 11271 } |
| 11256 | 11272 |
| 11257 | 11273 |
| 11258 static void UpdateStackLocalsFromMaterializedObject(Isolate* isolate, | 11274 static void UpdateStackLocalsFromMaterializedObject(Isolate* isolate, |
| 11259 Handle<JSObject> target, | 11275 Handle<JSObject> target, |
| 11260 Handle<JSFunction> function, | 11276 Handle<JSFunction> function, |
| 11261 JavaScriptFrame* frame, | 11277 JavaScriptFrame* frame, |
| 11262 int inlined_jsframe_index) { | 11278 int inlined_jsframe_index) { |
| 11263 if (inlined_jsframe_index != 0 || frame->is_optimized()) { | 11279 if (inlined_jsframe_index != 0 || frame->is_optimized()) { |
| 11264 // Optimized frames are not supported. | 11280 // Optimized frames are not supported. |
| 11265 // TODO(yangguo): make sure all code deoptimized when debugger is active | 11281 // TODO(yangguo): make sure all code deoptimized when debugger is active |
| 11266 // and assert that this cannot happen. | 11282 // and assert that this cannot happen. |
| 11267 return; | 11283 return; |
| 11268 } | 11284 } |
| 11269 | 11285 |
| 11270 Handle<SharedFunctionInfo> shared(function->shared()); | 11286 Handle<SharedFunctionInfo> shared(function->shared()); |
| 11271 Handle<ScopeInfo> scope_info(shared->scope_info()); | 11287 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 11272 | 11288 |
| 11273 // Parameters. | 11289 // Parameters. |
| 11274 for (int i = 0; i < scope_info->ParameterCount(); ++i) { | 11290 for (int i = 0; i < scope_info->ParameterCount(); ++i) { |
| 11291 ASSERT(!frame->GetParameter(i)->IsTheHole()); |
| 11275 HandleScope scope(isolate); | 11292 HandleScope scope(isolate); |
| 11276 Handle<Object> value = GetProperty( | 11293 Handle<Object> value = GetProperty( |
| 11277 isolate, target, Handle<String>(scope_info->ParameterName(i))); | 11294 isolate, target, Handle<String>(scope_info->ParameterName(i))); |
| 11278 frame->SetParameterValue(i, *value); | 11295 frame->SetParameterValue(i, *value); |
| 11279 } | 11296 } |
| 11280 | 11297 |
| 11281 // Stack locals. | 11298 // Stack locals. |
| 11282 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { | 11299 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { |
| 11300 if (frame->GetExpression(i)->IsTheHole()) continue; |
| 11283 HandleScope scope(isolate); | 11301 HandleScope scope(isolate); |
| 11284 Handle<Object> value = GetProperty( | 11302 Handle<Object> value = GetProperty( |
| 11285 isolate, target, Handle<String>(scope_info->StackLocalName(i))); | 11303 isolate, target, Handle<String>(scope_info->StackLocalName(i))); |
| 11286 frame->SetExpression(i, *value); | 11304 frame->SetExpression(i, *value); |
| 11287 } | 11305 } |
| 11288 } | 11306 } |
| 11289 | 11307 |
| 11290 | 11308 |
| 11291 static Handle<JSObject> MaterializeLocalContext(Isolate* isolate, | 11309 static Handle<JSObject> MaterializeLocalContext(Isolate* isolate, |
| 11292 Handle<JSObject> target, | 11310 Handle<JSObject> target, |
| (...skipping 2314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13607 | 13625 |
| 13608 local_object->SetInternalField(0, reinterpret_cast<Smi*>(date_format)); | 13626 local_object->SetInternalField(0, reinterpret_cast<Smi*>(date_format)); |
| 13609 | 13627 |
| 13610 RETURN_IF_EMPTY_HANDLE(isolate, | 13628 RETURN_IF_EMPTY_HANDLE(isolate, |
| 13611 JSObject::SetLocalPropertyIgnoreAttributes( | 13629 JSObject::SetLocalPropertyIgnoreAttributes( |
| 13612 local_object, | 13630 local_object, |
| 13613 isolate->factory()->NewStringFromAscii(CStrVector("dateFormat")), | 13631 isolate->factory()->NewStringFromAscii(CStrVector("dateFormat")), |
| 13614 isolate->factory()->NewStringFromAscii(CStrVector("valid")), | 13632 isolate->factory()->NewStringFromAscii(CStrVector("valid")), |
| 13615 NONE)); | 13633 NONE)); |
| 13616 | 13634 |
| 13617 Persistent<v8::Object> wrapper(reinterpret_cast<v8::Isolate*>(isolate), | |
| 13618 v8::Utils::ToLocal(local_object)); | |
| 13619 // Make object handle weak so we can delete the data format once GC kicks in. | 13635 // Make object handle weak so we can delete the data format once GC kicks in. |
| 13620 wrapper.MakeWeak<void>(NULL, &DateFormat::DeleteDateFormat); | 13636 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); |
| 13621 Handle<Object> result = Utils::OpenPersistent(wrapper); | 13637 GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()), |
| 13622 wrapper.ClearAndLeak(); | 13638 NULL, |
| 13623 return *result; | 13639 DateFormat::DeleteDateFormat); |
| 13640 return *local_object; |
| 13624 } | 13641 } |
| 13625 | 13642 |
| 13626 | 13643 |
| 13627 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalDateFormat) { | 13644 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalDateFormat) { |
| 13628 HandleScope scope(isolate); | 13645 HandleScope scope(isolate); |
| 13629 | 13646 |
| 13630 ASSERT(args.length() == 2); | 13647 ASSERT(args.length() == 2); |
| 13631 | 13648 |
| 13632 CONVERT_ARG_HANDLE_CHECKED(JSObject, date_format_holder, 0); | 13649 CONVERT_ARG_HANDLE_CHECKED(JSObject, date_format_holder, 0); |
| 13633 CONVERT_ARG_HANDLE_CHECKED(JSDate, date, 1); | 13650 CONVERT_ARG_HANDLE_CHECKED(JSDate, date, 1); |
| 13634 | 13651 |
| 13635 bool has_pending_exception = false; | 13652 bool has_pending_exception = false; |
| 13636 double millis = Execution::ToNumber(date, &has_pending_exception)->Number(); | 13653 Handle<Object> value = Execution::ToNumber(date, &has_pending_exception); |
| 13637 if (has_pending_exception) { | 13654 if (has_pending_exception) { |
| 13638 ASSERT(isolate->has_pending_exception()); | 13655 ASSERT(isolate->has_pending_exception()); |
| 13639 return Failure::Exception(); | 13656 return Failure::Exception(); |
| 13640 } | 13657 } |
| 13641 | 13658 |
| 13642 icu::SimpleDateFormat* date_format = | 13659 icu::SimpleDateFormat* date_format = |
| 13643 DateFormat::UnpackDateFormat(isolate, date_format_holder); | 13660 DateFormat::UnpackDateFormat(isolate, date_format_holder); |
| 13644 if (!date_format) return isolate->ThrowIllegalOperation(); | 13661 if (!date_format) return isolate->ThrowIllegalOperation(); |
| 13645 | 13662 |
| 13646 icu::UnicodeString result; | 13663 icu::UnicodeString result; |
| 13647 date_format->format(millis, result); | 13664 date_format->format(value->Number(), result); |
| 13648 | 13665 |
| 13649 return *isolate->factory()->NewStringFromTwoByte( | 13666 return *isolate->factory()->NewStringFromTwoByte( |
| 13650 Vector<const uint16_t>( | 13667 Vector<const uint16_t>( |
| 13651 reinterpret_cast<const uint16_t*>(result.getBuffer()), | 13668 reinterpret_cast<const uint16_t*>(result.getBuffer()), |
| 13652 result.length())); | 13669 result.length())); |
| 13653 } | 13670 } |
| 13654 | 13671 |
| 13655 | 13672 |
| 13656 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalDateParse) { | 13673 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalDateParse) { |
| 13657 HandleScope scope(isolate); | 13674 HandleScope scope(isolate); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13711 | 13728 |
| 13712 local_object->SetInternalField(0, reinterpret_cast<Smi*>(number_format)); | 13729 local_object->SetInternalField(0, reinterpret_cast<Smi*>(number_format)); |
| 13713 | 13730 |
| 13714 RETURN_IF_EMPTY_HANDLE(isolate, | 13731 RETURN_IF_EMPTY_HANDLE(isolate, |
| 13715 JSObject::SetLocalPropertyIgnoreAttributes( | 13732 JSObject::SetLocalPropertyIgnoreAttributes( |
| 13716 local_object, | 13733 local_object, |
| 13717 isolate->factory()->NewStringFromAscii(CStrVector("numberFormat")), | 13734 isolate->factory()->NewStringFromAscii(CStrVector("numberFormat")), |
| 13718 isolate->factory()->NewStringFromAscii(CStrVector("valid")), | 13735 isolate->factory()->NewStringFromAscii(CStrVector("valid")), |
| 13719 NONE)); | 13736 NONE)); |
| 13720 | 13737 |
| 13721 Persistent<v8::Object> wrapper(reinterpret_cast<v8::Isolate*>(isolate), | 13738 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); |
| 13722 v8::Utils::ToLocal(local_object)); | 13739 GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()), |
| 13723 // Make object handle weak so we can delete the number format once GC kicks | 13740 NULL, |
| 13724 // in. | 13741 NumberFormat::DeleteNumberFormat); |
| 13725 wrapper.MakeWeak<void>(NULL, &NumberFormat::DeleteNumberFormat); | 13742 return *local_object; |
| 13726 Handle<Object> result = Utils::OpenPersistent(wrapper); | |
| 13727 wrapper.ClearAndLeak(); | |
| 13728 return *result; | |
| 13729 } | 13743 } |
| 13730 | 13744 |
| 13731 | 13745 |
| 13732 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalNumberFormat) { | 13746 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalNumberFormat) { |
| 13733 HandleScope scope(isolate); | 13747 HandleScope scope(isolate); |
| 13734 | 13748 |
| 13735 ASSERT(args.length() == 2); | 13749 ASSERT(args.length() == 2); |
| 13736 | 13750 |
| 13737 CONVERT_ARG_HANDLE_CHECKED(JSObject, number_format_holder, 0); | 13751 CONVERT_ARG_HANDLE_CHECKED(JSObject, number_format_holder, 0); |
| 13738 CONVERT_ARG_HANDLE_CHECKED(Object, number, 1); | 13752 CONVERT_ARG_HANDLE_CHECKED(Object, number, 1); |
| 13739 | 13753 |
| 13740 bool has_pending_exception = false; | 13754 bool has_pending_exception = false; |
| 13741 double value = Execution::ToNumber(number, &has_pending_exception)->Number(); | 13755 Handle<Object> value = Execution::ToNumber(number, &has_pending_exception); |
| 13742 if (has_pending_exception) { | 13756 if (has_pending_exception) { |
| 13743 ASSERT(isolate->has_pending_exception()); | 13757 ASSERT(isolate->has_pending_exception()); |
| 13744 return Failure::Exception(); | 13758 return Failure::Exception(); |
| 13745 } | 13759 } |
| 13746 | 13760 |
| 13747 icu::DecimalFormat* number_format = | 13761 icu::DecimalFormat* number_format = |
| 13748 NumberFormat::UnpackNumberFormat(isolate, number_format_holder); | 13762 NumberFormat::UnpackNumberFormat(isolate, number_format_holder); |
| 13749 if (!number_format) return isolate->ThrowIllegalOperation(); | 13763 if (!number_format) return isolate->ThrowIllegalOperation(); |
| 13750 | 13764 |
| 13751 icu::UnicodeString result; | 13765 icu::UnicodeString result; |
| 13752 number_format->format(value, result); | 13766 number_format->format(value->Number(), result); |
| 13753 | 13767 |
| 13754 return *isolate->factory()->NewStringFromTwoByte( | 13768 return *isolate->factory()->NewStringFromTwoByte( |
| 13755 Vector<const uint16_t>( | 13769 Vector<const uint16_t>( |
| 13756 reinterpret_cast<const uint16_t*>(result.getBuffer()), | 13770 reinterpret_cast<const uint16_t*>(result.getBuffer()), |
| 13757 result.length())); | 13771 result.length())); |
| 13758 } | 13772 } |
| 13759 | 13773 |
| 13760 | 13774 |
| 13761 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalNumberParse) { | 13775 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalNumberParse) { |
| 13762 HandleScope scope(isolate); | 13776 HandleScope scope(isolate); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 13788 return *isolate->factory()->NewNumber(result.getDouble()); | 13802 return *isolate->factory()->NewNumber(result.getDouble()); |
| 13789 case icu::Formattable::kLong: | 13803 case icu::Formattable::kLong: |
| 13790 return *isolate->factory()->NewNumberFromInt(result.getLong()); | 13804 return *isolate->factory()->NewNumberFromInt(result.getLong()); |
| 13791 case icu::Formattable::kInt64: | 13805 case icu::Formattable::kInt64: |
| 13792 return *isolate->factory()->NewNumber( | 13806 return *isolate->factory()->NewNumber( |
| 13793 static_cast<double>(result.getInt64())); | 13807 static_cast<double>(result.getInt64())); |
| 13794 default: | 13808 default: |
| 13795 return isolate->heap()->undefined_value(); | 13809 return isolate->heap()->undefined_value(); |
| 13796 } | 13810 } |
| 13797 } | 13811 } |
| 13812 |
| 13813 |
| 13814 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateCollator) { |
| 13815 HandleScope scope(isolate); |
| 13816 |
| 13817 ASSERT(args.length() == 3); |
| 13818 |
| 13819 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); |
| 13820 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); |
| 13821 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); |
| 13822 |
| 13823 Handle<ObjectTemplateInfo> collator_template = I18N::GetTemplate(isolate); |
| 13824 |
| 13825 // Create an empty object wrapper. |
| 13826 bool has_pending_exception = false; |
| 13827 Handle<JSObject> local_object = Execution::InstantiateObject( |
| 13828 collator_template, &has_pending_exception); |
| 13829 if (has_pending_exception) { |
| 13830 ASSERT(isolate->has_pending_exception()); |
| 13831 return Failure::Exception(); |
| 13832 } |
| 13833 |
| 13834 // Set collator as internal field of the resulting JS object. |
| 13835 icu::Collator* collator = Collator::InitializeCollator( |
| 13836 isolate, locale, options, resolved); |
| 13837 |
| 13838 if (!collator) return isolate->ThrowIllegalOperation(); |
| 13839 |
| 13840 local_object->SetInternalField(0, reinterpret_cast<Smi*>(collator)); |
| 13841 |
| 13842 RETURN_IF_EMPTY_HANDLE(isolate, |
| 13843 JSObject::SetLocalPropertyIgnoreAttributes( |
| 13844 local_object, |
| 13845 isolate->factory()->NewStringFromAscii(CStrVector("collator")), |
| 13846 isolate->factory()->NewStringFromAscii(CStrVector("valid")), |
| 13847 NONE)); |
| 13848 |
| 13849 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); |
| 13850 GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()), |
| 13851 NULL, |
| 13852 Collator::DeleteCollator); |
| 13853 return *local_object; |
| 13854 } |
| 13855 |
| 13856 |
| 13857 RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalCompare) { |
| 13858 HandleScope scope(isolate); |
| 13859 |
| 13860 ASSERT(args.length() == 3); |
| 13861 |
| 13862 CONVERT_ARG_HANDLE_CHECKED(JSObject, collator_holder, 0); |
| 13863 CONVERT_ARG_HANDLE_CHECKED(String, string1, 1); |
| 13864 CONVERT_ARG_HANDLE_CHECKED(String, string2, 2); |
| 13865 |
| 13866 icu::Collator* collator = Collator::UnpackCollator(isolate, collator_holder); |
| 13867 if (!collator) return isolate->ThrowIllegalOperation(); |
| 13868 |
| 13869 v8::String::Value string_value1(v8::Utils::ToLocal(string1)); |
| 13870 v8::String::Value string_value2(v8::Utils::ToLocal(string2)); |
| 13871 const UChar* u_string1 = reinterpret_cast<const UChar*>(*string_value1); |
| 13872 const UChar* u_string2 = reinterpret_cast<const UChar*>(*string_value2); |
| 13873 UErrorCode status = U_ZERO_ERROR; |
| 13874 UCollationResult result = collator->compare(u_string1, |
| 13875 string_value1.length(), |
| 13876 u_string2, |
| 13877 string_value2.length(), |
| 13878 status); |
| 13879 if (U_FAILURE(status)) return isolate->ThrowIllegalOperation(); |
| 13880 |
| 13881 return *isolate->factory()->NewNumberFromInt(result); |
| 13882 } |
| 13883 |
| 13884 |
| 13885 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateBreakIterator) { |
| 13886 HandleScope scope(isolate); |
| 13887 |
| 13888 ASSERT(args.length() == 3); |
| 13889 |
| 13890 CONVERT_ARG_HANDLE_CHECKED(String, locale, 0); |
| 13891 CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1); |
| 13892 CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2); |
| 13893 |
| 13894 Handle<ObjectTemplateInfo> break_iterator_template = |
| 13895 I18N::GetTemplate2(isolate); |
| 13896 |
| 13897 // Create an empty object wrapper. |
| 13898 bool has_pending_exception = false; |
| 13899 Handle<JSObject> local_object = Execution::InstantiateObject( |
| 13900 break_iterator_template, &has_pending_exception); |
| 13901 if (has_pending_exception) { |
| 13902 ASSERT(isolate->has_pending_exception()); |
| 13903 return Failure::Exception(); |
| 13904 } |
| 13905 |
| 13906 // Set break iterator as internal field of the resulting JS object. |
| 13907 icu::BreakIterator* break_iterator = BreakIterator::InitializeBreakIterator( |
| 13908 isolate, locale, options, resolved); |
| 13909 |
| 13910 if (!break_iterator) return isolate->ThrowIllegalOperation(); |
| 13911 |
| 13912 local_object->SetInternalField(0, reinterpret_cast<Smi*>(break_iterator)); |
| 13913 // Make sure that the pointer to adopted text is NULL. |
| 13914 local_object->SetInternalField(1, reinterpret_cast<Smi*>(NULL)); |
| 13915 |
| 13916 RETURN_IF_EMPTY_HANDLE(isolate, |
| 13917 JSObject::SetLocalPropertyIgnoreAttributes( |
| 13918 local_object, |
| 13919 isolate->factory()->NewStringFromAscii(CStrVector("breakIterator")), |
| 13920 isolate->factory()->NewStringFromAscii(CStrVector("valid")), |
| 13921 NONE)); |
| 13922 |
| 13923 // Make object handle weak so we can delete the break iterator once GC kicks |
| 13924 // in. |
| 13925 Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); |
| 13926 GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()), |
| 13927 NULL, |
| 13928 BreakIterator::DeleteBreakIterator); |
| 13929 return *local_object; |
| 13930 } |
| 13931 |
| 13932 |
| 13933 RUNTIME_FUNCTION(MaybeObject*, Runtime_BreakIteratorAdoptText) { |
| 13934 HandleScope scope(isolate); |
| 13935 |
| 13936 ASSERT(args.length() == 2); |
| 13937 |
| 13938 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); |
| 13939 CONVERT_ARG_HANDLE_CHECKED(String, text, 1); |
| 13940 |
| 13941 icu::BreakIterator* break_iterator = |
| 13942 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); |
| 13943 if (!break_iterator) return isolate->ThrowIllegalOperation(); |
| 13944 |
| 13945 icu::UnicodeString* u_text = reinterpret_cast<icu::UnicodeString*>( |
| 13946 break_iterator_holder->GetInternalField(1)); |
| 13947 delete u_text; |
| 13948 |
| 13949 v8::String::Value text_value(v8::Utils::ToLocal(text)); |
| 13950 u_text = new icu::UnicodeString( |
| 13951 reinterpret_cast<const UChar*>(*text_value), text_value.length()); |
| 13952 break_iterator_holder->SetInternalField(1, reinterpret_cast<Smi*>(u_text)); |
| 13953 |
| 13954 break_iterator->setText(*u_text); |
| 13955 |
| 13956 return isolate->heap()->undefined_value(); |
| 13957 } |
| 13958 |
| 13959 |
| 13960 RUNTIME_FUNCTION(MaybeObject*, Runtime_BreakIteratorFirst) { |
| 13961 HandleScope scope(isolate); |
| 13962 |
| 13963 ASSERT(args.length() == 1); |
| 13964 |
| 13965 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); |
| 13966 |
| 13967 icu::BreakIterator* break_iterator = |
| 13968 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); |
| 13969 if (!break_iterator) return isolate->ThrowIllegalOperation(); |
| 13970 |
| 13971 return *isolate->factory()->NewNumberFromInt(break_iterator->first()); |
| 13972 } |
| 13973 |
| 13974 |
| 13975 RUNTIME_FUNCTION(MaybeObject*, Runtime_BreakIteratorNext) { |
| 13976 HandleScope scope(isolate); |
| 13977 |
| 13978 ASSERT(args.length() == 1); |
| 13979 |
| 13980 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); |
| 13981 |
| 13982 icu::BreakIterator* break_iterator = |
| 13983 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); |
| 13984 if (!break_iterator) return isolate->ThrowIllegalOperation(); |
| 13985 |
| 13986 return *isolate->factory()->NewNumberFromInt(break_iterator->next()); |
| 13987 } |
| 13988 |
| 13989 |
| 13990 RUNTIME_FUNCTION(MaybeObject*, Runtime_BreakIteratorCurrent) { |
| 13991 HandleScope scope(isolate); |
| 13992 |
| 13993 ASSERT(args.length() == 1); |
| 13994 |
| 13995 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); |
| 13996 |
| 13997 icu::BreakIterator* break_iterator = |
| 13998 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); |
| 13999 if (!break_iterator) return isolate->ThrowIllegalOperation(); |
| 14000 |
| 14001 return *isolate->factory()->NewNumberFromInt(break_iterator->current()); |
| 14002 } |
| 14003 |
| 14004 |
| 14005 RUNTIME_FUNCTION(MaybeObject*, Runtime_BreakIteratorBreakType) { |
| 14006 HandleScope scope(isolate); |
| 14007 |
| 14008 ASSERT(args.length() == 1); |
| 14009 |
| 14010 CONVERT_ARG_HANDLE_CHECKED(JSObject, break_iterator_holder, 0); |
| 14011 |
| 14012 icu::BreakIterator* break_iterator = |
| 14013 BreakIterator::UnpackBreakIterator(isolate, break_iterator_holder); |
| 14014 if (!break_iterator) return isolate->ThrowIllegalOperation(); |
| 14015 |
| 14016 // TODO(cira): Remove cast once ICU fixes base BreakIterator class. |
| 14017 icu::RuleBasedBreakIterator* rule_based_iterator = |
| 14018 static_cast<icu::RuleBasedBreakIterator*>(break_iterator); |
| 14019 int32_t status = rule_based_iterator->getRuleStatus(); |
| 14020 // Keep return values in sync with JavaScript BreakType enum. |
| 14021 if (status >= UBRK_WORD_NONE && status < UBRK_WORD_NONE_LIMIT) { |
| 14022 return *isolate->factory()->NewStringFromAscii(CStrVector("none")); |
| 14023 } else if (status >= UBRK_WORD_NUMBER && status < UBRK_WORD_NUMBER_LIMIT) { |
| 14024 return *isolate->factory()->NewStringFromAscii(CStrVector("number")); |
| 14025 } else if (status >= UBRK_WORD_LETTER && status < UBRK_WORD_LETTER_LIMIT) { |
| 14026 return *isolate->factory()->NewStringFromAscii(CStrVector("letter")); |
| 14027 } else if (status >= UBRK_WORD_KANA && status < UBRK_WORD_KANA_LIMIT) { |
| 14028 return *isolate->factory()->NewStringFromAscii(CStrVector("kana")); |
| 14029 } else if (status >= UBRK_WORD_IDEO && status < UBRK_WORD_IDEO_LIMIT) { |
| 14030 return *isolate->factory()->NewStringFromAscii(CStrVector("ideo")); |
| 14031 } else { |
| 14032 return *isolate->factory()->NewStringFromAscii(CStrVector("unknown")); |
| 14033 } |
| 14034 } |
| 13798 #endif // V8_I18N_SUPPORT | 14035 #endif // V8_I18N_SUPPORT |
| 13799 | 14036 |
| 13800 | 14037 |
| 13801 // Finds the script object from the script data. NOTE: This operation uses | 14038 // Finds the script object from the script data. NOTE: This operation uses |
| 13802 // heap traversal to find the function generated for the source position | 14039 // heap traversal to find the function generated for the source position |
| 13803 // for the requested break point. For lazily compiled functions several heap | 14040 // for the requested break point. For lazily compiled functions several heap |
| 13804 // traversals might be required rendering this operation as a rather slow | 14041 // traversals might be required rendering this operation as a rather slow |
| 13805 // operation. However for setting break points which is normally done through | 14042 // operation. However for setting break points which is normally done through |
| 13806 // some kind of user interaction the performance is not crucial. | 14043 // some kind of user interaction the performance is not crucial. |
| 13807 static Handle<Object> Runtime_GetScriptFromScriptName( | 14044 static Handle<Object> Runtime_GetScriptFromScriptName( |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14404 // Handle last resort GC and make sure to allow future allocations | 14641 // Handle last resort GC and make sure to allow future allocations |
| 14405 // to grow the heap without causing GCs (if possible). | 14642 // to grow the heap without causing GCs (if possible). |
| 14406 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14643 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14407 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14644 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14408 "Runtime::PerformGC"); | 14645 "Runtime::PerformGC"); |
| 14409 } | 14646 } |
| 14410 } | 14647 } |
| 14411 | 14648 |
| 14412 | 14649 |
| 14413 } } // namespace v8::internal | 14650 } } // namespace v8::internal |
| OLD | NEW |