class ChakraJSEngine(AbstractJSEngine): def __init__(self, source=u''): if not chakra_available: msg = 'No supported chakra binary found on your system!' if interpreter: msg += 'Please install PyChakra or use ExternalJSEngine.' raise RuntimeError(msg) self.chakra = ChakraHandle() AbstractJSEngine.__init__(self, source) def _get_source(self): return u'\n'.join(self._source) def _append(self, code): self._append_source(code) ok, result = self.chakra.eval(code, True) if not ok: raise ProgramError(str(result)) def _eval(self, code): self._append_source(code) ok, result = self.chakra.eval(code) if ok: return result else: raise ProgramError(str(result))
def chakra(self): chakra = Runtime() res1 = chakra.eval(open(react).read()) self.assertEqual(True, res1[0]) self.assertEqual(None, res1[1]) res2 = chakra.eval(open(react_domserver).read()) self.assertEqual(True, res2[0]) self.assertEqual(None, res2[1]) res3 = chakra.eval(open(es6).read()) self.assertEqual(True, res3[0]) self.assertEqual( {u'__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED': {u'ReactCurrentOwner': {u'current': None}}, u'version': u'16.3.1', u'Children': {}}, res3[1]) res4 = chakra.eval("typeof ReactDOMServer.renderToStaticMarkup") self.assertEqual(True, res4[0]) self.assertEqual("function", res4[1]) res5 = chakra.set_variable("foo", "'bar'") self.assertEqual(True, res5[0]) res6 = chakra.get_variable("foo") self.assertEqual("bar", res6) res7 = chakra.eval("(() => 2)();") self.assertEqual(True, res7[0]) self.assertEqual(2, res7[1]) res8 = chakra.eval("(() => a)()") self.assertEqual(False, res8[0]) self.assertEqual("ReferenceError: 'a' is not defined", res8[1])
def __init__(self, source=u''): if not chakra_available: msg = 'No supported chakra binary found on your system!' if interpreter: msg += 'Please install PyChakra or use ExternalJSEngine.' raise RuntimeError(msg) self.chakra = ChakraHandle() AbstractJSEngine.__init__(self, source)
class Context: def __init__(self, engine): self._engine = engine self._context = ChakraHandle() def eval(self, code, eval=True, raw=False): self._engine._append_source(code) ok, result = self._context.eval(code, raw=raw) if ok: if eval: return result else: raise ProgramError(str(result))
class ChakraJSEngine(AbstractJSEngine): def __init__(self, source=''): if not chakra_available: raise RuntimeError('No supported chakra binary found on your system!') self.chakra = ChakraHandle() AbstractJSEngine.__init__(self, source) def _get_source(self): return '\n'.join(self._source) def _append(self, code): self._append_source(code) ok, result = self.chakra.eval(code) if not ok: raise ProgramError(str(result)) def _eval(self, code): self._append_source(code) ok, result = self.chakra.eval(code) if ok: return result else: raise ProgramError(str(result))
def __init__(self, engine): self._engine = engine self._context = ChakraHandle()
def __init__(self, source=''): if not chakra_available: raise RuntimeError('No supported chakra binary found on your system!') self.chakra = ChakraHandle() AbstractJSEngine.__init__(self, source)