I don't see it running only once from the code you showed.
In addition, you can't assure the environment will remain "untainted"
after you call this function for the first time (assuming you cache
this value).

By the way, here's my modified version:

Object.tainted = function() {
        for (var key in {})
             return true;
        return false;
};

--
Ariel Flesler
http://flesler.blogspot.com

On Oct 3, 1:56 pm, "Jörn Zaefferer" <[EMAIL PROTECTED]>
wrote:
> The tainted-check runs just once, so for a non-tainted enviroment you
> avoid the overhead of the check. I don't know if that actually makes a
> difference.
>
> Jörn
>
> On Fri, Oct 3, 2008 at 6:37 PM, Ariel Flesler <[EMAIL PROTECTED]> wrote:
>
> > This is nothing new I think. The typical "safe" for..in iteration.
> > I don't quite see the point of the tainted function. I just see one
> > for..in iteration split into 2, and actually with extra overhead.
>
> > May I get some enlightenment ? :)
>
> > --
> > Ariel Flesler
> >http://flesler.blogspot.com
>
> > On Oct 3, 1:27 pm, "Jörn Zaefferer" <[EMAIL PROTECTED]>
> > wrote:
> >> Hi,
>
> >> I've thought about John's comment about trying to immunize jQuery
> >> against hostile enviroments, especially changes to Object.prototype.
> >> In that regard, whats wrong with the following code? I've tested in FF
> >> with Firebug, and for now assume thats its pure JavaScript and will
> >> therefore work in other browsers just as well (or not).
>
> >> Object.tainted = function() {
> >>         var i = 0;
> >>         for (var key in {})
> >>                 i++;
> >>         return i != 0;
>
> >> };
>
> >> Object.prototype.each = function(fn) {
> >>         var tainted = Object.tainted();
> >>         for (var key in this) {
> >>                 if (!tainted || !Object.prototype[key]) {
> >>                         fn(key, this[key]);
> >>                 }
> >>         }
>
> >> };
>
> >> function Obj() {
> >>         this.foo = "foo";}
>
> >> Obj.prototype = { bar: "bar" };
>
> >> var x = new Obj();
>
> >> x.each(function(key, value) {
> >>         console.log( key, value );
>
> >> });
>
> >> Its prints out "foo foo" and "bar bar", but not "each function()", as
> >> its supposed to.
>
> >> How is this applicable to jQuery? Consider moving the tainted()-check
> >> to jQuery.each. To check itself runs just once for a full iteration,
> >> and itself doesn't really do anything. The result is cached, so the
> >> overhead in an untainted enviroment for each iteration is a single
> >> boolean-check, which I assume is neglible. For tainted enviroments,
> >> there is the overhead of checking if that property is defined on
> >> Object.prototype.
>
> >> I'm sure I've missed one or more drawbacks to that approach. Once that
> >> is out the way, I'll try to run some performance tests. Though any
> >> help with benchmarking is highly welcome.
>
> >> Jörn
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to