Skip to content

Commit

Permalink
Merge branch 'main' into feature/update-vue-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
open-hippy authored Dec 26, 2023
2 parents d5e4deb + 0bc3f09 commit 74545e7
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions framework/ios/base/executors/HippyJSExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -566,27 +566,25 @@ - (void)executeApplicationScript:(NSData *)script sourceURL:(NSURL *)sourceURL o
return lock;
}

static NSError *executeApplicationScript(NSData *script, NSURL *sourceURL, SharedCtxPtr context, NSError **error) {
@autoreleasepool {
const char *scriptBytes = reinterpret_cast<const char *>([script bytes]);
string_view view = string_view::new_from_utf8(scriptBytes, [script length]);
string_view fileName = NSStringToU16StringView([sourceURL absoluteString]);
string_view errorMsg;
NSLock *lock = jslock();
BOOL lockSuccess = [lock lockBeforeDate:[NSDate dateWithTimeIntervalSinceNow:1]];
auto tryCatch = hippy::napi::CreateTryCatchScope(true, context);
SharedCtxValuePtr result = context->RunScript(view, fileName);
if (tryCatch->HasCaught()) {
errorMsg = std::move(tryCatch->GetExceptionMessage());
}
if (lockSuccess) {
[lock unlock];
}
*error = !StringViewUtils::IsEmpty(errorMsg) ? [NSError errorWithDomain:HippyErrorDomain code:2 userInfo:@{
NSLocalizedDescriptionKey: StringViewToNSString(errorMsg)}] : nil;
id objcResult = ObjectFromCtxValue(context, result);
return objcResult;
static id executeApplicationScript(NSData *script, NSURL *sourceURL, SharedCtxPtr context, NSError **error) {
const char *scriptBytes = reinterpret_cast<const char *>([script bytes]);
string_view view = string_view::new_from_utf8(scriptBytes, [script length]);
string_view fileName = NSStringToU16StringView([sourceURL absoluteString]);
string_view errorMsg;
NSLock *lock = jslock();
BOOL lockSuccess = [lock lockBeforeDate:[NSDate dateWithTimeIntervalSinceNow:1]];
auto tryCatch = hippy::napi::CreateTryCatchScope(true, context);
SharedCtxValuePtr result = context->RunScript(view, fileName);
if (tryCatch->HasCaught()) {
errorMsg = std::move(tryCatch->GetExceptionMessage());
}
if (lockSuccess) {
[lock unlock];
}
*error = !StringViewUtils::IsEmpty(errorMsg) ? [NSError errorWithDomain:HippyErrorDomain code:2 userInfo:@{
NSLocalizedDescriptionKey: StringViewToNSString(errorMsg)}] : nil;
id objcResult = ObjectFromCtxValue(context, result);
return objcResult;
}

- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block {
Expand Down

0 comments on commit 74545e7

Please sign in to comment.