Skip to content

Commit

Permalink
Merge Updated NodeJS to v22 and V8 to v12.4 (mr-650)
Browse files Browse the repository at this point in the history
6c7a573 - feat(v8): Updated NodeJS to v22 and V8 to v12.4
  • Loading branch information
prikolium-cfx committed Feb 17, 2025
2 parents c1cff3d + 6c7a573 commit 20a7e90
Show file tree
Hide file tree
Showing 73 changed files with 13,135 additions and 181 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,6 @@ privates_config.lua
/out/

# python files
*.pyc
*.pyc

/vendor/libuv/bin/libuv.*
12 changes: 6 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
[submodule "vendor/rapidjson"]
path = vendor/rapidjson
url = https://github.com/miloyip/rapidjson.git
[submodule "vendor/libuv"]
path = vendor/libuv
url = https://github.com/citizenfx/libuv.git
[submodule "vendor/fmtlib"]
path = vendor/fmtlib
url = https://github.com/fmtlib/fmt.git
Expand All @@ -56,9 +53,6 @@
[submodule "vendor/tbb"]
path = vendor/tbb
url = https://github.com/citizenfx/oneTBB.git
[submodule "vendor/cpprestsdk"]
path = vendor/cpprestsdk
url = https://github.com/Microsoft/cpprestsdk.git
[submodule "vendor/discord-rpc"]
path = vendor/discord-rpc
url = https://github.com/citizenfx/discord-rpc.git
Expand Down Expand Up @@ -457,6 +451,12 @@
[submodule "vendor/boost-submodules/boost-static-string"]
path = vendor/boost-submodules/boost-static-string
url = https://github.com/boostorg/static_string.git
[submodule "vendor/libnode/node"]
path = vendor/libnode/node
url = https://github.com/nodejs/node.git
[submodule "vendor/v8/12.4/source"]
path = vendor/v8/12.4/source
url = https://github.com/v8/v8.git
[submodule "vendor/AntiLag2-SDK"]
path = vendor/AntiLag2-SDK
url = https://github.com/GPUOpen-LibrariesAndSDKs/AntiLag2-SDK
6 changes: 1 addition & 5 deletions code/components/citizen-resources-core/component.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
if not os.istarget('windows') then
links { 'crypto', 'ssl' }
end

-- don't infect any downstream dependencies
return function()
add_dependencies { 'vendor:eastl', 'net:base' }
add_dependencies {'vendor:eastl', 'net:base'}
end
11 changes: 11 additions & 0 deletions code/components/citizen-scripting-node/component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "citizen:scripting:node",
"version": "0.1.0",
"dependencies": [
"fx[2]",
"net:tcp-server",
"citizen:server:instance",
"citizen:scripting:core"
],
"provides": []
}
3 changes: 3 additions & 0 deletions code/components/citizen-scripting-node/component.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return function()
add_dependencies { 'vendor:libnode' }
end
1 change: 1 addition & 0 deletions code/components/citizen-scripting-node/component.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fxComponent 115 component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

inline const char* g_envCode = R"(
function defineStream(name, getter) {
Object.defineProperty(process, name, {
configurable: true,
enumerable: true,
get: getter
});
}
defineStream('stdin', getStdin);
let stdin;
function getStdin() {
if (stdin) return stdin;
const fd = 0;
const { Readable } = require('stream');
stdin = new Readable({ read() {} });
stdin.push(null);
stdin.fd = 0;
return stdin;
}
//internals can't be accessed anymore even with --expose-internals, patch for this is added in libnode build
const { addBuiltinLibsToObject } = require('internal/modules/helpers');
addBuiltinLibsToObject(global);
const Module = require('module');
const m = new Module('dummy.js');
m.filename = Citizen.getResourcePath() + '/dummy.js';
m.paths = Module._nodeModulePaths(Citizen.getResourcePath() + '/');
const script = 'module.exports = {require};';
const result = m._compile(script, 'dummy-wrapper');
global.require = m.exports.require;
)";
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/

#pragma once

#include "StdInc.h"

#include <om/OMComponent.h>

#include <node/src/node.h>
#include <node/deps/uv/include/uv.h>

namespace fx::nodejs
{
class NodeParentEnvironment
{
private:
std::unique_ptr<node::MultiIsolatePlatform> m_platform;
bool m_initialized = false;

public:
NodeParentEnvironment() = default;

result_t Initialize();
bool IsStartNode() const;
result_t StartNode();

node::MultiIsolatePlatform* GetPlatform() const
{
return m_platform.get();
}

bool IsInitialized() const
{
return m_initialized;
}
};
}
29 changes: 29 additions & 0 deletions code/components/citizen-scripting-node/include/NodeScopeHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/

#pragma once

#include "StdInc.h"

#include "UvTcpServer.h"
#include "UvLoopManager.h"
#include "NodeScriptRuntime.h"

namespace fx::nodejs
{
class ScopeHandler
{
private:
bool m_initialized = false;

public:
ScopeHandler() = default;

void Initialize();
void Shutdown();
};
}
179 changes: 179 additions & 0 deletions code/components/citizen-scripting-node/include/NodeScriptRuntime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/

#pragma once

#include "StdInc.h"

#include <deque>

#include <fxScripting.h>
#include <Resource.h>
#include <ManifestVersion.h>

#include <om/OMComponent.h>

#include <node/deps/v8/include/v8config.h>
#include <node/deps/v8/include/v8.h>
#include <node/deps/v8/include/v8-profiler.h>
#include <node/src/node.h>
#include <node/deps/uv/include/uv.h>

#include "shared/RuntimeHelpers.h"
#include "fxScriptBuffer.h"

#include <ScriptInvoker.h>
using namespace fx::invoker;

namespace fx::nodejs
{
class NodeScriptRuntime : public OMClass<NodeScriptRuntime, IScriptRuntime, IScriptFileHandlingRuntime, IScriptTickRuntime, IScriptEventRuntime,
IScriptRefRuntime, IScriptStackWalkingRuntime, IScriptWarningRuntime>
{
private:
typedef std::function<void(const char*, const char*, size_t, const char*)> TEventRoutine;
typedef std::function<fx::OMPtr<IScriptBuffer>(int32_t, const char*, size_t)> TCallRefRoutine;
typedef std::function<int32_t(int32_t)> TDuplicateRefRoutine;
typedef std::function<void(int32_t)> TDeleteRefRoutine;
typedef std::function<void(void*, void*, char**, size_t*)> TStackTraceRoutine;
typedef std::function<void(v8::PromiseRejectMessage&)> TUnhandledPromiseRejectionRoutine;
typedef std::function<void()> TTickRoutine;

int m_instanceId;
std::string m_name;
std::string m_resourceName;

// direct host access
IScriptHost* m_scriptHost = nullptr;
IScriptHostWithResourceData* m_resourceHost = nullptr;
IScriptHostWithManifest* m_manifestHost = nullptr;
fx::Resource* m_parentObject = nullptr;
fx::OMPtr<IScriptRuntimeHandler> m_handler;

// v8 ande nodejs related
uv_loop_t* m_uvLoop = nullptr;
v8::Isolate* m_isolate = nullptr;
v8::UniquePersistent<v8::Context> m_context;
node::IsolateData* m_isolateData = nullptr;
node::Environment* m_nodeEnvironment = nullptr;

// string values, which need to be persisted across calls as well
std::unique_ptr<v8::String::Utf8Value> m_stringValues[50];
int m_curStringValue;

// routines and callbacks
TTickRoutine m_tickRoutine;
TEventRoutine m_eventRoutine;
TCallRefRoutine m_callRefRoutine;
TDuplicateRefRoutine m_duplicateRefRoutine;
TDeleteRefRoutine m_deleteRefRoutine;
TStackTraceRoutine m_stackTraceRoutine;
TUnhandledPromiseRejectionRoutine m_unhandledPromiseRejectionRoutine;

public:
NodeScriptRuntime()
{
m_instanceId = rand() ^ 0x3e3;
m_name = "ScriptDomain_" + std::to_string(m_instanceId);
m_curStringValue = 0;
}

result_t LoadFileInternal(OMPtr<fxIStream> stream, char* scriptFile, v8::Local<v8::Script>* outScript);
result_t LoadHostFileInternal(char* scriptFile, v8::Local<v8::Script>* outScript, bool isSystem = false);
result_t RunFileInternal(char* scriptName, std::function<result_t(char*, v8::Local<v8::Script>*)> loadFunction);
result_t LoadSystemFile(char* scriptFile);
const char* AssignStringValue(const v8::Local<v8::Value>& value, size_t* length);

v8::Isolate* GetIsolate() const
{
return m_isolate;
}

v8::Local<v8::Context> GetContext() const
{
return m_context.Get(m_isolate);
}

OMPtr<IScriptHost> GetScriptHost() const
{
return m_scriptHost;
}

const char* GetResourceName() const
{
char* resourceName = nullptr;
m_resourceHost->GetResourceName(&resourceName);

return resourceName;
}

void SetTickRoutine(const TTickRoutine& tickRoutine)
{
if (!m_tickRoutine)
{
m_tickRoutine = tickRoutine;
}
}

void SetEventRoutine(const TEventRoutine& eventRoutine)
{
if (!m_eventRoutine)
{
m_eventRoutine = eventRoutine;
}
}

void SetCallRefRoutine(const TCallRefRoutine& routine)
{
if (!m_callRefRoutine)
{
m_callRefRoutine = routine;
}
}

void SetDuplicateRefRoutine(const TDuplicateRefRoutine& routine)
{
if (!m_duplicateRefRoutine)
{
m_duplicateRefRoutine = routine;
}
}

void SetDeleteRefRoutine(const TDeleteRefRoutine& routine)
{
if (!m_deleteRefRoutine)
{
m_deleteRefRoutine = routine;
}
}

void SetStackTraceRoutine(const TStackTraceRoutine& routine)
{
if (!m_stackTraceRoutine)
{
m_stackTraceRoutine = routine;
}
}

void SetUnhandledPromiseRejectionRoutine(const TUnhandledPromiseRejectionRoutine& routine)
{
if (!m_unhandledPromiseRejectionRoutine)
{
m_unhandledPromiseRejectionRoutine = routine;
}
}

public:
NS_DECL_ISCRIPTRUNTIME;
NS_DECL_ISCRIPTFILEHANDLINGRUNTIME;
NS_DECL_ISCRIPTTICKRUNTIME;
NS_DECL_ISCRIPTEVENTRUNTIME;
NS_DECL_ISCRIPTREFRUNTIME;
NS_DECL_ISCRIPTSTACKWALKINGRUNTIME;
NS_DECL_ISCRIPTWARNINGRUNTIME;
};
}
24 changes: 24 additions & 0 deletions code/components/citizen-scripting-node/include/V8Debugger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/

#pragma once

namespace v8
{
class Isolate;
}

namespace fx
{
class V8Debugger
{
public:
virtual ~V8Debugger() {}
};

V8Debugger* CreateDebugger(v8::Isolate* isolate);
}
Loading

0 comments on commit 20a7e90

Please sign in to comment.