summaryrefslogtreecommitdiff
path: root/dev-lang/jerryscript/files/jerryscript-2.4.0-python3.patch
blob: a7046b4b645318e9427d5cdb7a490cd60452b07c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
From 3f725c9a6e62048dcc7e1d0dd0f9c3e8d2e092f6 Mon Sep 17 00:00:00 2001
From: Zac Medico <zmedico@gmail.com>
Date: Sun, 23 May 2021 13:46:30 -0700
Subject: [PATCH] Python debugger support for Python 3 (in addition to Python 2)

https://github.com/jerryscript-project/jerryscript/pull/4678

- Added ord builtin compatibility to pass through int arguments
- Fixed JerryDebugger _parse_source method to decode bytes as utf8 strings
- Fixed WebSocket send_message method to use packed_data[0:1] bytes slice

JerryScript-DCO-1.0-Signed-off-by: Zac Medico <zmedico@gmail.com>
---
 jerry-debugger/jerry_client_main.py      | 26 ++++++++++++++++--------
 jerry-debugger/jerry_client_websocket.py | 14 ++++++++++++-
 2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/jerry-debugger/jerry_client_main.py b/jerry-debugger/jerry_client_main.py
index e65d0e14..b465955f 100644
--- a/jerry-debugger/jerry_client_main.py
+++ b/jerry-debugger/jerry_client_main.py
@@ -151,2 +151,13 @@ def arguments_parse():
 
+if sys.version_info.major >= 3:
+    # pylint: disable=invalid-name
+    _ord_orig = ord
+    def _ord_compat(c):
+        if isinstance(c, int):
+            return c
+        return _ord_orig(c)
+    # pylint: disable=redefined-builtin
+    ord = _ord_compat
+
+
 class JerryBreakpoint(object):
@@ -563,2 +574,3 @@ class JerryDebugger(object):
     def _send_string(self, args, message_type, index=0):
+        args = args.encode("utf8")
 
@@ -810,3 +822,3 @@ class JerryDebugger(object):
             elif buffer_type in [JERRY_DEBUGGER_SCOPE_VARIABLES, JERRY_DEBUGGER_SCOPE_VARIABLES_END]:
-                self.scope_vars += "".join(data[1:])
+                self.scope_vars += "".join(data[1:].decode("utf8"))
 
@@ -866,5 +878,5 @@ class JerryDebugger(object):
     def _parse_source(self, data):
-        source_code = ""
-        source_code_name = ""
-        function_name = ""
+        source_code = b""
+        source_code_name = b""
+        function_name = b""
         stack = [{"line": 1,
@@ -905,7 +917,7 @@ class JerryDebugger(object):
 
-                stack.append({"source": source_code,
-                              "source_name": source_code_name,
+                stack.append({"source": source_code.decode("utf8"),
+                              "source_name": source_code_name.decode("utf8"),
                               "line": position[0],
                               "column": position[1],
-                              "name": function_name,
+                              "name": function_name.decode("utf8"),
                               "lines": [],
@@ -939,4 +951,4 @@ class JerryDebugger(object):
                 if not stack:
-                    func_desc["source"] = source_code
-                    func_desc["source_name"] = source_code_name
+                    func_desc["source"] = source_code.decode("utf8")
+                    func_desc["source_name"] = source_code_name.decode("utf8")
 
@@ -1153,4 +1165,4 @@ class JerryDebugger(object):
                 message = self.current_out + message
-                lines = message.split("\n")
-                self.current_out = lines.pop()
+                lines = message.decode("utf8").split("\n")
+                self.current_out = lines.pop().encode("utf8")
 
@@ -1162,4 +1174,4 @@ class JerryDebugger(object):
                 message = self.current_log + message
-                lines = message.split("\n")
-                self.current_log = lines.pop()
+                lines = message.decode("utf8").split("\n")
+                self.current_log = lines.pop().encode("utf8")
 
@@ -1171,7 +1183,7 @@ class JerryDebugger(object):
             if subtype == JERRY_DEBUGGER_OUTPUT_WARNING:
-                return "%swarning: %s%s" % (self.yellow, self.nocolor, message)
+                return "%swarning: %s%s" % (self.yellow, self.nocolor, message.decode("utf8"))
             elif subtype == JERRY_DEBUGGER_OUTPUT_ERROR:
-                return "%serr: %s%s" % (self.red, self.nocolor, message)
+                return "%serr: %s%s" % (self.red, self.nocolor, message.decode("utf8"))
             elif subtype == JERRY_DEBUGGER_OUTPUT_TRACE:
-                return "%strace: %s%s" % (self.blue, self.nocolor, message)
+                return "%strace: %s%s" % (self.blue, self.nocolor, message.decode("utf8"))
 
@@ -1180,2 +1192,3 @@ class JerryDebugger(object):
 
+        message = message.decode("utf8")
         if not message.endswith("\n"):
diff --git a/jerry-debugger/jerry_client_websocket.py b/jerry-debugger/jerry_client_websocket.py
index fe2c761a..9c755966 100644
--- a/jerry-debugger/jerry_client_websocket.py
+++ b/jerry-debugger/jerry_client_websocket.py
@@ -17,2 +17,3 @@
 import struct
+import sys
 
@@ -22,2 +23,14 @@ WEBSOCKET_FIN_BIT = 0x80
 
+
+if sys.version_info.major >= 3:
+    # pylint: disable=invalid-name
+    _ord_orig = ord
+    def _ord_compat(c):
+        if isinstance(c, int):
+            return c
+        return _ord_orig(c)
+    # pylint: disable=redefined-builtin
+    ord = _ord_compat
+
+
 class WebSocket(object):
@@ -94,3 +107,3 @@ class WebSocket(object):
                               WEBSOCKET_BINARY_FRAME | WEBSOCKET_FIN_BIT,
-                              WEBSOCKET_FIN_BIT + struct.unpack(byte_order + "B", packed_data[0])[0],
+                              WEBSOCKET_FIN_BIT + struct.unpack(byte_order + "B", packed_data[0:1])[0],
                               0) + packed_data[1:]