Skip to content

Commit e1a99a0

Browse files
committed
fix type conversion
1 parent 15f0b60 commit e1a99a0

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

NativeScript/ffi/Object.mm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ void finalize_objc_object(napi_env /*env*/, void* data, void* hint) {
178178
return nullptr;
179179
}
180180

181-
napi_value orig = result;
182-
183181
if (ownership == kUnownedObject) {
184182
[obj retain];
185183
}

NativeScript/ffi/TypeConv.mm

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "js_native_api_types.h"
1313
#include "node_api_util.h"
1414

15-
#import <Foundation/Foundation.h>
1615
#import <CoreFoundation/CoreFoundation.h>
16+
#import <Foundation/Foundation.h>
1717
#include <objc/runtime.h>
1818
#include <stdbool.h>
1919
#include <memory>
@@ -551,12 +551,13 @@ void toNative(napi_env env, napi_value value, void* result, bool* shouldFree,
551551

552552
// Check if we need to create a CFStringRef instead of a C string
553553
// if (pointeeType && pointeeType->kind == mdTypeNSStringObject) {
554-
// Create CFStringRef for CF/NS string pointers
555-
CFStringRef cfStr = CFStringCreateWithCString(kCFAllocatorDefault, str, kCFStringEncodingUTF8);
556-
::free(str); // Free the temporary C string
557-
*res = (void*)cfStr;
558-
*shouldFree = false; // CFStringRef is reference counted, don't use free()
559-
*shouldFreeAny = false;
554+
// Create CFStringRef for CF/NS string pointers
555+
CFStringRef cfStr =
556+
CFStringCreateWithCString(kCFAllocatorDefault, str, kCFStringEncodingUTF8);
557+
::free(str); // Free the temporary C string
558+
*res = (void*)cfStr;
559+
*shouldFree = false; // CFStringRef is reference counted, don't use free()
560+
*shouldFreeAny = false;
560561
// } else {
561562
// // Default behavior: return C string
562563
// *res = (void*)str;
@@ -625,7 +626,7 @@ void toNative(napi_env env, napi_value value, void* result, bool* shouldFree,
625626
}
626627

627628
default:
628-
NSLog(@"value %d", type);
629+
NSLog(@"value %d", type);
629630
napi_throw_error(env, nullptr, "Invalid pointer type");
630631
*res = nullptr;
631632
return;
@@ -987,23 +988,21 @@ void toNative(napi_env env, napi_value value, void* result, bool* shouldFree,
987988

988989
case napi_object:
989990
case napi_function: {
990-
status = napi_unwrap(env, value, (void**)res);
991+
if (Pointer::isInstance(env, value)) {
992+
Pointer* ptr = Pointer::unwrap(env, value);
993+
*res = (id)ptr->data;
994+
return;
995+
}
991996

992-
if (status != napi_ok) {
993-
// Check if this is a Pointer instance and use its underlying data
994-
if (Pointer::isInstance(env, value)) {
995-
Pointer* ptr = Pointer::unwrap(env, value);
996-
*res = (id)ptr->data;
997-
return;
998-
}
997+
if (Reference::isInstance(env, value)) {
998+
Reference* ref = Reference::unwrap(env, value);
999+
*res = (id)ref->data;
1000+
return;
1001+
}
9991002

1000-
// Check if this is a Reference instance and use its underlying data
1001-
if (Reference::isInstance(env, value)) {
1002-
Reference* ref = Reference::unwrap(env, value);
1003-
*res = (id)ref->data;
1004-
return;
1005-
}
1003+
status = napi_unwrap(env, value, (void**)res);
10061004

1005+
if (status != napi_ok) {
10071006
bool isArray = false;
10081007
napi_is_array(env, value, &isArray);
10091008
if (isArray) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nativescript/ios",
33
"description": "NativeScript Runtime for iOS",
4-
"version": "8.9.0",
4+
"version": "8.9.0-napi-v8.1",
55
"keywords": [
66
"NativeScript",
77
"iOS",

0 commit comments

Comments
 (0)