mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 03:50:11 +08:00
Add a way to access the underlying JavaScriptCore context
Summary: **Motivation** I'm working on a project that uses React Native and needs to add direct synchronous bindings to native stuff through the JavaScriptCore C API. This is because it's performance-sensitive and would benefit from the quickest JS->C path. It does this using cross-platform C++ code that works on both iOS and Android. Most of the infrastructure for getting access to the JSC context is already in React Native actually, just had to add a few more things. (lexs you mentioned to tag you in this pull request) **Test plan** Modify the JavaScriptCore context through the `JSContextRef` returned (eg. add an object at global scope) and verify that it exists in JavaScript. Closes https://github.com/facebook/react-native/pull/10399 Differential Revision: D4080945 Pulled By: lexs fbshipit-source-id: 6659b7a01e09fd84475adde183c1d3aca2d4cf09
This commit is contained in:
committed by
Facebook Github Bot
parent
0698b2beca
commit
c67225818d
@@ -75,4 +75,9 @@ public interface CatalystInstance extends MemoryPressureListener {
|
||||
|
||||
@VisibleForTesting
|
||||
void setGlobalVariable(String propName, String jsonValue);
|
||||
|
||||
/**
|
||||
* Get the C pointer (as a long) to the JavaScriptCore context associated with this instance.
|
||||
*/
|
||||
long getJavaScriptContext();
|
||||
}
|
||||
|
||||
@@ -339,4 +339,11 @@ public class ReactContext extends ContextWrapper {
|
||||
}
|
||||
return mCurrentActivity.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the C pointer (as a long) to the JavaScriptCore context associated with this instance.
|
||||
*/
|
||||
public long getJavaScriptContext() {
|
||||
return mCatalystInstance.getJavaScriptContext();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,6 +347,9 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
@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
|
||||
|
||||
Reference in New Issue
Block a user