Skip to content

Commit 703b755

Browse files
committed
revert: "fix: Intel simulators (#272)"
This reverts commit 0adeabf.
1 parent f9f7ac0 commit 703b755

File tree

2 files changed

+83
-42
lines changed

2 files changed

+83
-42
lines changed

NativeScript/runtime/ClassBuilder.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,34 @@
22

33
namespace tns {
44

5-
// Moved this method in a separate .cpp file because ARC destroys the class created with objc_allocateClassPair
6-
// when the control leaves this method scope
5+
// Moved this method in a separate .cpp file because ARC destroys the class
6+
// created with objc_allocateClassPair when the control leaves this method scope
77

8-
Class ClassBuilder::GetExtendedClass(std::string baseClassName, std::string staticClassName) {
9-
Class baseClass = objc_getClass(baseClassName.c_str());
10-
std::string name = !staticClassName.empty() ? staticClassName : baseClassName + "_" + std::to_string(++ClassBuilder::classNameCounter_);
11-
Class clazz = objc_getClass(name.c_str());
8+
Class ClassBuilder::GetExtendedClass(std::string baseClassName,
9+
std::string staticClassName) {
10+
Class baseClass = objc_getClass(baseClassName.c_str());
11+
std::string name =
12+
!staticClassName.empty()
13+
? staticClassName
14+
: baseClassName + "_" +
15+
std::to_string(++ClassBuilder::classNameCounter_);
16+
// here we could either call objc_getClass with the name to see if the class
17+
// already exists or we can just try allocating it, which will return nil if
18+
// the class already exists so we try allocating it every time to avoid race
19+
// conditions in case this method is being executed by multiple threads
20+
Class clazz = objc_allocateClassPair(baseClass, name.c_str(), 0);
1221

13-
if (clazz != nil) {
14-
int i = 1;
15-
std::string initialName = name;
16-
while (clazz != nil) {
17-
name = initialName + std::to_string(i++);
18-
clazz = objc_getClass(name.c_str());
19-
}
22+
if (clazz == nil) {
23+
int i = 1;
24+
std::string initialName = name;
25+
while (clazz == nil) {
26+
name = initialName + std::to_string(i++);
27+
clazz = objc_allocateClassPair(baseClass, name.c_str(), 0);
2028
}
29+
}
2130

22-
clazz = objc_allocateClassPair(baseClass, name.c_str(), 0);
23-
24-
objc_registerClassPair(clazz);
25-
return clazz;
31+
objc_registerClassPair(clazz);
32+
return clazz;
2633
}
2734

28-
}
35+
} // namespace tns

NativeScript/runtime/ClassBuilder.mm

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,28 @@
309309
return retain(self, @selector(retain));
310310
}
311311
if ([self retainCount] == 1) {
312-
auto innerCache = isolateWrapper.GetCache();
313-
auto it = innerCache->Instances.find(self);
314-
if (it != innerCache->Instances.end()) {
315-
v8::Locker locker(isolate);
316-
Isolate::Scope isolate_scope(isolate);
317-
HandleScope handle_scope(isolate);
318-
Local<Value> value = it->second->Get(isolate);
319-
BaseDataWrapper* wrapper = tns::GetValue(isolate, value);
320-
if (wrapper != nullptr && wrapper->Type() == WrapperType::ObjCObject) {
321-
ObjCDataWrapper* objcWrapper = static_cast<ObjCDataWrapper*>(wrapper);
322-
objcWrapper->GcProtect();
312+
auto runtime = Runtime::GetRuntime(isolate);
313+
auto runtimeLoop = runtime->RuntimeLoop();
314+
void* weakSelf = (__bridge void*)self;
315+
auto gcProtect = ^() {
316+
auto innerCache = isolateWrapper.GetCache();
317+
auto it = innerCache->Instances.find((id)weakSelf);
318+
if (it != innerCache->Instances.end()) {
319+
v8::Locker locker(isolate);
320+
Isolate::Scope isolate_scope(isolate);
321+
HandleScope handle_scope(isolate);
322+
Local<Value> value = it->second->Get(isolate);
323+
BaseDataWrapper* wrapper = tns::GetValue(isolate, value);
324+
if (wrapper != nullptr && wrapper->Type() == WrapperType::ObjCObject) {
325+
ObjCDataWrapper* objcWrapper = static_cast<ObjCDataWrapper*>(wrapper);
326+
objcWrapper->GcProtect();
327+
}
323328
}
329+
};
330+
if (CFRunLoopGetCurrent() != runtimeLoop) {
331+
tns::ExecuteOnRunLoop(runtimeLoop, gcProtect);
332+
} else {
333+
gcProtect();
324334
}
325335
}
326336

@@ -337,18 +347,42 @@
337347
}
338348

339349
if ([self retainCount] == 2) {
340-
auto innerCache = isolateWrapper.GetCache();
341-
auto it = innerCache->Instances.find(self);
342-
if (it != innerCache->Instances.end()) {
343-
v8::Locker locker(isolate);
344-
Isolate::Scope isolate_scope(isolate);
345-
HandleScope handle_scope(isolate);
346-
if (it->second != nullptr) {
347-
Local<Value> value = it->second->Get(isolate);
348-
BaseDataWrapper* wrapper = tns::GetValue(isolate, value);
349-
if (wrapper != nullptr && wrapper->Type() == WrapperType::ObjCObject) {
350-
ObjCDataWrapper* objcWrapper = static_cast<ObjCDataWrapper*>(wrapper);
351-
objcWrapper->GcUnprotect();
350+
void* weakSelf = (__bridge void*)self;
351+
auto gcUnprotect = ^() {
352+
auto innerCache = isolateWrapper.GetCache();
353+
auto it = innerCache->Instances.find((id)weakSelf);
354+
if (it != innerCache->Instances.end()) {
355+
v8::Locker locker(isolate);
356+
Isolate::Scope isolate_scope(isolate);
357+
HandleScope handle_scope(isolate);
358+
if (it->second != nullptr) {
359+
Local<Value> value = it->second->Get(isolate);
360+
BaseDataWrapper* wrapper = tns::GetValue(isolate, value);
361+
if (wrapper != nullptr && wrapper->Type() == WrapperType::ObjCObject) {
362+
ObjCDataWrapper* objcWrapper = static_cast<ObjCDataWrapper*>(wrapper);
363+
objcWrapper->GcUnprotect();
364+
}
365+
}
366+
}
367+
};
368+
auto runtime = Runtime::GetRuntime(isolate);
369+
auto runtimeLoop = runtime->RuntimeLoop();
370+
if (CFRunLoopGetCurrent() != runtimeLoop) {
371+
tns::ExecuteOnRunLoop(runtimeLoop, gcUnprotect);
372+
} else {
373+
auto innerCache = isolateWrapper.GetCache();
374+
auto it = innerCache->Instances.find(self);
375+
if (it != innerCache->Instances.end()) {
376+
v8::Locker locker(isolate);
377+
Isolate::Scope isolate_scope(isolate);
378+
HandleScope handle_scope(isolate);
379+
if (it->second != nullptr) {
380+
Local<Value> value = it->second->Get(isolate);
381+
BaseDataWrapper* wrapper = tns::GetValue(isolate, value);
382+
if (wrapper != nullptr && wrapper->Type() == WrapperType::ObjCObject) {
383+
ObjCDataWrapper* objcWrapper = static_cast<ObjCDataWrapper*>(wrapper);
384+
objcWrapper->GcUnprotect();
385+
}
352386
}
353387
}
354388
}
@@ -952,4 +986,4 @@
952986

953987
unsigned long long ClassBuilder::classNameCounter_ = 0;
954988

955-
}
989+
} // namespace tns

0 commit comments

Comments
 (0)