def test_call(self): v8 = v8eval.V8() v8.eval('function inc(x) { return x + 1; }') self.assertEqual(v8.call('inc', [7]), 8) with self.assertRaises(TypeError): v8.call(None, [7]) with self.assertRaises(TypeError): v8.call('inc', None) with self.assertRaises(v8eval.V8Error): v8.call('i', [7])
def test_eval(self): v8 = v8eval.V8() self.assertEqual(v8.eval('1 + 2'), 3) self.assertEqual(v8.eval('var p = { x: 1.1, y: 2.2 }; p'), { 'x': 1.1, 'y': 2.2 }) self.assertEqual(v8.eval(''), None) self.assertEqual(v8.eval('function inc(x) { return x + 1; }'), None) with self.assertRaises(TypeError): v8.eval(None) with self.assertRaises(v8eval.V8Error): v8.eval("foo")
def test_debugger(self): v8 = v8eval.V8() with self.assertRaises(TypeError): v8.enable_debugger(0.1) with self.assertRaises(v8eval.V8Error): v8.enable_debugger(-1) port = 12345 self.assertEqual(v8.enable_debugger(port), None) with self.assertRaises(v8eval.V8Error): v8.enable_debugger(port) self.assertEqual(v8.disable_debugger(), None) self.assertEqual(v8.enable_debugger(port), None) self.assertEqual(v8.disable_debugger(), None)
def __init__(self, test, num_repeat): threading.Thread.__init__(self) self.v8 = v8eval.V8() self.test = test self.num_repeat = num_repeat
def eval(self, jsEnv, js): try: return v8eval.V8().eval('{}{}'.format(jsEnv, js)) except (TypeError, v8eval.V8Error): RuntimeError('We encountered an error running the V8 Engine.')
def eval(self, body, domain): try: return v8eval.V8().eval(template(body, domain)) except (TypeError, v8eval.V8Error): RuntimeError('We encountered an error running the V8 Engine.')
def add(x, y): v8 = v8eval.V8() v8.eval('var add = (x, y) => x + y;') return v8.call('add', [x, y])