Experimental App Bundle API

Reviewed By: michalgr

Differential Revision: D4198629

fbshipit-source-id: b96a4b3ad3e5ab6b4cb8892442c6077edf7058a3
This commit is contained in:
Ashok Menon 2016-11-18 05:01:09 -08:00 committed by Facebook Github Bot
parent bcac6e7d39
commit 9e00a42fd7
4 changed files with 67 additions and 1 deletions

View File

@ -22,6 +22,14 @@ void JSExecutor::loadApplicationScript(std::string bundlePath, std::string sourc
std::move(sourceURL)); 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) { static JSBigOptimizedBundleString::Encoding encodingFromByte(uint8_t byte) {
switch (byte) { switch (byte) {
case 0: case 0:

View File

@ -182,7 +182,11 @@ public:
const char *c_str() const override { const char *c_str() const override {
if (!m_data) { if (!m_data) {
m_data = (const char *)mmap(0, m_size, PROT_READ, MAP_SHARED, m_fd, m_mapOff); 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; return m_data + m_pageOff;
} }
@ -279,6 +283,14 @@ public:
*/ */
virtual void loadApplicationScript(std::string bundlePath, std::string source, int flags); 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 * Add an application "unbundle" file
*/ */

View File

@ -363,6 +363,35 @@ void JSCExecutor::loadApplicationScript(
} }
#endif #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) { void JSCExecutor::loadApplicationScript(std::unique_ptr<const JSBigString> script, std::string sourceURL) throw(JSException) {
SystraceSection s("JSCExecutor::loadApplicationScript", SystraceSection s("JSCExecutor::loadApplicationScript",
"sourceURL", sourceURL); "sourceURL", sourceURL);

View File

@ -63,38 +63,55 @@ public:
virtual void loadApplicationScript( virtual void loadApplicationScript(
std::unique_ptr<const JSBigString> script, std::unique_ptr<const JSBigString> script,
std::string sourceURL) throw(JSException) override; std::string sourceURL) throw(JSException) override;
#ifdef WITH_FBJSCEXTENSIONS #ifdef WITH_FBJSCEXTENSIONS
virtual void loadApplicationScript( virtual void loadApplicationScript(
std::string bundlePath, std::string bundlePath,
std::string sourceURL, std::string sourceURL,
int flags) override; int flags) override;
#endif #endif
#ifdef WITH_FBJSCEXTENSIONS
virtual void loadApplicationScript(
int fd,
std::string sourceURL) override;
#endif
virtual void setJSModulesUnbundle( virtual void setJSModulesUnbundle(
std::unique_ptr<JSModulesUnbundle> unbundle) override; std::unique_ptr<JSModulesUnbundle> unbundle) override;
virtual void callFunction( virtual void callFunction(
const std::string& moduleId, const std::string& moduleId,
const std::string& methodId, const std::string& methodId,
const folly::dynamic& arguments) override; const folly::dynamic& arguments) override;
virtual void invokeCallback( virtual void invokeCallback(
const double callbackId, const double callbackId,
const folly::dynamic& arguments) override; const folly::dynamic& arguments) override;
template <typename T> template <typename T>
Value callFunctionSync( Value callFunctionSync(
const std::string& module, const std::string& method, T&& args) { const std::string& module, const std::string& method, T&& args) {
return callFunctionSyncWithValue(module, method, return callFunctionSyncWithValue(module, method,
toValue(m_context, std::forward<T>(args))); toValue(m_context, std::forward<T>(args)));
} }
virtual void setGlobalVariable( virtual void setGlobalVariable(
std::string propName, std::string propName,
std::unique_ptr<const JSBigString> jsonValue) override; std::unique_ptr<const JSBigString> jsonValue) override;
virtual void* getJavaScriptContext() override; virtual void* getJavaScriptContext() override;
virtual bool supportsProfiling() override; virtual bool supportsProfiling() override;
virtual void startProfiler(const std::string &titleString) override; virtual void startProfiler(const std::string &titleString) override;
virtual void stopProfiler(const std::string &titleString, const std::string &filename) override; virtual void stopProfiler(const std::string &titleString, const std::string &filename) override;
virtual void handleMemoryPressureUiHidden() override; virtual void handleMemoryPressureUiHidden() override;
virtual void handleMemoryPressureModerate() override; virtual void handleMemoryPressureModerate() override;
virtual void handleMemoryPressureCritical() override; virtual void handleMemoryPressureCritical() override;
virtual void destroy() override; virtual void destroy() override;
void setContextName(const std::string& name); void setContextName(const std::string& name);
private: private: