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;
}
예제 #2
0
파일: Js.cpp 프로젝트: sugarontop/D2DWindow
void RegistFunction( LPCWSTR function_name, JSFUNCTION func )
{
	JsSetCurrentContext(jscontext);

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

	JsSetCurrentContext(JS_INVALID_REFERENCE);
}