This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree 2 files changed +52
-2
lines changed
2 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -324,6 +324,42 @@ describe('Zone.patch', function () {
324
324
325
325
} ) ;
326
326
327
+ describe ( 'MutationObserver' , function ( ) {
328
+ it ( 'should work' , function ( ) {
329
+ if ( ! window . MutationObserver ) {
330
+ console . log ( 'WARNING: skipping MutationObserver test (missing this API)' ) ;
331
+ return ;
332
+ }
333
+
334
+ var flag = false ,
335
+ elt = document . createElement ( 'div' ) ,
336
+ hasParent ;
337
+
338
+ runs ( function ( ) {
339
+ var ob = new MutationObserver ( function ( ) {
340
+ hasParent = ! ! window . zone . parent ;
341
+ dump ( 'yo' )
342
+ flag = true ;
343
+ } ) ;
344
+
345
+ ob . observe ( elt , {
346
+ childList : true
347
+ } ) ;
348
+
349
+ elt . innerHTML = '<p>hey</p>' ;
350
+ } ) ;
351
+
352
+ waitsFor ( function ( ) {
353
+ return flag ;
354
+ } , 'promise to resolve' , 100 ) ;
355
+
356
+ runs ( function ( ) {
357
+ expect ( hasParent ) . toBe ( true ) ;
358
+ } ) ;
359
+
360
+ } ) ;
361
+ } ) ;
362
+
327
363
describe ( 'XMLHttpRequest' , function ( ) {
328
364
329
365
it ( 'should work with onreadystatechange' , function ( ) {
Original file line number Diff line number Diff line change @@ -267,6 +267,9 @@ Zone.patch = function patch () {
267
267
'catch'
268
268
] ) ;
269
269
}
270
+ if ( window . MutationObserver ) {
271
+ Zone . patchClass ( 'MutationObserver' ) ;
272
+ }
270
273
} ;
271
274
272
275
//
@@ -315,11 +318,22 @@ Zone.patchViaCapturingAllTheEvents = function () {
315
318
// TODO: wrap some native API
316
319
Zone . patchClass = function ( className ) {
317
320
var OriginalClass = window [ className ] ;
321
+ if ( ! OriginalClass ) {
322
+ return ;
323
+ }
318
324
window [ className ] = function ( ) {
319
- this . _o = new OriginalClass ( ) ;
325
+ var a = Zone . bindArguments ( arguments ) ;
326
+ switch ( a . length ) {
327
+ case 0 : this . _o = new OriginalClass ( ) ; break ;
328
+ case 1 : this . _o = new OriginalClass ( a [ 0 ] ) ; break ;
329
+ case 2 : this . _o = new OriginalClass ( a [ 0 ] , a [ 1 ] ) ; break ;
330
+ case 3 : this . _o = new OriginalClass ( a [ 0 ] , a [ 1 ] , a [ 2 ] ) ; break ;
331
+ case 4 : this . _o = new OriginalClass ( a [ 0 ] , a [ 1 ] , a [ 2 ] , a [ 3 ] ) ; break ;
332
+ default : throw new Error ( 'what are you even doing?' ) ;
333
+ }
320
334
} ;
321
335
322
- var instance = ( new OriginalClass ( ) ) ;
336
+ var instance = new OriginalClass ( className === 'MutationObserver' ? function ( ) { } : undefined ) ;
323
337
324
338
var prop ;
325
339
for ( prop in instance ) {
You can’t perform that action at this time.
0 commit comments