jsbindings/jscontroller-jsbindings.cpp
/**
 * @brief Callback invoked from JS to add an event listener
 *
 * @param[in] context JS execution context
 * @param[in] function JSObject that is the function being called
 * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
 * @param[in] argumentCount number of args
 * @param[in] arguments[] JSValue array of args
 * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
 *
 * @retval JSValue that is the function's return value
 */


@retval JSValue that is the function's return value
@retval JSValue that is the function ' s return value
static JSValueRef AAMPJSC_addEventListener(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
{
	LOG("[AAMP_JSController] %s()", __FUNCTION__);
	AAMP_JSController *aampObj = (AAMP_JSController *)JSObjectGetPrivate(thisObject);
	if (aampObj == NULL)
	{
		*exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP_JSController.addEventListener on instances of AAMP_JSController");
		return JSValueMakeUndefined(context);
	}
	if (argumentCount >= 2)
	{
		char* type = aamp_JSValueToCString(context, arguments[0], NULL);
		JSObjectRef callbackFunc = JSValueToObject(context, arguments[1], NULL);
		if (callbackFunc != NULL && JSObjectIsFunction(context, callbackFunc))
		{
			AAMPEventType eventType = aampPlayer_getEventTypeFromName(type);
			LOG("%s() eventType='%s', %d", __FUNCTION__, type, eventType);
			if ((eventType >= 0) && (eventType < AAMP_MAX_NUM_EVENTS))
			{
				AAMP_JSEventListener::AddEventListener(aampObj, eventType, callbackFunc);
			}
		}
		else
		{
			ERROR("%s() callbackFunc=%p, JSObjectIsFunction(context, callbackFunc)=%d", __FUNCTION__, callbackFunc, JSObjectIsFunction(context, callbackFunc));
			char errMsg[512];
			memset(errMsg, '\0', 512);
			snprintf(errMsg, 511, "Failed to execute addEventListener() for event %s - parameter 2 is not a function", type);
			*exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, (const char*)errMsg);
		}
		delete[] type;
	}
	else
	{
		*exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP_JSController.addEventListener' - 2 arguments required");
	}
	return JSValueMakeUndefined(context);
}
static JSValueRef AAMPJSC_addEventListener ( JSContextRef context , JSObjectRef function , JSObjectRef thisObject , size_t argumentCount , const JSValueRef arguments [ ] , JSValueRef * exception ) { LOG ( " " , __FUNCTION__ ) ; AAMP_JSController * aampObj = ( AAMP_JSController * ) JSObjectGetPrivate ( thisObject ) ; if ( aampObj == NULL ) { * exception = aamp_GetException ( context , AAMPJS_MISSING_OBJECT , " " ) ; return JSValueMakeUndefined ( context ) ; } if ( argumentCount >= 2 ) { char * type = aamp_JSValueToCString ( context , arguments [ 0 ] , NULL ) ; JSObjectRef callbackFunc = JSValueToObject ( context , arguments [ 1 ] , NULL ) ; if ( callbackFunc != NULL && JSObjectIsFunction ( context , callbackFunc ) ) { AAMPEventType eventType = aampPlayer_getEventTypeFromName ( type ) ; LOG ( " " , __FUNCTION__ , type , eventType ) ; if ( ( eventType >= 0 ) && ( eventType < AAMP_MAX_NUM_EVENTS ) ) { AAMP_JSEventListener :: AddEventListener ( aampObj , eventType , callbackFunc ) ; } } else { ERROR ( " " , __FUNCTION__ , callbackFunc , JSObjectIsFunction ( context , callbackFunc ) ) ; char errMsg [ 512 ] ; memset ( errMsg , ' \0 ' , 512 ) ; snprintf ( errMsg , 511 , " " , type ) ; * exception = aamp_GetException ( context , AAMPJS_INVALID_ARGUMENT , ( const char * ) errMsg ) ; } delete [ ] type ; } else { * exception = aamp_GetException ( context , AAMPJS_INVALID_ARGUMENT , " " ) ; } return JSValueMakeUndefined ( context ) ; }
@brief Callback invoked from JS to add an event listener
 @param[in] context JS execution context
 @param[in] function JSObject that is the function being called
 @param[in] thisObject JSObject that is the 'this' variable in the function's scope
 @param[in] argumentCount number of args
 @param[in] arguments[] JSValue array of args
 @param[out] exception pointer to a JSValueRef in which to return an exception, if any
@brief Callback invoked from JS to add an event listener @param [ in ] context JS execution context @param [ in ] function JSObject that is the function being called @param [ in ] thisObject JSObject that is the ' this ' variable in the function ' s scope @param [ in ] argumentCount number of args @param [ in ] arguments [] JSValue array of args @param [ out ] exception pointer to a JSValueRef in which to return an exception if any