Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions NativeScript/runtime/ArgConverter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -883,16 +883,18 @@

ObjCDataWrapper* objcDataWrapper = static_cast<ObjCDataWrapper*>(wrapper);
id target = objcDataWrapper->Data();
if (![target isKindOfClass:[NSArray class]]) {
// Treat anything that can report a count and return elements by index as
// indexable, not just NSArray (e.g. PHFetchResult, NSOrderedSet).
if (![target respondsToSelector:@selector(count)] ||
![target respondsToSelector:@selector(objectAtIndex:)]) {
return;
}

NSArray* array = (NSArray*)target;
if (index >= [array count]) {
if (index >= [target count]) {
return;
}

id obj = [array objectAtIndex:index];
id obj = [target objectAtIndex:index];

std::shared_ptr<Caches> cache = Caches::Get(isolate);
auto it = cache->Instances.find(obj);
Expand Down
14 changes: 14 additions & 0 deletions TestRunner/app/tests/ApiTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ describe(module.id, function () {
expect(res[0].constructor.name).toEqual("NSURL");
});

it("indexed access works for non-NSArray indexable collections", function () {
// NSOrderedSet is not an NSArray but responds to count + objectAtIndex:,
// so obj[i] should resolve the same elements as objectAtIndex(i).
const set = NSOrderedSet.orderedSetWithArray(['a', 'b', 'c']);
expect(set.count).toBe(3);
expect(set[0]).toBe(set.objectAtIndex(0));
expect(set[1]).toBe(set.objectAtIndex(1));
expect(set[2]).toBe(set.objectAtIndex(2));
expect(set[0]).toBe('a');
expect(set[2]).toBe('c');
// Out-of-range index returns undefined instead of throwing.
expect(set[3]).toBeUndefined();
});

it("MethodCalledInDealloc", function () {
expect(function () {
(function () {
Expand Down
Loading