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 2109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2120 int* heap_allocated = new int[100]; | 2120 int* heap_allocated = new int[100]; |
2121 CheckAlignedPointerInInternalField(obj, heap_allocated); | 2121 CheckAlignedPointerInInternalField(obj, heap_allocated); |
2122 delete[] heap_allocated; | 2122 delete[] heap_allocated; |
2123 | 2123 |
2124 int stack_allocated[100]; | 2124 int stack_allocated[100]; |
2125 CheckAlignedPointerInInternalField(obj, stack_allocated); | 2125 CheckAlignedPointerInInternalField(obj, stack_allocated); |
2126 | 2126 |
2127 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); | 2127 void* huge = reinterpret_cast<void*>(~static_cast<uintptr_t>(1)); |
2128 CheckAlignedPointerInInternalField(obj, huge); | 2128 CheckAlignedPointerInInternalField(obj, huge); |
2129 | 2129 |
2130 v8::UniquePersistent<v8::Object> persistent(isolate, obj); | 2130 v8::Global<v8::Object> persistent(isolate, obj); |
2131 CHECK_EQ(1, Object::InternalFieldCount(persistent)); | 2131 CHECK_EQ(1, Object::InternalFieldCount(persistent)); |
2132 CHECK_EQ(huge, Object::GetAlignedPointerFromInternalField(persistent, 0)); | 2132 CHECK_EQ(huge, Object::GetAlignedPointerFromInternalField(persistent, 0)); |
2133 } | 2133 } |
2134 | 2134 |
2135 | 2135 |
2136 static void CheckAlignedPointerInEmbedderData(LocalContext* env, int index, | 2136 static void CheckAlignedPointerInEmbedderData(LocalContext* env, int index, |
2137 void* value) { | 2137 void* value) { |
2138 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); | 2138 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); |
2139 (*env)->SetAlignedPointerInEmbedderData(index, value); | 2139 (*env)->SetAlignedPointerInEmbedderData(index, value); |
2140 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 2140 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3031 v8::HandleScope scope(isolate); | 3031 v8::HandleScope scope(isolate); |
3032 Local<String> empty; | 3032 Local<String> empty; |
3033 global.Reset(isolate, empty); | 3033 global.Reset(isolate, empty); |
3034 } | 3034 } |
3035 CHECK(global.IsEmpty()); | 3035 CHECK(global.IsEmpty()); |
3036 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1); | 3036 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count - 1); |
3037 } | 3037 } |
3038 | 3038 |
3039 | 3039 |
3040 template <class T> | 3040 template <class T> |
3041 static v8::UniquePersistent<T> PassUnique(v8::UniquePersistent<T> unique) { | 3041 static v8::Global<T> PassUnique(v8::Global<T> unique) { |
3042 return unique.Pass(); | 3042 return unique.Pass(); |
3043 } | 3043 } |
3044 | 3044 |
3045 | 3045 |
3046 template <class T> | 3046 template <class T> |
3047 static v8::UniquePersistent<T> ReturnUnique(v8::Isolate* isolate, | 3047 static v8::Global<T> ReturnUnique(v8::Isolate* isolate, |
3048 const v8::Persistent<T>& global) { | 3048 const v8::Persistent<T>& global) { |
3049 v8::UniquePersistent<String> unique(isolate, global); | 3049 v8::Global<String> unique(isolate, global); |
3050 return unique.Pass(); | 3050 return unique.Pass(); |
3051 } | 3051 } |
3052 | 3052 |
3053 | 3053 |
3054 THREADED_TEST(UniquePersistent) { | 3054 THREADED_TEST(Global) { |
3055 v8::Isolate* isolate = CcTest::isolate(); | 3055 v8::Isolate* isolate = CcTest::isolate(); |
3056 v8::Persistent<String> global; | 3056 v8::Persistent<String> global; |
3057 { | 3057 { |
3058 v8::HandleScope scope(isolate); | 3058 v8::HandleScope scope(isolate); |
3059 global.Reset(isolate, v8_str("str")); | 3059 global.Reset(isolate, v8_str("str")); |
3060 } | 3060 } |
3061 v8::internal::GlobalHandles* global_handles = | 3061 v8::internal::GlobalHandles* global_handles = |
3062 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); | 3062 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); |
3063 int initial_handle_count = global_handles->global_handles_count(); | 3063 int initial_handle_count = global_handles->global_handles_count(); |
3064 { | 3064 { |
3065 v8::UniquePersistent<String> unique(isolate, global); | 3065 v8::Global<String> unique(isolate, global); |
3066 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); | 3066 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); |
3067 // Test assignment via Pass | 3067 // Test assignment via Pass |
3068 { | 3068 { |
3069 v8::UniquePersistent<String> copy = unique.Pass(); | 3069 v8::Global<String> copy = unique.Pass(); |
3070 CHECK(unique.IsEmpty()); | 3070 CHECK(unique.IsEmpty()); |
3071 CHECK(copy == global); | 3071 CHECK(copy == global); |
3072 CHECK_EQ(initial_handle_count + 1, | 3072 CHECK_EQ(initial_handle_count + 1, |
3073 global_handles->global_handles_count()); | 3073 global_handles->global_handles_count()); |
3074 unique = copy.Pass(); | 3074 unique = copy.Pass(); |
3075 } | 3075 } |
3076 // Test ctor via Pass | 3076 // Test ctor via Pass |
3077 { | 3077 { |
3078 v8::UniquePersistent<String> copy(unique.Pass()); | 3078 v8::Global<String> copy(unique.Pass()); |
3079 CHECK(unique.IsEmpty()); | 3079 CHECK(unique.IsEmpty()); |
3080 CHECK(copy == global); | 3080 CHECK(copy == global); |
3081 CHECK_EQ(initial_handle_count + 1, | 3081 CHECK_EQ(initial_handle_count + 1, |
3082 global_handles->global_handles_count()); | 3082 global_handles->global_handles_count()); |
3083 unique = copy.Pass(); | 3083 unique = copy.Pass(); |
3084 } | 3084 } |
3085 // Test pass through function call | 3085 // Test pass through function call |
3086 { | 3086 { |
3087 v8::UniquePersistent<String> copy = PassUnique(unique.Pass()); | 3087 v8::Global<String> copy = PassUnique(unique.Pass()); |
3088 CHECK(unique.IsEmpty()); | 3088 CHECK(unique.IsEmpty()); |
3089 CHECK(copy == global); | 3089 CHECK(copy == global); |
3090 CHECK_EQ(initial_handle_count + 1, | 3090 CHECK_EQ(initial_handle_count + 1, |
3091 global_handles->global_handles_count()); | 3091 global_handles->global_handles_count()); |
3092 unique = copy.Pass(); | 3092 unique = copy.Pass(); |
3093 } | 3093 } |
3094 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); | 3094 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); |
3095 } | 3095 } |
3096 // Test pass from function call | 3096 // Test pass from function call |
3097 { | 3097 { |
3098 v8::UniquePersistent<String> unique = ReturnUnique(isolate, global); | 3098 v8::Global<String> unique = ReturnUnique(isolate, global); |
3099 CHECK(unique == global); | 3099 CHECK(unique == global); |
3100 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); | 3100 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); |
3101 } | 3101 } |
3102 CHECK_EQ(initial_handle_count, global_handles->global_handles_count()); | 3102 CHECK_EQ(initial_handle_count, global_handles->global_handles_count()); |
3103 global.Reset(); | 3103 global.Reset(); |
3104 } | 3104 } |
3105 | 3105 |
3106 | 3106 |
3107 template <typename K, typename V> | 3107 template <typename K, typename V> |
3108 class WeakStdMapTraits : public v8::StdMapTraits<K, V> { | 3108 class WeakStdMapTraits : public v8::StdMapTraits<K, V> { |
(...skipping 13 matching lines...) Expand all Loading... |
3122 } | 3122 } |
3123 static MapType* MapFromWeakCallbackData( | 3123 static MapType* MapFromWeakCallbackData( |
3124 const v8::WeakCallbackData<V, WeakCallbackDataType>& data) { | 3124 const v8::WeakCallbackData<V, WeakCallbackDataType>& data) { |
3125 return data.GetParameter()->map; | 3125 return data.GetParameter()->map; |
3126 } | 3126 } |
3127 static K KeyFromWeakCallbackData( | 3127 static K KeyFromWeakCallbackData( |
3128 const v8::WeakCallbackData<V, WeakCallbackDataType>& data) { | 3128 const v8::WeakCallbackData<V, WeakCallbackDataType>& data) { |
3129 return data.GetParameter()->key; | 3129 return data.GetParameter()->key; |
3130 } | 3130 } |
3131 static void DisposeCallbackData(WeakCallbackDataType* data) { delete data; } | 3131 static void DisposeCallbackData(WeakCallbackDataType* data) { delete data; } |
3132 static void Dispose(v8::Isolate* isolate, v8::UniquePersistent<V> value, | 3132 static void Dispose(v8::Isolate* isolate, v8::Global<V> value, K key) {} |
3133 K key) {} | |
3134 }; | 3133 }; |
3135 | 3134 |
3136 | 3135 |
3137 template <typename Map> | 3136 template <typename Map> |
3138 static void TestPersistentValueMap() { | 3137 static void TestPersistentValueMap() { |
3139 LocalContext env; | 3138 LocalContext env; |
3140 v8::Isolate* isolate = env->GetIsolate(); | 3139 v8::Isolate* isolate = env->GetIsolate(); |
3141 Map map(isolate); | 3140 Map map(isolate); |
3142 v8::internal::GlobalHandles* global_handles = | 3141 v8::internal::GlobalHandles* global_handles = |
3143 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); | 3142 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); |
3144 int initial_handle_count = global_handles->global_handles_count(); | 3143 int initial_handle_count = global_handles->global_handles_count(); |
3145 CHECK_EQ(0, static_cast<int>(map.Size())); | 3144 CHECK_EQ(0, static_cast<int>(map.Size())); |
3146 { | 3145 { |
3147 HandleScope scope(isolate); | 3146 HandleScope scope(isolate); |
3148 Local<v8::Object> obj = map.Get(7); | 3147 Local<v8::Object> obj = map.Get(7); |
3149 CHECK(obj.IsEmpty()); | 3148 CHECK(obj.IsEmpty()); |
3150 Local<v8::Object> expected = v8::Object::New(isolate); | 3149 Local<v8::Object> expected = v8::Object::New(isolate); |
3151 map.Set(7, expected); | 3150 map.Set(7, expected); |
3152 CHECK_EQ(1, static_cast<int>(map.Size())); | 3151 CHECK_EQ(1, static_cast<int>(map.Size())); |
3153 obj = map.Get(7); | 3152 obj = map.Get(7); |
3154 CHECK(expected->Equals(obj)); | 3153 CHECK(expected->Equals(obj)); |
3155 { | 3154 { |
3156 typename Map::PersistentValueReference ref = map.GetReference(7); | 3155 typename Map::PersistentValueReference ref = map.GetReference(7); |
3157 CHECK(expected->Equals(ref.NewLocal(isolate))); | 3156 CHECK(expected->Equals(ref.NewLocal(isolate))); |
3158 } | 3157 } |
3159 v8::UniquePersistent<v8::Object> removed = map.Remove(7); | 3158 v8::Global<v8::Object> removed = map.Remove(7); |
3160 CHECK_EQ(0, static_cast<int>(map.Size())); | 3159 CHECK_EQ(0, static_cast<int>(map.Size())); |
3161 CHECK(expected == removed); | 3160 CHECK(expected == removed); |
3162 removed = map.Remove(7); | 3161 removed = map.Remove(7); |
3163 CHECK(removed.IsEmpty()); | 3162 CHECK(removed.IsEmpty()); |
3164 map.Set(8, expected); | 3163 map.Set(8, expected); |
3165 CHECK_EQ(1, static_cast<int>(map.Size())); | 3164 CHECK_EQ(1, static_cast<int>(map.Size())); |
3166 map.Set(8, expected); | 3165 map.Set(8, expected); |
3167 CHECK_EQ(1, static_cast<int>(map.Size())); | 3166 CHECK_EQ(1, static_cast<int>(map.Size())); |
3168 { | 3167 { |
3169 typename Map::PersistentValueReference ref; | 3168 typename Map::PersistentValueReference ref; |
3170 Local<v8::Object> expected2 = v8::Object::New(isolate); | 3169 Local<v8::Object> expected2 = v8::Object::New(isolate); |
3171 removed = map.Set(8, v8::UniquePersistent<v8::Object>(isolate, expected2), | 3170 removed = map.Set(8, v8::Global<v8::Object>(isolate, expected2), &ref); |
3172 &ref); | |
3173 CHECK_EQ(1, static_cast<int>(map.Size())); | 3171 CHECK_EQ(1, static_cast<int>(map.Size())); |
3174 CHECK(expected == removed); | 3172 CHECK(expected == removed); |
3175 CHECK(expected2->Equals(ref.NewLocal(isolate))); | 3173 CHECK(expected2->Equals(ref.NewLocal(isolate))); |
3176 } | 3174 } |
3177 } | 3175 } |
3178 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); | 3176 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); |
3179 if (map.IsWeak()) { | 3177 if (map.IsWeak()) { |
3180 reinterpret_cast<v8::internal::Isolate*>(isolate) | 3178 reinterpret_cast<v8::internal::Isolate*>(isolate) |
3181 ->heap() | 3179 ->heap() |
3182 ->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3180 ->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
(...skipping 22 matching lines...) Expand all Loading... |
3205 v8::Isolate* isolate = env->GetIsolate(); | 3203 v8::Isolate* isolate = env->GetIsolate(); |
3206 v8::internal::GlobalHandles* global_handles = | 3204 v8::internal::GlobalHandles* global_handles = |
3207 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); | 3205 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); |
3208 int handle_count = global_handles->global_handles_count(); | 3206 int handle_count = global_handles->global_handles_count(); |
3209 HandleScope scope(isolate); | 3207 HandleScope scope(isolate); |
3210 | 3208 |
3211 v8::PersistentValueVector<v8::Object> vector(isolate); | 3209 v8::PersistentValueVector<v8::Object> vector(isolate); |
3212 | 3210 |
3213 Local<v8::Object> obj1 = v8::Object::New(isolate); | 3211 Local<v8::Object> obj1 = v8::Object::New(isolate); |
3214 Local<v8::Object> obj2 = v8::Object::New(isolate); | 3212 Local<v8::Object> obj2 = v8::Object::New(isolate); |
3215 v8::UniquePersistent<v8::Object> obj3(isolate, v8::Object::New(isolate)); | 3213 v8::Global<v8::Object> obj3(isolate, v8::Object::New(isolate)); |
3216 | 3214 |
3217 CHECK(vector.IsEmpty()); | 3215 CHECK(vector.IsEmpty()); |
3218 CHECK_EQ(0, static_cast<int>(vector.Size())); | 3216 CHECK_EQ(0, static_cast<int>(vector.Size())); |
3219 | 3217 |
3220 vector.ReserveCapacity(3); | 3218 vector.ReserveCapacity(3); |
3221 CHECK(vector.IsEmpty()); | 3219 CHECK(vector.IsEmpty()); |
3222 | 3220 |
3223 vector.Append(obj1); | 3221 vector.Append(obj1); |
3224 vector.Append(obj2); | 3222 vector.Append(obj2); |
3225 vector.Append(obj1); | 3223 vector.Append(obj1); |
(...skipping 18357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21583 } | 21581 } |
21584 { | 21582 { |
21585 v8::TryCatch try_catch; | 21583 v8::TryCatch try_catch; |
21586 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); | 21584 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); |
21587 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, | 21585 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, |
21588 length).IsEmpty()); | 21586 length).IsEmpty()); |
21589 CHECK(try_catch.HasCaught()); | 21587 CHECK(try_catch.HasCaught()); |
21590 } | 21588 } |
21591 free(buffer); | 21589 free(buffer); |
21592 } | 21590 } |
OLD | NEW |