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

Unified Diff: test/cctest/test-api.cc

Issue 1104463002: add StdGlobalValueMap (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8-util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 00c262ad9c34b220414fc2bd1be1be32822f7bdf..d90c824273baabd7d8dad2c3bef2fcf443e39684 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -3361,12 +3361,9 @@ class PhantomStdMapTraits : public v8::StdMapTraits<K, V> {
}
};
-} // namespace
-
-TEST(GlobalValueMap) {
- typedef v8::GlobalValueMap<int, v8::Object,
- PhantomStdMapTraits<int, v8::Object>> Map;
+template <typename Map>
+void TestGlobalValueMap() {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::Global<ObjectTemplate> templ;
@@ -3391,7 +3388,7 @@ TEST(GlobalValueMap) {
obj = map.Get(7);
CHECK(expected->Equals(obj));
{
- Map::PersistentValueReference ref = map.GetReference(7);
+ typename Map::PersistentValueReference ref = map.GetReference(7);
CHECK(expected->Equals(ref.NewLocal(isolate)));
}
v8::Global<v8::Object> removed = map.Remove(7);
@@ -3404,7 +3401,7 @@ TEST(GlobalValueMap) {
map.Set(8, expected);
CHECK_EQ(1, static_cast<int>(map.Size()));
{
- Map::PersistentValueReference ref;
+ typename Map::PersistentValueReference ref;
Local<v8::Object> expected2 = NewObjectForIntKey(isolate, templ, 8);
removed = map.Set(8, v8::Global<v8::Object>(isolate, expected2), &ref);
CHECK_EQ(1, static_cast<int>(map.Size()));
@@ -3413,8 +3410,12 @@ TEST(GlobalValueMap) {
}
}
CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count());
- CcTest::i_isolate()->heap()->CollectAllGarbage(
- i::Heap::kAbortIncrementalMarkingMask);
+ if (map.IsWeak()) {
+ CcTest::i_isolate()->heap()->CollectAllGarbage(
+ i::Heap::kAbortIncrementalMarkingMask);
+ } else {
+ map.Clear();
+ }
CHECK_EQ(0, static_cast<int>(map.Size()));
CHECK_EQ(initial_handle_count, global_handles->global_handles_count());
{
@@ -3427,6 +3428,19 @@ TEST(GlobalValueMap) {
CHECK_EQ(initial_handle_count, global_handles->global_handles_count());
}
+} // namespace
+
+
+TEST(GlobalValueMap) {
+ // Default case, w/o weak callbacks:
+ TestGlobalValueMap<v8::StdGlobalValueMap<int, v8::Object>>();
+
+ // Custom traits with weak callbacks:
+ typedef v8::GlobalValueMap<int, v8::Object,
+ PhantomStdMapTraits<int, v8::Object>> WeakMap;
+ TestGlobalValueMap<WeakMap>();
+}
+
TEST(PersistentValueVector) {
LocalContext env;
« no previous file with comments | « include/v8-util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698