summaryrefslogtreecommitdiff
path: root/xpcom
diff options
context:
space:
mode:
authorBrian Smith <brian@dbsoft.org>2023-04-09 12:22:33 -0500
committerBrian Smith <brian@dbsoft.org>2023-04-27 13:33:27 -0500
commit5f63601f0f2a01fbeb31861c40337cfe7b69cf91 (patch)
tree8a12bc2c05a231ac7dabb883144a2f154283656d /xpcom
parent1a4146cead903187df3fde50646a0dceb28413c0 (diff)
downloaduxp-5f63601f0f2a01fbeb31861c40337cfe7b69cf91.tar.gz
Issue #1691 - Part 6a: Support private values which contain pointers to cycle-collected C++ objects
https://bugzilla.mozilla.org/show_bug.cgi?id=1342012 (cherry picked from commit 1286cca73d58332ba0becd0011f747713b8acfac)
Diffstat (limited to 'xpcom')
-rw-r--r--xpcom/base/CycleCollectedJSContext.cpp43
1 files changed, 26 insertions, 17 deletions
diff --git a/xpcom/base/CycleCollectedJSContext.cpp b/xpcom/base/CycleCollectedJSContext.cpp
index 17a989c833..a28b1ed3ba 100644
--- a/xpcom/base/CycleCollectedJSContext.cpp
+++ b/xpcom/base/CycleCollectedJSContext.cpp
@@ -72,6 +72,7 @@
#include "mozilla/dom/ScriptSettings.h"
#include "jsprf.h"
#include "js/Debug.h"
+#include "jsfriendapi.h"
#include "nsContentUtils.h"
#include "nsCycleCollectionNoteRootCallback.h"
#include "nsCycleCollectionParticipant.h"
@@ -642,25 +643,33 @@ CycleCollectedJSContext::NoteGCThingXPCOMChildren(const js::Class* aClasp,
}
// XXX This test does seem fragile, we should probably whitelist classes
// that do hold a strong reference, but that might not be possible.
- else if (aClasp->flags & JSCLASS_HAS_PRIVATE &&
- aClasp->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) {
+ if (aClasp->flags & JSCLASS_HAS_PRIVATE &&
+ aClasp->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "js::GetObjectPrivate(obj)");
aCb.NoteXPCOMChild(static_cast<nsISupports*>(js::GetObjectPrivate(aObj)));
- } else {
- const DOMJSClass* domClass = GetDOMClass(aObj);
- if (domClass) {
- NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "UnwrapDOMObject(obj)");
- // It's possible that our object is an unforgeable holder object, in
- // which case it doesn't actually have a C++ DOM object associated with
- // it. Use UnwrapPossiblyNotInitializedDOMObject, which produces null in
- // that case, since NoteXPCOMChild/NoteNativeChild are null-safe.
- if (domClass->mDOMObjectIsISupports) {
- aCb.NoteXPCOMChild(UnwrapPossiblyNotInitializedDOMObject<nsISupports>(aObj));
- } else if (domClass->mParticipant) {
- aCb.NoteNativeChild(UnwrapPossiblyNotInitializedDOMObject<void>(aObj),
- domClass->mParticipant);
- }
- }
+ return;
+ }
+
+ const DOMJSClass* domClass = GetDOMClass(aObj);
+ if (domClass) {
+ NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCb, "UnwrapDOMObject(obj)");
+ // It's possible that our object is an unforgeable holder object, in
+ // which case it doesn't actually have a C++ DOM object associated with
+ // it. Use UnwrapPossiblyNotInitializedDOMObject, which produces null in
+ // that case, since NoteXPCOMChild/NoteNativeChild are null-safe.
+ if (domClass->mDOMObjectIsISupports) {
+ aCb.NoteXPCOMChild(
+ UnwrapPossiblyNotInitializedDOMObject<nsISupports>(aObj));
+ } else if (domClass->mParticipant) {
+ aCb.NoteNativeChild(UnwrapPossiblyNotInitializedDOMObject<void>(aObj),
+ domClass->mParticipant);
+ }
+ return;
+ }
+
+ JS::Value value = js::MaybeGetScriptPrivate(aObj);
+ if (!value.isUndefined()) {
+ aCb.NoteXPCOMChild(static_cast<nsISupports*>(value.toPrivate()));
}
}