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::Init() { currentSourceContext = 0; IfFailRet(JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &runtime)); IfFailRet(JsCreateContext(runtime, &context)); IfFailRet(JsSetCurrentContext(context)); IfFailRet(JsGetGlobalObject(&globalObject)); IfFailRet(InitJson()); IfFailRet(InitConsole()); return JsNoError; }