Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test-app/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ endif()

if ( NOT OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD )
# When building in Release mode we do not include the V8 inspector sources
add_definitions(-DINCLUDE_INSPECTOR)
add_definitions(-DAPPLICATION_IN_DEBUG)

set(
INSPECTOR_SOURCES
Expand Down
4 changes: 2 additions & 2 deletions test-app/runtime/src/main/cpp/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "sys/system_properties.h"
#include "ManualInstrumentation.h"

#ifdef INCLUDE_INSPECTOR
#ifdef APPLICATION_IN_DEBUG
#include "JsV8InspectorClient.h"
#endif

Expand Down Expand Up @@ -580,7 +580,7 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
global->DefineOwnProperty(context, ArgConverter::ConvertToV8String(isolate, "self"), global, readOnlyFlags);
}

#ifdef INCLUDE_INSPECTOR
#ifdef APPLICATION_IN_DEBUG
/*
* Attach __inspector object with function callbacks that report to the Chrome DevTools frontend
*/
Expand Down
33 changes: 33 additions & 0 deletions test-app/runtime/src/main/cpp/console/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ const std::string buildLogString(const v8::FunctionCallbackInfo<v8::Value>& info
}

void Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
return;
}
try {
auto isolate = info.GetIsolate();

Expand Down Expand Up @@ -193,6 +196,9 @@ void Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::errorCallback(const v8::FunctionCallbackInfo <v8::Value>& info) {
if (!isApplicationInDebug) {
return;
}
try {
std::string log = buildLogString(info);

Expand All @@ -212,6 +218,9 @@ void Console::errorCallback(const v8::FunctionCallbackInfo <v8::Value>& info) {
}

void Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
return;
}
try {
std::string log = buildLogString(info);

Expand All @@ -231,6 +240,9 @@ void Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
return;
}
try {
std::string log = buildLogString(info);

Expand All @@ -250,6 +262,9 @@ void Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
return;
}
try {
std::string log = buildLogString(info);

Expand All @@ -269,6 +284,9 @@ void Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
return;
}
try {
auto isolate = info.GetIsolate();
auto context = isolate->GetCurrentContext();
Expand Down Expand Up @@ -383,6 +401,9 @@ const std::string buildStacktraceFrameMessage(v8::Local<v8::StackFrame> frame) {
}

void Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
return;
}
try {
auto isolate = info.GetIsolate();
std::stringstream ss;
Expand Down Expand Up @@ -426,6 +447,9 @@ void Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
return;
}
try {
auto isolate = info.GetIsolate();

Expand Down Expand Up @@ -462,6 +486,9 @@ void Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
return;
}
try {
auto isolate = info.GetIsolate();

Expand Down Expand Up @@ -520,4 +547,10 @@ void Console::timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
const char* Console::LOG_TAG = "JS";
std::map<v8::Isolate*, std::map<std::string, double>> Console::s_isolateToConsoleTimersMap;
ConsoleCallback Console::m_callback = nullptr;

#ifdef APPLICATION_IN_DEBUG
bool Console::isApplicationInDebug = true;
#else
bool Console::isApplicationInDebug = false;
#endif
}
2 changes: 2 additions & 0 deletions test-app/runtime/src/main/cpp/console/Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Console {
static const char* LOG_TAG;
static std::map<v8::Isolate*, std::map<std::string, double>> s_isolateToConsoleTimersMap;

static bool isApplicationInDebug;

// heavily inspired by 'createBoundFunctionProperty' of V8's v8-console.h
static void bindFunctionProperty(v8::Local<v8::Context> context,
v8::Local<v8::Object> consoleInstance,
Expand Down