wojtossfm / pyv8

Automatically exported from code.google.com/p/pyv8

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSContext __exit__ does not unlock jslocker and __enter__ should lock instead of __init__

GoogleCodeExporter opened this issue · comments

What steps will reproduce the problem?
1. initialize context outside of with statement

ctxt = JSContext()
# lock already created and locked

with cx as ctxt:
    do someting ..
#no unlocking because __exit__ method never unlocks 
hasattr(JSLocker, 'lock'): will always be false
and lock is never released.
Heres the relevant code:

https://code.google.com/p/pyv8/source/browse/trunk/PyV8.py#780


Solution is to manually cll ctxt.leave()

This caused segfaults in my case.

Original issue reported on code.google.com by melit.st...@gmail.com on 29 Apr 2013 at 6:37

so, you means only auto create JSLocker in the __enter__  method? or let's you 
decide when to lock it?

Original comment by flier...@gmail.com on 30 Apr 2013 at 1:11

  • Changed state: Accepted
  • Added labels: OpSys-All
Surprise! Why JSContext enters the lock in the constructor? 
I think about too a scenario where the JSContext is created once someware, 
evals some javascript code and cached for future reuse.

ctx = JSContext()
ctx.eval(jscode)

...

def execute(param):
   with JSLocker(): # Do I need it?
      with ctx:
         ctx.locals.param = param;
         return ctx.eval('some_function(param)')


Does it works as expected?

ps: Could I wrap the ctx with JSIsolate() instead JSLocker() in this case?

Original comment by e.generalov on 12 Jun 2013 at 9:21