Copy-free Source loading implementation

Reviewed By: amnn

Differential Revision: D4914165

fbshipit-source-id: 38851679cb696c41f59edfd0d2005faf37813b23
This commit is contained in:
Dmitry Zakharov
2017-05-15 09:12:24 -07:00
committed by Facebook Github Bot
parent c4fb32fa40
commit f8b683b3ee
2 changed files with 21 additions and 2 deletions

View File

@@ -357,9 +357,12 @@ void JSCExecutor::loadApplicationScript(std::unique_ptr<const JSBigString> scrip
{
SystraceSection s_("JSCExecutor::loadApplicationScript-createExpectingAscii");
ReactMarker::logMarker(ReactMarker::JS_BUNDLE_STRING_CONVERT_START);
jsScript = jsStringFromBigString(m_context, *script);
jsScript = adoptString(std::move(script));
ReactMarker::logMarker(ReactMarker::JS_BUNDLE_STRING_CONVERT_STOP);
}
#ifdef WITH_FBSYSTRACE
fbsystrace_end_section(TRACE_TAG_REACT_CXX_BRIDGE);
#endif
SystraceSection s_("JSCExecutor::loadApplicationScript-evaluateScript");
evaluateScript(m_context, jsScript, jsSourceURL);
@@ -521,13 +524,27 @@ void JSCExecutor::setGlobalVariable(std::string propName, std::unique_ptr<const
try {
SystraceSection s("JSCExecutor::setGlobalVariable", "propName", propName);
auto valueToInject = Value::fromJSON(m_context, jsStringFromBigString(m_context, *jsonValue));
auto valueToInject = Value::fromJSON(m_context, adoptString(std::move(jsonValue)));
Object::getGlobalObject(m_context).setProperty(propName.c_str(), valueToInject);
} catch (...) {
std::throw_with_nested(std::runtime_error("Error setting global variable: " + propName));
}
}
String JSCExecutor::adoptString(std::unique_ptr<const JSBigString> script) {
#if defined(WITH_FBJSCEXTENSIONS)
const JSBigString* string = script.release();
auto jsString = JSStringCreateAdoptingExternal(string->c_str(), string->size(), (void*)string, [](void* s) {
delete static_cast<JSBigString*>(s);
});
return String::adopt(m_context, jsString);
#else
return script->isAscii()
? String::createExpectingAscii(m_context, script->c_str(), script->size())
: String(m_context, script->c_str());
#endif
}
void* JSCExecutor::getJavaScriptContext() {
return m_context;
}