Skip to content

Commit 17db3e2

Browse files
fix: Ensure Environment::get_verified_object actually called verify_object
Addresses a class of error that can be encountered when an object belongs to a different Environment.
1 parent 8249045 commit 17db3e2

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

bridge/jsb_environment.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,8 @@ namespace jsb
889889
{
890890
return nullptr;
891891
}
892-
return p_obj->GetAlignedPointerFromInternalField(IF_Pointer);
892+
void* pointer = p_obj->GetAlignedPointerFromInternalField(IF_Pointer);
893+
return verify_object(pointer) ? pointer : nullptr;
893894
}
894895

895896
bool Environment::reference_object(void* p_pointer, bool p_is_inc)
@@ -948,21 +949,21 @@ namespace jsb
948949

949950
// avoid crash in the situation that `InstanceBindingCallbacks::free_callback` is called before JS object gc callback is called,
950951
// which makes the pointer already erased in `object_gc_callback`
951-
if (jsb_unlikely(!object_handle))
952-
{
953-
return;
954-
}
955-
956-
#if JSB_DEBUG
957-
jsb_check(object_handle->pointer == p_pointer);
958-
#endif
959-
const NativeClassID class_id = object_handle->class_id;
960-
// hold it in a local variable to avoid gc too early
961-
v8::Global<v8::Object> obj_ref = std::move(object_handle->ref_);
952+
if (jsb_unlikely(!object_handle))
953+
{
954+
return;
955+
}
956+
957+
#if JSB_DEBUG
958+
jsb_check(object_handle->pointer == p_pointer);
959+
#endif
960+
const NativeClassID class_id = object_handle->class_id;
961+
// hold it in a local variable to avoid gc too early
962+
v8::Global<v8::Object> obj_ref = std::move(object_handle->ref_);
962963

963964
// erase from ObjectDB before clearing the ref to avoid exposing a transient state
964965
// with an empty `ref_` in the ObjectDB, which can race with reference callbacks.
965-
object_db_.remove_object(object_handle, p_pointer);
966+
object_db_.remove_object(object_handle, p_pointer);
966967

967968
// TODO: Look into if we ought to be calling obj->free_instance_binding(this)
968969

0 commit comments

Comments
 (0)