Skip to content

Commit 66da247

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 66da247

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
@@ -4637,6 +4637,13 @@ CHAKRA_API JsCreateWeakReference(
46374637
PARAM_NOT_NULL(weakRef);
46384638
*weakRef = nullptr;
46394639

4640+
if (Js::TaggedNumber::Is(value)) {
4641+
// non-recyclable-objects do not get GCd, so there is no difference
4642+
// between strong and weak references
4643+
*weakRef = value;
4644+
return JsNoError;
4645+
}
4646+
46404647
return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
46414648
ThreadContext* threadContext = ThreadContext::GetContextForCurrentThread();
46424649
if (threadContext == nullptr)
@@ -4665,6 +4672,12 @@ CHAKRA_API JsGetWeakReferenceValue(
46654672
PARAM_NOT_NULL(value);
46664673
*value = JS_INVALID_REFERENCE;
46674674

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

0 commit comments

Comments
 (0)