Bug 1521223, part 1 - Add an API to deliberately leak an object. r=froydnj
authorAndrew McCreight <continuation@gmail.com>
Wed, 23 Jan 2019 17:03:12 +0000
changeset 515133 7955097a8041bb803edeade4af995c9b5393c791
parent 515120 031aee32565cbe411a7153eaf483dd6d3f8c2bbf
child 515134 0b9c766c352f08a251449e8ab8a20e4cbf1c1d96
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1521223
milestone66.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 1521223, part 1 - Add an API to deliberately leak an object. r=froydnj This is needed to test various leak checking harnesses. Differential Revision: https://phabricator.services.mozilla.com/D17310
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -318,16 +318,22 @@ interface nsIXPCComponents_Utils : nsISu
     void schedulePreciseShrinkingGC(in ScheduledGCCallback callback);
 
     /*
      * In a debug build, unlink any ghost windows. This is only for debugging
      * leaks, and can cause bad things to happen if called.
      */
     void unlinkGhostWindows();
 
+    /*
+     * In an NS_FREE_PERMANENT_DATA build, intentionally leak a C++ object. This
+     * is needed to test leak checking.
+     */
+    void intentionallyLeak();
+
     [implicit_jscontext]
     jsval getJSTestingFunctions();
 
     /*
      * To be called from JS only.
      *
      * Call 'function', using the provided stack as the async stack responsible
      * for the call, and propagate its return value or the exception it throws.
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -1733,16 +1733,34 @@ nsXPCComponents_Utils::UnlinkGhostWindow
   }
 
   return NS_OK;
 #else
   return NS_ERROR_NOT_IMPLEMENTED;
 #endif
 }
 
+#ifdef NS_FREE_PERMANENT_DATA
+struct IntentionallyLeakedObject {
+  IntentionallyLeakedObject() { MOZ_COUNT_CTOR(IntentionallyLeakedObject); }
+
+  ~IntentionallyLeakedObject() { MOZ_COUNT_DTOR(IntentionallyLeakedObject); }
+};
+#endif
+
+NS_IMETHODIMP
+nsXPCComponents_Utils::IntentionallyLeak() {
+#ifdef NS_FREE_PERMANENT_DATA
+  Unused << new IntentionallyLeakedObject();
+  return NS_OK;
+#else
+  return NS_ERROR_NOT_IMPLEMENTED;
+#endif
+}
+
 NS_IMETHODIMP
 nsXPCComponents_Utils::GetJSTestingFunctions(JSContext* cx,
                                              MutableHandleValue retval) {
   JSObject* obj = js::GetTestingFunctions(cx);
   if (!obj) {
     return NS_ERROR_XPC_JAVASCRIPT_ERROR;
   }
   retval.setObject(*obj);