Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
ead6c5db
...
ead6c5db985386523b95e5150709f61768f29107
authored
2012-11-22 10:53:59 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added utils.objectValues()
1 parent
c6dd0e64
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
6 deletions
modules/casper.js
modules/utils.js
tests/suites/utils.js
modules/casper.js
View file @
ead6c5d
...
...
@@ -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
));
};
...
...
modules/utils.js
View file @
ead6c5d
...
...
@@ -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
...
...
tests/suites/utils.js
View file @
ead6c5d
...
...
@@ -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
=
[
...
...
Please
register
or
sign in
to post a comment