OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * Execute the given script and save its result. | |
kkania
2013/03/08 17:25:12
saves its asynchronous result
chrisgao (Use stgao instead)
2013/03/08 21:06:24
Done.
| |
7 * | |
8 * A callback function {function(*) : null} will be appended to the end of | |
9 * <code>args</code>. | |
10 * The script should call this callback when it is completed. The value passed to | |
11 * this callback will be saved in window.chromedriverAsyncScriptResult. Variable | |
kkania
2013/03/08 17:25:12
try not to include unnecessary implementation deta
chrisgao (Use stgao instead)
2013/03/08 21:06:24
Done.
| |
12 * window.chromedriverAsyncScriptFinsished indicates whether the script | |
13 * is completed. | |
14 * | |
15 * If script1 is executed before script2, but script1 completes after script2, | |
16 * then script1's result will be discarded while script2's will be saved. | |
17 * | |
18 * @param {!string} script The asynchronous script to be executed. | |
19 * @param {Array.<*>} args Arguments to be passed to the script. | |
20 */ | |
21 function executeAsyncScript(script, args) { | |
22 var idName = 'chromedriverAsyncScriptId'; | |
kkania
2013/03/08 17:25:12
how about:
function getAsyncScriptInfo() {
var
chrisgao (Use stgao instead)
2013/03/08 21:06:24
Done.
| |
23 var finishFlagName = 'chromedriverAsyncScriptFinsished'; | |
kkania
2013/03/08 17:25:12
i think technically you don't need the finish flag
chrisgao (Use stgao instead)
2013/03/08 21:06:24
ok.
| |
24 var resultName = 'chromedriverAsyncScriptResult'; | |
25 if (!(idName in document)) | |
26 document[idName] = 0; | |
27 document[idName] ++; | |
kkania
2013/03/08 17:25:12
style says no space i thnik
chrisgao (Use stgao instead)
2013/03/08 21:06:24
Done.
| |
28 document[resultName] = null; | |
kkania
2013/03/08 17:25:12
what's the point of this?
chrisgao (Use stgao instead)
2013/03/08 21:06:24
If last script timeout, its result might still be
| |
29 document[finishFlagName] = false; | |
30 var id = document[idName]; | |
31 | |
32 function callback(result) { | |
33 if (id == document[idName]) { | |
kkania
2013/03/08 17:25:12
i can think of two improvements here:
1) if the us
chrisgao (Use stgao instead)
2013/03/08 21:06:24
1) Raise Timeout error below if this case happens.
| |
34 document[resultName] = result; | |
35 document[finishFlagName] = true; | |
36 } | |
37 } | |
38 args.push(callback); | |
39 | |
40 new window['Function'](script).apply(null, args); | |
kkania
2013/03/08 17:25:12
I don't think you need the window. new Function(
chrisgao (Use stgao instead)
2013/03/08 21:06:24
Done.
Also set error code here.
| |
41 } | |
OLD | NEW |