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));

    return JsNoError;
}
Esempio n. 2
0
void RegistFunction( LPCWSTR function_name, JSFUNCTION func )
{
	JsSetCurrentContext(jscontext);

	IfFailRet(DefineHostCallback(ghostObject, function_name, func, nullptr));

	JsSetCurrentContext(JS_INVALID_REFERENCE);
}