Merge send_string functions in python debugger client (#1989)
Merging the messages to one check, therefore multiple duplicated lines are removed. I didn't find a good solution though in the HTML client, since it would be nested switch cases / ifs, which wouldn't look okay IMO, the other solution would only save like 2 lines of code overall. JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
This commit is contained in:
committed by
László Langó
parent
5cdb98c75e
commit
7905422b19
@@ -1089,33 +1089,47 @@ def main():
|
|||||||
|
|
||||||
prompt.cmdloop()
|
prompt.cmdloop()
|
||||||
|
|
||||||
|
|
||||||
elif buffer_type in [JERRY_DEBUGGER_EVAL_RESULT,
|
elif buffer_type in [JERRY_DEBUGGER_EVAL_RESULT,
|
||||||
JERRY_DEBUGGER_EVAL_RESULT_END]:
|
JERRY_DEBUGGER_EVAL_RESULT_END,
|
||||||
|
JERRY_DEBUGGER_OUTPUT_RESULT,
|
||||||
|
JERRY_DEBUGGER_OUTPUT_RESULT_END]:
|
||||||
message = b""
|
message = b""
|
||||||
eval_type = buffer_type
|
msg_type = buffer_type
|
||||||
while True:
|
while True:
|
||||||
message += data[3:]
|
if buffer_type in [JERRY_DEBUGGER_EVAL_RESULT_END,
|
||||||
|
JERRY_DEBUGGER_OUTPUT_RESULT_END]:
|
||||||
if buffer_type == JERRY_DEBUGGER_EVAL_RESULT_END:
|
subtype = ord(data[-1])
|
||||||
subtype = ord(message[-1])
|
message += data[3:-1]
|
||||||
message = message[:-1]
|
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
message += data[3:]
|
||||||
|
|
||||||
data = debugger.get_message(True)
|
data = debugger.get_message(True)
|
||||||
buffer_type = ord(data[2])
|
buffer_type = ord(data[2])
|
||||||
buffer_size = ord(data[1]) - 1
|
buffer_size = ord(data[1]) - 1
|
||||||
|
# Checks if the next frame would be an invalid data frame.
|
||||||
|
# If it is not the message type, or the end type of it, an exception is thrown.
|
||||||
|
if buffer_type not in [msg_type, msg_type + 1]:
|
||||||
|
raise Exception("Invalid data caught")
|
||||||
|
|
||||||
if buffer_type not in [eval_type,
|
# Subtypes of output
|
||||||
eval_type + 1]:
|
if buffer_type == JERRY_DEBUGGER_OUTPUT_RESULT_END:
|
||||||
raise Exception("Eval result expected")
|
if subtype == JERRY_DEBUGGER_OUTPUT_OK:
|
||||||
|
print("%sout: %s%s" % (debugger.blue, debugger.nocolor, message))
|
||||||
|
elif subtype == JERRY_DEBUGGER_OUTPUT_WARNING:
|
||||||
|
print("%swarning: %s%s" % (debugger.yellow, debugger.nocolor, message))
|
||||||
|
elif subtype == JERRY_DEBUGGER_OUTPUT_ERROR:
|
||||||
|
print("%serr: %s%s" % (debugger.red, debugger.nocolor, message))
|
||||||
|
|
||||||
if subtype == JERRY_DEBUGGER_EVAL_ERROR:
|
# Subtypes of eval
|
||||||
print("Uncaught exception: %s" % (message))
|
elif buffer_type == JERRY_DEBUGGER_EVAL_RESULT_END:
|
||||||
else:
|
if subtype == JERRY_DEBUGGER_EVAL_ERROR:
|
||||||
print(message)
|
print("Uncaught exception: %s" % (message))
|
||||||
|
else:
|
||||||
|
print(message)
|
||||||
|
|
||||||
prompt.cmdloop()
|
prompt.cmdloop()
|
||||||
|
|
||||||
elif buffer_type == JERRY_DEBUGGER_MEMSTATS_RECEIVE:
|
elif buffer_type == JERRY_DEBUGGER_MEMSTATS_RECEIVE:
|
||||||
|
|
||||||
@@ -1133,31 +1147,6 @@ def main():
|
|||||||
elif buffer_type == JERRY_DEBUGGER_WAIT_FOR_SOURCE:
|
elif buffer_type == JERRY_DEBUGGER_WAIT_FOR_SOURCE:
|
||||||
prompt.send_client_source()
|
prompt.send_client_source()
|
||||||
|
|
||||||
elif buffer_type in [JERRY_DEBUGGER_OUTPUT_RESULT, JERRY_DEBUGGER_OUTPUT_RESULT_END]:
|
|
||||||
message = ""
|
|
||||||
msg_type = buffer_type
|
|
||||||
while True:
|
|
||||||
if buffer_type == JERRY_DEBUGGER_OUTPUT_RESULT_END:
|
|
||||||
subtype = ord(data[-1])
|
|
||||||
message += data[3:-1]
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
message += data[3:]
|
|
||||||
|
|
||||||
data = debugger.get_message(True)
|
|
||||||
buffer_type = ord(data[2])
|
|
||||||
buffer_size = ord(data[1]) - 1
|
|
||||||
|
|
||||||
if buffer_type not in [msg_type, msg_type + 1]:
|
|
||||||
raise Exception("Output data expected")
|
|
||||||
|
|
||||||
if subtype == JERRY_DEBUGGER_OUTPUT_OK:
|
|
||||||
print("%sout: %s%s" % (debugger.blue, debugger.nocolor, message))
|
|
||||||
elif subtype == JERRY_DEBUGGER_OUTPUT_WARNING:
|
|
||||||
print("%swarning: %s%s" % (debugger.yellow, debugger.nocolor, message))
|
|
||||||
elif subtype == JERRY_DEBUGGER_OUTPUT_ERROR:
|
|
||||||
print("%serr: %s%s" % (debugger.red, debugger.nocolor, message))
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown message")
|
raise Exception("Unknown message")
|
||||||
|
|||||||
Reference in New Issue
Block a user