@@ -336,65 +336,65 @@ Reference::DataPair Reference::GetDataPair(Local<Object> obj) {
336336 BaseDataWrapper* wrapper = tns::GetValue (isolate, obj);
337337 tns::Assert (wrapper != nullptr && wrapper->Type () == WrapperType::Reference, isolate);
338338 ReferenceWrapper* refWrapper = static_cast <ReferenceWrapper*>(wrapper);
339-
340339 BaseDataWrapper* typeWrapper = refWrapper->TypeWrapper ();
341- if (typeWrapper == nullptr ) {
342- // TODO: Missing type when creating the Reference instance
343- tns::Assert (false , isolate);
344- }
345340
346341 size_t size = 0 ;
347- const TypeEncoding* typeEncoding = nullptr ;
348- bool isUnknownType = false ;
349-
350- if (Reference::IsSupportedType (typeWrapper->Type ())) {
351- switch (typeWrapper->Type ()) {
352- case WrapperType::Primitive: {
353- PrimitiveDataWrapper* primitiveWrapper = static_cast <PrimitiveDataWrapper*>(typeWrapper);
354-
355- size = primitiveWrapper->Size ();
356- typeEncoding = primitiveWrapper->TypeEncoding ();
357- break ;
358- }
359- case WrapperType::StructType: {
360- StructTypeWrapper* structTypeWrapper = static_cast <StructTypeWrapper*>(refWrapper->TypeWrapper ());
361- StructInfo structInfo = structTypeWrapper->StructInfo ();
362-
363- size = structInfo.FFIType ()->size ;
364- break ;
365- }
366- default : {
367- isUnknownType = true ;
368- break ;
342+
343+ if (typeWrapper != nullptr ) {
344+ const TypeEncoding* typeEncoding = nullptr ;
345+
346+ if (Reference::IsSupportedType (typeWrapper->Type ())) {
347+ switch (typeWrapper->Type ()) {
348+ case WrapperType::Primitive: {
349+ PrimitiveDataWrapper* primitiveWrapper = static_cast <PrimitiveDataWrapper*>(typeWrapper);
350+
351+ size = primitiveWrapper->Size ();
352+ typeEncoding = primitiveWrapper->TypeEncoding ();
353+ break ;
354+ }
355+ case WrapperType::StructType: {
356+ StructTypeWrapper* structTypeWrapper = static_cast <StructTypeWrapper*>(refWrapper->TypeWrapper ());
357+ StructInfo structInfo = structTypeWrapper->StructInfo ();
358+
359+ size = structInfo.FFIType ()->size ;
360+ break ;
361+ }
362+ default : {
363+ break ;
364+ }
369365 }
366+ } else {
367+ // TODO: Currently only PrimitiveDataWrappers and Structs are supported as type parameters
368+ // Objective C class classes should also be handled
369+ tns::Assert (false , isolate);
370370 }
371- } else {
372- isUnknownType = true ;
373- }
374-
375- if (isUnknownType) {
376- // TODO: Currently only PrimitiveDataWrappers and Structs are supported as type parameters
377- // Objective C class classes should also be handled
378- tns::Assert (false , isolate);
379- }
380371
381- Local<Value> value = refWrapper->Value ()->Get (isolate);
382- BaseDataWrapper* wrappedValue = tns::GetValue (isolate, value);
383- if (wrappedValue != nullptr && wrappedValue->Type () == WrapperType::Pointer) {
384- PointerWrapper* pw = static_cast <PointerWrapper*>(wrappedValue);
385- void * data = pw->Data ();
372+ Local<Value> value = refWrapper->Value ()->Get (isolate);
373+ BaseDataWrapper* wrappedValue = tns::GetValue (isolate, value);
374+ if (wrappedValue != nullptr && wrappedValue->Type () == WrapperType::Pointer) {
375+ PointerWrapper* pw = static_cast <PointerWrapper*>(wrappedValue);
376+ void * data = pw->Data ();
386377
387- DataPair pair (typeWrapper, typeEncoding, data, size);
388- return pair;
378+ DataPair pair (typeWrapper, typeEncoding, data, size);
379+ return pair;
380+ }
389381 }
390382
391383 if (refWrapper->Encoding () != nullptr && refWrapper->Data () != nullptr ) {
392- DataPair pair (typeWrapper, refWrapper->Encoding (), refWrapper->Data (), size);
384+ const TypeEncoding* typeEncoding = refWrapper->Encoding ();
385+
386+ if (typeWrapper == nullptr ) {
387+ ffi_type* ffiType = FFICall::GetArgumentType (typeEncoding);
388+ size = ffiType->size ;
389+ FFICall::DisposeFFIType (ffiType, typeEncoding);
390+ }
391+
392+ DataPair pair (typeWrapper, typeEncoding, refWrapper->Data (), size);
393393 return pair;
394394 }
395395
396396 tns::Assert (false , isolate);
397- return DataPair (typeWrapper, nullptr , nullptr , 0 );
397+ return DataPair (typeWrapper, nullptr , nullptr , size );
398398}
399399
400400bool Reference::IsSupportedType (WrapperType type) {
0 commit comments