@@ -70,38 +70,71 @@ export function migrateInfo( code, msg ) {
7070 migrateMessageInternal ( code , msg , "info" ) ;
7171}
7272
73- function migrateMessagePropInternal (
73+ function migratePatchPropInternal (
7474 obj , prop , value , code , msg , migrateMessageFn
7575) {
76+ var orig = obj [ prop ] ;
7677 Object . defineProperty ( obj , prop , {
7778 configurable : true ,
7879 enumerable : true ,
80+
7981 get : function ( ) {
80- migrateMessageFn ( code , msg ) ;
81- return value ;
82+ if ( jQuery . migrateIsPatchEnabled ( code ) ) {
83+
84+ // If `msg` not provided, do not message; more sophisticated
85+ // messaging logic is most likely embedded in `value`.
86+ if ( msg ) {
87+ migrateMessageFn ( code , msg ) ;
88+ }
89+
90+ return value ;
91+ }
92+
93+ return orig ;
8294 } ,
95+
8396 set : function ( newValue ) {
84- migrateMessageFn ( code , msg ) ;
85- value = newValue ;
97+ if ( jQuery . migrateIsPatchEnabled ( code ) ) {
98+
99+ // See the comment in the getter.
100+ if ( msg ) {
101+ migrateMessageFn ( code , msg ) ;
102+ }
103+ }
104+
105+ // If a new value was set, apply it regardless if
106+ // the patch is later disabled or not.
107+ orig = value = newValue ;
86108 }
87109 } ) ;
88110}
89111
90112export function migrateWarnProp ( obj , prop , value , code , msg ) {
91- migrateMessagePropInternal ( obj , prop , value , code , msg , migrateWarn ) ;
113+ if ( ! msg ) {
114+ throw new Error ( "No warning message provided" ) ;
115+ }
116+ migratePatchPropInternal ( obj , prop , value , code , msg , migrateWarn ) ;
92117}
93118
94119export function migrateInfoProp ( obj , prop , value , code , msg ) {
95- migrateMessagePropInternal ( obj , prop , value , code , msg , migrateInfo ) ;
120+ if ( ! msg ) {
121+ throw new Error ( "No warning message provided" ) ;
122+ }
123+ migratePatchPropInternal ( obj , prop , value , code , msg , migrateInfo ) ;
124+ }
125+
126+ export function migratePatchProp ( obj , prop , value , code ) {
127+ migratePatchPropInternal ( obj , prop , value , code ) ;
96128}
97129
98- function migrateMessageFuncInternal (
130+ // The value of the "Func" APIs is that for method we want to allow
131+ // checking for the method existence without triggering a warning.
132+ // For other deprecated properties, we do need to warn on access.
133+ function migratePatchFuncInternal (
99134 obj , prop , newFunc , code , msg , migrateMessageFn
100135) {
101- var finalFunc ,
102- origFunc = obj [ prop ] ;
103136
104- obj [ prop ] = function ( ) {
137+ function wrappedNewFunc ( ) {
105138
106139 // If `msg` not provided, do not warn; more sophisticated warnings
107140 // logic is most likely embedded in `newFunc`, in that case here
@@ -111,34 +144,28 @@ function migrateMessageFuncInternal(
111144 migrateMessageFn ( code , msg ) ;
112145 }
113146
114- // Since patches can be disabled & enabled dynamically, we
115- // need to decide which implementation to run on each invocation.
116- finalFunc = jQuery . migrateIsPatchEnabled ( code ) ?
117- newFunc :
118-
119- // The function may not have existed originally so we need a fallback.
120- ( origFunc || jQuery . noop ) ;
147+ return newFunc . apply ( this , arguments ) ;
148+ }
121149
122- return finalFunc . apply ( this , arguments ) ;
123- } ;
150+ migratePatchPropInternal ( obj , prop , wrappedNewFunc , code ) ;
124151}
125152
126153export function migratePatchAndWarnFunc ( obj , prop , newFunc , code , msg ) {
127154 if ( ! msg ) {
128155 throw new Error ( "No warning message provided" ) ;
129156 }
130- return migrateMessageFuncInternal ( obj , prop , newFunc , code , msg , migrateWarn ) ;
157+ return migratePatchFuncInternal ( obj , prop , newFunc , code , msg , migrateWarn ) ;
131158}
132159
133160export function migratePatchAndInfoFunc ( obj , prop , newFunc , code , msg ) {
134161 if ( ! msg ) {
135162 throw new Error ( "No info message provided" ) ;
136163 }
137- return migrateMessageFuncInternal ( obj , prop , newFunc , code , msg , migrateInfo ) ;
164+ return migratePatchFuncInternal ( obj , prop , newFunc , code , msg , migrateInfo ) ;
138165}
139166
140167export function migratePatchFunc ( obj , prop , newFunc , code ) {
141- return migrateMessageFuncInternal ( obj , prop , newFunc , code ) ;
168+ return migratePatchFuncInternal ( obj , prop , newFunc , code ) ;
142169}
143170
144171if ( window . document . compatMode === "BackCompat" ) {
0 commit comments