Commit 169aca86 169aca86ed1c9b0084b970ae28262f633de68025 by Nicolas Perriault

closes #145 - use of javascript strict mode for modules

1 parent c3f3748d
......@@ -9,6 +9,7 @@ XXXX-XX-XX, v0.6.11
- 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.**
- added [`Casper.userAgent()`](http://casperjs.org/api.html#casper.userAgent) to ease a more dynamic setting of user-agent string
- switched to more standard `.textContent` property to get a node text; this allows a better compatibility of the clientutils bookmarklet with non-webkit browsers
- casper modules now all use [javascript strict mode](http://www.nczonline.net/blog/2012/03/13/its-time-to-start-using-javascript-strict-mode/)
2012-06-04, v0.6.10
-------------------
......
Subproject commit de42a4e8a5aaa3906a26ae89b12d73c3a082f8c7
Subproject commit 23bd43286ab953b7c4b3fa74aeee1216320ae308
......
......@@ -28,6 +28,8 @@
*
*/
/*global CasperError console exports phantom require*/
var utils = require('utils');
/**
......@@ -38,6 +40,7 @@ var utils = require('utils');
* @return Object
*/
exports.parse = function parse(phantomArgs) {
"use strict";
var extract = {
args: [],
options: {},
......@@ -110,6 +113,7 @@ exports.parse = function parse(phantomArgs) {
* @return Mixed
*/
function castArgument(arg) {
"use strict";
if (arg.match(/^-?\d+$/)) {
return parseInt(arg, 10);
} else if (arg.match(/^-?\d+\.\d+$/)) {
......
......@@ -27,7 +27,12 @@
* DEALINGS IN THE SOFTWARE.
*
*/
/*global console escape exports NodeList window*/
(function(exports) {
"use strict";
exports.create = function create(options) {
return new this.ClientUtils(options);
};
......@@ -466,7 +471,7 @@
* @param mixed value The field value to set
*/
this.setField = function setField(field, value) {
var fields, out;
var logValue, fields, out;
value = logValue = (value || "");
if (field instanceof NodeList) {
fields = field;
......@@ -477,7 +482,7 @@
}
if (this.options && this.options.safeLogs && field.getAttribute('type') === "password") {
// obfuscate password value
logValue = Array(value.length + 1).join("*");
logValue = new Array(value.length + 1).join("*");
}
this.log('Set "' + field.getAttribute('name') + '" field value to ' + logValue, "debug");
try {
......
......@@ -28,10 +28,13 @@
*
*/
/*global exports console require*/
var fs = require('fs');
var utils = require('utils');
exports.create = function create(type) {
"use strict";
if (!type) {
return;
}
......@@ -48,6 +51,7 @@ exports.create = function create(type) {
* (c) Fabien Potencier, Symfony project, MIT license
*/
var Colorizer = function Colorizer() {
"use strict";
var options = { bold: 1, underscore: 4, blink: 5, reverse: 7, conceal: 8 };
var foreground = { black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37 };
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() {
if (typeof pad === "number" && text.length < pad) {
text += new Array(pad - text.length + 1).join(' ');
}
return "\033[" + codes.join(';') + 'm' + text + "\033[0m";
return "\u001b[" + codes.join(';') + 'm' + text + "\u001b[0m";
};
};
exports.Colorizer = Colorizer;
......@@ -114,6 +118,7 @@ exports.Colorizer = Colorizer;
*
*/
var Dummy = function Dummy() {
"use strict";
this.colorize = function colorize(text, styleName, pad) {
return text;
};
......
......@@ -28,9 +28,12 @@
*
*/
/*global CasperError console encodeURIComponent escape exports require*/
var utils = require('utils');
exports.create = function create(fn) {
"use strict";
return new FunctionArgsInjector(fn);
};
......@@ -40,6 +43,7 @@ exports.create = function create(fn) {
* FIXME: use new Function() instead of eval()
*/
var FunctionArgsInjector = function FunctionArgsInjector(fn) {
"use strict";
if (!utils.isFunction(fn)) {
throw new CasperError("FunctionArgsInjector() can only process functions");
}
......
......@@ -28,13 +28,17 @@
*
*/
/*global CasperError exports require*/
var utils = require('utils');
exports.create = function create(casper) {
"use strict";
return new Mouse(casper);
};
var Mouse = function Mouse(casper) {
"use strict";
if (!utils.isCasperObject(casper)) {
throw new CasperError('Mouse() needs a Casper instance');
}
......
......@@ -28,12 +28,15 @@
*
*/
/*global CasperError exports phantom require*/
var fs = require('fs');
var events = require('events');
var utils = require('utils');
var f = utils.format;
exports.create = function create(casper, options) {
"use strict";
return new Tester(casper, options);
};
......@@ -44,6 +47,7 @@ exports.create = function create(casper, options) {
* @param Object|null options Options object
*/
var Tester = function Tester(casper, options) {
"use strict";
if (!utils.isCasperObject(casper)) {
throw new CasperError("Tester needs a Casper instance");
}
......
......@@ -28,6 +28,8 @@
*
*/
/*global CasperError console exports phantom require*/
/**
* Provides a better typeof operator equivalent, able to retrieve the array
* type.
......@@ -37,6 +39,7 @@
* @see http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
*/
function betterTypeOf(input) {
"use strict";
try {
return Object.prototype.toString.call(input).match(/^\[object\s(.*)\]$/)[1].toLowerCase();
} catch (e) {
......@@ -52,6 +55,7 @@ exports.betterTypeOf = betterTypeOf;
* @param Mixed value
*/
function dump(value) {
"use strict";
console.log(serialize(value));
}
exports.dump = dump;
......@@ -63,6 +67,7 @@ exports.dump = dump;
* @return string
*/
function fileExt(file) {
"use strict";
try {
return file.split('.').pop().toLowerCase().trim();
} catch(e) {
......@@ -79,6 +84,7 @@ exports.fileExt = fileExt;
* @return String
*/
function fillBlanks(text, pad) {
"use strict";
pad = pad || 80;
if (text.length < pad) {
text += new Array(pad - text.length + 1).join(' ');
......@@ -93,15 +99,8 @@ exports.fillBlanks = fillBlanks;
* @return String
*/
function format(f) {
var i;
if (typeof f !== 'string') {
var objects = [];
for (i = 0; i < arguments.length; i++) {
objects.push(inspect(arguments[i]));
}
return objects.join(' ');
}
i = 1;
"use strict";
var i = 1;
var args = arguments;
var len = args.length;
var str = String(f).replace(/%[sdj%]/g, function _replace(x) {
......@@ -123,7 +122,7 @@ function format(f) {
if (x === null || typeof x !== 'object') {
str += ' ' + x;
} else {
str += ' ' + inspect(x);
str += '[obj]';
}
}
return str;
......@@ -138,6 +137,7 @@ exports.format = format;
* @param {function} superCtor Constructor function to inherit prototype from.
*/
function inherits(ctor, superCtor) {
"use strict";
ctor.super_ = ctor.__super__ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
......@@ -157,6 +157,7 @@ exports.inherits = inherits;
* @return Boolean
*/
function isArray(value) {
"use strict";
return Array.isArray(value) || isType(value, "array");
}
exports.isArray = isArray;
......@@ -168,6 +169,7 @@ exports.isArray = isArray;
* @return Boolean
*/
function isCasperObject(value) {
"use strict";
return value instanceof require('casper').Casper;
}
exports.isCasperObject = isCasperObject;
......@@ -179,6 +181,7 @@ exports.isCasperObject = isCasperObject;
* @return Boolean
*/
function isClipRect(value) {
"use strict";
return isType(value, "cliprect") || (
isObject(value) &&
isNumber(value.top) && isNumber(value.left) &&
......@@ -194,6 +197,7 @@ exports.isClipRect = isClipRect;
* @return Boolean
*/
function isFunction(value) {
"use strict";
return isType(value, "function");
}
exports.isFunction = isFunction;
......@@ -205,6 +209,7 @@ exports.isFunction = isFunction;
* @return Boolean
*/
function isJsFile(file) {
"use strict";
var ext = fileExt(file);
return isString(ext, "string") && ['js', 'coffee'].indexOf(ext) !== -1;
}
......@@ -216,6 +221,7 @@ exports.isJsFile = isJsFile;
* @return Boolean
*/
function isNull(value) {
"use strict";
return isType(value, "null");
}
exports.isNull = isNull;
......@@ -227,6 +233,7 @@ exports.isNull = isNull;
* @return Boolean
*/
function isNumber(value) {
"use strict";
return isType(value, "number");
}
exports.isNumber = isNumber;
......@@ -238,6 +245,7 @@ exports.isNumber = isNumber;
* @return Boolean
*/
function isObject(value) {
"use strict";
return isType(value, "object");
}
exports.isObject = isObject;
......@@ -249,6 +257,7 @@ exports.isObject = isObject;
* @return Boolean
*/
function isString(value) {
"use strict";
return isType(value, "string");
}
exports.isString = isString;
......@@ -262,6 +271,7 @@ exports.isString = isString;
* @return Boolean
*/
function isType(what, typeName) {
"use strict";
if (typeof typeName !== "string" || !typeName) {
throw new CasperError("You must pass isType() a typeName string");
}
......@@ -275,6 +285,7 @@ exports.isType = isType;
* @return Boolean
*/
function isUndefined(value) {
"use strict";
return isType(value, "undefined");
}
exports.isUndefined = isUndefined;
......@@ -286,14 +297,11 @@ exports.isUndefined = isUndefined;
* @return Boolean
*/
function isWebPage(what) {
"use strict";
if (!what || !isObject(what)) {
return false;
}
if (phantom.version.major <= 1 && phantom.version.minor < 3 && isFunction(require)) {
return what instanceof WebPage;
} else {
return what.toString().indexOf('WebPage(') === 0;
}
return what.toString().indexOf('WebPage(') === 0;
}
exports.isWebPage = isWebPage;
......@@ -305,6 +313,7 @@ exports.isWebPage = isWebPage;
* @return Object
*/
function mergeObjects(origin, add) {
"use strict";
for (var p in add) {
try {
if (add[p].constructor === Object) {
......@@ -328,6 +337,7 @@ exports.mergeObjects = mergeObjects;
* @return HTMLElement
*/
function node(name, attributes) {
"use strict";
var _node = document.createElement(name);
for (var attrName in attributes) {
var value = attributes[attrName];
......@@ -346,6 +356,7 @@ exports.node = node;
* @return String
*/
function serialize(value) {
"use strict";
if (isArray(value)) {
value = value.map(function _map(prop) {
return isFunction(prop) ? prop.toString().replace(/\s{2,}/, '') : prop;
......@@ -364,6 +375,7 @@ exports.serialize = serialize;
* @return Array
*/
function unique(array) {
"use strict";
var o = {},
r = [];
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 @@
*
*/
/*global CasperError console exports phantom require*/
var utils = require('utils');
var fs = require('fs');
exports.create = function create() {
"use strict";
return new XUnitExporter();
};
......@@ -39,12 +42,13 @@ exports.create = function create() {
* JUnit XML (xUnit) exporter for test results.
*
*/
XUnitExporter = function XUnitExporter() {
function XUnitExporter() {
"use strict";
this._xml = utils.node('testsuite');
this._xml.toString = function toString() {
return this.outerHTML; // ouch
};
};
}
exports.XUnitExporter = XUnitExporter;
/**
......@@ -54,6 +58,7 @@ exports.XUnitExporter = XUnitExporter;
* @param String name
*/
XUnitExporter.prototype.addSuccess = function addSuccess(classname, name) {
"use strict";
this._xml.appendChild(utils.node('testcase', {
classname: generateClassName(classname),
name: name
......@@ -69,6 +74,7 @@ XUnitExporter.prototype.addSuccess = function addSuccess(classname, name) {
* @param String type
*/
XUnitExporter.prototype.addFailure = function addFailure(classname, name, message, type) {
"use strict";
var fnode = utils.node('testcase', {
classname: generateClassName(classname),
name: name
......@@ -91,6 +97,7 @@ XUnitExporter.prototype.addFailure = function addFailure(classname, name, messag
* @return String
*/
function generateClassName(classname) {
"use strict";
classname = classname.replace(phantom.casperPath, "").trim();
var script = classname || phantom.casperScript;
if (script.indexOf(fs.workingDirectory) === 0) {
......@@ -111,5 +118,6 @@ function generateClassName(classname) {
* @return HTMLElement
*/
XUnitExporter.prototype.getXML = function getXML() {
"use strict";
return this._xml;
};
......