Commit 05250d2e 05250d2edcd9d6e7107d52fbea8de4bc28bf9c4b by Laurent Jouanneau

refs #482: sync with master

2 parents c1946343 e664bdd4
......@@ -28,11 +28,17 @@
*
*/
/*global console, phantom, require:true*/
/*global process, console, phantom, require:true*/
/*jshint maxstatements:33, maxcomplexity:10*/
// node check
if ('process' in this && process.title === "node") {
console.error('CasperJS cannot be executed within a nodejs environment');
process.exit(1);
}
// phantom check
if (!phantom) {
if (!('phantom' in this)) {
console.error('CasperJS needs to be executed in a PhantomJS environment http://phantomjs.org/');
}
......
......@@ -667,7 +667,7 @@ Casper.prototype.evaluate = function evaluate(fn, context) {
this.injectClientUtils();
// function context
if (arguments.length === 1) {
return this.page.evaluate(fn);
return utils.clone(this.page.evaluate(fn));
} else if (arguments.length === 2) {
// check for closure signature if it matches context
if (utils.isObject(context) && eval(fn).length === Object.keys(context).length) {
......@@ -679,7 +679,7 @@ Casper.prototype.evaluate = function evaluate(fn, context) {
// phantomjs-style signature
context = [].slice.call(arguments).slice(1);
}
return this.page.evaluate.apply(this.page, [fn].concat(context));
return utils.clone(this.page.evaluate.apply(this.page, [fn].concat(context)));
};
/**
......
......@@ -33,6 +33,7 @@
var require = patchRequire(require);
var fs = require('fs');
var utils = require('utils');
var env = require('system').env;
exports.create = function create(type) {
"use strict";
......@@ -79,7 +80,7 @@ var Colorizer = function Colorizer() {
* @return String
*/
this.colorize = function colorize(text, styleName, pad) {
if (fs.isWindows() || !(styleName in styles)) {
if ((fs.isWindows() && !env['ANSICON']) || !(styleName in styles)) {
return text;
}
return this.format(text, styles[styleName], pad);
......@@ -93,7 +94,7 @@ var Colorizer = function Colorizer() {
* @return String
*/
this.format = function format(text, style, pad) {
if (fs.isWindows() || !utils.isObject(style)) {
if ((fs.isWindows() && !env['ANSICON']) || !utils.isObject(style)) {
return text;
}
var codes = [];
......
......@@ -40,7 +40,7 @@ casper.echo("Let the match begin between \"" + (terms.join('", "')) + "\"!");
casper.start("http://google.fr/");
casper.each(terms, function(casper, term, i) {
this.echo('Fecthing score for ' + term);
this.echo('Fetching score for ' + term);
this.then(function() {
this.fill('form[action="/search"]', {q: term}, true);
});
......
......@@ -90,3 +90,23 @@ casper.test.begin('thenEvaluate() tests', 2, function(test) {
test.done();
});
});
// https://github.com/n1k0/casperjs/issues/489
// https://groups.google.com/forum/?fromgroups=#!topic/casperjs/95IgDMFnEKM
casper.test.begin("evaluate() returns a value which can be altered", 1, function(test) {
var list;
casper.start().then(function() {
list = this.evaluate(function() {
return [{a: 1}, {b: 2}];
});
var first = list[0];
first.a = 42;
test.assertEquals(list, [{a: 42}, {b: 2}],
'evaluate() returns a cloned value which can be altered');
});
casper.run(function() {
test.done();
});
});
......