fix(ios): fix conversion crash from oc object to CtxValue

This commit is contained in:
wwwcg
2024-03-29 17:10:09 +08:00
committed by wwwcg
parent 88152dbda7
commit 11ebce75c8
3 changed files with 99 additions and 4 deletions
+7 -2
View File
@@ -32,7 +32,7 @@
- (CtxValuePtr)convertToCtxValue:(const CtxPtr &)context; {
@autoreleasepool {
HippyLogWarn(@"%@ must implemente convertToCtxValue method", NSStringFromClass([self class]));
HippyLogWarn(@"%@ No convertToCtxValue method", NSStringFromClass([self class]));
std::unordered_map<CtxValuePtr, CtxValuePtr> valueMap;
return context->CreateObject(valueMap);
}
@@ -87,7 +87,9 @@
id value = [self objectForKey:key];
auto keyPtr = [key convertToCtxValue:context];
auto valuePtr = [value convertToCtxValue:context];
valueMap[keyPtr] = valuePtr;
if (keyPtr && valuePtr) {
valueMap[keyPtr] = valuePtr;
}
}
return context->CreateObject(valueMap);
}
@@ -99,6 +101,9 @@
- (CtxValuePtr)convertToCtxValue:(const CtxPtr &)context {
size_t bufferLength = [self length];
if (bufferLength == 0) {
return context->CreateNull();
}
void *buffer = malloc(bufferLength);
if (buffer) {
[self getBytes:buffer length:bufferLength];