|
1 | | -#include "NativeCall.h" |
| 1 | +#include "ClassMember.h" |
2 | 2 | #include "MetadataReader.h" |
3 | 3 | #include "ObjCBridge.h" |
4 | 4 | #include "TypeConv.h" |
|
12 | 12 |
|
13 | 13 | namespace objc_bridge { |
14 | 14 |
|
15 | | -NAPI_FUNCTION(CFunction) { |
16 | | - void *_offset; |
17 | | - |
18 | | - napi_get_cb_info(env, cbinfo, nullptr, nullptr, nullptr, &_offset); |
19 | | - |
20 | | - auto bridgeState = ObjCBridgeState::InstanceData(env); |
21 | | - MDSectionOffset offset = (MDSectionOffset)((size_t)_offset); |
22 | | - |
23 | | - auto func = bridgeState->getCFunction(env, offset); |
24 | | - auto cif = func->cif; |
25 | | - |
26 | | - size_t argc = cif->argc; |
27 | | - napi_get_cb_info(env, cbinfo, &argc, cif->argv, nullptr, nullptr); |
28 | | - |
29 | | - void *avalues[cif->argc]; |
30 | | - void *rvalue = cif->rvalue; |
31 | | - |
32 | | - bool shouldFreeAny = false; |
33 | | - bool shouldFree[cif->argc]; |
34 | | - |
35 | | - if (cif->argc > 0) { |
36 | | - for (unsigned int i = 0; i < cif->argc; i++) { |
37 | | - shouldFree[i] = false; |
38 | | - avalues[i] = cif->avalues[i]; |
39 | | - cif->argTypes[i]->toNative(env, cif->argv[i], avalues[i], &shouldFree[i], |
40 | | - &shouldFreeAny); |
41 | | - } |
42 | | - } |
43 | | - |
44 | | - cif->call(func->fnptr, rvalue, avalues); |
45 | | - |
46 | | - if (shouldFreeAny) { |
47 | | - for (unsigned int i = 0; i < cif->argc; i++) { |
48 | | - if (shouldFree[i]) { |
49 | | - cif->argTypes[i]->free(env, *((void **)avalues[i])); |
50 | | - } |
51 | | - } |
52 | | - } |
53 | | - |
54 | | - return cif->returnType->toJS(env, rvalue); |
55 | | -} |
56 | | - |
57 | 15 | inline void objcNativeCall(napi_env env, napi_value jsThis, MethodCif *cif, |
58 | 16 | id self, void **avalues, void *rvalue) { |
59 | 17 | // TODO: This seems bad for performance. Is there a better way? |
|
0 commit comments