deanagit / swfobject

Automatically exported from code.google.com/p/swfobject
0 stars 0 forks source link

adding Object.prototype.function makes generated flashvars invalid #451

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Include this javascript to your page:
//See http://my.opera.com/GreyWyvern/blog/show.dml/1725165, a method for 
cloning (not copying references) multi-dim arrays and all other objects

Object.prototype.clone = function() {
    var newObj = (this instanceof Array) ? [] : {};
    for (i in this) {
    if (i == 'clone') continue;
        if (this[i] && typeof this[i] == "object") {
            newObj[i] = this[i].clone();
        } else newObj[i] = this[i]
    } return newObj;
};

2. use swfobject.embedSWF with a non-empty flashvars object as a parameter
3. THE GENERATED HTML WILL LOOK SOMETHING LIKE THIS:
<object type="application/x-shockwave-flash" ...>
<param name="flashvars" 
value="shape=box&boxwidth=10&boxheight=4&clone=function() { var newObj = 
(this instanceof Array) ? [] : {}; for (i in this) { if (i == 'clone') 
continue; if (this[i] && typeof this[i] == "object") { newObj[i] = this
[i].clone(); } else newObj[i] = this[i] } return newObj; }"/>
</object>

What is the expected output? What do you see instead?

I don't need this prototype function, and I don't think anyone needs to 
pass javascript functions as a flashVar, so I expect:
<object type="application/x-shockwave-flash" ...>
<param name="flashvars" value="shape=box&boxwidth=10&boxheight=4"/>
</object>

What version of the product are you using? On what operating system?

SWFObject v2.2
Windows XP
Opera 10.51 and IE7

Please provide any additional information below.

Properly escaping the flashvars might solve this problem, actually it 
works in Opera, but fails in IE, the flashvar values are ignored in IE...

Original issue reported on code.google.com by frederik...@gmail.com on 25 Mar 2010 at 2:25

GoogleCodeExporter commented 9 years ago
SWFObject has a routine for checking for prototype additions inside the 
createSWF() 
function (which is called internally by embedSWF())

for (var j in parObj) {
if (parObj[j] != Object.prototype[j]) { // filter out prototype additions from 
other 
potential libraries
par += '<param name="' + j + '" value="' + parObj[j] + '" />';
}
}

It is possible that since the object properties are copied rather than 
referenced in 
the embedSWF() function, that the prototype you have attached to your object is 
coming through as a string value rather than a Object.prototype type.

This will need to be investigated further.

In the mean time, as you are just wanting to copy a simple object which only 
holds 
single dimension values, you can avoid adding prototype additions and just use 
a 
shallow clone like:

var newObject= {}; 
for (var i in oldObject) { 
    newObject[i] = oldObject[i];
}

Is there any reason you need to clone your flashvars object before passing it 
in ? 
(as it is cloned for you by SWFOBject anyway)

Original comment by aran.rhee@gmail.com on 26 Mar 2010 at 12:10

GoogleCodeExporter commented 9 years ago
There is no reason to clone the flashvars object, this function is added to 
easily 
clone any object. It's also easy to work around this issue, but it IS 
unexpected 
behaviour, and you need to investigate the generated DOM in order to understand 
what 
goes wrong.

If people use a js library which adds functions to the Object prototype, and 
also 
want to use SWFObject, it will be hard for them to understand why it doesn't 
work, 
and since SWFObject exists to make life easier, I thought it was worth 
mentioning :)

Original comment by frederik...@gmail.com on 26 Mar 2010 at 8:47

GoogleCodeExporter commented 9 years ago
I understand (hence the issue was not marked as invalid). As I noted already, I 
believe 
the check in createSWF() is being circumnavigated by the way the flashvars 
properties 
are being cloned in embedSWF().

Original comment by aran.rhee@gmail.com on 28 Mar 2010 at 10:18

GoogleCodeExporter commented 9 years ago
hi

I also had a 'clone' prototype over the javascript objects.

embedding using swfobject after this declaration causes a bug in IE.

The flashvars are not received correctly in the flash.

Lost 2 days on this issue due to poor IE debug tools. (throw 'anonymous 
function error')

Why cant we override standard Object ?

Original comment by julien.b...@gmail.com on 6 Oct 2010 at 11:20

GoogleCodeExporter commented 9 years ago
I was able to replicate the issue in several browsers.

Adding a simple obj.hasOwnProperty(prop) check within embedSWF fixes the 
problem.

Original comment by platelu...@gmail.com on 23 May 2011 at 5:14