Bug 1142820 - js/src/jsapi-tests/testPersistentRooted.cpp has leaks. r=jonco
authorJinank Jain <jinank94@gmail.com>
Thu, 14 May 2015 14:40:14 +0200
changeset 244102 25966a72111436da3857a7a6bed49c9ae83a1610
parent 244101 a1018d31e591e7f0db0ce4838039fad4250949ea
child 244103 b3902a6225c3d585976f6c3830a692155f9cce46
push id28766
push userphilringnalda@gmail.com
push dateSat, 16 May 2015 15:50:57 +0000
treeherdermozilla-central@e00b8970afbd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1142820
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1142820 - js/src/jsapi-tests/testPersistentRooted.cpp has leaks. r=jonco
js/src/jsapi-tests/testPersistentRooted.cpp
--- a/js/src/jsapi-tests/testPersistentRooted.cpp
+++ b/js/src/jsapi-tests/testPersistentRooted.cpp
@@ -1,16 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "js/Class.h"
 #include "jsapi-tests/tests.h"
 
 using namespace JS;
+using mozilla::UniquePtr;
 
 struct BarkWhenTracedClass {
     static int finalizeCount;
     static int traceCount;
 
     static const JSClass class_;
     static void finalize(JSFreeOp* fop, JSObject* obj) { finalizeCount++; }
     static void trace(JSTracer* trc, JSObject* obj) { traceCount++; }
@@ -76,23 +77,23 @@ GCFinalizesNBarkers(JSContext* cx, int n
             BarkWhenTracedClass::traceCount > preGCTrace);
 }
 
 // PersistentRooted instances protect their contents from being recycled.
 BEGIN_TEST(test_PersistentRooted)
 {
     BarkWhenTracedClass::reset();
 
-    Kennel* kennel = Allocate(cx);
-    CHECK(kennel);
+    UniquePtr<Kennel> kennel(Allocate(cx));
+    CHECK(kennel.get());
 
     // GC should be able to find our barker.
     CHECK(GCFinalizesNBarkers(cx, 0));
 
-    delete(kennel);
+    kennel = nullptr;
 
     // Now GC should not be able to find the barker.
     JS_GC(JS_GetRuntime(cx));
     CHECK(BarkWhenTracedClass::finalizeCount == 1);
 
     return true;
 }
 END_TEST(test_PersistentRooted)
@@ -112,76 +113,76 @@ BEGIN_TEST(test_PersistentRootedNull)
 }
 END_TEST(test_PersistentRootedNull)
 
 // Copy construction works.
 BEGIN_TEST(test_PersistentRootedCopy)
 {
     BarkWhenTracedClass::reset();
 
-    Kennel* kennel = Allocate(cx);
-    CHECK(kennel);
+    UniquePtr<Kennel> kennel(Allocate(cx));
+    CHECK(kennel.get());
 
     CHECK(GCFinalizesNBarkers(cx, 0));
 
     // Copy construction! AMAZING!
-    Kennel* newKennel = new Kennel(*kennel);
+    UniquePtr<Kennel> newKennel(new Kennel(*kennel));
 
     CHECK(GCFinalizesNBarkers(cx, 0));
 
-    delete(kennel);
+    kennel = nullptr;
 
     CHECK(GCFinalizesNBarkers(cx, 0));
 
-    delete(newKennel);
+    newKennel = nullptr;
 
     // Now that kennel and nowKennel are both deallocated, GC should not be
     // able to find the barker.
     JS_GC(JS_GetRuntime(cx));
     CHECK(BarkWhenTracedClass::finalizeCount == 1);
 
     return true;
 }
 END_TEST(test_PersistentRootedCopy)
 
 // Assignment works.
 BEGIN_TEST(test_PersistentRootedAssign)
 {
     BarkWhenTracedClass::reset();
 
-    Kennel* kennel = Allocate(cx);
-    CHECK(kennel);
+    UniquePtr<Kennel> kennel(Allocate(cx));
+    CHECK(kennel.get());
 
     CHECK(GCFinalizesNBarkers(cx, 0));
 
     // Allocate a new, empty kennel.
-    Kennel* kennel2 = new Kennel(cx);
+    UniquePtr<Kennel> kennel2(new Kennel(cx));
 
     // Assignment! ASTONISHING!
     *kennel2 = *kennel;
 
     // With both kennels referring to the same barker, it is held alive.
     CHECK(GCFinalizesNBarkers(cx, 0));
 
-    delete(kennel2);
+    kennel2 = nullptr;
 
     // The destination of the assignment alone holds the barker alive.
     CHECK(GCFinalizesNBarkers(cx, 0));
 
     // Allocate a second barker.
-    kennel2 = Allocate(cx);
-    CHECK(kennel);
+    kennel2 = UniquePtr<Kennel>(Allocate(cx));
+    CHECK(kennel2.get());
 
     *kennel = *kennel2;
 
     // Nothing refers to the first kennel any more.
     CHECK(GCFinalizesNBarkers(cx, 1));
 
-    delete(kennel);
-    delete(kennel2);
+    kennel = nullptr;
+    kennel2 = nullptr;
 
     // Now that kennel and kennel2 are both deallocated, GC should not be
     // able to find the barker.
     JS_GC(JS_GetRuntime(cx));
     CHECK(BarkWhenTracedClass::finalizeCount == 2);
 
     return true;
 }