@@ -149,6 +149,17 @@ def arguments_parse():
149
149
return args
150
150
151
151
152
+ if sys .version_info .major >= 3 :
153
+ # pylint: disable=invalid-name
154
+ _ord_orig = ord
155
+ def _ord_compat (c ):
156
+ if isinstance (c , int ):
157
+ return c
158
+ return _ord_orig (c )
159
+ # pylint: disable=redefined-builtin
160
+ ord = _ord_compat
161
+
162
+
152
163
class JerryBreakpoint (object ):
153
164
154
165
def __init__ (self , line , offset , function ):
@@ -561,6 +572,7 @@ def memstats(self):
561
572
self ._exec_command (JERRY_DEBUGGER_MEMSTATS )
562
573
563
574
def _send_string (self , args , message_type , index = 0 ):
575
+ args = args .encode ("utf8" )
564
576
565
577
# 1: length of type byte
566
578
# 4: length of an uint32 value
@@ -808,7 +820,7 @@ def process_messages(self):
808
820
return DebuggerAction (DebuggerAction .TEXT , result )
809
821
810
822
elif buffer_type in [JERRY_DEBUGGER_SCOPE_VARIABLES , JERRY_DEBUGGER_SCOPE_VARIABLES_END ]:
811
- self .scope_vars += "" .join (data [1 :])
823
+ self .scope_vars += "" .join (data [1 :]. decode ( "utf8" ) )
812
824
813
825
if buffer_type == JERRY_DEBUGGER_SCOPE_VARIABLES_END :
814
826
result = self ._process_scope_variables ()
@@ -864,9 +876,9 @@ def print_source(self, line_num, offset):
864
876
865
877
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
866
878
def _parse_source (self , data ):
867
- source_code = ""
868
- source_code_name = ""
869
- function_name = ""
879
+ source_code = b ""
880
+ source_code_name = b ""
881
+ function_name = b ""
870
882
stack = [{"line" : 1 ,
871
883
"column" : 1 ,
872
884
"name" : "" ,
@@ -903,11 +915,11 @@ def _parse_source(self, data):
903
915
position = struct .unpack (self .byte_order + self .idx_format + self .idx_format ,
904
916
data [1 : 1 + 4 + 4 ])
905
917
906
- stack .append ({"source" : source_code ,
907
- "source_name" : source_code_name ,
918
+ stack .append ({"source" : source_code . decode ( "utf8" ) ,
919
+ "source_name" : source_code_name . decode ( "utf8" ) ,
908
920
"line" : position [0 ],
909
921
"column" : position [1 ],
910
- "name" : function_name ,
922
+ "name" : function_name . decode ( "utf8" ) ,
911
923
"lines" : [],
912
924
"offsets" : []})
913
925
function_name = ""
@@ -937,8 +949,8 @@ def _parse_source(self, data):
937
949
938
950
# We know the last item in the list is the general byte code.
939
951
if not stack :
940
- func_desc ["source" ] = source_code
941
- func_desc ["source_name" ] = source_code_name
952
+ func_desc ["source" ] = source_code . decode ( "utf8" )
953
+ func_desc ["source_name" ] = source_code_name . decode ( "utf8" )
942
954
943
955
function = JerryFunction (stack ,
944
956
byte_code_cp ,
@@ -1151,33 +1163,34 @@ def _process_incoming_text(self, buffer_type, data):
1151
1163
log_type = "%sout:%s " % (self .blue , self .nocolor )
1152
1164
1153
1165
message = self .current_out + message
1154
- lines = message .split ("\n " )
1155
- self .current_out = lines .pop ()
1166
+ lines = message .decode ( "utf8" ). split ("\n " )
1167
+ self .current_out = lines .pop (). encode ( "utf8" )
1156
1168
1157
1169
return "" .join (["%s%s\n " % (log_type , line ) for line in lines ])
1158
1170
1159
1171
if subtype == JERRY_DEBUGGER_OUTPUT_DEBUG :
1160
1172
log_type = "%slog:%s " % (self .yellow , self .nocolor )
1161
1173
1162
1174
message = self .current_log + message
1163
- lines = message .split ("\n " )
1164
- self .current_log = lines .pop ()
1175
+ lines = message .decode ( "utf8" ). split ("\n " )
1176
+ self .current_log = lines .pop (). encode ( "utf8" )
1165
1177
1166
1178
return "" .join (["%s%s\n " % (log_type , line ) for line in lines ])
1167
1179
1168
1180
if not message .endswith ("\n " ):
1169
1181
message += "\n "
1170
1182
1171
1183
if subtype == JERRY_DEBUGGER_OUTPUT_WARNING :
1172
- return "%swarning: %s%s" % (self .yellow , self .nocolor , message )
1184
+ return "%swarning: %s%s" % (self .yellow , self .nocolor , message . decode ( "utf8" ) )
1173
1185
elif subtype == JERRY_DEBUGGER_OUTPUT_ERROR :
1174
- return "%serr: %s%s" % (self .red , self .nocolor , message )
1186
+ return "%serr: %s%s" % (self .red , self .nocolor , message . decode ( "utf8" ) )
1175
1187
elif subtype == JERRY_DEBUGGER_OUTPUT_TRACE :
1176
- return "%strace: %s%s" % (self .blue , self .nocolor , message )
1188
+ return "%strace: %s%s" % (self .blue , self .nocolor , message . decode ( "utf8" ) )
1177
1189
1178
1190
# Subtypes of eval
1179
1191
self .prompt = True
1180
1192
1193
+ message = message .decode ("utf8" )
1181
1194
if not message .endswith ("\n " ):
1182
1195
message += "\n "
1183
1196
0 commit comments