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
56dce225
...
56dce2253f01775fda33af14ef742048289a2ada
authored
2013-05-27 09:21:28 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix #489 - evaluate() should return a result which can be altered
1 parent
3b7575e3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
modules/casper.js
tests/suites/casper/evaluate.js
modules/casper.js
View file @
56dce22
...
...
@@ -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
)
));
};
/**
...
...
tests/suites/casper/evaluate.js
View file @
56dce22
...
...
@@ -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
();
});
});
...
...
Please
register
or
sign in
to post a comment