Skip to content

Commit

Permalink
fix(ios): resolve jsc_try_catch invalid issue (#4021)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg authored Sep 10, 2024
1 parent 592c010 commit c9ddbc1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
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

0 comments on commit c9ddbc1

Please sign in to comment.