I am developing an application which uses TinyMCE editors to allow the user to modify content. I have developed a Prototype.js class which, upon initialization, generates a unique ID and creates a TinyMCE editor on a <div>
with that ID. Here's some of the relevant code:
Region = Class.create(
{
initialize: function(options)
{
this._editorReady = false;
this._index = Region.nextIndex++;
this._uid = com.digitalfruition.Customizer.TypeRegion.uidPrefix+this._index;
Region.instances.push(this);
this.setupTinyMCE();
},
uid: function()
{
return this._uid;
},
index: function()
{
return this._index;
},
In a lot of places, I will refer to a Region
's uid()
, for example, when events occur within the TinyMCE editor (for example, the selection changes) my handlers are given the ID of the editor. I will often do:
var index = Region.instances.invoke('uid').indexOf(uid);
To find the actual Region
instance reflecting the interface the events occurred in.
I only ever set the _uid
property of any given Region
once. I'm sure of this.
But in Firefox 9.0.1, I am seeing really odd behavior. When events fire, the editor they're firing on can't be found because index
in the code above is -1
. After inspecting in Firebug, I saw this:
Those are debug messages from my code, logging various things (the height of the regions in this case) along with the region's this.uid()
value. The memory appears to have gotten corrupted! and you can even see where it happens, the first circled log entry is correct, and the subsequent ones are wrong.
The same code works fine in Safari and Chrome. So far only Firefox 9.0.1 seems to be affected...
To inspect further, I ran this in the Firebug console:
>>> com.digitalfruition.Customizer.TypeRegion.instances.invoke('uid');
["�ᔮ��蒦ᓤ�瀀魳ᓪ�倀⛺ᓪ�怀�eg����遀"]
That makes no sense to me. What could cause memory corruption like this in JavaScript? How do I even go about troubleshooting such a situation?
Is it possible that one of your files is saved with a different encoding? I'd look at that, and also maybe make sure you're serving the files with the correct encoding and mime types.
It might be a good idea to do some testing where you
console.log()
theuid
values as they are generated to confirm that the corruption is in fact occurring after the objects are created. I suspect it's happening when they are created.