Skip to content

Commit 280640d

Browse files
authored
Merge pull request #114 from boingoing/api-prototype-chakracore-8.x
Add proper wrapping for Jsrt API calls to avoid asserts due to missing exception handling
2 parents 0b7750a + af3cf37 commit 280640d

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

deps/chakrashim/core/lib/Jsrt/Jsrt.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,29 +3368,38 @@ CHAKRA_API JsCreateWeakReference(
33683368
_In_ JsValueRef strongRef,
33693369
_Out_ JsWeakRef* weakRef)
33703370
{
3371-
VALIDATE_JSREF(strongRef);
3371+
return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
3372+
VALIDATE_JSREF(strongRef);
33723373

3373-
ThreadContext* threadContext = ThreadContext::GetContextForCurrentThread();
3374-
if (threadContext == nullptr)
3375-
{
3376-
return JsErrorNoCurrentContext;
3377-
}
3374+
ThreadContext* threadContext = ThreadContext::GetContextForCurrentThread();
3375+
if (threadContext == nullptr)
3376+
{
3377+
return JsErrorNoCurrentContext;
3378+
}
33783379

3379-
Recycler* recycler = threadContext->GetRecycler();
3380-
Memory::RecyclerWeakReference<char>* recyclerWeakReference = recycler->CreateWeakReferenceHandle<char>(reinterpret_cast<char*>(strongRef));
3381-
*weakRef = reinterpret_cast<JsWeakRef>(recyclerWeakReference);
3382-
return JsNoError;
3380+
PARAM_NOT_NULL(weakRef);
3381+
*weakRef = nullptr;
3382+
3383+
Recycler* recycler = threadContext->GetRecycler();
3384+
Memory::RecyclerWeakReference<char>* recyclerWeakReference = recycler->CreateWeakReferenceHandle<char>(reinterpret_cast<char*>(strongRef));
3385+
*weakRef = reinterpret_cast<JsWeakRef>(recyclerWeakReference);
3386+
return JsNoError;
3387+
});
33833388
}
33843389

33853390
CHAKRA_API JsGetWeakReferenceValue(
33863391
_In_ JsWeakRef weakRef,
33873392
_Out_ JsValueRef* value)
33883393
{
3389-
VALIDATE_JSREF(weakRef);
3394+
return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
3395+
VALIDATE_JSREF(weakRef);
3396+
PARAM_NOT_NULL(value);
3397+
*value = nullptr;
33903398

3391-
Memory::RecyclerWeakReference<char>* recyclerWeakReference = reinterpret_cast<Memory::RecyclerWeakReference<char>*>(weakRef);
3392-
*value = reinterpret_cast<JsValueRef>(recyclerWeakReference->Get());
3393-
return JsNoError;
3399+
Memory::RecyclerWeakReference<char>* recyclerWeakReference = reinterpret_cast<Memory::RecyclerWeakReference<char>*>(weakRef);
3400+
*value = reinterpret_cast<JsValueRef>(recyclerWeakReference->Get());
3401+
return JsNoError;
3402+
});
33943403
}
33953404

33963405
/////////////////////

0 commit comments

Comments
 (0)