Skip to content

Commit

Permalink
fix(RequestAnimationFrame): pass the timestamp to the callback
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Sep 29, 2015
1 parent 7ea2ab5 commit 79a37c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/patch/functions.js
Expand Up @@ -62,7 +62,7 @@ function patchRequestAnimationFrame(obj, fnNames) {
var callZone = global.zone.isRootZone() ? global.zone.fork() : global.zone;
if (fn) {
arguments[0] = function () {
return callZone.run(fn, arguments);
return callZone.run(fn, this, arguments);
};
}
return delegate.apply(obj, arguments);
Expand All @@ -81,9 +81,8 @@ function patchSetFunction(obj, fnNames) {

if (delegate) {
global.zone[name] = function (fn) {
var fnRef = fn;
arguments[0] = function () {
return fnRef.apply(this, arguments);
return fn.apply(this, arguments);
};
var args = utils.bindArgumentsOnce(arguments);
return delegate.apply(obj, args);
Expand Down
11 changes: 9 additions & 2 deletions test/patch/requestAnimationFrame.spec.js
Expand Up @@ -26,9 +26,16 @@ describe('requestAnimationFrame', function () {
it('should bind to same zone when called recursively', function (done) {
testZone.run(function () {
var frames = 0;
var previousTimeStamp = 0;

function frameCallback(timestamp) {
expect(zone).toBe(testZone);

expect(timestamp).toMatch(/^[\d.]+$/);
// expect previous <= current
expect(previousTimeStamp).not.toBeGreaterThan(timestamp);
previousTimeStamp = timestamp;

function frameCallback() {
expect(zone === testZone).toBe(true);
if (frames++ > 15) {
return done();
}
Expand Down

0 comments on commit 79a37c0

Please sign in to comment.