From 9f1ff353eeb2614faaed4c3d83baf31da11a61b4 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 13 Oct 2023 15:47:51 +0200 Subject: [PATCH 1/2] shared: Remove DEBUG_BINDINGS --- .vscode/c_cpp_properties.json | 6 ++---- shared/src/Class.cpp | 9 +-------- shared/src/helpers/Template.cpp | 34 --------------------------------- shared/src/helpers/Template.h | 34 --------------------------------- xmake.lua | 8 -------- 5 files changed, 3 insertions(+), 88 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index a9ce633d9..023f9c3ac 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -13,8 +13,7 @@ "MODULE_VERSION", "DYNAMIC_BUILD", "WIN32", - "NODE_WANT_INTERNALS", - "DEBUG_BINDINGS" + "NODE_WANT_INTERNALS" ], "windowsSdkVersion": "10.0.19041.0", "cppStandard": "c++20", @@ -47,8 +46,7 @@ "ALT_SERVER", "MODULE_VERSION", "DYNAMIC_BUILD", - "NODE_WANT_INTERNALS", - "DEBUG_BINDINGS" + "NODE_WANT_INTERNALS" ], "cppStandard": "c++20", "includePath": [ diff --git a/shared/src/Class.cpp b/shared/src/Class.cpp index 10968021e..0b585a482 100644 --- a/shared/src/Class.cpp +++ b/shared/src/Class.cpp @@ -32,14 +32,7 @@ js::Class* js::Class::GetByClassId(uint16_t id) void js::Class::Initialize(v8::Isolate* isolate) { - for(auto class_ : GetAll()) - { - class_->Register(isolate); -#ifdef DEBUG_BINDINGS - class_->GetTemplate(isolate).DumpRegisteredKeys(); - Logger::Colored("~g~[BINDINGS] ~w~Dumped class", class_->GetName()); -#endif - } + for(auto class_ : GetAll()) class_->Register(isolate); // Only needed while setting up the templates, so we can free the data here ClassTemplate::CleanupPropertyGetterMap(isolate); diff --git a/shared/src/helpers/Template.cpp b/shared/src/helpers/Template.cpp index 23928eabf..b3b95324d 100644 --- a/shared/src/helpers/Template.cpp +++ b/shared/src/helpers/Template.cpp @@ -138,37 +138,3 @@ void js::ClassTemplate::Inherit(ClassTemplate& parent) // Inherit static methods for(auto& [name, method] : parent.staticMethods) StaticFunction(name, method); } - -#ifdef DEBUG_BINDINGS -void js::ClassTemplate::DumpRegisteredKeys() -{ - std::fstream outFile("v2debug/" + class_->GetName() + ".txt", std::ios::out); - if(!outFile.good()) return; - - std::stringstream ss; - ss << class_->GetName() << ": (Inherits from " << (class_->GetParentClass() ? class_->GetParentClass()->GetName() : "") << ")\n\n"; - - std::unordered_map> keysSortedByType; - for(auto& [key, type] : registeredKeys) - { - if(!keysSortedByType.contains(type)) keysSortedByType[type] = std::vector{ key }; - else - keysSortedByType[type].push_back(key); - } - - for(auto& [type, keys] : keysSortedByType) - { - ss << type << ":\n"; - for(auto& key : keys) - { - ss << "\t" << key << "\n"; - } - ss << "\n"; - } - - outFile << ss.str(); - outFile.close(); - - registeredKeys.clear(); -} -#endif diff --git a/shared/src/helpers/Template.h b/shared/src/helpers/Template.h index fce23b192..b429b32bb 100644 --- a/shared/src/helpers/Template.h +++ b/shared/src/helpers/Template.h @@ -308,15 +308,6 @@ namespace js Class* class_; -#ifdef DEBUG_BINDINGS - std::unordered_map registeredKeys; - - void RegisterKey(const std::string& type, const std::string& key) - { - registeredKeys.insert({ key, type }); - } -#endif - std::unordered_map staticMethods; template @@ -382,15 +373,8 @@ namespace js Get()->PrototypeTemplate()->Set(js::JSValue(name), v8::FunctionTemplate::New(GetIsolate(), Wrapper::MethodHandler)); } -#ifdef DEBUG_BINDINGS - void DumpRegisteredKeys(); -#endif - void Method(const std::string& name, internal::FunctionCallback callback) { -#ifdef DEBUG_BINDINGS - RegisterKey("Method", name); -#endif Get()->PrototypeTemplate()->Set(js::JSValue(name), WrapFunction(callback)); } #pragma endregion @@ -398,27 +382,18 @@ namespace js template void Property(const std::string& name) { -#ifdef DEBUG_BINDINGS - RegisterKey("Property", name); -#endif Get()->PrototypeTemplate()->SetAccessor(js::JSValue(name), Wrapper::PropertyGetterHandler, nullptr, v8::Local(), v8::DEFAULT, v8::ReadOnly); } template void Property(const std::string& name) { -#ifdef DEBUG_BINDINGS - RegisterKey("Property", name); -#endif Get()->PrototypeTemplate()->SetAccessor(js::JSValue(name), Wrapper::PropertyGetterHandler, Wrapper::PropertySetterHandler); } // If getter is nullptr, tries to get the getter defined by a base class void Property(const std::string& name, internal::PropertyCallback getter = nullptr, internal::PropertyCallback setter = nullptr) { -#ifdef DEBUG_BINDINGS - RegisterKey("Property", name); -#endif if(getter && !setter) { v8::Local getterTemplate = WrapProperty(getter); @@ -446,16 +421,10 @@ namespace js template void LazyProperty(const std::string& name) { -#ifdef DEBUG_BINDINGS - RegisterKey("LazyProperty", name); -#endif Get()->InstanceTemplate()->SetLazyDataProperty(js::JSValue(name), Wrapper::LazyPropertyHandler, v8::Local(), v8::PropertyAttribute::ReadOnly); } void LazyProperty(const std::string& name, internal::LazyPropertyCallback callback) { -#ifdef DEBUG_BINDINGS - RegisterKey("LazyProperty", name); -#endif Get()->InstanceTemplate()->SetLazyDataProperty( js::JSValue(name), Wrapper::LazyPropertyHandler, v8::External::New(GetIsolate(), (void*)callback), v8::PropertyAttribute::ReadOnly); } @@ -467,9 +436,6 @@ namespace js internal::DynamicPropertyDeleter deleter = nullptr, internal::DynamicPropertyEnumerator enumerator = nullptr) { -#ifdef DEBUG_BINDINGS - RegisterKey("DynamicProperty", name); -#endif DynamicPropertyData* data = GetDynamicPropertyData(GetIsolate(), class_, name); if(!data) { diff --git a/xmake.lua b/xmake.lua index 6d0984ef7..05c63ccdb 100644 --- a/xmake.lua +++ b/xmake.lua @@ -29,11 +29,6 @@ option("auto-update-deps") set_default(true) set_showmenu(true) -option("debug-bindings") - set_description("Print generated bindings") - set_default(false) - set_showmenu(true) - option("module-version") set_description("Module version") set_default("internal") @@ -75,9 +70,6 @@ target("shared") set_kind("headeronly") add_headerfiles("shared/src/**.h") add_deps("cpp-sdk") - if has_config("debug-bindings") then - add_defines("DEBUG_BINDINGS=1") - end target("server") set_basename("js-module-v2") From 98b9cbd7d693821634918ef1d1ce24813287b736 Mon Sep 17 00:00:00 2001 From: LeonMrBonnie Date: Fri, 13 Oct 2023 15:52:22 +0200 Subject: [PATCH 2/2] shared: Remove unneeded require --- shared/js/entityUtils.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/shared/js/entityUtils.js b/shared/js/entityUtils.js index 22703ce8a..e7af88e4f 100644 --- a/shared/js/entityUtils.js +++ b/shared/js/entityUtils.js @@ -1,6 +1,3 @@ -// NOTE (xLuxy): Entity.streamedIn getter -requireBinding(`${alt.isClient ? "client" : "shared"}/entity.js`); - function getClosestEntity(entities, options = {}) { if (!Array.isArray(entities) || !entities.length) return [null];