Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / vendor / jcalderonzumba / gastonjs / src / Client / poltergeist.js
1 Poltergeist = (function () {
2
3   /**
4    * The MAIN class of the project
5    * @param port
6    * @param width
7    * @param height
8    * @param jsErrors
9    * @constructor
10    */
11   function Poltergeist(port, width, height, jsErrors) {
12     var self;
13     this.browser = new Poltergeist.Browser(this, width, height, jsErrors);
14
15     this.commandServer = new Poltergeist.Server(this, port);
16     this.commandServer.start();
17
18     self = this;
19
20     phantom.onError = function (message, stack) {
21       return self.onError(message, stack);
22     };
23
24     this.running = false;
25   }
26
27   /**
28    * Tries to execute a command send by a client and returns the command response
29    * or error if something happened
30    * @param command
31    * @param serverResponse
32    * @return {boolean}
33    */
34   Poltergeist.prototype.serverRunCommand = function (command, serverResponse) {
35     var error;
36     this.running = true;
37     try {
38       return this.browser.serverRunCommand(command, serverResponse);
39     } catch (_error) {
40       error = _error;
41       if (error instanceof Poltergeist.Error) {
42         return this.serverSendError(error, serverResponse);
43       }
44       return this.serverSendError(new Poltergeist.BrowserError(error.toString(), error.stack), serverResponse);
45     }
46   };
47
48   /**
49    * Sends error back to the client
50    * @param error
51    * @param serverResponse
52    * @return {boolean}
53    */
54   Poltergeist.prototype.serverSendError = function (error, serverResponse) {
55     var errorObject;
56     errorObject = {
57       error: {
58         name: error.name || 'Generic',
59         args: error.args && error.args() || [error.toString()]
60       }
61     };
62     return this.commandServer.sendError(serverResponse, 500, errorObject);
63   };
64
65   /**
66    * Send the response back to the client
67    * @param response        Data to send to the client
68    * @param serverResponse  Phantomjs response object associated to the client request
69    * @return {boolean}
70    */
71   Poltergeist.prototype.serverSendResponse = function (response, serverResponse) {
72     return this.commandServer.send(serverResponse, {response: response});
73   };
74
75   return Poltergeist;
76 })();
77
78 window.Poltergeist = Poltergeist;