Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / socket.io-client / test / node / builder.common.js
1
2 /*!
3  * socket.io-node
4  * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
5  * MIT Licensed
6  */
7
8 var vm = require('vm')
9   , should = require('should');
10
11 /**
12  * Generates evn variables for the vm so we can `emulate` a browser.
13  * @returns {Object} evn variables
14  */
15
16 exports.env = function env () {
17   var details = {
18       location: {
19           port: 8080
20         , host: 'www.example.org'
21         , hostname: 'www.example.org'
22         , href: 'http://www.example.org/example/'
23         , pathname: '/example/'
24         , protocol: 'http:'
25         , search: ''
26         , hash: ''
27       }
28     , console: {
29         log:   function(){},
30         info:  function(){},
31         warn:  function(){},
32         error: function(){}
33       }
34     , navigator: {
35           userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit'
36            + '/534.27 (KHTML, like Gecko) Chrome/12.0.716.0 Safari/534.27'
37         , appName: 'socket.io'
38         , platform: process.platform
39         , appVersion: process.version
40     , }
41     , name: 'socket.io'
42     , innerWidth: 1024
43     , innerHeight: 768
44     , length: 1
45     , outerWidth: 1024
46     , outerHeight: 768
47     , pageXOffset: 0
48     , pageYOffset: 0
49     , screenX: 0
50     , screenY: 0
51     , screenLeft: 0
52     , screenTop: 0
53     , scrollX: 0
54     , scrollY: 0
55     , scrollTop: 0
56     , scrollLeft: 0
57     , screen: {
58           width: 0
59         , height: 0
60       }
61   };
62
63   // circular references
64   details.window = details.self = details.contentWindow = details;
65
66   // callable methods
67   details.Image = details.scrollTo = details.scrollBy = details.scroll = 
68   details.resizeTo = details.resizeBy = details.prompt = details.print = 
69   details.open = details.moveTo = details.moveBy = details.focus = 
70   details.createPopup = details.confirm = details.close = details.blur = 
71   details.alert = details.clearTimeout = details.clearInterval = 
72   details.setInterval = details.setTimeout = details.XMLHttpRequest = 
73   details.getComputedStyle = details.trigger = details.dispatchEvent = 
74   details.removeEventListener = details.addEventListener = function(){};
75
76   // frames
77   details.frames = [details];
78
79   // document
80   details.document = details;
81   details.document.domain = details.location.href;
82
83   return details;
84 };
85
86 /**
87  * Executes a script in a browser like env and returns
88  * the result
89  *
90  * @param {String} contents The script content
91  * @returns {Object} The evaluated script.
92  */
93
94 exports.execute = function execute (contents) {
95   var env = exports.env() 
96     , script = vm.createScript(contents);
97
98   // run the script with `browser like` globals
99   script.runInNewContext(env);
100
101   return env;
102 };