Skip to content

Commit

Permalink
fix(client): mvalue casts
Browse files Browse the repository at this point in the history
  • Loading branch information
vadzz-dev committed Mar 18, 2024
1 parent d6e5b97 commit e445b99
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion client/src/CV8Resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void StartFile(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_CHECK(!maybeMod.IsEmpty(), "Failed to start file");
auto mod = maybeMod.ToLocalChecked();
static_cast<CV8ResourceImpl*>(resource)->InstantiateModule(mod);
const alt::MValueDict& exports = std::dynamic_pointer_cast<alt::IMValueDict>(
const alt::MValueDict& exports = std::static_pointer_cast<alt::IMValueDict>(
V8Helpers::V8ToMValue(mod->GetModuleNamespace()));
resource->GetResource()->SetExports(exports);
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/bindings/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ static void GetOutputs(const v8::FunctionCallbackInfo<v8::Value>& info)
auto val = list->Get(i);
if(val->GetType() == alt::IMValue::Type::BASE_OBJECT)
{
auto baseObj = resource->GetBaseObjectOrNull(std::dynamic_pointer_cast<alt::IMValueBaseObject>(val)->RawValue());
auto baseObj = resource->GetBaseObjectOrNull(std::static_pointer_cast<alt::IMValueBaseObject>(val)->RawValue());
arr->Set(ctx, i, baseObj);
}
else if(val->GetType() == alt::IMValue::Type::UINT)
arr->Set(ctx, i, v8::Integer::NewFromUnsigned(isolate, std::dynamic_pointer_cast<alt::IMValueUInt>(val)->Value()));
arr->Set(ctx, i, v8::Integer::NewFromUnsigned(isolate, std::static_pointer_cast<alt::IMValueUInt>(val)->Value()));
}

V8_RETURN(arr);
Expand Down
9 changes: 7 additions & 2 deletions client/src/bindings/FocusData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ static void OverrideFocus(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_ARGS_LEN2(1, 2);

if(resource->IsVector3(info[0]))

auto cls = V8Class::ObjectClass::NONE;
if(info[0]->IsObject())
V8Helpers::GetObjectClass(info[0].As<v8::Object>());

if(cls == V8Class::ObjectClass::VECTOR3)
{
V8_ARG_TO_VECTOR3(1, pos);
alt::Vector3f offset = { 0, 0, 0 };
Expand All @@ -42,7 +47,7 @@ static void OverrideFocus(const v8::FunctionCallbackInfo<v8::Value>& info)
}
alt::ICore::Instance().OverrideFocusPosition(pos, offset);
}
else if(resource->IsBaseObject(info[0]))
else if(cls == V8Class::ObjectClass::BASE_OBJECT)
{
V8_ARG_TO_BASE_OBJECT(1, entity, alt::IEntity, "Entity");
alt::ICore::Instance().OverrideFocusEntity(entity);
Expand Down
20 changes: 10 additions & 10 deletions client/src/bindings/HttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static void GetExtraHeaders(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_NEW_OBJECT(headers);
for(auto it = dict->Begin(); it != dict->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}

V8_RETURN(headers);
Expand Down Expand Up @@ -71,7 +71,7 @@ static void Get(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -114,7 +114,7 @@ static void Head(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -158,7 +158,7 @@ static void Post(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -202,7 +202,7 @@ static void Put(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -246,7 +246,7 @@ static void Delete(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -290,7 +290,7 @@ static void Connect(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -334,7 +334,7 @@ static void Options(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -378,7 +378,7 @@ static void Trace(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -422,7 +422,7 @@ static void Patch(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down
3 changes: 1 addition & 2 deletions client/src/bindings/WebSocketClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ static void GetExtraHeaders(const v8::FunctionCallbackInfo<v8::Value>& info)

for(auto it = extraHeaders->Begin(); it != extraHeaders->End(); ++it)
{
std::string key = it->first;
V8_OBJECT_SET_STRING(headersObject, key.c_str(), std::dynamic_pointer_cast<alt::IMValueString>(extraHeaders->Get(key))->Value());
V8_OBJECT_SET_STRING(headersObject, it->first, std::static_pointer_cast<alt::IMValueString>(extraHeaders->Get(it->first))->Value());
}

V8_RETURN(headersObject);
Expand Down
4 changes: 2 additions & 2 deletions client/src/bindings/WebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ static void GetOutputs(const v8::FunctionCallbackInfo<v8::Value>& info)
auto val = list->Get(i);
if (val->GetType() == alt::IMValue::Type::BASE_OBJECT)
{
auto baseObj = resource->GetBaseObjectOrNull(std::dynamic_pointer_cast<alt::IMValueBaseObject>(val)->RawValue());
auto baseObj = resource->GetBaseObjectOrNull(std::static_pointer_cast<alt::IMValueBaseObject>(val)->RawValue());
arr->Set(ctx, i, baseObj);
}
else if (val->GetType() == alt::IMValue::Type::UINT)
arr->Set(ctx, i, v8::Integer::NewFromUnsigned(isolate, std::dynamic_pointer_cast<alt::IMValueUInt>(val)->Value()));
arr->Set(ctx, i, v8::Integer::NewFromUnsigned(isolate, std::static_pointer_cast<alt::IMValueUInt>(val)->Value()));
}

V8_RETURN(arr);
Expand Down

0 comments on commit e445b99

Please sign in to comment.