Skip to content

Commit f7e3382

Browse files
feat(runtime): add nullability annotations to NativeScript.h (#461)
* feat(runtime): add nullability annotations to NativeScript.h Without them every pointer in the embedder API imports into Swift as implicitly unwrapped, which hides the contract the implementation already has: BaseDir, the script string and the Config argument are required (their UTF8String feeds a std::string), while ApplicationPath, MetadataPtr and Arguments are optional with defaults (BaseDir/app, the __TNSMetadata section, no inspector arguments). initWithConfig: never returns nil. * fix(runtime): read no inspector flags from a nil Arguments array Config.Arguments is optional, but ArgumentsCount was handed to the inspector as is, so a nil array with a count above one made debug startup index a null argv. Pass a count of 0 when the array is nil; the argv loop keeps the C contract and trusts the count it is given.
1 parent 8c35e95 commit f7e3382

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎NativeScript/NativeScript.h‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#import <Foundation/Foundation.h>
22

3+
NS_ASSUME_NONNULL_BEGIN
4+
35
@interface Config : NSObject
46

57
@property (nonatomic, retain) NSString* BaseDir;
6-
@property (nonatomic, retain) NSString* ApplicationPath;
7-
@property (nonatomic) void* MetadataPtr;
8+
@property (nonatomic, retain, nullable) NSString* ApplicationPath;
9+
@property (nonatomic, nullable) void* MetadataPtr;
810
@property BOOL IsDebug;
911
@property BOOL LogToSystemConsole;
1012
@property int ArgumentsCount;
11-
@property (nonatomic) char** Arguments;
13+
@property (nonatomic) char* _Nullable* _Nullable Arguments;
1214

1315
@end
1416

@@ -26,3 +28,5 @@
2628
- (bool)liveSync;
2729

2830
@end
31+
32+
NS_ASSUME_NONNULL_END

‎NativeScript/NativeScript.mm‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ - (instancetype)initializeWithConfig:(Config*)config {
193193
new v8_inspector::JsV8InspectorClient(runtime_);
194194
inspectorClient->init();
195195
inspectorClient->registerModules();
196-
inspectorClient->connect([config ArgumentsCount], [config Arguments]);
196+
// A nil Arguments array carries no inspector flags, whatever ArgumentsCount says.
197+
inspectorClient->connect(config.Arguments != nullptr ? config.ArgumentsCount : 0,
198+
config.Arguments);
197199
Console::AttachInspectorClient(inspectorClient);
198200
}
199201
}

0 commit comments

Comments
 (0)