mobileFX WebKitX CEF3 ActiveX 4.x
WebKitXCEF3Lib ActiveX Control / WebKitXCEF3 Object / CallByName Method

The JavaScript function name to call.

An OLE/COM Variant passed to the JavaScript function.

In This Topic
    CallByName Method
    In This Topic
    Description

    Calls a JavaScript function synchronously of the global scope and returns its result.

    Syntax
    Visual Basic
    Public Function CallByName( _
       ByVal Name As String, _
       ByVal Arguments As Variant _
    ) As Variant
    Parameters
    Name

    The JavaScript function name to call.

    Arguments

    An OLE/COM Variant passed to the JavaScript function.

    Return Type

    An OLE/COM Variant returned from by the JavaScript function.

    Remarks

    The simplest way to call a JavaScript function in WebKitX is WebKitX.CallByName(Name, Variant) method. You can pass to JavaScript function arbitrary arguments using an OLE/COM Variant and receive the function's result value, as an OLE/COM Variant too.

    Execution of CallByName is IPC-synchronous and this method is an elegant alternative to Eval code as you can pass back-and-forth your variables without stringifying them.

    OLE/COM Variants to V8 Values Conversion

    WebKitX has a powerful OLE/COM Variant to Google V8 Value bi-directional converter that works both for Scalar and Array values, including nested array values (arrays of arrays of variants). This conversion mechanism is available to any WebKitX method transmitting and/or returning an OLE/COM Variant, such as CallByNameJSCallBack and DispatchEvent.

    WebKitX can serialize variant scalars VT_BSTR, VT_UINT, VT_INT, VT_NULL, VT_BOOL, VT_R4, VT_R8, VT_CY, VT_DATE as well as variant safearray of variants VT_ARRAY | VT_VARIANT and even typed arrays VT_ARRAY | VT_BSTR, VT_ARRAY | VT_UINT, VT_ARRAY | VT_INT, VT_ARRAY | VT_BOOL, VT_ARRAY | VT_R4, VT_ARRAY | VT_R8, VT_ARRAY | VT_CY, VT_ARRAY | VT_DATE to Google V8 JavaScript value objects.

    • Currently serialization of VT_DISPATCH is not supported and therefore you cannot pass OLE/COM Objects to JavaScript.
    • On the OLE/COM side, to pass multiple arguments to a JavaScript callback function you need to wrap them in a Variant Array of Variants.
    • On the JavaScript side, you can return V8 Scalar or V8 Array values to OLE/COM side, including nested V8 Arrays.

    WebKitX can serialize V8 scalar Boolean, Number, String, Null, Date values and Array of [Boolean or Number or String or Null or Date or Array] V8 values.

    Google V8 Arrays are always returned as Variant Arrays of Variants. On the receiving OLE/COM side the scalars are converted to a Variant of equivalent scalar type and Arrays are converted into a Variant Array of Variants.

    Example
    Private Sub mnuTestCallByName_Click()
        On Error Resume Next
        Dim s As String
        Dim result As Variant
        s = InputBox("Function to call", , "foo")
        If s = "" Then Exit Sub
        result = WebKitX1.CallByName(s, Array("My Data", 10, 3.14, Date + Time))
        If IsArray(result) Then
            MsgBox Join(result, ", "), vbInformation
        Else
            MsgBox result, vbInformation
        End If
    End Sub
    private void menuItemTestCallByName_Click(object sender, EventArgs e)
    {
        string input = Microsoft.VisualBasic.Interaction.InputBox("Function to call", "HTML5 Pad", "foo", 500, 300);            
        if (input != "")
        {
            object result = WebKitXCEF31.CallByName(input, new[] { "My Data", "10", "3.1", DateTime.Now.ToString() });
            string[] arr = Array.ConvertAll<object, string>((object[])result, Convert.ToString);
            MessageBox.Show(String.Join(",", arr), "HTML5 Pad", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
    See Also