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
f7ca4ea2
...
f7ca4ea2efa30a4a6560c953fd75e89e72c44de9
authored
2012-01-12 09:34:53 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixed no context was set when applying filter callbacks
1 parent
602e87f5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
3 deletions
modules/events.js
tests/suites/casper/events.js
modules/events.js
View file @
f7ca4ea
...
...
@@ -21,7 +21,9 @@
var
isArray
=
Array
.
isArray
;
function
EventEmitter
()
{
}
function
EventEmitter
()
{
this
.
_filters
=
{};
}
exports
.
EventEmitter
=
EventEmitter
;
// By default EventEmitters will print a warning if more than
...
...
@@ -221,15 +223,18 @@ EventEmitter.prototype.filter = function() {
this
.
_filters
=
{};
return
;
}
var
filter
=
this
.
_filters
[
type
];
if
(
typeof
filter
!==
'function'
)
{
return
;
}
return
filter
.
apply
(
null
,
Array
.
prototype
.
splice
.
call
(
arguments
,
1
));
return
filter
.
apply
(
this
,
Array
.
prototype
.
splice
.
call
(
arguments
,
1
));
};
EventEmitter
.
prototype
.
setFilter
=
function
(
type
,
filterFn
)
{
if
(
!
this
.
_filters
)
this
.
_filters
=
{};
if
(
!
this
.
_filters
)
{
this
.
_filters
=
{};
}
if
(
'function'
!==
typeof
filterFn
)
{
throw
new
CasperError
(
'setFilter only takes instances of Function'
);
}
...
...
tests/suites/casper/events.js
0 → 100644
View file @
f7ca4ea
// filters
casper
.
foo
=
0
;
casper
.
setFilter
(
"test"
,
function
(
a
)
{
this
.
foo
=
42
;
return
a
+
1
;
});
casper
.
test
.
assert
(
Object
.
keys
(
casper
.
_filters
).
some
(
function
(
i
)
{
return
i
===
"test"
;
}),
"setFilter() has set a filter"
);
casper
.
test
.
assertEquals
(
casper
.
filter
(
"test"
,
1
),
2
,
"filter() filters a value"
);
casper
.
test
.
assertEquals
(
casper
.
foo
,
42
,
"filter() applies the correct context"
);
delete
casper
.
foo
;
casper
.
test
.
done
();
\ No newline at end of file
Please
register
or
sign in
to post a comment