OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 2776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2787 return Utils::ToLocal(result); | 2787 return Utils::ToLocal(result); |
2788 } | 2788 } |
2789 | 2789 |
2790 | 2790 |
2791 Local<Value> v8::Object::Get(uint32_t index) { | 2791 Local<Value> v8::Object::Get(uint32_t index) { |
2792 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2792 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
2793 ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); | 2793 ON_BAILOUT(isolate, "v8::Object::Get()", return Local<v8::Value>()); |
2794 ENTER_V8(isolate); | 2794 ENTER_V8(isolate); |
2795 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 2795 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
2796 EXCEPTION_PREAMBLE(isolate); | 2796 EXCEPTION_PREAMBLE(isolate); |
2797 i::Handle<i::Object> result = i::GetElement(self, index); | 2797 i::Handle<i::Object> result = i::Object::GetElement(self, index); |
2798 has_pending_exception = result.is_null(); | 2798 has_pending_exception = result.is_null(); |
2799 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); | 2799 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
2800 return Utils::ToLocal(result); | 2800 return Utils::ToLocal(result); |
2801 } | 2801 } |
2802 | 2802 |
2803 | 2803 |
2804 PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) { | 2804 PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) { |
2805 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2805 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
2806 ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()", | 2806 ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()", |
2807 return static_cast<PropertyAttribute>(NONE)); | 2807 return static_cast<PropertyAttribute>(NONE)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2867 } | 2867 } |
2868 | 2868 |
2869 | 2869 |
2870 Local<Array> v8::Object::GetPropertyNames() { | 2870 Local<Array> v8::Object::GetPropertyNames() { |
2871 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2871 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
2872 ON_BAILOUT(isolate, "v8::Object::GetPropertyNames()", | 2872 ON_BAILOUT(isolate, "v8::Object::GetPropertyNames()", |
2873 return Local<v8::Array>()); | 2873 return Local<v8::Array>()); |
2874 ENTER_V8(isolate); | 2874 ENTER_V8(isolate); |
2875 i::HandleScope scope(isolate); | 2875 i::HandleScope scope(isolate); |
2876 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 2876 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2877 bool threw = false; |
2877 i::Handle<i::FixedArray> value = | 2878 i::Handle<i::FixedArray> value = |
2878 i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS); | 2879 i::GetKeysInFixedArrayFor(self, i::INCLUDE_PROTOS, &threw); |
| 2880 if (threw) return Local<v8::Array>(); |
2879 // Because we use caching to speed up enumeration it is important | 2881 // Because we use caching to speed up enumeration it is important |
2880 // to never change the result of the basic enumeration function so | 2882 // to never change the result of the basic enumeration function so |
2881 // we clone the result. | 2883 // we clone the result. |
2882 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); | 2884 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
2883 i::Handle<i::JSArray> result = | 2885 i::Handle<i::JSArray> result = |
2884 isolate->factory()->NewJSArrayWithElements(elms); | 2886 isolate->factory()->NewJSArrayWithElements(elms); |
2885 return Utils::ToLocal(scope.CloseAndEscape(result)); | 2887 return Utils::ToLocal(scope.CloseAndEscape(result)); |
2886 } | 2888 } |
2887 | 2889 |
2888 | 2890 |
2889 Local<Array> v8::Object::GetOwnPropertyNames() { | 2891 Local<Array> v8::Object::GetOwnPropertyNames() { |
2890 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2892 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
2891 ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyNames()", | 2893 ON_BAILOUT(isolate, "v8::Object::GetOwnPropertyNames()", |
2892 return Local<v8::Array>()); | 2894 return Local<v8::Array>()); |
2893 ENTER_V8(isolate); | 2895 ENTER_V8(isolate); |
2894 i::HandleScope scope(isolate); | 2896 i::HandleScope scope(isolate); |
2895 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 2897 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
| 2898 bool threw = false; |
2896 i::Handle<i::FixedArray> value = | 2899 i::Handle<i::FixedArray> value = |
2897 i::GetKeysInFixedArrayFor(self, i::LOCAL_ONLY); | 2900 i::GetKeysInFixedArrayFor(self, i::LOCAL_ONLY, &threw); |
| 2901 if (threw) return Local<v8::Array>(); |
2898 // Because we use caching to speed up enumeration it is important | 2902 // Because we use caching to speed up enumeration it is important |
2899 // to never change the result of the basic enumeration function so | 2903 // to never change the result of the basic enumeration function so |
2900 // we clone the result. | 2904 // we clone the result. |
2901 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); | 2905 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); |
2902 i::Handle<i::JSArray> result = | 2906 i::Handle<i::JSArray> result = |
2903 isolate->factory()->NewJSArrayWithElements(elms); | 2907 isolate->factory()->NewJSArrayWithElements(elms); |
2904 return Utils::ToLocal(scope.CloseAndEscape(result)); | 2908 return Utils::ToLocal(scope.CloseAndEscape(result)); |
2905 } | 2909 } |
2906 | 2910 |
2907 | 2911 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3086 i::Handle<i::String> name, | 3090 i::Handle<i::String> name, |
3087 i::LookupResult* lookup) { | 3091 i::LookupResult* lookup) { |
3088 if (!lookup->IsProperty()) { | 3092 if (!lookup->IsProperty()) { |
3089 // No real property was found. | 3093 // No real property was found. |
3090 return Local<Value>(); | 3094 return Local<Value>(); |
3091 } | 3095 } |
3092 | 3096 |
3093 // If the property being looked up is a callback, it can throw | 3097 // If the property being looked up is a callback, it can throw |
3094 // an exception. | 3098 // an exception. |
3095 EXCEPTION_PREAMBLE(isolate); | 3099 EXCEPTION_PREAMBLE(isolate); |
3096 i::Handle<i::Object> result = i::GetProperty(receiver, name, lookup); | 3100 PropertyAttributes ignored; |
| 3101 i::Handle<i::Object> result = |
| 3102 i::Object::GetProperty(receiver, receiver, lookup, name, |
| 3103 &ignored); |
3097 has_pending_exception = result.is_null(); | 3104 has_pending_exception = result.is_null(); |
3098 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); | 3105 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); |
3099 | 3106 |
3100 return Utils::ToLocal(result); | 3107 return Utils::ToLocal(result); |
3101 } | 3108 } |
3102 | 3109 |
3103 | 3110 |
3104 Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain( | 3111 Local<Value> v8::Object::GetRealNamedPropertyInPrototypeChain( |
3105 Handle<String> key) { | 3112 Handle<String> key) { |
3106 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3113 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
3107 ON_BAILOUT(isolate, | 3114 ON_BAILOUT(isolate, |
3108 "v8::Object::GetRealNamedPropertyInPrototypeChain()", | 3115 "v8::Object::GetRealNamedPropertyInPrototypeChain()", |
3109 return Local<Value>()); | 3116 return Local<Value>()); |
3110 ENTER_V8(isolate); | 3117 ENTER_V8(isolate); |
3111 i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); | 3118 i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
3112 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); | 3119 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
3113 i::LookupResult lookup; | 3120 i::LookupResult lookup(isolate); |
3114 self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup); | 3121 self_obj->LookupRealNamedPropertyInPrototypes(*key_obj, &lookup); |
3115 return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); | 3122 return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
3116 } | 3123 } |
3117 | 3124 |
3118 | 3125 |
3119 Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) { | 3126 Local<Value> v8::Object::GetRealNamedProperty(Handle<String> key) { |
3120 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3127 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
3121 ON_BAILOUT(isolate, "v8::Object::GetRealNamedProperty()", | 3128 ON_BAILOUT(isolate, "v8::Object::GetRealNamedProperty()", |
3122 return Local<Value>()); | 3129 return Local<Value>()); |
3123 ENTER_V8(isolate); | 3130 ENTER_V8(isolate); |
3124 i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); | 3131 i::Handle<i::JSObject> self_obj = Utils::OpenHandle(this); |
3125 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); | 3132 i::Handle<i::String> key_obj = Utils::OpenHandle(*key); |
3126 i::LookupResult lookup; | 3133 i::LookupResult lookup(isolate); |
3127 self_obj->LookupRealNamedProperty(*key_obj, &lookup); | 3134 self_obj->LookupRealNamedProperty(*key_obj, &lookup); |
3128 return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); | 3135 return GetPropertyByLookup(isolate, self_obj, key_obj, &lookup); |
3129 } | 3136 } |
3130 | 3137 |
3131 | 3138 |
3132 // Turns on access checks by copying the map and setting the check flag. | 3139 // Turns on access checks by copying the map and setting the check flag. |
3133 // Because the object gets a new map, existing inline cache caching | 3140 // Because the object gets a new map, existing inline cache caching |
3134 // the old map of this object will fail. | 3141 // the old map of this object will fail. |
3135 void v8::Object::TurnOnAccessCheck() { | 3142 void v8::Object::TurnOnAccessCheck() { |
3136 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3143 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3627 | 3634 |
3628 | 3635 |
3629 int String::WriteUtf8(char* buffer, | 3636 int String::WriteUtf8(char* buffer, |
3630 int capacity, | 3637 int capacity, |
3631 int* nchars_ref, | 3638 int* nchars_ref, |
3632 int options) const { | 3639 int options) const { |
3633 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3640 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
3634 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; | 3641 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; |
3635 LOG_API(isolate, "String::WriteUtf8"); | 3642 LOG_API(isolate, "String::WriteUtf8"); |
3636 ENTER_V8(isolate); | 3643 ENTER_V8(isolate); |
| 3644 i::Handle<i::String> str = Utils::OpenHandle(this); |
| 3645 if (str->IsAsciiRepresentation()) { |
| 3646 int len; |
| 3647 if (capacity == -1) { |
| 3648 capacity = str->length() + 1; |
| 3649 len = str->length(); |
| 3650 } else { |
| 3651 len = i::Min(capacity, str->length()); |
| 3652 } |
| 3653 i::String::WriteToFlat(*str, buffer, 0, len); |
| 3654 if (nchars_ref != NULL) *nchars_ref = len; |
| 3655 if (!(options & NO_NULL_TERMINATION) && capacity > len) { |
| 3656 buffer[len] = '\0'; |
| 3657 return len + 1; |
| 3658 } |
| 3659 return len; |
| 3660 } |
| 3661 |
3637 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); | 3662 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); |
3638 i::Handle<i::String> str = Utils::OpenHandle(this); | |
3639 isolate->string_tracker()->RecordWrite(str); | 3663 isolate->string_tracker()->RecordWrite(str); |
3640 if (options & HINT_MANY_WRITES_EXPECTED) { | 3664 if (options & HINT_MANY_WRITES_EXPECTED) { |
3641 // Flatten the string for efficiency. This applies whether we are | 3665 // Flatten the string for efficiency. This applies whether we are |
3642 // using StringInputBuffer or Get(i) to access the characters. | 3666 // using StringInputBuffer or Get(i) to access the characters. |
3643 str->TryFlatten(); | 3667 FlattenString(str); |
3644 } | 3668 } |
3645 write_input_buffer.Reset(0, *str); | 3669 write_input_buffer.Reset(0, *str); |
3646 int len = str->length(); | 3670 int len = str->length(); |
3647 // Encode the first K - 3 bytes directly into the buffer since we | 3671 // Encode the first K - 3 bytes directly into the buffer since we |
3648 // know there's room for them. If no capacity is given we copy all | 3672 // know there's room for them. If no capacity is given we copy all |
3649 // of them here. | 3673 // of them here. |
3650 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); | 3674 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); |
3651 int i; | 3675 int i; |
3652 int pos = 0; | 3676 int pos = 0; |
3653 int nchars = 0; | 3677 int nchars = 0; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3954 } | 3978 } |
3955 | 3979 |
3956 | 3980 |
3957 HeapStatistics::HeapStatistics(): total_heap_size_(0), | 3981 HeapStatistics::HeapStatistics(): total_heap_size_(0), |
3958 total_heap_size_executable_(0), | 3982 total_heap_size_executable_(0), |
3959 used_heap_size_(0), | 3983 used_heap_size_(0), |
3960 heap_size_limit_(0) { } | 3984 heap_size_limit_(0) { } |
3961 | 3985 |
3962 | 3986 |
3963 void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) { | 3987 void v8::V8::GetHeapStatistics(HeapStatistics* heap_statistics) { |
| 3988 if (!i::Isolate::Current()->IsInitialized()) { |
| 3989 // Isolate is unitialized thus heap is not configured yet. |
| 3990 heap_statistics->set_total_heap_size(0); |
| 3991 heap_statistics->set_total_heap_size_executable(0); |
| 3992 heap_statistics->set_used_heap_size(0); |
| 3993 heap_statistics->set_heap_size_limit(0); |
| 3994 return; |
| 3995 } |
| 3996 |
3964 i::Heap* heap = i::Isolate::Current()->heap(); | 3997 i::Heap* heap = i::Isolate::Current()->heap(); |
3965 heap_statistics->set_total_heap_size(heap->CommittedMemory()); | 3998 heap_statistics->set_total_heap_size(heap->CommittedMemory()); |
3966 heap_statistics->set_total_heap_size_executable( | 3999 heap_statistics->set_total_heap_size_executable( |
3967 heap->CommittedMemoryExecutable()); | 4000 heap->CommittedMemoryExecutable()); |
3968 heap_statistics->set_used_heap_size(heap->SizeOfObjects()); | 4001 heap_statistics->set_used_heap_size(heap->SizeOfObjects()); |
3969 heap_statistics->set_heap_size_limit(heap->MaxReserved()); | 4002 heap_statistics->set_heap_size_limit(heap->MaxReserved()); |
3970 } | 4003 } |
3971 | 4004 |
3972 | 4005 |
3973 bool v8::V8::IdleNotification() { | 4006 bool v8::V8::IdleNotification() { |
3974 // Returning true tells the caller that it need not | 4007 // Returning true tells the caller that it need not |
3975 // continue to call IdleNotification. | 4008 // continue to call IdleNotification. |
3976 if (!i::Isolate::Current()->IsInitialized()) return true; | 4009 i::Isolate* isolate = i::Isolate::Current(); |
| 4010 if (isolate == NULL || !isolate->IsInitialized()) return true; |
3977 return i::V8::IdleNotification(); | 4011 return i::V8::IdleNotification(); |
3978 } | 4012 } |
3979 | 4013 |
3980 | 4014 |
3981 void v8::V8::LowMemoryNotification() { | 4015 void v8::V8::LowMemoryNotification() { |
3982 i::Isolate* isolate = i::Isolate::Current(); | 4016 i::Isolate* isolate = i::Isolate::Current(); |
3983 if (!isolate->IsInitialized()) return; | 4017 if (isolate == NULL || !isolate->IsInitialized()) return; |
3984 isolate->heap()->CollectAllAvailableGarbage(); | 4018 isolate->heap()->CollectAllAvailableGarbage(); |
3985 } | 4019 } |
3986 | 4020 |
3987 | 4021 |
3988 int v8::V8::ContextDisposedNotification() { | 4022 int v8::V8::ContextDisposedNotification() { |
3989 i::Isolate* isolate = i::Isolate::Current(); | 4023 i::Isolate* isolate = i::Isolate::Current(); |
3990 if (!isolate->IsInitialized()) return 0; | 4024 if (!isolate->IsInitialized()) return 0; |
3991 return isolate->heap()->NotifyContextDisposed(); | 4025 return isolate->heap()->NotifyContextDisposed(); |
3992 } | 4026 } |
3993 | 4027 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4068 ASSERT(!proxy_constructor.is_null()); | 4102 ASSERT(!proxy_constructor.is_null()); |
4069 global_constructor->set_access_check_info( | 4103 global_constructor->set_access_check_info( |
4070 proxy_constructor->access_check_info()); | 4104 proxy_constructor->access_check_info()); |
4071 global_constructor->set_needs_access_check( | 4105 global_constructor->set_needs_access_check( |
4072 proxy_constructor->needs_access_check()); | 4106 proxy_constructor->needs_access_check()); |
4073 } | 4107 } |
4074 isolate->runtime_profiler()->Reset(); | 4108 isolate->runtime_profiler()->Reset(); |
4075 } | 4109 } |
4076 // Leave V8. | 4110 // Leave V8. |
4077 | 4111 |
4078 if (env.is_null()) | 4112 if (env.is_null()) { |
4079 return Persistent<Context>(); | 4113 return Persistent<Context>(); |
| 4114 } |
4080 return Persistent<Context>(Utils::ToLocal(env)); | 4115 return Persistent<Context>(Utils::ToLocal(env)); |
4081 } | 4116 } |
4082 | 4117 |
4083 | 4118 |
4084 void v8::Context::SetSecurityToken(Handle<Value> token) { | 4119 void v8::Context::SetSecurityToken(Handle<Value> token) { |
4085 i::Isolate* isolate = i::Isolate::Current(); | 4120 i::Isolate* isolate = i::Isolate::Current(); |
4086 if (IsDeadCheck(isolate, "v8::Context::SetSecurityToken()")) { | 4121 if (IsDeadCheck(isolate, "v8::Context::SetSecurityToken()")) { |
4087 return; | 4122 return; |
4088 } | 4123 } |
4089 ENTER_V8(isolate); | 4124 ENTER_V8(isolate); |
(...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6065 | 6100 |
6066 | 6101 |
6067 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 6102 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
6068 HandleScopeImplementer* scope_implementer = | 6103 HandleScopeImplementer* scope_implementer = |
6069 reinterpret_cast<HandleScopeImplementer*>(storage); | 6104 reinterpret_cast<HandleScopeImplementer*>(storage); |
6070 scope_implementer->IterateThis(v); | 6105 scope_implementer->IterateThis(v); |
6071 return storage + ArchiveSpacePerThread(); | 6106 return storage + ArchiveSpacePerThread(); |
6072 } | 6107 } |
6073 | 6108 |
6074 } } // namespace v8::internal | 6109 } } // namespace v8::internal |
OLD | NEW |