Skip to content

Commit eb96f85

Browse files
committed
switch to objc++
1 parent 43093ac commit eb96f85

18 files changed

Lines changed: 418 additions & 125 deletions

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ NativeScript for macOS.app/
99
libffi/build_*
1010
libffi/darwin_*
1111
libffi/x86_64-*
12+
/compile_commands.json
1213
.cache/

‎CMakeLists.txt‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ include_directories(
7070

7171
set(LIB_SOURCE_FILES
7272
src/objc.mm
73-
src/bridge.cc
74-
src/class.cc
75-
src/closure.cc
76-
src/bridged_class.cc
77-
src/bridged_method.cc
78-
src/method_cif.cc
79-
src/objc_bridge_data.cc
80-
src/type_conv.cc
81-
src/util.cc
73+
src/bridge.mm
74+
src/class.mm
75+
src/closure.mm
76+
src/bridged_class.mm
77+
src/bridged_method.mm
78+
src/method_cif.mm
79+
src/objc_bridge_data.mm
80+
src/type_conv.mm
81+
src/util.mm
8282
)
8383

8484
add_library(

‎deno.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"app": {
33
"name": "NativeScript for macOS",
44
"identifier": "com.nativescript.AppKit",
5-
"entryPoint": "test/split_view.js",
5+
"entryPoint": "test/spritekit.js",
66
"assets": "./assets",
77
"icon": "./assets/NativeScript.icns",
88
"version": "0.1.0"

‎include/node_api_util.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
NAPI_ERROR_INFO \
2929
napi_throw_error(env, NULL, error_info->error_message);
3030

31-
#ifndef DEBUG
31+
#ifdef DEBUG
3232

3333
#define NAPI_GUARD(expr) \
3434
status = expr; \

‎include/util.h‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,4 @@
88
std::string implicitSetterSelector(std::string name);
99
std::string jsifySelector(std::string selector);
1010

11-
class sel {
12-
public:
13-
static SEL signatureWithObjCTypes_;
14-
static SEL numberOfArguments;
15-
static SEL methodReturnType;
16-
static SEL methodReturnLength;
17-
static SEL getArgumentTypeAtIndex_;
18-
static SEL frameLength;
19-
static SEL release;
20-
static SEL length;
21-
static SEL description;
22-
static SEL UTF8String;
23-
};
24-
25-
typedef id (*msgSend_signatureWithObjCTypes)(id, SEL, const char *);
26-
typedef unsigned long (*msgSend_numberOfArguments)(id, SEL);
27-
typedef const char *(*msgSend_methodReturnType)(id, SEL);
28-
typedef const char *(*msgSend_methodGetArgumentType)(id, SEL, unsigned int);
29-
typedef void (*msgSend_release)(id, SEL);
30-
typedef id (*msgSend_description)(id, SEL);
31-
typedef char *(*msgSend_UTF8String)(id, SEL);
32-
typedef unsigned long (*msgSend_length)(id, SEL);
33-
34-
class ObjC {
35-
public:
36-
static void release(id object) noexcept {
37-
((msgSend_release)objc_msgSend)(object, sel::release);
38-
}
39-
};
40-
4111
#endif /* UTIL_H */

‎lib/inline_functions.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ export function NSMakeRect(x, y, width, height) {
55
export function NSMakeSize(width, height) {
66
return new Float64Array([width, height]);
77
}
8+
9+
export function CGRectGetMidX(rect) {
10+
rect = new Float64Array(rect);
11+
return rect[0] + rect[2] / 2;
12+
}
13+
14+
export function CGRectGetMidY(rect) {
15+
rect = new Float64Array(rect);
16+
return rect[1] + rect[3] / 2;
17+
}
File renamed without changes.
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include "node_api_util.h"
44
#include "util.h"
55

6+
#import <Foundation/Foundation.h>
7+
#include <string>
8+
69
NAPI_FUNCTION(BridgedConstructor) {
710
NAPI_CALLBACK_BEGIN(0)
811

@@ -92,9 +95,8 @@ NAPI_FUNCTION(CustomInspect) {
9295
id self;
9396
napi_unwrap(env, jsThis, (void **)&self);
9497

95-
id description = ((msgSend_description)objc_msgSend)(self, sel::description);
96-
char *descriptionString =
97-
((msgSend_UTF8String)objc_msgSend)(description, sel::UTF8String);
98+
auto description = [self description];
99+
auto descriptionString = [description UTF8String];
98100

99101
napi_value result;
100102
napi_create_string_utf8(env, descriptionString, NAPI_AUTO_LENGTH, &result);
@@ -109,7 +111,7 @@ NAPI_FUNCTION(lengthCustom) {
109111
napi_get_cb_info(env, cbinfo, nil, nil, &jsThis, &data);
110112
id self;
111113
napi_unwrap(env, jsThis, (void **)&self);
112-
unsigned long length = ((msgSend_length)objc_msgSend)(self, sel::length);
114+
auto length = [self length];
113115
napi_value result;
114116
napi_create_int64(env, length, &result);
115117
return result;
@@ -294,7 +296,8 @@ BridgedClass::BridgedClass(napi_env env, std::string name) {
294296
bool isNativeObject = name == NativeObjectName;
295297

296298
if (nativeClass == nil && !isNativeObject) {
297-
napi_throw_error(env, nil, "Objective-C class not found");
299+
std::string msg = "Objective-C class not found: " + name;
300+
napi_throw_error(env, nil, msg.c_str());
298301
return;
299302
}
300303

File renamed without changes.

0 commit comments

Comments
 (0)