Skip navigation.

miscoded

the web is a hack

eval ... everywhere?

, , , , ,

Harvested from an Opera bug report, here is another interesting surprise from Gecko internals: Object.prototype.eval . It's like a normal eval() but in the scope of that object. In other words, doing

document.body.eval('tagName');


is practically the same as doing

with(document.body){eval('tagName');}


(Before you ask, the best practice would be to say either
document.body.tagName
or
document.body['tagName']
Using eval should be avoided and generally can be avoided without problems. So don't let me catch you using any of the two first snippets on a production site!)

So hey Gecko, where did this come from? Is it something we should copy and implement or something we should scorn and point fingers at?

praising Firefox :)no ballads in this Opera

Comments

Doug Wright 7. September 2006, 12:27

According to the Mozilla docs - http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object:eval , it was implemented as part of JS1.1, deprecated in JS1.2 and actually removed in JS1.4. So it's not something Opera should be copying IMHO.

I haven't tested, but if it's still present in Firefox 1.5, you should file a bug against Mozilla.

João Eiras 7. September 2006, 17:56

hum... is that why w3c DOM 3 LS testsuite fails on Opera ?

Hallvord R. M. Steen 7. September 2006, 18:37

dwright: thank you! :smile:

xErath: don't know - I have to check. That test suite was buggy when I tried running it in Opera, but that's a while ago and I reported some issues that probably got fixed.

JibberJim 8. September 2006, 14:34

It should be scorned!

Hallvord R. M. Steen 8. September 2006, 19:29

dwright: my Firefox/1.5.0.1 certainly has it. Should I bug this without testing in a nightly build though? I don't mind filing it but wouldn't go as far as downloading a nightly build - more than enough of test builds from Opera so no, thanks.. :smile:

Doug Wright 9. September 2006, 14:46

javascript:var foo=new Object();foo.bar="foobar";alert(foo.eval('b'+'ar'));

Shows "foobar" in a nightly (specifically Minefield 3.0a1/20060908). You should file that bug.

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies