Skip to content

Commit

Permalink
chore(shared): Remove [JS] prefix in favor of core prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Sep 22, 2024
1 parent b795574 commit fd1ed73
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 46 deletions.
12 changes: 6 additions & 6 deletions client/src/CJavaScriptResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ v8::Local<v8::Module> CJavaScriptResource::CompileAndRun(const std::string& path

if(maybeMod.IsEmpty())
{
js::Logger::Error("[JS] Failed to compile file", path);
js::Logger::Error("Failed to compile file", path);
tryCatch.Check(true, true);
return v8::Local<v8::Module>();
}
Expand All @@ -26,11 +26,11 @@ v8::Local<v8::Module> CJavaScriptResource::CompileAndRun(const std::string& path

if(!InstantiateModule(GetContext(), mod) || tryCatch.HasCaught())
{
js::Logger::Error("[JS] Failed to instantiate file", path);
js::Logger::Error("Failed to instantiate file", path);
if(mod->GetStatus() == v8::Module::kErrored)
{
js::Object exceptionObj = mod->GetException().As<v8::Object>();
js::Logger::Error("[JS]", exceptionObj.Get<std::string>("message"));
js::Logger::Error(exceptionObj.Get<std::string>("message"));
std::string stack = exceptionObj.Get<std::string>("stack");
if(!stack.empty()) js::Logger::Error(stack);
}
Expand All @@ -40,11 +40,11 @@ v8::Local<v8::Module> CJavaScriptResource::CompileAndRun(const std::string& path
v8::MaybeLocal<v8::Value> maybeResult = EvaluateModule(GetContext(), mod);
if(maybeResult.IsEmpty() || maybeResult.ToLocalChecked().As<v8::Promise>()->State() == v8::Promise::PromiseState::kRejected)
{
js::Logger::Error("[JS] Failed to start file", path);
js::Logger::Error("Failed to start file", path);
if(mod->GetStatus() == v8::Module::kErrored)
{
js::Object exceptionObj = mod->GetException().As<v8::Object>();
js::Logger::Error("[JS]", exceptionObj.Get<std::string>("message"));
js::Logger::Error(exceptionObj.Get<std::string>("message"));
std::string stack = exceptionObj.Get<std::string>("stack");
if(!stack.empty()) js::Logger::Error(stack);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ bool CJavaScriptResource::Start()
if (IsCompatibilityModeEnabled())
{
auto resourceName = resource->GetName();
js::Logger::Colored << "~y~[JS] Compatibility mode is enabled for resource " << resourceName << js::Logger::Endl;
js::Logger::Colored << "~y~Compatibility mode is enabled for resource " << resourceName << js::Logger::Endl;
}

return true;
Expand Down
8 changes: 4 additions & 4 deletions client/src/CJavaScriptRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

void CJavaScriptRuntime::OnFatalError(const char* location, const char* message)
{
js::Logger::Error("[JS] V8 fatal error!", location, message);
js::Logger::Error("V8 fatal error!", location, message);
}

void CJavaScriptRuntime::OnHeapOOM(const char* location, bool isHeap)
{
if(!isHeap) return;
js::Logger::Error("[JS] V8 heap out of memory!", location);
js::Logger::Error("V8 heap out of memory!", location);
}

size_t CJavaScriptRuntime::OnNearHeapLimit(void*, size_t current, size_t initial)
{
js::Logger::Warn("[JS] The remaining V8 heap space is approaching critical levels. Increasing heap limit...");
js::Logger::Warn("The remaining V8 heap space is approaching critical levels. Increasing heap limit...");

// Increase the heap limit by 100MB if the heap limit has not exceeded 4GB
uint64_t currentLimitMb = (current / 1024) / 1024;
Expand Down Expand Up @@ -103,7 +103,7 @@ void CJavaScriptRuntime::InitializeImportMetaObject(v8::Local<v8::Context> conte

void CJavaScriptRuntime::MessageListener(v8::Local<v8::Message> message, v8::Local<v8::Value> error)
{
js::Logger::Warn("[JS] V8 message received!", js::CppValue(message->Get()));
js::Logger::Warn("V8 message received!", js::CppValue(message->Get()));
}

void CJavaScriptRuntime::SetupIsolateHandlers()
Expand Down
14 changes: 7 additions & 7 deletions client/src/helpers/IExceptionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ void IExceptionHandler::OnPromiseRejectAfterResolve(v8::PromiseRejectMessage& me
v8::Isolate* isolate = resource->GetIsolate();
std::string rejectionMsg = *v8::String::Utf8Value(isolate, message.GetValue()->ToString(resource->GetContext()).ToLocalChecked());

js::Logger::Error("[JS] Promise rejected after already being resolved in resource '" + resourceName + "'");
if(!rejectionMsg.empty()) js::Logger::Error("[JS]", rejectionMsg);
js::Logger::Error("Promise rejected after already being resolved in resource '" + resourceName + "'");
if(!rejectionMsg.empty()) js::Logger::Error(rejectionMsg);
}

void IExceptionHandler::OnPromiseResolveAfterResolve(v8::PromiseRejectMessage& message)
Expand All @@ -38,8 +38,8 @@ void IExceptionHandler::OnPromiseResolveAfterResolve(v8::PromiseRejectMessage& m
v8::Isolate* isolate = resource->GetIsolate();
std::string rejectionMsg = *v8::String::Utf8Value(isolate, message.GetValue()->ToString(resource->GetContext()).ToLocalChecked());

js::Logger::Error("[JS] Promise resolved after already being resolved in resource '" + resourceName + "'");
if(!rejectionMsg.empty()) js::Logger::Error("[JS]", rejectionMsg);
js::Logger::Error("Promise resolved after already being resolved in resource '" + resourceName + "'");
if(!rejectionMsg.empty()) js::Logger::Error(rejectionMsg);
}

void IExceptionHandler::ProcessExceptions()
Expand All @@ -51,9 +51,9 @@ void IExceptionHandler::ProcessExceptions()
for(PromiseRejection& rejection : promiseRejections)
{
std::string rejectionMsg = *v8::String::Utf8Value(isolate, rejection.value.Get(isolate)->ToString(resource->GetContext()).ToLocalChecked());
js::Logger::Error("[JS] Unhandled promise rejection in resource '" + resourceName + "' in file '" + rejection.location.file + "' at line " + std::to_string(rejection.location.line));
if(!rejectionMsg.empty()) js::Logger::Error("[JS]", rejectionMsg);
if(!rejection.stackTrace.IsEmpty()) js::Logger::Error("[JS]", rejection.stackTrace.ToString());
js::Logger::Error("Unhandled promise rejection in resource '" + resourceName + "' in file '" + rejection.location.file + "' at line " + std::to_string(rejection.location.line));
if(!rejectionMsg.empty()) js::Logger::Error(rejectionMsg);
if(!rejection.stackTrace.IsEmpty()) js::Logger::Error(rejection.stackTrace.ToString());
}
promiseRejections.clear();
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/helpers/IModuleHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ v8::MaybeLocal<v8::Module> IModuleHandler::CompileBytecode(const std::string& na
v8::MaybeLocal<v8::Module> module = v8::ScriptCompiler::CompileModule(isolate, &source, v8::ScriptCompiler::kConsumeCodeCache);
if(cachedData->rejected)
{
js::Logger::Error("[JS] Trying to load invalid bytecode");
js::Logger::Error("Trying to load invalid bytecode");
return v8::MaybeLocal<v8::Module>();
}
return module;
Expand Down
6 changes: 3 additions & 3 deletions client/src/helpers/NativeInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool js::NativeInvoker::PushArgs(js::FunctionContext& ctx, alt::INative* native)
}
default:
{
Logger::Warn("[JS] Unknown native argument type", magic_enum::enum_name(nativeArgs[i]), "for native", native->GetName(), "at index", i);
Logger::Warn("Unknown native argument type", magic_enum::enum_name(nativeArgs[i]), "for native", native->GetName(), "at index", i);
break;
}
}
Expand All @@ -115,7 +115,7 @@ v8::Local<v8::Value> js::NativeInvoker::GetPointerReturnValue(alt::INative::Type
return resource->CreateVector3({ vector->x, vector->y, vector->z });
}
}
// js::Logger::Warn("[JS] Unknown native pointer return type:", magic_enum::enum_name(type), (int)type);
// js::Logger::Warn("Unknown native pointer return type:", magic_enum::enum_name(type), (int)type);
return v8::Undefined(resource->GetIsolate());
}

Expand All @@ -137,7 +137,7 @@ v8::Local<v8::Value> js::NativeInvoker::GetReturnValue()
case Type::ARG_STRING: return js::JSValue(nativeContext->ResultString());
case Type::ARG_VOID: return v8::Undefined(resource->GetIsolate());
}
js::Logger::Warn("[JS] Unknown native return type:", magic_enum::enum_name(native->GetRetnType()), (int)native->GetRetnType());
js::Logger::Warn("Unknown native return type:", magic_enum::enum_name(native->GetRetnType()), (int)native->GetRetnType());
return v8::Undefined(resource->GetIsolate());
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/CNodeResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bool CNodeResource::Start()
if (IsCompatibilityModeEnabled())
{
auto resourceName = resource->GetName();
js::Logger::Colored << "~y~[JS] Compatibility mode is enabled for resource " << resourceName << js::Logger::Endl;
js::Logger::Colored << "~y~Compatibility mode is enabled for resource " << resourceName << js::Logger::Endl;
}

return true;
Expand Down
10 changes: 5 additions & 5 deletions shared/js/compatibility/utils/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function applyNonStaticProperties(baseClass, cls, options) {
["get", "set", "value"].forEach((key) => {
if (key in newDescriptor && (!mergedDescriptor[key] || isWhitelisted)) {
if (options.verbose) {
alt.log(`~ly~[JS] ~lr~Merged ${key} for ${prop} from ${prot.constructor.name} to ${baseClass.name}`);
alt.log(`~lr~Merged ${key} for ${prop} from ${prot.constructor.name} to ${baseClass.name}`);
}
mergedDescriptor[key] = newDescriptor[key];
}
Expand All @@ -50,7 +50,7 @@ function applyNonStaticProperties(baseClass, cls, options) {

if (options.verbose) {
const action = baseDescriptor ? "Merged" : "Applied";
alt.log(`~ly~[JS] ~lb~${action} non-static property ${prop} from ${prot.constructor.name} to ${baseClass.name}`);
alt.log(`~lb~${action} non-static property ${prop} from ${prot.constructor.name} to ${baseClass.name}`);
}
}
}
Expand All @@ -67,7 +67,7 @@ function applyStaticProperties(baseClass, cls, options) {
if (doesPropertyExist && !canBeOverriden) {
if (options.verbose) {
const reason = !canBeOverriden ? "blacklisted" : "already exists";
alt.log(`~ly~[JS] ~lb~Skipping static property ${propKey} in ${cls.name}: ${reason}`);
alt.log(`~lb~Skipping static property ${propKey} in ${cls.name}: ${reason}`);
}

continue;
Expand All @@ -82,7 +82,7 @@ function applyStaticProperties(baseClass, cls, options) {
Object.defineProperty(baseClass, propKey, descriptor);

if (options.verbose) {
alt.log(`~ly~[JS] ~lb~Applied static property ${propKey} in ${cls.name} to ${baseClass.name}`);
alt.log(`~lb~Applied static property ${propKey} in ${cls.name} to ${baseClass.name}`);
}
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ export function overrideLazyProperty(instance, propertyName, value) {
const descriptor = Object.getOwnPropertyDescriptor(instance, propertyName);

if (!descriptor) {
alt.log(`~ly~[JS] ~lr~Lazy Property ${propertyName} does not exist in ${instance.constructor.name} to override property`);
alt.log(`~lr~Lazy Property ${propertyName} does not exist in ${instance.constructor.name} to override property`);
return;
}

Expand Down
12 changes: 6 additions & 6 deletions shared/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ export class Event {

const duration = alt.getNetTime() - startTime;
if (duration > Event.#warningThreshold) {
alt.logWarning(`[JS] Event handler in resource '${cppBindings.resourceName}' (${location.fileName}:${location.lineNumber}) for script event '${name}' took ${duration}ms to execute (Threshold: ${Event.#warningThreshold}ms)`);
alt.logWarning(`Event handler in resource '${cppBindings.resourceName}' (${location.fileName}:${location.lineNumber}) for script event '${name}' took ${duration}ms to execute (Threshold: ${Event.#warningThreshold}ms)`);
}

if (onlyOnce) eventHandler.destroy();
} catch (e) {
alt.logError(`[JS] Exception caught while invoking script event '${name}' handler`);
alt.logError(`Exception caught while invoking script event '${name}' handler`);
alt.logError(e);

Event.invoke(alt.Enums.CustomEventType.ERROR, { error: e, location, stack: e.stack }, true);
Expand Down Expand Up @@ -218,10 +218,10 @@ export class Event {

const duration = alt.getNetTime() - startTime;
if (duration > Event.#warningThreshold) {
alt.logWarning(`[JS] Generic event handler in resource '${cppBindings.resourceName}' (${location.fileName}:${location.lineNumber}) for event '${Event.getEventName(eventType, custom)}' took ${duration}ms to execute (Threshold: ${Event.#warningThreshold}ms)`);
alt.logWarning(`Generic event handler in resource '${cppBindings.resourceName}' (${location.fileName}:${location.lineNumber}) for event '${Event.getEventName(eventType, custom)}' took ${duration}ms to execute (Threshold: ${Event.#warningThreshold}ms)`);
}
} catch (e) {
alt.logError(`[JS] Exception caught while invoking generic event handler`);
alt.logError(`Exception caught while invoking generic event handler`);
alt.logError(e);

Event.invoke(alt.Enums.CustomEventType.ERROR, { error: e, location, stack: e.stack }, true);
Expand Down Expand Up @@ -292,14 +292,14 @@ export class Event {

const duration = alt.getNetTime() - startTime;
if (duration > Event.#warningThreshold) {
alt.logWarning(`[JS] Event handler in resource '${cppBindings.resourceName}' (${location.fileName}:${location.lineNumber}) for event '${Event.getEventName(eventType, custom)}' took ${duration}ms to execute (Threshold: ${Event.#warningThreshold}ms)`);
alt.logWarning(`Event handler in resource '${cppBindings.resourceName}' (${location.fileName}:${location.lineNumber}) for event '${Event.getEventName(eventType, custom)}' took ${duration}ms to execute (Threshold: ${Event.#warningThreshold}ms)`);
}

if (onlyOnce) {
eventHandler.destroy();
}
} catch (e) {
alt.logError(`[JS] Exception caught while invoking event handler`);
alt.logError(`Exception caught while invoking event handler`);
alt.logError(e);

Event.invoke(alt.Enums.CustomEventType.ERROR, { error: e, location, stack: e.stack }, true);
Expand Down
4 changes: 2 additions & 2 deletions shared/js/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,7 @@ function timeLog(label) {
}

const duration = alt.getNetTime() - startTime;
alt.log(`[JS] ${label ?? "Timer"}: ${duration}ms`);
alt.log(`${label ?? "Timer"}: ${duration}ms`);
}
function timeEnd(label) {
const startTime = timeLabelMap.get(label ?? "Timer");
Expand All @@ -2836,7 +2836,7 @@ function timeEnd(label) {
}

const duration = alt.getNetTime() - startTime;
alt.log(`[JS] ${label ?? "Timer"}: ${duration}ms`);
alt.log(`${label ?? "Timer"}: ${duration}ms`);
timeLabelMap.delete(label ?? "Timer");
}

Expand Down
4 changes: 2 additions & 2 deletions shared/js/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Timer {
try {
this.callback();
} catch (e) {
alt.logError(`[JS] Exception caught while invoking timer callback`);
alt.logError(`Exception caught while invoking timer callback`);
alt.logError(e);

Event.invoke(alt.Enums.CustomEventType.ERROR, { error: e, location: this.location, stack: e.stack }, true);
Expand All @@ -113,7 +113,7 @@ class Timer {

const duration = this.lastTick - now;
if (duration > Timer.#_warningThreshold) {
alt.logWarning(`[JS] Timer callback in resource '${cppBindings.resourceName}' (${this.location.fileName}:${this.location.lineNumber}) took ${duration}ms to execute (Threshold: ${Timer.#_warningThreshold}ms)`);
alt.logWarning(`Timer callback in resource '${cppBindings.resourceName}' (${this.location.fileName}:${this.location.lineNumber}) took ${duration}ms to execute (Threshold: ${Timer.#_warningThreshold}ms)`);
}

if (this.once) this.destroy();
Expand Down
10 changes: 5 additions & 5 deletions shared/src/Bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ void js::Binding::CleanupForResource(IResource* resource)

void js::Binding::Dump()
{
Logger::Warn("[JS] Binding:", GetName());
Logger::Warn("[JS] Valid:", IsValid());
Logger::Warn("[JS] Scope:", magic_enum::enum_name(GetScope()));
Logger::Warn("[JS] Source size:", strlen(GetSource()));
Logger::Warn("Binding:", GetName());
Logger::Warn(" Valid:", IsValid());
Logger::Warn(" Scope:", magic_enum::enum_name(GetScope()));
Logger::Warn(" Source size:", strlen(GetSource()));
Logger::Warn(GetSource());
}

void js::Binding::DumpAll()
{
Logger::Warn("[JS] Bindings count:", __bindings.size());
Logger::Warn("Bindings count:", __bindings.size());
for(auto& [name, binding] : __bindings) binding.Dump();
}
10 changes: 6 additions & 4 deletions shared/src/helpers/JS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ void js::TryCatch::PrintError(bool skipLocation)
std::string stack = stackTrace.IsEmpty() ? "" : *v8::String::Utf8Value(isolate, stackTrace.ToLocalChecked());
std::string exceptionStr = *v8::String::Utf8Value(isolate, exception);

if(!skipLocation) Logger::Error("[JS] Exception caught in resource '" + resource->GetName() + "' in file '" + file + "' at line " + lineStr);
if(!skipLocation) Logger::Error("Exception caught in resource '" + resource->GetName() + "' in file '" + file + "' at line " + lineStr);
if(!exceptionStr.empty() && stack.empty())
{
Logger::Error("[JS]", exceptionStr);
Logger::Error("[JS] ", sourceLine);
Logger::Error(exceptionStr);
Logger::Error(" ", sourceLine);
}
if(!stack.empty()) Logger::Error("[JS]", stack);

if(!stack.empty())
Logger::Error(stack);

js::Event::EventArgs args;
args.Set("error", exception);
Expand Down

0 comments on commit fd1ed73

Please sign in to comment.