objc-js 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
Binary file
|
package/package.json
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"format": "prettier --write \"**/*.{ts,js,json,md}\"",
|
|
40
40
|
"preinstall-disabled": "npm run build-scripts && npm run make-clangd-config"
|
|
41
41
|
},
|
|
42
|
-
"version": "0.0.
|
|
42
|
+
"version": "0.0.10",
|
|
43
43
|
"description": "Objective-C bridge for Node.js",
|
|
44
44
|
"main": "dist/index.js",
|
|
45
45
|
"dependencies": {
|
|
@@ -572,8 +572,10 @@ void ForwardInvocation(id self, SEL _cmd, NSInvocation *invocation) {
|
|
|
572
572
|
if (is_js_thread) {
|
|
573
573
|
// We're on the JS thread, so it's safe to access N-API values directly
|
|
574
574
|
// Do a second lookup to get the JS callback
|
|
575
|
+
// IMPORTANT: We must call .Value() while holding the lock to prevent
|
|
576
|
+
// DeallocImplementation from erasing the entry while we're using it
|
|
575
577
|
napi_env stored_env;
|
|
576
|
-
Napi::
|
|
578
|
+
Napi::Function jsFn;
|
|
577
579
|
{
|
|
578
580
|
std::lock_guard<std::mutex> lock(g_implementations_mutex);
|
|
579
581
|
auto it = g_implementations.find(ptr);
|
|
@@ -591,12 +593,13 @@ void ForwardInvocation(id self, SEL _cmd, NSInvocation *invocation) {
|
|
|
591
593
|
}
|
|
592
594
|
|
|
593
595
|
stored_env = it->second.env;
|
|
594
|
-
|
|
596
|
+
// Get the function value WHILE HOLDING THE LOCK
|
|
597
|
+
// This prevents a race with DeallocImplementation clearing the jsCallbacks map
|
|
598
|
+
jsFn = jsCallbackIt->second.Value();
|
|
595
599
|
}
|
|
596
600
|
|
|
597
|
-
// Now
|
|
601
|
+
// Now jsFn is a local Napi::Function (napi_value), safe to use after lock release
|
|
598
602
|
Napi::Env env(stored_env);
|
|
599
|
-
Napi::Function jsFn = jsCallbackPtr->Value(); // Safe: on JS thread with valid HandleScope
|
|
600
603
|
CallJSCallback(env, jsFn, data);
|
|
601
604
|
// Data is deleted in CallJSCallback
|
|
602
605
|
} else {
|