コード例 #1
0
        def _exec_(self, source):
            source = '''\
            (function() {{
                {0};
                {1};
            }})()'''.format(encode_unicode_codepoints(self._source),
                            encode_unicode_codepoints(source))
            source = str(source)

            # backward compatibility
            with PyV8.JSContext() as ctxt, PyV8.JSEngine() as engine:
                js_errors = (PyV8.JSError, IndexError, ReferenceError,
                             SyntaxError, TypeError)
                try:
                    script = engine.compile(source)
                except js_errors as e:
                    raise exceptions.ProgramError(e)
                try:
                    value = script.run()
                except js_errors as e:
                    raise exceptions.ProgramError(e)
                return self.convert(value)
コード例 #2
0
        def _extract_result(self, output):
            output = output.decode(self._runtime._encoding)
            output = output.replace("\r\n", "\n").replace("\r", "\n")
            output_last_line = output.split("\n")[-2]

            if not output_last_line:
                status = value = None
            else:
                ret = json.loads(output_last_line)
                if len(ret) == 1:
                    ret = [ret[0], None]
                status, value = ret

            if status == "ok":
                return value
            elif value.startswith('SyntaxError:'):
                raise exceptions.RuntimeError(value)
            else:
                raise exceptions.ProgramError(value)