-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Updated NodeJS to v22 and V8 to v12.4 (mr-650)
6c7a573 - feat(v8): Updated NodeJS to v22 and V8 to v12.4
- Loading branch information
Showing
73 changed files
with
13,135 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,4 +192,6 @@ privates_config.lua | |
/out/ | ||
|
||
# python files | ||
*.pyc | ||
*.pyc | ||
|
||
/vendor/libuv/bin/libuv.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
return function() | ||
add_dependencies { 'vendor:libnode' } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fxComponent 115 component.json |
43 changes: 43 additions & 0 deletions
43
code/components/citizen-scripting-node/include/JavaScriptEnvironmentCode.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
)"; |
42 changes: 42 additions & 0 deletions
42
code/components/citizen-scripting-node/include/NodeParentEnvironment.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
code/components/citizen-scripting-node/include/NodeScopeHandler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
179
code/components/citizen-scripting-node/include/NodeScriptRuntime.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
code/components/citizen-scripting-node/include/V8Debugger.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.