Skip to content

Commit 57ae52a

Browse files
committed
Adding support for tagged values with JSRT weak reference APIs
Tagged values will never be GCd, and don't have correpsonding heap blocks. Since tagged values are an internal detail, we should handle it at the JSRT layer, and since tagged values won't be GCd there is no difference between a strong reference and a weak reference.
1 parent 1262d2e commit 57ae52a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/Jsrt/Jsrt.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4644,6 +4644,13 @@ CHAKRA_API JsCreateWeakReference(
46444644
return JsErrorNoCurrentContext;
46454645
}
46464646

4647+
if (Js::TaggedNumber::Is(value)) {
4648+
// non-recyclable-objects do not get GCd, so there is no difference
4649+
// between strong and weak references
4650+
*weakRef = value;
4651+
return JsNoError;
4652+
}
4653+
46474654
Recycler* recycler = threadContext->GetRecycler();
46484655
if (recycler->IsInObjectBeforeCollectCallback())
46494656
{
@@ -4666,6 +4673,12 @@ CHAKRA_API JsGetWeakReferenceValue(
46664673
*value = JS_INVALID_REFERENCE;
46674674

46684675
return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
4676+
if (Js::TaggedNumber::Is(value))
4677+
{
4678+
*value = weakRef;
4679+
return JsNoError;
4680+
}
4681+
46694682
Memory::RecyclerWeakReference<char>* recyclerWeakReference =
46704683
reinterpret_cast<Memory::RecyclerWeakReference<char>*>(weakRef);
46714684
*value = reinterpret_cast<JsValueRef>(recyclerWeakReference->Get());

0 commit comments

Comments
 (0)