Skip to content

Commit

Permalink
#1204 Throw typeError if maxHeight et al is not a number
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjbradshaw committed Feb 2, 2024
1 parent 21dec0b commit 6bc8f23
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions src/iframeResizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,24 @@
}
}

function chkIsNumber(key) {
function isNumber(key) {
return (
!Number.isNaN(settings[iframeId][key]) &&
'' !== settings[iframeId][key]
)
}

if (!isNumber(key)) {
throw new TypeError(key + ' is not a number')
}
}

chkIsNumber('maxHeight')
chkIsNumber('minHeight')
chkIsNumber('maxWidth')
chkIsNumber('minWidth')

chkMinMax('Height')
chkMinMax('Width')

Expand Down Expand Up @@ -1067,13 +1085,10 @@
}

function checkReset() {
// Reduce scope of firstRun to function, because IE8's JS execution
// context stack is borked and this value gets externally
// changed midway through running this function!!!
var firstRun = settings[iframeId] && settings[iframeId].firstRun,
resetRequertMethod =
settings[iframeId] &&
settings[iframeId].heightCalculationMethod in resetRequiredMethods
var firstRun = settings[iframeId] && settings[iframeId].firstRun
var resetRequertMethod =
settings[iframeId] &&
settings[iframeId].heightCalculationMethod in resetRequiredMethods

if (!firstRun && resetRequertMethod) {
resetIFrame({ iframe: iframe, height: 0, width: 0, type: 'init' })
Expand Down Expand Up @@ -1184,25 +1199,6 @@
: remoteHost
}

function depricate(key) {
var splitName = key.split('Callback')

if (splitName.length === 2) {
var name =
'on' + splitName[0].charAt(0).toUpperCase() + splitName[0].slice(1)
this[name] = this[key]
delete this[key]
warn(
iframeId,
"Deprecated: '" +
key +
"' has been renamed '" +
name +
"'. The old method will be removed in the next major version."
)
}
}

function processOptions(options) {
options = options || {}

Expand All @@ -1213,7 +1209,6 @@
iframe.src && iframe.src.split('/').slice(0, 3).join('/')

checkOptions(options)
Object.keys(options).forEach(depricate, options)
copyOptions(options)

if (settings[iframeId]) {
Expand Down Expand Up @@ -1367,14 +1362,11 @@

function setupEventListeners() {
addEventListener(window, 'message', iFrameListener)

addEventListener(document, 'visibilitychange', tabVisible)
addEventListener(document, '-webkit-visibilitychange', tabVisible)
addEventListener(window, 'resize', function () {
resizeIFrames('resize')
})

addEventListener(document, 'visibilitychange', tabVisible)

addEventListener(document, '-webkit-visibilitychange', tabVisible)
}

var setupComplete = false
Expand Down

0 comments on commit 6bc8f23

Please sign in to comment.