Skip to content

Commit 325e639

Browse files
committed
fix(runtime): Throw a native exception in parseType
`parseType` would return a non-initialized result variable which lead to a crash later when execution continued. Replace it with an Objective-C exception which rewinds the stack and only after that becomes converted to a JS exception.
1 parent cbf89d0 commit 325e639

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/NativeScript/JSErrors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#define NS_EXCEPTION_SCOPE_ZERO_RECURSION_KEY @"__nsExceptionScopeZeroRecursion"
1818

19+
#define NS_THROW(msg) @throw [NSException exceptionWithName:NSGenericException reason:msg userInfo:nil];
20+
1921
#define NS_TRY @try
2022

2123
#define NS_CATCH_THROW_TO_JS(execState) \

src/NativeScript/TypeFactory.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101

102102
const StructMeta* structInfo = static_cast<const StructMeta*>(MetaFile::instance()->globalTableJs()->findMeta(structName.impl()));
103103
if (!structInfo) {
104-
@throw [NSException exceptionWithName:NSGenericException reason:[NSString stringWithFormat:@"Struct \"%s\" is missing from metadata. It may have been blacklisted.", structName.utf8().data()] userInfo:nil];
104+
NSString* errorMsg = [NSString stringWithFormat:@"Struct \"%s\" is missing from metadata. It may have been blacklisted.", structName.utf8().data()];
105+
NS_THROW(errorMsg);
105106
}
106107

107108
ffi_type* ffiType = new ffi_type({ .size = 0,
@@ -277,7 +278,7 @@
277278

278279
if (!klass || !metadata) {
279280
if (strcmp(metadata->name(), "NSObject") == 0) {
280-
@throw [NSException exceptionWithName:NSGenericException reason:@"fatal error: NativeScript cannot create constructor for NSObject." userInfo:nil];
281+
NS_THROW(@"fatal error: NativeScript cannot create constructor for NSObject.");
281282
}
282283
#ifdef DEBUG
283284
NSLog(@"** Can not create constructor for \"%s\". Casting it to \"NSObject\". **", metadata->name());
@@ -478,9 +479,8 @@
478479
if (Class klass = objc_getClass(declarationName.utf8().data())) {
479480
result = globalObject->constructorFor(klass, additionalProtocols);
480481
} else {
481-
auto scope = DECLARE_THROW_SCOPE(execState->vm());
482-
WTF::String message = makeString("Class \"", declarationName, "\" referenced by type encoding not found at runtime.");
483-
throwException(execState, scope, JSC::createError(execState, message, defaultSourceAppender));
482+
auto errorMsg = [NSString stringWithFormat:@"Class \"%s\" referenced by type encoding not found at runtime.", declarationName.utf8().data()];
483+
NS_THROW(errorMsg);
484484
}
485485

486486
break;

0 commit comments

Comments
 (0)