jsbindings/jsbindings.cpp
/**
 * @brief Callback invoked from JS to add a custom HTTP header/s
 *
 * @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 AAMP_addCustomHTTPHeader(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
{
	LOG("[AAMP_JS] %s()", __FUNCTION__);
	AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
	if(!pAAMP)
	{
		ERROR("[AAMP_JS] %s() Error: JSObjectGetPrivate returned NULL!", __FUNCTION__);
		*exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.addCustomHTTPHeader on instances of AAMP");
		return JSValueMakeUndefined(context);
	}
	if (argumentCount != 2)
	{
		ERROR("[AAMP_JS] %s() InvalidArgument: argumentCount=%d, expected: 2", __FUNCTION__, argumentCount);
		*exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.addCustomHTTPHeader' - 2 argument required");
	}
	else
	{
		char *name = aamp_JSValueToCString(context, arguments[0], exception);
		std::string headerName(name);
		std::vector<std::string> headerVal;
		delete[] name;
		if (aamp_JSValueIsArray(context, arguments[1]))
		{
			headerVal = aamp_StringArrayToCStringArray(context, arguments[1]);
		}
		else if (JSValueIsString(context, arguments[1]))
		{
			headerVal.reserve(1);
			char *value =  aamp_JSValueToCString(context, arguments[1], exception);
			headerVal.push_back(value);
			delete[] value;
		}
		if (headerVal.size() == 0)
		{
			ERROR("[AAMP_JS] %s() InvalidArgument: Custom header's value is empty", __FUNCTION__, argumentCount);
			*exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.addCustomHTTPHeader' - 2nd argument should be a string or array of strings");
			return JSValueMakeUndefined(context);
		}
		pAAMP->_aamp->AddCustomHTTPHeader(headerName, headerVal);
	}
	return JSValueMakeUndefined(context);
}
static JSValueRef AAMP_addCustomHTTPHeader ( JSContextRef context , JSObjectRef function , JSObjectRef thisObject , size_t argumentCount , const JSValueRef arguments [ ] , JSValueRef * exception ) { LOG ( " " , __FUNCTION__ ) ; AAMP_JS * pAAMP = ( AAMP_JS * ) JSObjectGetPrivate ( thisObject ) ; if ( ! pAAMP ) { ERROR ( " " , __FUNCTION__ ) ; * exception = aamp_GetException ( context , AAMPJS_MISSING_OBJECT , " " ) ; return JSValueMakeUndefined ( context ) ; } if ( argumentCount != 2 ) { ERROR ( " " , __FUNCTION__ , argumentCount ) ; * exception = aamp_GetException ( context , AAMPJS_INVALID_ARGUMENT , " " ) ; } else { char * name = aamp_JSValueToCString ( context , arguments [ 0 ] , exception ) ; std :: string headerName ( name ) ; std :: vector < std :: string > headerVal ; delete [ ] name ; if ( aamp_JSValueIsArray ( context , arguments [ 1 ] ) ) { headerVal = aamp_StringArrayToCStringArray ( context , arguments [ 1 ] ) ; } else if ( JSValueIsString ( context , arguments [ 1 ] ) ) { headerVal . reserve ( 1 ) ; char * value = aamp_JSValueToCString ( context , arguments [ 1 ] , exception ) ; headerVal . push_back ( value ) ; delete [ ] value ; } if ( headerVal . size ( ) == 0 ) { ERROR ( " " , __FUNCTION__ , argumentCount ) ; * exception = aamp_GetException ( context , AAMPJS_INVALID_ARGUMENT , " " ) ; return JSValueMakeUndefined ( context ) ; } pAAMP -> _aamp -> AddCustomHTTPHeader ( headerName , headerVal ) ; } return JSValueMakeUndefined ( context ) ; }
@brief Callback invoked from JS to add a custom HTTP header/s
 @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 a custom HTTP header / s @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
// Don't support empty values now