Skip to content

Commit 8786f80

Browse files
committed
fix(bridge): Don't read JS properties without obtaining a lock
In `TNSArrayAdapter`'s `countByEnumeratingWithState` we need to obtain a JS engine lock before accessing properties of the JS array(-like) object.
1 parent bdfdd9c commit 8786f80

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/NativeScript/ObjC/TNSArrayAdapter.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ - (id)objectAtIndex:(NSUInteger)index {
5555

5656
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state objects:(id[])buffer count:(NSUInteger)len {
5757
RELEASE_ASSERT_WITH_MESSAGE([TNSRuntime runtimeForVM:self->_vm], "The runtime is deallocated.");
58+
59+
JSLockHolder lock(self->_execState);
60+
5861
if (state->state == 0) { // uninitialized
5962
state->state = 1;
6063
state->mutationsPtr = reinterpret_cast<unsigned long*>(self);
@@ -67,7 +70,6 @@ - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state objects
6770
NSUInteger count = 0;
6871
state->itemsPtr = buffer;
6972

70-
JSLockHolder lock(self->_execState);
7173
while (count < len && currentIndex < length) {
7274
*buffer++ = toObject(self->_execState, self->_object->get(self->_execState, currentIndex));
7375
currentIndex++;

0 commit comments

Comments
 (0)