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

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

Issue 3011009: Add a check that weak object handle is not in NEAR_DEATH state after weak callback invocation. (Closed)
Patch Set: Addressing Mads' comments Created 10 years, 5 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
« no previous file with comments | « src/profile-generator.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 7997 matching lines...) Expand 10 before | Expand all | Expand 10 after
8008 v8_compile("gc();")->Run(); 8008 v8_compile("gc();")->Run();
8009 } 8009 }
8010 CHECK_EQ(count, GetSurvivingGlobalObjectsCount()); 8010 CHECK_EQ(count, GetSurvivingGlobalObjectsCount());
8011 } 8011 }
8012 } 8012 }
8013 8013
8014 8014
8015 v8::Persistent<v8::Object> some_object; 8015 v8::Persistent<v8::Object> some_object;
8016 v8::Persistent<v8::Object> bad_handle; 8016 v8::Persistent<v8::Object> bad_handle;
8017 8017
8018 void NewPersistentHandleCallback(v8::Persistent<v8::Value>, void*) { 8018 void NewPersistentHandleCallback(v8::Persistent<v8::Value> handle, void*) {
8019 v8::HandleScope scope; 8019 v8::HandleScope scope;
8020 bad_handle = v8::Persistent<v8::Object>::New(some_object); 8020 bad_handle = v8::Persistent<v8::Object>::New(some_object);
8021 handle.Dispose();
8021 } 8022 }
8022 8023
8023 8024
8024 THREADED_TEST(NewPersistentHandleFromWeakCallback) { 8025 THREADED_TEST(NewPersistentHandleFromWeakCallback) {
8025 LocalContext context; 8026 LocalContext context;
8026 8027
8027 v8::Persistent<v8::Object> handle1, handle2; 8028 v8::Persistent<v8::Object> handle1, handle2;
8028 { 8029 {
8029 v8::HandleScope scope; 8030 v8::HandleScope scope;
8030 some_object = v8::Persistent<v8::Object>::New(v8::Object::New()); 8031 some_object = v8::Persistent<v8::Object>::New(v8::Object::New());
8031 handle1 = v8::Persistent<v8::Object>::New(v8::Object::New()); 8032 handle1 = v8::Persistent<v8::Object>::New(v8::Object::New());
8032 handle2 = v8::Persistent<v8::Object>::New(v8::Object::New()); 8033 handle2 = v8::Persistent<v8::Object>::New(v8::Object::New());
8033 } 8034 }
8034 // Note: order is implementation dependent alas: currently 8035 // Note: order is implementation dependent alas: currently
8035 // global handle nodes are processed by PostGarbageCollectionProcessing 8036 // global handle nodes are processed by PostGarbageCollectionProcessing
8036 // in reverse allocation order, so if second allocated handle is deleted, 8037 // in reverse allocation order, so if second allocated handle is deleted,
8037 // weak callback of the first handle would be able to 'reallocate' it. 8038 // weak callback of the first handle would be able to 'reallocate' it.
8038 handle1.MakeWeak(NULL, NewPersistentHandleCallback); 8039 handle1.MakeWeak(NULL, NewPersistentHandleCallback);
8039 handle2.Dispose(); 8040 handle2.Dispose();
8040 i::Heap::CollectAllGarbage(false); 8041 i::Heap::CollectAllGarbage(false);
8041 } 8042 }
8042 8043
8043 8044
8044 v8::Persistent<v8::Object> to_be_disposed; 8045 v8::Persistent<v8::Object> to_be_disposed;
8045 8046
8046 void DisposeAndForceGcCallback(v8::Persistent<v8::Value> handle, void*) { 8047 void DisposeAndForceGcCallback(v8::Persistent<v8::Value> handle, void*) {
8047 to_be_disposed.Dispose(); 8048 to_be_disposed.Dispose();
8048 i::Heap::CollectAllGarbage(false); 8049 i::Heap::CollectAllGarbage(false);
8050 handle.Dispose();
8049 } 8051 }
8050 8052
8051 8053
8052 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { 8054 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) {
8053 LocalContext context; 8055 LocalContext context;
8054 8056
8055 v8::Persistent<v8::Object> handle1, handle2; 8057 v8::Persistent<v8::Object> handle1, handle2;
8056 { 8058 {
8057 v8::HandleScope scope; 8059 v8::HandleScope scope;
8058 handle1 = v8::Persistent<v8::Object>::New(v8::Object::New()); 8060 handle1 = v8::Persistent<v8::Object>::New(v8::Object::New());
8059 handle2 = v8::Persistent<v8::Object>::New(v8::Object::New()); 8061 handle2 = v8::Persistent<v8::Object>::New(v8::Object::New());
8060 } 8062 }
8061 handle1.MakeWeak(NULL, DisposeAndForceGcCallback); 8063 handle1.MakeWeak(NULL, DisposeAndForceGcCallback);
8062 to_be_disposed = handle2; 8064 to_be_disposed = handle2;
8063 i::Heap::CollectAllGarbage(false); 8065 i::Heap::CollectAllGarbage(false);
8064 } 8066 }
8065 8067
8066 void DisposingCallback(v8::Persistent<v8::Value> handle, void*) { 8068 void DisposingCallback(v8::Persistent<v8::Value> handle, void*) {
8067 handle.Dispose(); 8069 handle.Dispose();
8068 } 8070 }
8069 8071
8070 void HandleCreatingCallback(v8::Persistent<v8::Value> handle, void*) { 8072 void HandleCreatingCallback(v8::Persistent<v8::Value> handle, void*) {
8071 v8::HandleScope scope; 8073 v8::HandleScope scope;
8072 v8::Persistent<v8::Object>::New(v8::Object::New()); 8074 v8::Persistent<v8::Object>::New(v8::Object::New());
8075 handle.Dispose();
8073 } 8076 }
8074 8077
8075 8078
8076 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { 8079 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) {
8077 LocalContext context; 8080 LocalContext context;
8078 8081
8079 v8::Persistent<v8::Object> handle1, handle2, handle3; 8082 v8::Persistent<v8::Object> handle1, handle2, handle3;
8080 { 8083 {
8081 v8::HandleScope scope; 8084 v8::HandleScope scope;
8082 handle3 = v8::Persistent<v8::Object>::New(v8::Object::New()); 8085 handle3 = v8::Persistent<v8::Object>::New(v8::Object::New());
(...skipping 3094 matching lines...) Expand 10 before | Expand all | Expand 10 after
11177 11180
11178 ExpectString("str2.substring(2, 10);", "elspenda"); 11181 ExpectString("str2.substring(2, 10);", "elspenda");
11179 11182
11180 ExpectString("str2.substring(2, 20);", "elspendabelabelspe"); 11183 ExpectString("str2.substring(2, 20);", "elspendabelabelspe");
11181 11184
11182 ExpectString("str2.charAt(2);", "e"); 11185 ExpectString("str2.charAt(2);", "e");
11183 11186
11184 reresult = CompileRun("str2.charCodeAt(2);"); 11187 reresult = CompileRun("str2.charCodeAt(2);");
11185 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value()); 11188 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value());
11186 } 11189 }
OLDNEW
« no previous file with comments | « src/profile-generator.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698