JSCExecutorFactory.mm 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #include "JSCExecutorFactory.h"
  8. #import <React/RCTLog.h>
  9. #import <jsi/JSCRuntime.h>
  10. #import <memory>
  11. namespace facebook {
  12. namespace react {
  13. std::unique_ptr<JSExecutor> JSCExecutorFactory::createJSExecutor(
  14. std::shared_ptr<ExecutorDelegate> delegate,
  15. std::shared_ptr<MessageQueueThread> __unused jsQueue)
  16. {
  17. auto installBindings = [runtimeInstaller = runtimeInstaller_](jsi::Runtime &runtime) {
  18. react::Logger iosLoggingBinder = [](const std::string &message, unsigned int logLevel) {
  19. _RCTLogJavaScriptInternal(static_cast<RCTLogLevel>(logLevel), [NSString stringWithUTF8String:message.c_str()]);
  20. };
  21. react::bindNativeLogger(runtime, iosLoggingBinder);
  22. react::PerformanceNow iosPerformanceNowBinder = []() {
  23. // CACurrentMediaTime() returns the current absolute time, in seconds
  24. return CACurrentMediaTime() * 1000;
  25. };
  26. react::bindNativePerformanceNow(runtime, iosPerformanceNowBinder);
  27. // Wrap over the original runtimeInstaller
  28. if (runtimeInstaller) {
  29. runtimeInstaller(runtime);
  30. }
  31. };
  32. return std::make_unique<JSIExecutor>(
  33. facebook::jsc::makeJSCRuntime(), delegate, JSIExecutor::defaultTimeoutInvoker, std::move(installBindings));
  34. }
  35. } // namespace react
  36. } // namespace facebook