Skip to content

Commit cea6051

Browse files
authored
fix: user supplied prop function detection (#6070)
1 parent d6d8e3c commit cea6051

File tree

6 files changed

+14
-48
lines changed

6 files changed

+14
-48
lines changed

src/components/calendar/calendar.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
} from '../../utils/date'
4444
import { attemptBlur, attemptFocus, requestAF } from '../../utils/dom'
4545
import { stopEvent } from '../../utils/events'
46-
import { isArray, isPlainObject, isString, isUndefined } from '../../utils/inspect'
46+
import { isArray, isPlainObject, isString } from '../../utils/inspect'
4747
import { isLocaleRTL } from '../../utils/locale'
4848
import { mathMax } from '../../utils/math'
4949
import { toInteger } from '../../utils/number'
@@ -342,20 +342,12 @@ export const BCalendar = Vue.extend({
342342
},
343343
computedDateDisabledFn() {
344344
const { dateDisabledFn } = this
345-
let result = null
346-
try {
347-
result = dateDisabledFn()
348-
} catch {}
349-
return isUndefined(result) ? () => false : dateDisabledFn
345+
return dateDisabledFn.name !== 'default' ? dateDisabledFn : () => false
350346
},
351347
// TODO: Change `dateInfoFn` to handle events and notes as well as classes
352348
computedDateInfoFn() {
353349
const { dateInfoFn } = this
354-
let result = null
355-
try {
356-
result = dateInfoFn()
357-
} catch {}
358-
return isUndefined(result) ? () => ({}) : dateInfoFn
350+
return dateInfoFn.name !== 'default' ? dateInfoFn : () => ({})
359351
},
360352
calendarLocale() {
361353
// This locale enforces the gregorian calendar (for use in formatter functions)

src/components/form-file/form-file.js

+4-13
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ import { makePropsConfigurable } from '../../utils/config'
1010
import { closest } from '../../utils/dom'
1111
import { hasPromiseSupport } from '../../utils/env'
1212
import { eventOn, eventOff, stopEvent } from '../../utils/events'
13-
import {
14-
isArray,
15-
isFile,
16-
isFunction,
17-
isNull,
18-
isUndefined,
19-
isUndefinedOrNull
20-
} from '../../utils/inspect'
13+
import { isArray, isFile, isFunction, isNull, isUndefinedOrNull } from '../../utils/inspect'
2114
import { File } from '../../utils/safe-types'
2215
import { escapeRegExp } from '../../utils/string'
2316
import { warn } from '../../utils/warn'
@@ -276,11 +269,9 @@ export const BFormFile = /*#__PURE__*/ Vue.extend({
276269
},
277270
computedFileNameFormatter() {
278271
const { fileNameFormatter } = this
279-
let result = null
280-
try {
281-
result = fileNameFormatter()
282-
} catch {}
283-
return isUndefined(result) ? this.defaultFileNameFormatter : fileNameFormatter
272+
return fileNameFormatter.name !== 'default'
273+
? fileNameFormatter
274+
: this.defaultFileNameFormatter
284275
},
285276
clonedFiles() {
286277
return cloneDeep(this.files)

src/components/form-spinbutton/form-spinbutton.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { arrayIncludes, concat } from '../../utils/array'
1313
import { makePropsConfigurable } from '../../utils/config'
1414
import { attemptBlur, attemptFocus } from '../../utils/dom'
1515
import { eventOnOff, stopEvent } from '../../utils/events'
16-
import { isNull, isUndefined } from '../../utils/inspect'
16+
import { isNull } from '../../utils/inspect'
1717
import { isLocaleRTL } from '../../utils/locale'
1818
import { mathFloor, mathMax, mathPow, mathRound } from '../../utils/math'
1919
import { toFloat, toInteger } from '../../utils/number'
@@ -223,11 +223,7 @@ export const BFormSpinbutton = /*#__PURE__*/ Vue.extend({
223223
},
224224
computedFormatter() {
225225
const { formatterFn } = this
226-
let result = null
227-
try {
228-
result = formatterFn()
229-
} catch {}
230-
return isUndefined(result) ? this.defaultFormatter : formatterFn
226+
return formatterFn.name !== 'default' ? formatterFn : this.defaultFormatter
231227
},
232228
computedAttrs() {
233229
return {

src/components/form-tags/form-tags.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from '../../utils/dom'
2222
import { stopEvent } from '../../utils/events'
2323
import { pick } from '../../utils/object'
24-
import { isEvent, isNumber, isString, isUndefined } from '../../utils/inspect'
24+
import { isEvent, isNumber, isString } from '../../utils/inspect'
2525
import { escapeRegExp, toString, trim, trimLeft } from '../../utils/string'
2626
import formControlMixin, { props as formControlProps } from '../../mixins/form-control'
2727
import formSizeMixin, { props as formSizeProps } from '../../mixins/form-size'
@@ -508,11 +508,7 @@ export const BFormTags = /*#__PURE__*/ Vue.extend({
508508
},
509509
validateTag(tag) {
510510
const { tagValidator } = this
511-
let result = null
512-
try {
513-
result = tagValidator()
514-
} catch {}
515-
return isUndefined(result) ? true : tagValidator(tag)
511+
return tagValidator.name !== 'default' ? tagValidator(tag) : true
516512
},
517513
getInput() {
518514
// Returns the input element reference (or null if not found)

src/components/table/helpers/mixin-filtering.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import identity from '../../../utils/identity'
55
import looseEqual from '../../../utils/loose-equal'
66
import { concat } from '../../../utils/array'
77
import { makePropsConfigurable } from '../../../utils/config'
8-
import { isFunction, isString, isRegExp, isUndefined } from '../../../utils/inspect'
8+
import { isFunction, isString, isRegExp } from '../../../utils/inspect'
99
import { toInteger } from '../../../utils/number'
1010
import { escapeRegExp } from '../../../utils/string'
1111
import { warn } from '../../../utils/warn'
@@ -83,11 +83,7 @@ export default {
8383
localFilterFn() {
8484
// Return `null` to signal to use internal filter function
8585
const { filterFunction } = this
86-
let result = null
87-
try {
88-
result = filterFunction()
89-
} catch {}
90-
return isUndefined(result) ? null : filterFunction
86+
return filterFunction.name !== 'default' ? filterFunction : null
9187
},
9288
// Returns the records in `localItems` that match the filter criteria
9389
// Returns the original `localItems` array if not sorting

src/mixins/form-text.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { makePropsConfigurable } from '../utils/config'
22
import { attemptBlur, attemptFocus } from '../utils/dom'
33
import { stopEvent } from '../utils/events'
4-
import { isUndefined } from '../utils/inspect'
54
import { mathMax } from '../utils/math'
65
import { toInteger, toFloat } from '../utils/number'
76
import { toString } from '../utils/string'
@@ -113,11 +112,7 @@ export default {
113112
return mathMax(toInteger(this.debounce, 0), 0)
114113
},
115114
hasFormatter() {
116-
let result = null
117-
try {
118-
result = this.formatter()
119-
} catch {}
120-
return !isUndefined(result)
115+
return this.formatter.name !== 'default'
121116
}
122117
},
123118
watch: {

0 commit comments

Comments
 (0)