From e445b99150a170c106e6d89202eb2640bdab0036 Mon Sep 17 00:00:00 2001 From: Vadim Zubkov Date: Mon, 18 Mar 2024 19:44:53 +0300 Subject: [PATCH] fix(client): mvalue casts --- client/src/CV8Resource.cpp | 2 +- client/src/bindings/Audio.cpp | 4 ++-- client/src/bindings/FocusData.cpp | 9 +++++++-- client/src/bindings/HttpClient.cpp | 20 ++++++++++---------- client/src/bindings/WebSocketClient.cpp | 3 +-- client/src/bindings/WebView.cpp | 4 ++-- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/client/src/CV8Resource.cpp b/client/src/CV8Resource.cpp index 94a72011..7c80142e 100644 --- a/client/src/CV8Resource.cpp +++ b/client/src/CV8Resource.cpp @@ -62,7 +62,7 @@ void StartFile(const v8::FunctionCallbackInfo& info) V8_CHECK(!maybeMod.IsEmpty(), "Failed to start file"); auto mod = maybeMod.ToLocalChecked(); static_cast(resource)->InstantiateModule(mod); - const alt::MValueDict& exports = std::dynamic_pointer_cast( + const alt::MValueDict& exports = std::static_pointer_cast( V8Helpers::V8ToMValue(mod->GetModuleNamespace())); resource->GetResource()->SetExports(exports); } diff --git a/client/src/bindings/Audio.cpp b/client/src/bindings/Audio.cpp index e7df7cd0..ea29b65d 100644 --- a/client/src/bindings/Audio.cpp +++ b/client/src/bindings/Audio.cpp @@ -101,11 +101,11 @@ static void GetOutputs(const v8::FunctionCallbackInfo& info) auto val = list->Get(i); if(val->GetType() == alt::IMValue::Type::BASE_OBJECT) { - auto baseObj = resource->GetBaseObjectOrNull(std::dynamic_pointer_cast(val)->RawValue()); + auto baseObj = resource->GetBaseObjectOrNull(std::static_pointer_cast(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(val)->Value())); + arr->Set(ctx, i, v8::Integer::NewFromUnsigned(isolate, std::static_pointer_cast(val)->Value())); } V8_RETURN(arr); diff --git a/client/src/bindings/FocusData.cpp b/client/src/bindings/FocusData.cpp index ec87abfe..a924db5d 100644 --- a/client/src/bindings/FocusData.cpp +++ b/client/src/bindings/FocusData.cpp @@ -31,7 +31,12 @@ static void OverrideFocus(const v8::FunctionCallbackInfo& 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()); + + if(cls == V8Class::ObjectClass::VECTOR3) { V8_ARG_TO_VECTOR3(1, pos); alt::Vector3f offset = { 0, 0, 0 }; @@ -42,7 +47,7 @@ static void OverrideFocus(const v8::FunctionCallbackInfo& 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); diff --git a/client/src/bindings/HttpClient.cpp b/client/src/bindings/HttpClient.cpp index d95a9528..0f621916 100644 --- a/client/src/bindings/HttpClient.cpp +++ b/client/src/bindings/HttpClient.cpp @@ -25,7 +25,7 @@ static void GetExtraHeaders(const v8::FunctionCallbackInfo& 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(it->second)->Value().c_str())); + headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast(it->second)->Value().c_str())); } V8_RETURN(headers); @@ -71,7 +71,7 @@ static void Get(const v8::FunctionCallbackInfo& 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(it->second)->Value().c_str())); + headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast(it->second)->Value().c_str())); } responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers); resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); @@ -114,7 +114,7 @@ static void Head(const v8::FunctionCallbackInfo& 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(it->second)->Value().c_str())); + headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast(it->second)->Value().c_str())); } responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers); resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); @@ -158,7 +158,7 @@ static void Post(const v8::FunctionCallbackInfo& 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(it->second)->Value().c_str())); + headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast(it->second)->Value().c_str())); } responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers); resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); @@ -202,7 +202,7 @@ static void Put(const v8::FunctionCallbackInfo& 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(it->second)->Value().c_str())); + headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast(it->second)->Value().c_str())); } responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers); resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); @@ -246,7 +246,7 @@ static void Delete(const v8::FunctionCallbackInfo& 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(it->second)->Value().c_str())); + headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast(it->second)->Value().c_str())); } responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers); resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); @@ -290,7 +290,7 @@ static void Connect(const v8::FunctionCallbackInfo& 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(it->second)->Value().c_str())); + headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast(it->second)->Value().c_str())); } responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers); resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); @@ -334,7 +334,7 @@ static void Options(const v8::FunctionCallbackInfo& 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(it->second)->Value().c_str())); + headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast(it->second)->Value().c_str())); } responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers); resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); @@ -378,7 +378,7 @@ static void Trace(const v8::FunctionCallbackInfo& 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(it->second)->Value().c_str())); + headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast(it->second)->Value().c_str())); } responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers); resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); @@ -422,7 +422,7 @@ static void Patch(const v8::FunctionCallbackInfo& 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(it->second)->Value().c_str())); + headers->Set(ctx, V8Helpers::JSValue(it->first), V8Helpers::JSValue(std::static_pointer_cast(it->second)->Value().c_str())); } responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers); resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj); diff --git a/client/src/bindings/WebSocketClient.cpp b/client/src/bindings/WebSocketClient.cpp index 9ccd2a33..3ff62ea0 100644 --- a/client/src/bindings/WebSocketClient.cpp +++ b/client/src/bindings/WebSocketClient.cpp @@ -133,8 +133,7 @@ static void GetExtraHeaders(const v8::FunctionCallbackInfo& 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(extraHeaders->Get(key))->Value()); + V8_OBJECT_SET_STRING(headersObject, it->first, std::static_pointer_cast(extraHeaders->Get(it->first))->Value()); } V8_RETURN(headersObject); diff --git a/client/src/bindings/WebView.cpp b/client/src/bindings/WebView.cpp index 41152f7a..d59b4744 100644 --- a/client/src/bindings/WebView.cpp +++ b/client/src/bindings/WebView.cpp @@ -303,11 +303,11 @@ static void GetOutputs(const v8::FunctionCallbackInfo& info) auto val = list->Get(i); if (val->GetType() == alt::IMValue::Type::BASE_OBJECT) { - auto baseObj = resource->GetBaseObjectOrNull(std::dynamic_pointer_cast(val)->RawValue()); + auto baseObj = resource->GetBaseObjectOrNull(std::static_pointer_cast(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(val)->Value())); + arr->Set(ctx, i, v8::Integer::NewFromUnsigned(isolate, std::static_pointer_cast(val)->Value())); } V8_RETURN(arr);