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
b8be54b5
...
b8be54b5c3e0c2232d5dd118fde057d1c85fa9f6
authored
2011-12-09 21:27:25 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
enhanced reusability of FunctionArgsInjector
1 parent
cbc01fc3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
5 deletions
casper.js
casper.js
View file @
b8be54b
...
...
@@ -342,7 +342,7 @@
*/
evaluate
:
function
(
fn
,
context
)
{
context
=
isType
(
context
,
"object"
)
?
context
:
{};
var
newFn
=
new
phantom
.
Casper
.
FunctionArgsInjector
(
fn
,
context
).
process
(
);
var
newFn
=
new
phantom
.
Casper
.
FunctionArgsInjector
(
fn
).
process
(
context
);
return
this
.
page
.
evaluate
(
newFn
);
},
...
...
@@ -1647,9 +1647,11 @@
* Function argument injector.
*
*/
phantom
.
Casper
.
FunctionArgsInjector
=
function
(
fn
,
values
)
{
phantom
.
Casper
.
FunctionArgsInjector
=
function
(
fn
)
{
if
(
!
isType
(
fn
,
"function"
))
{
throw
"FunctionArgsInjector() can only process functions"
;
}
this
.
fn
=
fn
;
this
.
values
=
typeof
values
===
"object"
?
values
:
{};
this
.
extract
=
function
(
fn
)
{
var
match
=
/^function
\s?(\w
+
)?\s?\((
.*
)\)\s?\{([\s\S]
*
)\}
/i
.
exec
(
fn
.
toString
().
trim
());
...
...
@@ -1667,9 +1669,12 @@
}
};
this
.
process
=
function
()
{
this
.
process
=
function
(
values
)
{
var
fnObj
=
this
.
extract
(
this
.
fn
);
var
inject
=
this
.
getArgsInjectionString
(
fnObj
.
args
,
this
.
values
);
if
(
!
isType
(
fnObj
,
"object"
))
{
throw
"Unable to process function "
+
this
.
fn
.
toString
();
}
var
inject
=
this
.
getArgsInjectionString
(
fnObj
.
args
,
values
);
return
'function '
+
(
fnObj
.
name
||
''
)
+
'(){'
+
inject
+
fnObj
.
body
+
'}'
;
};
...
...
Please
register
or
sign in
to post a comment