Bug 1288793 - Part 2: Test slice callback and message formatting; r=jonco
authorTerrence Cole <terrence@mozilla.com>
Thu, 28 Jul 2016 09:34:11 -0700
changeset 349287 2ffdc17e68e06e837dc9d8cea0741e3f6bda8631
parent 349286 c85767662b633604936c5b5e4869770423f5ec01
child 349288 0785fb4ba8cf297ece281f97e8a733ea547e3e6a
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1288793
milestone50.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 1288793 - Part 2: Test slice callback and message formatting; r=jonco
js/src/jsapi-tests/moz.build
js/src/jsapi-tests/testGCHooks.cpp
--- a/js/src/jsapi-tests/moz.build
+++ b/js/src/jsapi-tests/moz.build
@@ -39,16 +39,17 @@ UNIFIED_SOURCES += [
     'testFreshGlobalEvalRedefinition.cpp',
     'testFunctionProperties.cpp',
     'testGCAllocator.cpp',
     'testGCCellPtr.cpp',
     'testGCChunkPool.cpp',
     'testGCExactRooting.cpp',
     'testGCFinalizeCallback.cpp',
     'testGCHeapPostBarriers.cpp',
+    'testGCHooks.cpp',
     'testGCMarking.cpp',
     'testGCOutOfMemory.cpp',
     'testGCStoreBufferRemoval.cpp',
     'testGCUniqueId.cpp',
     'testGCWeakCache.cpp',
     'testGCWeakRef.cpp',
     'testGetPropertyDescriptor.cpp',
     'testHashTable.cpp',
new file mode 100644
--- /dev/null
+++ b/js/src/jsapi-tests/testGCHooks.cpp
@@ -0,0 +1,36 @@
+/* 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 "mozilla/UniquePtr.h"
+
+#include "js/GCAPI.h"
+
+#include "jsapi-tests/tests.h"
+
+static unsigned gSliceCallbackCount = 0;
+
+static void
+NonIncrementalGCSliceCallback(JSContext* cx, JS::GCProgress progress, const JS::GCDescription& desc)
+{
+    ++gSliceCallbackCount;
+    MOZ_RELEASE_ASSERT(progress == JS::GC_CYCLE_BEGIN || progress == JS::GC_CYCLE_END);
+    MOZ_RELEASE_ASSERT(desc.isCompartment_ == false);
+    MOZ_RELEASE_ASSERT(desc.invocationKind_ == GC_NORMAL);
+    MOZ_RELEASE_ASSERT(desc.reason_ == JS::gcreason::API);
+    if (progress == JS::GC_CYCLE_END) {
+        mozilla::UniquePtr<char16_t> summary(desc.formatSummaryMessage(cx));
+        mozilla::UniquePtr<char16_t> message(desc.formatSliceMessage(cx));
+        mozilla::UniquePtr<char16_t> json(desc.formatJSON(cx, 0));
+    }
+}
+
+BEGIN_TEST(testGCSliceCallback)
+{
+    JS::SetGCSliceCallback(cx, NonIncrementalGCSliceCallback);
+    JS_GC(cx);
+    JS::SetGCSliceCallback(cx, nullptr);
+    CHECK(gSliceCallbackCount == 2);
+    return true;
+}
+END_TEST(testGCSliceCallback)