Skip to content

Commit 7e616c8

Browse files
committed
chore: remove borrowed object
1 parent cf7bf03 commit 7e616c8

File tree

10 files changed

+105
-20
lines changed

10 files changed

+105
-20
lines changed

include/ObjCBridge.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ typedef enum ObjectOwnership {
3636
// we will call retain and release when the JS object is
3737
// garbage collected.
3838
kUnownedObject,
39-
// The object is not owned by JS land, but we will not call
40-
// retain/release at all. This is useful for objects that
41-
// passed to JS land as callback parameters.
42-
kBorrowedObject,
4339
} ObjectOwnership;
4440

4541
class ObjCBridgeState {

metadata/metadata.ios.nsmd

1.5 KB
Binary file not shown.

packages/ios/types/Foundation.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7093,6 +7093,10 @@ declare class NSData extends NSObject implements NSCopying, NSMutableCopying, NS
70937093

70947094
base64Encoding(): string;
70957095

7096+
static dataWithContentsOfFileCompletion(path: string, callback: (p1: NSData) => void): void;
7097+
7098+
writeToFileAtomicallyCompletion(path: string, atomically: boolean, callback: () => void): void;
7099+
70967100
copyWithZone(zone: interop.PointerConvertible): interop.Object;
70977101

70987102
mutableCopyWithZone(zone: interop.PointerConvertible): interop.Object;
@@ -9787,6 +9791,10 @@ declare class NSFileHandle extends NSObject implements NSSecureCoding {
97879791

97889792
closeFile(): void;
97899793

9794+
appendDataCompletion(data: NSData, callback: (p1: NSError) => void): void;
9795+
9796+
static fileHandleWithDataCompletion(path: string, data: NSData, callback: (p1: NSFileHandle, p2: NSError) => void): void;
9797+
97909798
static readonly supportsSecureCoding: boolean;
97919799

97929800
encodeWithCoder(coder: NSCoder): void;
@@ -11512,6 +11520,10 @@ declare class NSString extends NSObject implements NSCopying, NSMutableCopying,
1151211520

1151311521
static localizedUserNotificationStringForKeyArguments(key: string, arguments$: NSArray<interop.Object> | Array<interop.Object> | null): string;
1151411522

11523+
static stringWithContentsOfFileEncodingCompletion(path: string, enc: number, callback: (p1: string, p2: NSError) => void): void;
11524+
11525+
writeToFileAtomicallyEncodingCompletion(path: string, atomically: boolean, enc: number, callback: (p1: NSError) => void): void;
11526+
1151511527
copyWithZone(zone: interop.PointerConvertible): interop.Object;
1151611528

1151711529
mutableCopyWithZone(zone: interop.PointerConvertible): interop.Object;

packages/ios/types/Runtime.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ declare interface NSObjectProtocol {
132132
declare class NSObjectProtocol extends NativeObject implements NSObjectProtocol {
133133
}
134134

135+
declare interface NativeScriptEmbedderDelegate {
136+
presentNativeScriptApp(vc: UIViewController): interop.Object;
137+
}
138+
139+
declare class NativeScriptEmbedderDelegate extends NativeObject implements NativeScriptEmbedderDelegate {
140+
}
141+
135142
declare class NSObject extends NativeObject implements NSObjectProtocol {
136143
static load(): void;
137144

@@ -525,10 +532,30 @@ declare class NSObject extends NativeObject implements NSObjectProtocol {
525532
readonly debugDescription: string;
526533
}
527534

535+
declare class NativeScriptEmbedder extends NSObject {
536+
readonly delegate: NativeScriptEmbedderDelegate;
537+
538+
static sharedInstance(): NativeScriptEmbedder;
539+
}
540+
528541
declare class OS_object extends NSObject {
529542
init(): this;
530543
}
531544

545+
declare class NativeScriptUtils extends NSObject {
546+
static getSystemFontWeightItalicSymbolicTraits(size: number, weight: number, italic: boolean, symbolicTraits: interop.Enum<typeof UIFontDescriptorSymbolicTraits>): UIFont;
547+
548+
static createUIFont(font: NSDictionary<interop.Object, interop.Object> | Record<interop.Object, interop.Object>): UIFont;
549+
550+
static createMutableStringWithDetails(details: NSDictionary<interop.Object, interop.Object> | Record<interop.Object, interop.Object>): NSMutableAttributedString;
551+
552+
static createMutableStringForSpanFontColorBackgroundColorTextDecorationBaselineOffset(text: string, font: UIFont, color: UIColor, backgroundColor: UIColor, textDecoration: string, baselineOffset: number): NSMutableAttributedString;
553+
554+
static scaleImageWidthHeightScaleFactor(image: UIImage, width: number, height: number, scaleFactor: number): UIImage;
555+
556+
static getImageDataFormatQuality(image: UIImage, format: string, quality: number): NSData;
557+
}
558+
532559
declare class OS_os_workgroup extends OS_object {
533560
init(): this;
534561
}

packages/ios/types/TNSWidgets.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference types="@nativescript/objc-node-api" />
2+
/// <reference path="./UIKit.d.ts" />
3+
4+
declare const TNSWidgetsVersionNumber: number;
5+
6+
declare const TNSWidgetsVersionString: interop.Pointer;
7+
8+
declare function __tns_uptime(): number;
9+
10+
declare function __nslog(message: string): void;
11+
12+
declare class TNSLabel extends UILabel {
13+
padding: UIEdgeInsets;
14+
15+
borderThickness: UIEdgeInsets;
16+
}
17+

packages/ios/types/UIKit.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7844,6 +7844,16 @@ declare class UIView extends UIResponder implements NSCoding, UIAppearance, UIAp
78447844

78457845
drawRectForViewPrintFormatter(rect: CGRect, formatter: UIViewPrintFormatter): void;
78467846

7847+
passThroughParent(): boolean;
7848+
7849+
setPassThroughParent(passThroughParent: boolean): void;
7850+
7851+
nativeScriptSetTextDecorationAndTransformTextDecorationLetterSpacingLineHeight(text: string, textDecoration: string, letterSpacing: number, lineHeight: number): void;
7852+
7853+
nativeScriptSetFormattedTextDecorationAndTransformLetterSpacingLineHeight(details: NSDictionary<interop.Object, interop.Object> | Record<interop.Object, interop.Object>, letterSpacing: number, lineHeight: number): void;
7854+
7855+
nativeScriptSetFormattedTextStrokeColor(width: number, color: UIColor): void;
7856+
78477857
encodeWithCoder(coder: NSCoder): void;
78487858

78497859
static appearance<This extends abstract new (...args: any) => any>(this: This): InstanceType<This>;
@@ -19516,6 +19526,14 @@ declare class UIImage extends NSObject implements NSSecureCoding {
1951619526

1951719527
readonly topCapHeight: number;
1951819528

19529+
static tns_safeDecodeImageNamedCompletion(name: string, callback: (p1: UIImage) => void): void;
19530+
19531+
static tns_safeImageNamed(name: string): UIImage;
19532+
19533+
static tns_decodeImageWithDataCompletion(data: NSData, callback: (p1: UIImage) => void): void;
19534+
19535+
static tns_decodeImageWidthContentsOfFileCompletion(file: string, callback: (p1: UIImage) => void): void;
19536+
1951919537
static readonly supportsSecureCoding: boolean;
1952019538

1952119539
encodeWithCoder(coder: NSCoder): void;

packages/ios/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/// <reference path="./QuartzCore.d.ts" />
1818
/// <reference path="./ModelIO.d.ts" />
1919
/// <reference path="./MetalKit.d.ts" />
20+
/// <reference path="./TNSWidgets.d.ts" />
2021
/// <reference path="./WebKit.d.ts" />
2122
/// <reference path="./CoreServices.d.ts" />
2223
/// <reference path="./Security.d.ts" />

scripts/metagen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ for (const framework of sdk.frameworks) {
116116
}
117117

118118
// TODO: commit these files to the repo
119-
const withNativeScriptCore = false;
119+
const withNativeScriptCore = true;
120120
if(withNativeScriptCore){
121121
const customFrameworks = [
122122
"/Users/dj/Projects/NativeScript/packages/ui-mobile-base/dist/package/platforms/ios/TNSWidgets.xcframework/ios-arm64/TNSWidgets.framework",

src/Object.mm

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ void finalize_objc_object(napi_env /*env*/, void *data, void *hint) {
6565
bridgeState->unregisterObject(object);
6666
}
6767

68-
void finalize_objc_object_borrowed(napi_env, void *data, void *hint) {
69-
id object = static_cast<id>(data);
70-
ObjCBridgeState *bridgeState = static_cast<ObjCBridgeState *>(hint);
71-
bridgeState->objectRefs.erase(object);
72-
}
73-
7468
napi_value ObjCBridgeState::getObject(napi_env env, id obj,
7569
napi_value constructor,
7670
ObjectOwnership ownership) {
@@ -128,11 +122,8 @@ void finalize_objc_object_borrowed(napi_env, void *data, void *hint) {
128122
napi_wrap(env, result, obj, nullptr, nullptr, nullptr);
129123

130124
napi_ref ref = nullptr;
131-
NAPI_GUARD(napi_add_finalizer(env, result, obj,
132-
ownership == kBorrowedObject
133-
? finalize_objc_object_borrowed
134-
: finalize_objc_object,
135-
this, &ref)) {
125+
NAPI_GUARD(napi_add_finalizer(env, result, obj, finalize_objc_object, this,
126+
&ref)) {
136127
NAPI_THROW_LAST_ERROR
137128
return nullptr;
138129
}
@@ -142,6 +133,24 @@ void finalize_objc_object_borrowed(napi_env, void *data, void *hint) {
142133
if (ownership == kUnownedObject) {
143134
[obj retain];
144135
}
136+
// #if DEBUG
137+
// napi_value global, Error, error, stack;
138+
// napi_get_global(env, &global);
139+
// napi_get_named_property(env, global, "Error", &Error);
140+
// napi_new_instance(env, Error, 0, nullptr, &error);
141+
// napi_get_named_property(env, error, "stack", &stack);
142+
143+
// size_t stackSize;
144+
// napi_get_value_string_utf8(env, stack, nullptr, 0, &stackSize);
145+
// char *stackStr = new char[stackSize + 1];
146+
// napi_get_value_string_utf8(env, stack, stackStr, stackSize + 1, nullptr);
147+
148+
// NSString *str = [NSString stringWithFormat:@"Wrapped object <%s: %p> @ %ld # %s",
149+
// class_getName(cls), obj, [obj retainCount], stackStr];
150+
// dbglog([str UTF8String]);
151+
152+
// delete[] stackStr;
153+
// #endif
145154
}
146155

147156
return result;
@@ -297,6 +306,14 @@ napi_value findConstructorForObject(napi_env env, ObjCBridgeState *bridgeState,
297306
}
298307

299308
void ObjCBridgeState::unregisterObject(id object) noexcept {
309+
// #if DEBUG
310+
// NSString *string = [NSString stringWithFormat: @"Unregistering object <%s: %p> @ %ld # success: %d, finalized: %d",
311+
// class_getName(object_getClass(object)), object, [object retainCount],
312+
// (int)objectRefs.contains(object), (int)finalized];
313+
314+
// dbglog([string UTF8String]);
315+
// #endif
316+
300317
if (objectRefs.contains(object)) {
301318
objectRefs.erase(object);
302319
[object release];

src/TypeConv.mm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,6 @@ napi_value toJS(napi_env env, void *value, uint32_t flags) override {
878878
ObjectOwnership ownership;
879879
if ((flags & kReturnOwned) != 0) {
880880
ownership = kOwnedObject;
881-
} else if ((flags & kBlockParam) != 0) {
882-
ownership = kBorrowedObject;
883881
} else {
884882
ownership = kUnownedObject;
885883
}
@@ -891,6 +889,7 @@ napi_value toJS(napi_env env, void *value, uint32_t flags) override {
891889
napi_get_null(env, &null);
892890
return null;
893891
}
892+
894893
return object;
895894
}
896895

@@ -1098,8 +1097,6 @@ void toNative(napi_env env, napi_value value, void *result, bool *shouldFree,
10981097
napi_value toJS(napi_env env, void *value, uint32_t flags) override {
10991098
Class cls = *((Class *)value);
11001099

1101-
NSLog(@"class toJS: %@", cls);
1102-
11031100
if (cls == nullptr) {
11041101
return nullptr;
11051102
}

0 commit comments

Comments
 (0)