@@ -4,12 +4,19 @@ globalThis.isNonMonkeyPatchableClass = function(ctor, makeInstance) {
44 const existing = ctor . prototype ;
55
66 try {
7- ctor . prototype = { } ;
7+ try {
8+ ctor . prototype = { } ;
9+ } catch ( e ) {
10+ expect ( e ) . toBeInstanceOf ( TypeError ) ;
11+ }
12+
813 expect ( ctor . prototype ) . toBe ( existing ) ;
914 } finally {
1015 // This will be a no-op if the test passed, but will prevent state
1116 // leakage if it failed.
12- ctor . prototype = existing ;
17+ if ( ctor . prototype !== existing ) {
18+ ctor . prototype = existing ;
19+ }
1320 }
1421 } ) ;
1522
@@ -35,14 +42,21 @@ globalThis.isNonMonkeyPatchableClass = function(ctor, makeInstance) {
3542 const existingValue = ctor . prototype [ k ] ;
3643
3744 try {
38- ctor . prototype [ k ] = { } ;
45+ try {
46+ ctor . prototype [ k ] = { } ;
47+ } catch ( e ) {
48+ expect ( e ) . toBeInstanceOf ( TypeError ) ;
49+ }
50+
3951 expect ( ctor . prototype [ k ] )
4052 . withContext ( k )
4153 . toBe ( existingValue ) ;
4254 } finally {
4355 // This will be a no-op if the test passed, but will prevent state
4456 // leakage if it failed.
45- ctor . prototype [ k ] = existingValue ;
57+ if ( ctor . prototype [ k ] !== existingValue ) {
58+ ctor . prototype [ k ] = existingValue ;
59+ }
4660 }
4761 }
4862
@@ -55,7 +69,13 @@ globalThis.isNonMonkeyPatchableClass = function(ctor, makeInstance) {
5569
5670 for ( const k of Object . getOwnPropertyNames ( ctor . prototype ) ) {
5771 any = true ;
58- instance [ k ] = { } ;
72+
73+ try {
74+ instance [ k ] = { } ;
75+ } catch ( e ) {
76+ expect ( e ) . toBeInstanceOf ( TypeError ) ;
77+ }
78+
5979 expect ( instance [ k ] )
6080 . withContext ( k )
6181 . toBe ( ctor . prototype [ k ] ) ;
0 commit comments