Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 79a37c0

Browse files
committed
fix(RequestAnimationFrame): pass the timestamp to the callback
fixes #187
1 parent 7ea2ab5 commit 79a37c0

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/patch/functions.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function patchRequestAnimationFrame(obj, fnNames) {
6262
var callZone = global.zone.isRootZone() ? global.zone.fork() : global.zone;
6363
if (fn) {
6464
arguments[0] = function () {
65-
return callZone.run(fn, arguments);
65+
return callZone.run(fn, this, arguments);
6666
};
6767
}
6868
return delegate.apply(obj, arguments);
@@ -81,9 +81,8 @@ function patchSetFunction(obj, fnNames) {
8181

8282
if (delegate) {
8383
global.zone[name] = function (fn) {
84-
var fnRef = fn;
8584
arguments[0] = function () {
86-
return fnRef.apply(this, arguments);
85+
return fn.apply(this, arguments);
8786
};
8887
var args = utils.bindArgumentsOnce(arguments);
8988
return delegate.apply(obj, args);

test/patch/requestAnimationFrame.spec.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ describe('requestAnimationFrame', function () {
2626
it('should bind to same zone when called recursively', function (done) {
2727
testZone.run(function () {
2828
var frames = 0;
29+
var previousTimeStamp = 0;
30+
31+
function frameCallback(timestamp) {
32+
expect(zone).toBe(testZone);
33+
34+
expect(timestamp).toMatch(/^[\d.]+$/);
35+
// expect previous <= current
36+
expect(previousTimeStamp).not.toBeGreaterThan(timestamp);
37+
previousTimeStamp = timestamp;
2938

30-
function frameCallback() {
31-
expect(zone === testZone).toBe(true);
3239
if (frames++ > 15) {
3340
return done();
3441
}

0 commit comments

Comments
 (0)