Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / node_modules / phridge / lib / phantom / methods.js
1 "use strict";
2
3 /**
4  * Opens the given page and resolves when PhantomJS called back.
5  * Will be executed inside of PhantomJS.
6  *
7  * @private
8  * @this Page
9  * @param {string} url
10  * @param {Function} resolve
11  * @param {Function} reject
12  */
13 function openPage(url, resolve, reject) { /* jshint validthis: true */
14     this.open(url, function onPageLoaded(status) {
15         if (status !== "success") {
16             return reject(new Error("Cannot load " + url + ": PhantomJS returned status " + status));
17         }
18         resolve();
19     });
20 }
21
22 /**
23  * Calls phantom.exit() with errorcode 0
24  *
25  * @private
26  */
27 function exitPhantom() { /* global phantom */
28     Object.keys(pages).forEach(function (pageId) {
29         // Closing all pages just to cleanup properly
30         pages[pageId].close();
31     });
32
33     // Using setTimeout(0) to ensure that all JS code still waiting in the queue is executed before exiting
34     // Otherwise PhantomJS prints a confusing security warning
35     // @see https://github.com/ariya/phantomjs/commit/1eec21ed5c887bf21a1a6833da3c98c68401d90e
36     setTimeout(function () {
37         phantom.exit(0);
38     }, 0);
39 }
40
41 /**
42  * Cleans all references to a specific page.
43  *
44  * @private
45  * @param {number} pageId
46  */
47 function disposePage(pageId) { /* global pages */
48     pages[pageId].close();
49     delete pages[pageId];
50 }
51
52 exports.openPage = openPage;
53 exports.exitPhantom = exitPhantom;
54 exports.disposePage = disposePage;