Skip to content

Commit

Permalink
server: Add console log, error, warn overwrite
Browse files Browse the repository at this point in the history
Former-commit-id: f9d155b
  • Loading branch information
C0kkie committed Oct 18, 2021
1 parent 9cb2966 commit 8febddc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/src/CNodeResourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "CNodeResourceImpl.h"
#include "CNodeScriptRuntime.h"
#include "V8Module.h"
#include "V8Helpers.h"

static void ResourceLoaded(const v8::FunctionCallbackInfo<v8::Value>& info)
{
Expand Down Expand Up @@ -63,6 +65,7 @@ static const char bootstrap_code[] = R"(
})();
)";

extern V8Module sharedModule;
bool CNodeResourceImpl::Start()
{
v8::Locker locker(isolate);
Expand Down Expand Up @@ -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<v8::Object>();
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");

Expand Down

0 comments on commit 8febddc

Please sign in to comment.