closes #145 - use of javascript strict mode for modules
Showing
13 changed files
with
68 additions
and
21 deletions
... | @@ -9,6 +9,7 @@ XXXX-XX-XX, v0.6.11 | ... | @@ -9,6 +9,7 @@ XXXX-XX-XX, v0.6.11 |
9 | - closed [#144](https://github.com/n1k0/casperjs/issues/144) - added a `safeLogs` option to blur password values in debug logs. **This option is set to `true` by default.** | 9 | - closed [#144](https://github.com/n1k0/casperjs/issues/144) - added a `safeLogs` option to blur password values in debug logs. **This option is set to `true` by default.** |
10 | - added [`Casper.userAgent()`](http://casperjs.org/api.html#casper.userAgent) to ease a more dynamic setting of user-agent string | 10 | - added [`Casper.userAgent()`](http://casperjs.org/api.html#casper.userAgent) to ease a more dynamic setting of user-agent string |
11 | - switched to more standard `.textContent` property to get a node text; this allows a better compatibility of the clientutils bookmarklet with non-webkit browsers | 11 | - switched to more standard `.textContent` property to get a node text; this allows a better compatibility of the clientutils bookmarklet with non-webkit browsers |
12 | - casper modules now all use [javascript strict mode](http://www.nczonline.net/blog/2012/03/13/its-time-to-start-using-javascript-strict-mode/) | ||
12 | 13 | ||
13 | 2012-06-04, v0.6.10 | 14 | 2012-06-04, v0.6.10 |
14 | ------------------- | 15 | ------------------- | ... | ... |
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
... | @@ -28,6 +28,8 @@ | ... | @@ -28,6 +28,8 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError console exports phantom require*/ | ||
32 | |||
31 | var utils = require('utils'); | 33 | var utils = require('utils'); |
32 | 34 | ||
33 | /** | 35 | /** |
... | @@ -38,6 +40,7 @@ var utils = require('utils'); | ... | @@ -38,6 +40,7 @@ var utils = require('utils'); |
38 | * @return Object | 40 | * @return Object |
39 | */ | 41 | */ |
40 | exports.parse = function parse(phantomArgs) { | 42 | exports.parse = function parse(phantomArgs) { |
43 | "use strict"; | ||
41 | var extract = { | 44 | var extract = { |
42 | args: [], | 45 | args: [], |
43 | options: {}, | 46 | options: {}, |
... | @@ -110,6 +113,7 @@ exports.parse = function parse(phantomArgs) { | ... | @@ -110,6 +113,7 @@ exports.parse = function parse(phantomArgs) { |
110 | * @return Mixed | 113 | * @return Mixed |
111 | */ | 114 | */ |
112 | function castArgument(arg) { | 115 | function castArgument(arg) { |
116 | "use strict"; | ||
113 | if (arg.match(/^-?\d+$/)) { | 117 | if (arg.match(/^-?\d+$/)) { |
114 | return parseInt(arg, 10); | 118 | return parseInt(arg, 10); |
115 | } else if (arg.match(/^-?\d+\.\d+$/)) { | 119 | } else if (arg.match(/^-?\d+\.\d+$/)) { | ... | ... |
... | @@ -27,7 +27,12 @@ | ... | @@ -27,7 +27,12 @@ |
27 | * DEALINGS IN THE SOFTWARE. | 27 | * DEALINGS IN THE SOFTWARE. |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | |||
31 | /*global console escape exports NodeList window*/ | ||
32 | |||
30 | (function(exports) { | 33 | (function(exports) { |
34 | "use strict"; | ||
35 | |||
31 | exports.create = function create(options) { | 36 | exports.create = function create(options) { |
32 | return new this.ClientUtils(options); | 37 | return new this.ClientUtils(options); |
33 | }; | 38 | }; |
... | @@ -466,7 +471,7 @@ | ... | @@ -466,7 +471,7 @@ |
466 | * @param mixed value The field value to set | 471 | * @param mixed value The field value to set |
467 | */ | 472 | */ |
468 | this.setField = function setField(field, value) { | 473 | this.setField = function setField(field, value) { |
469 | var fields, out; | 474 | var logValue, fields, out; |
470 | value = logValue = (value || ""); | 475 | value = logValue = (value || ""); |
471 | if (field instanceof NodeList) { | 476 | if (field instanceof NodeList) { |
472 | fields = field; | 477 | fields = field; |
... | @@ -477,7 +482,7 @@ | ... | @@ -477,7 +482,7 @@ |
477 | } | 482 | } |
478 | if (this.options && this.options.safeLogs && field.getAttribute('type') === "password") { | 483 | if (this.options && this.options.safeLogs && field.getAttribute('type') === "password") { |
479 | // obfuscate password value | 484 | // obfuscate password value |
480 | logValue = Array(value.length + 1).join("*"); | 485 | logValue = new Array(value.length + 1).join("*"); |
481 | } | 486 | } |
482 | this.log('Set "' + field.getAttribute('name') + '" field value to ' + logValue, "debug"); | 487 | this.log('Set "' + field.getAttribute('name') + '" field value to ' + logValue, "debug"); |
483 | try { | 488 | try { | ... | ... |
... | @@ -28,10 +28,13 @@ | ... | @@ -28,10 +28,13 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global exports console require*/ | ||
32 | |||
31 | var fs = require('fs'); | 33 | var fs = require('fs'); |
32 | var utils = require('utils'); | 34 | var utils = require('utils'); |
33 | 35 | ||
34 | exports.create = function create(type) { | 36 | exports.create = function create(type) { |
37 | "use strict"; | ||
35 | if (!type) { | 38 | if (!type) { |
36 | return; | 39 | return; |
37 | } | 40 | } |
... | @@ -48,6 +51,7 @@ exports.create = function create(type) { | ... | @@ -48,6 +51,7 @@ exports.create = function create(type) { |
48 | * (c) Fabien Potencier, Symfony project, MIT license | 51 | * (c) Fabien Potencier, Symfony project, MIT license |
49 | */ | 52 | */ |
50 | var Colorizer = function Colorizer() { | 53 | var Colorizer = function Colorizer() { |
54 | "use strict"; | ||
51 | var options = { bold: 1, underscore: 4, blink: 5, reverse: 7, conceal: 8 }; | 55 | var options = { bold: 1, underscore: 4, blink: 5, reverse: 7, conceal: 8 }; |
52 | var foreground = { black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37 }; | 56 | var foreground = { black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37 }; |
53 | var background = { black: 40, red: 41, green: 42, yellow: 43, blue: 44, magenta: 45, cyan: 46, white: 47 }; | 57 | var background = { black: 40, red: 41, green: 42, yellow: 43, blue: 44, magenta: 45, cyan: 46, white: 47 }; |
... | @@ -104,7 +108,7 @@ var Colorizer = function Colorizer() { | ... | @@ -104,7 +108,7 @@ var Colorizer = function Colorizer() { |
104 | if (typeof pad === "number" && text.length < pad) { | 108 | if (typeof pad === "number" && text.length < pad) { |
105 | text += new Array(pad - text.length + 1).join(' '); | 109 | text += new Array(pad - text.length + 1).join(' '); |
106 | } | 110 | } |
107 | return "\033[" + codes.join(';') + 'm' + text + "\033[0m"; | 111 | return "\u001b[" + codes.join(';') + 'm' + text + "\u001b[0m"; |
108 | }; | 112 | }; |
109 | }; | 113 | }; |
110 | exports.Colorizer = Colorizer; | 114 | exports.Colorizer = Colorizer; |
... | @@ -114,6 +118,7 @@ exports.Colorizer = Colorizer; | ... | @@ -114,6 +118,7 @@ exports.Colorizer = Colorizer; |
114 | * | 118 | * |
115 | */ | 119 | */ |
116 | var Dummy = function Dummy() { | 120 | var Dummy = function Dummy() { |
121 | "use strict"; | ||
117 | this.colorize = function colorize(text, styleName, pad) { | 122 | this.colorize = function colorize(text, styleName, pad) { |
118 | return text; | 123 | return text; |
119 | }; | 124 | }; | ... | ... |
... | @@ -28,9 +28,12 @@ | ... | @@ -28,9 +28,12 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError console encodeURIComponent escape exports require*/ | ||
32 | |||
31 | var utils = require('utils'); | 33 | var utils = require('utils'); |
32 | 34 | ||
33 | exports.create = function create(fn) { | 35 | exports.create = function create(fn) { |
36 | "use strict"; | ||
34 | return new FunctionArgsInjector(fn); | 37 | return new FunctionArgsInjector(fn); |
35 | }; | 38 | }; |
36 | 39 | ||
... | @@ -40,6 +43,7 @@ exports.create = function create(fn) { | ... | @@ -40,6 +43,7 @@ exports.create = function create(fn) { |
40 | * FIXME: use new Function() instead of eval() | 43 | * FIXME: use new Function() instead of eval() |
41 | */ | 44 | */ |
42 | var FunctionArgsInjector = function FunctionArgsInjector(fn) { | 45 | var FunctionArgsInjector = function FunctionArgsInjector(fn) { |
46 | "use strict"; | ||
43 | if (!utils.isFunction(fn)) { | 47 | if (!utils.isFunction(fn)) { |
44 | throw new CasperError("FunctionArgsInjector() can only process functions"); | 48 | throw new CasperError("FunctionArgsInjector() can only process functions"); |
45 | } | 49 | } | ... | ... |
... | @@ -28,13 +28,17 @@ | ... | @@ -28,13 +28,17 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError exports require*/ | ||
32 | |||
31 | var utils = require('utils'); | 33 | var utils = require('utils'); |
32 | 34 | ||
33 | exports.create = function create(casper) { | 35 | exports.create = function create(casper) { |
36 | "use strict"; | ||
34 | return new Mouse(casper); | 37 | return new Mouse(casper); |
35 | }; | 38 | }; |
36 | 39 | ||
37 | var Mouse = function Mouse(casper) { | 40 | var Mouse = function Mouse(casper) { |
41 | "use strict"; | ||
38 | if (!utils.isCasperObject(casper)) { | 42 | if (!utils.isCasperObject(casper)) { |
39 | throw new CasperError('Mouse() needs a Casper instance'); | 43 | throw new CasperError('Mouse() needs a Casper instance'); |
40 | } | 44 | } | ... | ... |
... | @@ -28,12 +28,15 @@ | ... | @@ -28,12 +28,15 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError exports phantom require*/ | ||
32 | |||
31 | var fs = require('fs'); | 33 | var fs = require('fs'); |
32 | var events = require('events'); | 34 | var events = require('events'); |
33 | var utils = require('utils'); | 35 | var utils = require('utils'); |
34 | var f = utils.format; | 36 | var f = utils.format; |
35 | 37 | ||
36 | exports.create = function create(casper, options) { | 38 | exports.create = function create(casper, options) { |
39 | "use strict"; | ||
37 | return new Tester(casper, options); | 40 | return new Tester(casper, options); |
38 | }; | 41 | }; |
39 | 42 | ||
... | @@ -44,6 +47,7 @@ exports.create = function create(casper, options) { | ... | @@ -44,6 +47,7 @@ exports.create = function create(casper, options) { |
44 | * @param Object|null options Options object | 47 | * @param Object|null options Options object |
45 | */ | 48 | */ |
46 | var Tester = function Tester(casper, options) { | 49 | var Tester = function Tester(casper, options) { |
50 | "use strict"; | ||
47 | if (!utils.isCasperObject(casper)) { | 51 | if (!utils.isCasperObject(casper)) { |
48 | throw new CasperError("Tester needs a Casper instance"); | 52 | throw new CasperError("Tester needs a Casper instance"); |
49 | } | 53 | } | ... | ... |
... | @@ -28,6 +28,8 @@ | ... | @@ -28,6 +28,8 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError console exports phantom require*/ | ||
32 | |||
31 | /** | 33 | /** |
32 | * Provides a better typeof operator equivalent, able to retrieve the array | 34 | * Provides a better typeof operator equivalent, able to retrieve the array |
33 | * type. | 35 | * type. |
... | @@ -37,6 +39,7 @@ | ... | @@ -37,6 +39,7 @@ |
37 | * @see http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/ | 39 | * @see http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/ |
38 | */ | 40 | */ |
39 | function betterTypeOf(input) { | 41 | function betterTypeOf(input) { |
42 | "use strict"; | ||
40 | try { | 43 | try { |
41 | return Object.prototype.toString.call(input).match(/^\[object\s(.*)\]$/)[1].toLowerCase(); | 44 | return Object.prototype.toString.call(input).match(/^\[object\s(.*)\]$/)[1].toLowerCase(); |
42 | } catch (e) { | 45 | } catch (e) { |
... | @@ -52,6 +55,7 @@ exports.betterTypeOf = betterTypeOf; | ... | @@ -52,6 +55,7 @@ exports.betterTypeOf = betterTypeOf; |
52 | * @param Mixed value | 55 | * @param Mixed value |
53 | */ | 56 | */ |
54 | function dump(value) { | 57 | function dump(value) { |
58 | "use strict"; | ||
55 | console.log(serialize(value)); | 59 | console.log(serialize(value)); |
56 | } | 60 | } |
57 | exports.dump = dump; | 61 | exports.dump = dump; |
... | @@ -63,6 +67,7 @@ exports.dump = dump; | ... | @@ -63,6 +67,7 @@ exports.dump = dump; |
63 | * @return string | 67 | * @return string |
64 | */ | 68 | */ |
65 | function fileExt(file) { | 69 | function fileExt(file) { |
70 | "use strict"; | ||
66 | try { | 71 | try { |
67 | return file.split('.').pop().toLowerCase().trim(); | 72 | return file.split('.').pop().toLowerCase().trim(); |
68 | } catch(e) { | 73 | } catch(e) { |
... | @@ -79,6 +84,7 @@ exports.fileExt = fileExt; | ... | @@ -79,6 +84,7 @@ exports.fileExt = fileExt; |
79 | * @return String | 84 | * @return String |
80 | */ | 85 | */ |
81 | function fillBlanks(text, pad) { | 86 | function fillBlanks(text, pad) { |
87 | "use strict"; | ||
82 | pad = pad || 80; | 88 | pad = pad || 80; |
83 | if (text.length < pad) { | 89 | if (text.length < pad) { |
84 | text += new Array(pad - text.length + 1).join(' '); | 90 | text += new Array(pad - text.length + 1).join(' '); |
... | @@ -93,15 +99,8 @@ exports.fillBlanks = fillBlanks; | ... | @@ -93,15 +99,8 @@ exports.fillBlanks = fillBlanks; |
93 | * @return String | 99 | * @return String |
94 | */ | 100 | */ |
95 | function format(f) { | 101 | function format(f) { |
96 | var i; | 102 | "use strict"; |
97 | if (typeof f !== 'string') { | 103 | var i = 1; |
98 | var objects = []; | ||
99 | for (i = 0; i < arguments.length; i++) { | ||
100 | objects.push(inspect(arguments[i])); | ||
101 | } | ||
102 | return objects.join(' '); | ||
103 | } | ||
104 | i = 1; | ||
105 | var args = arguments; | 104 | var args = arguments; |
106 | var len = args.length; | 105 | var len = args.length; |
107 | var str = String(f).replace(/%[sdj%]/g, function _replace(x) { | 106 | var str = String(f).replace(/%[sdj%]/g, function _replace(x) { |
... | @@ -123,7 +122,7 @@ function format(f) { | ... | @@ -123,7 +122,7 @@ function format(f) { |
123 | if (x === null || typeof x !== 'object') { | 122 | if (x === null || typeof x !== 'object') { |
124 | str += ' ' + x; | 123 | str += ' ' + x; |
125 | } else { | 124 | } else { |
126 | str += ' ' + inspect(x); | 125 | str += '[obj]'; |
127 | } | 126 | } |
128 | } | 127 | } |
129 | return str; | 128 | return str; |
... | @@ -138,6 +137,7 @@ exports.format = format; | ... | @@ -138,6 +137,7 @@ exports.format = format; |
138 | * @param {function} superCtor Constructor function to inherit prototype from. | 137 | * @param {function} superCtor Constructor function to inherit prototype from. |
139 | */ | 138 | */ |
140 | function inherits(ctor, superCtor) { | 139 | function inherits(ctor, superCtor) { |
140 | "use strict"; | ||
141 | ctor.super_ = ctor.__super__ = superCtor; | 141 | ctor.super_ = ctor.__super__ = superCtor; |
142 | ctor.prototype = Object.create(superCtor.prototype, { | 142 | ctor.prototype = Object.create(superCtor.prototype, { |
143 | constructor: { | 143 | constructor: { |
... | @@ -157,6 +157,7 @@ exports.inherits = inherits; | ... | @@ -157,6 +157,7 @@ exports.inherits = inherits; |
157 | * @return Boolean | 157 | * @return Boolean |
158 | */ | 158 | */ |
159 | function isArray(value) { | 159 | function isArray(value) { |
160 | "use strict"; | ||
160 | return Array.isArray(value) || isType(value, "array"); | 161 | return Array.isArray(value) || isType(value, "array"); |
161 | } | 162 | } |
162 | exports.isArray = isArray; | 163 | exports.isArray = isArray; |
... | @@ -168,6 +169,7 @@ exports.isArray = isArray; | ... | @@ -168,6 +169,7 @@ exports.isArray = isArray; |
168 | * @return Boolean | 169 | * @return Boolean |
169 | */ | 170 | */ |
170 | function isCasperObject(value) { | 171 | function isCasperObject(value) { |
172 | "use strict"; | ||
171 | return value instanceof require('casper').Casper; | 173 | return value instanceof require('casper').Casper; |
172 | } | 174 | } |
173 | exports.isCasperObject = isCasperObject; | 175 | exports.isCasperObject = isCasperObject; |
... | @@ -179,6 +181,7 @@ exports.isCasperObject = isCasperObject; | ... | @@ -179,6 +181,7 @@ exports.isCasperObject = isCasperObject; |
179 | * @return Boolean | 181 | * @return Boolean |
180 | */ | 182 | */ |
181 | function isClipRect(value) { | 183 | function isClipRect(value) { |
184 | "use strict"; | ||
182 | return isType(value, "cliprect") || ( | 185 | return isType(value, "cliprect") || ( |
183 | isObject(value) && | 186 | isObject(value) && |
184 | isNumber(value.top) && isNumber(value.left) && | 187 | isNumber(value.top) && isNumber(value.left) && |
... | @@ -194,6 +197,7 @@ exports.isClipRect = isClipRect; | ... | @@ -194,6 +197,7 @@ exports.isClipRect = isClipRect; |
194 | * @return Boolean | 197 | * @return Boolean |
195 | */ | 198 | */ |
196 | function isFunction(value) { | 199 | function isFunction(value) { |
200 | "use strict"; | ||
197 | return isType(value, "function"); | 201 | return isType(value, "function"); |
198 | } | 202 | } |
199 | exports.isFunction = isFunction; | 203 | exports.isFunction = isFunction; |
... | @@ -205,6 +209,7 @@ exports.isFunction = isFunction; | ... | @@ -205,6 +209,7 @@ exports.isFunction = isFunction; |
205 | * @return Boolean | 209 | * @return Boolean |
206 | */ | 210 | */ |
207 | function isJsFile(file) { | 211 | function isJsFile(file) { |
212 | "use strict"; | ||
208 | var ext = fileExt(file); | 213 | var ext = fileExt(file); |
209 | return isString(ext, "string") && ['js', 'coffee'].indexOf(ext) !== -1; | 214 | return isString(ext, "string") && ['js', 'coffee'].indexOf(ext) !== -1; |
210 | } | 215 | } |
... | @@ -216,6 +221,7 @@ exports.isJsFile = isJsFile; | ... | @@ -216,6 +221,7 @@ exports.isJsFile = isJsFile; |
216 | * @return Boolean | 221 | * @return Boolean |
217 | */ | 222 | */ |
218 | function isNull(value) { | 223 | function isNull(value) { |
224 | "use strict"; | ||
219 | return isType(value, "null"); | 225 | return isType(value, "null"); |
220 | } | 226 | } |
221 | exports.isNull = isNull; | 227 | exports.isNull = isNull; |
... | @@ -227,6 +233,7 @@ exports.isNull = isNull; | ... | @@ -227,6 +233,7 @@ exports.isNull = isNull; |
227 | * @return Boolean | 233 | * @return Boolean |
228 | */ | 234 | */ |
229 | function isNumber(value) { | 235 | function isNumber(value) { |
236 | "use strict"; | ||
230 | return isType(value, "number"); | 237 | return isType(value, "number"); |
231 | } | 238 | } |
232 | exports.isNumber = isNumber; | 239 | exports.isNumber = isNumber; |
... | @@ -238,6 +245,7 @@ exports.isNumber = isNumber; | ... | @@ -238,6 +245,7 @@ exports.isNumber = isNumber; |
238 | * @return Boolean | 245 | * @return Boolean |
239 | */ | 246 | */ |
240 | function isObject(value) { | 247 | function isObject(value) { |
248 | "use strict"; | ||
241 | return isType(value, "object"); | 249 | return isType(value, "object"); |
242 | } | 250 | } |
243 | exports.isObject = isObject; | 251 | exports.isObject = isObject; |
... | @@ -249,6 +257,7 @@ exports.isObject = isObject; | ... | @@ -249,6 +257,7 @@ exports.isObject = isObject; |
249 | * @return Boolean | 257 | * @return Boolean |
250 | */ | 258 | */ |
251 | function isString(value) { | 259 | function isString(value) { |
260 | "use strict"; | ||
252 | return isType(value, "string"); | 261 | return isType(value, "string"); |
253 | } | 262 | } |
254 | exports.isString = isString; | 263 | exports.isString = isString; |
... | @@ -262,6 +271,7 @@ exports.isString = isString; | ... | @@ -262,6 +271,7 @@ exports.isString = isString; |
262 | * @return Boolean | 271 | * @return Boolean |
263 | */ | 272 | */ |
264 | function isType(what, typeName) { | 273 | function isType(what, typeName) { |
274 | "use strict"; | ||
265 | if (typeof typeName !== "string" || !typeName) { | 275 | if (typeof typeName !== "string" || !typeName) { |
266 | throw new CasperError("You must pass isType() a typeName string"); | 276 | throw new CasperError("You must pass isType() a typeName string"); |
267 | } | 277 | } |
... | @@ -275,6 +285,7 @@ exports.isType = isType; | ... | @@ -275,6 +285,7 @@ exports.isType = isType; |
275 | * @return Boolean | 285 | * @return Boolean |
276 | */ | 286 | */ |
277 | function isUndefined(value) { | 287 | function isUndefined(value) { |
288 | "use strict"; | ||
278 | return isType(value, "undefined"); | 289 | return isType(value, "undefined"); |
279 | } | 290 | } |
280 | exports.isUndefined = isUndefined; | 291 | exports.isUndefined = isUndefined; |
... | @@ -286,14 +297,11 @@ exports.isUndefined = isUndefined; | ... | @@ -286,14 +297,11 @@ exports.isUndefined = isUndefined; |
286 | * @return Boolean | 297 | * @return Boolean |
287 | */ | 298 | */ |
288 | function isWebPage(what) { | 299 | function isWebPage(what) { |
300 | "use strict"; | ||
289 | if (!what || !isObject(what)) { | 301 | if (!what || !isObject(what)) { |
290 | return false; | 302 | return false; |
291 | } | 303 | } |
292 | if (phantom.version.major <= 1 && phantom.version.minor < 3 && isFunction(require)) { | 304 | return what.toString().indexOf('WebPage(') === 0; |
293 | return what instanceof WebPage; | ||
294 | } else { | ||
295 | return what.toString().indexOf('WebPage(') === 0; | ||
296 | } | ||
297 | } | 305 | } |
298 | exports.isWebPage = isWebPage; | 306 | exports.isWebPage = isWebPage; |
299 | 307 | ||
... | @@ -305,6 +313,7 @@ exports.isWebPage = isWebPage; | ... | @@ -305,6 +313,7 @@ exports.isWebPage = isWebPage; |
305 | * @return Object | 313 | * @return Object |
306 | */ | 314 | */ |
307 | function mergeObjects(origin, add) { | 315 | function mergeObjects(origin, add) { |
316 | "use strict"; | ||
308 | for (var p in add) { | 317 | for (var p in add) { |
309 | try { | 318 | try { |
310 | if (add[p].constructor === Object) { | 319 | if (add[p].constructor === Object) { |
... | @@ -328,6 +337,7 @@ exports.mergeObjects = mergeObjects; | ... | @@ -328,6 +337,7 @@ exports.mergeObjects = mergeObjects; |
328 | * @return HTMLElement | 337 | * @return HTMLElement |
329 | */ | 338 | */ |
330 | function node(name, attributes) { | 339 | function node(name, attributes) { |
340 | "use strict"; | ||
331 | var _node = document.createElement(name); | 341 | var _node = document.createElement(name); |
332 | for (var attrName in attributes) { | 342 | for (var attrName in attributes) { |
333 | var value = attributes[attrName]; | 343 | var value = attributes[attrName]; |
... | @@ -346,6 +356,7 @@ exports.node = node; | ... | @@ -346,6 +356,7 @@ exports.node = node; |
346 | * @return String | 356 | * @return String |
347 | */ | 357 | */ |
348 | function serialize(value) { | 358 | function serialize(value) { |
359 | "use strict"; | ||
349 | if (isArray(value)) { | 360 | if (isArray(value)) { |
350 | value = value.map(function _map(prop) { | 361 | value = value.map(function _map(prop) { |
351 | return isFunction(prop) ? prop.toString().replace(/\s{2,}/, '') : prop; | 362 | return isFunction(prop) ? prop.toString().replace(/\s{2,}/, '') : prop; |
... | @@ -364,6 +375,7 @@ exports.serialize = serialize; | ... | @@ -364,6 +375,7 @@ exports.serialize = serialize; |
364 | * @return Array | 375 | * @return Array |
365 | */ | 376 | */ |
366 | function unique(array) { | 377 | function unique(array) { |
378 | "use strict"; | ||
367 | var o = {}, | 379 | var o = {}, |
368 | r = []; | 380 | r = []; |
369 | for (var i = 0, len = array.length; i !== len; i++) { | 381 | for (var i = 0, len = array.length; i !== len; i++) { | ... | ... |
This diff could not be displayed because it is too large.
... | @@ -28,10 +28,13 @@ | ... | @@ -28,10 +28,13 @@ |
28 | * | 28 | * |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /*global CasperError console exports phantom require*/ | ||
32 | |||
31 | var utils = require('utils'); | 33 | var utils = require('utils'); |
32 | var fs = require('fs'); | 34 | var fs = require('fs'); |
33 | 35 | ||
34 | exports.create = function create() { | 36 | exports.create = function create() { |
37 | "use strict"; | ||
35 | return new XUnitExporter(); | 38 | return new XUnitExporter(); |
36 | }; | 39 | }; |
37 | 40 | ||
... | @@ -39,12 +42,13 @@ exports.create = function create() { | ... | @@ -39,12 +42,13 @@ exports.create = function create() { |
39 | * JUnit XML (xUnit) exporter for test results. | 42 | * JUnit XML (xUnit) exporter for test results. |
40 | * | 43 | * |
41 | */ | 44 | */ |
42 | XUnitExporter = function XUnitExporter() { | 45 | function XUnitExporter() { |
46 | "use strict"; | ||
43 | this._xml = utils.node('testsuite'); | 47 | this._xml = utils.node('testsuite'); |
44 | this._xml.toString = function toString() { | 48 | this._xml.toString = function toString() { |
45 | return this.outerHTML; // ouch | 49 | return this.outerHTML; // ouch |
46 | }; | 50 | }; |
47 | }; | 51 | } |
48 | exports.XUnitExporter = XUnitExporter; | 52 | exports.XUnitExporter = XUnitExporter; |
49 | 53 | ||
50 | /** | 54 | /** |
... | @@ -54,6 +58,7 @@ exports.XUnitExporter = XUnitExporter; | ... | @@ -54,6 +58,7 @@ exports.XUnitExporter = XUnitExporter; |
54 | * @param String name | 58 | * @param String name |
55 | */ | 59 | */ |
56 | XUnitExporter.prototype.addSuccess = function addSuccess(classname, name) { | 60 | XUnitExporter.prototype.addSuccess = function addSuccess(classname, name) { |
61 | "use strict"; | ||
57 | this._xml.appendChild(utils.node('testcase', { | 62 | this._xml.appendChild(utils.node('testcase', { |
58 | classname: generateClassName(classname), | 63 | classname: generateClassName(classname), |
59 | name: name | 64 | name: name |
... | @@ -69,6 +74,7 @@ XUnitExporter.prototype.addSuccess = function addSuccess(classname, name) { | ... | @@ -69,6 +74,7 @@ XUnitExporter.prototype.addSuccess = function addSuccess(classname, name) { |
69 | * @param String type | 74 | * @param String type |
70 | */ | 75 | */ |
71 | XUnitExporter.prototype.addFailure = function addFailure(classname, name, message, type) { | 76 | XUnitExporter.prototype.addFailure = function addFailure(classname, name, message, type) { |
77 | "use strict"; | ||
72 | var fnode = utils.node('testcase', { | 78 | var fnode = utils.node('testcase', { |
73 | classname: generateClassName(classname), | 79 | classname: generateClassName(classname), |
74 | name: name | 80 | name: name |
... | @@ -91,6 +97,7 @@ XUnitExporter.prototype.addFailure = function addFailure(classname, name, messag | ... | @@ -91,6 +97,7 @@ XUnitExporter.prototype.addFailure = function addFailure(classname, name, messag |
91 | * @return String | 97 | * @return String |
92 | */ | 98 | */ |
93 | function generateClassName(classname) { | 99 | function generateClassName(classname) { |
100 | "use strict"; | ||
94 | classname = classname.replace(phantom.casperPath, "").trim(); | 101 | classname = classname.replace(phantom.casperPath, "").trim(); |
95 | var script = classname || phantom.casperScript; | 102 | var script = classname || phantom.casperScript; |
96 | if (script.indexOf(fs.workingDirectory) === 0) { | 103 | if (script.indexOf(fs.workingDirectory) === 0) { |
... | @@ -111,5 +118,6 @@ function generateClassName(classname) { | ... | @@ -111,5 +118,6 @@ function generateClassName(classname) { |
111 | * @return HTMLElement | 118 | * @return HTMLElement |
112 | */ | 119 | */ |
113 | XUnitExporter.prototype.getXML = function getXML() { | 120 | XUnitExporter.prototype.getXML = function getXML() { |
121 | "use strict"; | ||
114 | return this._xml; | 122 | return this._xml; |
115 | }; | 123 | }; | ... | ... |
-
Please register or sign in to post a comment