| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
| 7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 #include "include/dart_tools_api.h" | 9 #include "include/dart_tools_api.h" |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 3149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3160 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); | 3160 EXPECT(!Dart_IsNull(AsHandle(strong_weak))); |
| 3161 EXPECT(weak1 == NULL); | 3161 EXPECT(weak1 == NULL); |
| 3162 EXPECT(weak2 == NULL); | 3162 EXPECT(weak2 == NULL); |
| 3163 EXPECT(weak3 == NULL); | 3163 EXPECT(weak3 == NULL); |
| 3164 EXPECT(weak4 == NULL); | 3164 EXPECT(weak4 == NULL); |
| 3165 Dart_ExitScope(); | 3165 Dart_ExitScope(); |
| 3166 } | 3166 } |
| 3167 } | 3167 } |
| 3168 | 3168 |
| 3169 | 3169 |
| 3170 TEST_CASE(DuplicateWeakReferenceSetEntries) { |
| 3171 Isolate* isolate = Isolate::Current(); |
| 3172 Dart_PersistentHandle strong = NULL; |
| 3173 Dart_WeakPersistentHandle weak = NULL; // A weak handle to strong. |
| 3174 |
| 3175 Dart_EnterScope(); |
| 3176 { |
| 3177 DARTSCOPE(isolate); |
| 3178 |
| 3179 // Strong handle to keep the reference set alive. |
| 3180 Dart_Handle local = Api::NewHandle(isolate, String::New("string")); |
| 3181 strong = Dart_NewPersistentHandle(local); |
| 3182 EXPECT_VALID(AsHandle(strong)); |
| 3183 EXPECT(!Dart_IsNull(AsHandle(strong))); |
| 3184 // Corresponding weak handle to use as key and duplicated value. |
| 3185 weak = Dart_NewWeakPersistentHandle(local, NULL, 0, NopCallback); |
| 3186 EXPECT_VALID(AsHandle(weak)); |
| 3187 EXPECT(!Dart_IsNull(AsHandle(weak))); |
| 3188 } |
| 3189 Dart_ExitScope(); |
| 3190 |
| 3191 { |
| 3192 Dart_EnterScope(); |
| 3193 // Create the weak reference set. |
| 3194 Dart_WeakReferenceSetBuilder builder = Dart_NewWeakReferenceSetBuilder(); |
| 3195 EXPECT_NOTNULL(builder); |
| 3196 // Register the key and the first copy of the value. |
| 3197 Dart_WeakReferenceSet set = Dart_NewWeakReferenceSet(builder, weak, weak); |
| 3198 EXPECT_NOTNULL(set); |
| 3199 // Add the second copy of the value. |
| 3200 Dart_Handle result = Dart_AppendValueToWeakReferenceSet(set, weak); |
| 3201 EXPECT_VALID(result); |
| 3202 |
| 3203 // Trigger GC to ensure that we can visit duplicate entries in weak |
| 3204 // reference sets. |
| 3205 isolate->heap()->CollectGarbage(Heap::kNew); |
| 3206 Dart_ExitScope(); |
| 3207 } |
| 3208 } |
| 3209 |
| 3210 |
| 3170 static Dart_WeakPersistentHandle old_pwph = NULL; | 3211 static Dart_WeakPersistentHandle old_pwph = NULL; |
| 3171 static Dart_WeakPersistentHandle new_pwph = NULL; | 3212 static Dart_WeakPersistentHandle new_pwph = NULL; |
| 3172 | 3213 |
| 3173 | 3214 |
| 3174 static void PrologueWeakHandleCallback(void* isolate_callback_data, | 3215 static void PrologueWeakHandleCallback(void* isolate_callback_data, |
| 3175 Dart_WeakPersistentHandle handle, | 3216 Dart_WeakPersistentHandle handle, |
| 3176 void* peer) { | 3217 void* peer) { |
| 3177 if (handle == old_pwph) { | 3218 if (handle == old_pwph) { |
| 3178 old_pwph = NULL; | 3219 old_pwph = NULL; |
| 3179 } else if (handle == new_pwph) { | 3220 } else if (handle == new_pwph) { |
| (...skipping 6190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9370 // Heartbeat test. | 9411 // Heartbeat test. |
| 9371 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9412 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9372 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9413 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9373 EXPECT_SUBSTRING("\"function\":\"main\"", buffer); | 9414 EXPECT_SUBSTRING("\"function\":\"main\"", buffer); |
| 9374 | 9415 |
| 9375 // Free buffer allocated by AppendStreamConsumer | 9416 // Free buffer allocated by AppendStreamConsumer |
| 9376 free(data.buffer); | 9417 free(data.buffer); |
| 9377 } | 9418 } |
| 9378 | 9419 |
| 9379 } // namespace dart | 9420 } // namespace dart |
| OLD | NEW |