Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: chrome/test/chromedriver/js/execute_async_script.js

Issue 12675002: [chromedriver] Implement command: executeAsyncScript and setScriptTimeout (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address +5000 timeout problem. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 * Return the information of asynchronous script execution.
7 *
8 * @return {Object.<string, ?>} Information of asynchronous script execution.
9 */
10 function getAsyncScriptInfo() {
11 var key = 'chromedriverAsyncScriptInfo';
12 if (!(key in document))
13 document[key] = {'id': 0, 'finished': false};
14 return document[key];
15 }
16
17 /**
18 * Execute the given script and save its asynchronous result.
19 *
20 * If script1 finishes after script2 is executed, then script1's result will be
21 * discarded while script2's will be saved.
22 *
23 * @param {!string} script The asynchronous script to be executed.
24 * @param {Array.<*>} args Arguments to be passed to the script.
25 */
26 function executeAsyncScript(script, args) {
27 var info = getAsyncScriptInfo();
28 info.id++;
29 info.finished = false;
30 delete info.result;
31 var id = info.id;
32
33 function callback(result) {
34 if (id == info.id) {
35 info.result = result;
36 info.finished = true;
37 }
38 }
39 args.push(callback);
40
41 try {
42 new Function(script).apply(null, args);
43 } catch (error) {
44 error.code = 17; // Error code for JavaScriptError.
45 throw error;
46 }
47 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/command_executor_impl.cc ('k') | chrome/test/chromedriver/js/execute_async_script_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698