|
15 | 15 | var p = document.createElement('p'); |
16 | 16 | var br = document.createElement('br'); |
17 | 17 | var br2 = document.createElement('br'); |
| 18 | + var hr = document.createElement('hr'); |
18 | 19 | var title = document.createTextNode('Async Call: '); |
19 | 20 | var callText = document.createTextNode(call); |
20 | 21 | var endText = document.createTextNode(end); |
|
24 | 25 | p.appendChild(callText); |
25 | 26 | p.appendChild(br2); |
26 | 27 | p.appendChild(endText); |
27 | | - |
| 28 | + p.appendChild(hr); |
| 29 | + |
28 | 30 | asResult.appendChild(p); |
29 | 31 | } |
30 | 32 |
|
31 | 33 | function asyncError() |
32 | 34 | { |
33 | | - var call = "Async call (Throw Exception): " + Date(); |
| 35 | + let call = "Async call (Throw Exception): " + Date(); |
34 | 36 | boundAsync.error().catch(function (e) |
35 | 37 | { |
36 | 38 | var end = "Error: " + e + "(" + Date() + ")"; |
37 | 39 | writeAsyncResult(call, end); |
38 | 40 | }); |
39 | 41 | } |
40 | 42 |
|
41 | | - function asyncDivOk() |
| 43 | + async function asyncDivOk() |
42 | 44 | { |
43 | | - var call = "Async call (Divide 16 / 2): " + Date(); |
44 | | - boundAsync.div(16, 2).then(function (res) |
45 | | - { |
46 | | - var end = "Result: " + res + "(" + Date() + ")"; |
47 | | - writeAsyncResult(call, end); |
48 | | - }); |
| 45 | + let call = "Async call (Divide 16 / 2): " + Date(); |
| 46 | + |
| 47 | + let res = await boundAsync.div(16, 2); |
| 48 | + |
| 49 | + let end = "Result: " + res + "(" + Date() + ")"; |
| 50 | + writeAsyncResult(call, end); |
49 | 51 | } |
50 | 52 |
|
51 | 53 | function asyncDivFail() |
|
63 | 65 | }); |
64 | 66 | } |
65 | 67 |
|
66 | | - function asyncHello() |
| 68 | + async function asyncHello() |
67 | 69 | { |
68 | | - var call = "Async call (Hello): " + Date(); |
69 | | - boundAsync.hello('CefSharp').then(function (res) |
70 | | - { |
71 | | - var end = "Result: " + res + "(" + Date() + ")"; |
72 | | - writeAsyncResult(call, end); |
73 | | - }); |
| 70 | + let call = "Async call (Hello): " + Date(); |
| 71 | + let res = await boundAsync.hello('CefSharp'); |
| 72 | + |
| 73 | + var end = "Result: " + res + "(" + Date() + ")"; |
| 74 | + writeAsyncResult(call, end); |
| 75 | + |
| 76 | + return end; |
74 | 77 | } |
75 | 78 |
|
76 | | - function asyncDoSomething() |
| 79 | + async function asyncDoSomething() |
77 | 80 | { |
78 | | - var call = "Async call (Long Running Task): " + Date(); |
79 | | - boundAsync.doSomething().then(function (res) |
80 | | - { |
81 | | - var end = "Result: " + res + "(" + Date() + ")"; |
82 | | - writeAsyncResult(call, end); |
83 | | - }); |
| 81 | + let call = "Async call (Long Running Task): " + Date(); |
| 82 | + let res = await boundAsync.doSomething(); |
| 83 | + |
| 84 | + let end = "Result: " + res + "(" + Date() + ")"; |
| 85 | + writeAsyncResult(call, end); |
84 | 86 | } |
85 | 87 |
|
86 | | - function asyncObject() |
| 88 | + async function asyncObject() |
87 | 89 | { |
88 | | - var call = "Async call (Object): " + Date(); |
89 | | - boundAsync.returnObject('CefSharp').then(function (res) |
90 | | - { |
91 | | - var end = "Result: " + JSON.stringify(res) + " (" + Date() + ")"; |
92 | | - writeAsyncResult(call, end); |
93 | | - }); |
| 90 | + let call = "Async call (Object): " + Date(); |
| 91 | + var res = await boundAsync.returnObject('CefSharp'); |
| 92 | + var end = "Result: " + JSON.stringify(res) + " (" + Date() + ")"; |
| 93 | + writeAsyncResult(call, end); |
94 | 94 | } |
95 | 95 |
|
96 | | - function asyncObjectArray() |
| 96 | + async function asyncObjectArray() |
97 | 97 | { |
98 | | - var call = "Async call (ObjectArray): " + Date(); |
99 | | - boundAsync.objectArray('CefSharp').then(function (res) |
100 | | - { |
101 | | - var end = "Result: [ " + res.map(function (item) { return item.Value }) + " ] (" + Date() + ")"; |
102 | | - writeAsyncResult(call, end); |
103 | | - }); |
| 98 | + let call = "Async call (ObjectArray): " + Date(); |
| 99 | + let res = await boundAsync.objectArray('CefSharp'); |
| 100 | + let end = "Result: [ " + res.map(function (item) { return item.Value }) + " ] (" + Date() + ")"; |
| 101 | + writeAsyncResult(call, end); |
104 | 102 | } |
105 | 103 |
|
| 104 | + async function asyncDictionaryPassedAsParam() |
| 105 | + { |
| 106 | + let call = [{ Name : "Chrome", Engine : {Name : "WebKit"} }, { Name : "Chromium", Engine : {Name : "WebKit"} }, { Name : "Opera", Engine : {Name : "WebKit"} }]; |
| 107 | + let res = await boundAsync.dynamiObjectList(call); |
| 108 | + writeAsyncResult(call, res); |
| 109 | + } |
| 110 | + |
106 | 111 | asyncError(); |
107 | 112 | asyncDivOk(); |
108 | 113 | asyncDivFail(); |
109 | 114 | asyncDoSomething(); |
110 | 115 | asyncHello(); |
111 | 116 | asyncObject(); |
112 | 117 | asyncObjectArray(); |
| 118 | + asyncDictionaryPassedAsParam(); |
113 | 119 | </script> |
114 | 120 | </p> |
115 | 121 | <p> |
|
293 | 299 | <script type="text/javascript"> |
294 | 300 | function str2ab(str) |
295 | 301 | { |
296 | | - var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char |
297 | | - var bufView = new Uint16Array(buf); |
298 | | - for (var i = 0, strLen = str.length; i < strLen; i++) |
299 | | - { |
300 | | - bufView[i] = str.charCodeAt(i); |
301 | | - } |
302 | | - return buf; |
| 302 | + var enc = new TextEncoder("utf-8"); |
| 303 | + return enc.encode(str).buffer; |
303 | 304 | } |
304 | 305 |
|
305 | 306 | document.write(bound.methodWithParams('With 1 Params', 'hello-world') + "<br/>"); |
|
313 | 314 | document.write(bound.methodWithThreeParamsOneOptionalOneArray("Test", null) + "<br/>"); |
314 | 315 | document.write(bound.methodWithThreeParamsOneOptionalOneArray(null, null, "Arg1", "Arg2") + "<br/>"); |
315 | 316 |
|
316 | | - var buffer = str2ab("Testing array buffer"); |
317 | | - document.write(bound.complexParamObject(buffer)); |
| 317 | + //CEF Does not currently support ArrayBuffer directly |
| 318 | + //https://bitbucket.org/chromiumembedded/cef/issues/244 |
| 319 | + //https://bitbucket.org/chromiumembedded/cef/pull-requests/12/v8-renderer-add-basic-arraybuffer-support/diff |
| 320 | + //var buffer = str2ab("Testing array buffer"); |
| 321 | + //document.write(bound.complexParamObject(buffer)); |
318 | 322 | </script> |
319 | 323 | </p> |
320 | 324 | </body> |
|
0 commit comments