-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce native api to access RuntimeExecutor (#42758)
Summary: Changelog: [Added][iOS] introduce native api to access RuntimeExecutor The goal of this API is to provide a safe way to access the `jsi::runtime` in bridgeless mode. The decision to limit access to the runtime in bridgeless was a conscious one - the runtime pointer is not thread-safe and its lifecycle must be managed correctly by owners. However, interacting with the runtime is an advanced use case we would want to support. Our recommended ways to access the runtime in bridgeless mode is either 1) via the RuntimeExecutor, or 2) via a C++ TurboModule. This diff introduces the API that would allow for 1). The integration consists of these parts: - Wrapper objects for RuntimeExecutor access. These are `RCTRuntimeExecution` and `RCTRuntimeExecutionWrapper`. RCTRuntimeExecutionWrapper is a C++ free wrapper of RCTRuntimeExecution to be reliably used in Swift modules. - The new API on RCTBridgeModule, following a similar pattern to other decoration APIs, and integration with our module infrastructure. Differential Revision: D53256188
- Loading branch information
1 parent
6a8a28b
commit 9ec157b
Showing
7 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/react-native/React/Base/RCTRuntimeExecutionWrapper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
@class RCTRuntimeExecution; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
Swift friendly wrapper of RCTRuntimeExecution. | ||
*/ | ||
@interface RCTRuntimeExecutionWrapper : NSObject | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
- (instancetype)initWithRuntimeExecution:(RCTRuntimeExecution *)runtimeExecution; | ||
|
||
- (RCTRuntimeExecution *)getRuntimeExecution; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
32 changes: 32 additions & 0 deletions
32
packages/react-native/React/Base/RCTRuntimeExecutionWrapper.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#import "RCTRuntimeExecutionWrapper.h" | ||
|
||
@implementation RCTRuntimeExecutionWrapper { | ||
RCTRuntimeExecution *_runtimeExecution; | ||
} | ||
|
||
#pragma mark - Initializer | ||
|
||
- (instancetype)initWithRuntimeExecution:(RCTRuntimeExecution *)runtimeExecution | ||
{ | ||
if (self = [super init]) { | ||
_runtimeExecution = runtimeExecution; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
#pragma mark - Public API | ||
|
||
- (RCTRuntimeExecution *)getRuntimeExecution | ||
{ | ||
return _runtimeExecution; | ||
} | ||
|
||
@end |
30 changes: 30 additions & 0 deletions
30
...native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTRuntimeExecution.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#import <jsi/jsi.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
typedef void (^RCTJSIRuntimeHandlingBlock)(facebook::jsi::Runtime &runtime); | ||
typedef void (^RCTRuntimeExecutorBlock)(RCTJSIRuntimeHandlingBlock); | ||
|
||
@interface RCTRuntimeExecution : NSObject | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
|
||
/** | ||
Initializes an object that wraps ways to access the RuntimeExecutor. | ||
@param runtimeExecutorBlock A block that provides thread-safe access to jsi::runtime. | ||
*/ | ||
- (instancetype)initWithRuntimeExecutorBlock:(RCTRuntimeExecutorBlock)runtimeExecutorBlock NS_DESIGNATED_INITIALIZER; | ||
|
||
- (RCTRuntimeExecutorBlock)runtimeExecutorBlock; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
32 changes: 32 additions & 0 deletions
32
...ative/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTRuntimeExecution.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#import "RCTRuntimeExecution.h" | ||
|
||
@implementation RCTRuntimeExecution { | ||
RCTRuntimeExecutorBlock _runtimeExecutorBlock; | ||
} | ||
|
||
#pragma mark - Initializer | ||
|
||
- (instancetype)initWithRuntimeExecutorBlock:(RCTRuntimeExecutorBlock)runtimeExecutorBlock | ||
{ | ||
if (self = [super init]) { | ||
_runtimeExecutorBlock = [runtimeExecutorBlock copy]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
#pragma mark - Public API | ||
|
||
- (RCTRuntimeExecutorBlock)runtimeExecutorBlock | ||
{ | ||
return _runtimeExecutorBlock; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters