mirror of
https://github.com/status-im/react-native.git
synced 2025-01-13 19:15:05 +00:00
Experimental App Bundle API
Reviewed By: michalgr Differential Revision: D4198629 fbshipit-source-id: b96a4b3ad3e5ab6b4cb8892442c6077edf7058a3
This commit is contained in:
parent
bcac6e7d39
commit
9e00a42fd7
@ -22,6 +22,14 @@ void JSExecutor::loadApplicationScript(std::string bundlePath, std::string sourc
|
||||
std::move(sourceURL));
|
||||
}
|
||||
|
||||
void JSExecutor::loadApplicationScript(int fd, std::string sourceURL) {
|
||||
struct stat fileInfo;
|
||||
folly::checkUnixError(::fstat(fd, &fileInfo), "fstat on bundle failed.");
|
||||
|
||||
auto bundle = folly::make_unique<JSBigFileString>(fd, fileInfo.st_size);
|
||||
return loadApplicationScript(std::move(bundle), std::move(sourceURL));
|
||||
}
|
||||
|
||||
static JSBigOptimizedBundleString::Encoding encodingFromByte(uint8_t byte) {
|
||||
switch (byte) {
|
||||
case 0:
|
||||
|
@ -182,7 +182,11 @@ public:
|
||||
const char *c_str() const override {
|
||||
if (!m_data) {
|
||||
m_data = (const char *)mmap(0, m_size, PROT_READ, MAP_SHARED, m_fd, m_mapOff);
|
||||
CHECK(m_data != MAP_FAILED);
|
||||
CHECK(m_data != MAP_FAILED)
|
||||
<< " fd: " << m_fd
|
||||
<< " size: " << m_size
|
||||
<< " offset: " << m_mapOff
|
||||
<< " error: " << std::strerror(errno);
|
||||
}
|
||||
return m_data + m_pageOff;
|
||||
}
|
||||
@ -279,6 +283,14 @@ public:
|
||||
*/
|
||||
virtual void loadApplicationScript(std::string bundlePath, std::string source, int flags);
|
||||
|
||||
/**
|
||||
* @experimental
|
||||
*
|
||||
* Read an app bundle from a file descriptor, determine how it should be
|
||||
* loaded, load and execute it in the JS context.
|
||||
*/
|
||||
virtual void loadApplicationScript(int fd, std::string source);
|
||||
|
||||
/**
|
||||
* Add an application "unbundle" file
|
||||
*/
|
||||
|
@ -363,6 +363,35 @@ void JSCExecutor::loadApplicationScript(
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_FBJSCEXTENSIONS
|
||||
void JSCExecutor::loadApplicationScript(
|
||||
int fd,
|
||||
std::string sourceURL)
|
||||
{
|
||||
String jsSourceURL {sourceURL.c_str()};
|
||||
|
||||
auto bcSourceCode = JSCreateCompiledSourceCode(fd, jsSourceURL);
|
||||
if (!bcSourceCode) {
|
||||
// Not bytecode, fall through.
|
||||
return JSExecutor::loadApplicationScript(fd, sourceURL);
|
||||
}
|
||||
|
||||
ReactMarker::logMarker("RUN_JS_BUNDLE_START");
|
||||
|
||||
evaluateSourceCode(m_context, bcSourceCode, jsSourceURL);
|
||||
|
||||
// TODO(luk): t13903306 Remove this check once we make native modules
|
||||
// working for java2js
|
||||
if (m_delegate) {
|
||||
bindBridge();
|
||||
flush();
|
||||
}
|
||||
|
||||
ReactMarker::logMarker("CREATE_REACT_CONTEXT_END");
|
||||
ReactMarker::logMarker("RUN_JS_BUNDLE_END");
|
||||
}
|
||||
#endif
|
||||
|
||||
void JSCExecutor::loadApplicationScript(std::unique_ptr<const JSBigString> script, std::string sourceURL) throw(JSException) {
|
||||
SystraceSection s("JSCExecutor::loadApplicationScript",
|
||||
"sourceURL", sourceURL);
|
||||
|
@ -63,38 +63,55 @@ public:
|
||||
virtual void loadApplicationScript(
|
||||
std::unique_ptr<const JSBigString> script,
|
||||
std::string sourceURL) throw(JSException) override;
|
||||
|
||||
#ifdef WITH_FBJSCEXTENSIONS
|
||||
virtual void loadApplicationScript(
|
||||
std::string bundlePath,
|
||||
std::string sourceURL,
|
||||
int flags) override;
|
||||
#endif
|
||||
|
||||
#ifdef WITH_FBJSCEXTENSIONS
|
||||
virtual void loadApplicationScript(
|
||||
int fd,
|
||||
std::string sourceURL) override;
|
||||
#endif
|
||||
|
||||
virtual void setJSModulesUnbundle(
|
||||
std::unique_ptr<JSModulesUnbundle> unbundle) override;
|
||||
|
||||
virtual void callFunction(
|
||||
const std::string& moduleId,
|
||||
const std::string& methodId,
|
||||
const folly::dynamic& arguments) override;
|
||||
|
||||
virtual void invokeCallback(
|
||||
const double callbackId,
|
||||
const folly::dynamic& arguments) override;
|
||||
|
||||
template <typename T>
|
||||
Value callFunctionSync(
|
||||
const std::string& module, const std::string& method, T&& args) {
|
||||
return callFunctionSyncWithValue(module, method,
|
||||
toValue(m_context, std::forward<T>(args)));
|
||||
}
|
||||
|
||||
virtual void setGlobalVariable(
|
||||
std::string propName,
|
||||
std::unique_ptr<const JSBigString> jsonValue) override;
|
||||
|
||||
virtual void* getJavaScriptContext() override;
|
||||
|
||||
virtual bool supportsProfiling() override;
|
||||
virtual void startProfiler(const std::string &titleString) override;
|
||||
virtual void stopProfiler(const std::string &titleString, const std::string &filename) override;
|
||||
|
||||
virtual void handleMemoryPressureUiHidden() override;
|
||||
virtual void handleMemoryPressureModerate() override;
|
||||
virtual void handleMemoryPressureCritical() override;
|
||||
|
||||
virtual void destroy() override;
|
||||
|
||||
void setContextName(const std::string& name);
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user