Beispiel #1
0
    def testStackLimit(self):
        with STPyV8.JSIsolate():
            STPyV8.JSEngine.setStackLimit(256 * 1024)

            with STPyV8.JSContext() as ctxt:
                oldStackSize = ctxt.eval("var maxStackSize = function(i){try{(function m(){++i&&m()}())}catch(e){return i}}(0); maxStackSize")

        with STPyV8.JSIsolate():
            STPyV8.JSEngine.setStackLimit(512 * 1024)

            with STPyV8.JSContext() as ctxt:
                newStackSize = ctxt.eval("var maxStackSize = function(i){try{(function m(){++i&&m()}())}catch(e){return i}}(0); maxStackSize")

        self.assertTrue(newStackSize > oldStackSize * 2)
Beispiel #2
0
 def run():
     with STPyV8.JSIsolate():
         with STPyV8.JSContext(g) as ctxt:
             ctxt.eval("""
                 for (i=0; i<10; i++)
                     add(i);
             """)
Beispiel #3
0
    def testLocker(self):
        with STPyV8.JSIsolate():
            self.assertFalse(STPyV8.JSLocker.active)
            self.assertFalse(STPyV8.JSLocker.locked)

            with STPyV8.JSLocker() as outter_locker:
                self.assertTrue(STPyV8.JSLocker.active)
                self.assertTrue(STPyV8.JSLocker.locked)

                self.assertTrue(outter_locker)

                with STPyV8.JSLocker() as inner_locker:
                    self.assertTrue(STPyV8.JSLocker.locked)

                    self.assertTrue(outter_locker)
                    self.assertTrue(inner_locker)

                    with STPyV8.JSUnlocker():
                        self.assertFalse(STPyV8.JSLocker.locked)

                        self.assertTrue(outter_locker)
                        self.assertTrue(inner_locker)

                    self.assertTrue(STPyV8.JSLocker.locked)

            self.assertTrue(STPyV8.JSLocker.active)
            self.assertFalse(STPyV8.JSLocker.locked)

            locker = STPyV8.JSLocker()

        with STPyV8.JSContext():
            self.assertRaises(RuntimeError, locker.__enter__)
            self.assertRaises(RuntimeError, locker.__exit__, None, None, None)

        del locker
Beispiel #4
0
        def run():
            with STPyV8.JSIsolate():
                with STPyV8.JSContext(g) as ctxt:
                    ctxt.eval("""
                        started.wait();

                        for (i=0; i<10; i++)
                        {
                            sleep(100);
                        }

                        finished.release();
                    """)
Beispiel #5
0
    def _testOutOfMemory(self):
        with STPyV8.JSIsolate():
            STPyV8.JSEngine.setMemoryLimit(max_young_space_size=16 * 1024, max_old_space_size=4 * 1024 * 1024)

            with STPyV8.JSContext() as ctxt:
                STPyV8.JSEngine.ignoreOutOfMemoryException()

                ctxt.eval("var a = new Array(); while(true) a.push(a);")

                self.assertTrue(ctxt.hasOutOfMemoryException)

                STPyV8.JSEngine.setMemoryLimit()

                STPyV8.JSEngine.collect()
Beispiel #6
0
 def testBase(self):
     with STPyV8.JSIsolate() as isolate:
         self.assertIsNotNone(isolate.current)
         self.assertFalse(isolate.locked)
Beispiel #7
0
 def testEnterLeave(self):
     with STPyV8.JSIsolate() as isolate:
         self.assertIsNotNone(isolate.current)