JsErrorCode CreateHostContext(JsRuntimeHandle runtime, int argc, wchar_t *argv [], int argumentsStart, JsContextRef *context) { JsCreateContext(runtime, context); JsSetCurrentContext(*context); JsValueRef hostObject; JsCreateObject(&hostObject); ghostObject = hostObject; JsValueRef globalObject; JsGetGlobalObject(&globalObject); JsPropertyIdRef hostPropertyId; JsGetPropertyIdFromName(L"app", &hostPropertyId); // app.XXXXX JsSetProperty(globalObject, hostPropertyId, hostObject, true); //IfFailRet(DefineHostCallback(hostObject, L"msgbox", msgbox, nullptr)); JsSetCurrentContext(JS_INVALID_REFERENCE); return JsNoError; }
void SDKLoader::LoadSDK(queue<Task*>* taskQueue) { JsValueRef global; JsGetGlobalObject(&global); JsValueRef game; JsCreateObject(&game); Js::AddPropertyToObject(global, L"game", game); JsValueRef addEventListenerFunction; JsCreateFunction(&addEventListener, taskQueue, &addEventListenerFunction); Js::AddPropertyToObject(game, L"addEventListener", addEventListenerFunction); Js::AddPropertyToObject(global, L"addEventListener", addEventListenerFunction); }
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; }