@@ -368,6 +368,7 @@ Zone.patch = function patch () {
368
368
}
369
369
Zone . patchMutationObserverClass ( 'MutationObserver' ) ;
370
370
Zone . patchMutationObserverClass ( 'WebKitMutationObserver' ) ;
371
+ Zone . patchDefineProperty ( ) ;
371
372
Zone . patchRegisterElement ( ) ;
372
373
} ;
373
374
@@ -512,6 +513,49 @@ Zone.patchMutationObserverClass = function (className) {
512
513
}
513
514
} ;
514
515
516
+ // might need similar for object.freeze
517
+ // i regret nothing
518
+ Zone . patchDefineProperty = function ( ) {
519
+ var _defineProperty = Object . defineProperty ;
520
+ var _getOwnPropertyDescriptor = Object . getOwnPropertyDescriptor ;
521
+
522
+ Object . defineProperty = function ( obj , prop , desc ) {
523
+ if ( isUnconfigurable ( obj , prop ) ) {
524
+ throw new TypeError ( 'Cannot assign to read only property \'' + prop + '\' of ' + obj ) ;
525
+ }
526
+ return rewriteDescriptor ( obj , prop , desc ) ;
527
+ } ;
528
+
529
+ Object . getOwnPropertyDescriptor = function ( obj , prop ) {
530
+ var desc = _getOwnPropertyDescriptor ( obj , prop ) ;
531
+ if ( isUnconfigurable ( obj , prop ) ) {
532
+ desc . configurable = false ;
533
+ }
534
+ return desc ;
535
+ } ;
536
+
537
+ Zone . _redefineProperty = function ( obj , prop , desc ) {
538
+ return rewriteDescriptor ( obj , prop , desc ) ;
539
+ } ;
540
+
541
+ function isUnconfigurable ( obj , prop ) {
542
+ return obj && obj . __unconfigurables && obj . __unconfigurables [ prop ] ;
543
+ }
544
+
545
+ function rewriteDescriptor ( obj , prop , desc ) {
546
+ if ( ! desc . configurable ) {
547
+ desc . configurable = true ;
548
+ if ( ! obj . __unconfigurables ) {
549
+ _defineProperty ( obj , '__unconfigurables' , {
550
+ value : { }
551
+ } ) ;
552
+ }
553
+ obj . __unconfigurables [ prop ] = true ;
554
+ }
555
+ return _defineProperty ( obj , prop , desc ) ;
556
+ }
557
+ } ;
558
+
515
559
Zone . patchRegisterElement = function ( ) {
516
560
if ( ! ( 'registerElement' in document ) ) {
517
561
return ;
@@ -526,7 +570,11 @@ Zone.patchRegisterElement = function () {
526
570
document . registerElement = function ( name , opts ) {
527
571
callbacks . forEach ( function ( callback ) {
528
572
if ( opts . prototype [ callback ] ) {
529
- opts . prototype [ callback ] = zone . bind ( opts . prototype [ callback ] ) ;
573
+ var descriptor = Object . getOwnPropertyDescriptor ( opts . prototype , callback ) ;
574
+ if ( descriptor . value ) {
575
+ descriptor . value = zone . bind ( descriptor . value ) ;
576
+ Zone . _redefineProperty ( opts . prototype , callback , descriptor ) ;
577
+ }
530
578
}
531
579
} ) ;
532
580
return _registerElement . apply ( document , [ name , opts ] ) ;
0 commit comments