From 00d0e7fd39ad1e2774d64353036189336c747a93 Mon Sep 17 00:00:00 2001 From: vadzz Date: Fri, 12 Apr 2024 22:51:27 +0300 Subject: [PATCH 1/2] fix: memory buffer natives --- client/src/bindings/V8Natives.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/src/bindings/V8Natives.cpp b/client/src/bindings/V8Natives.cpp index a2d7b888..2e71f3f6 100644 --- a/client/src/bindings/V8Natives.cpp +++ b/client/src/bindings/V8Natives.cpp @@ -47,11 +47,12 @@ static void* ToMemoryBuffer(v8::Local val, v8::Local ctx if(val->IsObject()) { v8::Local obj = val.As(); + auto cls = V8Helpers::GetObjectClass(obj); - if(obj->InternalFieldCount() == 2) + if(cls == V8Class::ObjectClass::MEMORY_BUFFER) { - void* memory = obj->GetAlignedPointerFromInternalField(0); - uint32_t size = obj->GetInternalField(0)->Uint32Value(ctx).ToChecked(); + void* memory = obj->GetAlignedPointerFromInternalField(1); + uint32_t size = obj->GetInternalField(2)->Uint32Value(ctx).ToChecked(); if(size > 0) return memory; } From 5785c5106079624614b037012771b92c54f28764 Mon Sep 17 00:00:00 2001 From: vadzz Date: Sat, 13 Apr 2024 00:22:56 +0300 Subject: [PATCH 2/2] fix: add IsExternal check to GetObjectClass --- shared/V8Helpers.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shared/V8Helpers.cpp b/shared/V8Helpers.cpp index 5f0d7d11..4cfca3a4 100644 --- a/shared/V8Helpers.cpp +++ b/shared/V8Helpers.cpp @@ -384,8 +384,12 @@ V8Class::ObjectClass V8Helpers::GetObjectClass(v8::Local obj) { if(obj->InternalFieldCount() <= static_cast(V8Class::InternalFields::OBJECT_CLASS)) return V8Class::ObjectClass::NONE; + + auto val = obj->GetInternalField(static_cast(V8Class::InternalFields::OBJECT_CLASS)); + if(!val->IsExternal()) + return V8Class::ObjectClass::NONE; - void* cls = obj->GetInternalField(static_cast(V8Class::InternalFields::OBJECT_CLASS)).As()->Value(); + void* cls = val.As()->Value(); return *reinterpret_cast(&cls); }