Hacker News new | ask | show | jobs
by shardling 4733 days ago
In Firefox you could always do it manually with about:memory -- 1MB a second should be easy enough to notice. Not sure they've added a way to get a pretty graph yet, though. Probably Firebug has a way?

I wonder if using the "use strict" directive would let the browser optimize this more easily? Probably not, but Javascript does have a lot of crazy corner cases, and one of them might be preventing (or just making it harder to prove safe) the optimization.

e: Here's an example of one of those corner cases:

    console.log = eval
Now whether those functions reference a particular variable depends on the string they're printing! And this swap out of log() could be done at any time.

e2: Ah, as glasser and pcwalton point out, an indirect reference to eval doesn't work the same way as a direct call. TIL!

1 comments

No, actually, you literally have to call eval as a function called eval if you want to get the local lexicals. See sections 10.4.2 and 15.1.2.1.1 of the ECMAScript standard, or try it out:

   > (function () { var x = 5; eval("console.log(x)"); })()
   5
   > (function () { var x = 5; var e = eval; e("console.log(x)"); })()
   ReferenceError: x is not defined