Commit ead6c5db ead6c5db985386523b95e5150709f61768f29107 by Nicolas Perriault

added utils.objectValues()

1 parent c6dd0e64
......@@ -608,9 +608,7 @@ Casper.prototype.evaluate = function evaluate(fn, context) {
} else if (arguments.length === 2) {
// check for closure signature if it matches context
if (utils.isObject(context) && eval(fn).length === Object.keys(context).length) {
context = Object.keys(context).map(function(arg) {
return context[arg];
});
context = utils.objectValues(context);
} else {
context = [context];
}
......@@ -619,9 +617,7 @@ Casper.prototype.evaluate = function evaluate(fn, context) {
context = [].slice.call(arguments).slice(1);
} else {
// old casperjs method signature
context = Object.keys(context).map(function(arg) {
return context[arg];
});
context = utils.objectValues(context);
}
return this.page.evaluate.apply(this.page, [fn].concat(context));
};
......
......@@ -480,6 +480,19 @@ function node(name, attributes) {
exports.node = node;
/**
* Maps an object to an array made from its values.
*
* @param Object obj
* @return Array
*/
function objectValues(obj) {
return Object.keys(obj).map(function(arg) {
return obj[arg];
});
}
exports.objectValues = objectValues;
/**
* Serializes a value using JSON.
*
* @param Mixed value
......
......@@ -255,6 +255,12 @@ t.comment('mergeObjects()');
});
})();
t.comment('objectValues()');
(function() {
t.assertEquals(utils.objectValues({}), [], 'objectValues() can extract object values');
t.assertEquals(utils.objectValues({a: 1, b: 2}), [1, 2], 'objectValues() can extract object values');
})();
t.comment('unique()');
(function() {
var testCases = [
......