Hi Jakob,

This is a good idea, but unfortunately my existing code relies on the eval-like 
nature of fragments, in that they "return" whatever the last line in the script 
evaluates to.  e.g. the script

7 + 6

evaluates as 13.  But the function

f = function() {
   7 + 6;
}
f()

evaluates as undefined because it is missing a return statement.


  Oliver

On 16 Jul 2014, at 5:56 pm, Jakob Kummerow <[email protected]> wrote:

> How about wrapping the fragments in anonymous closures? Roughly:
> 
> script_to_execute = "(function() {" + fragment + "})();";
> 
> That should get you most of what you want, except for undoing monkey-patching 
> of Array.prototype and stuff, but maybe that's good enough, and it's 
> certainly easy and fast.
> 
> 
> On Wed, Jul 16, 2014 at 8:35 AM, Oliver Bock <[email protected]> wrote:
> What is the most efficient way to clean up the global object between running 
> fragments of JavaScript?  
> 
> I am running a fragment of JavaScript in a tight loop to make a simple 
> calculation for each of hundreds of thousands of inputs.  I don't want 
> variables set by one execution to bleed into the next.
> 
> My first thought was to try to swap in a different global object for each v8 
> iteration, but I can find no mechanism to do that.  (Earlier versions of v8 
> might have supported it via something like Context.ReattachGlobal(), but that 
> function no longer exists.)
> 
> I can manually iterate over the global object and clean up after myself (as 
> this guy does), but my JavaScript fragments are fairly simple and the cleanup 
> dominates execution time (because v8 is so fast).
> 
> I think recreating the Context each time will be even slower than this. 
> particularly because I will need to repopulate it with various objects.

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to