Re: [v8-users] Cleaning up the global object between scripts

2014-07-17 Thread 'Andreas Rossberg' via v8-users
On 17 July 2014 02:01, Oliver Bock oli...@g7.org wrote: In the last message from this discussion in 2012, Andreas Rossberg suggests that v8 will need to allow arbitrary user objects to be used as the global object in order to support ES6 module loaders. Perhaps this will eventually give me

[v8-users] Cleaning up the global object between scripts

2014-07-16 Thread Oliver Bock
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

Re: [v8-users] Cleaning up the global object between scripts

2014-07-16 Thread Jakob Kummerow
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

Re: [v8-users] Cleaning up the global object between scripts

2014-07-16 Thread Toon Verwaest
V8 has no way to clean up a global object. The global object is referenced in two ways: either directly (implicit references from contexts), or indirectly via the global proxy (references from JavaScript). ReattachGlobal didn't do what you would have expected, reattached the global object of a

Re: [v8-users] Cleaning up the global object between scripts

2014-07-16 Thread Oliver Bock
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

Re: [v8-users] Cleaning up the global object between scripts

2014-07-16 Thread Sven Panne
On Wed, Jul 16, 2014 at 12:29 PM, Oliver Bock oli...@g7.org wrote: 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. [...] Easily fixable via the highly

Re: [v8-users] Cleaning up the global object between scripts

2014-07-16 Thread Jakob Kummerow
...which of course kills any chance you had at getting the code optimized, but if the fragments are short enough, they probably didn't get optimized anyway (because 6+7 executes wy to quickly to be worth the overhead of firing up the optimizing compiler), so this may not matter. If you

Re: [v8-users] Cleaning up the global object between scripts

2014-07-16 Thread joko_suwito
Thank you. -- -- v8-users mailing list v8-users@googlegroups.com 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

Re: [v8-users] Cleaning up the global object between scripts

2014-07-16 Thread joko_suwito
Thank you. -- -- v8-users mailing list v8-users@googlegroups.com 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

Re: [v8-users] Cleaning up the global object between scripts

2014-07-16 Thread Oliver Bock
Sadly the JavaScript fragments are outside of my control so I cannot require that they include a return statement, and they are a bit more complicated than 6+7 and do benefit from optimisation, especially as they are executed many, many times. Object.freeze() (thanks Toon) won't help because