Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): resolve jsc_try_catch invalid issue #4021

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
1 change: 0 additions & 1 deletion driver/js/include/driver/napi/jsc/jsc_try_catch.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class JSCTryCatch : public TryCatch {
virtual footstone::string_view GetExceptionMessage();

private:
std::shared_ptr<JSCCtxValue> exception_;
bool is_verbose_;
bool is_rethrow_;
};
Expand Down
16 changes: 9 additions & 7 deletions driver/js/src/napi/jsc/jsc_try_catch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

#include "driver/napi/jsc/jsc_try_catch.h"

#include "driver/napi/jsc/jsc_ctx.h"
#include "driver/napi/jsc/jsc_ctx_value.h"

Expand All @@ -45,7 +44,6 @@ JSCTryCatch::~JSCTryCatch() {
if (HasCaught()) {
if (is_rethrow_ || is_verbose_) {
std::shared_ptr<JSCCtx> ctx = std::static_pointer_cast<JSCCtx>(ctx_);
ctx->SetException(exception_);
if (is_rethrow_) {
ctx->SetExceptionHandled(false);
} else {
Expand All @@ -61,21 +59,24 @@ void JSCTryCatch::ReThrow() {

bool JSCTryCatch::HasCaught() {
if (enable_) {
return !!exception_;
std::shared_ptr<JSCCtx> ctx = std::static_pointer_cast<JSCCtx>(ctx_);
return !!ctx->GetException();
}
return false;
}

bool JSCTryCatch::CanContinue() {
if (enable_) {
return !exception_;
std::shared_ptr<JSCCtx> ctx = std::static_pointer_cast<JSCCtx>(ctx_);
return !ctx->GetException();
}
return true;
}

bool JSCTryCatch::HasTerminated() {
if (enable_) {
return !!exception_;
std::shared_ptr<JSCCtx> ctx = std::static_pointer_cast<JSCCtx>(ctx_);
return !!ctx->GetException();
}
return false;
}
Expand All @@ -89,13 +90,14 @@ void JSCTryCatch::SetVerbose(bool is_verbose) {
}

std::shared_ptr<CtxValue> JSCTryCatch::Exception() {
return exception_;
std::shared_ptr<JSCCtx> ctx = std::static_pointer_cast<JSCCtx>(ctx_);
return ctx->GetException();
}

string_view JSCTryCatch::GetExceptionMessage() {
if (enable_) {
std::shared_ptr<JSCCtx> ctx = std::static_pointer_cast<JSCCtx>(ctx_);
return ctx->GetExceptionMessage(exception_);
return ctx->GetExceptionMessage(ctx->GetException());
}
return "";
}
Expand Down
10 changes: 7 additions & 3 deletions framework/ios/base/bridge/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -710,15 +710,19 @@ - (void)executeJSCode:(NSData *)script
return;
}
HippyAssert(self.javaScriptExecutor, @"js executor must not be null");
__weak HippyBridge *weakSelf = self;
__weak __typeof(self)weakSelf = self;
[self.javaScriptExecutor executeApplicationScript:script sourceURL:sourceURL onComplete:^(id result ,NSError *error) {
HippyBridge *strongSelf = weakSelf;
__strong __typeof(weakSelf)strongSelf = weakSelf;
if (!strongSelf || ![strongSelf isValid]) {
completion(result, error);
return;
}
if (error) {
[strongSelf stopLoadingWithError:error scriptSourceURL:sourceURL];
HippyLogError(@"ExecuteApplicationScript Error! %@", error.description);
HippyExecuteOnMainQueue(^{
__strong __typeof(weakSelf)strongSelf = weakSelf;
[strongSelf stopLoadingWithError:error scriptSourceURL:sourceURL];
});
}
completion(result, error);
}];
Expand Down
1 change: 1 addition & 0 deletions modules/ios/base/HippyAssert.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void HippyFatal(NSError *error) {
}
[NSException raise:name format:@"%@", message];
} @catch (NSException *e) {
// no op
}
#endif //#ifdef DEBUG
}
Expand Down
Loading