mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
5ae53cc051
Summary: Enables two new experiments (and the current behaviour as default) to speed up access to TurboModule methods from JS. 1) HostObject - Current behaviour 2) Prototype - Connect the TM HostObject via `__proto__`, and cache any methods accessed on the wrapper object. 3) Eager - Eagerly store all methods on the wrapper object, do not expose the HostObject to JS at all (TurboModules no longer need to be HostObjects in this scenario) Changelog: [Internal] Reviewed By: JoshuaGross, rubennorte, mdvacca Differential Revision: D36590018 fbshipit-source-id: c9565eb239eb6aeee0f06b581ff8cd72a92073fc
41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "TurboModule.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
TurboModule::TurboModule(
|
|
std::string name,
|
|
std::shared_ptr<CallInvoker> jsInvoker)
|
|
: name_(std::move(name)), jsInvoker_(std::move(jsInvoker)) {}
|
|
|
|
jsi::Value TurboModule::get(
|
|
jsi::Runtime &runtime,
|
|
const jsi::PropNameID &propName,
|
|
const MethodMetadata &meta) {
|
|
auto result = jsi::Function::createFromHostFunction(
|
|
runtime,
|
|
propName,
|
|
static_cast<unsigned int>(meta.argCount),
|
|
[this, meta](
|
|
jsi::Runtime &rt,
|
|
const jsi::Value &thisVal,
|
|
const jsi::Value *args,
|
|
size_t count) { return meta.invoker(rt, *this, args, count); });
|
|
// If we have a JS wrapper, cache the result of this lookup
|
|
// We don't cache misses, to allow for methodMap_ to dynamically be extended
|
|
if (jsRepresentation_) {
|
|
jsRepresentation_->setProperty(runtime, propName, result);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|