Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jsc): fix gc finalize bug and performance #3479

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading