aboutsummaryrefslogtreecommitdiffstats
path: root/signaling-server/node_modules/socket.io/node_modules/socket.io-client/test/node/builder.common.js
blob: fa8d46eda119e10292a1ff9d533568aa70064a59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*!
 * socket.io-node
 * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
 * MIT Licensed
 */

var vm = require('vm')
  , should = require('should');

/**
 * Generates evn variables for the vm so we can `emulate` a browser.
 * @returns {Object} evn variables
 */

exports.env = function env () {
  var details = {
      location: {
          port: 8080
        , host: 'www.example.org'
        , hostname: 'www.example.org'
        , href: 'http://www.example.org/example/'
        , pathname: '/example/'
        , protocol: 'http:'
        , search: ''
        , hash: ''
      }
    , console: {
        log:   function(){},
        info:  function(){},
        warn:  function(){},
        error: function(){}
      }
    , navigator: {
          userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit'
           + '/534.27 (KHTML, like Gecko) Chrome/12.0.716.0 Safari/534.27'
        , appName: 'socket.io'
        , platform: process.platform
        , appVersion: process.version
    , }
    , name: 'socket.io'
    , innerWidth: 1024
    , innerHeight: 768
    , length: 1
    , outerWidth: 1024
    , outerHeight: 768
    , pageXOffset: 0
    , pageYOffset: 0
    , screenX: 0
    , screenY: 0
    , screenLeft: 0
    , screenTop: 0
    , scrollX: 0
    , scrollY: 0
    , scrollTop: 0
    , scrollLeft: 0
    , screen: {
          width: 0
        , height: 0
      }
  };

  // circular references
  details.window = details.self = details.contentWindow = details;

  // callable methods
  details.Image = details.scrollTo = details.scrollBy = details.scroll = 
  details.resizeTo = details.resizeBy = details.prompt = details.print = 
  details.open = details.moveTo = details.moveBy = details.focus = 
  details.createPopup = details.confirm = details.close = details.blur = 
  details.alert = details.clearTimeout = details.clearInterval = 
  details.setInterval = details.setTimeout = details.XMLHttpRequest = 
  details.getComputedStyle = details.trigger = details.dispatchEvent = 
  details.removeEventListener = details.addEventListener = function(){};

  // frames
  details.frames = [details];

  // document
  details.document = details;
  details.document.domain = details.location.href;

  return details;
};

/**
 * Executes a script in a browser like env and returns
 * the result
 *
 * @param {String} contents The script content
 * @returns {Object} The evaluated script.
 */

exports.execute = function execute (contents) {
  var env = exports.env() 
    , script = vm.createScript(contents);

  // run the script with `browser like` globals
  script.runInNewContext(env);

  return env;
};