diff --git a/server/src/CNodeResourceImpl.cpp b/server/src/CNodeResourceImpl.cpp index 4b3a9f4b..ec57ac22 100644 --- a/server/src/CNodeResourceImpl.cpp +++ b/server/src/CNodeResourceImpl.cpp @@ -2,6 +2,8 @@ #include "CNodeResourceImpl.h" #include "CNodeScriptRuntime.h" +#include "V8Module.h" +#include "V8Helpers.h" static void ResourceLoaded(const v8::FunctionCallbackInfo& info) { @@ -63,6 +65,7 @@ static const char bootstrap_code[] = R"( })(); )"; +extern V8Module sharedModule; bool CNodeResourceImpl::Start() { v8::Locker locker(isolate); @@ -96,6 +99,17 @@ bool CNodeResourceImpl::Start() node::LoadEnvironment(env, bootstrap_code); + auto exports = sharedModule.GetExports(isolate, _context); + + // Overwrite global console object + auto console = _context->Global()->Get(_context, V8_NEW_STRING("console")).ToLocalChecked().As(); + if(!console.IsEmpty()) + { + console->Set(_context, V8_NEW_STRING("log"), exports->Get(_context, V8_NEW_STRING("log")).ToLocalChecked()); + console->Set(_context, V8_NEW_STRING("warn"), exports->Get(_context, V8_NEW_STRING("logWarning")).ToLocalChecked()); + console->Set(_context, V8_NEW_STRING("error"), exports->Get(_context, V8_NEW_STRING("logError")).ToLocalChecked()); + } + asyncResource.Reset(isolate, v8::Object::New(isolate)); asyncContext = node::EmitAsyncInit(isolate, asyncResource.Get(isolate), "CNodeResourceImpl");