Skip to content

Commit

Permalink
fix(hermes): resolve context nullptr exception
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Nov 6, 2024
1 parent 56f6b5d commit 2ca9c97
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions driver/js/src/napi/hermes/hermes_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ std::shared_ptr<CtxValue> HermesCtx::CreateMap(
}

std::shared_ptr<CtxValue> HermesCtx::CreateArray(size_t count, std::shared_ptr<CtxValue> values[]) {
if (count <= 0) {
if (count < 0) {
return nullptr;
}
facebook::jsi::Array array = facebook::jsi::Array(*runtime_, count);
Expand Down Expand Up @@ -725,7 +725,8 @@ std::shared_ptr<CtxValue> HermesCtx::CallFunction(const std::shared_ptr<CtxValue
arg_vec.resize(jsi_arg_count);
for (size_t i = 0; i < jsi_arg_count; i++) {
std::shared_ptr<HermesCtxValue> argument_ctx_val = std::static_pointer_cast<HermesCtxValue>(arguments[i]);
arg_vec[i] = argument_ctx_val->GetValue(runtime_);
FOOTSTONE_DCHECK(argument_ctx_val);
arg_vec[i] = argument_ctx_val ? argument_ctx_val->GetValue(runtime_) : facebook::jsi::Value::null();
}
const Value* jsi_arg = &arg_vec[0];
Value value = jsi_func.callWithThis(*runtime_, this_object.asObject(*runtime_), jsi_arg, jsi_arg_count);
Expand Down
5 changes: 3 additions & 2 deletions driver/js/src/napi/jsc/jsc_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ std::shared_ptr<CtxValue> JSCCtx::DefineClass(const string_view& name,
std::shared_ptr<CtxValue> JSCCtx::NewInstance(const std::shared_ptr<CtxValue>& cls, int argc, std::shared_ptr<CtxValue> argv[], void* external) {
auto jsc_cls = std::static_pointer_cast<JSCCtxValue>(cls);
JSValueRef values[argc]; // NOLINT(runtime/arrays)
for (size_t i = 0; i < argc; i++) {
for (int i = 0; i < argc; i++) {
auto arg_value = std::static_pointer_cast<JSCCtxValue>(argv[i]);
values[i] = arg_value->value_;
}
Expand Down Expand Up @@ -921,7 +921,8 @@ std::shared_ptr<CtxValue> JSCCtx::CallFunction(const std::shared_ptr<CtxValue>&
JSValueRef values[argc]; // NOLINT(runtime/arrays)
for (size_t i = 0; i < argc; i++) {
auto arg_value = std::static_pointer_cast<JSCCtxValue>(argv[i]);
values[i] = arg_value->value_;
FOOTSTONE_DCHECK(arg_value);
values[i] = arg_value ? arg_value->value_ : JSValueMakeNull(context_);
}

auto ret_value_ref = JSObjectCallAsFunction(context_, function_object, receiver_object, argc, values, &exception);
Expand Down
2 changes: 0 additions & 2 deletions framework/ios/base/executors/HippyJSExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,6 @@ - (void)executeApplicationScript:(NSData *)script sourceURL:(NSURL *)sourceURL o
id result = executeApplicationScript(script,
sourceURL,
strongSelf.pScope->GetContext(),
self.bridge.usingHermesEngine,
&error);
entry->BundleInfoOfUrl(url).execute_source_end_ = footstone::TimePoint::SystemNow();
if (onComplete) {
Expand All @@ -737,7 +736,6 @@ - (void)executeApplicationScript:(NSData *)script sourceURL:(NSURL *)sourceURL o
static NSError *executeApplicationScript(NSData *script,
NSURL *sourceURL,
SharedCtxPtr context,
BOOL usingHermes,
__strong NSError **error) {
const char *scriptBytes = reinterpret_cast<const char *>([script bytes]);
string_view view = string_view::new_from_utf8(scriptBytes, [script length]);
Expand Down

0 comments on commit 2ca9c97

Please sign in to comment.