|
98 | 98 |
|
99 | 99 | QUnit.test("JavascriptCallback EvalPromise:", async (assert) => |
100 | 100 | { |
101 | | - let convertPromiseToCefSharpCallback = function (p) |
102 | | - { |
103 | | - let f = function (callbackId, ...args) |
104 | | - { |
105 | | - //We immediately return CefSharpDefEvalScriptRes as we will be |
106 | | - //using a promise and will call sendEvalScriptResponse when our |
107 | | - //promise has completed |
108 | | - (async function () |
109 | | - { |
110 | | - try |
111 | | - { |
112 | | - //Await the promise |
113 | | - let response = await p(...args); |
114 | | - |
115 | | - //We're done, let's send our response back to our .Net App |
116 | | - cefSharp.sendEvalScriptResponse(callbackId, true, response, true); |
117 | | - } |
118 | | - catch (err) |
119 | | - { |
120 | | - //An error occurred let's send the response back to our .Net App |
121 | | - cefSharp.sendEvalScriptResponse(callbackId, false, err.message, true); |
122 | | - |
123 | | - } |
124 | | - })(); |
125 | | - |
126 | | - //Let CefSharp know we're going to be defering our response as we have some async/await |
127 | | - //processing to happen before our callback returns it's value |
128 | | - return "CefSharpDefEvalScriptRes"; |
129 | | - } |
130 | | - |
131 | | - return f; |
132 | | - } |
133 | | - |
134 | | - //The function convertPromiseToCefSharpCallback can be used in your own projects |
135 | | - //Pass in a function that wraps your promise, not your promise directly |
136 | | - let callback = convertPromiseToCefSharpCallback(function (msg) |
| 101 | + let callback = function (msg) |
137 | 102 | { |
138 | 103 | return new Promise((resolve, reject) => |
139 | 104 | { |
|
142 | 107 | resolve(msg); |
143 | 108 | }, 300); |
144 | 109 | }); |
145 | | - }); |
| 110 | + }; |
146 | 111 |
|
147 | 112 | const expectedResult = "JavascriptCallback after promise"; |
148 | 113 | const actualResult = await boundAsync.javascriptCallbackEvalPromise(expectedResult, callback); |
|
153 | 118 | // Issue #3979 |
154 | 119 | QUnit.test("JavascriptCallback conditionally EvalPromise:", async (assert) => |
155 | 120 | { |
156 | | - let convertPromiseToCefSharpCallback = function (p) |
157 | | - { |
158 | | - let f = function (callbackId, ...args) |
159 | | - { |
160 | | - //We immediately return CefSharpDefEvalScriptRes as we will be |
161 | | - //using a promise and will call sendEvalScriptResponse when our |
162 | | - //promise has completed |
163 | | - (async function () |
164 | | - { |
165 | | - try |
166 | | - { |
167 | | - //Await the promise |
168 | | - let response = await p(...args); |
169 | | - |
170 | | - //We're done, let's send our response back to our .Net App |
171 | | - cefSharp.sendEvalScriptResponse(callbackId, true, response, true); |
172 | | - } |
173 | | - catch (err) |
174 | | - { |
175 | | - //An error occurred let's send the response back to our .Net App |
176 | | - cefSharp.sendEvalScriptResponse(callbackId, false, err.message, true); |
177 | | - } |
178 | | - })(); |
179 | | - |
180 | | - //Let CefSharp know we're going to be defering our response as we have some async/await |
181 | | - //processing to happen before our callback returns it's value |
182 | | - return "CefSharpDefEvalScriptRes"; |
183 | | - } |
184 | | - |
185 | | - return f; |
186 | | - } |
187 | | - |
188 | | - //The function convertPromiseToCefSharpCallback can be used in your own projects |
189 | | - //Pass in a function that wraps your promise, not your promise directly |
190 | | - let callback = convertPromiseToCefSharpCallback(function (msg) |
| 121 | + let callback = function (msg) |
191 | 122 | { |
192 | 123 | return new Promise((resolve, reject) => |
193 | 124 | { |
|
196 | 127 | resolve(msg); |
197 | 128 | }, 300); |
198 | 129 | }); |
199 | | - }); |
| 130 | + }; |
200 | 131 |
|
201 | 132 | const expectedResult = "Callback has not been invoked"; |
202 | 133 | const actualResult = await boundAsync.javascriptOptionalCallbackEvalPromise(false, expectedResult, callback); |
|
0 commit comments