@@ -70,38 +70,71 @@ export function migrateInfo( code, msg ) {
70
70
migrateMessageInternal ( code , msg , "info" ) ;
71
71
}
72
72
73
- function migrateMessagePropInternal (
73
+ function migratePatchPropInternal (
74
74
obj , prop , value , code , msg , migrateMessageFn
75
75
) {
76
+ var orig = obj [ prop ] ;
76
77
Object . defineProperty ( obj , prop , {
77
78
configurable : true ,
78
79
enumerable : true ,
80
+
79
81
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 ;
82
94
} ,
95
+
83
96
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 ;
86
108
}
87
109
} ) ;
88
110
}
89
111
90
112
export 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 ) ;
92
117
}
93
118
94
119
export 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 ) ;
96
128
}
97
129
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 (
99
134
obj , prop , newFunc , code , msg , migrateMessageFn
100
135
) {
101
- var finalFunc ,
102
- origFunc = obj [ prop ] ;
103
136
104
- obj [ prop ] = function ( ) {
137
+ function wrappedNewFunc ( ) {
105
138
106
139
// If `msg` not provided, do not warn; more sophisticated warnings
107
140
// logic is most likely embedded in `newFunc`, in that case here
@@ -111,34 +144,28 @@ function migrateMessageFuncInternal(
111
144
migrateMessageFn ( code , msg ) ;
112
145
}
113
146
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
+ }
121
149
122
- return finalFunc . apply ( this , arguments ) ;
123
- } ;
150
+ migratePatchPropInternal ( obj , prop , wrappedNewFunc , code ) ;
124
151
}
125
152
126
153
export function migratePatchAndWarnFunc ( obj , prop , newFunc , code , msg ) {
127
154
if ( ! msg ) {
128
155
throw new Error ( "No warning message provided" ) ;
129
156
}
130
- return migrateMessageFuncInternal ( obj , prop , newFunc , code , msg , migrateWarn ) ;
157
+ return migratePatchFuncInternal ( obj , prop , newFunc , code , msg , migrateWarn ) ;
131
158
}
132
159
133
160
export function migratePatchAndInfoFunc ( obj , prop , newFunc , code , msg ) {
134
161
if ( ! msg ) {
135
162
throw new Error ( "No info message provided" ) ;
136
163
}
137
- return migrateMessageFuncInternal ( obj , prop , newFunc , code , msg , migrateInfo ) ;
164
+ return migratePatchFuncInternal ( obj , prop , newFunc , code , msg , migrateInfo ) ;
138
165
}
139
166
140
167
export function migratePatchFunc ( obj , prop , newFunc , code ) {
141
- return migrateMessageFuncInternal ( obj , prop , newFunc , code ) ;
168
+ return migratePatchFuncInternal ( obj , prop , newFunc , code ) ;
142
169
}
143
170
144
171
if ( window . document . compatMode === "BackCompat" ) {
0 commit comments