summaryrefslogtreecommitdiff
path: root/xpcom
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2023-04-30 10:51:26 +0000
committerMoonchild <moonchild@palemoon.org>2023-04-30 10:51:26 +0000
commit732e1bb7f7720250b096260b27ecc5707518ce74 (patch)
tree2d04fc52ea257d3e40b56044f57532ea1c0eeab9 /xpcom
parent22e68f166c42e2d65967190a75add0dcf0394b71 (diff)
parentf7ee58a9e71442a8d4422df4c0bb919104d76016 (diff)
downloaduxp-732e1bb7f7720250b096260b27ecc5707518ce74.tar.gz
Merge pull request 'Implement Dynamic Module Import and its various dependencies.' (#2215) from dbsoft/UXP:d-m-i into master
Reviewed-on: https://repo.palemoon.org/MoonchildProductions/UXP/pulls/2215
Diffstat (limited to 'xpcom')
-rw-r--r--xpcom/base/CycleCollectedJSContext.cpp43
-rw-r--r--xpcom/base/ErrorList.h7
-rw-r--r--xpcom/base/nsCycleCollector.cpp38
3 files changed, 64 insertions, 24 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()));
}
}
diff --git a/xpcom/base/ErrorList.h b/xpcom/base/ErrorList.h
index a99d0e83fc..c39ea68d07 100644
--- a/xpcom/base/ErrorList.h
+++ b/xpcom/base/ErrorList.h
@@ -568,6 +568,13 @@
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_CHUNKED_RESPONSETYPES_UNSUPPORTED_FOR_SYNC, FAILURE(1027)),
ERROR(NS_ERROR_DOM_INVALID_ACCESS_XHR_TIMEOUT_AND_RESPONSETYPE_UNSUPPORTED_FOR_SYNC, FAILURE(1028)),
+
+ /* When manipulating the bytecode cache with the JS API, some transcoding
+ * errors, such as a different bytecode format can cause failures of the
+ * decoding process.
+ */
+ ERROR(NS_ERROR_DOM_JS_DECODING_ERROR, FAILURE(1030)),
+
/* May be used to indicate when e.g. setting a property value didn't
* actually change the value, like for obj.foo = "bar"; obj.foo = "bar";
* the second assignment throws NS_SUCCESS_DOM_NO_OPERATION.
diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp
index 8df3c3a6bc..2e5804929e 100644
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -337,7 +337,7 @@ public:
// Base types
////////////////////////////////////////////////////////////////////////
-struct PtrInfo;
+class PtrInfo;
class EdgePool
{
@@ -533,13 +533,15 @@ enum NodeColor { black, white, grey };
// hundreds of thousands of them to be allocated and touched
// repeatedly during each cycle collection.
-struct PtrInfo
+class PtrInfo final
{
+public:
void* mPointer;
nsCycleCollectionParticipant* mParticipant;
uint32_t mColor : 2;
uint32_t mInternalRefs : 30;
uint32_t mRefCount;
+
private:
EdgePool::Iterator mFirstChild;
@@ -609,8 +611,29 @@ public:
CC_GRAPH_ASSERT(aLastChild.Initialized());
(this + 1)->mFirstChild = aLastChild;
}
+
+ void AnnotatedReleaseAssert(bool aCondition, const char* aMessage);
};
+void
+PtrInfo::AnnotatedReleaseAssert(bool aCondition, const char* aMessage)
+{
+ if (aCondition) {
+ return;
+ }
+
+#ifdef MOZ_CRASHREPORTER
+ const char* piName = "Unknown";
+ if (mParticipant) {
+ piName = mParticipant->ClassName();
+ }
+ nsPrintfCString msg("%s, for class %s", aMessage, piName);
+ CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("CycleCollector"), msg);
+#endif
+
+ MOZ_CRASH();
+}
+
/**
* A structure designed to be used like a linked list of PtrInfo, except
* it allocates many PtrInfos at a time.
@@ -2294,8 +2317,10 @@ CCGraphBuilder::NoteNativeRoot(void* aRoot,
NS_IMETHODIMP_(void)
CCGraphBuilder::DescribeRefCountedNode(nsrefcnt aRefCount, const char* aObjName)
{
- MOZ_RELEASE_ASSERT(aRefCount != 0, "CCed refcounted object has zero refcount");
- MOZ_RELEASE_ASSERT(aRefCount != UINT32_MAX, "CCed refcounted object has overflowing refcount");
+ mCurrPi->AnnotatedReleaseAssert(aRefCount != 0,
+ "CCed refcounted object has zero refcount");
+ mCurrPi->AnnotatedReleaseAssert(aRefCount != UINT32_MAX,
+ "CCed refcounted object has overflowing refcount");
mResults.mVisitedRefCounted++;
@@ -3109,9 +3134,8 @@ nsCycleCollector::ScanWhiteNodes(bool aFullySynchGraphBuild)
continue;
}
- if (pi->mInternalRefs > pi->mRefCount) {
- MOZ_CRASH();
- }
+ pi->AnnotatedReleaseAssert(pi->mInternalRefs <= pi->mRefCount,
+ "More references to an object than its refcount");
// This node will get marked black in the next pass.
}