LongTail Video is now JW Player - New Name, Same Passion For Video

Close

JW Player Forums

CATEGORY:

/

jwplayer.js

1 reply [Last post]

Hello,

I found a bug in jwplayer.js.

In the current version of :
http://developer.longtailvideo.com/trac/browser/trunk/fl5/js/bin-debug/jwplayer.js

Lines 3483 to 3499 :

var _modes;
if (parsedConfig.flashplayer && !parsedConfig.modes) {
_modes = _playerDefaults(parsedConfig.flashplayer);
delete parsedConfig.flashplayer;
} else if (parsedConfig.modes) {
if (typeof parsedConfig.modes == "string") {
_modes = _playerDefaults(parsedConfig.modes);
} else if (parsedConfig.modes instanceof Array) {
_modes = parsedConfig.modes;
} else if (typeof parsedConfig.modes == "object" && parsedConfig.modes.type) {
_modes = [parsedConfig.modes];
}
delete parsedConfig.modes;
} else {
_modes = _playerDefaults();
}
parsedConfig.modes = _modes;

There is a problem on the line :

} else if (parsedConfig.modes instanceof Array) {

As the use of instanceof to check if a variable is an array is NOT reliable.
(See http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/ for details)

I had to change this line to :

} else if (Object.prototype.toString.call(parsedConfig.modes) === '[object Array]') {

Also, there should be an 'else' on the second if, with the playerDetaults(), or it fails further in the code when modes is undefined.

Final code should be :

var _modes;
if (parsedConfig.flashplayer && !parsedConfig.modes) {
_modes = _playerDefaults(parsedConfig.flashplayer);
delete parsedConfig.flashplayer;
} else if (parsedConfig.modes) {
if (typeof parsedConfig.modes == "string") {
_modes = _playerDefaults(parsedConfig.modes);
} else if (Object.prototype.toString.call(parsedConfig.modes) === '[object Array]') {
_modes = parsedConfig.modes;
} else if (typeof parsedConfig.modes == "object" && parsedConfig.modes.type) {
_modes = [parsedConfig.modes];
} else {
_modes = _playerDefaults();
}
delete parsedConfig.modes;
} else {
_modes = _playerDefaults();
}
parsedConfig.modes = _modes;

I hope this could be merged into the next versions ;-)

Thank you!

Olivier.

@Olivier -

Thanks for the feedback. Could I ask where you're seeing this usage cause problems? In the blog post you linked, the problem arose when the script instantiated an array whose constructor was defined in another iframe, which the player doesn't do.

Still don't have the new JW Player? Get It Here