fn call(
        &self,
        fn_name: &str,
        return_type: JsFunctionArgumentType,
        arg_types: Option<Vec<JsFunctionArgumentType>>,
        args: Option<&JsValue>,
    ) -> JsValue {
        fn js_value_from_argument_type(arg_type: JsFunctionArgumentType) -> JsValue {
            match arg_type {
                JsFunctionArgumentType::Void => JsValue::undefined(),
                JsFunctionArgumentType::Number | JsFunctionArgumentType::Pointer => {
                    JsValue::from(intern("number"))
                }
                JsFunctionArgumentType::String => JsValue::from(intern("string")),
            }
        }

        log::debug!(
            "pdfium-render::PdfiumRenderWasmState::call(): performing call to function: {:#?}",
            fn_name
        );

        let js_fn_name = JsValue::from(intern(fn_name));

        let js_return_type = js_value_from_argument_type(return_type);

        let js_arg_types = match arg_types {
            Some(arg_types) => {
                if self.debug {
                    // Type-check arguments.

                    if let Some(args) = args {
                        if !Array::is_array(args) {
                            log::warn!("pdfium-render::PdfiumRenderWasmState::call(): argument type list given, but arguments is not an Array");
                        }

                        let args = Array::from(args);

                        if arg_types.len() != args.length() as usize {
                            log::warn!("pdfium-render::PdfiumRenderWasmState::call(): length of argument type and argument lists does not match");
                        }

                        for (index, (arg_type, arg)) in arg_types
                            .iter()
                            .zip(args.iter().collect::<Vec<_>>())
                            .enumerate()
                        {
                            if !match arg_type {
                                JsFunctionArgumentType::Void => arg.is_undefined(),
                                JsFunctionArgumentType::Number
                                | JsFunctionArgumentType::Pointer => arg.as_f64().is_some(),
                                JsFunctionArgumentType::String => arg.as_string().is_some(),
                            } {
                                log::warn!("pdfium-render::PdfiumRenderWasmState::call(): type-checking of argument {} failed: expected {:#?}, received {:#?}",
                            index,
                            arg_type,
                            arg);
                            }
                        }
                    }
                }

                JsValue::from(
                    arg_types
                        .into_iter()
                        .map(|arg_type| js_value_from_argument_type(arg_type))
                        .collect::<Array>(),
                )
            }
            None => JsValue::undefined(),
        };

        log::debug!(
            "pdfium-render::PdfiumRenderWasmState::call(): arguments: {:#?}",
            args
        );

        match self.call_js_fn.as_ref().unwrap().apply(
            &JsValue::null(),
            &Array::of4(
                &js_fn_name,
                &js_return_type,
                &js_arg_types,
                args.unwrap_or(&JsValue::undefined()),
            ),
        ) {
            Ok(result) => {
                log::debug!(
                    "pdfium-render::PdfiumRenderWasmState::call(): call returned result: {:#?}",
                    result
                );

                if self.debug {
                    // Type-check result.

                    if !match return_type {
                        JsFunctionArgumentType::Void => result.is_undefined(),
                        JsFunctionArgumentType::Number | JsFunctionArgumentType::Pointer => {
                            result.as_f64().is_some()
                        }
                        JsFunctionArgumentType::String => result.as_string().is_some(),
                    } {
                        log::warn!("pdfium-render::PdfiumRenderWasmState::call(): result data type does not match expected return type {:#?}", return_type);
                    }
                }

                result
            }
            Err(err) => {
                log::error!(
                    "pdfium-render::PdfiumRenderWasmState::call(): call to {:#?} failed: {:#?}",
                    fn_name,
                    err,
                );

                panic!();
            }
        }
    }
/// Calls an emscripten-wrapped Pdfium function.
Calls an emscripten-wrapped Pdfium function.
Calls an emscripten - wrapped Pdfium function .
fn call(
        &self,
        fn_name: &str,
        return_type: JsFunctionArgumentType,
        arg_types: Option<Vec<JsFunctionArgumentType>>,
        args: Option<&JsValue>,
    ) -> JsValue {
        fn js_value_from_argument_type(arg_type: JsFunctionArgumentType) -> JsValue {
            match arg_type {
                JsFunctionArgumentType::Void => JsValue::undefined(),
                JsFunctionArgumentType::Number | JsFunctionArgumentType::Pointer => {
                    JsValue::from(intern("number"))
                }
                JsFunctionArgumentType::String => JsValue::from(intern("string")),
            }
        }
        log::debug!(
            "pdfium-render::PdfiumRenderWasmState::call(): performing call to function: {:#?}",
            fn_name
        );
        let js_fn_name = JsValue::from(intern(fn_name));
        let js_return_type = js_value_from_argument_type(return_type);
        let js_arg_types = match arg_types {
            Some(arg_types) => {
                if self.debug {
                    // Type-check arguments.
                    if let Some(args) = args {
                        if !Array::is_array(args) {
                            log::warn!("pdfium-render::PdfiumRenderWasmState::call(): argument type list given, but arguments is not an Array");
                        }
                        let args = Array::from(args);
                        if arg_types.len() != args.length() as usize {
                            log::warn!("pdfium-render::PdfiumRenderWasmState::call(): length of argument type and argument lists does not match");
                        }
                        for (index, (arg_type, arg)) in arg_types
                            .iter()
                            .zip(args.iter().collect::<Vec<_>>())
                            .enumerate()
                        {
                            if !match arg_type {
                                JsFunctionArgumentType::Void => arg.is_undefined(),
                                JsFunctionArgumentType::Number
                                | JsFunctionArgumentType::Pointer => arg.as_f64().is_some(),
                                JsFunctionArgumentType::String => arg.as_string().is_some(),
                            } {
                                log::warn!("pdfium-render::PdfiumRenderWasmState::call(): type-checking of argument {} failed: expected {:#?}, received {:#?}",
                            index,
                            arg_type,
                            arg);
                            }
                        }
                    }
                }
                JsValue::from(
                    arg_types
                        .into_iter()
                        .map(|arg_type| js_value_from_argument_type(arg_type))
                        .collect::<Array>(),
                )
            }
            None => JsValue::undefined(),
        };
        log::debug!(
            "pdfium-render::PdfiumRenderWasmState::call(): arguments: {:#?}",
            args
        );
        match self.call_js_fn.as_ref().unwrap().apply(
            &JsValue::null(),
            &Array::of4(
                &js_fn_name,
                &js_return_type,
                &js_arg_types,
                args.unwrap_or(&JsValue::undefined()),
            ),
        ) {
            Ok(result) => {
                log::debug!(
                    "pdfium-render::PdfiumRenderWasmState::call(): call returned result: {:#?}",
                    result
                );
                if self.debug {
                    // Type-check result.
                    if !match return_type {
                        JsFunctionArgumentType::Void => result.is_undefined(),
                        JsFunctionArgumentType::Number | JsFunctionArgumentType::Pointer => {
                            result.as_f64().is_some()
                        }
                        JsFunctionArgumentType::String => result.as_string().is_some(),
                    } {
                        log::warn!("pdfium-render::PdfiumRenderWasmState::call(): result data type does not match expected return type {:#?}", return_type);
                    }
                }
                result
            }
            Err(err) => {
                log::error!(
                    "pdfium-render::PdfiumRenderWasmState::call(): call to {:#?} failed: {:#?}",
                    fn_name,
                    err,
                );
                panic!();
            }
        }
    }
fn call ( & self , fn_name : & str , return_type : JsFunctionArgumentType , arg_types : Option < Vec < JsFunctionArgumentType > > , args : Option < & JsValue > , ) -> JsValue { fn js_value_from_argument_type ( arg_type : JsFunctionArgumentType ) -> JsValue { match arg_type { JsFunctionArgumentType :: Void => JsValue :: undefined ( ) , JsFunctionArgumentType :: Number | JsFunctionArgumentType :: Pointer => { JsValue :: from ( intern ( " " ) ) } JsFunctionArgumentType :: String => JsValue :: from ( intern ( " " ) ) , } } log :: debug ! ( " " fn_name ) ; let js_fn_name = JsValue :: from ( intern ( fn_name ) ) ; let js_return_type = js_value_from_argument_type ( return_type ) ; let js_arg_types = match arg_types { Some ( arg_types ) => { if self . debug { // Type-check arguments. if let Some ( args ) = args { if ! Array :: is_array ( args ) { log :: warn ! ( " " ) ; } let args = Array :: from ( args ) ; if arg_types . len ( ) != args . length ( ) as usize { log :: warn ! ( " " ) ; } for ( index , ( arg_type , arg ) ) in arg_types . iter ( ) . zip ( args . iter ( ) . collect :: < Vec < _ > > ( ) ) . enumerate ( ) { if ! match arg_type { JsFunctionArgumentType :: Void => arg . is_undefined ( ) , JsFunctionArgumentType :: Number | JsFunctionArgumentType :: Pointer => arg . as_f64 ( ) . is_some ( ) , JsFunctionArgumentType :: String => arg . as_string ( ) . is_some ( ) , } { log :: warn ! ( " " index arg_type arg ) ; } } } } JsValue :: from ( arg_types . into_iter ( ) . map ( | arg_type | js_value_from_argument_type ( arg_type ) ) . collect :: < Array > ( ) , ) } None => JsValue :: undefined ( ) , } ; log :: debug ! ( " " args ) ; match self . call_js_fn . as_ref ( ) . unwrap ( ) . apply ( & JsValue :: null ( ) , & Array :: of4 ( & js_fn_name , & js_return_type , & js_arg_types , args . unwrap_or ( & JsValue :: undefined ( ) ) , ) , ) { Ok ( result ) => { log :: debug ! ( " " result ) ; if self . debug { // Type-check result. if ! match return_type { JsFunctionArgumentType :: Void => result . is_undefined ( ) , JsFunctionArgumentType :: Number | JsFunctionArgumentType :: Pointer => { result . as_f64 ( ) . is_some ( ) } JsFunctionArgumentType :: String => result . as_string ( ) . is_some ( ) , } { log :: warn ! ( " " return_type ) ; } } result } Err ( err ) => { log :: error ! ( " " fn_name err ) ; panic ! ( ) ; } } }
Calls an emscripten-wrapped Pdfium function.
Calls an emscripten - wrapped Pdfium function .
&self
fn_name
&str
return_type
JsFunctionArgumentType
arg_types
Option<Vec<JsFunctionArgumentType>>
args
Option<&JsValue>
&self
fn_name
&str
return_type
JsFunctionArgumentType
arg_types
Option<Vec<JsFunctionArgumentType>>
args
Option<&JsValue>