JsErrorCode DefineHostCallback(JsValueRef globalObject, const wchar_t *callbackName, JsNativeFunction callback, void *callbackState) { JsPropertyIdRef propertyId; IfFailRet(JsGetPropertyIdFromName(callbackName, &propertyId)); JsValueRef function; IfFailRet(JsCreateFunction(callback, callbackState, &function)); IfFailRet(JsSetProperty(globalObject, propertyId, function, true)); 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); }