Issue MoonchildProductions/UXP#2306: Add pref-gated WeakRef with safe stub when disabled

* Add javascript.options.weakrefs and plumb it through context options, XPConnect, and workers
* Keep referents alive via strong tracing when the pref is off so deref() still returns the target
* Retain weak-edge semantics when the pref is enabled
This commit is contained in:
Basilisk-Dev 2025-12-17 16:35:41 -05:00 • committed by wuggy
commit 3cf82e2ca1
7 changed files with 32 additions and 8 deletions

View file

@ -998,7 +998,9 @@ class JS_PUBLIC_API(ContextOptions) {
werror_(false),
strictMode_(false),
extraWarnings_(false),
arrayProtoValues_(true)
arrayProtoValues_(true),
streams_(true),
weakRefs_(false)
{
}
@ -1138,6 +1140,16 @@ class JS_PUBLIC_API(ContextOptions) {
return *this;
}
bool weakRefs() const { return weakRefs_; }
ContextOptions& setWeakRefs(bool flag) {
weakRefs_ = flag;
return *this;
}
ContextOptions& toggleWeakRefs() {
weakRefs_ = !weakRefs_;
return *this;
}
private:
bool baseline_ : 1;
bool ion_ : 1;
@ -1155,6 +1167,7 @@ class JS_PUBLIC_API(ContextOptions) {
bool extraWarnings_ : 1;
bool arrayProtoValues_ : 1;
bool streams_ : 1;
bool weakRefs_ : 1;
};
JS_PUBLIC_API(ContextOptions&)