Skip to content

Commit ce39d39

Browse files
committed
fix(client): internal fields
1 parent a168b92 commit ce39d39

8 files changed

+44
-20
lines changed

client/src/bindings/AudioCategory.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
1818
auto audioCategory = alt::ICore::Instance().GetAudioCategory(audioCategoryStr);
1919
V8_CHECK(audioCategory, "Audio category not found");
2020

21-
info.This()->SetInternalField(0, v8::String::NewFromUtf8(isolate, audioCategoryStr.c_str()).ToLocalChecked());
21+
V8Helpers::SetObjectClass(info.GetIsolate(), info.This(), V8Class::ObjectClass::AUDIO_CATEGORY);
22+
info.This()->SetInternalField(1, v8::String::NewFromUtf8(isolate, audioCategoryStr.c_str()).ToLocalChecked());
2223
}
2324

2425
// Getters
@@ -356,7 +357,7 @@ extern V8Class v8AudioCategory("AudioCategory",
356357
[](v8::Local<v8::FunctionTemplate> tpl)
357358
{
358359
v8::Isolate* isolate = v8::Isolate::GetCurrent();
359-
tpl->InstanceTemplate()->SetInternalFieldCount(1);
360+
tpl->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(V8Class::InternalFields::COUNT));
360361

361362
V8Helpers::SetStaticMethod(isolate, tpl, "getForName", &GetForName);
362363

client/src/bindings/Handling.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
1313
V8_CHECK_ARGS_LEN(1);
1414
V8_ARG_TO_OBJECT(1, vehicle);
1515

16-
info.This()->SetInternalField(0, vehicle);
16+
V8Helpers::SetObjectClass(info.GetIsolate(), info.This(), V8Class::ObjectClass::HANDLING);
17+
info.This()->SetInternalField(1, vehicle);
1718
}
1819

1920
static void IsModified(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -1213,7 +1214,7 @@ extern V8Class v8Handling("Handling", Constructor, [](v8::Local<v8::FunctionTemp
12131214

12141215
v8::Local<v8::ObjectTemplate> proto = tpl->PrototypeTemplate();
12151216

1216-
tpl->InstanceTemplate()->SetInternalFieldCount(1);
1217+
tpl->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(V8Class::InternalFields::COUNT));
12171218

12181219
V8Helpers::SetMethod(isolate, tpl, "isModified", &IsModified);
12191220
V8Helpers::SetMethod(isolate, tpl, "reset", &Reset);

client/src/bindings/HandlingData.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
1313
auto handling = alt::ICore::Instance().GetHandlingData(modelHash);
1414
V8_CHECK(handling, "model doesn't exist");
1515

16-
info.This()->SetInternalField(0, info[0]);
16+
17+
V8Helpers::SetObjectClass(info.GetIsolate(), info.This(), V8Class::ObjectClass::HANDLING_DATA);
18+
info.This()->SetInternalField(1, info[0]);
1719
}
1820

1921
static void GetForHandlingName(const v8::FunctionCallbackInfo<v8::Value>& info)
@@ -1731,8 +1733,8 @@ static void DamageFlagsSetter(v8::Local<v8::String>, v8::Local<v8::Value> val, c
17311733

17321734
extern V8Class v8HandlingData("HandlingData", Constructor, [](v8::Local<v8::FunctionTemplate> tpl) {
17331735
v8::Isolate* isolate = v8::Isolate::GetCurrent();
1734-
1735-
tpl->InstanceTemplate()->SetInternalFieldCount(1);
1736+
1737+
tpl->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(V8Class::InternalFields::COUNT));
17361738

17371739
V8Helpers::SetStaticMethod(isolate, tpl, "getForHandlingName", &GetForHandlingName);
17381740

client/src/bindings/MapZoomData.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
1212

1313
V8_CHECK(info[0]->IsNumber() || info[0]->IsString(), "zoomDataId must be a number or string");
1414

15+
16+
V8Helpers::SetObjectClass(info.GetIsolate(), info.This(), V8Class::ObjectClass::MAP_ZOOM_DATA);
1517
if(info[0]->IsNumber())
1618
{
1719
V8_ARG_TO_UINT(1, zoomDataId);
1820
auto data = alt::ICore::Instance().GetMapData(zoomDataId);
1921
V8_CHECK(data, "zoomData with this id not found");
2022

21-
info.This()->SetInternalField(0, info[0]);
23+
info.This()->SetInternalField(1, info[0]);
2224
}
2325
else
2426
{
@@ -28,7 +30,7 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
2830
V8_CHECK(data, "zoomData with this id not found");
2931

3032
uint8_t id = alt::ICore::Instance().GetMapDataIDFromAlias(zoomDataAlias);
31-
info.This()->SetInternalField(0, V8Helpers::JSValue(id));
33+
info.This()->SetInternalField(1, V8Helpers::JSValue(id));
3234
}
3335
}
3436

@@ -176,7 +178,7 @@ extern V8Class v8MapZoomData("MapZoomData", Constructor, [](v8::Local<v8::Functi
176178

177179
v8::Local<v8::ObjectTemplate> proto = tpl->PrototypeTemplate();
178180

179-
tpl->InstanceTemplate()->SetInternalFieldCount(1);
181+
tpl->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(V8Class::InternalFields::COUNT));
180182

181183
V8Helpers::SetStaticMethod(isolate, tpl, "get", &Get);
182184
V8Helpers::SetStaticMethod(isolate, tpl, "resetAll", &ResetAll);

client/src/bindings/MemoryBuffer.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
2121
V8_CHECK_CONSTRUCTOR();
2222
V8_CHECK_ARGS_LEN(1);
2323

24+
V8Helpers::SetObjectClass(info.GetIsolate(), info.This(), V8Class::ObjectClass::MEMORY_BUFFER);
25+
2426
// Ask alt:V to add pattern searching to C++ SDK if you want this available
2527
// if(info[0]->IsString())
2628
// {
@@ -38,16 +40,16 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
3840
V8_ARG_TO_UINT(1, size);
3941
if(size == 0)
4042
{
41-
info.This()->SetAlignedPointerInInternalField(0, nullptr);
42-
info.This()->SetInternalField(1, V8Helpers::JSValue(0));
43+
info.This()->SetAlignedPointerInInternalField(1, nullptr);
44+
info.This()->SetInternalField(2, V8Helpers::JSValue(0));
4345
return;
4446
}
4547
V8_CHECK(size <= 1024, "You can't allocate > 1KB");
4648

4749
uint8_t* allocatedMemory = new uint8_t[size];
4850
memset(allocatedMemory, 0, size);
49-
info.This()->SetAlignedPointerInInternalField(0, allocatedMemory);
50-
info.This()->SetInternalField(1, V8Helpers::JSValue(size));
51+
info.This()->SetAlignedPointerInInternalField(1, allocatedMemory);
52+
info.This()->SetInternalField(2, V8Helpers::JSValue(size));
5153
}
5254

5355
/*v8::Global<v8::Object> persistent(isolate, info.This());
@@ -170,7 +172,7 @@ static void GetDataOfType(const v8::FunctionCallbackInfo<v8::Value>& info)
170172
extern V8Class v8MemoryBuffer("MemoryBuffer", Constructor, [](v8::Local<v8::FunctionTemplate> tpl) {
171173
v8::Isolate* isolate = v8::Isolate::GetCurrent();
172174

173-
tpl->InstanceTemplate()->SetInternalFieldCount(2);
175+
tpl->InstanceTemplate()->SetInternalFieldCount(3);
174176

175177
V8Helpers::SetAccessor(isolate, tpl, "size", SizeGetter);
176178
V8Helpers::SetAccessor(isolate, tpl, "address", AddressGetter);

client/src/bindings/WeaponData.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
2626
auto weaponData = alt::ICore::Instance().GetWeaponData(weaponHash);
2727
V8_CHECK(weaponData, "Weapon data not found");
2828

29-
info.This()->SetInternalField(0, v8::Integer::NewFromUnsigned(isolate, weaponHash));
29+
V8Helpers::SetObjectClass(info.GetIsolate(), info.This(), V8Class::ObjectClass::WEAPON_DATA);
30+
info.This()->SetInternalField(1, v8::Integer::NewFromUnsigned(isolate, weaponHash));
3031
}
3132

3233
// Getters
@@ -336,7 +337,8 @@ extern V8Class v8WeaponData("WeaponData",
336337
[](v8::Local<v8::FunctionTemplate> tpl)
337338
{
338339
v8::Isolate* isolate = v8::Isolate::GetCurrent();
339-
tpl->InstanceTemplate()->SetInternalFieldCount(1);
340+
341+
tpl->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(V8Class::InternalFields::COUNT));
340342

341343
V8Helpers::SetStaticMethod(isolate, tpl, "getForHash", &GetForHash);
342344
V8Helpers::SetStaticAccessor(isolate, tpl, "allHashes", &GetAllHashes);

client/src/bindings/Worker.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
2929
std::string filePath = pathInfo.prefix + pathInfo.fileName;
3030

3131
CWorker* worker = new CWorker(filePath, static_cast<CV8ResourceImpl*>(resource));
32-
info.This()->SetInternalField(0, v8::External::New(isolate, worker));
32+
33+
V8Helpers::SetObjectClass(info.GetIsolate(), info.This(), V8Class::ObjectClass::WORKER);
34+
info.This()->SetInternalField(1, v8::External::New(isolate, worker));
35+
3336
static_cast<CV8ResourceImpl*>(resource)->AddWorker(worker);
3437
}
3538

@@ -212,7 +215,8 @@ extern V8Class v8Worker("Worker",
212215
[](v8::Local<v8::FunctionTemplate> tpl)
213216
{
214217
v8::Isolate* isolate = v8::Isolate::GetCurrent();
215-
tpl->InstanceTemplate()->SetInternalFieldCount(1);
218+
219+
tpl->InstanceTemplate()->SetInternalFieldCount(static_cast<int>(V8Class::InternalFields::COUNT));
216220

217221
tpl->Set(V8Helpers::JSValue("maxWorkers"), V8Helpers::JSValue(MAX_WORKERS), v8::PropertyAttribute::ReadOnly);
218222
V8Helpers::SetStaticAccessor(isolate, tpl, "activeWorkers", &ActiveWorkersGetter);

shared/V8Class.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,22 @@ class V8Class
2929
enum class ObjectClass
3030
{
3131
NONE,
32-
RESOURCE,
32+
3333
BASE_OBJECT,
3434
VECTOR2,
3535
VECTOR3,
3636
RGBA,
3737
QUATERNION,
38+
MEMORY_BUFFER,
39+
40+
RESOURCE,
41+
WORKER,
42+
43+
AUDIO_CATEGORY,
44+
HANDLING,
45+
HANDLING_DATA,
46+
MAP_ZOOM_DATA,
47+
WEAPON_DATA
3848
};
3949

4050
static auto& All()

0 commit comments

Comments
 (0)