Calls a JavaScript function synchronously of the global scope and returns its result.
The JavaScript function name to call.
An OLE/COM Variant passed to the JavaScript function.
Calls a JavaScript function synchronously of the global scope and returns its result.
The JavaScript function name to call.
An OLE/COM Variant passed to the JavaScript function.
An OLE/COM Variant returned from by the JavaScript function.
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.
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 CallByName, JSCallBack 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.
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.
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); } }