Repository navigation
Expand file tree
/
Copy pathUtil.mm
More file actions
121 lines (93 loc) · 2.32 KB
/
Copy pathUtil.mm
File metadata and controls
121 lines (93 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "Util.h"
#include "Metadata.h"
#include "js_native_api.h"
#include "js_native_api_types.h"
using namespace metagen;
namespace objc_bridge {
std::string implicitSetterSelector(std::string name) {
std::string setter;
setter += "set";
setter += toupper(name[0]);
setter += name.substr(1);
setter += ":";
return setter;
}
std::string jsifySelector(std::string selector) {
std::string jsifiedSelector;
bool nextupper = false;
for (auto c : selector) {
if (c == ':') {
nextupper = true;
} else if (nextupper) {
jsifiedSelector += toupper(c);
nextupper = false;
} else {
jsifiedSelector += c;
}
}
return jsifiedSelector;
}
napi_value jsSymbolFor(napi_env env, const char *string) {
napi_value global, Symbol, SymbolFor, symbol, symbolString;
napi_get_global(env, &global);
napi_get_named_property(env, global, "Symbol", &Symbol);
napi_get_named_property(env, Symbol, "for", &SymbolFor);
napi_create_string_utf8(env, string, NAPI_AUTO_LENGTH, &symbolString);
napi_call_function(env, global, SymbolFor, 1, &symbolString, &symbol);
return symbol;
}
char name_buf[512];
std::string getEncodedType(napi_env env, napi_value value) {
napi_valuetype type;
napi_typeof(env, value, &type);
switch (type) {
case napi_number: {
int32_t number = -1;
napi_get_value_int32(env, value, &number);
switch (number) {
case mdTypeVoid:
return "v";
case mdTypeBool:
return "B";
case mdTypeChar:
return "c";
case mdTypeUInt8:
return "C";
case mdTypeSShort:
return "s";
case mdTypeUShort:
return "S";
case mdTypeSInt:
return "i";
case mdTypeUInt:
return "I";
case mdTypeSInt64:
return "q";
case mdTypeUInt64:
return "Q";
case mdTypeFloat:
return "f";
case mdTypeDouble:
return "d";
case mdTypeString:
return "*";
case mdTypeAnyObject:
return "@";
case mdTypePointer:
return "^v";
case mdTypeSelector:
return ":";
default:
napi_throw_error(env, nullptr, "Invalid type");
return "v";
}
}
case napi_function:
// Must be a native class constructor like NSObject.
return "@";
default:
napi_throw_error(env, nullptr, "Invalid type");
return "v";
}
}
} // namespace objc_bridge