Skip to content

Commit

Permalink
fix(jsc): fix gc finalize bug and performance
Browse files Browse the repository at this point in the history
  • Loading branch information
etkmao committed Aug 31, 2023
1 parent 6ba3474 commit e01c89f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion driver/js/include/driver/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class Scope : public std::enable_shared_from_this<Scope> {
FOOTSTONE_CHECK(context);
auto weak_callback_wrapper = std::make_unique<WeakCallbackWrapper>([](void* callback_data, void* internal_data) {
auto class_template = reinterpret_cast<ClassTemplate<T>*>(callback_data);
auto holder_map = class_template->holder_map;
auto& holder_map = class_template->holder_map;
auto it = holder_map.find(internal_data);
if (it != holder_map.end()) {
holder_map.erase(it);
Expand Down
16 changes: 8 additions & 8 deletions driver/js/src/napi/jsc/jsc_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ std::shared_ptr<CtxValue> JSCCtx::DefineClass(const string_view& name,
auto weak_callback_wrapper = constructor_data->weak_callback_wrapper;
if (weak_callback_wrapper) {
auto wrapper = reinterpret_cast<WeakCallbackWrapper*>(weak_callback_wrapper);
auto object_data_map = constructor_data->object_data_map;
auto& object_data_map = constructor_data->object_data_map;
wrapper->callback(wrapper->data, object_data_map[object]);
object_data_map.erase(object_data_map.find(object));
object_data_map.erase(object);
}
};
class_definition.hasInstance = [](JSContextRef ctx, JSObjectRef constructor, JSValueRef instance, JSValueRef* exception) -> bool {
Expand All @@ -287,7 +287,7 @@ std::shared_ptr<CtxValue> JSCCtx::DefineClass(const string_view& name,
auto constructor_prototype = reinterpret_cast<ConstructorData*>(constructor_private)->prototype;
auto constructor_prototype_value = std::static_pointer_cast<JSCCtxValue>(constructor_prototype)->value_;
auto instance_prototype = JSObjectGetPrototype(ctx, instance_object);

while (!JSValueIsNull(ctx, instance_prototype)) {
if (JSValueIsEqual(ctx, instance_prototype, constructor_prototype_value, exception)) {
return true;
Expand All @@ -298,7 +298,7 @@ std::shared_ptr<CtxValue> JSCCtx::DefineClass(const string_view& name,
}
instance_prototype = JSObjectGetPrototype(ctx, instance_prototype_object);
}

return false;
};
JSClassRef parent_class_ref = nullptr;
Expand Down Expand Up @@ -379,7 +379,7 @@ std::shared_ptr<CtxValue> JSCCtx::DefineClass(const string_view& name,
JSStringRelease(set_key_name);
JSStringRelease(define_property_name);
JSStringRelease(object_name);

if (parent_prototype_value) {
JSObjectSetPrototype(context_, prototype, parent_prototype_value);
}
Expand Down Expand Up @@ -897,14 +897,14 @@ std::shared_ptr<CtxValue> JSCCtx::CallFunction(const std::shared_ptr<CtxValue>&
SetException(std::make_shared<JSCCtxValue>(context_, exception));
return nullptr;
}

auto receiver_value = std::static_pointer_cast<JSCCtxValue>(receiver);
auto receiver_object = JSValueToObject(context_, receiver_value->value_, &exception);
if (exception) {
SetException(std::make_shared<JSCCtxValue>(context_, exception));
return nullptr;
}

if (argc <= 0) {
auto ret_value_ref = JSObjectCallAsFunction(context_, function_object, receiver_object, 0, nullptr, &exception);
if (exception) {
Expand Down Expand Up @@ -981,7 +981,7 @@ void JSCCtx::SaveConstructorData(std::unique_ptr<ConstructorData> constructor_da
JSCVM::SaveConstructorDataPtr(constructor_data.get());
holder[this][constructor_data->class_ref] = std::move(constructor_data);
}

std::shared_ptr<JSCCtxValue> JSCCtx::GetClassPrototype(JSClassRef ref) {
auto vm = vm_.lock();
FOOTSTONE_CHECK(vm);
Expand Down

0 comments on commit e01c89f

Please sign in to comment.