代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/firefox 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# HG changeset patch
# User Jon Coppeard <jcoppeard@mozilla.com>
# Date 1603288237 0
# Wed Oct 21 13:50:37 2020 +0000
# Node ID 8a8d7fdc7038fb360d7c50f5943ccafd7f0bb829
# Parent 7e223284a9225c66b590aaad671c7448d1ff0b57
Bug 1670358 - Add test for shrinking nsTArrays of JS::Heap<T> r=sg
Depends on D93654
Differential Revision: https://phabricator.services.mozilla.com/D94270
diff -r 7e223284a922 -r 8a8d7fdc7038 xpcom/tests/gtest/TestGCPostBarriers.cpp
--- a/xpcom/tests/gtest/TestGCPostBarriers.cpp Wed Oct 21 13:50:36 2020 +0000
+++ b/xpcom/tests/gtest/TestGCPostBarriers.cpp Wed Oct 21 13:50:37 2020 +0000
@@ -9,6 +9,8 @@
* implemented for nsTArrays that contain JavaScript Values.
*/
+#include "mozilla/UniquePtr.h"
+
#include "jsapi.h"
#include "nsTArray.h"
@@ -37,11 +39,13 @@
const size_t InitialElements = ElementCount / 10;
template <class ArrayT>
-static void RunTest(JSContext* cx, ArrayT* array) {
+static void TestGrow(JSContext* cx) {
JS_GC(cx);
+ auto array = MakeUnique<ArrayT>();
ASSERT_TRUE(array != nullptr);
- JS_AddExtraGCRootsTracer(cx, TraceArray<ArrayT>, array);
+
+ JS_AddExtraGCRootsTracer(cx, TraceArray<ArrayT>, array.get());
/*
* Create the array and fill it with new JS objects. With GGC these will be
@@ -66,7 +70,8 @@
/*
* Sanity check that our array contains what we expect.
*/
- for (size_t i = 0; i < ElementCount; ++i) {
+ ASSERT_EQ(array->Length(), ElementCount);
+ for (size_t i = 0; i < array->Length(); i++) {
RootedObject obj(cx, array->ElementAt(i));
ASSERT_TRUE(JS::ObjectIsTenured(obj));
ASSERT_TRUE(JS_GetProperty(cx, obj, property, &value));
@@ -74,7 +79,54 @@
ASSERT_EQ(static_cast<int32_t>(i), value.toInt32());
}
- JS_RemoveExtraGCRootsTracer(cx, TraceArray<ArrayT>, array);
+ JS_RemoveExtraGCRootsTracer(cx, TraceArray<ArrayT>, array.get());
+}
+
+template <class ArrayT>
+static void TestShrink(JSContext* cx) {
+ JS_GC(cx);
+
+ auto array = MakeUnique<ArrayT>();
+ ASSERT_TRUE(array != nullptr);
+
+ JS_AddExtraGCRootsTracer(cx, TraceArray<ArrayT>, array.get());
+
+ /*
+ * Create the array and fill it with new JS objects. With GGC these will be
+ * allocated in the nursery.
+ */
+ RootedValue value(cx);
+ const char* property = "foo";
+ for (size_t i = 0; i < ElementCount; ++i) {
+ RootedObject obj(cx, JS_NewPlainObject(cx));
+ ASSERT_FALSE(JS::ObjectIsTenured(obj));
+ value = Int32Value(i);
+ ASSERT_TRUE(JS_SetProperty(cx, obj, property, value));
+ ASSERT_TRUE(array->AppendElement(obj, fallible));
+ }
+
+ /* Shrink and compact the array */
+ array->RemoveElementsAt(InitialElements, ElementCount - InitialElements);
+ array->Compact();
+
+ JS_GC(cx);
+
+ ASSERT_EQ(array->Length(), InitialElements);
+ for (size_t i = 0; i < array->Length(); i++) {
+ RootedObject obj(cx, array->ElementAt(i));
+ ASSERT_TRUE(JS::ObjectIsTenured(obj));
+ ASSERT_TRUE(JS_GetProperty(cx, obj, property, &value));
+ ASSERT_TRUE(value.isInt32());
+ ASSERT_EQ(static_cast<int32_t>(i), value.toInt32());
+ }
+
+ JS_RemoveExtraGCRootsTracer(cx, TraceArray<ArrayT>, array.get());
+}
+
+template <class ArrayT>
+static void TestArrayType(JSContext* cx) {
+ TestGrow<ArrayT>(cx);
+ TestShrink<ArrayT>(cx);
}
static void CreateGlobalAndRunTest(JSContext* cx) {
@@ -89,25 +141,11 @@
JS::Realm* oldRealm = JS::EnterRealm(cx, global);
- typedef Heap<JSObject*> ElementT;
-
- {
- nsTArray<ElementT>* array = new nsTArray<ElementT>(InitialElements);
- RunTest(cx, array);
- delete array;
- }
+ using ElementT = Heap<JSObject*>;
- {
- FallibleTArray<ElementT>* array =
- new FallibleTArray<ElementT>(InitialElements);
- RunTest(cx, array);
- delete array;
- }
-
- {
- AutoTArray<ElementT, InitialElements> array;
- RunTest(cx, &array);
- }
+ TestArrayType<nsTArray<ElementT>>(cx);
+ TestArrayType<FallibleTArray<ElementT>>(cx);
+ TestArrayType<AutoTArray<ElementT, 1>>(cx);
JS::LeaveRealm(cx, oldRealm);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。