|
12 | 12 | #include "js_native_api_types.h"
|
13 | 13 | #include "node_api_util.h"
|
14 | 14 |
|
15 |
| -#import <Foundation/Foundation.h> |
16 | 15 | #import <CoreFoundation/CoreFoundation.h>
|
| 16 | +#import <Foundation/Foundation.h> |
17 | 17 | #include <objc/runtime.h>
|
18 | 18 | #include <stdbool.h>
|
19 | 19 | #include <memory>
|
@@ -551,12 +551,13 @@ void toNative(napi_env env, napi_value value, void* result, bool* shouldFree,
|
551 | 551 |
|
552 | 552 | // Check if we need to create a CFStringRef instead of a C string
|
553 | 553 | // 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; |
560 | 561 | // } else {
|
561 | 562 | // // Default behavior: return C string
|
562 | 563 | // *res = (void*)str;
|
@@ -625,7 +626,7 @@ void toNative(napi_env env, napi_value value, void* result, bool* shouldFree,
|
625 | 626 | }
|
626 | 627 |
|
627 | 628 | default:
|
628 |
| - NSLog(@"value %d", type); |
| 629 | + NSLog(@"value %d", type); |
629 | 630 | napi_throw_error(env, nullptr, "Invalid pointer type");
|
630 | 631 | *res = nullptr;
|
631 | 632 | return;
|
@@ -987,23 +988,21 @@ void toNative(napi_env env, napi_value value, void* result, bool* shouldFree,
|
987 | 988 |
|
988 | 989 | case napi_object:
|
989 | 990 | 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 | + } |
991 | 996 |
|
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 | + } |
999 | 1002 |
|
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); |
1006 | 1004 |
|
| 1005 | + if (status != napi_ok) { |
1007 | 1006 | bool isArray = false;
|
1008 | 1007 | napi_is_array(env, value, &isArray);
|
1009 | 1008 | if (isArray) {
|
|
0 commit comments