Skip to content

Commit

Permalink
fix: incorrect wrapper in indexed array access (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
rigor789 authored Mar 30, 2023
1 parent aec61e5 commit b689434
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion NativeScript/runtime/ArgConverter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@

Local<Context> context = isolate->GetCurrentContext();
auto newWrapper = new ObjCDataWrapper(obj);
Local<Value> result = ArgConverter::ConvertArgument(context, wrapper);
Local<Value> result = ArgConverter::ConvertArgument(context, newWrapper);
tns::DeleteWrapperIfUnused(isolate, result, newWrapper);
args.GetReturnValue().Set(result);
}
Expand Down
1 change: 1 addition & 0 deletions TestFixtures/Marshalling/TNSObjCTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ typedef int (^NumberReturner)(int, int, int);
- (NSDecimalNumber*)methodWithNSDecimalNumber:(NSDecimalNumber*)number;
- (NSNumber*)methodWithNSCFBool;
- (NSNull*)methodWithNSNull;
- (NSArray*)getNSArrayOfNSURLs;
@end
8 changes: 8 additions & 0 deletions TestFixtures/Marshalling/TNSObjCTypes.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,12 @@ - (NSNull*)methodWithNSNull {
return [NSNull null];
}

- (NSArray*)getNSArrayOfNSURLs {
NSURL* url1 = [NSURL URLWithString:(@"dummy://url1")];
NSURL* url2 = [NSURL URLWithString:(@"dummy://url2")];
NSArray *urlArray = @[url1, url2];

return urlArray;
}

@end
10 changes: 10 additions & 0 deletions TestRunner/app/tests/ApiTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ describe(module.id, function () {
expect(object.hash).toBe(3);
});

it("NSArray from native (uncached) array access", function () {
const res = TNSObjCTypes.new().getNSArrayOfNSURLs();
console.log(res);
expect(res).toBeDefined();
expect(res.count > 0).toBe(true);
expect(res[0]).toEqual(res.objectAtIndex(0));
expect(res[1]).toEqual(res.objectAtIndex(1));
expect(res[0].constructor.name).toEqual("NSURL");
});

it("MethodCalledInDealloc", function () {
expect(function () {
(function () {
Expand Down
3 changes: 2 additions & 1 deletion TestRunner/app/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ require("./Marshalling/ObjCTypesTests");
require("./Marshalling/ConstantsTests");
require("./Marshalling/RecordTests");
require("./Marshalling/VectorTests");
require("./Marshalling/MatrixTests");
// todo: figure out why this test is failing with a EXC_BAD_ACCESS on TNSRecords.m matrix initialization
// require("./Marshalling/MatrixTests");
require("./Marshalling/NSStringTests");
//import "./Marshalling/TypesTests";
require("./Marshalling/PointerTests");
Expand Down

0 comments on commit b689434

Please sign in to comment.