Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ChakraBridge): fixing NativeJavaScriptExecutor to use nativeLoggingCallback #1015

Merged
merged 1 commit into from
Feb 17, 2017
Merged
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
74 changes: 26 additions & 48 deletions ReactWindows/ChakraBridge/ChakraHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,35 @@ JsErrorCode DefineHostCallback(JsValueRef globalObject, const wchar_t *callbackN
return JsNoError;
}

JsValueRef InvokeConsole(const wchar_t* kind, JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
wchar_t* LogLevel(int logLevel)
{
#ifdef _DEBUG

wchar_t buff[56];
swprintf(buff, 56, L"[JS {%s}] ", kind);
OutputDebugStringW(buff);

// First argument is this-context, ignore...
for (USHORT i = 1; i < argumentCount; i++)
{
std::set<JsValueRef> values;
IfFailThrow(StringifyJsValue(arguments[i], 0, values), L"Failed to convert object to string");
OutputDebugStringW(L" ");
}

OutputDebugStringW(L"\n");

#endif

return JS_INVALID_REFERENCE;
};

JsValueRef CALLBACK ConsoleLog(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
{
return InvokeConsole(L"log", callee, isConstructCall, arguments, argumentCount, callbackState);
switch (logLevel)
{
case 0:
return L"Trace";
case 1:
return L"Info";
case 2:
return L"Warn";
case 3:
return L"Error";
default:
return L"Log";
}
}

JsValueRef CALLBACK ConsoleWarn(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
JsValueRef CALLBACK NativeLoggingCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
{
return InvokeConsole(L"warn", callee, isConstructCall, arguments, argumentCount, callbackState);
}

JsValueRef CALLBACK ConsoleInfo(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
{
return InvokeConsole(L"info", callee, isConstructCall, arguments, argumentCount, callbackState);
}

JsValueRef CALLBACK ConsoleError(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
{
return InvokeConsole(L"error", callee, isConstructCall, arguments, argumentCount, callbackState);
#ifdef _DEBUG
wchar_t buff[56];
double logLevelIndex;
JsNumberToDouble(arguments[2], &logLevelIndex);
swprintf(buff, 56, L"[JS %s] ", LogLevel((int)logLevelIndex));
OutputDebugStringW(buff);
StringifyJsString(arguments[1]);
OutputDebugStringW(L"\n");
#endif
return JS_INVALID_REFERENCE;
}

JsErrorCode LoadByteCode(const wchar_t* szPath, BYTE** pData, HANDLE* hFile, HANDLE* hMap)
Expand Down Expand Up @@ -273,17 +261,7 @@ JsErrorCode ChakraHost::InitJson()

JsErrorCode ChakraHost::InitConsole()
{
JsPropertyIdRef consolePropertyId;
IfFailRet(JsGetPropertyIdFromName(L"console", &consolePropertyId));

JsValueRef consoleObject;
IfFailRet(JsCreateObject(&consoleObject));
IfFailRet(JsSetProperty(globalObject, consolePropertyId, consoleObject, true));

IfFailRet(DefineHostCallback(consoleObject, L"info", ConsoleInfo, nullptr));
IfFailRet(DefineHostCallback(consoleObject, L"log", ConsoleLog, nullptr));
IfFailRet(DefineHostCallback(consoleObject, L"warn", ConsoleWarn, nullptr));
IfFailRet(DefineHostCallback(consoleObject, L"error", ConsoleError, nullptr));
IfFailRet(DefineHostCallback(globalObject, L"nativeLoggingHook", NativeLoggingCallback, nullptr));

return JsNoError;
}
Expand Down