@@ -64,17 +64,72 @@ describe("wrapped built-ins", function() {
6464 } ) ;
6565 } ) ;
6666
67- it ( "should capture exceptions inside requestAnimationFrame" , function ( ) {
68- // needs to be visible or requestAnimationFrame won't ever fire
69- sandbox . style . display = "block" ;
67+ describe ( "requestAnimationFrame" , function ( ) {
68+ it ( "should capture exceptions inside callback" , function ( ) {
69+ // needs to be visible or requestAnimationFrame won't ever fire
70+ sandbox . style . display = "block" ;
7071
71- return runInSandbox ( sandbox , { manual : true } , function ( ) {
72- requestAnimationFrame ( function ( ) {
73- window . finalizeManualTest ( ) ;
74- foo ( ) ;
72+ return runInSandbox ( sandbox , { manual : true } , function ( ) {
73+ requestAnimationFrame ( function ( ) {
74+ window . finalizeManualTest ( ) ;
75+ foo ( ) ;
76+ } ) ;
77+ } ) . then ( function ( summary ) {
78+ assert . match ( summary . events [ 0 ] . exception . values [ 0 ] . value , / b a z / ) ;
79+ } ) ;
80+ } ) ;
81+
82+ it ( "wrapped callback should preserve correct context - window (not-bound)" , function ( ) {
83+ // needs to be visible or requestAnimationFrame won't ever fire
84+ sandbox . style . display = "block" ;
85+ return runInSandbox ( sandbox , { manual : true } , function ( ) {
86+ requestAnimationFrame ( function ( ) {
87+ window . capturedCtx = this ;
88+ window . finalizeManualTest ( ) ;
89+ } ) ;
90+ } ) . then ( function ( summary ) {
91+ assert . strictEqual ( summary . window . capturedCtx , summary . window ) ;
92+ delete summary . window . capturedCtx ;
93+ } ) ;
94+ } ) ;
95+
96+ it ( "wrapped callback should preserve correct context - class bound method" , function ( ) {
97+ // needs to be visible or requestAnimationFrame won't ever fire
98+ sandbox . style . display = "block" ;
99+ return runInSandbox ( sandbox , { manual : true } , function ( ) {
100+ // TypeScript-transpiled class syntax
101+ var Foo = ( function ( ) {
102+ function Foo ( ) {
103+ var _this = this ;
104+ this . magicNumber = 42 ;
105+ this . getThis = function ( ) {
106+ window . capturedCtx = _this ;
107+ window . finalizeManualTest ( ) ;
108+ } ;
109+ }
110+ return Foo ;
111+ } ) ( ) ;
112+ var foo = new Foo ( ) ;
113+ requestAnimationFrame ( foo . getThis ) ;
114+ } ) . then ( function ( summary ) {
115+ assert . strictEqual ( summary . window . capturedCtx . magicNumber , 42 ) ;
116+ delete summary . window . capturedCtx ;
117+ } ) ;
118+ } ) ;
119+
120+ it ( "wrapped callback should preserve correct context - `bind` bound method" , function ( ) {
121+ // needs to be visible or requestAnimationFrame won't ever fire
122+ sandbox . style . display = "block" ;
123+ return runInSandbox ( sandbox , { manual : true } , function ( ) {
124+ function foo ( ) {
125+ window . capturedCtx = this ;
126+ window . finalizeManualTest ( ) ;
127+ }
128+ requestAnimationFrame ( foo . bind ( { magicNumber : 42 } ) ) ;
129+ } ) . then ( function ( summary ) {
130+ assert . strictEqual ( summary . window . capturedCtx . magicNumber , 42 ) ;
131+ delete summary . window . capturedCtx ;
75132 } ) ;
76- } ) . then ( function ( summary ) {
77- assert . match ( summary . events [ 0 ] . exception . values [ 0 ] . value , / b a z / ) ;
78133 } ) ;
79134 } ) ;
80135
0 commit comments