mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-02 14:54:58 +08:00
Add locking around CatalystInstance.getJavaScriptContext()
Reviewed By: kathryngray Differential Revision: D5861693 fbshipit-source-id: 226ff15622d5e1a8ae3ad4c63f1434bd95c1fa21
This commit is contained in:
committed by
Facebook Github Bot
parent
c1058b1e90
commit
e9aab0d452
@@ -91,6 +91,8 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
private boolean mJSBundleHasLoaded;
|
||||
private @Nullable String mSourceURL;
|
||||
|
||||
private JavaScriptContextHolder mJavaScriptContextHolder;
|
||||
|
||||
// C++ parts
|
||||
private final HybridData mHybridData;
|
||||
private native static HybridData initHybrid();
|
||||
@@ -126,6 +128,8 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
mNativeModuleRegistry.getJavaModules(this),
|
||||
mNativeModuleRegistry.getCxxModules());
|
||||
Log.d(ReactConstants.TAG, "Initializing React Xplat Bridge after initializeBridge");
|
||||
|
||||
mJavaScriptContextHolder = new JavaScriptContextHolder(getJavaScriptContext());
|
||||
}
|
||||
|
||||
private static class BridgeCallback implements ReactCallback {
|
||||
@@ -333,6 +337,11 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
public void run() {
|
||||
// Kill non-UI threads from neutral third party
|
||||
// potentially expensive, so don't run on UI thread
|
||||
|
||||
// contextHolder is used as a lock to guard against other users of the JS VM having
|
||||
// the VM destroyed underneath them, so notify them before we resetNative
|
||||
mJavaScriptContextHolder.clear();
|
||||
|
||||
mHybridData.resetNative();
|
||||
getReactQueueConfiguration().destroy();
|
||||
Log.d(ReactConstants.TAG, "CatalystInstanceImpl.destroy() end");
|
||||
@@ -436,7 +445,11 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
public native void setGlobalVariable(String propName, String jsonValue);
|
||||
|
||||
@Override
|
||||
public native long getJavaScriptContext();
|
||||
public JavaScriptContextHolder getJavaScriptContextHolder() {
|
||||
return mJavaScriptContextHolder;
|
||||
}
|
||||
|
||||
private native long getJavaScriptContext();
|
||||
|
||||
private void incrementPendingJSCalls() {
|
||||
int oldPendingCalls = mPendingJSCalls.getAndIncrement();
|
||||
|
||||
Reference in New Issue
Block a user