Skip to content

Commit a59e8e6

Browse files
committed
ALTV-380 Update v8 version
1 parent 9c8caa9 commit a59e8e6

13 files changed

+71
-50
lines changed

client/cmake/DepsDownload.cmake

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ include(../shared/cmake/DepsHelpers.cmake)
22

33
# Set this to false, when using a custom v8 build for testing
44
set(__deps_check_enabled true)
5+
set(V8_VERSION "12.4.254")
56

67
function(DownloadDeps)
78
set(__base_path "${PROJECT_SOURCE_DIR}/deps/v8")
89

910
GetBranchAndOS(__deps_branch __deps_os_path_name)
10-
set(__deps_url_base_path "https://cdn.alt-mp.com/deps/v8/${__deps_branch}")
11+
set(__deps_url_base_path "https://cdn.alt-mp.com/deps/v8/${V8_VERSION}")
1112

1213
if(__deps_check_enabled)
1314
message("Checking release binaries...")
1415

1516
GetCDNInfo("${__deps_url_base_path}/${__deps_os_path_name}/Release" __deps_release_hashes __deps_current_version)
16-
1717
DownloadFile("v8_monolith.lib" "${__base_path}/lib/Release" "${__deps_os_path_name}/Release" ${__deps_release_hashes})
1818

1919
# Only download debug binary in Debug builds
2020
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
2121
message("Checking debug binaries...")
2222

23-
GetCDNInfo("${__deps_url_base_path}/${__deps_os_path_name}/Debug" __deps_debug_hashes __deps_current_version)
24-
25-
DownloadFile("v8_monolith.lib" "${__base_path}/lib/Debug" "${__deps_os_path_name}/Debug" ${__deps_debug_hashes})
23+
# GetCDNInfo("${__deps_url_base_path}/${__deps_os_path_name}/Debug" __deps_debug_hashes __deps_current_version)
24+
# DownloadFile("v8_monolith.lib" "${__base_path}/lib/Debug" "${__deps_os_path_name}/Debug" ${__deps_debug_hashes})
2625
endif()
2726

28-
GetCDNInfo("${__deps_url_base_path}" __deps_headers_hashes __deps_current_version)
29-
DownloadFile("headers.zip" "${__base_path}/include" "" ${__deps_headers_hashes})
30-
file(ARCHIVE_EXTRACT INPUT "${__base_path}/include/headers.zip" DESTINATION "${__base_path}/..")
27+
GetCDNInfo("${__deps_url_base_path}/include" __deps_headers_hashes __deps_current_version)
28+
DownloadFile("include.zip" "${__base_path}/include" "include" ${__deps_headers_hashes})
29+
file(ARCHIVE_EXTRACT INPUT "${__base_path}/include/include.zip" DESTINATION "${__base_path}/include")
30+
file(REMOVE "${__base_path}/include/include.zip")
3131

3232
if(__deps_current_version)
3333
message("V8 deps version: ${__deps_current_version}")

client/src/CV8Resource.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,16 @@ v8::MaybeLocal<v8::Value> EvaluateSyntheticModule(v8::Local<v8::Context> context
567567

568568
v8::Local<v8::Module> CV8ResourceImpl::CreateSyntheticModule(const std::string& name, v8::Local<v8::Value> exportValue)
569569
{
570-
std::vector<v8::Local<v8::String>> exports = {V8Helpers::JSValue("default")};
570+
v8::Local<v8::String> defaultExport = V8Helpers::JSValue("default");
571+
v8::MemorySpan<const v8::Local<v8::String>> exports = { &defaultExport, 1 };
572+
571573
v8::Local<v8::Module> syntheticModule = v8::Module::CreateSyntheticModule(
572-
isolate, V8Helpers::JSValue(name), exports, &EvaluateSyntheticModule);
574+
isolate, V8Helpers::JSValue(name), exports, &EvaluateSyntheticModule);
575+
573576
syntheticModuleExports.insert({
574577
syntheticModule->GetIdentityHash(), V8Helpers::CPersistent<v8::Value>(isolate, exportValue)
575-
});
578+
});
579+
576580
return syntheticModule;
577581
}
578582

client/src/CV8ScriptRuntime.cpp

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
21
#include "CV8ScriptRuntime.h"
32
#include "inspector/CV8InspectorClient.h"
43
#include "inspector/CV8InspectorChannel.h"
54
#include "V8Module.h"
65
#include "events/Events.h"
7-
#include "CProfiler.h"
6+
#include "CProfiler.h"
7+
#include <Windows.h>
88

99
CV8ScriptRuntime::CV8ScriptRuntime()
1010
{
1111
// !!! Don't change these without adjusting bytecode module !!!
1212
v8::V8::SetFlagsFromString("--harmony-import-assertions --short-builtin-calls --no-lazy --no-flush-bytecode");
13-
platform = v8::platform::NewDefaultPlatform();
13+
platform = v8::platform::NewDefaultPlatform();
14+
15+
v8::LogEventCallback;
16+
1417
v8::V8::InitializePlatform(platform.get());
1518
v8::V8::InitializeICU((alt::ICore::Instance().GetClientPath() + "/libs/icudtl_v8.dat").c_str());
19+
// MessageBoxA(NULL, "js init 3", "", MB_OK);
1620
v8::V8::Initialize();
1721

1822
create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
@@ -22,9 +26,10 @@ CV8ScriptRuntime::CV8ScriptRuntime()
2226
isolate->SetFatalErrorHandler([](const char* location, const char* message) { Log::Error << "[V8] " << location << ": " << message << Log::Endl; });
2327

2428
isolate->SetOOMErrorHandler(
25-
[](const char* location, bool isHeap)
29+
[](const char* location, const v8::OOMDetails& details)
2630
{
27-
if(!isHeap) return;
31+
if(!details.is_heap_oom) return;
32+
2833
Log::Error << "[V8] " << location << ": Heap out of memory. Forward this to the server developers." << Log::Endl;
2934
Log::Error << "[V8] The current heap limit can be shown with the 'heap' console command. Consider increasing your system RAM." << Log::Endl;
3035
});
@@ -79,22 +84,26 @@ CV8ScriptRuntime::CV8ScriptRuntime()
7984
});
8085

8186
isolate->SetHostImportModuleDynamicallyCallback(
82-
[](v8::Local<v8::Context> context, v8::Local<v8::ScriptOrModule> referrer, v8::Local<v8::String> specifier, v8::Local<v8::FixedArray> importAssertions)
87+
[](v8::Local<v8::Context> context,
88+
v8::Local<v8::Data> host_defined_options,
89+
v8::Local<v8::Value> resource_name,
90+
v8::Local<v8::String> specifier,
91+
v8::Local<v8::FixedArray> import_attributes)
8392
{
8493
v8::Isolate* isolate = context->GetIsolate();
8594

86-
auto referrerVal = referrer->GetResourceName();
87-
if(referrerVal->IsUndefined()) return v8::MaybeLocal<v8::Promise>();
95+
if(resource_name->IsUndefined())
96+
return v8::MaybeLocal<v8::Promise>();
8897

89-
std::string referrerUrl = *v8::String::Utf8Value(isolate, referrer->GetResourceName());
98+
std::string referrerUrl = *v8::String::Utf8Value(isolate, resource_name);
9099
auto resource = static_cast<CV8ResourceImpl*>(V8ResourceImpl::Get(context));
91100

92101
auto resolver = v8::Promise::Resolver::New(context).ToLocalChecked();
93102

94103
V8Helpers::CPersistent<v8::Promise::Resolver> presolver(isolate, resolver);
95104
V8Helpers::CPersistent<v8::String> pspecifier(isolate, specifier);
96105
V8Helpers::CPersistent<v8::Module> preferrerModule(isolate, resource->GetModuleFromPath(referrerUrl));
97-
V8Helpers::CPersistent<v8::FixedArray> pimportAssertions(isolate, importAssertions);
106+
V8Helpers::CPersistent<v8::FixedArray> pimportAssertions(isolate, import_attributes);
98107

99108
// careful what we take in by value in the lambda
100109
// it is possible pass v8::Local but should not be done
@@ -236,7 +245,7 @@ void CV8ScriptRuntime::OnDispose()
236245
while(isolate->IsInUse()) isolate->Exit();
237246
isolate->Dispose();
238247
v8::V8::Dispose();
239-
v8::V8::ShutdownPlatform();
248+
v8::V8::DisposePlatform();
240249
delete create_params.array_buffer_allocator;
241250

242251
if(CProfiler::Instance().IsEnabled()) CProfiler::Instance().Dump(alt::ICore::Instance().GetClientPath());

client/src/bindings/Handling.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ static void DriveBiasRearSetter(v8::Local<v8::String>, v8::Local<v8::Value> val,
237237
V8_TO_NUMBER(val, fvalue);
238238
vehicle->ReplaceHandling();
239239
vehicle->GetHandling()->SetDriveBiasRear(fvalue);
240-
}
240+
}
241241

242242
static void AccelerationGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
243243
{
244-
V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear");
244+
V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear");
245245

246246
V8_GET_ISOLATE_CONTEXT();
247247
V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle);
@@ -251,7 +251,7 @@ static void AccelerationGetter(v8::Local<v8::String>, const v8::PropertyCallback
251251

252252
static void AccelerationSetter(v8::Local<v8::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& info)
253253
{
254-
V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear");
254+
V8_DEPRECATE("HandlingData.acceleration", "HandlingData.driveBiasRear");
255255

256256
V8_GET_ISOLATE_CONTEXT();
257257
V8_GET_THIS_INTERNAL_FIELD_ENTITY(1, vehicle, alt::IVehicle);

client/src/bindings/HandlingData.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void HandlingNameHashGetter(v8::Local<v8::String>, const v8::PropertyCall
4646

4747
V8_GET_THIS_INTERNAL_FIELD_INTEGER(1, modelHash);
4848

49-
uint32_t modelHash2 = info.This()->GetInternalField(0)->IntegerValue(ctx).ToChecked();
49+
uint32_t modelHash2 = info.This()->GetInternalField(0).As<v8::Value>()->IntegerValue(ctx).ToChecked();
5050

5151
auto handling = alt::ICore::Instance().GetHandlingData(modelHash);
5252
V8_CHECK(handling, "handling data for vehicle not found");

client/src/bindings/V8Natives.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void* ToMemoryBuffer(v8::Local<v8::Value> val, v8::Local<v8::Context> ctx
5252
if(cls == V8Class::ObjectClass::MEMORY_BUFFER)
5353
{
5454
void* memory = obj->GetAlignedPointerFromInternalField(1);
55-
uint32_t size = obj->GetInternalField(2)->Uint32Value(ctx).ToChecked();
55+
uint32_t size = obj->GetInternalField(2).As<v8::Value>()->Uint32Value(ctx).ToChecked();
5656

5757
if(size > 0) return memory;
5858
}

client/src/workers/CWorker.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ void CWorker::SetupIsolate()
150150
});
151151

152152
isolate->SetHostImportModuleDynamicallyCallback(
153-
[](v8::Local<v8::Context> context, v8::Local<v8::ScriptOrModule> referrer, v8::Local<v8::String> specifier, v8::Local<v8::FixedArray> assertions)
153+
[](v8::Local<v8::Context> context,
154+
v8::Local<v8::Data> host_defined_options,
155+
v8::Local<v8::Value> resource_name,
156+
v8::Local<v8::String> specifier,
157+
v8::Local<v8::FixedArray> import_attributes)
154158
{
155159
v8::Isolate* isolate = context->GetIsolate();
156160
v8::Isolate::Scope isolateScope(isolate);
@@ -161,13 +165,15 @@ void CWorker::SetupIsolate()
161165
if(maybeResolver.IsEmpty()) return v8::MaybeLocal<v8::Promise>();
162166
v8::Local<v8::Promise::Resolver> resolver = maybeResolver.ToLocalChecked();
163167

168+
// if(!resource_name->IsString()) return v8::MaybeLocal<v8::Promise>();
169+
164170
CWorker* worker = static_cast<CWorker*>(context->GetAlignedPointerFromEmbedderData(2));
165-
std::string referrerName = *v8::String::Utf8Value(isolate, referrer->GetResourceName());
171+
std::string referrerName = *v8::String::Utf8Value(isolate, resource_name);
166172
v8::Local<v8::Module> referrerModule = worker->GetModuleFromPath(referrerName);
167173
if(referrerModule.IsEmpty() && referrerName != "<bootstrapper>") resolver->Reject(context, v8::Exception::ReferenceError(V8Helpers::JSValue("Could not resolve referrer module")));
168174
else
169175
{
170-
v8::MaybeLocal<v8::Module> maybeModule = CWorker::Import(context, specifier, assertions, referrerModule);
176+
v8::MaybeLocal<v8::Module> maybeModule = CWorker::Import(context, specifier, import_attributes, referrerModule);
171177
if(maybeModule.IsEmpty()) resolver->Reject(context, v8::Exception::ReferenceError(V8Helpers::JSValue("Could not resolve module")));
172178
else
173179
{
@@ -218,7 +224,7 @@ bool CWorker::SetupScript()
218224
{
219225
v8::Local<v8::Context> ctx = context.Get(isolate);
220226
v8::MaybeLocal<v8::Module> maybeModule;
221-
v8::ScriptOrigin scriptOrigin(isolate, V8Helpers::JSValue("<bootstrapper>"), 0, 0, false, -1, v8::Local<v8::Value>(), false, false, true, v8::Local<v8::PrimitiveArray>());
227+
v8::ScriptOrigin scriptOrigin(V8Helpers::JSValue("<bootstrapper>"), 0, 0, false, -1, v8::Local<v8::Value>(), false, false, true, v8::Local<v8::PrimitiveArray>());
222228
v8::ScriptCompiler::Source source{ V8Helpers::JSValue(bootstrap_code), scriptOrigin };
223229
maybeModule = v8::ScriptCompiler::CompileModule(isolate, &source);
224230

shared/V8Entity.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ class V8Entity
4343
v8::Local<v8::Object> obj = val.As<v8::Object>();
4444
if(obj->InternalFieldCount() <= static_cast<int>(V8Class::InternalFields::BASE_OBJECT)) return nullptr;
4545

46-
v8::Local<v8::Value> i = obj->GetInternalField(static_cast<int>(V8Class::InternalFields::BASE_OBJECT));
47-
if(!i->IsExternal()) return nullptr;
46+
v8::Local<v8::Data> i = obj->GetInternalField(static_cast<int>(V8Class::InternalFields::BASE_OBJECT));
47+
if(!i->IsValue()) return nullptr;
48+
49+
v8::Local<v8::Value> iv = i.As<v8::Value>();
50+
if(!iv->IsExternal()) return nullptr;
4851

4952
return static_cast<V8Entity*>(i.As<v8::External>()->Value());
5053
}

shared/V8FastFunction.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ v8::Local<v8::FunctionTemplate> V8FastFunction::GetTemplate(v8::Isolate* isolate
1818

1919
v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(
2020
isolate, slowCallback, v8::Local<v8::Value>(), v8::Local<v8::Signature>(), 1, v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasSideEffect, &fastCallback);
21-
tplMap.insert({ isolate, v8::Persistent<v8::FunctionTemplate, v8::CopyablePersistentTraits<v8::FunctionTemplate>>(isolate, tpl) });
21+
22+
tplMap.insert({ isolate, v8::Persistent<v8::FunctionTemplate>(isolate, tpl) });
2223
return tpl;
2324
}
2425

shared/V8Helpers.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,7 @@ v8::Local<v8::Object> V8Helpers::CreateCustomObject(v8::Isolate* isolate,
134134
v8::GenericNamedPropertyQueryCallback query)
135135
{
136136
v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New(isolate);
137-
v8::NamedPropertyHandlerConfiguration config;
138-
config.getter = getter;
139-
config.setter = setter;
140-
config.deleter = deleter;
141-
config.query = query;
142-
config.enumerator = enumerator;
143-
config.data = v8::External::New(isolate, data);
144-
config.flags = v8::PropertyHandlerFlags::kHasNoSideEffect;
137+
v8::NamedPropertyHandlerConfiguration config{ getter, setter, query, deleter, enumerator, v8::External::New(isolate, data), v8::PropertyHandlerFlags::kHasNoSideEffect };
145138
objTemplate->SetHandler(config);
146139

147140
v8::Local<v8::Object> obj = objTemplate->NewInstance(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked();
@@ -384,10 +377,13 @@ V8Class::ObjectClass V8Helpers::GetObjectClass(v8::Local<v8::Object> obj)
384377
{
385378
if(obj->InternalFieldCount() <= static_cast<int>(V8Class::InternalFields::OBJECT_CLASS))
386379
return V8Class::ObjectClass::NONE;
380+
381+
auto data = obj->GetInternalField(static_cast<int>(V8Class::InternalFields::OBJECT_CLASS));
382+
if(!data->IsValue()) return V8Class::ObjectClass::NONE;
387383

388-
auto val = obj->GetInternalField(static_cast<int>(V8Class::InternalFields::OBJECT_CLASS));
384+
auto val = data.As<v8::Value>();
389385
if(!val->IsExternal())
390-
return V8Class::ObjectClass::NONE;
386+
return V8Class::ObjectClass::NONE;
391387

392388
void* cls = val.As<v8::External>()->Value();
393389
return *reinterpret_cast<V8Class::ObjectClass*>(&cls);

shared/cmake/DepsHelpers.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function(DownloadFile name path urlpath checksums)
66
else()
77
set(__deps_file_checksum 0)
88
endif()
9+
910
string(JSON __deps_file_checksum_cdn GET ${checksums} ${name})
1011
if(NOT ${__deps_file_checksum} STREQUAL ${__deps_file_checksum_cdn})
1112
message("Downloading ${name}...")
@@ -18,9 +19,11 @@ function(DownloadFile name path urlpath checksums)
1819
file(DOWNLOAD "${__download_url}" "${path}/${name}"
1920
STATUS DOWNLOAD_STATUS
2021
)
22+
2123
# Separate the returned status code, and error message.
2224
list(GET DOWNLOAD_STATUS 0 STATUS_CODE)
2325
list(GET DOWNLOAD_STATUS 1 ERROR_MESSAGE)
26+
2427
# Check if download was successful.
2528
if(${STATUS_CODE} EQUAL 0)
2629
message(STATUS "Download completed successfully!")

shared/helpers/Bindings.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ void V8Helpers::SetAccessor(v8::Isolate* isolate, v8::Local<v8::FunctionTemplate
5454
getter,
5555
setter,
5656
v8::Local<v8::Value>(),
57-
v8::AccessControl::DEFAULT,
5857
setter != nullptr ? v8::PropertyAttribute::None : v8::PropertyAttribute::ReadOnly);
5958
}
6059

shared/helpers/Macros.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,29 @@
5050

5151
#define V8_GET_THIS_INTERNAL_FIELD_OBJECT(idx, val) \
5252
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
53-
auto val = info.This()->GetInternalField(idx)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked();
53+
auto val = info.This()->GetInternalField(idx).As<v8::Value>()->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked();
5454

5555
#define V8_GET_THIS_INTERNAL_FIELD_V8ENTITY(idx, val) \
5656
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
57-
auto val = V8Entity::Get(info.This()->GetInternalField(idx)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked());
57+
auto val = V8Entity::Get(info.This()->GetInternalField(idx).As<v8::Value>()->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked());
5858

5959
#define V8_GET_THIS_INTERNAL_FIELD_ENTITY(idx, val, type) \
6060
type* val; \
6161
{ \
6262
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
63-
V8Entity* __val = V8Entity::Get(info.This()->GetInternalField(idx)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked()); \
63+
V8Entity* __val = V8Entity::Get(info.This()->GetInternalField(idx).As<v8::Value>()->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked()); \
6464
V8_CHECK(__val, "baseobject is invalid"); \
6565
val = dynamic_cast<type*>(__val->GetHandle()); \
6666
V8_CHECK(val, "baseobject is not of type " #type); \
6767
}
6868

6969
#define V8_GET_THIS_INTERNAL_FIELD_INTEGER(idx, val) \
7070
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
71-
auto val = info.This()->GetInternalField(idx)->IntegerValue(ctx).ToChecked();
71+
auto val = info.This()->GetInternalField(idx).As<v8::Value>()->IntegerValue(ctx).ToChecked();
7272

7373
#define V8_GET_THIS_INTERNAL_FIELD_UINT32(idx, val) \
7474
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \
75-
auto val = info.This()->GetInternalField(idx)->Uint32Value(ctx).ToChecked();
75+
auto val = info.This()->GetInternalField(idx).As<v8::Value>()->Uint32Value(ctx).ToChecked();
7676

7777
#define V8_GET_THIS_INTERNAL_FIELD_EXTERNAL(idx, val, type) \
7878
V8_CHECK(info.This()->InternalFieldCount() > idx - 1, "Invalid internal field count (is the 'this' context correct?)"); \

0 commit comments

Comments
 (0)