ftsun / pyv8

Automatically exported from code.google.com/p/pyv8
0 stars 0 forks source link

The best way to use shared JS code? #197

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I’d like to find the best way to re-use JS code.

I have the following requirements:

1. Relatively large JS code base (about 500KB)
2. JS code must be performed in separate thread.
3. JS execution must be fast and perform on each user keystroke

To make things perform as required, I’m using the following setup: the JS 
codebase inited as JSExtension and the action itself is performed as follows:

def run():
    with PyV8.JSContext(extensions=['my_ext']) as c:
        # do JS stuff here

with PyV8.JSLocker():
    threading.Thread(target=run).start()

Everything seems to works fast and smooth, until I try to update extension in 
runtime, e.g. push updated JS code into extension. Seems like creating 
extension with the same name during runtime doesn’t update it.

So my question is: is it possible to update existing extension? Or maybe 
there’s another way to use shared (precompiled) JS code? 

For example, create JSContext with shared codebase in main thread and then use 
it as `with JSContext(shared_context):` in separate thread. Will this work? Or 
it‘s a bad idea?

Thanks!

Original issue reported on code.google.com by serge....@gmail.com on 12 Aug 2013 at 10:05

GoogleCodeExporter commented 9 years ago
In fact, v8 maintain all the JS extension with a linked list, it will install 
all the auto enable extension when create context, it means if you have two or 
more extension with same name, the last/old one will be used.

So, please create your extension without auto extension and register it by 
manual

JSExtension(..., register=False) 

Original comment by flier...@gmail.com on 14 Aug 2013 at 3:28