PDA

View Full Version : [FIXED-13][3.x] FlashComponent mutates passed in config objects



Animal
6 Aug 2009, 2:40 AM
The code has



onRender : function(){
Ext.FlashComponent.superclass.onRender.apply(this, arguments);

var params = Ext.apply(this.flashParams || {}, {
allowScriptAccess: 'always',
bgcolor: this.backgroundColor,
wmode: this.wmode
}), vars = Ext.apply(this.flashVars || {}, {
allowedDomain: document.location.hostname,
elementID: this.getId(),
eventHandler: 'Ext.FlashEventProxy.onEvent'
});

new swfobject.embedSWF(this.url, this.id, this.swfWidth, this.swfHeight, this.flashVersion,
this.expressInstall ? Ext.FlashComponent.EXPRESS_INSTALL_URL : undefined, vars, params);

this.swf = Ext.getDom(this.id);
this.el = Ext.get(this.swf);
},


This mutates any flashParams or flashVars object passed in which might have unforeseen side effects on the calling code which might still reference and use those objects.

The code should stick to the standard of applying configs to objects:



onRender : function(){
Ext.FlashComponent.superclass.onRender.apply(this, arguments);

var params = Ext.apply({
allowScriptAccess: 'always',
bgcolor: this.backgroundColor,
wmode: this.wmode
}, this.flashParams || {}), vars = Ext.apply({
allowedDomain: document.location.hostname,
elementID: this.getId(),
eventHandler: 'Ext.FlashEventProxy.onEvent'
}, this.flashVars || {});

new swfobject.embedSWF(this.url, this.id, this.swfWidth, this.swfHeight, this.flashVersion,
this.expressInstall ? Ext.FlashComponent.EXPRESS_INSTALL_URL : undefined, vars, params);

this.swf = Ext.getDom(this.id);
this.el = Ext.get(this.swf);
},

Condor
6 Aug 2009, 2:44 AM
Ext.apply can handle an empty second parameter, so the "|| {}" isn't required.

Animal
6 Aug 2009, 2:47 AM
Well checked. I couldn't be bothered to check it!

Animal
6 Aug 2009, 2:48 AM
Another advantage of the fix is that you can also override the default allowScriptAccess, bgcolor etc in your configuration.

evant
6 Aug 2009, 7:28 PM
Agreed, fixed in SVN.