Files
nitro/packages/react-native-nitro-modules/cpp/entrypoint/InstallNitro.cpp
T
Marc RousavyandGitHub 229e7d83db feat: Create ObjectUtils for Object.freeze, Object.defineProperty, ... (#967)
* feat: Create `ObjectUtils` for `Object.freeze`, `Object.defineProperty`, ...

* Use Object.create

* Fix missing obj

* fix: Better error

* Cache

* fix: Actually cache by preventing copy

* Object.create is part of RN 78

* Use `defineProperty(...)` for `Dispatcher` too

* Optimize Dispatcher install

* Create `getGlobalFunction`

* feat: Use `defineGlobal(...)` to define our global props

* fix: Move the globals

* fix: Don't protect/freeze the globals in JS

we already do it in native.
2025-10-17 18:35:16 +02:00

30 lines
857 B
C++

//
// InstallNitro.cpp
// NitroModules
//
// Created by Marc Rousavy on 05.10.24
//
#include "InstallNitro.hpp"
#include "HybridNitroModulesProxy.hpp"
#include "ObjectUtils.hpp"
namespace margelo::nitro {
void install(jsi::Runtime& runtime, std::shared_ptr<Dispatcher> dispatcher) {
// Registers a Dispatcher for Nitro to call back into the JS Runtime.
// This allows creating Promises and calling back to JS.
Dispatcher::installRuntimeGlobalDispatcher(runtime, dispatcher);
// Installs NitroModulesProxy itself into the Runtime's global.
install(runtime);
}
void install(jsi::Runtime& runtime) {
// Installs global.NitroModulesProxy
auto proxy = std::make_shared<HybridNitroModulesProxy>();
ObjectUtils::defineGlobal(runtime, KnownGlobalPropertyName::NITRO_MODULES_PROXY, proxy->toObject(runtime));
}
} // namespace margelo::nitro