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
3 changes: 2 additions & 1 deletion test-app/app/src/main/assets/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"memoryCheckInterval": 10,
"freeMemoryRatio": 0.50,
"markingMode": "full",
"maxLogcatObjectSize": 1024
"maxLogcatObjectSize": 1024,
"forceLog": false
}
}
14 changes: 7 additions & 7 deletions test-app/runtime/src/main/cpp/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ ObjectManager* Runtime::GetObjectManager() const {
return m_objectManager;
}

void Runtime::Init(JNIEnv* _env, jobject obj, int runtimeId, jstring filesPath, jstring nativeLibDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize) {
void Runtime::Init(JNIEnv* _env, jobject obj, int runtimeId, jstring filesPath, jstring nativeLibDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize, bool forceLog) {
JEnv env(_env);

auto runtime = new Runtime(env, obj, runtimeId);

auto enableLog = verboseLoggingEnabled == JNI_TRUE;

runtime->Init(filesPath, nativeLibDir, enableLog, isDebuggable, packageName, args, callingDir, maxLogcatObjectSize);
runtime->Init(filesPath, nativeLibDir, enableLog, isDebuggable, packageName, args, callingDir, maxLogcatObjectSize, forceLog);
}

void Runtime::Init(jstring filesPath, jstring nativeLibDir, bool verboseLoggingEnabled, bool isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize) {
void Runtime::Init(jstring filesPath, jstring nativeLibDir, bool verboseLoggingEnabled, bool isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize, bool forceLog) {
LogEnabled = verboseLoggingEnabled;

auto filesRoot = ArgConverter::jstringToString(filesPath);
Expand All @@ -183,7 +183,7 @@ void Runtime::Init(jstring filesPath, jstring nativeLibDir, bool verboseLoggingE
auto profilerOutputDirStr = ArgConverter::jstringToString(profilerOutputDir);

NativeScriptException::Init(m_objectManager);
m_isolate = PrepareV8Runtime(filesRoot, nativeLibDirStr, packageNameStr, isDebuggable, callingDirStr, profilerOutputDirStr, maxLogcatObjectSize);
m_isolate = PrepareV8Runtime(filesRoot, nativeLibDirStr, packageNameStr, isDebuggable, callingDirStr, profilerOutputDirStr, maxLogcatObjectSize, forceLog);

s_isolate2RuntimesCache.insert(make_pair(m_isolate, this));
}
Expand Down Expand Up @@ -408,7 +408,7 @@ static void InitializeV8() {
V8::Initialize();
}

Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& nativeLibDir, const string& packageName, bool isDebuggable, const string& callingDir, const string& profilerOutputDir, const int maxLogcatObjectSize) {
Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& nativeLibDir, const string& packageName, bool isDebuggable, const string& callingDir, const string& profilerOutputDir, const int maxLogcatObjectSize, const bool forceLog) {
tns::instrumentation::Frame frame("Runtime.PrepareV8Runtime");

Isolate::CreateParams create_params;
Expand Down Expand Up @@ -611,9 +611,9 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
}

#ifdef APPLICATION_IN_DEBUG
v8::Local<v8::Object> console = Console::createConsole(context, JsV8InspectorClient::consoleLogCallback, maxLogcatObjectSize);
v8::Local<v8::Object> console = Console::createConsole(context, JsV8InspectorClient::consoleLogCallback, maxLogcatObjectSize, forceLog);
#else
v8::Local<v8::Object> console = Console::createConsole(context, nullptr, maxLogcatObjectSize);
v8::Local<v8::Object> console = Console::createConsole(context, nullptr, maxLogcatObjectSize, forceLog);
#endif

/*
Expand Down
7 changes: 4 additions & 3 deletions test-app/runtime/src/main/cpp/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ class Runtime {

static void Init(JavaVM* vm, void* reserved);

static void Init(JNIEnv* _env, jobject obj, int runtimeId, jstring filesPath, jstring nativeLibsDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize);
static void Init(JNIEnv* _env, jobject obj, int runtimeId, jstring filesPath, jstring nativeLibsDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize,
bool forceLog);

static void SetManualInstrumentationMode(jstring mode);

void Init(jstring filesPath, jstring nativeLibsDir, bool verboseLoggingEnabled, bool isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize);
void Init(jstring filesPath, jstring nativeLibsDir, bool verboseLoggingEnabled, bool isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, int maxLogcatObjectSize, bool forceLog);

v8::Isolate* GetIsolate() const;

Expand Down Expand Up @@ -83,7 +84,7 @@ class Runtime {
v8::Persistent<v8::Function>* m_gcFunc;
volatile bool m_runGC;

v8::Isolate* PrepareV8Runtime(const std::string& filesPath, const std::string& nativeLibsDir, const std::string& packageName, bool isDebuggable, const std::string& callingDir, const std::string& profilerOutputDir, const int maxLogcatObjectSize);
v8::Isolate* PrepareV8Runtime(const std::string& filesPath, const std::string& nativeLibsDir, const std::string& packageName, bool isDebuggable, const std::string& callingDir, const std::string& profilerOutputDir, const int maxLogcatObjectSize, const bool forceLog);
jobject ConvertJsValueToJavaObject(JEnv& env, const v8::Local<v8::Value>& value, int classReturnType);
static int GetAndroidVersion();
static int m_androidVersion;
Expand Down
4 changes: 2 additions & 2 deletions test-app/runtime/src/main/cpp/com_tns_Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ extern "C" JNIEXPORT void Java_com_tns_Runtime_SetManualInstrumentationMode(JNIE
}
}

extern "C" JNIEXPORT void Java_com_tns_Runtime_initNativeScript(JNIEnv* _env, jobject obj, jint runtimeId, jstring filesPath, jstring nativeLibDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, jint maxLogcatObjectSize) {
extern "C" JNIEXPORT void Java_com_tns_Runtime_initNativeScript(JNIEnv* _env, jobject obj, jint runtimeId, jstring filesPath, jstring nativeLibDir, jboolean verboseLoggingEnabled, jboolean isDebuggable, jstring packageName, jobjectArray args, jstring callingDir, jint maxLogcatObjectSize, jboolean forceLog) {
try {
Runtime::Init(_env, obj, runtimeId, filesPath, nativeLibDir, verboseLoggingEnabled, isDebuggable, packageName, args, callingDir, maxLogcatObjectSize);
Runtime::Init(_env, obj, runtimeId, filesPath, nativeLibDir, verboseLoggingEnabled, isDebuggable, packageName, args, callingDir, maxLogcatObjectSize, forceLog);
} catch (NativeScriptException& e) {
e.ReThrowToJava();
} catch (std::exception e) {
Expand Down
22 changes: 12 additions & 10 deletions test-app/runtime/src/main/cpp/console/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

namespace tns {

v8::Local<v8::Object> Console::createConsole(v8::Local<v8::Context> context, ConsoleCallback callback, const int maxLogcatObjectSize) {
v8::Local<v8::Object> Console::createConsole(v8::Local<v8::Context> context, ConsoleCallback callback, const int maxLogcatObjectSize, const bool forceLog) {
m_callback = callback;
m_maxLogcatObjectSize = maxLogcatObjectSize;
m_forceLog = forceLog;
v8::Context::Scope contextScope(context);
v8::Isolate* isolate = context->GetIsolate();

Expand Down Expand Up @@ -165,7 +166,7 @@ const std::string buildLogString(const v8::FunctionCallbackInfo<v8::Value>& info
}

void Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
if (!shouldLog()) {
return;
}
try {
Expand Down Expand Up @@ -203,7 +204,7 @@ void Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::errorCallback(const v8::FunctionCallbackInfo <v8::Value>& info) {
if (!isApplicationInDebug) {
if (!shouldLog()) {
return;
}
try {
Expand All @@ -225,7 +226,7 @@ void Console::errorCallback(const v8::FunctionCallbackInfo <v8::Value>& info) {
}

void Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
if (!shouldLog()) {
return;
}
try {
Expand All @@ -247,7 +248,7 @@ void Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
if (!shouldLog()) {
return;
}
try {
Expand All @@ -269,7 +270,7 @@ void Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
if (!shouldLog()) {
return;
}
try {
Expand All @@ -291,7 +292,7 @@ void Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
if (!shouldLog()) {
return;
}
try {
Expand Down Expand Up @@ -408,7 +409,7 @@ const std::string buildStacktraceFrameMessage(v8::Local<v8::StackFrame> frame) {
}

void Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
if (!shouldLog()) {
return;
}
try {
Expand Down Expand Up @@ -454,7 +455,7 @@ void Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
if (!shouldLog()) {
return;
}
try {
Expand Down Expand Up @@ -493,7 +494,7 @@ void Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
}

void Console::timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
if (!isApplicationInDebug) {
if (!shouldLog()) {
return;
}
try {
Expand Down Expand Up @@ -555,6 +556,7 @@ const char* Console::LOG_TAG = "JS";
std::map<v8::Isolate*, std::map<std::string, double>> Console::s_isolateToConsoleTimersMap;
ConsoleCallback Console::m_callback = nullptr;
int Console::m_maxLogcatObjectSize;
bool Console::m_forceLog;

#ifdef APPLICATION_IN_DEBUG
bool Console::isApplicationInDebug = true;
Expand Down
6 changes: 5 additions & 1 deletion test-app/runtime/src/main/cpp/console/Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ typedef void (*ConsoleCallback)(const std::string& message, const std::string& l

class Console {
public:
static v8::Local<v8::Object> createConsole(v8::Local<v8::Context> context, ConsoleCallback callback, const int maxLogcatObjectSize);
static v8::Local<v8::Object> createConsole(v8::Local<v8::Context> context, ConsoleCallback callback, const int maxLogcatObjectSize, const bool forceLog);

static void assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info);
static void errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info);
Expand All @@ -29,11 +29,15 @@ class Console {

private:
static int m_maxLogcatObjectSize;
static bool m_forceLog;
static ConsoleCallback m_callback;
static const char* LOG_TAG;
static std::map<v8::Isolate*, std::map<std::string, double>> s_isolateToConsoleTimersMap;

static bool isApplicationInDebug;
static bool shouldLog() {
return m_forceLog || isApplicationInDebug;
}

// heavily inspired by 'createBoundFunctionProperty' of V8's v8-console.h
static void bindFunctionProperty(v8::Local<v8::Context> context,
Expand Down
10 changes: 9 additions & 1 deletion test-app/runtime/src/main/java/com/tns/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ protected enum KnownKeys {
Profiling("profiling", ""),
MarkingMode("markingMode", com.tns.MarkingMode.full),
HandleTimeZoneChanges("handleTimeZoneChanges", false),
MaxLogcatObjectSize("maxLogcatObjectSize", 1024);
MaxLogcatObjectSize("maxLogcatObjectSize", 1024),
ForceLog("forceLog", false);

private final String name;
private final Object defaultValue;
Expand Down Expand Up @@ -108,6 +109,9 @@ public AppConfig(File appDir) {
if (androidObject.has(KnownKeys.MaxLogcatObjectSize.getName())) {
values[KnownKeys.MaxLogcatObjectSize.ordinal()] = androidObject.getInt(KnownKeys.MaxLogcatObjectSize.getName());
}
if (androidObject.has(KnownKeys.ForceLog.getName())) {
values[KnownKeys.ForceLog.ordinal()] = androidObject.getBoolean(KnownKeys.ForceLog.getName());
}
}
}
} catch (Exception e) {
Expand Down Expand Up @@ -154,4 +158,8 @@ public boolean handleTimeZoneChanges() {
public int getMaxLogcatObjectSize() {
return (int)values[KnownKeys.MaxLogcatObjectSize.ordinal()];
}

public boolean getForceLog() {
return (boolean)values[KnownKeys.ForceLog.ordinal()];
}
}
7 changes: 5 additions & 2 deletions test-app/runtime/src/main/java/com/tns/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.tns.bindings.ProxyGenerator;

public class Runtime {
private native void initNativeScript(int runtimeId, String filesPath, String nativeLibDir, boolean verboseLoggingEnabled, boolean isDebuggable, String packageName, Object[] v8Options, String callingDir, int maxLogcatObjectSize);
private native void initNativeScript(int runtimeId, String filesPath, String nativeLibDir, boolean verboseLoggingEnabled, boolean isDebuggable, String packageName, Object[] v8Options, String callingDir, int maxLogcatObjectSize, boolean forceLog);

private native void runModule(int runtimeId, String filePath) throws NativeScriptException;

Expand Down Expand Up @@ -490,7 +490,10 @@ private void init(Logger logger, String appName, String nativeLibDir, File rootD
throw new RuntimeException("Fail to initialize Require class", ex);
}

initNativeScript(getRuntimeId(), Module.getApplicationFilesPath(), nativeLibDir, logger.isEnabled(), isDebuggable, appName, appConfig.getAsArray(), callingJsDir, appConfig.getMaxLogcatObjectSize());
boolean forceConsoleLog = appConfig.getForceLog() || "timeline".equalsIgnoreCase(appConfig.getProfilingMode());

initNativeScript(getRuntimeId(), Module.getApplicationFilesPath(), nativeLibDir, logger.isEnabled(), isDebuggable, appName, appConfig.getAsArray(),
callingJsDir, appConfig.getMaxLogcatObjectSize(), forceConsoleLog);

//clearStartupData(getRuntimeId()); // It's safe to delete the data after the V8 debugger is initialized

Expand Down