Skip to content

Commit 650723f

Browse files
committed
Refactor TNSTestNativeCallbacks and related tests
- Removed duplicate inclusion of <TargetConditionals.h> in TNSTestNativeCallbacks.h. - Reformatted method calls and assertions in TNSTestNativeCallbacks.m for improved readability. - Updated imports in TestFixtures.h to maintain consistent ordering. - Enhanced RecordTests.js to support both CGRect and NSRect constructors, ensuring compatibility across platforms. - Modified VersionDiffTests.js to handle macOS and iOS version checks more gracefully.
1 parent 505a68b commit 650723f

13 files changed

Lines changed: 627 additions & 567 deletions

File tree

NativeScript/ffi/TypeConv.mm

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ napi_value toJS(napi_env env, void* value, uint32_t flags) override {
369369
napi_get_boolean(env, raw == 1, &result);
370370
return result;
371371
}
372+
372373
napi_value result;
373374
napi_create_int32(env, raw, &result);
374375
return result;
@@ -401,6 +402,7 @@ napi_value toJS(napi_env env, void* value, uint32_t flags) override {
401402
napi_get_boolean(env, raw == 1, &result);
402403
return result;
403404
}
405+
404406
napi_value result;
405407
napi_create_uint32(env, raw, &result);
406408
return result;
@@ -433,6 +435,7 @@ napi_value toJS(napi_env env, void* value, uint32_t flags) override {
433435
napi_get_boolean(env, raw == 1, &result);
434436
return result;
435437
}
438+
436439
napi_value result;
437440
napi_create_uint32(env, raw, &result);
438441
return result;
@@ -782,17 +785,43 @@ void toNative(napi_env env, napi_value value, void* result, bool* shouldFree,
782785
}
783786

784787
napi_value toJS(napi_env env, void* value, uint32_t flags) override {
788+
uint8_t raw = *(uint8_t*)value;
789+
if (raw == 0 || raw == 1) {
790+
napi_value result;
791+
napi_get_boolean(env, raw == 1, &result);
792+
return result;
793+
}
794+
785795
napi_value result;
786-
napi_get_boolean(env, *(bool*)value, &result);
796+
napi_create_uint32(env, raw, &result);
787797
return result;
788798
}
789799

790800
void toNative(napi_env env, napi_value value, void* result, bool* shouldFree,
791801
bool* shouldFreeAny) override {
792-
bool val;
802+
napi_valuetype valueType = napi_undefined;
803+
napi_typeof(env, value, &valueType);
804+
805+
if (valueType == napi_number) {
806+
uint32_t val = 0;
807+
napi_coerce_to_number(env, value, &value);
808+
napi_get_value_uint32(env, value, &val);
809+
*(uint8_t*)result = static_cast<uint8_t>(val);
810+
return;
811+
}
812+
813+
if (valueType == napi_bigint) {
814+
uint64_t val = 0;
815+
bool lossless = false;
816+
napi_get_value_bigint_uint64(env, value, &val, &lossless);
817+
*(uint8_t*)result = static_cast<uint8_t>(val);
818+
return;
819+
}
820+
821+
bool val = false;
793822
napi_coerce_to_bool(env, value, &value);
794823
napi_get_value_bool(env, value, &val);
795-
*(bool*)result = val;
824+
*(uint8_t*)result = static_cast<uint8_t>(val ? 1 : 0);
796825
}
797826

798827
void encode(std::string* encoding) override { *encoding += "B"; }

NativeScript/napi/v8/v8_inspector/src/base/bounds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#ifndef V8_BASE_BOUNDS_H_
66
#define V8_BASE_BOUNDS_H_
77

8-
#include "v8config.h"
98
#include "src/base/macros.h"
9+
#include "v8config.h"
1010

1111
namespace v8 {
1212
namespace base {

NativeScript/napi/v8/v8_inspector/src/base/immediate-crash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#ifndef V8_BASE_IMMEDIATE_CRASH_H_
66
#define V8_BASE_IMMEDIATE_CRASH_H_
77

8-
#include "v8config.h"
98
#include "src/base/build_config.h"
9+
#include "v8config.h"
1010

1111
// Crashes in the fastest possible way with no attempt at logging.
1212
// There are several constraints; see http://crbug.com/664209 for more context.

NativeScript/napi/v8/v8_inspector/src/base/platform/platform-posix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#ifndef V8_BASE_PLATFORM_PLATFORM_POSIX_H_
66
#define V8_BASE_PLATFORM_PLATFORM_POSIX_H_
77

8-
#include "v8config.h"
98
#include "src/base/platform/platform.h"
109
#include "src/base/timezone-cache.h"
10+
#include "v8config.h"
1111

1212
namespace v8 {
1313
namespace base {

NativeScript/runtime/NativeScript.mm

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "NativeScript.h"
22
#include "Runtime.h"
33
#include "RuntimeConfig.h"
4-
#include "js_native_api.h"
5-
#include "jsr.h"
64
#include "ffi/NativeScriptException.h"
75
#include "ffi/Tasks.h"
6+
#include "js_native_api.h"
7+
#include "jsr.h"
88

99
using namespace nativescript;
1010

@@ -44,9 +44,7 @@ - (void)runMainApplication {
4444
userInfo:nil];
4545
} catch (const std::exception& e) {
4646
NSLog(@"NativeScript runMainApplication failed: %s", e.what());
47-
@throw [NSException exceptionWithName:@"NativeScriptException"
48-
reason:@(e.what())
49-
userInfo:nil];
47+
@throw [NSException exceptionWithName:@"NativeScriptException" reason:@(e.what()) userInfo:nil];
5048
}
5149
runtime_->RunLoop();
5250
Tasks::Drain();
@@ -72,8 +70,7 @@ - (bool)liveSync {
7270
}
7371

7472
bool hasLiveSyncCallback = false;
75-
if (napi_has_named_property(env, global, "__onLiveSync",
76-
&hasLiveSyncCallback) != napi_ok ||
73+
if (napi_has_named_property(env, global, "__onLiveSync", &hasLiveSyncCallback) != napi_ok ||
7774
!hasLiveSyncCallback) {
7875
return false;
7976
}
@@ -84,8 +81,7 @@ - (bool)liveSync {
8481
}
8582

8683
napi_valuetype callbackType;
87-
if (napi_typeof(env, callback, &callbackType) != napi_ok ||
88-
callbackType != napi_function) {
84+
if (napi_typeof(env, callback, &callbackType) != napi_ok || callbackType != napi_function) {
8985
return false;
9086
}
9187

@@ -98,8 +94,7 @@ - (bool)liveSync {
9894
napi_status status = napi_call_function(env, global, callback, 1, &context, &result);
9995
if (status != napi_ok) {
10096
bool hasPendingException = false;
101-
if (napi_is_exception_pending(env, &hasPendingException) == napi_ok &&
102-
hasPendingException) {
97+
if (napi_is_exception_pending(env, &hasPendingException) == napi_ok && hasPendingException) {
10398
napi_value error;
10499
napi_get_and_clear_last_exception(env, &error);
105100
}
@@ -110,8 +105,7 @@ - (bool)liveSync {
110105

111106
if (result != nullptr) {
112107
napi_valuetype returnType;
113-
if (napi_typeof(env, result, &returnType) == napi_ok &&
114-
returnType == napi_boolean) {
108+
if (napi_typeof(env, result, &returnType) == napi_ok && returnType == napi_boolean) {
115109
bool callbackResult = false;
116110
if (napi_get_value_bool(env, result, &callbackResult) == napi_ok) {
117111
didInvokeCallback = callbackResult;

TestFixtures/Api/TNSApi.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@ typedef UIColor TNSPlatformColor;
99
#endif
1010

1111
typedef NS_ENUM(NSInteger, TNSEnums) {
12-
TNSEnum1 = -1,
13-
TNSEnum2,
14-
TNSEnum3,
12+
TNSEnum1 = -1,
13+
TNSEnum2,
14+
TNSEnum3,
1515
};
1616

1717
typedef NS_OPTIONS(NSInteger, TNSOptions) {
18-
TNSOption1 = 1 << 0,
19-
TNSOption2 = 1 << 1,
20-
TNSOption3 = 1 << 2,
18+
TNSOption1 = 1 << 0,
19+
TNSOption2 = 1 << 1,
20+
TNSOption3 = 1 << 2,
2121
};
2222

23-
enum {
24-
AnonymousEnumField = -1
25-
};
23+
enum { AnonymousEnumField = -1 };
2624

2725
extern NSString* const TNSConstant;
2826

@@ -37,7 +35,7 @@ void functionThrowsException();
3735
@property(getter=customGetter, setter=customSetter:) int property;
3836

3937
typedef TNSPlatformColor NIKColor;
40-
@property(strong, nonatomic) NIKColor* strokeColor; // ^{UIColor=#}
38+
@property(strong, nonatomic) NIKColor* strokeColor; // ^{UIColor=#}
4139

4240
+ (void)methodThrowsException;
4341
- (void)methodThrowsException;
@@ -80,5 +78,5 @@ typedef TNSPlatformColor NIKColor;
8078
- (CGRect)getRect;
8179
@end
8280

83-
@interface RectClass : NSObject<RectProtocol>
81+
@interface RectClass : NSObject <RectProtocol>
8482
@end

TestFixtures/Api/TNSVersions.h

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
#import <Foundation/Foundation.h>
22

3-
#define generateVersionDeclarations(V1, V2) \
4-
__attribute__((availability(ios, introduced = V1))) \
5-
__attribute__((availability(visionos, introduced = V1))) @interface TNSInterface \
6-
##V2##Plus : NSObject @end \
7-
\
8-
@interface TNSInterfaceMembers \
9-
##V2 : NSObject @property int property __attribute__((availability(ios, introduced = V1))) \
10-
__attribute__((availability(visionos, introduced = V1))); \
11-
\
12-
+(void)staticMethod __attribute__((availability(ios, introduced = V1))) \
13-
__attribute__((availability(visionos, introduced = V1))); \
14-
\
15-
-(void)instanceMethod __attribute__((availability(ios, introduced = V1))) \
16-
__attribute__((availability(visionos, introduced = V1))); \
17-
@end \
18-
\
19-
__attribute__((availability(ios, introduced = V1))) \
20-
__attribute__((availability(visionos, introduced = V1))) void TNSFunction##V2##Plus(); \
21-
\
22-
__attribute__((availability(ios, introduced = V1))) __attribute__( \
23-
(availability(visionos, introduced = V1))) extern const int TNSConstant##V2##Plus; \
24-
\
25-
enum TNSEnum##V2##Plus { TNSEnum##V2##Member } \
26-
__attribute__((availability(ios, introduced = V1))) \
27-
__attribute__((availability(visionos, introduced = V1)))
3+
#define generateVersionDeclarations(V1, V2) \
4+
__attribute__((availability(ios, introduced = V1))) \
5+
__attribute__((availability(visionos, introduced = V1))) \
6+
__attribute__((availability(macos, introduced = V1))) \
7+
@interface TNSInterface \
8+
##V2##Plus : NSObject @end \
9+
\
10+
@interface TNSInterfaceMembers \
11+
##V2 : NSObject @property int property __attribute__((availability(ios, introduced = V1))) \
12+
__attribute__((availability(visionos, introduced = V1))) \
13+
__attribute__((availability(macos, introduced = V1))); \
14+
\
15+
+(void)staticMethod __attribute__((availability(ios, introduced = V1))) \
16+
__attribute__((availability(visionos, introduced = V1))) \
17+
__attribute__((availability(macos, introduced = V1))); \
18+
\
19+
-(void)instanceMethod __attribute__((availability(ios, introduced = V1))) \
20+
__attribute__((availability(visionos, introduced = V1))) \
21+
__attribute__((availability(macos, introduced = V1))); \
22+
@end \
23+
\
24+
__attribute__((availability(ios, introduced = V1))) \
25+
__attribute__((availability(visionos, introduced = V1))) \
26+
__attribute__((availability(macos, introduced = V1))) void \
27+
TNSFunction##V2##Plus(); \
28+
\
29+
__attribute__((availability(ios, introduced = V1))) \
30+
__attribute__((availability(visionos, introduced = V1))) \
31+
__attribute__((availability(macos, introduced = V1))) extern const int TNSConstant##V2##Plus; \
32+
\
33+
enum TNSEnum##V2##Plus { TNSEnum##V2##Member } \
34+
__attribute__((availability(ios, introduced = V1))) \
35+
__attribute__((availability(visionos, introduced = V1))) \
36+
__attribute__((availability(macos, introduced = V1)))
2837

2938
#ifndef generateVersionImpl
3039
#define generateVersion(V1, V2) generateVersionDeclarations(V1, V2)
@@ -70,6 +79,7 @@ generateMinors(15);
7079

7180
__attribute__((availability(ios, introduced = MAX_AVAILABILITY)))
7281
__attribute__((availability(visionos, introduced = MAX_AVAILABILITY)))
82+
__attribute__((availability(macos, introduced = MAX_AVAILABILITY)))
7383
@protocol TNSProtocolNeverAvailable<NSObject>
7484

7585
@property(class, readonly) int staticPropertyFromProtocolNeverAvailable;
@@ -88,6 +98,7 @@ __attribute__((availability(visionos, introduced = MAX_AVAILABILITY)))
8898

8999
__attribute__((availability(ios, introduced = 1.0)))
90100
__attribute__((availability(visionos, introduced = 1.0)))
101+
__attribute__((availability(macos, introduced = 1.0)))
91102
@protocol TNSProtocolAlwaysAvailable<NSObject>
92103

93104
@property(class, readonly) int staticPropertyFromProtocolAlwaysAvailable;
@@ -106,6 +117,7 @@ __attribute__((availability(visionos, introduced = 1.0)))
106117

107118
__attribute__((availability(ios, introduced = MAX_AVAILABILITY)))
108119
__attribute__((availability(visionos, introduced = MAX_AVAILABILITY)))
120+
__attribute__((availability(macos, introduced = MAX_AVAILABILITY)))
109121
@interface TNSInterfaceNeverAvailable : TNSInterfaceAlwaysAvailable
110122
@end
111123

0 commit comments

Comments
 (0)