My JavaScript book is out! Don't miss the opportunity to upgrade your beginner or average dev skills.

Tuesday, September 28, 2010

Opera, Inevitably Unexpected


Opera fellas works at speed light, the problem described in this post has been patched already, great stuff and thanks!

Just a quick one, about what I have discovered with Opera 10.62 when I have tested wru against this browser ...

// host object
var xhr = new XMLHttpRequest;

// this is true
alert("addEventListener" in xhr);

// this is undefined
// not even null
// simply undefined!!!

The Problem

99% of libraries out there are assuming that key in object is one of the fastest and most reliable way to have features detection.
Today, we know that this assumption is wrong.
It's not about the reproducibility of the problem:

var o = {};
o.key = o.key;
"key" in o && o.key;

It's about an ...

Epic Fail (Already Fixed!)

The engine "behind the scene" is broken. Whatever it happens there, we have a broken chain through pseudo inheritance that exposes publicly a method that does not exist, which brings us down the assumption that host objects are not tested before the release ... or surely not their "apparently valid" methods.
Nothing else to say, come on guys, you've always been pioneer and good fellas, so please don't release these mistakes, thanks.


Sauron said...

XHR.addEventListener was added in Opera together with the web workers work. But it was just a stub, letovers of incomplete work. Given that the feature was never supported, there were no tests to check for it and that it works properly. Hence, to prevent broken feature detection, XHR.addEventListener is removed by browser.js (Search for "PATCH-272") while this isn't fixed in the core.

Hallvord R. M. Steen said...

Hi Andrea,
love the title of this post. Doing QA and testing for Opera, I know that exact feeling :)

Anyway, somebody brought this post to my attention this morning, and I have to confess that this is my fault entirely. The good news is that since it's my fault I'm also able to fix it, and the fix will go live today or tomorrow. Within a week or so, all existing Opera installations should handle your test code as WRU expects. Not bad turnaround for a blogged bug report, right?

Background story: we will some day have proper support for XHR objects as DOM-style event target, complete with addEventListener. Unfortunately, while releasing Web Workers in desktop builds, an entirely non-functional addEventListener method left the building attached to XMLHttpRequest.prototype. Yeah, I know that sucks - but I'm sure you can tell why we forgot to test that something we expected not to be there, wasn't.

Anyway, so to avoid breaking feature detection we shipped a browser.js patch removing this method - but only by setting it to undefined on the prototype. Oops, I obviously only thought about typeof checks and not about the in operator. This is fixed at source, next browser.js file to go live will use 'delete' and since Opera calls home once a week, the problem will soon be history. Thanks for bringing it to my attention :)

Anonymous said...

I assume you filled a bug report at right ?

Andrea Giammarchi said...

Yeah Hallvord R. M. Steen, that's a Hell of a Turnaround, great stuff!

I can imagine the method should have not be there, but at the same time I don't know why you don't have a sort of "host exposure test" for host objects, you would have catched that undefined instantly.

In few words, I believe it's kinda weird I can easily spot a problem in the higher level, JavaScript, while you can flag methods without implementing them and forgive them on the lower, I am sure you know what I mean.

Thanks a lot for the effort and the quick fix guys, all the best and keep doing your hard work there ;)


Hallvord R. M. Steen said...

The new file is released and you are now credited on :-)

Anonymous said...

Hello there,

This is a message for the webmaster/admin here at

Can I use some of the information from your post above if I provide a backlink back to this website?


Andrea Giammarchi said...

Hi Jules, the reason I write posts is to share so ... the more my share reaches, the more I feel "not wasting time" ;)

In few words, do whatever you want with this blog posts, and I surely appreciate a backlink, thanks.