Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: test/cctest/test-api.cc

Issue 212893007: Amend PersistentValueMap. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Re-upload after rebase. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« include/v8-util.h ('K') | « include/v8-util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3480 matching lines...) Expand 10 before | Expand all | Expand 10 after
3491 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); 3491 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count());
3492 } 3492 }
3493 CHECK_EQ(initial_handle_count, global_handles->global_handles_count()); 3493 CHECK_EQ(initial_handle_count, global_handles->global_handles_count());
3494 global.Reset(); 3494 global.Reset();
3495 } 3495 }
3496 3496
3497 3497
3498 template<typename K, typename V> 3498 template<typename K, typename V>
3499 class WeakStdMapTraits : public v8::StdMapTraits<K, V> { 3499 class WeakStdMapTraits : public v8::StdMapTraits<K, V> {
3500 public: 3500 public:
3501 typedef typename v8::DefaultPersistentValueMapTraits<K, V>::Impl Impl; 3501 typedef typename v8::PersistentValueMap<K, V, WeakStdMapTraits<K, V> >
3502 MapType;
3502 static const bool kIsWeak = true; 3503 static const bool kIsWeak = true;
3503 struct WeakCallbackDataType { 3504 struct WeakCallbackDataType {
3504 Impl* impl; 3505 MapType* map;
3505 K key; 3506 K key;
3506 }; 3507 };
3507 static WeakCallbackDataType* WeakCallbackParameter( 3508 static WeakCallbackDataType* WeakCallbackParameter(
3508 Impl* impl, const K& key, Local<V> value) { 3509 MapType* map, const K& key, Local<V> value) {
3509 WeakCallbackDataType* data = new WeakCallbackDataType; 3510 WeakCallbackDataType* data = new WeakCallbackDataType;
3510 data->impl = impl; 3511 data->map = map;
3511 data->key = key; 3512 data->key = key;
3512 return data; 3513 return data;
3513 } 3514 }
3514 static Impl* ImplFromWeakCallbackData( 3515 static MapType* MapFromWeakCallbackData(
3515 const v8::WeakCallbackData<V, WeakCallbackDataType>& data) { 3516 const v8::WeakCallbackData<V, WeakCallbackDataType>& data) {
3516 return data.GetParameter()->impl; 3517 return data.GetParameter()->map;
3517 } 3518 }
3518 static K KeyFromWeakCallbackData( 3519 static K KeyFromWeakCallbackData(
3519 const v8::WeakCallbackData<V, WeakCallbackDataType>& data) { 3520 const v8::WeakCallbackData<V, WeakCallbackDataType>& data) {
3520 return data.GetParameter()->key; 3521 return data.GetParameter()->key;
3521 } 3522 }
3522 static void DisposeCallbackData(WeakCallbackDataType* data) { 3523 static void DisposeCallbackData(WeakCallbackDataType* data) {
3523 delete data; 3524 delete data;
3524 } 3525 }
3525 static void Dispose(v8::Isolate* isolate, v8::UniquePersistent<V> value, 3526 static void Dispose(v8::Isolate* isolate, v8::UniquePersistent<V> value,
3526 Impl* impl, K key) { } 3527 K key) { }
3527 }; 3528 };
3528 3529
3529 3530
3530 template<typename Map> 3531 template<typename Map>
3531 static void TestPersistentValueMap() { 3532 static void TestPersistentValueMap() {
3532 LocalContext env; 3533 LocalContext env;
3533 v8::Isolate* isolate = env->GetIsolate(); 3534 v8::Isolate* isolate = env->GetIsolate();
3534 Map map(isolate); 3535 Map map(isolate);
3535 v8::internal::GlobalHandles* global_handles = 3536 v8::internal::GlobalHandles* global_handles =
3536 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles(); 3537 reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
(...skipping 28 matching lines...) Expand all
3565 CHECK_EQ(0, static_cast<int>(map.Size())); 3566 CHECK_EQ(0, static_cast<int>(map.Size()));
3566 CHECK_EQ(initial_handle_count, global_handles->global_handles_count()); 3567 CHECK_EQ(initial_handle_count, global_handles->global_handles_count());
3567 } 3568 }
3568 3569
3569 3570
3570 TEST(PersistentValueMap) { 3571 TEST(PersistentValueMap) {
3571 // Default case, w/o weak callbacks: 3572 // Default case, w/o weak callbacks:
3572 TestPersistentValueMap<v8::StdPersistentValueMap<int, v8::Object> >(); 3573 TestPersistentValueMap<v8::StdPersistentValueMap<int, v8::Object> >();
3573 3574
3574 // Custom traits with weak callbacks: 3575 // Custom traits with weak callbacks:
3575 typedef v8::StdPersistentValueMap<int, v8::Object, 3576 typedef v8::PersistentValueMap<int, v8::Object,
3576 WeakStdMapTraits<int, v8::Object> > WeakPersistentValueMap; 3577 WeakStdMapTraits<int, v8::Object> > WeakPersistentValueMap;
3577 TestPersistentValueMap<WeakPersistentValueMap>(); 3578 TestPersistentValueMap<WeakPersistentValueMap>();
3578 } 3579 }
3579 3580
3580 3581
3581 THREADED_TEST(GlobalHandleUpcast) { 3582 THREADED_TEST(GlobalHandleUpcast) {
3582 v8::Isolate* isolate = CcTest::isolate(); 3583 v8::Isolate* isolate = CcTest::isolate();
3583 v8::HandleScope scope(isolate); 3584 v8::HandleScope scope(isolate);
3584 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str")); 3585 v8::Local<String> local = v8::Local<String>::New(isolate, v8_str("str"));
3585 v8::Persistent<String> global_string(isolate, local); 3586 v8::Persistent<String> global_string(isolate, local);
(...skipping 18772 matching lines...) Expand 10 before | Expand all | Expand 10 after
22358 "f.call(friend);"); 22359 "f.call(friend);");
22359 CHECK_EQ(2, named_access_count); 22360 CHECK_EQ(2, named_access_count);
22360 22361
22361 // Test access using Object.setPrototypeOf reflective method. 22362 // Test access using Object.setPrototypeOf reflective method.
22362 named_access_count = 0; 22363 named_access_count = 0;
22363 CompileRun("Object.setPrototypeOf(friend, {});"); 22364 CompileRun("Object.setPrototypeOf(friend, {});");
22364 CHECK_EQ(1, named_access_count); 22365 CHECK_EQ(1, named_access_count);
22365 CompileRun("Object.getPrototypeOf(friend);"); 22366 CompileRun("Object.getPrototypeOf(friend);");
22366 CHECK_EQ(2, named_access_count); 22367 CHECK_EQ(2, named_access_count);
22367 } 22368 }
OLDNEW
« include/v8-util.h ('K') | « include/v8-util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698