Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions React/Executors/RCTJSCExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,9 @@ RCT_EXTERN NSString *const RCTFBJSValueClassKey;
arguments:(NSArray *)args
jsValueCallback:(RCTJavaScriptValueCallback)onComplete;

/**
* Get the JavaScriptCore context associated with this executor instance.
*/
- (JSContext *)jsContext;

@end
5 changes: 5 additions & 0 deletions React/Executors/RCTJSCExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,11 @@ static RandomAccessBundleStartupCode readRAMBundle(file_ptr bundle, RandomAccess
return [NSData dataWithBytesNoCopy:startupCode.code.release() length:startupCode.size freeWhenDone:YES];
}

- (JSContext *)jsContext
{
return [self context].context;
}

@end

@implementation RCTJSContextProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ void callFunction(

@VisibleForTesting
void setGlobalVariable(String propName, String jsonValue);

/**
* Get the C pointer (as a long) to the JavaScriptCore context associated with this instance.
*/
long getJavaScriptContext();
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,11 @@ public boolean startActivityForResult(Intent intent, int code, Bundle bundle) {
}
return mCurrentActivity.get();
}

/**
* Get the C pointer (as a long) to the JavaScriptCore context associated with this instance.
*/
public long getJavaScriptContext() {
return mCatalystInstance.getJavaScriptContext();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ public void removeBridgeIdleDebugListener(NotThreadSafeBridgeIdleDebugListener l
@Override
public native void setGlobalVariable(String propName, String jsonValue);

@Override
public native long getJavaScriptContext();

// TODO mhorowitz: add mDestroyed checks to the next three methods

@Override
Expand Down
5 changes: 5 additions & 0 deletions ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void CatalystInstanceImpl::registerNatives() {
makeNativeMethod("callJSCallback", CatalystInstanceImpl::callJSCallback),
makeNativeMethod("getMainExecutorToken", CatalystInstanceImpl::getMainExecutorToken),
makeNativeMethod("setGlobalVariable", CatalystInstanceImpl::setGlobalVariable),
makeNativeMethod("getJavaScriptContext", CatalystInstanceImpl::getJavaScriptContext),
makeNativeMethod("handleMemoryPressureUiHidden", CatalystInstanceImpl::handleMemoryPressureUiHidden),
makeNativeMethod("handleMemoryPressureModerate", CatalystInstanceImpl::handleMemoryPressureModerate),
makeNativeMethod("handleMemoryPressureCritical", CatalystInstanceImpl::handleMemoryPressureCritical),
Expand Down Expand Up @@ -219,6 +220,10 @@ void CatalystInstanceImpl::setGlobalVariable(std::string propName,
folly::make_unique<JSBigStdString>(std::move(jsonValue)));
}

jlong CatalystInstanceImpl::getJavaScriptContext() {
return (jlong) (intptr_t) instance_->getJavaScriptContext();
}

void CatalystInstanceImpl::handleMemoryPressureUiHidden() {
instance_->handleMemoryPressureUiHidden();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CatalystInstanceImpl : public jni::HybridClass<CatalystInstanceImpl> {
local_ref<JExecutorToken::JavaPart> getMainExecutorToken();
void setGlobalVariable(std::string propName,
std::string&& jsonValue);
jlong getJavaScriptContext();
void handleMemoryPressureUiHidden();
void handleMemoryPressureModerate();
void handleMemoryPressureCritical();
Expand Down
4 changes: 4 additions & 0 deletions ReactCommon/cxxreact/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ void Instance::setGlobalVariable(std::string propName,
nativeToJsBridge_->setGlobalVariable(std::move(propName), std::move(jsonValue));
}

void *Instance::getJavaScriptContext() {
return nativeToJsBridge_->getJavaScriptContext();
}

void Instance::callJSFunction(ExecutorToken token, std::string&& module, std::string&& method,
folly::dynamic&& params) {
callback_->incrementPendingJSCalls();
Expand Down
1 change: 1 addition & 0 deletions ReactCommon/cxxreact/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Instance {
void startProfiler(const std::string& title);
void stopProfiler(const std::string& title, const std::string& filename);
void setGlobalVariable(std::string propName, std::unique_ptr<const JSBigString> jsonValue);
void *getJavaScriptContext();
void callJSFunction(ExecutorToken token, std::string&& module, std::string&& method,
folly::dynamic&& params);
void callJSCallback(ExecutorToken token, uint64_t callbackId, folly::dynamic&& params);
Expand Down